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

Version Path
ruby-dnn-0.9.4 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.9.3 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.9.2 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.9.1 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.9.0 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.8 ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.7 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.6 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.5 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.4 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.3 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.2 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.1 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.8.0 lib/dnn/ext/cifar10_loader/cifar10_loader.c
ruby-dnn-0.7.3 lib/dnn/ext/cifar10_loader/cifar10_loader.c