ruby-dnn 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf955bc9993a8c9495b144659cedc0cc97c1bde3bc1521be2453847d9d3afd91
4
- data.tar.gz: b64395b3976619575ded55fd7ab508d09a8f0cde0dd0ab8a7d611dd7ae76f169
3
+ metadata.gz: 5c2ef751fa76ea2918c5f706e1828eba514385b831dc042fa561a08d38da977a
4
+ data.tar.gz: b906f6a9c63620378b284a2be3ca3bb8e007534b945493b9f8323f77c012cd0f
5
5
  SHA512:
6
- metadata.gz: 8dca44e876a1403b8b02e94936ce46f98a7dfa14a47874976c88fad12544f447481959cec6d563c6af6cfe9fa643f37a18c016b39e1da955f915f18027580f11
7
- data.tar.gz: ad647ff01b6f9d9afe9a7dde002e68dce80dc1de57570d160e684f2a54fc635c9a0f6661fc563adbbe8196bd517f7c86f546302b185bac557209773f8d832da0
6
+ metadata.gz: 94e7af50f4cdc556b252e3afed0703aa7d9e9d519f2e1e24253a1a27b388fe9d00444edfc271343365dc39e8a02d326df27e923216834509cb639986576664de
7
+ data.tar.gz: 5fc8acfeed67fff5b41247ab6c3f03b68f96f48bdda877951e23d1fb12f2cc6c113a6102b8b531cd41d1c596d2ab6fa96a243607d38182d804ab1f5396e5439c
@@ -19,10 +19,12 @@ module DNN
19
19
  end
20
20
 
21
21
  # Forward propagation.
22
- def forward() end
22
+ # Classes that inherit from this class must implement this method.
23
+ # def forward() end
23
24
 
24
25
  # Backward propagation.
25
- def backward() end
26
+ # Classes that inherit from this class must implement this method.
27
+ # def backward() end
26
28
 
27
29
  # Get the shape of the layer.
28
30
  def shape
@@ -102,11 +104,12 @@ module DNN
102
104
  end
103
105
 
104
106
 
107
+ # It is a superclass of all connection layers.
105
108
  class Connection < HasParamLayer
106
109
  include Initializers
107
110
 
108
- attr_reader :l1_lambda
109
- attr_reader :l2_lambda
111
+ attr_reader :l1_lambda # L1 regularization
112
+ attr_reader :l2_lambda # L2 regularization
110
113
 
