X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=flatland.c;h=df5075b733449995bbdf2b4b62f6c2a7d5c7c0c1;hb=90d1c5704c30e7f1d041e32eacbc2893741110e1;hp=13da6fd24b3494666583303b6624ab5d30aec7b5;hpb=5d4e9eaeec9263692d39ca840e498a5f1d818eaa;p=flatland.git
diff --git a/flatland.c b/flatland.c
index 13da6fd..df5075b 100644
--- a/flatland.c
+++ b/flatland.c
@@ -1,6 +1,3 @@
-
-#include
-
/*
Example of FFI extension I started from:
@@ -17,38 +14,50 @@
*/
+#include |
+
#include "sequence_generator.h"
-int generate_sequence(long nb_sequences, THByteTensor *output) {
- long nb_images_per_sequence = 5;
- long depth = 3;
- long width = 64;
- long height = 64;
- long s;
+THByteTensor *generate_sequence(int pulling,
+ long nb_sequences,
+ long nb_images,
+ long image_height, long image_width,
+ long nb_shapes,
+ int random_shape_size, int random_colors) {
+
+ long nb_channels = 3;
unsigned char *a, *b;
- int c, k, i, j, st0, st1, st2, st3, st4;
+ long s, c, k, i, j, st0, st1, st2, st3, st4;
- THByteTensor_resize5d(output, nb_sequences, nb_images_per_sequence, depth, height, width);
+ THLongStorage *size = THLongStorage_newWithSize(5);
+ size->data[0] = nb_sequences;
+ size->data[1] = nb_images;
+ size->data[2] = nb_channels;
+ size->data[3] = image_height;
+ size->data[4] = image_width;
+ THByteTensor *result = THByteTensor_newWithSize(size, NULL);
+ THLongStorage_free(size);
- st0 = THByteTensor_stride(output, 0);
- st1 = THByteTensor_stride(output, 1);
- st2 = THByteTensor_stride(output, 2);
- st3 = THByteTensor_stride(output, 3);
- st4 = THByteTensor_stride(output, 4);
+ st0 = THByteTensor_stride(result, 0);
+ st1 = THByteTensor_stride(result, 1);
+ st2 = THByteTensor_stride(result, 2);
+ st3 = THByteTensor_stride(result, 3);
+ st4 = THByteTensor_stride(result, 4);
- a =
- THByteTensor_storage(output)->data + THByteTensor_storageOffset(output);
+ unsigned char tmp_buffer[nb_images * nb_channels * image_width * image_height];
for(s = 0; s < nb_sequences; s++) {
- unsigned char result[nb_images_per_sequence * depth * width * height];
- unsigned char *r = result;
- fl_generate_sequences(1, nb_images_per_sequence, width, height, result);
- for(k = 0; k < nb_images_per_sequence; k++) {
- for(c = 0; c < depth; c++) {
- for(i = 0; i < height; i++) {
- b = a
- + s * st0 + k * st1 + c * st2 + i * st3;
- for(j = 0; j < width; j++) {
+ a = THByteTensor_storage(result)->data + THByteTensor_storageOffset(result) + s * st0;
+ fl_generate_sequence(nb_images, image_width, image_height, nb_shapes,
+ random_shape_size, random_colors,
+ pulling,
+ tmp_buffer);
+ unsigned char *r = tmp_buffer;
+ for(k = 0; k < nb_images; k++) {
+ for(c = 0; c < nb_channels; c++) {
+ for(i = 0; i < image_height; i++) {
+ b = a + k * st1 + c * st2 + i * st3;
+ for(j = 0; j < image_width; j++) {
*b = (unsigned char) (*r);
r++;
b += st4;
@@ -58,5 +67,5 @@ int generate_sequence(long nb_sequences, THByteTensor *output) {
}
}
- return 1;
+ return result;
}
|