X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=flatland.git;a=blobdiff_plain;f=flatland.c;fp=flatland.c;h=13da6fd24b3494666583303b6624ab5d30aec7b5;hp=0000000000000000000000000000000000000000;hb=5d4e9eaeec9263692d39ca840e498a5f1d818eaa;hpb=ee0d125312834bf7692df2e9caa1f858780f335c
diff --git a/flatland.c b/flatland.c
new file mode 100644
index 0000000..13da6fd
--- /dev/null
+++ b/flatland.c
@@ -0,0 +1,62 @@
+
+#include
+
+/*
+
+ Example of FFI extension I started from:
+
+ https://github.com/pytorch/extension-ffi.git
+
+ There is this tutorial
+
+ https://github.com/pytorch/tutorials/blob/master/Creating%20Extensions%20using%20FFI.md
+
+ And TH's Tensor definition are here in my install:
+
+ anaconda3/lib/python3.5/site-packages/torch/lib/include/TH/generic/THTensor.h
+
+ */
+
+#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;
+ unsigned char *a, *b;
+ int c, k, i, j, st0, st1, st2, st3, st4;
+
+ THByteTensor_resize5d(output, nb_sequences, nb_images_per_sequence, depth, height, width);
+
+ 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);
+
+ a =
+ THByteTensor_storage(output)->data + THByteTensor_storageOffset(output);
+
+ 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++) {
+ *b = (unsigned char) (*r);
+ r++;
+ b += st4;
+ }
+ }
+ }
+ }
+ }
+
+ return 1;
+}
|