111
114
  def initialize(weight_initializer: nil,
112
115
  bias_initializer: nil,
@@ -1,26 +1,27 @@
1
1
  #include <ruby.h>
2
+ #include <stdint.h>
2
3
  #include <stdlib.h>
3
4
 
4
5
  #define CIFAR10_WIDTH 32
5
6
  #define CIFAR10_HEIGHT 32
6
7
  #define CIFAR10_CHANNEL 3
7
8
 
8
- VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
9
- char* bin = StringValuePtr(rb_bin);
10
- int num_datas = FIX2INT(rb_num_datas);
9
+ static VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
10
+ uint8_t* bin = (uint8_t*)StringValuePtr(rb_bin);
11
+ int32_t num_datas = FIX2INT(rb_num_datas);
11
12
  VALUE rb_x_bin;
12
13
  VALUE rb_y_bin;
13
- int i;
14
- int j = 0;
15
- int k = 0;
16
- int size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
17
- int x_bin_size = num_datas * size;
18
- int y_bin_size = num_datas;
19
- char* x_bin;
20
- char* y_bin;
14
+ int32_t i;
15
+ int32_t j = 0;
16
+ int32_t k = 0;
17
+ int32_t size = CIFAR10_WIDTH * CIFAR10_HEIGHT * CIFAR10_CHANNEL;
18
+ int32_t x_bin_size = num_datas * size;
19
+ int32_t y_bin_size = num_datas;
20
+ uint8_t* x_bin;
21
+ uint8_t* y_bin;
21
22
 
22
- x_bin = (char*)malloc(x_bin_size);
23
- y_bin = (char*)malloc(y_bin_size);
23
+ x_bin = (uint8_t*)malloc(x_bin_size);
24
+ y_bin = (uint8_t*)malloc(y_bin_size);
24
25
  for (i = 0; i < num_datas; i++) {
25
26
  y_bin[i] = bin[j];
26
27
  j++;
@@ -28,8 +29,8 @@ VALUE cifar10_load_binary(VALUE self, VALUE rb_bin, VALUE rb_num_datas) {
28
29
  j += size;
29
30
  k += size;
30
31
  }
31
- rb_x_bin = rb_str_new(x_bin, x_bin_size);
32
- rb_y_bin = rb_str_new(y_bin, y_bin_size);
32
+ rb_x_bin = rb_str_new((char*)x_bin, x_bin_size);
33
+ rb_y_bin = rb_str_new((char*)y_bin, y_bin_size);
33
34
  free(x_bin);
34
35
  free(y_bin);
35
36
  return rb_ary_new3(2, rb_x_bin, rb_y_bin);
@@ -1,4 +1,5 @@
1
1
  #include <ruby.h>
2
+ #include <stdint.h>
2
3
 
3
4
  #define STB_IMAGE_IMPLEMENTATION
4
5
  #define STB_IMAGE_WRITE_IMPLEMENTATION
@@ -6,13 +7,13 @@
6
7
  #include "stb_image.h"
7
8
  #include "stb_image_write.h"
8
9
 
9
- //STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp);
10
- VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
10
+ // STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp);
11
+ static VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
11
12
  char* filename = StringValuePtr(rb_filename);
12
- int x, y, n;
13
- int req_comp = FIX2INT(rb_req_comp);
14
- unsigned char* data;
15
- int ch;
13
+ int32_t x, y, n;
14
+ int32_t req_comp = FIX2INT(rb_req_comp);
15
+ uint8_t* data;
16
+ int32_t ch;
16
17
  VALUE rb_x, rb_y, rb_n;
17
18
  VALUE rb_data;
18
19
 
@@ -26,42 +27,68 @@ VALUE rb_stbi_load(VALUE self, VALUE rb_filename, VALUE rb_req_comp) {
26
27
  return rb_ary_new3(4, rb_data, rb_x, rb_y, rb_n);
27
28
  }
28
29
 
29
- //STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
30
- VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_stride_in_bytes) {
30
+ // STBIWDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
31
+ static VALUE rb_stbi_write_png(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_stride_in_bytes) {
31
32
  char* filename = StringValuePtr(rb_filename);
32
- int w = FIX2INT(rb_w);
33
- int h = FIX2INT(rb_h);
34
- int comp = FIX2INT(rb_comp);
35
- unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
36
- int stride_in_bytes = FIX2INT(rb_stride_in_bytes);
37
- int result;
33
+ int32_t w = FIX2INT(rb_w);
34
+ int32_t h = FIX2INT(rb_h);
35
+ int32_t comp = FIX2INT(rb_comp);
36
+ uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
37
+ int32_t stride_in_bytes = FIX2INT(rb_stride_in_bytes);
38
+ int32_t result;
38
39
 
39
40
  result = stbi_write_png(filename, w, h, comp, data, stride_in_bytes);
40
41
  return INT2FIX(result);
41
42
  }
42
43
 
43
- //STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
44
- VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
44
+ // STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
45
+ static VALUE rb_stbi_write_bmp(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
45
46
  char* filename = StringValuePtr(rb_filename);
46
- int w = FIX2INT(rb_w);
47
- int h = FIX2INT(rb_h);
48
- int comp = FIX2INT(rb_comp);
49
- unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
50
- int result;
47
+ int32_t w = FIX2INT(rb_w);
48
+ int32_t h = FIX2INT(rb_h);
49
+ int32_t comp = FIX2INT(rb_comp);
50
+ uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
51
+ int32_t result;
51
52
 
52
53
  result = stbi_write_bmp(filename, w, h, comp, data);
53
54
  return INT2FIX(result);
54
55
  }
55
56
 
56
- //STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
57
- VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_quality) {
57
+ // STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
58
+ static VALUE rb_stbi_write_tga(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
58
59
  char* filename = StringValuePtr(rb_filename);
59
- int w = FIX2INT(rb_w);
60
- int h = FIX2INT(rb_h);
61
- int comp = FIX2INT(rb_comp);
62
- unsigned char* data = (unsigned char*)StringValuePtr(rb_data);
63
- int quality = FIX2INT(rb_quality);
64
- int result;
60
+ int32_t w = FIX2INT(rb_w);
61
+ int32_t h = FIX2INT(rb_h);
62
+ int32_t comp = FIX2INT(rb_comp);
63
+ uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
64
+ int32_t result;
65
+
66
+ result = stbi_write_tga(filename, w, h, comp, data);
67
+ return INT2FIX(result);
68
+ }
69
+
70
+ // STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
71
+ static VALUE rb_stbi_write_hdr(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data) {
72
+ char* filename = StringValuePtr(rb_filename);
73
+ int32_t w = FIX2INT(rb_w);
74
+ int32_t h = FIX2INT(rb_h);
75
+ int32_t comp = FIX2INT(rb_comp);
76
+ float* data = (float*)StringValuePtr(rb_data);
77
+ int32_t result;
78
+
79
+ result = stbi_write_hdr(filename, w, h, comp, data);
80
+ return INT2FIX(result);
81
+ }
82
+
83
+ // STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
84
+ static VALUE rb_stbi_write_jpg(VALUE self, VALUE rb_filename, VALUE rb_w, VALUE rb_h, VALUE rb_comp, VALUE rb_data, VALUE rb_quality) {
85
+ char* filename = StringValuePtr(rb_filename);
86
+ int32_t w = FIX2INT(rb_w);
87
+ int32_t h = FIX2INT(rb_h);
88
+ int32_t comp = FIX2INT(rb_comp);
89
+ uint8_t* data = (uint8_t*)StringValuePtr(rb_data);
90
+ int32_t quality = FIX2INT(rb_quality);
91
+ int32_t result;
65
92
 
66
93
  result = stbi_write_jpg(filename, w, h, comp, data, quality);
67
94
  return INT2FIX(result);
@@ -74,5 +101,7 @@ void Init_rb_stb_image() {
74
101
  rb_define_module_function(rb_stb, "stbi_load", rb_stbi_load, 2);
75
102
  rb_define_module_function(rb_stb, "stbi_write_png", rb_stbi_write_png, 6);
76
103
  rb_define_module_function(rb_stb, "stbi_write_bmp", rb_stbi_write_bmp, 5);
104
+ rb_define_module_function(rb_stb, "stbi_write_tga", rb_stbi_write_tga, 5);
105
+ rb_define_module_function(rb_stb, "stbi_write_hdr", rb_stbi_write_hdr, 5);
77
106
  rb_define_module_function(rb_stb, "stbi_write_jpg", rb_stbi_write_jpg, 6);
78
107
  }
@@ -1,4 +1,3 @@
1
- require "dnn"
2
1
  require "open-uri"
3
2
  require "zlib"
4
3
  require "archive/tar/minitar"
data/lib/dnn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DNN
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-dnn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - unagiootoro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-07 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray