Sha256: 4a7171451102fb4866e1399426153e11a50fff7790897d83a96b88a42c27df23
Contents?: true
Size: 1.21 KB
Versions: 15
Compression:
Stored size: 1.21 KB
Contents
#include <ruby.h> #include <stdint.h> #include <stdlib.h> #define CIFAR10_WIDTH 32 #define CIFAR10_HEIGHT 32 #define CIFAR10_CHANNEL 3 static VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) { uint8_t* bin = (uint8_t*)StringValuePtr(rb_bin); int32_t num_datas = FIX2INT(rb_num_datas); VALUE rb_x_bin; VALUE rb_y_bin; int32_t i; int32_t j = 0; int32_t k = 0; int32_t size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL; int32_t x_bin_size = num_datas * size; int32_t y_bin_size = num_datas; uint8_t* x_bin; uint8_t* y_bin; x_bin = (uint8_t*)malloc(x_bin_size); y_bin = (uint8_t*)malloc(y_bin_size); for (i = 0; i < num_datas; i++) { y_bin[i] = bin[j]; j++; memcpy(&x_bin[k], &bin[j], size); j += size; k += size; } rb_x_bin = rb_str_new((char*)x_bin, x_bin_size); rb_y_bin = rb_str_new((char*)y_bin, y_bin_size); free(x_bin); free(y_bin); return rb_ary_new3(2, rb_x_bin, rb_y_bin); } void Init_cifar10_loader() { VALUE rb_dnn = rb_define_module("DNN"); VALUE rb_cifar10 = rb_define_module_under(rb_dnn, "CIFAR10"); rb_define_singleton_method(rb_cifar10, "load_binary", cifar10_load_binary, 2); }
Version data entries
15 entries across 15 versions & 1 rubygems