X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=inline;f=svrt_generator.cc;h=33b98ee905541633632374f08ec3334806f9f3d6;hb=refs%2Fheads%2Fmaster;hp=80cfd1202fb13d32ebda1bbb2fbb3ee4d8efb168;hpb=44bd6cf57f00009c7049dcd3e5600f12f2f41de5;p=pysvrt.git
diff --git a/svrt_generator.cc b/svrt_generator.cc
index 80cfd12..33b98ee 100644
--- a/svrt_generator.cc
+++ b/svrt_generator.cc
@@ -18,7 +18,7 @@
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with selector. If not, see .
+ * along with svrt. If not, see .
*
*/
@@ -153,9 +153,15 @@ struct VignetteSet {
unsigned char *data;
};
-void svrt_generate_vignettes(int n_problem, int nb_vignettes, VignetteSet *result) {
+void svrt_generate_vignettes(int n_problem, int nb_vignettes, long *labels,
+ VignetteSet *result) {
Vignette tmp;
+ if(n_problem < 1 || n_problem > NB_PROBLEMS) {
+ printf("Problem number should be between 1 and %d. Provided value is %d.\n", NB_PROBLEMS, n_problem);
+ exit(1);
+ }
+
VignetteGenerator *vg = new_generator(n_problem);
result->n_problem = n_problem;
result->nb_vignettes = nb_vignettes;
@@ -165,7 +171,13 @@ void svrt_generate_vignettes(int n_problem, int nb_vignettes, VignetteSet *resul
unsigned char *s = result->data;
for(int i = 0; i < nb_vignettes; i++) {
- vg->generate(drand48() < 0.5 ? 1 : 0, &tmp);
+ if(labels[i] == 0 || labels[i] == 1) {
+ vg->generate(labels[i], &tmp);
+ } else {
+ printf("Vignette class label has to be 0 or 1. Provided value is %ld.\n", labels[i]);
+ exit(1);
+ }
+
int *r = tmp.content;
for(int k = 0; k < Vignette::width * Vignette::height; k++) {
*s++ = *r++;