Sha256: 72b3c81c227e37a6a8a06a22267ac28b476919a5efe71c55b9b6fb00479c967c

Contents?: true

Size: 1.12 KB

Versions: 31

Compression:

Stored size: 1.12 KB

Contents

#include <ruby.h>
#include <stdlib.h>

#define CIFAR10_WIDTH 32
#define CIFAR10_HEIGHT 32
#define CIFAR10_CHANNEL 3

VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
  char* bin = StringValuePtr(rb_bin);
  int num_datas = FIX2INT(rb_num_datas);
  VALUE rb_x_bin;
  VALUE rb_y_bin;
  int i;
  int j = 0;
  int k = 0;
  int size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
  int x_bin_size = num_datas * size;
  int y_bin_size = num_datas;
  char* x_bin;
  char* y_bin;

  x_bin = (char*)malloc(x_bin_size);
  y_bin = (char*)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(x_bin, x_bin_size);
  rb_y_bin = rb_str_new(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

31 entries across 31 versions & 1 rubygems

Version Path
ruby-dnn-0.7.2 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.7.1 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.7.0 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.10 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.9 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.8 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.7 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.6 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.5 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.4 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.3 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.2 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.1 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.6.0 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.12 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.11 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.10 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.9 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.8 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.5.7 lib/dnn/ext/cifar10_loader/cifar10_loader.c