X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=svrt.c;h=4969d5aac43f22750088c309850e97433217a8cc;hb=349b55a2d9ca213718df8941058d42689ba68163;hp=1a2449b04ee43638b9bc961478dbbe5db3adfabe;hpb=24368498f3065e8a4be34c5e8e2b68f9d1220f7d;p=pysvrt.git
diff --git a/svrt.c b/svrt.c
index 1a2449b..4969d5a 100644
--- a/svrt.c
+++ b/svrt.c
@@ -19,7 +19,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 .
*
*/
@@ -27,6 +27,69 @@
#include "svrt_generator.h"
+THByteStorage *compress(THByteStorage *x) {
+ long k, g, n;
+
+ k = 0; n = 0;
+ while(k < x->size) {
+ g = 0;
+ while(k < x->size && x->data[k] == 255 && g < 255) { g++; k++; }
+ n++;
+ if(k < x->size && g < 255) { k++; }
+ }
+
+ if(x->data[k-1] == 0) {
+ n++;
+ }
+
+ THByteStorage *result = THByteStorage_newWithSize(n);
+
+ k = 0; n = 0;
+ while(k < x->size) {
+ g = 0;
+ while(k < x->size && x->data[k] == 255 && g < 255) { g++; k++; }
+ result->data[n++] = g;
+ if(k < x->size && g < 255) { k++; }
+ }
+ if(x->data[k-1] == 0) {
+ result->data[n++] = 0;
+ }
+
+ return result;
+}
+
+THByteStorage *uncompress(THByteStorage *x) {
+ long k, g, n;
+
+ k = 0;
+ for(n = 0; n < x->size - 1; n++) {
+ k = k + x->data[n];
+ if(x->data[n] < 255) { k++; }
+ }
+ k = k + x->data[n];
+
+ THByteStorage *result = THByteStorage_newWithSize(k);
+
+ k = 0;
+ for(n = 0; n < x->size - 1; n++) {
+ for(g = 0; g < x->data[n]; g++) {
+ result->data[k++] = 255;
+ }
+ if(x->data[n] < 255) {
+ result->data[k++] = 0;
+ }
+ }
+ for(g = 0; g < x->data[n]; g++) {
+ result->data[k++] = 255;
+ }
+
+ return result;
+}
+
+void seed(long s) {
+ srand48(s);
+}
+
THByteTensor *generate_vignettes(long n_problem, THLongTensor *labels) {
struct VignetteSet vs;
long nb_vignettes;
@@ -35,6 +98,11 @@ THByteTensor *generate_vignettes(long n_problem, THLongTensor *labels) {
long *m, *l;
unsigned char *a, *b;
+ if(THLongTensor_nDimension(labels) != 1) {
+ printf("Label tensor has to be of dimension 1.\n");
+ exit(1);
+ }
+
nb_vignettes = THLongTensor_size(labels, 0);
m = THLongTensor_storage(labels)->data + THLongTensor_storageOffset(labels);
st0 = THLongTensor_stride(labels, 0);