cumo 0.4.3 → 0.5.1
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 +1252 -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 +43 -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 +85 -0
- data/Dockerfile +34 -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 +6 -9
- data/docker-build.sh +4 -0
- data/docker-launch.sh +4 -0
- data/docs/src-tree.md +1 -1
- data/ext/cumo/cuda/cudnn.c +2 -2
- data/ext/cumo/cuda/cudnn_impl.cpp +25 -3
- data/ext/cumo/cuda/driver.c +8 -0
- data/ext/cumo/cumo.c +7 -3
- data/ext/cumo/depend.erb +15 -13
- data/ext/cumo/extconf.rb +33 -47
- data/ext/cumo/include/cumo/cuda/cudnn.h +3 -1
- data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +13 -6
- data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +3 -3
- 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/complex_macro_kernel.h +15 -4
- data/ext/cumo/include/cumo/types/float_macro.h +2 -2
- data/ext/cumo/include/cumo/types/real_accum_kernel.h +15 -4
- data/ext/cumo/include/cumo/types/xint_macro.h +3 -2
- data/ext/cumo/include/cumo/types/xint_macro_kernel.h +11 -3
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/narray/array.c +8 -6
- data/ext/cumo/narray/data.c +48 -28
- 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/accum.c +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +1 -1
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +1 -1
- data/ext/cumo/narray/gen/tmpl/aref.c +18 -18
- data/ext/cumo/narray/gen/tmpl/aset.c +16 -16
- data/ext/cumo/narray/gen/tmpl/at.c +34 -0
- data/ext/cumo/narray/gen/tmpl/batch_norm.c +5 -2
- data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +6 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +7 -7
- data/ext/cumo/narray/gen/tmpl/clip.c +11 -15
- 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/cum.c +1 -1
- data/ext/cumo/narray/gen/tmpl/each.c +4 -2
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +5 -2
- data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +5 -2
- data/ext/cumo/narray/gen/tmpl/init_class.c +1 -0
- data/ext/cumo/narray/gen/tmpl/logseq.c +6 -5
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +5 -6
- data/ext/cumo/narray/gen/tmpl/median.c +2 -2
- data/ext/cumo/narray/gen/tmpl/minmax.c +1 -1
- data/ext/cumo/narray/gen/tmpl/poly.c +4 -4
- 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/rand.c +8 -6
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +18 -16
- data/ext/cumo/narray/gen/tmpl/seq.c +5 -4
- data/ext/cumo/narray/gen/tmpl/sort.c +3 -3
- data/ext/cumo/narray/gen/tmpl/sort_index.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +26 -32
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +18 -30
- 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 +244 -40
- data/ext/cumo/narray/index_kernel.cu +84 -0
- data/ext/cumo/narray/narray.c +57 -19
- 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 +297 -341
- 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 +31 -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 +34 -54
- data/.travis.yml +0 -5
- data/numo-narray-version +0 -1
data/ext/cumo/narray/data.c
CHANGED
|
@@ -195,21 +195,21 @@ check_axis(int axis, int ndim)
|
|
|
195
195
|
@example
|
|
196
196
|
x = Cumo::Int32[[1,2,3]]
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
# Cumo::Int32(view)#shape=[3,1]
|
|
198
|
+
x.swapaxes(0,1)
|
|
199
|
+
# => Cumo::Int32(view)#shape=[3,1]
|
|
200
200
|
# [[1],
|
|
201
201
|
# [2],
|
|
202
202
|
# [3]]
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
# Cumo::Int32#shape=[2,2,2]
|
|
204
|
+
x = Cumo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
|
|
205
|
+
# => Cumo::Int32#shape=[2,2,2]
|
|
206
206
|
# [[[0, 1],
|
|
207
207
|
# [2, 3]],
|
|
208
208
|
# [[4, 5],
|
|
209
209
|
# [6, 7]]]
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
# Cumo::Int32(view)#shape=[2,2,2]
|
|
211
|
+
x.swapaxes(0,2)
|
|
212
|
+
# => Cumo::Int32(view)#shape=[2,2,2]
|
|
213
213
|
# [[[0, 4],
|
|
214
214
|
# [2, 6]],
|
|
215
215
|
# [[1, 5],
|
|
@@ -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) {
|
|
@@ -489,7 +510,6 @@ cumo_na_flatten_dim(VALUE self, int sd)
|
|
|
489
510
|
case CUMO_NARRAY_FILEMAP_T:
|
|
490
511
|
stride = cumo_na_element_stride(self);
|
|
491
512
|
for (i=sd+1; i--; ) {
|
|
492
|
-
//printf("data: i=%d shpae[i]=%ld stride=%ld\n",i,shape[i],stride);
|
|
493
513
|
CUMO_SDX_SET_STRIDE(na2->stridx[i],stride);
|
|
494
514
|
stride *= shape[i];
|
|
495
515
|
}
|
|
@@ -512,12 +532,10 @@ cumo_na_flatten_dim(VALUE self, int sd)
|
|
|
512
532
|
CUMO_SDX_SET_INDEX(na2->stridx[i],idx2);
|
|
513
533
|
} else {
|
|
514
534
|
na2->stridx[i] = na1->stridx[i];
|
|
515
|
-
//printf("view: i=%d stridx=%d\n",i,CUMO_SDX_GET_STRIDE(sdx));
|
|
516
535
|
}
|
|
517
536
|
}
|
|
518
537
|
// flat dimenion == last dimension
|
|
519
538
|
if (RTEST(cumo_na_check_ladder(self,sd))) {
|
|
520
|
-
//if (0) {
|
|
521
539
|
na2->stridx[sd] = na1->stridx[nd-1];
|
|
522
540
|
} else {
|
|
523
541
|
// set index
|
|
@@ -586,28 +604,30 @@ void cumo_na_diagonal_stride_index_kernel_launch(size_t *idx, ssize_t s0, size_t
|
|
|
586
604
|
@return [Cumo::NArray] diagonal view of NArray.
|
|
587
605
|
@example
|
|
588
606
|
a = Cumo::DFloat.new(4,5).seq
|
|
589
|
-
=> Cumo::DFloat#shape=[4,5]
|
|
590
|
-
[[0, 1, 2, 3, 4],
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
607
|
+
# => Cumo::DFloat#shape=[4,5]
|
|
608
|
+
# [[0, 1, 2, 3, 4],
|
|
609
|
+
# [5, 6, 7, 8, 9],
|
|
610
|
+
# [10, 11, 12, 13, 14],
|
|
611
|
+
# [15, 16, 17, 18, 19]]
|
|
594
612
|
b = a.diagonal(1)
|
|
595
|
-
=> Cumo::DFloat(view)#shape=[4]
|
|
596
|
-
[1, 7, 13, 19]
|
|
613
|
+
# => Cumo::DFloat(view)#shape=[4]
|
|
614
|
+
# [1, 7, 13, 19]
|
|
615
|
+
|
|
597
616
|
b.store(0)
|
|
598
617
|
a
|
|
599
|
-
=> Cumo::DFloat#shape=[4,5]
|
|
600
|
-
[[0, 0, 2, 3, 4],
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
618
|
+
# => Cumo::DFloat#shape=[4,5]
|
|
619
|
+
# [[0, 0, 2, 3, 4],
|
|
620
|
+
# [5, 6, 0, 8, 9],
|
|
621
|
+
# [10, 11, 12, 0, 14],
|
|
622
|
+
# [15, 16, 17, 18, 0]]
|
|
623
|
+
|
|
604
624
|
b.store([1,2,3,4])
|
|
605
625
|
a
|
|
606
|
-
=> Cumo::DFloat#shape=[4,5]
|
|
607
|
-
[[0, 1, 2, 3, 4],
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
626
|
+
# => Cumo::DFloat#shape=[4,5]
|
|
627
|
+
# [[0, 1, 2, 3, 4],
|
|
628
|
+
# [5, 6, 2, 8, 9],
|
|
629
|
+
# [10, 11, 12, 3, 14],
|
|
630
|
+
# [15, 16, 17, 18, 4]]
|
|
611
631
|
*/
|
|
612
632
|
static VALUE
|
|
613
633
|
cumo_na_diagonal(int argc, VALUE *argv, VALUE self)
|
|
@@ -940,7 +960,7 @@ cumo_na_dot(VALUE self, VALUE other)
|
|
|
940
960
|
#endif
|
|
941
961
|
|
|
942
962
|
void
|
|
943
|
-
Init_cumo_na_data()
|
|
963
|
+
Init_cumo_na_data(void)
|
|
944
964
|
{
|
|
945
965
|
rb_define_method(cNArray, "copy", cumo_na_copy, 0); // deprecated
|
|
946
966
|
|
|
@@ -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);}"
|