ruby-dnn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +42 -0
  8. data/Rakefile +10 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/dnn.rb +14 -0
  12. data/lib/dnn/core/activations.rb +116 -0
  13. data/lib/dnn/core/error.rb +13 -0
  14. data/lib/dnn/core/initializers.rb +46 -0
  15. data/lib/dnn/core/layers.rb +366 -0
  16. data/lib/dnn/core/model.rb +158 -0
  17. data/lib/dnn/core/optimizers.rb +113 -0
  18. data/lib/dnn/core/util.rb +24 -0
  19. data/lib/dnn/core/version.rb +3 -0
  20. data/lib/dnn/ext/cifar10/Makefile +263 -0
  21. data/lib/dnn/ext/cifar10/cifar10_ext.c +52 -0
  22. data/lib/dnn/ext/cifar10/cifar10_ext.o +0 -0
  23. data/lib/dnn/ext/cifar10/cifar10_ext.so +0 -0
  24. data/lib/dnn/ext/cifar10/extconf.rb +3 -0
  25. data/lib/dnn/ext/cifar10/numo/compat.h +23 -0
  26. data/lib/dnn/ext/cifar10/numo/extconf.h +13 -0
  27. data/lib/dnn/ext/cifar10/numo/intern.h +117 -0
  28. data/lib/dnn/ext/cifar10/numo/narray.h +430 -0
  29. data/lib/dnn/ext/cifar10/numo/ndloop.h +94 -0
  30. data/lib/dnn/ext/cifar10/numo/template.h +149 -0
  31. data/lib/dnn/ext/cifar10/numo/types/bit.h +33 -0
  32. data/lib/dnn/ext/cifar10/numo/types/complex.h +409 -0
  33. data/lib/dnn/ext/cifar10/numo/types/complex_macro.h +377 -0
  34. data/lib/dnn/ext/cifar10/numo/types/dcomplex.h +44 -0
  35. data/lib/dnn/ext/cifar10/numo/types/dfloat.h +42 -0
  36. data/lib/dnn/ext/cifar10/numo/types/float_def.h +34 -0
  37. data/lib/dnn/ext/cifar10/numo/types/float_macro.h +186 -0
  38. data/lib/dnn/ext/cifar10/numo/types/int16.h +24 -0
  39. data/lib/dnn/ext/cifar10/numo/types/int32.h +24 -0
  40. data/lib/dnn/ext/cifar10/numo/types/int64.h +24 -0
  41. data/lib/dnn/ext/cifar10/numo/types/int8.h +24 -0
  42. data/lib/dnn/ext/cifar10/numo/types/int_macro.h +41 -0
  43. data/lib/dnn/ext/cifar10/numo/types/real_accum.h +486 -0
  44. data/lib/dnn/ext/cifar10/numo/types/robj_macro.h +75 -0
  45. data/lib/dnn/ext/cifar10/numo/types/robject.h +27 -0
  46. data/lib/dnn/ext/cifar10/numo/types/scomplex.h +44 -0
  47. data/lib/dnn/ext/cifar10/numo/types/sfloat.h +43 -0
  48. data/lib/dnn/ext/cifar10/numo/types/uint16.h +21 -0
  49. data/lib/dnn/ext/cifar10/numo/types/uint32.h +21 -0
  50. data/lib/dnn/ext/cifar10/numo/types/uint64.h +21 -0
  51. data/lib/dnn/ext/cifar10/numo/types/uint8.h +21 -0
  52. data/lib/dnn/ext/cifar10/numo/types/uint_macro.h +32 -0
  53. data/lib/dnn/ext/cifar10/numo/types/xint_macro.h +189 -0
  54. data/lib/dnn/ext/image_io/Makefile +263 -0
  55. data/lib/dnn/ext/image_io/extconf.rb +3 -0
  56. data/lib/dnn/ext/image_io/image_io_ext.c +89 -0
  57. data/lib/dnn/ext/image_io/image_io_ext.so +0 -0
  58. data/lib/dnn/ext/image_io/numo/compat.h +23 -0
  59. data/lib/dnn/ext/image_io/numo/extconf.h +13 -0
  60. data/lib/dnn/ext/image_io/numo/intern.h +117 -0
  61. data/lib/dnn/ext/image_io/numo/narray.h +430 -0
  62. data/lib/dnn/ext/image_io/numo/ndloop.h +94 -0
  63. data/lib/dnn/ext/image_io/numo/template.h +149 -0
  64. data/lib/dnn/ext/image_io/numo/types/bit.h +33 -0
  65. data/lib/dnn/ext/image_io/numo/types/complex.h +409 -0
  66. data/lib/dnn/ext/image_io/numo/types/complex_macro.h +377 -0
  67. data/lib/dnn/ext/image_io/numo/types/dcomplex.h +44 -0
  68. data/lib/dnn/ext/image_io/numo/types/dfloat.h +42 -0
  69. data/lib/dnn/ext/image_io/numo/types/float_def.h +34 -0
  70. data/lib/dnn/ext/image_io/numo/types/float_macro.h +186 -0
  71. data/lib/dnn/ext/image_io/numo/types/int16.h +24 -0
  72. data/lib/dnn/ext/image_io/numo/types/int32.h +24 -0
  73. data/lib/dnn/ext/image_io/numo/types/int64.h +24 -0
  74. data/lib/dnn/ext/image_io/numo/types/int8.h +24 -0
  75. data/lib/dnn/ext/image_io/numo/types/int_macro.h +41 -0
  76. data/lib/dnn/ext/image_io/numo/types/real_accum.h +486 -0
  77. data/lib/dnn/ext/image_io/numo/types/robj_macro.h +75 -0
  78. data/lib/dnn/ext/image_io/numo/types/robject.h +27 -0
  79. data/lib/dnn/ext/image_io/numo/types/scomplex.h +44 -0
  80. data/lib/dnn/ext/image_io/numo/types/sfloat.h +43 -0
  81. data/lib/dnn/ext/image_io/numo/types/uint16.h +21 -0
  82. data/lib/dnn/ext/image_io/numo/types/uint32.h +21 -0
  83. data/lib/dnn/ext/image_io/numo/types/uint64.h +21 -0
  84. data/lib/dnn/ext/image_io/numo/types/uint8.h +21 -0
  85. data/lib/dnn/ext/image_io/numo/types/uint_macro.h +32 -0
  86. data/lib/dnn/ext/image_io/numo/types/xint_macro.h +189 -0
  87. data/lib/dnn/ext/image_io/stb_image.h +7462 -0
  88. data/lib/dnn/ext/image_io/stb_image_write.h +1568 -0
  89. data/lib/dnn/ext/mnist/Makefile +263 -0
  90. data/lib/dnn/ext/mnist/extconf.rb +3 -0
  91. data/lib/dnn/ext/mnist/mnist_ext.c +49 -0
  92. data/lib/dnn/ext/mnist/mnist_ext.o +0 -0
  93. data/lib/dnn/ext/mnist/mnist_ext.so +0 -0
  94. data/lib/dnn/ext/mnist/numo/compat.h +23 -0
  95. data/lib/dnn/ext/mnist/numo/extconf.h +13 -0
  96. data/lib/dnn/ext/mnist/numo/intern.h +117 -0
  97. data/lib/dnn/ext/mnist/numo/narray.h +430 -0
  98. data/lib/dnn/ext/mnist/numo/ndloop.h +94 -0
  99. data/lib/dnn/ext/mnist/numo/template.h +149 -0
  100. data/lib/dnn/ext/mnist/numo/types/bit.h +33 -0
  101. data/lib/dnn/ext/mnist/numo/types/complex.h +409 -0
  102. data/lib/dnn/ext/mnist/numo/types/complex_macro.h +377 -0
  103. data/lib/dnn/ext/mnist/numo/types/dcomplex.h +44 -0
  104. data/lib/dnn/ext/mnist/numo/types/dfloat.h +42 -0
  105. data/lib/dnn/ext/mnist/numo/types/float_def.h +34 -0
  106. data/lib/dnn/ext/mnist/numo/types/float_macro.h +186 -0
  107. data/lib/dnn/ext/mnist/numo/types/int16.h +24 -0
  108. data/lib/dnn/ext/mnist/numo/types/int32.h +24 -0
  109. data/lib/dnn/ext/mnist/numo/types/int64.h +24 -0
  110. data/lib/dnn/ext/mnist/numo/types/int8.h +24 -0
  111. data/lib/dnn/ext/mnist/numo/types/int_macro.h +41 -0
  112. data/lib/dnn/ext/mnist/numo/types/real_accum.h +486 -0
  113. data/lib/dnn/ext/mnist/numo/types/robj_macro.h +75 -0
  114. data/lib/dnn/ext/mnist/numo/types/robject.h +27 -0
  115. data/lib/dnn/ext/mnist/numo/types/scomplex.h +44 -0
  116. data/lib/dnn/ext/mnist/numo/types/sfloat.h +43 -0
  117. data/lib/dnn/ext/mnist/numo/types/uint16.h +21 -0
  118. data/lib/dnn/ext/mnist/numo/types/uint32.h +21 -0
  119. data/lib/dnn/ext/mnist/numo/types/uint64.h +21 -0
  120. data/lib/dnn/ext/mnist/numo/types/uint8.h +21 -0
  121. data/lib/dnn/ext/mnist/numo/types/uint_macro.h +32 -0
  122. data/lib/dnn/ext/mnist/numo/types/xint_macro.h +189 -0
  123. data/lib/dnn/lib/cifar10.rb +26 -0
  124. data/lib/dnn/lib/image_io.rb +33 -0
  125. data/lib/dnn/lib/mnist.rb +61 -0
  126. data/ruby-dnn.gemspec +41 -0
  127. metadata +225 -0
