cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
data/ext/cumo/narray/math.c
CHANGED
@@ -4,24 +4,24 @@
|
|
4
4
|
VALUE cumo_mNMath;
|
5
5
|
extern VALUE cumo_mDFloatMath, cumo_mDComplexMath;
|
6
6
|
extern VALUE cumo_mSFloatMath, cumo_mSComplexMath;
|
7
|
-
static ID
|
8
|
-
static ID
|
9
|
-
static ID
|
10
|
-
static ID
|
7
|
+
static ID cumo_id_send;
|
8
|
+
static ID cumo_id_UPCAST;
|
9
|
+
static ID cumo_id_DISPATCH;
|
10
|
+
static ID cumo_id_extract;
|
11
11
|
|
12
12
|
static VALUE
|
13
|
-
|
13
|
+
cumo_na_type_s_upcast(VALUE type1, VALUE type2)
|
14
14
|
{
|
15
15
|
VALUE upcast_hash;
|
16
16
|
VALUE result_type;
|
17
17
|
|
18
18
|
if (type1==type2) return type1;
|
19
|
-
upcast_hash = rb_const_get(type1,
|
19
|
+
upcast_hash = rb_const_get(type1, cumo_id_UPCAST);
|
20
20
|
result_type = rb_hash_aref(upcast_hash, type2);
|
21
21
|
if (NIL_P(result_type)) {
|
22
22
|
if (TYPE(type2)==T_CLASS) {
|
23
23
|
if ( RTEST(rb_class_inherited_p(type2,cNArray)) ) {
|
24
|
-
upcast_hash = rb_const_get(type2,
|
24
|
+
upcast_hash = rb_const_get(type2, cumo_id_UPCAST);
|
25
25
|
result_type = rb_hash_aref(upcast_hash, type1);
|
26
26
|
}
|
27
27
|
}
|
@@ -30,13 +30,13 @@ nary_type_s_upcast(VALUE type1, VALUE type2)
|
|
30
30
|
}
|
31
31
|
|
32
32
|
|
33
|
-
static VALUE
|
33
|
+
static VALUE cumo_na_math_cast2(VALUE type1, VALUE type2)
|
34
34
|
{
|
35
35
|
if ( RTEST(rb_class_inherited_p( type1, cNArray )) ){
|
36
|
-
return
|
36
|
+
return cumo_na_type_s_upcast( type1, type2 );
|
37
37
|
}
|
38
38
|
if ( RTEST(rb_class_inherited_p( type2, cNArray )) ){
|
39
|
-
return
|
39
|
+
return cumo_na_type_s_upcast( type2, type1 );
|
40
40
|
}
|
41
41
|
if ( RTEST(rb_class_inherited_p( type1, rb_cNumeric )) &&
|
42
42
|
RTEST(rb_class_inherited_p( type2, rb_cNumeric )) ){
|
@@ -50,17 +50,17 @@ static VALUE nary_math_cast2(VALUE type1, VALUE type2)
|
|
50
50
|
}
|
51
51
|
|
52
52
|
|
53
|
-
VALUE
|
53
|
+
VALUE cumo_na_ary_composition_dtype(VALUE);
|
54
54
|
|
55
|
-
static VALUE
|
55
|
+
static VALUE cumo_na_mathcast(int argc, VALUE *argv)
|
56
56
|
{
|
57
57
|
VALUE type, type2;
|
58
58
|
int i;
|
59
59
|
|
60
|
-
type =
|
60
|
+
type = cumo_na_ary_composition_dtype(argv[0]);
|
61
61
|
for (i=1; i<argc; i++) {
|
62
|
-
type2 =
|
63
|
-
type =
|
62
|
+
type2 = cumo_na_ary_composition_dtype(argv[i]);
|
63
|
+
type = cumo_na_math_cast2(type, type2);
|
64
64
|
if (NIL_P(type)) {
|
65
65
|
rb_raise(rb_eTypeError,"includes unknown DataType for upcast");
|
66
66
|
}
|
@@ -77,24 +77,24 @@ static VALUE nary_mathcast(int argc, VALUE *argv)
|
|
77
77
|
@param [NArray,Numeric] x input array.
|
78
78
|
@return [NArray] result.
|
79
79
|
*/
|
80
|
-
static VALUE
|
80
|
+
static VALUE cumo_na_math_method_missing(int argc, VALUE *argv, VALUE mod)
|
81
81
|
{
|
82
82
|
VALUE type, ans, typemod, hash;
|
83
83
|
if (argc>1) {
|
84
|
-
type =
|
84
|
+
type = cumo_na_mathcast(argc-1,argv+1);
|
85
85
|
|
86
|
-
hash = rb_const_get(mod,
|
86
|
+
hash = rb_const_get(mod, cumo_id_DISPATCH);
|
87
87
|
typemod = rb_hash_aref( hash, type );
|
88
88
|
if (NIL_P(typemod)) {
|
89
89
|
rb_raise(rb_eTypeError,"%s is unknown for Cumo::NMath",
|
90
90
|
rb_class2name(type));
|
91
91
|
}
|
92
92
|
|
93
|
-
ans = rb_funcall2(typemod,
|
93
|
+
ans = rb_funcall2(typemod,cumo_id_send,argc,argv);
|
94
94
|
|
95
95
|
if (!RTEST(rb_class_inherited_p(type,cNArray)) &&
|
96
|
-
|
97
|
-
ans = rb_funcall(ans,
|
96
|
+
CumoIsNArray(ans) ) {
|
97
|
+
ans = rb_funcall(ans,cumo_id_extract,0);
|
98
98
|
}
|
99
99
|
return ans;
|
100
100
|
}
|
@@ -104,12 +104,12 @@ static VALUE nary_math_method_missing(int argc, VALUE *argv, VALUE mod)
|
|
104
104
|
|
105
105
|
|
106
106
|
void
|
107
|
-
|
107
|
+
Init_cumo_na_math()
|
108
108
|
{
|
109
109
|
VALUE hCast;
|
110
110
|
|
111
111
|
cumo_mNMath = rb_define_module_under(mCumo, "NMath");
|
112
|
-
rb_define_singleton_method(cumo_mNMath, "method_missing",
|
112
|
+
rb_define_singleton_method(cumo_mNMath, "method_missing", cumo_na_math_method_missing, -1);
|
113
113
|
|
114
114
|
hCast = rb_hash_new();
|
115
115
|
rb_define_const(cumo_mNMath, "DISPATCH", hCast);
|
@@ -135,8 +135,8 @@ Init_cumo_nary_math()
|
|
135
135
|
rb_hash_aset(hCast, rb_cFloat, rb_mMath);
|
136
136
|
rb_hash_aset(hCast, rb_cComplex, cumo_mDComplexMath);
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
138
|
+
cumo_id_send = rb_intern("send");
|
139
|
+
cumo_id_UPCAST = rb_intern("UPCAST");
|
140
|
+
cumo_id_DISPATCH = rb_intern("DISPATCH");
|
141
|
+
cumo_id_extract = rb_intern("extract");
|
142
142
|
}
|
data/ext/cumo/narray/narray.c
CHANGED
@@ -9,68 +9,68 @@
|
|
9
9
|
/* global variables within this module */
|
10
10
|
VALUE cumo_cNArray;
|
11
11
|
VALUE rb_mCumo;
|
12
|
-
VALUE
|
13
|
-
VALUE
|
14
|
-
VALUE
|
15
|
-
VALUE
|
16
|
-
VALUE
|
17
|
-
|
18
|
-
static ID
|
19
|
-
static ID
|
20
|
-
static ID
|
21
|
-
static ID
|
22
|
-
static ID
|
23
|
-
static ID
|
24
|
-
static ID
|
25
|
-
static ID
|
26
|
-
static ID
|
27
|
-
static ID
|
28
|
-
static ID
|
29
|
-
static ID
|
30
|
-
static ID
|
31
|
-
static ID
|
32
|
-
static ID
|
33
|
-
static ID
|
34
|
-
static ID
|
35
|
-
static ID
|
36
|
-
static ID
|
37
|
-
|
38
|
-
VALUE
|
39
|
-
VALUE
|
40
|
-
VALUE
|
41
|
-
VALUE
|
42
|
-
|
43
|
-
VALUE
|
12
|
+
VALUE cumo_na_eCastError;
|
13
|
+
VALUE cumo_na_eShapeError;
|
14
|
+
VALUE cumo_na_eOperationError;
|
15
|
+
VALUE cumo_na_eDimensionError;
|
16
|
+
VALUE cumo_na_eValueError;
|
17
|
+
|
18
|
+
static ID cumo_id_contiguous_stride;
|
19
|
+
static ID cumo_id_allocate;
|
20
|
+
static ID cumo_id_element_byte_size;
|
21
|
+
static ID cumo_id_fill;
|
22
|
+
static ID cumo_id_seq;
|
23
|
+
static ID cumo_id_logseq;
|
24
|
+
static ID cumo_id_eye;
|
25
|
+
static ID cumo_id_UPCAST;
|
26
|
+
static ID cumo_id_cast;
|
27
|
+
static ID cumo_id_dup;
|
28
|
+
static ID cumo_id_to_host;
|
29
|
+
static ID cumo_id_bracket;
|
30
|
+
static ID cumo_id_shift_left;
|
31
|
+
static ID cumo_id_eq;
|
32
|
+
static ID cumo_id_count_false;
|
33
|
+
static ID cumo_id_count_false_cpu;
|
34
|
+
static ID cumo_id_axis;
|
35
|
+
static ID cumo_id_nan;
|
36
|
+
static ID cumo_id_keepdims;
|
37
|
+
|
38
|
+
VALUE cumo_sym_reduce;
|
39
|
+
VALUE cumo_sym_option;
|
40
|
+
VALUE cumo_sym_loop_opt;
|
41
|
+
VALUE cumo_sym_init;
|
42
|
+
|
43
|
+
VALUE cumo_na_cStep;
|
44
44
|
#ifndef HAVE_RB_CCOMPLEX
|
45
45
|
VALUE rb_cComplex;
|
46
46
|
#endif
|
47
47
|
|
48
|
-
int
|
49
|
-
int
|
48
|
+
int cumo_na_inspect_rows_=20;
|
49
|
+
int cumo_na_inspect_cols_=80;
|
50
50
|
|
51
|
-
const rb_data_type_t
|
51
|
+
const rb_data_type_t cumo_na_data_type = {
|
52
52
|
"Cumo::NArray",
|
53
53
|
{0, 0, 0,}, 0, 0, 0,
|
54
54
|
};
|
55
55
|
|
56
56
|
static void
|
57
|
-
|
57
|
+
cumo_na_debug_info_nadata(VALUE self)
|
58
58
|
{
|
59
|
-
|
60
|
-
|
59
|
+
cumo_narray_data_t *na;
|
60
|
+
CumoGetNArrayData(self,na);
|
61
61
|
|
62
62
|
printf(" ptr = 0x%"SZF"x\n", (size_t)(na->ptr));
|
63
63
|
}
|
64
64
|
|
65
65
|
|
66
66
|
static VALUE
|
67
|
-
|
67
|
+
cumo_na_debug_info_naview(VALUE self)
|
68
68
|
{
|
69
69
|
int i;
|
70
|
-
|
70
|
+
cumo_narray_view_t *na;
|
71
71
|
size_t *idx;
|
72
72
|
size_t j;
|
73
|
-
|
73
|
+
CumoGetNArrayView(self,na);
|
74
74
|
|
75
75
|
printf(" data = 0x%"SZF"x\n", (size_t)na->data);
|
76
76
|
printf(" offset = %"SZF"d\n", (size_t)na->offset);
|
@@ -79,9 +79,9 @@ nary_debug_info_naview(VALUE self)
|
|
79
79
|
if (na->stridx) {
|
80
80
|
printf(" stridx = [");
|
81
81
|
for (i=0; i<na->base.ndim; i++) {
|
82
|
-
if (
|
82
|
+
if (CUMO_SDX_IS_INDEX(na->stridx[i])) {
|
83
83
|
|
84
|
-
idx =
|
84
|
+
idx = CUMO_SDX_GET_INDEX(na->stridx[i]);
|
85
85
|
printf(" index[%d]=[", i);
|
86
86
|
for (j=0; j<na->base.shape[i]; j++) {
|
87
87
|
printf(" %"SZF"d", idx[j]);
|
@@ -89,7 +89,7 @@ nary_debug_info_naview(VALUE self)
|
|
89
89
|
printf(" ] ");
|
90
90
|
|
91
91
|
} else {
|
92
|
-
printf(" %"SZF"d",
|
92
|
+
printf(" %"SZF"d", CUMO_SDX_GET_STRIDE(na->stridx[i]));
|
93
93
|
}
|
94
94
|
}
|
95
95
|
printf(" ]\n");
|
@@ -99,13 +99,13 @@ nary_debug_info_naview(VALUE self)
|
|
99
99
|
|
100
100
|
|
101
101
|
VALUE
|
102
|
-
|
102
|
+
cumo_na_debug_info(VALUE self)
|
103
103
|
{
|
104
104
|
int i;
|
105
|
-
|
106
|
-
|
105
|
+
cumo_narray_t *na;
|
106
|
+
CumoGetNArray(self,na);
|
107
107
|
|
108
|
-
printf("%s:\n",rb_class2name(
|
108
|
+
printf("%s:\n",rb_class2name(rb_obj_class(self)));
|
109
109
|
printf(" id = 0x%"PRI_VALUE_PREFIX"x\n", self);
|
110
110
|
printf(" type = %d\n", na->type);
|
111
111
|
printf(" flag = [%d,%d]\n", na->flag[0], na->flag[1]);
|
@@ -120,12 +120,12 @@ nary_debug_info(VALUE self)
|
|
120
120
|
}
|
121
121
|
|
122
122
|
switch(na->type) {
|
123
|
-
case
|
124
|
-
case
|
125
|
-
|
123
|
+
case CUMO_NARRAY_DATA_T:
|
124
|
+
case CUMO_NARRAY_FILEMAP_T:
|
125
|
+
cumo_na_debug_info_nadata(self);
|
126
126
|
break;
|
127
|
-
case
|
128
|
-
|
127
|
+
case CUMO_NARRAY_VIEW_T:
|
128
|
+
cumo_na_debug_info_naview(self);
|
129
129
|
break;
|
130
130
|
}
|
131
131
|
return Qnil;
|
@@ -133,21 +133,21 @@ nary_debug_info(VALUE self)
|
|
133
133
|
|
134
134
|
|
135
135
|
static size_t
|
136
|
-
|
136
|
+
cumo_na_view_memsize(const void* ptr)
|
137
137
|
{
|
138
138
|
int i;
|
139
|
-
size_t size = sizeof(
|
140
|
-
const
|
139
|
+
size_t size = sizeof(cumo_narray_view_t);
|
140
|
+
const cumo_narray_view_t *na = ptr;
|
141
141
|
|
142
|
-
assert(na->base.type ==
|
142
|
+
assert(na->base.type == CUMO_NARRAY_VIEW_T);
|
143
143
|
|
144
144
|
if (na->stridx != NULL) {
|
145
145
|
for (i=0; i<na->base.ndim; i++) {
|
146
|
-
if (
|
146
|
+
if (CUMO_SDX_IS_INDEX(na->stridx[i])) {
|
147
147
|
size += sizeof(size_t) * na->base.shape[i];
|
148
148
|
}
|
149
149
|
}
|
150
|
-
size += sizeof(
|
150
|
+
size += sizeof(cumo_stridx_t) * na->base.ndim;
|
151
151
|
}
|
152
152
|
if (na->base.size > 0) {
|
153
153
|
if (na->base.shape != NULL && na->base.shape != &(na->base.size)) {
|
@@ -158,17 +158,17 @@ na_view_memsize(const void* ptr)
|
|
158
158
|
}
|
159
159
|
|
160
160
|
static void
|
161
|
-
|
161
|
+
cumo_na_view_free(void* ptr)
|
162
162
|
{
|
163
163
|
int i;
|
164
|
-
|
164
|
+
cumo_narray_view_t *na = (cumo_narray_view_t*)ptr;
|
165
165
|
|
166
|
-
assert(na->base.type ==
|
166
|
+
assert(na->base.type == CUMO_NARRAY_VIEW_T);
|
167
167
|
|
168
168
|
if (na->stridx != NULL) {
|
169
169
|
for (i=0; i<na->base.ndim; i++) {
|
170
|
-
if (
|
171
|
-
void *p =
|
170
|
+
if (CUMO_SDX_IS_INDEX(na->stridx[i])) {
|
171
|
+
void *p = CUMO_SDX_GET_INDEX(na->stridx[i]);
|
172
172
|
if (cumo_cuda_runtime_is_device_memory(p)) {
|
173
173
|
cumo_cuda_runtime_free(p);
|
174
174
|
} else {
|
@@ -189,42 +189,42 @@ na_view_free(void* ptr)
|
|
189
189
|
}
|
190
190
|
|
191
191
|
static void
|
192
|
-
|
192
|
+
cumo_na_view_gc_mark(void* na)
|
193
193
|
{
|
194
|
-
if (((
|
195
|
-
rb_gc_mark(((
|
194
|
+
if (((cumo_narray_t*)na)->type == CUMO_NARRAY_VIEW_T) {
|
195
|
+
rb_gc_mark(((cumo_narray_view_t*)na)->data);
|
196
196
|
}
|
197
197
|
}
|
198
198
|
|
199
|
-
const rb_data_type_t
|
199
|
+
const rb_data_type_t cumo_na_data_type_view = {
|
200
200
|
"Cumo::NArrayView",
|
201
|
-
{
|
202
|
-
&
|
201
|
+
{cumo_na_view_gc_mark, cumo_na_view_free, cumo_na_view_memsize,},
|
202
|
+
&cumo_na_data_type, 0, 0,
|
203
203
|
};
|
204
204
|
|
205
205
|
VALUE
|
206
|
-
|
206
|
+
cumo_na_s_allocate_view(VALUE klass)
|
207
207
|
{
|
208
|
-
|
208
|
+
cumo_narray_view_t *na = ALLOC(cumo_narray_view_t);
|
209
209
|
|
210
210
|
na->base.ndim = 0;
|
211
|
-
na->base.type =
|
212
|
-
na->base.flag[0] =
|
213
|
-
na->base.flag[1] =
|
211
|
+
na->base.type = CUMO_NARRAY_VIEW_T;
|
212
|
+
na->base.flag[0] = CUMO_NA_FL0_INIT;
|
213
|
+
na->base.flag[1] = CUMO_NA_FL1_INIT;
|
214
214
|
na->base.size = 0;
|
215
215
|
na->base.shape = NULL;
|
216
216
|
na->base.reduce = INT2FIX(0);
|
217
217
|
na->data = Qnil;
|
218
218
|
na->offset = 0;
|
219
219
|
na->stridx = NULL;
|
220
|
-
return TypedData_Wrap_Struct(klass, &
|
220
|
+
return TypedData_Wrap_Struct(klass, &cumo_na_data_type_view, (void*)na);
|
221
221
|
}
|
222
222
|
|
223
223
|
|
224
224
|
//static const size_t zero=0;
|
225
225
|
|
226
226
|
void
|
227
|
-
|
227
|
+
cumo_na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape)
|
228
228
|
{
|
229
229
|
size_t i, n, c, s;
|
230
230
|
ssize_t x;
|
@@ -234,7 +234,7 @@ na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape)
|
|
234
234
|
n = RARRAY_LEN(ary);
|
235
235
|
|
236
236
|
if (RTEST(self)) {
|
237
|
-
flag =
|
237
|
+
flag = CUMO_TEST_COLUMN_MAJOR(self);
|
238
238
|
}
|
239
239
|
if (flag) {
|
240
240
|
c = n-1;
|
@@ -257,7 +257,7 @@ na_array_to_internal_shape(VALUE self, VALUE ary, size_t *shape)
|
|
257
257
|
|
258
258
|
|
259
259
|
void
|
260
|
-
|
260
|
+
cumo_na_alloc_shape(cumo_narray_t *na, int ndim)
|
261
261
|
{
|
262
262
|
na->ndim = ndim;
|
263
263
|
na->size = 0;
|
@@ -268,22 +268,22 @@ na_alloc_shape(narray_t *na, int ndim)
|
|
268
268
|
break;
|
269
269
|
default:
|
270
270
|
if (ndim < 0) {
|
271
|
-
rb_raise(
|
271
|
+
rb_raise(cumo_na_eDimensionError,"ndim=%d is negative", ndim);
|
272
272
|
}
|
273
|
-
if (ndim >
|
274
|
-
rb_raise(
|
273
|
+
if (ndim > CUMO_NA_MAX_DIMENSION) {
|
274
|
+
rb_raise(cumo_na_eDimensionError,"ndim=%d is too many", ndim);
|
275
275
|
}
|
276
276
|
na->shape = ALLOC_N(size_t, ndim);
|
277
277
|
}
|
278
278
|
}
|
279
279
|
|
280
280
|
void
|
281
|
-
|
281
|
+
cumo_na_setup_shape(cumo_narray_t *na, int ndim, size_t *shape)
|
282
282
|
{
|
283
283
|
int i;
|
284
284
|
size_t size;
|
285
285
|
|
286
|
-
|
286
|
+
cumo_na_alloc_shape(na, ndim);
|
287
287
|
|
288
288
|
if (ndim==0) {
|
289
289
|
na->size = 1;
|
@@ -301,11 +301,11 @@ na_setup_shape(narray_t *na, int ndim, size_t *shape)
|
|
301
301
|
}
|
302
302
|
|
303
303
|
static void
|
304
|
-
|
304
|
+
cumo_na_setup(VALUE self, int ndim, size_t *shape)
|
305
305
|
{
|
306
|
-
|
307
|
-
|
308
|
-
|
306
|
+
cumo_narray_t *na;
|
307
|
+
CumoGetNArray(self,na);
|
308
|
+
cumo_na_setup_shape(na, ndim, shape);
|
309
309
|
}
|
310
310
|
|
311
311
|
|
@@ -343,7 +343,7 @@ na_setup(VALUE self, int ndim, size_t *shape)
|
|
343
343
|
|
344
344
|
*/
|
345
345
|
static VALUE
|
346
|
-
|
346
|
+
cumo_na_initialize(VALUE self, VALUE args)
|
347
347
|
{
|
348
348
|
VALUE v;
|
349
349
|
size_t *shape=NULL;
|
@@ -358,36 +358,36 @@ na_initialize(VALUE self, VALUE args)
|
|
358
358
|
v = args;
|
359
359
|
}
|
360
360
|
ndim = RARRAY_LEN(v);
|
361
|
-
if (ndim >
|
361
|
+
if (ndim > CUMO_NA_MAX_DIMENSION) {
|
362
362
|
rb_raise(rb_eArgError,"ndim=%d exceeds maximum dimension",ndim);
|
363
363
|
}
|
364
364
|
shape = ALLOCA_N(size_t, ndim);
|
365
365
|
// setup size_t shape[] from VALUE shape argument
|
366
|
-
|
367
|
-
|
366
|
+
cumo_na_array_to_internal_shape(self, v, shape);
|
367
|
+
cumo_na_setup(self, ndim, shape);
|
368
368
|
|
369
369
|
return self;
|
370
370
|
}
|
371
371
|
|
372
372
|
|
373
373
|
VALUE
|
374
|
-
|
374
|
+
cumo_na_new(VALUE klass, int ndim, size_t *shape)
|
375
375
|
{
|
376
376
|
volatile VALUE obj;
|
377
377
|
|
378
|
-
obj = rb_funcall(klass,
|
379
|
-
|
378
|
+
obj = rb_funcall(klass, cumo_id_allocate, 0);
|
379
|
+
cumo_na_setup(obj, ndim, shape);
|
380
380
|
return obj;
|
381
381
|
}
|
382
382
|
|
383
383
|
|
384
384
|
VALUE
|
385
|
-
|
385
|
+
cumo_na_view_new(VALUE klass, int ndim, size_t *shape)
|
386
386
|
{
|
387
387
|
volatile VALUE obj;
|
388
388
|
|
389
|
-
obj =
|
390
|
-
|
389
|
+
obj = cumo_na_s_allocate_view(klass);
|
390
|
+
cumo_na_setup(obj, ndim, shape);
|
391
391
|
return obj;
|
392
392
|
}
|
393
393
|
|
@@ -400,14 +400,14 @@ nary_view_new(VALUE klass, int ndim, size_t *shape)
|
|
400
400
|
@return [Cumo::NArray] self
|
401
401
|
*/
|
402
402
|
static VALUE
|
403
|
-
|
403
|
+
cumo_na_initialize_copy(VALUE self, VALUE orig)
|
404
404
|
{
|
405
|
-
|
406
|
-
|
405
|
+
cumo_narray_t *na;
|
406
|
+
CumoGetNArray(orig,na);
|
407
407
|
|
408
|
-
|
409
|
-
|
410
|
-
|
408
|
+
cumo_na_setup(self,CUMO_NA_NDIM(na),CUMO_NA_SHAPE(na));
|
409
|
+
cumo_na_store(self,orig);
|
410
|
+
cumo_na_copy_flags(orig,self);
|
411
411
|
return self;
|
412
412
|
}
|
413
413
|
|
@@ -428,11 +428,11 @@ na_initialize_copy(VALUE self, VALUE orig)
|
|
428
428
|
* [0, 0, 0, 0, 0]]
|
429
429
|
*/
|
430
430
|
static VALUE
|
431
|
-
|
431
|
+
cumo_na_s_zeros(int argc, VALUE *argv, VALUE klass)
|
432
432
|
{
|
433
433
|
VALUE obj;
|
434
434
|
obj = rb_class_new_instance(argc, argv, klass);
|
435
|
-
return rb_funcall(obj,
|
435
|
+
return rb_funcall(obj, cumo_id_fill, 1, INT2FIX(0));
|
436
436
|
}
|
437
437
|
|
438
438
|
|
@@ -452,11 +452,11 @@ na_s_zeros(int argc, VALUE *argv, VALUE klass)
|
|
452
452
|
* [1, 1, 1, 1, 1]]
|
453
453
|
*/
|
454
454
|
static VALUE
|
455
|
-
|
455
|
+
cumo_na_s_ones(int argc, VALUE *argv, VALUE klass)
|
456
456
|
{
|
457
457
|
VALUE obj;
|
458
458
|
obj = rb_class_new_instance(argc, argv, klass);
|
459
|
-
return rb_funcall(obj,
|
459
|
+
return rb_funcall(obj, cumo_id_fill, 1, INT2FIX(1));
|
460
460
|
}
|
461
461
|
|
462
462
|
|
@@ -477,7 +477,7 @@ na_s_ones(int argc, VALUE *argv, VALUE klass)
|
|
477
477
|
[-5, -3.33333, -1.66667, 0, 1.66667, 3.33333, 5]
|
478
478
|
*/
|
479
479
|
static VALUE
|
480
|
-
|
480
|
+
cumo_na_s_linspace(int argc, VALUE *argv, VALUE klass)
|
481
481
|
{
|
482
482
|
VALUE obj, vx1, vx2, vstep, vsize;
|
483
483
|
double n;
|
@@ -495,7 +495,7 @@ na_s_linspace(int argc, VALUE *argv, VALUE klass)
|
|
495
495
|
vstep = rb_funcall(obj, '/', 1, DBL2NUM(n-1));
|
496
496
|
|
497
497
|
obj = rb_class_new_instance(1, &vsize, klass);
|
498
|
-
return rb_funcall(obj,
|
498
|
+
return rb_funcall(obj, cumo_id_seq, 2, vx1, vstep);
|
499
499
|
}
|
500
500
|
|
501
501
|
/*
|
@@ -519,7 +519,7 @@ na_s_linspace(int argc, VALUE *argv, VALUE klass)
|
|
519
519
|
[1+4.44659e-323i, 0.707107+0.707107i, 6.12323e-17+1i, -0.707107+0.707107i, ...]
|
520
520
|
*/
|
521
521
|
static VALUE
|
522
|
-
|
522
|
+
cumo_na_s_logspace(int argc, VALUE *argv, VALUE klass)
|
523
523
|
{
|
524
524
|
VALUE obj, vx1, vx2, vstep, vsize, vbase;
|
525
525
|
double n;
|
@@ -539,7 +539,7 @@ na_s_logspace(int argc, VALUE *argv, VALUE klass)
|
|
539
539
|
vstep = rb_funcall(obj, '/', 1, DBL2NUM(n-1));
|
540
540
|
|
541
541
|
obj = rb_class_new_instance(1, &vsize, klass);
|
542
|
-
return rb_funcall(obj,
|
542
|
+
return rb_funcall(obj, cumo_id_logseq, 3, vx1, vstep, vbase);
|
543
543
|
}
|
544
544
|
|
545
545
|
|
@@ -556,7 +556,7 @@ na_s_logspace(int argc, VALUE *argv, VALUE klass)
|
|
556
556
|
[0, 0, 1]]
|
557
557
|
*/
|
558
558
|
static VALUE
|
559
|
-
|
559
|
+
cumo_na_s_eye(int argc, VALUE *argv, VALUE klass)
|
560
560
|
{
|
561
561
|
VALUE obj;
|
562
562
|
VALUE tmp[2];
|
@@ -570,7 +570,7 @@ na_s_eye(int argc, VALUE *argv, VALUE klass)
|
|
570
570
|
argc = 2;
|
571
571
|
}
|
572
572
|
obj = rb_class_new_instance(argc, argv, klass);
|
573
|
-
return rb_funcall(obj,
|
573
|
+
return rb_funcall(obj, cumo_id_eye, 0);
|
574
574
|
}
|
575
575
|
|
576
576
|
|
@@ -579,92 +579,92 @@ na_s_eye(int argc, VALUE *argv, VALUE klass)
|
|
579
579
|
#define WRITE 2
|
580
580
|
|
581
581
|
static char *
|
582
|
-
|
582
|
+
cumo_na_get_pointer_for_rw(VALUE self, int flag)
|
583
583
|
{
|
584
584
|
char *ptr;
|
585
585
|
VALUE obj;
|
586
|
-
|
586
|
+
cumo_narray_t *na;
|
587
587
|
|
588
588
|
if ((flag & WRITE) && OBJ_FROZEN(self)) {
|
589
589
|
rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
|
590
590
|
}
|
591
591
|
|
592
|
-
|
592
|
+
CumoGetNArray(self,na);
|
593
593
|
|
594
|
-
switch(
|
595
|
-
case
|
596
|
-
ptr =
|
597
|
-
if (
|
594
|
+
switch(CUMO_NA_TYPE(na)) {
|
595
|
+
case CUMO_NARRAY_DATA_T:
|
596
|
+
ptr = CUMO_NA_DATA_PTR(na);
|
597
|
+
if (CUMO_NA_SIZE(na) > 0 && ptr == NULL) {
|
598
598
|
if (flag & READ) {
|
599
599
|
rb_raise(rb_eRuntimeError,"cannot read unallocated NArray");
|
600
600
|
}
|
601
601
|
if (flag & WRITE) {
|
602
|
-
rb_funcall(self,
|
603
|
-
ptr =
|
602
|
+
rb_funcall(self, cumo_id_allocate, 0);
|
603
|
+
ptr = CUMO_NA_DATA_PTR(na);
|
604
604
|
}
|
605
605
|
}
|
606
606
|
return ptr;
|
607
|
-
case
|
608
|
-
obj =
|
607
|
+
case CUMO_NARRAY_VIEW_T:
|
608
|
+
obj = CUMO_NA_VIEW_DATA(na);
|
609
609
|
if ((flag & WRITE) && OBJ_FROZEN(obj)) {
|
610
610
|
rb_raise(rb_eRuntimeError, "cannot write to frozen NArray.");
|
611
611
|
}
|
612
|
-
|
613
|
-
switch(
|
614
|
-
case
|
615
|
-
ptr =
|
612
|
+
CumoGetNArray(obj,na);
|
613
|
+
switch(CUMO_NA_TYPE(na)) {
|
614
|
+
case CUMO_NARRAY_DATA_T:
|
615
|
+
ptr = CUMO_NA_DATA_PTR(na);
|
616
616
|
if (flag & (READ|WRITE)) {
|
617
|
-
if (
|
617
|
+
if (CUMO_NA_SIZE(na) > 0 && ptr == NULL) {
|
618
618
|
rb_raise(rb_eRuntimeError,"cannot read/write unallocated NArray");
|
619
619
|
}
|
620
620
|
}
|
621
621
|
return ptr;
|
622
622
|
default:
|
623
|
-
rb_raise(rb_eRuntimeError,"invalid
|
623
|
+
rb_raise(rb_eRuntimeError,"invalid CUMO_NA_TYPE of view: %d",CUMO_NA_TYPE(na));
|
624
624
|
}
|
625
625
|
default:
|
626
|
-
rb_raise(rb_eRuntimeError,"invalid
|
626
|
+
rb_raise(rb_eRuntimeError,"invalid CUMO_NA_TYPE: %d",CUMO_NA_TYPE(na));
|
627
627
|
}
|
628
628
|
|
629
629
|
return NULL;
|
630
630
|
}
|
631
631
|
|
632
632
|
char *
|
633
|
-
|
633
|
+
cumo_na_get_pointer_for_read(VALUE self)
|
634
634
|
{
|
635
|
-
return
|
635
|
+
return cumo_na_get_pointer_for_rw(self, READ);
|
636
636
|
}
|
637
637
|
|
638
638
|
char *
|
639
|
-
|
639
|
+
cumo_na_get_pointer_for_write(VALUE self)
|
640
640
|
{
|
641
|
-
return
|
641
|
+
return cumo_na_get_pointer_for_rw(self, WRITE);
|
642
642
|
}
|
643
643
|
|
644
644
|
char *
|
645
|
-
|
645
|
+
cumo_na_get_pointer_for_read_write(VALUE self)
|
646
646
|
{
|
647
|
-
return
|
647
|
+
return cumo_na_get_pointer_for_rw(self, READ|WRITE);
|
648
648
|
}
|
649
649
|
|
650
650
|
char *
|
651
|
-
|
651
|
+
cumo_na_get_pointer(VALUE self)
|
652
652
|
{
|
653
|
-
return
|
653
|
+
return cumo_na_get_pointer_for_rw(self, 0);
|
654
654
|
}
|
655
655
|
|
656
656
|
|
657
657
|
void
|
658
|
-
|
658
|
+
cumo_na_release_lock(VALUE self)
|
659
659
|
{
|
660
|
-
|
660
|
+
cumo_narray_t *na;
|
661
661
|
|
662
|
-
|
663
|
-
|
662
|
+
CUMO_UNCUMO_SET_LOCK(self);
|
663
|
+
CumoGetNArray(self,na);
|
664
664
|
|
665
|
-
switch(
|
666
|
-
case
|
667
|
-
|
665
|
+
switch(CUMO_NA_TYPE(na)) {
|
666
|
+
case CUMO_NARRAY_VIEW_T:
|
667
|
+
cumo_na_release_lock(CUMO_NA_VIEW_DATA(na));
|
668
668
|
break;
|
669
669
|
}
|
670
670
|
}
|
@@ -672,20 +672,20 @@ na_release_lock(VALUE self)
|
|
672
672
|
|
673
673
|
/* method: size() -- returns the total number of typeents */
|
674
674
|
static VALUE
|
675
|
-
|
675
|
+
cumo_na_size(VALUE self)
|
676
676
|
{
|
677
|
-
|
678
|
-
|
677
|
+
cumo_narray_t *na;
|
678
|
+
CumoGetNArray(self,na);
|
679
679
|
return SIZET2NUM(na->size);
|
680
680
|
}
|
681
681
|
|
682
682
|
|
683
683
|
/* method: size() -- returns the total number of typeents */
|
684
684
|
static VALUE
|
685
|
-
|
685
|
+
cumo_na_ndim(VALUE self)
|
686
686
|
{
|
687
|
-
|
688
|
-
|
687
|
+
cumo_narray_t *na;
|
688
|
+
CumoGetNArray(self,na);
|
689
689
|
return INT2NUM(na->ndim);
|
690
690
|
}
|
691
691
|
|
@@ -695,11 +695,11 @@ na_ndim(VALUE self)
|
|
695
695
|
@overload empty?
|
696
696
|
*/
|
697
697
|
static VALUE
|
698
|
-
|
698
|
+
cumo_na_empty_p(VALUE self)
|
699
699
|
{
|
700
|
-
|
701
|
-
|
702
|
-
if (
|
700
|
+
cumo_narray_t *na;
|
701
|
+
CumoGetNArray(self,na);
|
702
|
+
if (CUMO_NA_SIZE(na)==0) {
|
703
703
|
return Qtrue;
|
704
704
|
}
|
705
705
|
return Qfalse;
|
@@ -708,15 +708,15 @@ na_empty_p(VALUE self)
|
|
708
708
|
|
709
709
|
/* method: shape() -- returns shape, array of the size of dimensions */
|
710
710
|
static VALUE
|
711
|
-
|
711
|
+
cumo_na_shape(VALUE self)
|
712
712
|
{
|
713
713
|
volatile VALUE v;
|
714
|
-
|
714
|
+
cumo_narray_t *na;
|
715
715
|
size_t i, n, c, s;
|
716
716
|
|
717
|
-
|
718
|
-
n =
|
719
|
-
if (
|
717
|
+
CumoGetNArray(self,na);
|
718
|
+
n = CUMO_NA_NDIM(na);
|
719
|
+
if (CUMO_TEST_COLUMN_MAJOR(self)) {
|
720
720
|
c = n-1;
|
721
721
|
s = -1;
|
722
722
|
} else {
|
@@ -733,52 +733,52 @@ static VALUE
|
|
733
733
|
|
734
734
|
|
735
735
|
unsigned int
|
736
|
-
|
736
|
+
cumo_na_element_stride(VALUE v)
|
737
737
|
{
|
738
|
-
|
739
|
-
|
738
|
+
cumo_narray_type_info_t *info;
|
739
|
+
cumo_narray_t *na;
|
740
740
|
|
741
|
-
|
742
|
-
if (na->type ==
|
743
|
-
v =
|
744
|
-
|
741
|
+
CumoGetNArray(v,na);
|
742
|
+
if (na->type == CUMO_NARRAY_VIEW_T) {
|
743
|
+
v = CUMO_NA_VIEW_DATA(na);
|
744
|
+
CumoGetNArray(v,na);
|
745
745
|
}
|
746
|
-
assert(na->type ==
|
746
|
+
assert(na->type == CUMO_NARRAY_DATA_T);
|
747
747
|
|
748
|
-
info = (
|
748
|
+
info = (cumo_narray_type_info_t *)(RTYPEDDATA_TYPE(v)->data);
|
749
749
|
return info->element_stride;
|
750
750
|
}
|
751
751
|
|
752
752
|
size_t
|
753
|
-
|
753
|
+
cumo_na_dtype_element_stride(VALUE klass)
|
754
754
|
{
|
755
|
-
return NUM2SIZET(rb_const_get(klass,
|
755
|
+
return NUM2SIZET(rb_const_get(klass, cumo_id_contiguous_stride));
|
756
756
|
}
|
757
757
|
|
758
758
|
size_t
|
759
|
-
|
759
|
+
cumo_na_get_offset(VALUE self)
|
760
760
|
{
|
761
|
-
|
762
|
-
|
761
|
+
cumo_narray_t *na;
|
762
|
+
CumoGetNArray(self,na);
|
763
763
|
|
764
764
|
switch(na->type) {
|
765
|
-
case
|
766
|
-
case
|
765
|
+
case CUMO_NARRAY_DATA_T:
|
766
|
+
case CUMO_NARRAY_FILEMAP_T:
|
767
767
|
return 0;
|
768
|
-
case
|
769
|
-
return
|
768
|
+
case CUMO_NARRAY_VIEW_T:
|
769
|
+
return CUMO_NA_VIEW_OFFSET(na);
|
770
770
|
}
|
771
771
|
return 0;
|
772
772
|
}
|
773
773
|
|
774
774
|
|
775
775
|
void
|
776
|
-
|
776
|
+
cumo_na_index_arg_to_internal_order(int argc, VALUE *argv, VALUE self)
|
777
777
|
{
|
778
778
|
int i,j;
|
779
779
|
VALUE tmp;
|
780
780
|
|
781
|
-
if (
|
781
|
+
if (CUMO_TEST_COLUMN_MAJOR(self)) {
|
782
782
|
for (i=0,j=argc-1; i<argc/2; i++,j--) {
|
783
783
|
tmp = argv[i];
|
784
784
|
argv[i] = argv[j];
|
@@ -788,15 +788,15 @@ na_index_arg_to_internal_order(int argc, VALUE *argv, VALUE self)
|
|
788
788
|
}
|
789
789
|
|
790
790
|
void
|
791
|
-
|
791
|
+
cumo_na_copy_flags(VALUE src, VALUE dst)
|
792
792
|
{
|
793
|
-
|
793
|
+
cumo_narray_t *na1, *na2;
|
794
794
|
|
795
|
-
|
796
|
-
|
795
|
+
CumoGetNArray(src,na1);
|
796
|
+
CumoGetNArray(dst,na2);
|
797
797
|
|
798
798
|
na2->flag[0] = na1->flag[0];
|
799
|
-
//na2->flag[1] =
|
799
|
+
//na2->flag[1] = CUMO_NA_FL1_INIT;
|
800
800
|
|
801
801
|
RBASIC(dst)->flags |= (RBASIC(src)->flags) &
|
802
802
|
(FL_USER1|FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6|FL_USER7);
|
@@ -805,36 +805,36 @@ na_copy_flags(VALUE src, VALUE dst)
|
|
805
805
|
|
806
806
|
// fix name, ex, allow_stride_for_flatten_view
|
807
807
|
VALUE
|
808
|
-
|
808
|
+
cumo_na_check_ladder(VALUE self, int start_dim)
|
809
809
|
{
|
810
810
|
int i;
|
811
811
|
ssize_t st0, st1;
|
812
|
-
|
813
|
-
|
812
|
+
cumo_narray_t *na;
|
813
|
+
CumoGetNArray(self,na);
|
814
814
|
|
815
815
|
if (start_dim < -na->ndim || start_dim >= na->ndim) {
|
816
816
|
rb_bug("start_dim (%d) out of range",start_dim);
|
817
817
|
}
|
818
818
|
|
819
819
|
switch(na->type) {
|
820
|
-
case
|
821
|
-
case
|
820
|
+
case CUMO_NARRAY_DATA_T:
|
821
|
+
case CUMO_NARRAY_FILEMAP_T:
|
822
822
|
return Qtrue;
|
823
|
-
case
|
823
|
+
case CUMO_NARRAY_VIEW_T:
|
824
824
|
// negative dim -> position from last dim
|
825
825
|
if (start_dim < 0) {
|
826
|
-
start_dim +=
|
826
|
+
start_dim += CUMO_NA_NDIM(na);
|
827
827
|
}
|
828
828
|
// not ladder if it has index
|
829
|
-
for (i=start_dim; i<
|
830
|
-
if (
|
829
|
+
for (i=start_dim; i<CUMO_NA_NDIM(na); i++) {
|
830
|
+
if (CUMO_NA_IS_INDEX_AT(na,i))
|
831
831
|
return Qfalse;
|
832
832
|
}
|
833
833
|
// check stride
|
834
|
-
st0 =
|
835
|
-
for (i=start_dim+1; i<
|
836
|
-
st1 =
|
837
|
-
if (st0 != (ssize_t)(st1 *
|
834
|
+
st0 = CUMO_NA_STRIDE_AT(na,start_dim);
|
835
|
+
for (i=start_dim+1; i<CUMO_NA_NDIM(na); i++) {
|
836
|
+
st1 = CUMO_NA_STRIDE_AT(na,i);
|
837
|
+
if (st0 != (ssize_t)(st1 * CUMO_NA_SHAPE(na)[i])) {
|
838
838
|
return Qfalse;
|
839
839
|
}
|
840
840
|
st0 = st1;
|
@@ -844,23 +844,23 @@ na_check_ladder(VALUE self, int start_dim)
|
|
844
844
|
}
|
845
845
|
|
846
846
|
VALUE
|
847
|
-
|
847
|
+
cumo_na_check_contiguous(VALUE self)
|
848
848
|
{
|
849
849
|
ssize_t elmsz;
|
850
|
-
|
851
|
-
|
850
|
+
cumo_narray_t *na;
|
851
|
+
CumoGetNArray(self,na);
|
852
852
|
|
853
853
|
switch(na->type) {
|
854
|
-
case
|
855
|
-
case
|
854
|
+
case CUMO_NARRAY_DATA_T:
|
855
|
+
case CUMO_NARRAY_FILEMAP_T:
|
856
856
|
return Qtrue;
|
857
|
-
case
|
858
|
-
if (
|
857
|
+
case CUMO_NARRAY_VIEW_T:
|
858
|
+
if (CUMO_NA_VIEW_STRIDX(na)==0) {
|
859
859
|
return Qtrue;
|
860
860
|
}
|
861
|
-
if (
|
862
|
-
elmsz =
|
863
|
-
if (elmsz ==
|
861
|
+
if (cumo_na_check_ladder(self,0)==Qtrue) {
|
862
|
+
elmsz = cumo_na_element_stride(self);
|
863
|
+
if (elmsz == CUMO_NA_STRIDE_AT(na,CUMO_NA_NDIM(na)-1)) {
|
864
864
|
return Qtrue;
|
865
865
|
}
|
866
866
|
}
|
@@ -877,48 +877,48 @@ na_check_contiguous(VALUE self)
|
|
877
877
|
* Return view of NArray
|
878
878
|
*/
|
879
879
|
VALUE
|
880
|
-
|
880
|
+
cumo_na_make_view(VALUE self)
|
881
881
|
{
|
882
882
|
int i, nd;
|
883
883
|
size_t j;
|
884
884
|
size_t *idx1, *idx2;
|
885
885
|
ssize_t stride;
|
886
|
-
|
887
|
-
|
886
|
+
cumo_narray_t *na;
|
887
|
+
cumo_narray_view_t *na1, *na2;
|
888
888
|
volatile VALUE view;
|
889
889
|
|
890
|
-
|
890
|
+
CumoGetNArray(self,na);
|
891
891
|
nd = na->ndim;
|
892
892
|
|
893
|
-
view =
|
893
|
+
view = cumo_na_s_allocate_view(rb_obj_class(self));
|
894
894
|
|
895
|
-
|
896
|
-
|
895
|
+
cumo_na_copy_flags(self, view);
|
896
|
+
CumoGetNArrayView(view, na2);
|
897
897
|
|
898
|
-
|
899
|
-
na2->stridx = ALLOC_N(
|
898
|
+
cumo_na_setup_shape((cumo_narray_t*)na2, nd, na->shape);
|
899
|
+
na2->stridx = ALLOC_N(cumo_stridx_t,nd);
|
900
900
|
|
901
901
|
switch(na->type) {
|
902
|
-
case
|
903
|
-
case
|
904
|
-
stride =
|
902
|
+
case CUMO_NARRAY_DATA_T:
|
903
|
+
case CUMO_NARRAY_FILEMAP_T:
|
904
|
+
stride = cumo_na_element_stride(self);
|
905
905
|
for (i=nd; i--;) {
|
906
|
-
|
906
|
+
CUMO_SDX_SET_STRIDE(na2->stridx[i],stride);
|
907
907
|
stride *= na->shape[i];
|
908
908
|
}
|
909
909
|
na2->offset = 0;
|
910
910
|
na2->data = self;
|
911
911
|
break;
|
912
|
-
case
|
913
|
-
|
912
|
+
case CUMO_NARRAY_VIEW_T:
|
913
|
+
CumoGetNArrayView(self, na1);
|
914
914
|
for (i=0; i<nd; i++) {
|
915
|
-
if (
|
916
|
-
idx1 =
|
915
|
+
if (CUMO_SDX_IS_INDEX(na1->stridx[i])) {
|
916
|
+
idx1 = CUMO_SDX_GET_INDEX(na1->stridx[i]);
|
917
917
|
idx2 = ALLOC_N(size_t,na1->base.shape[i]);
|
918
918
|
for (j=0; j<na1->base.shape[i]; j++) {
|
919
919
|
idx2[j] = idx1[j];
|
920
920
|
}
|
921
|
-
|
921
|
+
CUMO_SDX_SET_INDEX(na2->stridx[i],idx2);
|
922
922
|
} else {
|
923
923
|
na2->stridx[i] = na1->stridx[i];
|
924
924
|
}
|
@@ -944,51 +944,51 @@ na_make_view(VALUE self)
|
|
944
944
|
* @return [Cumo::NArray] result narray view.
|
945
945
|
*/
|
946
946
|
static VALUE
|
947
|
-
|
947
|
+
cumo_na_expand_dims(VALUE self, VALUE vdim)
|
948
948
|
{
|
949
949
|
int i, j, nd, dim;
|
950
|
-
size_t *shape, *
|
951
|
-
|
952
|
-
|
953
|
-
|
950
|
+
size_t *shape, *cumo_na_shape;
|
951
|
+
cumo_stridx_t *stridx, *cumo_na_stridx;
|
952
|
+
cumo_narray_t *na;
|
953
|
+
cumo_narray_view_t *na2;
|
954
954
|
VALUE view;
|
955
955
|
|
956
|
-
|
956
|
+
CumoGetNArray(self,na);
|
957
957
|
nd = na->ndim;
|
958
958
|
|
959
959
|
dim = NUM2INT(vdim);
|
960
960
|
if (dim < -nd-1 || dim > nd) {
|
961
|
-
rb_raise(
|
961
|
+
rb_raise(cumo_na_eDimensionError,"invalid axis (%d for %dD NArray)",
|
962
962
|
dim,nd);
|
963
963
|
}
|
964
964
|
if (dim < 0) {
|
965
965
|
dim += nd+1;
|
966
966
|
}
|
967
967
|
|
968
|
-
view =
|
969
|
-
|
968
|
+
view = cumo_na_make_view(self);
|
969
|
+
CumoGetNArrayView(view, na2);
|
970
970
|
|
971
971
|
shape = ALLOC_N(size_t,nd+1);
|
972
|
-
stridx = ALLOC_N(
|
973
|
-
|
974
|
-
|
972
|
+
stridx = ALLOC_N(cumo_stridx_t,nd+1);
|
973
|
+
cumo_na_shape = na2->base.shape;
|
974
|
+
cumo_na_stridx = na2->stridx;
|
975
975
|
|
976
976
|
for (i=j=0; i<=nd; i++) {
|
977
977
|
if (i==dim) {
|
978
978
|
shape[i] = 1;
|
979
|
-
|
979
|
+
CUMO_SDX_SET_STRIDE(stridx[i],0);
|
980
980
|
} else {
|
981
|
-
shape[i] =
|
982
|
-
stridx[i] =
|
981
|
+
shape[i] = cumo_na_shape[j];
|
982
|
+
stridx[i] = cumo_na_stridx[j];
|
983
983
|
j++;
|
984
984
|
}
|
985
985
|
}
|
986
986
|
|
987
987
|
na2->stridx = stridx;
|
988
|
-
xfree(
|
988
|
+
xfree(cumo_na_stridx);
|
989
989
|
na2->base.shape = shape;
|
990
|
-
if (
|
991
|
-
xfree(
|
990
|
+
if (cumo_na_shape != &(na2->base.size)) {
|
991
|
+
xfree(cumo_na_shape);
|
992
992
|
}
|
993
993
|
na2->base.ndim++;
|
994
994
|
return view;
|
@@ -1003,7 +1003,7 @@ na_expand_dims(VALUE self, VALUE vdim)
|
|
1003
1003
|
* Return reversed view along specified dimeinsion
|
1004
1004
|
*/
|
1005
1005
|
static VALUE
|
1006
|
-
|
1006
|
+
cumo_na_reverse(int argc, VALUE *argv, VALUE self)
|
1007
1007
|
{
|
1008
1008
|
int i, nd;
|
1009
1009
|
size_t j, n;
|
@@ -1011,51 +1011,51 @@ nary_reverse(int argc, VALUE *argv, VALUE self)
|
|
1011
1011
|
size_t *idx1, *idx2;
|
1012
1012
|
ssize_t stride;
|
1013
1013
|
ssize_t sign;
|
1014
|
-
|
1015
|
-
|
1014
|
+
cumo_narray_t *na;
|
1015
|
+
cumo_narray_view_t *na1, *na2;
|
1016
1016
|
VALUE view;
|
1017
1017
|
VALUE reduce;
|
1018
1018
|
|
1019
|
-
reduce =
|
1019
|
+
reduce = cumo_na_reduce_dimension(argc, argv, 1, &self, 0, 0);
|
1020
1020
|
|
1021
|
-
|
1021
|
+
CumoGetNArray(self,na);
|
1022
1022
|
nd = na->ndim;
|
1023
1023
|
|
1024
|
-
view =
|
1024
|
+
view = cumo_na_s_allocate_view(rb_obj_class(self));
|
1025
1025
|
|
1026
|
-
|
1027
|
-
|
1026
|
+
cumo_na_copy_flags(self, view);
|
1027
|
+
CumoGetNArrayView(view, na2);
|
1028
1028
|
|
1029
|
-
|
1030
|
-
na2->stridx = ALLOC_N(
|
1029
|
+
cumo_na_setup_shape((cumo_narray_t*)na2, nd, na->shape);
|
1030
|
+
na2->stridx = ALLOC_N(cumo_stridx_t,nd);
|
1031
1031
|
|
1032
1032
|
switch(na->type) {
|
1033
|
-
case
|
1034
|
-
case
|
1035
|
-
stride =
|
1033
|
+
case CUMO_NARRAY_DATA_T:
|
1034
|
+
case CUMO_NARRAY_FILEMAP_T:
|
1035
|
+
stride = cumo_na_element_stride(self);
|
1036
1036
|
offset = 0;
|
1037
1037
|
for (i=nd; i--;) {
|
1038
|
-
if (
|
1038
|
+
if (cumo_na_test_reduce(reduce,i)) {
|
1039
1039
|
offset += (na->shape[i]-1)*stride;
|
1040
1040
|
sign = -1;
|
1041
1041
|
} else {
|
1042
1042
|
sign = 1;
|
1043
1043
|
}
|
1044
|
-
|
1044
|
+
CUMO_SDX_SET_STRIDE(na2->stridx[i],stride*sign);
|
1045
1045
|
stride *= na->shape[i];
|
1046
1046
|
}
|
1047
1047
|
na2->offset = offset;
|
1048
1048
|
na2->data = self;
|
1049
1049
|
break;
|
1050
|
-
case
|
1051
|
-
|
1050
|
+
case CUMO_NARRAY_VIEW_T:
|
1051
|
+
CumoGetNArrayView(self, na1);
|
1052
1052
|
offset = na1->offset;
|
1053
1053
|
for (i=0; i<nd; i++) {
|
1054
1054
|
n = na1->base.shape[i];
|
1055
|
-
if (
|
1056
|
-
idx1 =
|
1055
|
+
if (CUMO_SDX_IS_INDEX(na1->stridx[i])) {
|
1056
|
+
idx1 = CUMO_SDX_GET_INDEX(na1->stridx[i]);
|
1057
1057
|
idx2 = ALLOC_N(size_t,n);
|
1058
|
-
if (
|
1058
|
+
if (cumo_na_test_reduce(reduce,i)) {
|
1059
1059
|
for (j=0; j<n; j++) {
|
1060
1060
|
idx2[n-1-j] = idx1[j];
|
1061
1061
|
}
|
@@ -1064,12 +1064,12 @@ nary_reverse(int argc, VALUE *argv, VALUE self)
|
|
1064
1064
|
idx2[j] = idx1[j];
|
1065
1065
|
}
|
1066
1066
|
}
|
1067
|
-
|
1067
|
+
CUMO_SDX_SET_INDEX(na2->stridx[i],idx2);
|
1068
1068
|
} else {
|
1069
|
-
stride =
|
1070
|
-
if (
|
1069
|
+
stride = CUMO_SDX_GET_STRIDE(na1->stridx[i]);
|
1070
|
+
if (cumo_na_test_reduce(reduce,i)) {
|
1071
1071
|
offset += (n-1)*stride;
|
1072
|
-
|
1072
|
+
CUMO_SDX_SET_STRIDE(na2->stridx[i],-stride);
|
1073
1073
|
} else {
|
1074
1074
|
na2->stridx[i] = na1->stridx[i];
|
1075
1075
|
}
|
@@ -1094,12 +1094,12 @@ cumo_na_upcast(VALUE type1, VALUE type2)
|
|
1094
1094
|
if (type1==type2) {
|
1095
1095
|
return type1;
|
1096
1096
|
}
|
1097
|
-
upcast_hash = rb_const_get(type1,
|
1097
|
+
upcast_hash = rb_const_get(type1, cumo_id_UPCAST);
|
1098
1098
|
result_type = rb_hash_aref(upcast_hash, type2);
|
1099
1099
|
if (NIL_P(result_type)) {
|
1100
1100
|
if (TYPE(type2)==T_CLASS) {
|
1101
1101
|
if (RTEST(rb_class_inherited_p(type2,cNArray))) {
|
1102
|
-
upcast_hash = rb_const_get(type2,
|
1102
|
+
upcast_hash = rb_const_get(type2, cumo_id_UPCAST);
|
1103
1103
|
result_type = rb_hash_aref(upcast_hash, type1);
|
1104
1104
|
}
|
1105
1105
|
}
|
@@ -1117,12 +1117,12 @@ cumo_na_upcast(VALUE type1, VALUE type2)
|
|
1117
1117
|
@return [Array] NArray-casted [other,self]
|
1118
1118
|
*/
|
1119
1119
|
static VALUE
|
1120
|
-
|
1120
|
+
cumo_na_coerce(VALUE x, VALUE y)
|
1121
1121
|
{
|
1122
1122
|
VALUE type;
|
1123
1123
|
|
1124
|
-
type = cumo_na_upcast(
|
1125
|
-
y = rb_funcall(type,
|
1124
|
+
type = cumo_na_upcast(rb_obj_class(x), rb_obj_class(y));
|
1125
|
+
y = rb_funcall(type,cumo_id_cast,1,y);
|
1126
1126
|
return rb_assoc_new(y , x);
|
1127
1127
|
}
|
1128
1128
|
|
@@ -1132,13 +1132,13 @@ nary_coerce(VALUE x, VALUE y)
|
|
1132
1132
|
@return [Integer] byte size.
|
1133
1133
|
*/
|
1134
1134
|
static VALUE
|
1135
|
-
|
1135
|
+
cumo_na_byte_size(VALUE self)
|
1136
1136
|
{
|
1137
1137
|
VALUE velmsz;
|
1138
|
-
|
1138
|
+
cumo_narray_t *na;
|
1139
1139
|
|
1140
|
-
|
1141
|
-
velmsz = rb_const_get(
|
1140
|
+
CumoGetNArray(self,na);
|
1141
|
+
velmsz = rb_const_get(rb_obj_class(self), cumo_id_element_byte_size);
|
1142
1142
|
if (FIXNUM_P(velmsz)) {
|
1143
1143
|
return SIZET2NUM(NUM2SIZET(velmsz) * na->size);
|
1144
1144
|
}
|
@@ -1150,9 +1150,9 @@ nary_byte_size(VALUE self)
|
|
1150
1150
|
@return [Numeric] byte size.
|
1151
1151
|
*/
|
1152
1152
|
static VALUE
|
1153
|
-
|
1153
|
+
cumo_na_s_byte_size(VALUE type)
|
1154
1154
|
{
|
1155
|
-
return rb_const_get(type,
|
1155
|
+
return rb_const_get(type, cumo_id_element_byte_size);
|
1156
1156
|
}
|
1157
1157
|
|
1158
1158
|
|
@@ -1164,7 +1164,7 @@ nary_s_byte_size(VALUE type)
|
|
1164
1164
|
@return [Cumo::NArray] NArray containing binary data.
|
1165
1165
|
*/
|
1166
1166
|
static VALUE
|
1167
|
-
|
1167
|
+
cumo_na_s_from_binary(int argc, VALUE *argv, VALUE type)
|
1168
1168
|
{
|
1169
1169
|
size_t len, str_len, byte_size;
|
1170
1170
|
size_t *shape;
|
@@ -1176,7 +1176,7 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
|
|
1176
1176
|
narg = rb_scan_args(argc,argv,"11",&vstr,&vshape);
|
1177
1177
|
Check_Type(vstr,T_STRING);
|
1178
1178
|
str_len = RSTRING_LEN(vstr);
|
1179
|
-
velmsz = rb_const_get(type,
|
1179
|
+
velmsz = rb_const_get(type, cumo_id_element_byte_size);
|
1180
1180
|
if (narg==2) {
|
1181
1181
|
switch(TYPE(vshape)) {
|
1182
1182
|
case T_FIXNUM:
|
@@ -1186,8 +1186,8 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
|
|
1186
1186
|
break;
|
1187
1187
|
case T_ARRAY:
|
1188
1188
|
nd = RARRAY_LEN(vshape);
|
1189
|
-
if (nd == 0 || nd >
|
1190
|
-
rb_raise(
|
1189
|
+
if (nd == 0 || nd > CUMO_NA_MAX_DIMENSION) {
|
1190
|
+
rb_raise(cumo_na_eDimensionError,"too long or empty shape (%d)", nd);
|
1191
1191
|
}
|
1192
1192
|
shape = ALLOCA_N(size_t,nd);
|
1193
1193
|
len = 1;
|
@@ -1222,8 +1222,8 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
|
|
1222
1222
|
shape[0] = len;
|
1223
1223
|
}
|
1224
1224
|
|
1225
|
-
vna =
|
1226
|
-
ptr =
|
1225
|
+
vna = cumo_na_new(type, nd, shape);
|
1226
|
+
ptr = cumo_na_get_pointer_for_write(vna);
|
1227
1227
|
|
1228
1228
|
memcpy(ptr, RSTRING_PTR(vstr), byte_size);
|
1229
1229
|
|
@@ -1238,14 +1238,14 @@ nary_s_from_binary(int argc, VALUE *argv, VALUE type)
|
|
1238
1238
|
@return [Integer] stored length.
|
1239
1239
|
*/
|
1240
1240
|
static VALUE
|
1241
|
-
|
1241
|
+
cumo_na_store_binary(int argc, VALUE *argv, VALUE self)
|
1242
1242
|
{
|
1243
1243
|
size_t size, str_len, byte_size, offset;
|
1244
1244
|
char *ptr;
|
1245
1245
|
int narg;
|
1246
1246
|
VALUE vstr, voffset;
|
1247
1247
|
VALUE velmsz;
|
1248
|
-
|
1248
|
+
cumo_narray_t *na;
|
1249
1249
|
|
1250
1250
|
narg = rb_scan_args(argc,argv,"11",&vstr,&voffset);
|
1251
1251
|
str_len = RSTRING_LEN(vstr);
|
@@ -1259,9 +1259,9 @@ nary_store_binary(int argc, VALUE *argv, VALUE self)
|
|
1259
1259
|
offset = 0;
|
1260
1260
|
}
|
1261
1261
|
|
1262
|
-
|
1263
|
-
size =
|
1264
|
-
velmsz = rb_const_get(
|
1262
|
+
CumoGetNArray(self,na);
|
1263
|
+
size = CUMO_NA_SIZE(na);
|
1264
|
+
velmsz = rb_const_get(rb_obj_class(self), cumo_id_element_byte_size);
|
1265
1265
|
if (FIXNUM_P(velmsz)) {
|
1266
1266
|
byte_size = size * NUM2SIZET(velmsz);
|
1267
1267
|
} else {
|
@@ -1271,7 +1271,7 @@ nary_store_binary(int argc, VALUE *argv, VALUE self)
|
|
1271
1271
|
rb_raise(rb_eArgError, "string is too short to store");
|
1272
1272
|
}
|
1273
1273
|
|
1274
|
-
ptr =
|
1274
|
+
ptr = cumo_na_get_pointer_for_write(self);
|
1275
1275
|
memcpy(ptr, RSTRING_PTR(vstr)+offset, byte_size);
|
1276
1276
|
|
1277
1277
|
return SIZET2NUM(byte_size);
|
@@ -1283,26 +1283,26 @@ nary_store_binary(int argc, VALUE *argv, VALUE self)
|
|
1283
1283
|
@return [String] String object containing binary raw data.
|
1284
1284
|
*/
|
1285
1285
|
static VALUE
|
1286
|
-
|
1286
|
+
cumo_na_to_binary(VALUE self)
|
1287
1287
|
{
|
1288
1288
|
size_t len, offset=0;
|
1289
1289
|
char *ptr;
|
1290
1290
|
VALUE str;
|
1291
|
-
|
1291
|
+
cumo_narray_t *na;
|
1292
1292
|
|
1293
|
-
|
1293
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("cumo_na_to_binary", "any");
|
1294
1294
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
1295
1295
|
|
1296
|
-
|
1297
|
-
if (na->type ==
|
1298
|
-
if (
|
1299
|
-
offset =
|
1296
|
+
CumoGetNArray(self,na);
|
1297
|
+
if (na->type == CUMO_NARRAY_VIEW_T) {
|
1298
|
+
if (cumo_na_check_contiguous(self)==Qtrue) {
|
1299
|
+
offset = CUMO_NA_VIEW_OFFSET(na);
|
1300
1300
|
} else {
|
1301
|
-
self = rb_funcall(self,
|
1301
|
+
self = rb_funcall(self,cumo_id_dup,0);
|
1302
1302
|
}
|
1303
1303
|
}
|
1304
|
-
len = NUM2SIZET(
|
1305
|
-
ptr =
|
1304
|
+
len = NUM2SIZET(cumo_na_byte_size(self));
|
1305
|
+
ptr = cumo_na_get_pointer_for_read(self);
|
1306
1306
|
str = rb_usascii_str_new(ptr+offset,len);
|
1307
1307
|
RB_GC_GUARD(self);
|
1308
1308
|
return str;
|
@@ -1314,39 +1314,39 @@ nary_to_binary(VALUE self)
|
|
1314
1314
|
@return [Array] Array containing marshal data.
|
1315
1315
|
*/
|
1316
1316
|
static VALUE
|
1317
|
-
|
1317
|
+
cumo_na_marshal_dump(VALUE self)
|
1318
1318
|
{
|
1319
1319
|
VALUE a;
|
1320
1320
|
|
1321
|
-
|
1321
|
+
CUMO_SHOW_SYNCHRONIZE_WARNING_ONCE("cumo_na_marshal_dump", "any");
|
1322
1322
|
cumo_cuda_runtime_check_status(cudaDeviceSynchronize());
|
1323
1323
|
|
1324
1324
|
a = rb_ary_new();
|
1325
1325
|
rb_ary_push(a, INT2FIX(1)); // version
|
1326
|
-
rb_ary_push(a,
|
1327
|
-
rb_ary_push(a, INT2FIX(
|
1328
|
-
if (
|
1329
|
-
|
1326
|
+
rb_ary_push(a, cumo_na_shape(self));
|
1327
|
+
rb_ary_push(a, INT2FIX(CUMO_NA_FLAG0(self)));
|
1328
|
+
if (rb_obj_class(self) == cumo_cRObject) {
|
1329
|
+
cumo_narray_t *na;
|
1330
1330
|
VALUE *ptr;
|
1331
1331
|
size_t offset=0;
|
1332
|
-
|
1333
|
-
if (na->type ==
|
1334
|
-
if (
|
1335
|
-
offset =
|
1332
|
+
CumoGetNArray(self,na);
|
1333
|
+
if (na->type == CUMO_NARRAY_VIEW_T) {
|
1334
|
+
if (cumo_na_check_contiguous(self)==Qtrue) {
|
1335
|
+
offset = CUMO_NA_VIEW_OFFSET(na);
|
1336
1336
|
} else {
|
1337
|
-
self = rb_funcall(self,
|
1337
|
+
self = rb_funcall(self,cumo_id_dup,0);
|
1338
1338
|
}
|
1339
1339
|
}
|
1340
|
-
ptr = (VALUE*)
|
1341
|
-
rb_ary_push(a, rb_ary_new4(
|
1340
|
+
ptr = (VALUE*)cumo_na_get_pointer_for_read(self);
|
1341
|
+
rb_ary_push(a, rb_ary_new4(CUMO_NA_SIZE(na), ptr+offset));
|
1342
1342
|
} else {
|
1343
|
-
rb_ary_push(a,
|
1343
|
+
rb_ary_push(a, cumo_na_to_binary(self));
|
1344
1344
|
}
|
1345
1345
|
RB_GC_GUARD(self);
|
1346
1346
|
return a;
|
1347
1347
|
}
|
1348
1348
|
|
1349
|
-
static VALUE
|
1349
|
+
static VALUE cumo_na_inplace( VALUE self );
|
1350
1350
|
/*
|
1351
1351
|
Load marshal data.
|
1352
1352
|
@overload marshal_load(data)
|
@@ -1354,7 +1354,7 @@ static VALUE na_inplace( VALUE self );
|
|
1354
1354
|
@return [nil]
|
1355
1355
|
*/
|
1356
1356
|
static VALUE
|
1357
|
-
|
1357
|
+
cumo_na_marshal_load(VALUE self, VALUE a)
|
1358
1358
|
{
|
1359
1359
|
VALUE v;
|
1360
1360
|
|
@@ -1368,26 +1368,26 @@ nary_marshal_load(VALUE self, VALUE a)
|
|
1368
1368
|
rb_raise(rb_eArgError,"NArray marshal version %d is not supported "
|
1369
1369
|
"(only version 1)", NUM2INT(RARRAY_AREF(a,0)));
|
1370
1370
|
}
|
1371
|
-
|
1372
|
-
|
1371
|
+
cumo_na_initialize(self,RARRAY_AREF(a,1));
|
1372
|
+
CUMO_NA_FL0_SET(self,FIX2INT(RARRAY_AREF(a,2)));
|
1373
1373
|
v = RARRAY_AREF(a,3);
|
1374
|
-
if (
|
1375
|
-
|
1374
|
+
if (rb_obj_class(self) == cumo_cRObject) {
|
1375
|
+
cumo_narray_t *na;
|
1376
1376
|
char *ptr;
|
1377
1377
|
if (TYPE(v) != T_ARRAY) {
|
1378
1378
|
rb_raise(rb_eArgError,"RObject content should be array");
|
1379
1379
|
}
|
1380
|
-
|
1381
|
-
if (RARRAY_LEN(v) != (long)
|
1380
|
+
CumoGetNArray(self,na);
|
1381
|
+
if (RARRAY_LEN(v) != (long)CUMO_NA_SIZE(na)) {
|
1382
1382
|
rb_raise(rb_eArgError,"RObject content size mismatch");
|
1383
1383
|
}
|
1384
|
-
ptr =
|
1385
|
-
memcpy(ptr, RARRAY_PTR(v),
|
1384
|
+
ptr = cumo_na_get_pointer_for_write(self);
|
1385
|
+
memcpy(ptr, RARRAY_PTR(v), CUMO_NA_SIZE(na)*sizeof(VALUE));
|
1386
1386
|
} else {
|
1387
|
-
|
1388
|
-
if (
|
1389
|
-
rb_funcall(
|
1390
|
-
|
1387
|
+
cumo_na_store_binary(1,&v,self);
|
1388
|
+
if (CUMO_TEST_BYTE_SWAPPED(self)) {
|
1389
|
+
rb_funcall(cumo_na_inplace(self),cumo_id_to_host,0);
|
1390
|
+
CUMO_REVERSE_ENDIAN(self); // correct behavior??
|
1391
1391
|
}
|
1392
1392
|
}
|
1393
1393
|
RB_GC_GUARD(a);
|
@@ -1402,9 +1402,9 @@ nary_marshal_load(VALUE self, VALUE a)
|
|
1402
1402
|
@return [Cumo::NArray]
|
1403
1403
|
*/
|
1404
1404
|
static VALUE
|
1405
|
-
|
1405
|
+
cumo_na_cast_to(VALUE obj, VALUE type)
|
1406
1406
|
{
|
1407
|
-
return rb_funcall(type,
|
1407
|
+
return rb_funcall(type, cumo_id_cast, 1, obj);
|
1408
1408
|
}
|
1409
1409
|
|
1410
1410
|
|
@@ -1412,7 +1412,7 @@ nary_cast_to(VALUE obj, VALUE type)
|
|
1412
1412
|
// reduce is dimension indicies to reduce in reduction kernel (in bits), e.g., for an array of shape:
|
1413
1413
|
// [2,3,4], 111b for sum(), 010b for sum(axis: 1), 110b for sum(axis: [1,2])
|
1414
1414
|
bool
|
1415
|
-
|
1415
|
+
cumo_na_test_reduce(VALUE reduce, int dim)
|
1416
1416
|
{
|
1417
1417
|
size_t m;
|
1418
1418
|
|
@@ -1423,40 +1423,40 @@ na_test_reduce(VALUE reduce, int dim)
|
|
1423
1423
|
if (m==0) return 1;
|
1424
1424
|
return (m & (1u<<dim)) ? 1 : 0;
|
1425
1425
|
} else {
|
1426
|
-
return (rb_funcall(reduce,
|
1426
|
+
return (rb_funcall(reduce,cumo_id_bracket,1,INT2FIX(dim))==INT2FIX(1)) ?
|
1427
1427
|
1 : 0 ;
|
1428
1428
|
}
|
1429
1429
|
}
|
1430
1430
|
|
1431
1431
|
|
1432
1432
|
static VALUE
|
1433
|
-
|
1433
|
+
cumo_na_get_reduce_flag_from_narray(int naryc, VALUE *naryv, int *max_arg)
|
1434
1434
|
{
|
1435
1435
|
int ndim, ndim0;
|
1436
1436
|
int rowmaj;
|
1437
1437
|
int i;
|
1438
1438
|
size_t j;
|
1439
|
-
|
1439
|
+
cumo_narray_t *na;
|
1440
1440
|
VALUE reduce;
|
1441
1441
|
|
1442
1442
|
if (naryc<1) {
|
1443
1443
|
rb_raise(rb_eRuntimeError,"must be positive: naryc=%d", naryc);
|
1444
1444
|
}
|
1445
|
-
|
1445
|
+
CumoGetNArray(naryv[0],na);
|
1446
1446
|
if (na->size==0) {
|
1447
|
-
rb_raise(
|
1447
|
+
rb_raise(cumo_na_eShapeError,"cannot reduce empty NArray");
|
1448
1448
|
}
|
1449
1449
|
reduce = na->reduce;
|
1450
1450
|
ndim = ndim0 = na->ndim;
|
1451
1451
|
if (max_arg) *max_arg = 0;
|
1452
|
-
rowmaj =
|
1452
|
+
rowmaj = CUMO_TEST_COLUMN_MAJOR(naryv[0]);
|
1453
1453
|
for (i=0; i<naryc; i++) {
|
1454
|
-
|
1454
|
+
CumoGetNArray(naryv[i],na);
|
1455
1455
|
if (na->size==0) {
|
1456
|
-
rb_raise(
|
1456
|
+
rb_raise(cumo_na_eShapeError,"cannot reduce empty NArray");
|
1457
1457
|
}
|
1458
|
-
if (
|
1459
|
-
rb_raise(
|
1458
|
+
if (CUMO_TEST_COLUMN_MAJOR(naryv[i]) != rowmaj) {
|
1459
|
+
rb_raise(cumo_na_eDimensionError,"dimension order is different");
|
1460
1460
|
}
|
1461
1461
|
if (na->ndim > ndim) { // maximum dimension
|
1462
1462
|
ndim = na->ndim;
|
@@ -1472,7 +1472,7 @@ na_get_reduce_flag_from_narray(int naryc, VALUE *naryv, int *max_arg)
|
|
1472
1472
|
|
1473
1473
|
|
1474
1474
|
static VALUE
|
1475
|
-
|
1475
|
+
cumo_na_get_reduce_flag_from_axes(VALUE cumo_na_obj, VALUE axes)
|
1476
1476
|
{
|
1477
1477
|
int i, r;
|
1478
1478
|
int ndim, rowmaj;
|
@@ -1483,11 +1483,11 @@ na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes)
|
|
1483
1483
|
VALUE v;
|
1484
1484
|
size_t m;
|
1485
1485
|
VALUE reduce;
|
1486
|
-
|
1486
|
+
cumo_narray_t *na;
|
1487
1487
|
|
1488
|
-
|
1488
|
+
CumoGetNArray(cumo_na_obj,na);
|
1489
1489
|
ndim = na->ndim;
|
1490
|
-
rowmaj =
|
1490
|
+
rowmaj = CUMO_TEST_COLUMN_MAJOR(cumo_na_obj);
|
1491
1491
|
|
1492
1492
|
m = 0;
|
1493
1493
|
reduce = Qnil;
|
@@ -1499,16 +1499,16 @@ na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes)
|
|
1499
1499
|
beg = FIX2INT(v);
|
1500
1500
|
if (beg<0) beg+=ndim;
|
1501
1501
|
if (beg>=ndim || beg<0) {
|
1502
|
-
rb_raise(
|
1502
|
+
rb_raise(cumo_na_eDimensionError,"dimension is out of range");
|
1503
1503
|
}
|
1504
1504
|
len = 1;
|
1505
1505
|
step = 0;
|
1506
1506
|
//printf("beg=%d step=%d len=%d\n",beg,step,len);
|
1507
1507
|
} else if (rb_obj_is_kind_of(v,rb_cRange) ||
|
1508
|
-
rb_obj_is_kind_of(v,
|
1509
|
-
|
1508
|
+
rb_obj_is_kind_of(v,cumo_na_cStep)) {
|
1509
|
+
cumo_na_step_array_index( v, ndim, &len, &beg, &step );
|
1510
1510
|
} else {
|
1511
|
-
rb_raise(
|
1511
|
+
rb_raise(cumo_na_eDimensionError, "invalid dimension argument %s",
|
1512
1512
|
rb_obj_classname(v));
|
1513
1513
|
}
|
1514
1514
|
for (j=0; j<len; j++) {
|
@@ -1524,7 +1524,7 @@ na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes)
|
|
1524
1524
|
reduce = SIZET2NUM(m);
|
1525
1525
|
}
|
1526
1526
|
}
|
1527
|
-
v = rb_funcall( INT2FIX(1),
|
1527
|
+
v = rb_funcall( INT2FIX(1), cumo_id_shift_left, 1, INT2FIX(r) );
|
1528
1528
|
reduce = rb_funcall( reduce, '|', 1, v );
|
1529
1529
|
}
|
1530
1530
|
}
|
@@ -1534,8 +1534,8 @@ na_get_reduce_flag_from_axes(VALUE na_obj, VALUE axes)
|
|
1534
1534
|
|
1535
1535
|
|
1536
1536
|
VALUE
|
1537
|
-
|
1538
|
-
|
1537
|
+
cumo_na_reduce_options(VALUE axes, VALUE *opts, int naryc, VALUE *naryv,
|
1538
|
+
cumo_ndfunc_t *ndf)
|
1539
1539
|
{
|
1540
1540
|
int max_arg;
|
1541
1541
|
VALUE reduce;
|
@@ -1556,26 +1556,26 @@ nary_reduce_options(VALUE axes, VALUE *opts, int naryc, VALUE *naryv,
|
|
1556
1556
|
// option: keepdims
|
1557
1557
|
if (opts[1] != Qundef) {
|
1558
1558
|
if (RTEST(opts[1]))
|
1559
|
-
ndf->flag |=
|
1559
|
+
ndf->flag |= CUMO_NDF_KEEP_DIM;
|
1560
1560
|
}
|
1561
1561
|
}
|
1562
1562
|
|
1563
|
-
reduce =
|
1563
|
+
reduce = cumo_na_get_reduce_flag_from_narray(naryc, naryv, &max_arg);
|
1564
1564
|
|
1565
1565
|
if (NIL_P(axes)) return reduce;
|
1566
1566
|
|
1567
|
-
return
|
1567
|
+
return cumo_na_get_reduce_flag_from_axes(naryv[max_arg], axes);
|
1568
1568
|
}
|
1569
1569
|
|
1570
1570
|
|
1571
1571
|
VALUE
|
1572
|
-
|
1573
|
-
|
1572
|
+
cumo_na_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv,
|
1573
|
+
cumo_ndfunc_t *ndf, cumo_na_iter_func_t iter_nan)
|
1574
1574
|
{
|
1575
1575
|
long narg;
|
1576
1576
|
VALUE axes;
|
1577
1577
|
VALUE kw_hash = Qnil;
|
1578
|
-
ID kw_table[3] = {
|
1578
|
+
ID kw_table[3] = {cumo_id_axis,cumo_id_keepdims,cumo_id_nan};
|
1579
1579
|
VALUE opts[3] = {Qundef,Qundef,Qundef};
|
1580
1580
|
|
1581
1581
|
narg = rb_scan_args(argc, argv, "*:", &axes, &kw_hash);
|
@@ -1589,15 +1589,15 @@ nary_reduce_dimension(int argc, VALUE *argv, int naryc, VALUE *naryv,
|
|
1589
1589
|
}
|
1590
1590
|
}
|
1591
1591
|
|
1592
|
-
return
|
1592
|
+
return cumo_na_reduce_options((narg)?axes:Qnil, opts, naryc, naryv, ndf);
|
1593
1593
|
}
|
1594
1594
|
|
1595
1595
|
/*
|
1596
1596
|
Return true if column major.
|
1597
1597
|
*/
|
1598
|
-
static VALUE
|
1598
|
+
static VALUE cumo_na_column_major_p( VALUE self )
|
1599
1599
|
{
|
1600
|
-
if (
|
1600
|
+
if (CUMO_TEST_COLUMN_MAJOR(self))
|
1601
1601
|
return Qtrue;
|
1602
1602
|
else
|
1603
1603
|
return Qfalse;
|
@@ -1606,9 +1606,9 @@ static VALUE na_column_major_p( VALUE self )
|
|
1606
1606
|
/*
|
1607
1607
|
Return true if row major.
|
1608
1608
|
*/
|
1609
|
-
static VALUE
|
1609
|
+
static VALUE cumo_na_row_major_p( VALUE self )
|
1610
1610
|
{
|
1611
|
-
if (
|
1611
|
+
if (CUMO_TEST_ROW_MAJOR(self))
|
1612
1612
|
return Qtrue;
|
1613
1613
|
else
|
1614
1614
|
return Qfalse;
|
@@ -1618,9 +1618,9 @@ static VALUE na_row_major_p( VALUE self )
|
|
1618
1618
|
/*
|
1619
1619
|
Return true if byte swapped.
|
1620
1620
|
*/
|
1621
|
-
static VALUE
|
1621
|
+
static VALUE cumo_na_byte_swapped_p( VALUE self )
|
1622
1622
|
{
|
1623
|
-
if (
|
1623
|
+
if (CUMO_TEST_BYTE_SWAPPED(self))
|
1624
1624
|
return Qtrue;
|
1625
1625
|
return Qfalse;
|
1626
1626
|
}
|
@@ -1628,9 +1628,9 @@ static VALUE na_byte_swapped_p( VALUE self )
|
|
1628
1628
|
/*
|
1629
1629
|
Return true if not byte swapped.
|
1630
1630
|
*/
|
1631
|
-
static VALUE
|
1631
|
+
static VALUE cumo_na_host_order_p( VALUE self )
|
1632
1632
|
{
|
1633
|
-
if (
|
1633
|
+
if (CUMO_TEST_BYTE_SWAPPED(self))
|
1634
1634
|
return Qfalse;
|
1635
1635
|
return Qtrue;
|
1636
1636
|
}
|
@@ -1640,11 +1640,11 @@ static VALUE na_host_order_p( VALUE self )
|
|
1640
1640
|
Returns view of narray with inplace flagged.
|
1641
1641
|
@return [Cumo::NArray] view of narray with inplace flag.
|
1642
1642
|
*/
|
1643
|
-
static VALUE
|
1643
|
+
static VALUE cumo_na_inplace( VALUE self )
|
1644
1644
|
{
|
1645
1645
|
VALUE view = self;
|
1646
|
-
view =
|
1647
|
-
|
1646
|
+
view = cumo_na_make_view(self);
|
1647
|
+
CUMO_SET_INPLACE(view);
|
1648
1648
|
return view;
|
1649
1649
|
}
|
1650
1650
|
|
@@ -1652,18 +1652,18 @@ static VALUE na_inplace( VALUE self )
|
|
1652
1652
|
Set inplace flag to self.
|
1653
1653
|
@return [Cumo::NArray] self
|
1654
1654
|
*/
|
1655
|
-
static VALUE
|
1655
|
+
static VALUE cumo_na_inplace_bang( VALUE self )
|
1656
1656
|
{
|
1657
|
-
|
1657
|
+
CUMO_SET_INPLACE(self);
|
1658
1658
|
return self;
|
1659
1659
|
}
|
1660
1660
|
|
1661
1661
|
/*
|
1662
1662
|
Return true if inplace flagged.
|
1663
1663
|
*/
|
1664
|
-
static VALUE
|
1664
|
+
static VALUE cumo_na_inplace_p( VALUE self )
|
1665
1665
|
{
|
1666
|
-
if (
|
1666
|
+
if (CUMO_TEST_INPLACE(self))
|
1667
1667
|
return Qtrue;
|
1668
1668
|
else
|
1669
1669
|
return Qfalse;
|
@@ -1673,30 +1673,30 @@ static VALUE na_inplace_p( VALUE self )
|
|
1673
1673
|
Unset inplace flag to self.
|
1674
1674
|
@return [Cumo::NArray] self
|
1675
1675
|
*/
|
1676
|
-
static VALUE
|
1676
|
+
static VALUE cumo_na_out_of_place_bang( VALUE self )
|
1677
1677
|
{
|
1678
|
-
|
1678
|
+
CUMO_UNCUMO_SET_INPLACE(self);
|
1679
1679
|
return self;
|
1680
1680
|
}
|
1681
1681
|
|
1682
|
-
int
|
1682
|
+
int cumo_na_debug_flag=0;
|
1683
1683
|
|
1684
|
-
static VALUE
|
1684
|
+
static VALUE cumo_na_debug_set(VALUE mod, VALUE flag)
|
1685
1685
|
{
|
1686
|
-
|
1686
|
+
cumo_na_debug_flag = RTEST(flag);
|
1687
1687
|
return Qnil;
|
1688
1688
|
}
|
1689
1689
|
|
1690
|
-
static double
|
1690
|
+
static double cumo_na_profile_value=0;
|
1691
1691
|
|
1692
|
-
static VALUE
|
1692
|
+
static VALUE cumo_na_profile(VALUE mod)
|
1693
1693
|
{
|
1694
|
-
return rb_float_new(
|
1694
|
+
return rb_float_new(cumo_na_profile_value);
|
1695
1695
|
}
|
1696
1696
|
|
1697
|
-
static VALUE
|
1697
|
+
static VALUE cumo_na_profile_set(VALUE mod, VALUE val)
|
1698
1698
|
{
|
1699
|
-
|
1699
|
+
cumo_na_profile_value = NUM2DBL(val);
|
1700
1700
|
return val;
|
1701
1701
|
}
|
1702
1702
|
|
@@ -1706,10 +1706,10 @@ static VALUE na_profile_set(VALUE mod, VALUE val)
|
|
1706
1706
|
@overload inspect_rows
|
1707
1707
|
@return [Integer or nil] the number of rows.
|
1708
1708
|
*/
|
1709
|
-
static VALUE
|
1709
|
+
static VALUE cumo_na_inspect_rows(VALUE mod)
|
1710
1710
|
{
|
1711
|
-
if (
|
1712
|
-
return INT2NUM(
|
1711
|
+
if (cumo_na_inspect_rows_ > 0) {
|
1712
|
+
return INT2NUM(cumo_na_inspect_rows_);
|
1713
1713
|
} else {
|
1714
1714
|
return Qnil;
|
1715
1715
|
}
|
@@ -1721,12 +1721,12 @@ static VALUE na_inspect_rows(VALUE mod)
|
|
1721
1721
|
@param [Integer or nil] rows the number of rows
|
1722
1722
|
@return [nil]
|
1723
1723
|
*/
|
1724
|
-
static VALUE
|
1724
|
+
static VALUE cumo_na_inspect_rows_set(VALUE mod, VALUE num)
|
1725
1725
|
{
|
1726
1726
|
if (RTEST(num)) {
|
1727
|
-
|
1727
|
+
cumo_na_inspect_rows_ = NUM2INT(num);
|
1728
1728
|
} else {
|
1729
|
-
|
1729
|
+
cumo_na_inspect_rows_ = 0;
|
1730
1730
|
}
|
1731
1731
|
return Qnil;
|
1732
1732
|
}
|
@@ -1736,10 +1736,10 @@ static VALUE na_inspect_rows_set(VALUE mod, VALUE num)
|
|
1736
1736
|
@overload inspect_cols
|
1737
1737
|
@return [Integer or nil] the number of cols.
|
1738
1738
|
*/
|
1739
|
-
static VALUE
|
1739
|
+
static VALUE cumo_na_inspect_cols(VALUE mod)
|
1740
1740
|
{
|
1741
|
-
if (
|
1742
|
-
return INT2NUM(
|
1741
|
+
if (cumo_na_inspect_cols_ > 0) {
|
1742
|
+
return INT2NUM(cumo_na_inspect_cols_);
|
1743
1743
|
} else {
|
1744
1744
|
return Qnil;
|
1745
1745
|
}
|
@@ -1751,12 +1751,12 @@ static VALUE na_inspect_cols(VALUE mod)
|
|
1751
1751
|
@param [Integer or nil] cols the number of cols
|
1752
1752
|
@return [nil]
|
1753
1753
|
*/
|
1754
|
-
static VALUE
|
1754
|
+
static VALUE cumo_na_inspect_cols_set(VALUE mod, VALUE num)
|
1755
1755
|
{
|
1756
1756
|
if (RTEST(num)) {
|
1757
|
-
|
1757
|
+
cumo_na_inspect_cols_ = NUM2INT(num);
|
1758
1758
|
} else {
|
1759
|
-
|
1759
|
+
cumo_na_inspect_cols_ = 0;
|
1760
1760
|
}
|
1761
1761
|
return Qnil;
|
1762
1762
|
}
|
@@ -1770,19 +1770,19 @@ static VALUE na_inspect_cols_set(VALUE mod, VALUE num)
|
|
1770
1770
|
@return [Boolean] true if self and other is equal.
|
1771
1771
|
*/
|
1772
1772
|
static VALUE
|
1773
|
-
|
1773
|
+
cumo_na_equal(VALUE self, volatile VALUE other)
|
1774
1774
|
{
|
1775
1775
|
volatile VALUE vbool;
|
1776
|
-
|
1776
|
+
cumo_narray_t *na1, *na2;
|
1777
1777
|
int i;
|
1778
1778
|
|
1779
|
-
|
1779
|
+
CumoGetNArray(self,na1);
|
1780
1780
|
|
1781
1781
|
if (!rb_obj_is_kind_of(other,cNArray)) {
|
1782
|
-
other = rb_funcall(
|
1782
|
+
other = rb_funcall(rb_obj_class(self), cumo_id_cast, 1, other);
|
1783
1783
|
}
|
1784
1784
|
|
1785
|
-
|
1785
|
+
CumoGetNArray(other,na2);
|
1786
1786
|
if (na1->ndim != na2->ndim) {
|
1787
1787
|
return Qfalse;
|
1788
1788
|
}
|
@@ -1791,8 +1791,8 @@ na_equal(VALUE self, volatile VALUE other)
|
|
1791
1791
|
return Qfalse;
|
1792
1792
|
}
|
1793
1793
|
}
|
1794
|
-
vbool = rb_funcall(self,
|
1795
|
-
return (rb_funcall(vbool,
|
1794
|
+
vbool = rb_funcall(self, cumo_id_eq, 1, other);
|
1795
|
+
return (rb_funcall(vbool, cumo_id_count_false_cpu, 0)==INT2FIX(0)) ? Qtrue : Qfalse;
|
1796
1796
|
}
|
1797
1797
|
|
1798
1798
|
/*
|
@@ -1803,18 +1803,18 @@ na_equal(VALUE self, volatile VALUE other)
|
|
1803
1803
|
VALUE
|
1804
1804
|
cumo_na_free_data(VALUE self)
|
1805
1805
|
{
|
1806
|
-
|
1807
|
-
|
1806
|
+
cumo_narray_t *na;
|
1807
|
+
CumoGetNArray(self, na);
|
1808
1808
|
|
1809
|
-
if (na->type ==
|
1810
|
-
void *ptr =
|
1809
|
+
if (na->type == CUMO_NARRAY_DATA_T) {
|
1810
|
+
void *ptr = CUMO_NA_DATA_PTR(na);
|
1811
1811
|
if (ptr != NULL) {
|
1812
1812
|
if (cumo_cuda_runtime_is_device_memory(ptr)) {
|
1813
1813
|
cumo_cuda_runtime_free(ptr);
|
1814
1814
|
} else {
|
1815
1815
|
xfree(ptr);
|
1816
1816
|
}
|
1817
|
-
|
1817
|
+
CUMO_NA_DATA_PTR(na) = NULL;
|
1818
1818
|
return Qtrue;
|
1819
1819
|
}
|
1820
1820
|
}
|
@@ -1845,104 +1845,104 @@ Init_cumo_narray()
|
|
1845
1845
|
|
1846
1846
|
rb_define_const(cNArray, "VERSION", rb_str_new2(CUMO_VERSION));
|
1847
1847
|
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1848
|
+
cumo_na_eCastError = rb_define_class_under(cNArray, "CastError", rb_eStandardError);
|
1849
|
+
cumo_na_eShapeError = rb_define_class_under(cNArray, "ShapeError", rb_eStandardError);
|
1850
|
+
cumo_na_eOperationError = rb_define_class_under(cNArray, "OperationError", rb_eStandardError);
|
1851
|
+
cumo_na_eDimensionError = rb_define_class_under(cNArray, "DimensionError", rb_eStandardError);
|
1852
|
+
cumo_na_eValueError = rb_define_class_under(cNArray, "ValueError", rb_eStandardError);
|
1853
1853
|
|
1854
|
-
rb_define_singleton_method(cNArray, "debug=",
|
1855
|
-
rb_define_singleton_method(cNArray, "profile",
|
1856
|
-
rb_define_singleton_method(cNArray, "profile=",
|
1854
|
+
rb_define_singleton_method(cNArray, "debug=", cumo_na_debug_set, 1);
|
1855
|
+
rb_define_singleton_method(cNArray, "profile", cumo_na_profile, 0);
|
1856
|
+
rb_define_singleton_method(cNArray, "profile=", cumo_na_profile_set, 1);
|
1857
1857
|
|
1858
|
-
rb_define_singleton_method(cNArray, "inspect_rows",
|
1859
|
-
rb_define_singleton_method(cNArray, "inspect_rows=",
|
1860
|
-
rb_define_singleton_method(cNArray, "inspect_cols",
|
1861
|
-
rb_define_singleton_method(cNArray, "inspect_cols=",
|
1858
|
+
rb_define_singleton_method(cNArray, "inspect_rows", cumo_na_inspect_rows, 0);
|
1859
|
+
rb_define_singleton_method(cNArray, "inspect_rows=", cumo_na_inspect_rows_set, 1);
|
1860
|
+
rb_define_singleton_method(cNArray, "inspect_cols", cumo_na_inspect_cols, 0);
|
1861
|
+
rb_define_singleton_method(cNArray, "inspect_cols=", cumo_na_inspect_cols_set, 1);
|
1862
1862
|
|
1863
1863
|
/* Ruby allocation framework */
|
1864
1864
|
rb_undef_alloc_func(cNArray);
|
1865
|
-
rb_define_method(cNArray, "initialize",
|
1866
|
-
rb_define_method(cNArray, "initialize_copy",
|
1865
|
+
rb_define_method(cNArray, "initialize", cumo_na_initialize, -2);
|
1866
|
+
rb_define_method(cNArray, "initialize_copy", cumo_na_initialize_copy, 1);
|
1867
1867
|
|
1868
1868
|
rb_define_method(cNArray, "free", cumo_na_free_data, 0);
|
1869
1869
|
|
1870
|
-
rb_define_singleton_method(cNArray, "zeros",
|
1871
|
-
rb_define_singleton_method(cNArray, "ones",
|
1872
|
-
rb_define_singleton_method(cNArray, "linspace",
|
1873
|
-
rb_define_singleton_method(cNArray, "logspace",
|
1874
|
-
rb_define_singleton_method(cNArray, "eye",
|
1870
|
+
rb_define_singleton_method(cNArray, "zeros", cumo_na_s_zeros, -1);
|
1871
|
+
rb_define_singleton_method(cNArray, "ones", cumo_na_s_ones, -1);
|
1872
|
+
rb_define_singleton_method(cNArray, "linspace", cumo_na_s_linspace, -1);
|
1873
|
+
rb_define_singleton_method(cNArray, "logspace", cumo_na_s_logspace, -1);
|
1874
|
+
rb_define_singleton_method(cNArray, "eye", cumo_na_s_eye, -1);
|
1875
1875
|
|
1876
|
-
rb_define_method(cNArray, "size",
|
1876
|
+
rb_define_method(cNArray, "size", cumo_na_size, 0);
|
1877
1877
|
rb_define_alias (cNArray, "length","size");
|
1878
1878
|
rb_define_alias (cNArray, "total","size");
|
1879
|
-
rb_define_method(cNArray, "shape",
|
1880
|
-
rb_define_method(cNArray, "ndim",
|
1879
|
+
rb_define_method(cNArray, "shape", cumo_na_shape, 0);
|
1880
|
+
rb_define_method(cNArray, "ndim", cumo_na_ndim,0);
|
1881
1881
|
rb_define_alias (cNArray, "rank","ndim");
|
1882
|
-
rb_define_method(cNArray, "empty?",
|
1882
|
+
rb_define_method(cNArray, "empty?", cumo_na_empty_p, 0);
|
1883
1883
|
|
1884
|
-
rb_define_method(cNArray, "debug_info",
|
1884
|
+
rb_define_method(cNArray, "debug_info", cumo_na_debug_info, 0);
|
1885
1885
|
|
1886
|
-
rb_define_method(cNArray, "contiguous?",
|
1886
|
+
rb_define_method(cNArray, "contiguous?", cumo_na_check_contiguous, 0);
|
1887
1887
|
|
1888
|
-
rb_define_method(cNArray, "view",
|
1889
|
-
rb_define_method(cNArray, "expand_dims",
|
1890
|
-
rb_define_method(cNArray, "reverse",
|
1888
|
+
rb_define_method(cNArray, "view", cumo_na_make_view, 0);
|
1889
|
+
rb_define_method(cNArray, "expand_dims", cumo_na_expand_dims, 1);
|
1890
|
+
rb_define_method(cNArray, "reverse", cumo_na_reverse, -1);
|
1891
1891
|
|
1892
1892
|
rb_define_singleton_method(cNArray, "upcast", cumo_na_upcast, 1);
|
1893
|
-
rb_define_singleton_method(cNArray, "byte_size",
|
1893
|
+
rb_define_singleton_method(cNArray, "byte_size", cumo_na_s_byte_size, 0);
|
1894
1894
|
|
1895
|
-
rb_define_singleton_method(cNArray, "from_binary",
|
1895
|
+
rb_define_singleton_method(cNArray, "from_binary", cumo_na_s_from_binary, -1);
|
1896
1896
|
rb_define_alias (rb_singleton_class(cNArray), "from_string", "from_binary");
|
1897
|
-
rb_define_method(cNArray, "store_binary",
|
1898
|
-
rb_define_method(cNArray, "to_binary",
|
1897
|
+
rb_define_method(cNArray, "store_binary", cumo_na_store_binary, -1);
|
1898
|
+
rb_define_method(cNArray, "to_binary", cumo_na_to_binary, 0);
|
1899
1899
|
rb_define_alias (cNArray, "to_string", "to_binary");
|
1900
|
-
rb_define_method(cNArray, "marshal_dump",
|
1901
|
-
rb_define_method(cNArray, "marshal_load",
|
1900
|
+
rb_define_method(cNArray, "marshal_dump", cumo_na_marshal_dump, 0);
|
1901
|
+
rb_define_method(cNArray, "marshal_load", cumo_na_marshal_load, 1);
|
1902
1902
|
|
1903
|
-
rb_define_method(cNArray, "byte_size",
|
1903
|
+
rb_define_method(cNArray, "byte_size", cumo_na_byte_size, 0);
|
1904
1904
|
|
1905
|
-
rb_define_method(cNArray, "cast_to",
|
1905
|
+
rb_define_method(cNArray, "cast_to", cumo_na_cast_to, 1);
|
1906
1906
|
|
1907
|
-
rb_define_method(cNArray, "coerce",
|
1907
|
+
rb_define_method(cNArray, "coerce", cumo_na_coerce, 1);
|
1908
1908
|
|
1909
|
-
rb_define_method(cNArray, "column_major?",
|
1910
|
-
rb_define_method(cNArray, "row_major?",
|
1911
|
-
rb_define_method(cNArray, "byte_swapped?",
|
1912
|
-
rb_define_method(cNArray, "host_order?",
|
1909
|
+
rb_define_method(cNArray, "column_major?", cumo_na_column_major_p, 0);
|
1910
|
+
rb_define_method(cNArray, "row_major?", cumo_na_row_major_p, 0);
|
1911
|
+
rb_define_method(cNArray, "byte_swapped?", cumo_na_byte_swapped_p, 0);
|
1912
|
+
rb_define_method(cNArray, "host_order?", cumo_na_host_order_p, 0);
|
1913
1913
|
|
1914
|
-
rb_define_method(cNArray, "inplace",
|
1915
|
-
rb_define_method(cNArray, "inplace?",
|
1916
|
-
rb_define_method(cNArray, "inplace!",
|
1917
|
-
rb_define_method(cNArray, "out_of_place!",
|
1914
|
+
rb_define_method(cNArray, "inplace", cumo_na_inplace, 0);
|
1915
|
+
rb_define_method(cNArray, "inplace?", cumo_na_inplace_p, 0);
|
1916
|
+
rb_define_method(cNArray, "inplace!", cumo_na_inplace_bang, 0);
|
1917
|
+
rb_define_method(cNArray, "out_of_place!", cumo_na_out_of_place_bang, 0);
|
1918
1918
|
rb_define_alias (cNArray, "not_inplace!", "out_of_place!");
|
1919
1919
|
|
1920
|
-
rb_define_method(cNArray, "==",
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
//
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1920
|
+
rb_define_method(cNArray, "==", cumo_na_equal, 1);
|
1921
|
+
|
1922
|
+
cumo_id_allocate = rb_intern("allocate");
|
1923
|
+
cumo_id_contiguous_stride = rb_intern("CONTIGUOUS_STRIDE");
|
1924
|
+
//cumo_id_element_bit_size = rb_intern("ELEMENT_BIT_SIZE");
|
1925
|
+
cumo_id_element_byte_size = rb_intern("ELEMENT_BYTE_SIZE");
|
1926
|
+
|
1927
|
+
cumo_id_fill = rb_intern("fill");
|
1928
|
+
cumo_id_seq = rb_intern("seq");
|
1929
|
+
cumo_id_logseq = rb_intern("logseq");
|
1930
|
+
cumo_id_eye = rb_intern("eye");
|
1931
|
+
cumo_id_UPCAST = rb_intern("UPCAST");
|
1932
|
+
cumo_id_cast = rb_intern("cast");
|
1933
|
+
cumo_id_dup = rb_intern("dup");
|
1934
|
+
cumo_id_to_host = rb_intern("to_host");
|
1935
|
+
cumo_id_bracket = rb_intern("[]");
|
1936
|
+
cumo_id_shift_left = rb_intern("<<");
|
1937
|
+
cumo_id_eq = rb_intern("eq");
|
1938
|
+
cumo_id_count_false = rb_intern("count_false");
|
1939
|
+
cumo_id_count_false_cpu = rb_intern("count_false_cpu");
|
1940
|
+
cumo_id_axis = rb_intern("axis");
|
1941
|
+
cumo_id_nan = rb_intern("nan");
|
1942
|
+
cumo_id_keepdims = rb_intern("keepdims");
|
1943
|
+
|
1944
|
+
cumo_sym_reduce = ID2SYM(rb_intern("reduce"));
|
1945
|
+
cumo_sym_option = ID2SYM(rb_intern("option"));
|
1946
|
+
cumo_sym_loop_opt = ID2SYM(rb_intern("loop_opt"));
|
1947
|
+
cumo_sym_init = ID2SYM(rb_intern("init"));
|
1948
1948
|
}
|