cumo 0.4.3 → 0.5.0
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 +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +1272 -0
- data/3rd_party/mkmf-cu/Gemfile +2 -0
- data/3rd_party/mkmf-cu/Rakefile +2 -1
- data/3rd_party/mkmf-cu/bin/mkmf-cu-nvcc +2 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +36 -7
- data/3rd_party/mkmf-cu/lib/mkmf-cu/nvcc.rb +51 -45
- data/3rd_party/mkmf-cu/lib/mkmf-cu.rb +2 -0
- data/3rd_party/mkmf-cu/mkmf-cu.gemspec +3 -1
- data/3rd_party/mkmf-cu/test/test_mkmf-cu.rb +5 -3
- data/CHANGELOG.md +69 -0
- data/Gemfile +6 -1
- data/README.md +2 -10
- data/Rakefile +8 -11
- data/bench/broadcast_fp32.rb +28 -26
- data/bench/cumo_bench.rb +18 -16
- data/bench/numo_bench.rb +18 -16
- data/bench/reduction_fp32.rb +14 -12
- data/bin/console +1 -0
- data/cumo.gemspec +5 -8
- data/ext/cumo/cuda/cudnn.c +2 -2
- data/ext/cumo/cumo.c +7 -3
- data/ext/cumo/depend.erb +15 -13
- data/ext/cumo/extconf.rb +32 -46
- data/ext/cumo/include/cumo/cuda/cudnn.h +3 -1
- data/ext/cumo/include/cumo/intern.h +1 -0
- data/ext/cumo/include/cumo/narray.h +13 -1
- data/ext/cumo/include/cumo/template.h +2 -4
- data/ext/cumo/include/cumo/types/complex_macro.h +1 -1
- data/ext/cumo/include/cumo/types/float_macro.h +2 -2
- data/ext/cumo/include/cumo/types/xint_macro.h +3 -2
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/narray/array.c +3 -3
- data/ext/cumo/narray/data.c +23 -2
- data/ext/cumo/narray/gen/cogen.rb +8 -7
- data/ext/cumo/narray/gen/cogen_kernel.rb +8 -7
- data/ext/cumo/narray/gen/def/bit.rb +3 -1
- data/ext/cumo/narray/gen/def/dcomplex.rb +2 -0
- data/ext/cumo/narray/gen/def/dfloat.rb +2 -0
- data/ext/cumo/narray/gen/def/int16.rb +2 -0
- data/ext/cumo/narray/gen/def/int32.rb +2 -0
- data/ext/cumo/narray/gen/def/int64.rb +2 -0
- data/ext/cumo/narray/gen/def/int8.rb +2 -0
- data/ext/cumo/narray/gen/def/robject.rb +2 -0
- data/ext/cumo/narray/gen/def/scomplex.rb +2 -0
- data/ext/cumo/narray/gen/def/sfloat.rb +2 -0
- data/ext/cumo/narray/gen/def/uint16.rb +2 -0
- data/ext/cumo/narray/gen/def/uint32.rb +2 -0
- data/ext/cumo/narray/gen/def/uint64.rb +2 -0
- data/ext/cumo/narray/gen/def/uint8.rb +2 -0
- data/ext/cumo/narray/gen/erbln.rb +9 -7
- data/ext/cumo/narray/gen/erbpp2.rb +26 -24
- data/ext/cumo/narray/gen/narray_def.rb +13 -11
- data/ext/cumo/narray/gen/spec.rb +58 -55
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +1 -1
- data/ext/cumo/narray/gen/tmpl/at.c +34 -0
- data/ext/cumo/narray/gen/tmpl/batch_norm.c +1 -1
- data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +2 -2
- data/ext/cumo/narray/gen/tmpl/conv.c +1 -1
- data/ext/cumo/narray/gen/tmpl/conv_grad_w.c +3 -1
- data/ext/cumo/narray/gen/tmpl/conv_transpose.c +1 -1
- data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +1 -1
- data/ext/cumo/narray/gen/tmpl/init_class.c +1 -0
- data/ext/cumo/narray/gen/tmpl/pooling_backward.c +1 -1
- data/ext/cumo/narray/gen/tmpl/pooling_forward.c +1 -1
- data/ext/cumo/narray/gen/tmpl/qsort.c +1 -5
- data/ext/cumo/narray/gen/tmpl/sort.c +1 -1
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +42 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +5 -0
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +27 -7
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +21 -7
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +21 -7
- data/ext/cumo/narray/index.c +243 -39
- data/ext/cumo/narray/index_kernel.cu +84 -0
- data/ext/cumo/narray/narray.c +38 -1
- data/ext/cumo/narray/ndloop.c +1 -1
- data/ext/cumo/narray/struct.c +1 -1
- data/lib/cumo/cuda/compile_error.rb +1 -1
- data/lib/cumo/cuda/compiler.rb +23 -22
- data/lib/cumo/cuda/cudnn.rb +1 -1
- data/lib/cumo/cuda/device.rb +1 -1
- data/lib/cumo/cuda/link_state.rb +2 -2
- data/lib/cumo/cuda/module.rb +1 -2
- data/lib/cumo/cuda/nvrtc_program.rb +3 -2
- data/lib/cumo/cuda.rb +2 -0
- data/lib/cumo/linalg.rb +2 -0
- data/lib/cumo/narray/extra.rb +137 -185
- data/lib/cumo/narray.rb +2 -0
- data/lib/cumo.rb +3 -1
- data/test/bit_test.rb +157 -0
- data/test/cuda/compiler_test.rb +69 -0
- data/test/cuda/device_test.rb +30 -0
- data/test/cuda/memory_pool_test.rb +45 -0
- data/test/cuda/nvrtc_test.rb +51 -0
- data/test/cuda/runtime_test.rb +28 -0
- data/test/cudnn_test.rb +498 -0
- data/test/cumo_test.rb +27 -0
- data/test/narray_test.rb +745 -0
- data/test/ractor_test.rb +52 -0
- data/test/test_helper.rb +31 -0
- metadata +31 -54
- data/.travis.yml +0 -5
- data/numo-narray-version +0 -1
|
@@ -117,7 +117,7 @@ static inline dtype c_from_dcomplex(cumo_dcomplex x) {
|
|
|
117
117
|
#define m_acosh(x) c_acosh(x)
|
|
118
118
|
#define m_atanh(x) c_atanh(x)
|
|
119
119
|
#define m_hypot(x,y) c_hypot(x,y)
|
|
120
|
-
#define m_sinc(x) c_div(c_sin(x),x)
|
|
120
|
+
#define m_sinc(x) ((REAL(x)==0 && IMAG(x)==0) ? (c_new(1,0)):(c_div(c_sin(x),x)))
|
|
121
121
|
|
|
122
122
|
#define m_sum_init INT2FIX(0)
|
|
123
123
|
#define m_mulsum_init INT2FIX(0)
|
|
@@ -12,7 +12,7 @@ extern double pow(double, double);
|
|
|
12
12
|
#define m_zero 0.0
|
|
13
13
|
#define m_one 1.0
|
|
14
14
|
|
|
15
|
-
#define m_num_to_data(x) NUM2DBL(x)
|
|
15
|
+
#define m_num_to_data(x) (NIL_P(x) ? nan("") : NUM2DBL(x))
|
|
16
16
|
#define m_data_to_num(x) rb_float_new(x)
|
|
17
17
|
|
|
18
18
|
#define m_from_double(x) (x)
|
|
@@ -110,7 +110,7 @@ extern double pow(double, double);
|
|
|
110
110
|
#define m_atanh(x) atanh(x)
|
|
111
111
|
#define m_atan2(x,y) atan2(x,y)
|
|
112
112
|
#define m_hypot(x,y) hypot(x,y)
|
|
113
|
-
#define m_sinc(x) (sin(x)/(x))
|
|
113
|
+
#define m_sinc(x) (((x)==0) ? 1.0:(sin(x)/(x)))
|
|
114
114
|
|
|
115
115
|
#define m_erf(x) erf(x)
|
|
116
116
|
#define m_erfc(x) erfc(x)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#define m_zero 0
|
|
2
2
|
#define m_one 1
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
#define
|
|
4
|
+
/* Handle negative values consistently across platforms for unsigned integer types */
|
|
5
|
+
#define m_from_double(x) ((x) < 0 ? (dtype)((long long)(x)) : (dtype)(x))
|
|
6
|
+
#define m_from_real(x) ((x) < 0 ? (dtype)((long long)(x)) : (dtype)(x))
|
|
6
7
|
#define m_from_sint(x) (x)
|
|
7
8
|
#define m_from_int32(x) (x)
|
|
8
9
|
#define m_from_int64(x) (x)
|
data/ext/cumo/include/cumo.h
CHANGED
data/ext/cumo/narray/array.c
CHANGED
|
@@ -366,7 +366,7 @@ cumo_na_composition3_ary(VALUE ary, VALUE *ptype, VALUE *pshape, VALUE *pnary)
|
|
|
366
366
|
VALUE dtype, dshape;
|
|
367
367
|
|
|
368
368
|
mdai = cumo_na_mdai_alloc(ary);
|
|
369
|
-
vmdai = TypedData_Wrap_Struct(
|
|
369
|
+
vmdai = TypedData_Wrap_Struct(rb_cObject, &mdai_data_type, (void*)mdai);
|
|
370
370
|
if ( cumo_na_mdai_investigate(mdai, 1) ) {
|
|
371
371
|
// empty
|
|
372
372
|
dtype = update_type(ptype, cumo_cInt32);
|
|
@@ -612,7 +612,7 @@ cumo_na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
|
|
|
612
612
|
|
|
613
613
|
mdai = cumo_na_mdai_alloc(ary);
|
|
614
614
|
mdai->na_type = nstruct;
|
|
615
|
-
vmdai = TypedData_Wrap_Struct(
|
|
615
|
+
vmdai = TypedData_Wrap_Struct(rb_cObject, &mdai_data_type, (void*)mdai);
|
|
616
616
|
cumo_na_mdai_for_struct(mdai, 0);
|
|
617
617
|
nc = cumo_na_compose_alloc();
|
|
618
618
|
vnc = WrapCompose(nc);
|
|
@@ -626,7 +626,7 @@ cumo_na_ary_composition_for_struct(VALUE nstruct, VALUE ary)
|
|
|
626
626
|
|
|
627
627
|
|
|
628
628
|
void
|
|
629
|
-
Init_cumo_na_array()
|
|
629
|
+
Init_cumo_na_array(void)
|
|
630
630
|
{
|
|
631
631
|
rb_define_singleton_method(cNArray, "array_shape", cumo_na_s_array_shape, 1);
|
|
632
632
|
rb_define_singleton_method(cNArray, "array_type", cumo_na_s_array_type, 1);
|
data/ext/cumo/narray/data.c
CHANGED
|
@@ -402,6 +402,10 @@ cumo_na_reshape_bang(int argc, VALUE *argv, VALUE self)
|
|
|
402
402
|
{
|
|
403
403
|
size_t *shape;
|
|
404
404
|
cumo_narray_t *na;
|
|
405
|
+
cumo_narray_view_t *na2;
|
|
406
|
+
ssize_t stride;
|
|
407
|
+
cumo_stridx_t *stridx;
|
|
408
|
+
int i;
|
|
405
409
|
|
|
406
410
|
if (cumo_na_check_contiguous(self)==Qfalse) {
|
|
407
411
|
rb_raise(rb_eStandardError, "cannot change shape of non-contiguous NArray");
|
|
@@ -410,6 +414,23 @@ cumo_na_reshape_bang(int argc, VALUE *argv, VALUE self)
|
|
|
410
414
|
cumo_na_check_reshape(argc, argv, self, shape);
|
|
411
415
|
|
|
412
416
|
CumoGetNArray(self, na);
|
|
417
|
+
if (na->type == CUMO_NARRAY_VIEW_T) {
|
|
418
|
+
CumoGetNArrayView(self, na2);
|
|
419
|
+
if (na->ndim < argc) {
|
|
420
|
+
stridx = ALLOC_N(cumo_stridx_t,argc);
|
|
421
|
+
} else {
|
|
422
|
+
stridx = na2->stridx;
|
|
423
|
+
}
|
|
424
|
+
stride = CUMO_SDX_GET_STRIDE(na2->stridx[na->ndim-1]);
|
|
425
|
+
for (i=argc; i--;) {
|
|
426
|
+
CUMO_SDX_SET_STRIDE(stridx[i],stride);
|
|
427
|
+
stride *= shape[i];
|
|
428
|
+
}
|
|
429
|
+
if (stridx != na2->stridx) {
|
|
430
|
+
xfree(na2->stridx);
|
|
431
|
+
na2->stridx = stridx;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
413
434
|
cumo_na_setup_shape(na, argc, shape);
|
|
414
435
|
return self;
|
|
415
436
|
}
|
|
@@ -457,7 +478,7 @@ cumo_na_flatten_dim(VALUE self, int sd)
|
|
|
457
478
|
CumoGetNArray(self,na);
|
|
458
479
|
nd = na->ndim;
|
|
459
480
|
|
|
460
|
-
|
|
481
|
+
if (nd==0 || na->size==0) {
|
|
461
482
|
return cumo_na_make_view(self);
|
|
462
483
|
}
|
|
463
484
|
if (sd<0 || sd>=nd) {
|
|
@@ -940,7 +961,7 @@ cumo_na_dot(VALUE self, VALUE other)
|
|
|
940
961
|
#endif
|
|
941
962
|
|
|
942
963
|
void
|
|
943
|
-
Init_cumo_na_data()
|
|
964
|
+
Init_cumo_na_data(void)
|
|
944
965
|
{
|
|
945
966
|
rb_define_method(cNArray, "copy", cumo_na_copy, 0); // deprecated
|
|
946
967
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
thisdir = File.dirname(__FILE__)
|
|
4
|
-
libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
|
|
5
|
+
libpath = File.absolute_path(File.dirname(__FILE__)) + "/../../../../lib"
|
|
5
6
|
$LOAD_PATH.unshift libpath
|
|
6
7
|
|
|
7
8
|
require_relative "narray_def"
|
|
@@ -28,11 +29,11 @@ if ARGV.size != 1
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
type_file, = ARGV
|
|
31
|
-
type_name = File.basename(type_file,".rb")
|
|
32
|
+
type_name = File.basename(type_file, ".rb")
|
|
32
33
|
|
|
33
34
|
erb_dir = ["tmpl"]
|
|
34
35
|
erb_dir.unshift("tmpl_bit") if (type_name == "bit")
|
|
35
|
-
erb_dir.map!{|d| File.join(thisdir,d)}
|
|
36
|
+
erb_dir.map! { |d| File.join(thisdir, d) }
|
|
36
37
|
|
|
37
38
|
code = DefLib.new do
|
|
38
39
|
set line_number: $line_number
|
|
@@ -40,20 +41,20 @@ code = DefLib.new do
|
|
|
40
41
|
set erb_suffix: ".c"
|
|
41
42
|
set ns_var: "mCumo"
|
|
42
43
|
|
|
43
|
-
set file_name: $output||""
|
|
44
|
+
set file_name: $output || ""
|
|
44
45
|
set type_name: type_name
|
|
45
|
-
set lib_name: "cumo_"+type_name
|
|
46
|
+
set lib_name: "cumo_" + type_name
|
|
46
47
|
|
|
47
48
|
def_class do
|
|
48
49
|
extend NArrayMethod
|
|
49
50
|
extend NArrayType
|
|
50
51
|
eval File.read(type_file), binding, type_file
|
|
51
|
-
eval File.read(File.join(thisdir,"spec.rb")), binding, "spec.rb"
|
|
52
|
+
eval File.read(File.join(thisdir, "spec.rb")), binding, "spec.rb"
|
|
52
53
|
end
|
|
53
54
|
end.result
|
|
54
55
|
|
|
55
56
|
if $output
|
|
56
|
-
open($output,"w").write(code)
|
|
57
|
+
open($output, "w").write(code)
|
|
57
58
|
else
|
|
58
59
|
$stdout.write(code)
|
|
59
60
|
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
thisdir = File.dirname(__FILE__)
|
|
4
|
-
libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
|
|
5
|
+
libpath = File.absolute_path(File.dirname(__FILE__)) + "/../../../../lib"
|
|
5
6
|
$LOAD_PATH.unshift libpath
|
|
6
7
|
|
|
7
8
|
require_relative "narray_def"
|
|
@@ -28,11 +29,11 @@ if ARGV.size != 1
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
type_file, = ARGV
|
|
31
|
-
type_name = File.basename(type_file,".rb")
|
|
32
|
+
type_name = File.basename(type_file, ".rb")
|
|
32
33
|
|
|
33
34
|
erb_dir = ["tmpl"]
|
|
34
35
|
erb_dir.unshift("tmpl_bit") if (type_name == "bit")
|
|
35
|
-
erb_dir.map!{|d| File.join(thisdir,d)}
|
|
36
|
+
erb_dir.map! { |d| File.join(thisdir, d) }
|
|
36
37
|
|
|
37
38
|
code = DefLib.new do
|
|
38
39
|
set line_number: $line_number
|
|
@@ -40,9 +41,9 @@ code = DefLib.new do
|
|
|
40
41
|
set erb_suffix: "_kernel.cu"
|
|
41
42
|
set ns_var: "mCumo"
|
|
42
43
|
|
|
43
|
-
set file_name: $output||""
|
|
44
|
+
set file_name: $output || ""
|
|
44
45
|
set type_name: type_name
|
|
45
|
-
set lib_name: "cumo_"+type_name
|
|
46
|
+
set lib_name: "cumo_" + type_name
|
|
46
47
|
|
|
47
48
|
set opt_indexer_ndim: File.read(File.expand_path("../../../include/cumo/indexer.h", __FILE__)).match(/CUMO_NA_INDEXER_OPTIMIZED_NDIM (\d+)/)[1].to_i
|
|
48
49
|
|
|
@@ -50,12 +51,12 @@ code = DefLib.new do
|
|
|
50
51
|
extend NArrayMethod
|
|
51
52
|
extend NArrayType
|
|
52
53
|
eval File.read(type_file), binding, type_file
|
|
53
|
-
eval File.read(File.join(thisdir,"spec.rb")), binding, "spec.rb"
|
|
54
|
+
eval File.read(File.join(thisdir, "spec.rb")), binding, "spec.rb"
|
|
54
55
|
end
|
|
55
56
|
end.result
|
|
56
57
|
|
|
57
58
|
if $output
|
|
58
|
-
open($output,"w").write(code)
|
|
59
|
+
open($output, "w").write(code)
|
|
59
60
|
else
|
|
60
61
|
$stdout.write(code)
|
|
61
62
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
set name: "bit"
|
|
2
4
|
set type_name: "bit"
|
|
3
5
|
set full_class_name: "Cumo::Bit"
|
|
@@ -16,7 +18,7 @@ set is_object: false
|
|
|
16
18
|
set is_real: false
|
|
17
19
|
set is_comparable: false
|
|
18
20
|
set is_double_precision: false
|
|
19
|
-
set need_align:
|
|
21
|
+
set need_align: false
|
|
20
22
|
|
|
21
23
|
upcast_rb "Integer"
|
|
22
24
|
upcast_rb "Float", "DFloat"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'erb'
|
|
2
4
|
|
|
3
5
|
class ErbPP
|
|
@@ -7,11 +9,11 @@ class ErbPP
|
|
|
7
9
|
def initialize(filename)
|
|
8
10
|
@filename = filename
|
|
9
11
|
@lnchar = "\n"
|
|
10
|
-
@buf = ""
|
|
11
|
-
@str = ""
|
|
12
|
+
@buf = +""
|
|
13
|
+
@str = +""
|
|
12
14
|
@countln = 1
|
|
13
15
|
@current = 1
|
|
14
|
-
super("\n"+report_line)
|
|
16
|
+
super("\n" + report_line)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def report_line
|
|
@@ -52,7 +54,7 @@ class ErbPP
|
|
|
52
54
|
end
|
|
53
55
|
concat(@buf)
|
|
54
56
|
|
|
55
|
-
b = @buf.gsub(/".*?(?<!\\)"/,'""')
|
|
57
|
+
b = @buf.gsub(/".*?(?<!\\)"/, '""')
|
|
56
58
|
/^.*(\/\*)(.*?)$/ =~ b
|
|
57
59
|
x = $2
|
|
58
60
|
/^.*(\*\/)(.*?)$/ =~ b
|
|
@@ -81,12 +83,12 @@ class ErbPP
|
|
|
81
83
|
|
|
82
84
|
@countln = @current + @buf.count(@lnchar)
|
|
83
85
|
@current = n
|
|
84
|
-
@buf = ""
|
|
85
|
-
@str = ""
|
|
86
|
+
@buf = +""
|
|
87
|
+
@str = +""
|
|
86
88
|
end
|
|
87
89
|
|
|
88
90
|
def d(s)
|
|
89
|
-
p [s, [x,y], r]
|
|
91
|
+
p [s, [x, y], r]
|
|
90
92
|
r
|
|
91
93
|
end
|
|
92
94
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "erb"
|
|
2
4
|
require_relative "erbln"
|
|
3
5
|
|
|
@@ -38,7 +40,7 @@ class ErbPP
|
|
|
38
40
|
|
|
39
41
|
def description
|
|
40
42
|
if s = @opts[:description] || @opts[:desc]
|
|
41
|
-
s.gsub(/\@\{/,"[").gsub(/\@\}/,"]")
|
|
43
|
+
s.gsub(/\@\{/, "[").gsub(/\@\}/, "]")
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
@@ -65,7 +67,7 @@ class ErbPP
|
|
|
65
67
|
dirs = [dirs] if !dirs.kind_of?(Array)
|
|
66
68
|
dirs.each do |x|
|
|
67
69
|
Dir.glob(x).each do |dir|
|
|
68
|
-
path = File.join(dir,file)
|
|
70
|
+
path = File.join(dir, file)
|
|
69
71
|
if File.exist?(path)
|
|
70
72
|
if get(:line_number)
|
|
71
73
|
erb = ERBLN.new(File.read(path), path, trim_mode)
|
|
@@ -100,7 +102,7 @@ class ErbPP
|
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
def write(output)
|
|
103
|
-
File.open(output,"wt") do |f|
|
|
105
|
+
File.open(output, "wt") do |f|
|
|
104
106
|
f.print(result)
|
|
105
107
|
end
|
|
106
108
|
end
|
|
@@ -109,11 +111,11 @@ class ErbPP
|
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
def find_tmpl(name)
|
|
112
|
-
@parent.children.find{|x| x.name == name }
|
|
114
|
+
@parent.children.find { |x| x.name == name }
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
def find(name)
|
|
116
|
-
children.find{|x| x.name == name }
|
|
118
|
+
children.find { |x| x.name == name }
|
|
117
119
|
end
|
|
118
120
|
end
|
|
119
121
|
|
|
@@ -126,13 +128,13 @@ class DefLib < ErbPP
|
|
|
126
128
|
end
|
|
127
129
|
def cumo_id_assign
|
|
128
130
|
ids = []
|
|
129
|
-
@children.each{|c| a=c.get(:cumo_id_list); ids.concat(a) if a}
|
|
130
|
-
ids.sort.uniq.map{|x| "cumo_id_#{x[1]} = rb_intern(\"#{x[0]}\");"}
|
|
131
|
+
@children.each { |c| a = c.get(:cumo_id_list); ids.concat(a) if a }
|
|
132
|
+
ids.sort.uniq.map { |x| "cumo_id_#{x[1]} = rb_intern(\"#{x[0]}\");" }
|
|
131
133
|
end
|
|
132
134
|
def cumo_id_decl
|
|
133
135
|
ids = []
|
|
134
|
-
@children.each{|c| a=c.get(:cumo_id_list); ids.concat(a) if a}
|
|
135
|
-
ids.sort.uniq.map{|x| "static ID cumo_id_#{x[1]};\n"}
|
|
136
|
+
@children.each { |c| a = c.get(:cumo_id_list); ids.concat(a) if a }
|
|
137
|
+
ids.sort.uniq.map { |x| "static ID cumo_id_#{x[1]};\n" }
|
|
136
138
|
end
|
|
137
139
|
def def_class(**opts, &block)
|
|
138
140
|
DefClass.new(self, **opts, &block)
|
|
@@ -144,25 +146,25 @@ end
|
|
|
144
146
|
|
|
145
147
|
module DeclMethod
|
|
146
148
|
def def_alloc_func(m, erb_path=nil, **opts, &block)
|
|
147
|
-
DefAllocFunc.new(self, erb_path||m, name:m, singleton:true, **opts, &block)
|
|
149
|
+
DefAllocFunc.new(self, erb_path || m, name:m, singleton:true, **opts, &block)
|
|
148
150
|
end
|
|
149
151
|
def undef_alloc_func
|
|
150
152
|
UndefAllocFunc.new(self)
|
|
151
153
|
end
|
|
152
154
|
def def_method(m, erb_path=nil, **opts, &block)
|
|
153
|
-
DefMethod.new(self, erb_path||m, name:m, **opts, &block)
|
|
155
|
+
DefMethod.new(self, erb_path || m, name:m, **opts, &block)
|
|
154
156
|
end
|
|
155
157
|
def undef_method(m)
|
|
156
|
-
UndefMethod.new(self,name:m)
|
|
158
|
+
UndefMethod.new(self, name:m)
|
|
157
159
|
end
|
|
158
160
|
def def_singleton_method(m, erb_path=nil, **opts, &block)
|
|
159
|
-
DefMethod.new(self, erb_path||m, name:m, singleton:true, **opts, &block)
|
|
161
|
+
DefMethod.new(self, erb_path || m, name:m, singleton:true, **opts, &block)
|
|
160
162
|
end
|
|
161
163
|
def undef_singleton_method(m)
|
|
162
|
-
UndefSingletonMethod.new(self,name:m)
|
|
164
|
+
UndefSingletonMethod.new(self, name:m)
|
|
163
165
|
end
|
|
164
166
|
def def_module_function(m, erb_path=nil, **opts, &block)
|
|
165
|
-
DefModuleFunction.new(self, erb_path||m, name:m, **opts, &block)
|
|
167
|
+
DefModuleFunction.new(self, erb_path || m, name:m, **opts, &block)
|
|
166
168
|
end
|
|
167
169
|
def def_alias(from, to)
|
|
168
170
|
DefAlias.new(self, from:from, to:to)
|
|
@@ -181,9 +183,9 @@ class DefModule < ErbPP
|
|
|
181
183
|
def cumo_id_list
|
|
182
184
|
@cumo_id_list ||= []
|
|
183
185
|
end
|
|
184
|
-
def def_id(name,var=nil)
|
|
185
|
-
var = name.gsub(/\?/,"_p").gsub(/\!/,"_bang") if var.nil?
|
|
186
|
-
cumo_id_list << [name,var]
|
|
186
|
+
def def_id(name, var=nil)
|
|
187
|
+
var = name.gsub(/\?/, "_p").gsub(/\!/, "_bang") if var.nil?
|
|
188
|
+
cumo_id_list << [name, var]
|
|
187
189
|
end
|
|
188
190
|
def init_def
|
|
189
191
|
load_erb(init_erb).result(binding)
|
|
@@ -192,7 +194,7 @@ class DefModule < ErbPP
|
|
|
192
194
|
@opts[:init_erb] || "init_module"
|
|
193
195
|
end
|
|
194
196
|
def method_code
|
|
195
|
-
@children.map{|c| c.result}.join("\n")
|
|
197
|
+
@children.map { |c| c.result }.join("\n")
|
|
196
198
|
end
|
|
197
199
|
def _mod_var
|
|
198
200
|
@opts[:module_var]
|
|
@@ -214,7 +216,7 @@ class DefClass < DefModule
|
|
|
214
216
|
@opts[:super_class] || "rb_cObject"
|
|
215
217
|
end
|
|
216
218
|
def free_func
|
|
217
|
-
@opts[:free_func] || "gsl_"+get(:name)+"_free"
|
|
219
|
+
@opts[:free_func] || "gsl_" + get(:name) + "_free"
|
|
218
220
|
end
|
|
219
221
|
end
|
|
220
222
|
|
|
@@ -235,7 +237,7 @@ class DefMethod < ErbPP
|
|
|
235
237
|
end
|
|
236
238
|
|
|
237
239
|
def c_name
|
|
238
|
-
@opts[:name].gsub(/\?/,"_p").gsub(/\!/,"_bang").gsub(/=/,"_set")
|
|
240
|
+
@opts[:name].gsub(/\?/, "_p").gsub(/\!/, "_bang").gsub(/=/, "_set")
|
|
239
241
|
end
|
|
240
242
|
|
|
241
243
|
def op_map
|
|
@@ -318,7 +320,7 @@ end
|
|
|
318
320
|
|
|
319
321
|
class DefError < ErbPP
|
|
320
322
|
def initialize(parent, name, sup_var, **opts, &block)
|
|
321
|
-
super(parent, error_name:name, error_var:"e"+name, super_var:sup_var,
|
|
323
|
+
super(parent, error_name:name, error_var:"e" + name, super_var:sup_var,
|
|
322
324
|
**opts, &block)
|
|
323
325
|
end
|
|
324
326
|
def result
|
|
@@ -335,7 +337,7 @@ class DefStruct < ErbPP
|
|
|
335
337
|
"static VALUE #{class_var};"
|
|
336
338
|
end
|
|
337
339
|
def init_def
|
|
338
|
-
items = members.map{|s| "\"#{s}\""}.join(",")
|
|
340
|
+
items = members.map { |s| "\"#{s}\"" }.join(",")
|
|
339
341
|
"/*#{description}*/
|
|
340
342
|
#{class_var} = rb_struct_define(\"#{class_name}\",#{items},NULL);"
|
|
341
343
|
end
|
|
@@ -343,7 +345,7 @@ end
|
|
|
343
345
|
|
|
344
346
|
class DefInclueModule < ErbPP
|
|
345
347
|
def initialize(parent=nil, incl_class, incl_module, **opts, &block)
|
|
346
|
-
super(parent,incl_class:incl_class,incl_module:incl_module
|
|
348
|
+
super(parent, incl_class:incl_class, incl_module:incl_module, **opts, &block)
|
|
347
349
|
end
|
|
348
350
|
def init_def
|
|
349
351
|
"rb_include_module(#{get(:incl_class)}, #{get(:incl_module)});"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'erbpp2'
|
|
2
4
|
|
|
3
5
|
module NArrayMethod
|
|
@@ -27,10 +29,10 @@ module NArrayMethod
|
|
|
27
29
|
|
|
28
30
|
def set2(meth, dtype, result_class)
|
|
29
31
|
h = {dtype:dtype, result_class:result_class}
|
|
30
|
-
def_method(meth, "set2", h)
|
|
32
|
+
def_method(meth, "set2", **h)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
def cond_binary(meth,op=nil)
|
|
35
|
+
def cond_binary(meth, op=nil)
|
|
34
36
|
op = meth unless op
|
|
35
37
|
def_method(meth, "cond_binary", op:op)
|
|
36
38
|
end
|
|
@@ -105,11 +107,11 @@ module NArrayType
|
|
|
105
107
|
alias tp type_name
|
|
106
108
|
|
|
107
109
|
def type_var
|
|
108
|
-
@opts[:type_var] ||= "cumo_c"+class_name
|
|
110
|
+
@opts[:type_var] ||= "cumo_c" + class_name
|
|
109
111
|
end
|
|
110
112
|
|
|
111
113
|
def math_var
|
|
112
|
-
@opts[:math_var] ||= "cumo_m"+class_name+"Math"
|
|
114
|
+
@opts[:math_var] ||= "cumo_m" + class_name + "Math"
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
def real_class_name(arg=nil)
|
|
@@ -129,7 +131,7 @@ module NArrayType
|
|
|
129
131
|
end
|
|
130
132
|
|
|
131
133
|
def real_type_var
|
|
132
|
-
@opts[:real_type_var] ||= "cumo_c"+real_class_name
|
|
134
|
+
@opts[:real_type_var] ||= "cumo_c" + real_class_name
|
|
133
135
|
end
|
|
134
136
|
|
|
135
137
|
def real_type_name
|
|
@@ -147,7 +149,7 @@ module NArrayType
|
|
|
147
149
|
a.concat(args)
|
|
148
150
|
end
|
|
149
151
|
|
|
150
|
-
def upcast(c=nil,t=nil)
|
|
152
|
+
def upcast(c=nil, t=nil)
|
|
151
153
|
@opts[:upcast] ||= []
|
|
152
154
|
if c
|
|
153
155
|
if t
|
|
@@ -161,14 +163,14 @@ module NArrayType
|
|
|
161
163
|
end
|
|
162
164
|
end
|
|
163
165
|
|
|
164
|
-
def upcast_rb(c,t=nil)
|
|
166
|
+
def upcast_rb(c, t=nil)
|
|
165
167
|
@opts[:upcast] ||= []
|
|
166
168
|
if t
|
|
167
169
|
t = "cumo_c#{t}"
|
|
168
170
|
else
|
|
169
171
|
t = "cT"
|
|
170
172
|
end
|
|
171
|
-
if c=="Integer"
|
|
173
|
+
if c == "Integer"
|
|
172
174
|
@opts[:upcast] << "#ifdef RUBY_INTEGER_UNIFICATION"
|
|
173
175
|
@opts[:upcast] << "rb_hash_aset(hCast, rb_cInteger, #{t});"
|
|
174
176
|
@opts[:upcast] << "#else"
|
|
@@ -186,10 +188,10 @@ end
|
|
|
186
188
|
module StoreFrom
|
|
187
189
|
|
|
188
190
|
def store_from(cname, dtype=nil, macro=nil)
|
|
189
|
-
tmpl = (cname=="Bit") ? "store_bit" : "store_from"
|
|
191
|
+
tmpl = (cname == "Bit") ? "store_bit" : "store_from"
|
|
190
192
|
h = { name:cname.downcase,
|
|
191
193
|
type_name:cname,
|
|
192
|
-
type_var:"cumo_c"+cname,
|
|
194
|
+
type_var:"cumo_c" + cname,
|
|
193
195
|
dtype:dtype,
|
|
194
196
|
macro:macro }
|
|
195
197
|
Store.new(self, tmpl, **h)
|
|
@@ -229,7 +231,7 @@ class Store < DefMethod
|
|
|
229
231
|
"#{klass}==#{type_var}"
|
|
230
232
|
end
|
|
231
233
|
|
|
232
|
-
def extract_data(ptr,pos,x)
|
|
234
|
+
def extract_data(ptr, pos, x)
|
|
233
235
|
case type_name
|
|
234
236
|
when "Bit"
|
|
235
237
|
"{BIT_DIGIT b; CUMO_LOAD_BIT(#{ptr},#{pos},b); x = m_from_sint(b);}"
|