@@ -0,0 +1,263 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@ :)
9
+ ECHO = $(ECHO1:0=@ echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /home/ootoro/.rbenv/versions/2.5.1/include/ruby-2.5.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /home/ootoro/.rbenv/versions/2.5.1/include/ruby-2.5.0/x86_64-linux
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
20
+ prefix = $(DESTDIR)/home/ootoro/.rbenv/versions/2.5.1
21
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
+ rubyarchprefix = $(rubylibprefix)/$(arch)
23
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
24
+ exec_prefix = $(prefix)
25
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
26
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
27
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
28
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
29
+ sitehdrdir = $(rubyhdrdir)/site_ruby
30
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
31
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
32
+ vendorlibdir = $(vendordir)/$(ruby_version)
33
+ vendordir = $(rubylibprefix)/vendor_ruby
34
+ sitearchdir = $(sitelibdir)/$(sitearch)
35
+ sitelibdir = $(sitedir)/$(ruby_version)
36
+ sitedir = $(rubylibprefix)/site_ruby
37
+ rubyarchdir = $(rubylibdir)/$(arch)
38
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
39
+ sitearchincludedir = $(includedir)/$(sitearch)
40
+ archincludedir = $(includedir)/$(arch)
41
+ sitearchlibdir = $(libdir)/$(sitearch)
42
+ archlibdir = $(libdir)/$(arch)
43
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
44
+ mandir = $(datarootdir)/man
45
+ localedir = $(datarootdir)/locale
46
+ libdir = $(exec_prefix)/lib
47
+ psdir = $(docdir)
48
+ pdfdir = $(docdir)
49
+ dvidir = $(docdir)
50
+ htmldir = $(docdir)
51
+ infodir = $(datarootdir)/info
52
+ docdir = $(datarootdir)/doc/$(PACKAGE)
53
+ oldincludedir = $(DESTDIR)/usr/include
54
+ includedir = $(prefix)/include
55
+ localstatedir = $(prefix)/var
56
+ sharedstatedir = $(prefix)/com
57
+ sysconfdir = $(prefix)/etc
58
+ datadir = $(datarootdir)
59
+ datarootdir = $(prefix)/share
60
+ libexecdir = $(exec_prefix)/libexec
61
+ sbindir = $(exec_prefix)/sbin
62
+ bindir = $(exec_prefix)/bin
63
+ archdir = $(rubyarchdir)
64
+
65
+
66
+ CC = gcc
67
+ CXX = g++
68
+ LIBRUBY = $(LIBRUBY_A)
69
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
70
+ LIBRUBYARG_SHARED = -Wl,-rpath,$(libdir) -L$(libdir)
71
+ LIBRUBYARG_STATIC = -Wl,-rpath,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static
72
+ empty =
73
+ OUTFLAG = -o $(empty)
74
+ COUTFLAG = -o $(empty)
75
+ CSRCFLAG = $(empty)
76
+
77
+ RUBY_EXTCONF_H =
78
+ cflags = $(optflags) $(debugflags) $(warnflags)
79
+ cxxflags = $(optflags) $(debugflags) $(warnflags)
80
+ optflags = -O3
81
+ debugflags = -ggdb3
82
+ warnflags = -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wno-maybe-uninitialized
83
+ CCDLFLAGS = -fPIC
84
+ CFLAGS = $(CCDLFLAGS) $(cflags) $(ARCH_FLAG)
85
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
86
+ DEFS =
87
+ CPPFLAGS = -I/home/ootoro/.rbenv/versions/2.5.1/include $(DEFS) $(cppflags)
88
+ CXXFLAGS = $(CCDLFLAGS) $(cxxflags) $(ARCH_FLAG)
89
+ ldflags = -L. -L/home/ootoro/.rbenv/versions/2.5.1/lib -fstack-protector -rdynamic -Wl,-export-dynamic
90
+ dldflags = -L/home/ootoro/.rbenv/versions/2.5.1/lib -Wl,--compress-debug-sections=zlib
91
+ ARCH_FLAG =
92
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
93
+ LDSHARED = $(CC) -shared
94
+ LDSHAREDXX = $(CXX) -shared
95
+ AR = ar
96
+ EXEEXT =
97
+
98
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
99
+ RUBY_SO_NAME = ruby
100
+ RUBYW_INSTALL_NAME =
101
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
102
+ RUBYW_BASE_NAME = rubyw
103
+ RUBY_BASE_NAME = ruby
104
+
105
+ arch = x86_64-linux
106
+ sitearch = $(arch)
107
+ ruby_version = 2.5.0
108
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
109
+ RUBY = $(ruby)
110
+ ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
111
+
112
+ RM = rm -f
113
+ RM_RF = $(RUBY) -run -e rm -- -rf
114
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
115
+ MAKEDIRS = /bin/mkdir -p
116
+ INSTALL = /usr/bin/install -c
117
+ INSTALL_PROG = $(INSTALL) -m 0755
118
+ INSTALL_DATA = $(INSTALL) -m 644
119
+ COPY = cp
120
+ TOUCH = exit >
121
+
122
+ #### End of system configuration section. ####
123
+
124
+ preload =
125
+ libpath = . $(libdir)
126
+ LIBPATH = -L. -L$(libdir) -Wl,-rpath,$(libdir)
127
+ DEFFILE =
128
+
129
+ CLEANFILES = mkmf.log
130
+ DISTCLEANFILES =
131
+ DISTCLEANDIRS =
132
+
133
+ extout =
134
+ extout_prefix =
135
+ target_prefix =
136
+ LOCAL_LIBS =
137
+ LIBS = -lpthread -ldl -lcrypt -lm -lc
138
+ ORIG_SRCS = mnist_ext.c
139
+ SRCS = $(ORIG_SRCS)
140
+ OBJS = mnist_ext.o
141
+ HDRS =
142
+ LOCAL_HDRS =
143
+ TARGET = mnist_ext
144
+ TARGET_NAME = mnist_ext
145
+ TARGET_ENTRY = Init_$(TARGET_NAME)
146
+ DLLIB = $(TARGET).so
147
+ EXTSTATIC =
148
+ STATIC_LIB =
149
+
150
+ TIMESTAMP_DIR = .
151
+ BINDIR = $(bindir)
152
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
153
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
154
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
155
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
156
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
157
+ TARGET_SO_DIR =
158
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
159
+ CLEANLIBS = $(TARGET_SO)
160
+ CLEANOBJS = *.o *.bak
161
+
162
+ all: $(DLLIB)
163
+ static: $(STATIC_LIB)
164
+ .PHONY: all install static install-so install-rb
165
+ .PHONY: clean clean-so clean-static clean-rb
166
+
167
+ clean-static::
168
+ clean-rb-default::
169
+ clean-rb::
170
+ clean-so::
171
+ clean: clean-so clean-static clean-rb-default clean-rb
172
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
173
+
174
+ distclean-rb-default::
175
+ distclean-rb::
176
+ distclean-so::
177
+ distclean-static::
178
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
179
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
180
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
181
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
182
+
183
+ realclean: distclean
184
+ install: install-so install-rb
185
+
186
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.time
187
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
188
+ clean-static::
189
+ -$(Q)$(RM) $(STATIC_LIB)
190
+ install-rb: pre-install-rb do-install-rb install-rb-default
191
+ install-rb-default: pre-install-rb-default do-install-rb-default
192
+ pre-install-rb: Makefile
193
+ pre-install-rb-default: Makefile
194
+ do-install-rb:
195
+ do-install-rb-default:
196
+ pre-install-rb-default:
197
+ @$(NULLCMD)
198
+ $(TIMESTAMP_DIR)/.sitearchdir.time:
199
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
200
+ $(Q) $(TOUCH) $@
201
+
202
+ site-install: site-install-so site-install-rb
203
+ site-install-so: install-so
204
+ site-install-rb: install-rb
205
+
206
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
207
+
208
+ .cc.o:
209
+ $(ECHO) compiling $(<)
210
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
211
+
212
+ .cc.S:
213
+ $(ECHO) translating $(<)
214
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
215
+
216
+ .mm.o:
217
+ $(ECHO) compiling $(<)
218
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
219
+
220
+ .mm.S:
221
+ $(ECHO) translating $(<)
222
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
223
+
224
+ .cxx.o:
225
+ $(ECHO) compiling $(<)
226
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
227
+
228
+ .cxx.S:
229
+ $(ECHO) translating $(<)
230
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
231
+
232
+ .cpp.o:
233
+ $(ECHO) compiling $(<)
234
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
235
+
236
+ .cpp.S:
237
+ $(ECHO) translating $(<)
238
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
239
+
240
+ .c.o:
241
+ $(ECHO) compiling $(<)
242
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
243
+
244
+ .c.S:
245
+ $(ECHO) translating $(<)
246
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
247
+
248
+ .m.o:
249
+ $(ECHO) compiling $(<)
250
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
251
+
252
+ .m.S:
253
+ $(ECHO) translating $(<)
254
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
255
+
256
+ $(TARGET_SO): $(OBJS) Makefile
257
+ $(ECHO) linking shared-object $(DLLIB)
258
+ -$(Q)$(RM) $(@)
259
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
260
+
261
+
262
+
263
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("mnist_ext")
@@ -0,0 +1,49 @@
1
+ #include <ruby.h>
2
+ #include <stdlib.h>
3
+ #include "numo/narray.h"
4
+
5
+ VALUE mnist_load_images(VALUE self, VALUE rb_bin, VALUE rb_num_images, VALUE rb_cols, VALUE rb_rows) {
6
+ char* bin = StringValuePtr(rb_bin);
7
+ int num_images = FIX2INT(rb_num_images);
8
+ int cols = FIX2INT(rb_cols);
9
+ int rows = FIX2INT(rb_rows);
10
+ int i;
11
+ int j;
12
+ char script[64];
13
+ VALUE rb_na;
14
+ narray_data_t* na_data;
15
+
16
+ sprintf(script, "Numo::UInt8.zeros(%d, %d, %d)", num_images, cols, rows);
17
+ rb_na = rb_eval_string(&script[0]);
18
+ na_data = RNARRAY_DATA(rb_na);
19
+
20
+ for (i = 0; i < num_images; i++) {
21
+ j = i * cols * rows;
22
+ memcpy(&na_data->ptr[j], &bin[j], cols * rows);
23
+ }
24
+ return rb_na;
25
+ }
26
+
27
+ VALUE mnist_load_labels(VALUE self, VALUE rb_bin, VALUE rb_num_labels) {
28
+ char* bin = StringValuePtr(rb_bin);
29
+ int num_labels = FIX2INT(rb_num_labels);
30
+ char script[64];
31
+ VALUE rb_na;
32
+ narray_data_t* na_data;
33
+
34
+ sprintf(script, "Numo::UInt8.zeros(%d)", num_labels);
35
+ rb_na = rb_eval_string(&script[0]);
36
+ na_data = RNARRAY_DATA(rb_na);
37
+
38
+ memcpy(na_data->ptr, bin, num_labels);
39
+ return rb_na;
40
+ }
41
+
42
+ void Init_mnist_ext() {
43
+ VALUE rb_dnn;
44
+ VALUE rb_mnist;
45
+ rb_dnn = rb_define_module("DNN");
46
+ rb_mnist = rb_define_module_under(rb_dnn, "MNIST");
47
+ rb_define_singleton_method(rb_mnist, "_mnist_load_images", mnist_load_images, 4);
48
+ rb_define_singleton_method(rb_mnist, "_mnist_load_labels", mnist_load_labels, 2);
49
+ }
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ #ifndef COMPAT_H
2
+ #define COMPAT_H
3
+
4
+ #if !defined RSTRING_LEN
5
+ #define RSTRING_LEN(a) RSTRING(a)->len
6
+ #endif
7
+ #if !defined RSTRING_PTR
8
+ #define RSTRING_PTR(a) RSTRING(a)->ptr
9
+ #endif
10
+ #if !defined RARRAY_LEN
11
+ #define RARRAY_LEN(a) RARRAY(a)->len
12
+ #endif
13
+ #if !defined RARRAY_PTR
14
+ #define RARRAY_PTR(a) RARRAY(a)->ptr
15
+ #endif
16
+ #if !defined RARRAY_AREF
17
+ #define RARRAY_AREF(a,i) RARRAY_PTR(a)[i]
18
+ #endif
19
+ #if !defined RARRAY_ASET
20
+ #define RARRAY_ASET(a,i,v) (RARRAY_PTR(a)[i] = v)
21
+ #endif
22
+
23
+ #endif /* ifndef COMPAT_H */
@@ -0,0 +1,13 @@
1
+ #ifndef NUMO_EXTCONF_H
2
+ #define NUMO_EXTCONF_H
3
+ #define HAVE_STDBOOL_H 1
4
+ #define HAVE_STDINT_H 1
5
+ #define HAVE_TYPE_BOOL 1
6
+ #define HAVE_TYPE_UINT8_T 1
7
+ #define HAVE_TYPE_UINT16_T 1
8
+ #define HAVE_TYPE_INT32_T 1
9
+ #define HAVE_TYPE_UINT32_T 1
10
+ #define HAVE_TYPE_INT64_T 1
11
+ #define HAVE_TYPE_UINT64_T 1
12
+ #define HAVE_RB_CCOMPLEX 1
13
+ #endif
@@ -0,0 +1,117 @@
1
+ /*
2
+ intern.h
3
+ Numerical Array Extension for Ruby
4
+ (C) Copyright 1999-2017 by Masahiro TANAKA
5
+ */
6
+ #ifndef INTERN_H
7
+ #define INTERN_H
8
+
9
+ #define rb_narray_new nary_new
10
+ VALUE nary_new(VALUE elem, int ndim, size_t *shape);
11
+ #define rb_narray_view_new nary_view_new
12
+ VALUE nary_view_new(VALUE elem, int ndim, size_t *shape);
13
+ #define rb_narray_debug_info nary_debug_info
14
+ VALUE nary_debug_info(VALUE);
15
+
16
+ #define na_make_view nary_make_view
17
+ VALUE nary_make_view(VALUE self);
18
+
19
+ #define na_s_allocate nary_s_allocate
20
+ VALUE nary_s_allocate(VALUE klass);
21
+ #define na_s_allocate_view nary_s_allocate_view
22
+ VALUE nary_s_allocate_view(VALUE klass);
23
+ #define na_s_new_like nary_s_new_like
24
+ VALUE nary_s_new_like(VALUE type, VALUE obj);
25
+
26
+ void na_alloc_shape(narray_t *na, int ndim);
27
+ void na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape);
28
+ void na_index_arg_to_internal_order(int argc, VALUE *argv, VALUE self);
29
+ void na_setup_shape(narray_t *na, int ndim, size_t *shape);
30
+
31
+ #define na_get_elmsz nary_element_stride
32
+ //#define na_element_stride nary_element_stride
33
+ unsigned int nary_element_stride(VALUE nary);
34
+ #define na_dtype_elmsz nary_dtype_element_stride
35
+ size_t nary_dtype_element_stride(VALUE klass);
36
+
37
+ #define na_get_pointer nary_get_pointer
38
+ char *nary_get_pointer(VALUE);
39
+ #define na_get_pointer_for_write nary_get_pointer_for_write
40
+ char *nary_get_pointer_for_write(VALUE);
41
+ #define na_get_pointer_for_read nary_get_pointer_for_read
42
+ char *nary_get_pointer_for_read(VALUE);
43
+ #define na_get_pointer_for_read_write nary_get_pointer_for_read_write
44
+ char *nary_get_pointer_for_read_write(VALUE);
45
+ #define na_get_offset nary_get_offset
46
+ size_t nary_get_offset(VALUE self);
47
+
48
+ #define na_copy_flags nary_copy_flags
49
+ void nary_copy_flags(VALUE src, VALUE dst);
50
+
51
+ #define na_check_ladder nary_check_ladder
52
+ VALUE nary_check_ladder(VALUE self, int start_dim);
53
+ #define na_check_contiguous nary_check_contiguous
54
+ VALUE nary_check_contiguous(VALUE self);
55
+
56
+ #define na_flatten_dim nary_flatten_dim
57
+ VALUE nary_flatten_dim(VALUE self, int sd);
58
+
59
+ #define na_flatten nary_flatten
60
+ VALUE nary_flatten(VALUE);
61
+
62
+ #define na_copy nary_dup
63
+ VALUE nary_dup(VALUE);
64
+
65
+ #define na_store nary_store
66
+ VALUE nary_store(VALUE self, VALUE src);
67
+
68
+ #define na_upcast numo_na_upcast
69
+ VALUE numo_na_upcast(VALUE type1, VALUE type2);
70
+
71
+ void na_release_lock(VALUE); // currently do nothing
72
+
73
+ // used in reduce methods
74
+ #define na_reduce_dimension nary_reduce_dimension
75
+ VALUE nary_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv,
76
+ ndfunc_t *ndf, na_iter_func_t nan_iter);
77
+
78
+ #define na_reduce_options nary_reduce_options
79
+ VALUE nary_reduce_options(VALUE axes, VALUE *opts, int naryc, VALUE *naryv,
80
+ ndfunc_t *ndf);
81
+
82
+ // ndloop
83
+ VALUE na_ndloop(ndfunc_t *nf, int argc, ...);
84
+ VALUE na_ndloop2(ndfunc_t *nf, VALUE args);
85
+ VALUE na_ndloop3(ndfunc_t *nf, void *ptr, int argc, ...);
86
+ VALUE na_ndloop4(ndfunc_t *nf, void *ptr, VALUE args);
87
+
88
+ VALUE na_ndloop_cast_narray_to_rarray(ndfunc_t *nf, VALUE nary, VALUE fmt);
89
+ VALUE na_ndloop_store_rarray(ndfunc_t *nf, VALUE nary, VALUE rary);
90
+ VALUE na_ndloop_store_rarray2(ndfunc_t *nf, VALUE nary, VALUE rary, VALUE opt);
91
+ VALUE na_ndloop_inspect(VALUE nary, na_text_func_t func, VALUE opt);
92
+ VALUE na_ndloop_with_index(ndfunc_t *nf, int argc, ...);
93
+
94
+ #define na_info_str nary_info_str
95
+ VALUE nary_info_str(VALUE);
96
+
97
+ #define na_test_reduce nary_test_reduce
98
+ bool nary_test_reduce(VALUE reduce, int dim);
99
+
100
+ void nary_step_array_index(VALUE self, size_t ary_size, size_t *plen, ssize_t *pbeg, ssize_t *pstep);
101
+ void nary_step_sequence(VALUE self, size_t *plen, double *pbeg, double *pstep);
102
+
103
+ // used in aref, aset
104
+ #define na_get_result_dimension nary_get_result_dimension
105
+ int nary_get_result_dimension(VALUE self, int argc, VALUE *argv, ssize_t stride, size_t *pos_idx);
106
+ #define na_aref_main nary_aref_main
107
+ VALUE nary_aref_main(int nidx, VALUE *idx, VALUE self, int keep_dim, int nd);
108
+
109
+ #include "ruby/version.h"
110
+
111
+ #if RUBY_API_VERSION_CODE == 20100 // 2.1.0
112
+ int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *);
113
+ VALUE rb_extract_keywords(VALUE *orighash);
114
+ #endif
115
+
116
+
117
+ #endif /* ifndef INTERN_H */