X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=flatland.git;a=blobdiff_plain;f=flatland.c;h=d92d2256d519781c84096386fc14c1a923c9c9f9;hp=71dee6352b600b1de6edc10e4716b1c3b4dbc2b9;hb=HEAD;hpb=4aed0ce274b7c0e379651c28e439375c821c047a diff --git a/flatland.c b/flatland.c index 71dee63..d92d225 100644 --- a/flatland.c +++ b/flatland.c @@ -1,37 +1,49 @@ + /* - Example of FFI extension I started from: + flatland is a simple 2d physical simulator - https://github.com/pytorch/extension-ffi.git + Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ + Written by Francois Fleuret - There is this tutorial + This file is part of flatland - https://github.com/pytorch/tutorials/blob/master/Creating%20Extensions%20using%20FFI.md + flatland is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License version 3 as + published by the Free Software Foundation. - And TH's Tensor definition are here in my install: + flatland is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. - anaconda3/lib/python3.5/site-packages/torch/lib/include/TH/generic/THTensor.h + You should have received a copy of the GNU General Public License + along with flatland. If not, see . - */ +*/ #include #include "sequence_generator.h" -THByteTensor *generate_sequence(long nb_sequences, long nb_images_per_sequence, long image_width, long image_height) { +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; long s, c, k, i, j, st0, st1, st2, st3, st4; THLongStorage *size = THLongStorage_newWithSize(5); size->data[0] = nb_sequences; - size->data[1] = nb_images_per_sequence; + 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(result, 0); @@ -40,20 +52,19 @@ THByteTensor *generate_sequence(long nb_sequences, long nb_images_per_sequence, st3 = THByteTensor_stride(result, 3); st4 = THByteTensor_stride(result, 4); - unsigned char tmp_buffer[nb_images_per_sequence * nb_channels * image_width * image_height]; + unsigned char tmp_buffer[nb_images * nb_channels * image_width * image_height]; for(s = 0; s < nb_sequences; s++) { - a = - THByteTensor_storage(result)->data + THByteTensor_storageOffset(result) + s * st0; - - fl_generate_sequences(1, nb_images_per_sequence, image_width, image_height, tmp_buffer); - + 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_per_sequence; k++) { + 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; + b = a + k * st1 + c * st2 + i * st3; for(j = 0; j < image_width; j++) { *b = (unsigned char) (*r); r++;