numo-narray 0.9.0.4 → 0.9.0.5
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/README.md +11 -8
- data/Rakefile +9 -0
- data/ext/numo/narray/array.c +178 -47
- data/ext/numo/narray/data.c +105 -97
- data/ext/numo/narray/depend.erb +6 -7
- data/ext/numo/narray/gen/cogen.rb +30 -7
- data/ext/numo/narray/gen/def/bit.rb +17 -14
- data/ext/numo/narray/gen/def/dcomplex.rb +19 -15
- data/ext/numo/narray/gen/def/dfloat.rb +17 -13
- data/ext/numo/narray/gen/def/int16.rb +16 -12
- data/ext/numo/narray/gen/def/int32.rb +16 -12
- data/ext/numo/narray/gen/def/int64.rb +16 -12
- data/ext/numo/narray/gen/def/int8.rb +16 -12
- data/ext/numo/narray/gen/def/robject.rb +18 -14
- data/ext/numo/narray/gen/def/scomplex.rb +19 -15
- data/ext/numo/narray/gen/def/sfloat.rb +17 -13
- data/ext/numo/narray/gen/def/uint16.rb +16 -12
- data/ext/numo/narray/gen/def/uint32.rb +16 -12
- data/ext/numo/narray/gen/def/uint64.rb +16 -12
- data/ext/numo/narray/gen/def/uint8.rb +16 -12
- data/ext/numo/narray/gen/erbpp2.rb +324 -0
- data/ext/numo/narray/gen/narray_def.rb +252 -0
- data/ext/numo/narray/gen/spec.rb +141 -71
- data/ext/numo/narray/gen/tmpl/accum.c +22 -9
- data/ext/numo/narray/gen/tmpl/accum_binary.c +29 -13
- data/ext/numo/narray/gen/tmpl/accum_index.c +38 -16
- data/ext/numo/narray/gen/tmpl/alloc_func.c +107 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +1 -1
- data/ext/numo/narray/gen/tmpl/aref.c +1 -1
- data/ext/numo/narray/gen/tmpl/aset.c +4 -2
- data/ext/numo/narray/gen/tmpl/binary.c +4 -4
- data/ext/numo/narray/gen/tmpl/binary2.c +5 -5
- data/ext/numo/narray/gen/tmpl/binary_s.c +5 -5
- data/ext/numo/narray/gen/tmpl/bincount.c +4 -4
- data/ext/numo/narray/gen/tmpl/cast.c +9 -6
- data/ext/numo/narray/gen/tmpl/cast_array.c +4 -9
- data/ext/numo/narray/gen/tmpl/class.c +9 -0
- data/ext/numo/narray/gen/tmpl/clip.c +118 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +4 -2
- data/ext/numo/narray/gen/tmpl/cond_binary.c +5 -5
- data/ext/numo/narray/gen/tmpl/cond_unary.c +6 -6
- data/ext/numo/narray/gen/tmpl/cum.c +18 -9
- data/ext/numo/narray/gen/tmpl/each.c +2 -2
- data/ext/numo/narray/gen/tmpl/each_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/extract.c +2 -2
- data/ext/numo/narray/gen/tmpl/extract_data.c +48 -0
- data/ext/numo/narray/gen/tmpl/eye.c +3 -3
- data/ext/numo/narray/gen/tmpl/fill.c +2 -2
- data/ext/numo/narray/gen/tmpl/format.c +5 -5
- data/ext/numo/narray/gen/tmpl/format_to_a.c +4 -4
- data/ext/numo/narray/gen/tmpl/frexp.c +37 -0
- data/ext/numo/narray/gen/tmpl/init_class.c +20 -0
- data/ext/numo/narray/gen/tmpl/init_module.c +12 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +2 -2
- data/ext/numo/narray/gen/tmpl/lib.c +45 -0
- data/ext/numo/narray/gen/tmpl/logseq.c +1 -1
- data/ext/numo/narray/gen/tmpl/map_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/median.c +31 -8
- data/ext/numo/narray/gen/tmpl/minmax.c +24 -24
- data/ext/numo/narray/gen/tmpl/module.c +9 -0
- data/ext/numo/narray/gen/tmpl/new_dim0.c +12 -0
- data/ext/numo/narray/gen/tmpl/poly.c +3 -3
- data/ext/numo/narray/gen/tmpl/pow.c +1 -1
- data/ext/numo/narray/gen/tmpl/powint.c +1 -1
- data/ext/numo/narray/gen/tmpl/qsort.c +10 -3
- data/ext/numo/narray/gen/tmpl/rand.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand_norm.c +1 -1
- data/ext/numo/narray/gen/tmpl/seq.c +1 -1
- data/ext/numo/narray/gen/tmpl/set2.c +5 -5
- data/ext/numo/narray/gen/tmpl/sort.c +29 -14
- data/ext/numo/narray/gen/tmpl/sort_index.c +41 -20
- data/ext/numo/narray/gen/tmpl/store.c +11 -5
- data/ext/numo/narray/gen/tmpl/store_array.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_bit.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_from.c +1 -1
- data/ext/numo/narray/gen/tmpl/store_numeric.c +3 -16
- data/ext/numo/narray/gen/tmpl/to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl/unary.c +7 -7
- data/ext/numo/narray/gen/tmpl/unary2.c +8 -8
- data/ext/numo/narray/gen/tmpl/unary_ret2.c +33 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -5
- data/ext/numo/narray/gen/tmpl_bit/aref.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/binary.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/bit_count.c +8 -8
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +6 -6
- data/ext/numo/narray/gen/tmpl_bit/each.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/extract.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/fill.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/format.c +5 -5
- data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/inspect.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/mask.c +5 -5
- data/ext/numo/narray/gen/tmpl_bit/none_p.c +4 -4
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/store_from.c +1 -1
- data/ext/numo/narray/gen/tmpl_bit/to_a.c +2 -2
- data/ext/numo/narray/gen/tmpl_bit/unary.c +9 -9
- data/ext/numo/narray/gen/tmpl_bit/where.c +6 -6
- data/ext/numo/narray/gen/tmpl_bit/where2.c +8 -8
- data/ext/numo/narray/index.c +46 -30
- data/ext/numo/narray/math.c +12 -6
- data/ext/numo/narray/narray.c +242 -218
- data/ext/numo/narray/ndloop.c +17 -24
- data/ext/numo/narray/numo/intern.h +63 -67
- data/ext/numo/narray/numo/narray.h +38 -13
- data/ext/numo/narray/numo/ndloop.h +1 -1
- data/ext/numo/narray/numo/template.h +1 -1
- data/ext/numo/narray/numo/types/complex.h +8 -4
- data/ext/numo/narray/numo/types/complex_macro.h +118 -1
- data/ext/numo/narray/numo/types/float_macro.h +283 -6
- data/ext/numo/narray/numo/types/robj_macro.h +261 -9
- data/ext/numo/narray/numo/types/xint_macro.h +35 -0
- data/ext/numo/narray/struct.c +34 -15
- data/lib/erbpp.rb +5 -1
- data/lib/erbpp/line_number.rb +10 -3
- data/lib/erbpp/narray_def.rb +55 -25
- data/lib/numo/narray/extra.rb +638 -219
- data/numo-narray.gemspec +1 -0
- data/spec/narray_spec.rb +2 -2
- metadata +17 -14
- data/ext/numo/narray/gen/dtype.erb.c +0 -82
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +0 -22
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +0 -32
- data/ext/numo/narray/gen/tmpl_bit/cast.c +0 -37
- data/ext/numo/narray/gen/tmpl_bit/cast_array.c +0 -18
- data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +0 -22
- data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +0 -8
- data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +0 -94
- data/ext/numo/narray/gen/tmpl_bit/store.c +0 -32
- data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +0 -22
@@ -0,0 +1,118 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2, *p3, *p4;
|
6
|
+
ssize_t s1, s2, s3, s4;
|
7
|
+
dtype x, min, max;
|
8
|
+
INIT_COUNTER(lp, i);
|
9
|
+
INIT_PTR(lp, 0, p1, s1);
|
10
|
+
INIT_PTR(lp, 1, p2, s2);
|
11
|
+
INIT_PTR(lp, 2, p3, s3);
|
12
|
+
INIT_PTR(lp, 3, p4, s4);
|
13
|
+
for (; i--;) {
|
14
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
15
|
+
GET_DATA_STRIDE(p2,s2,dtype,min);
|
16
|
+
GET_DATA_STRIDE(p3,s3,dtype,max);
|
17
|
+
if (m_gt(min,max)) {rb_raise(nary_eOperationError,"min is greater than max");}
|
18
|
+
if (m_lt(x,min)) {x=min;}
|
19
|
+
if (m_gt(x,max)) {x=max;}
|
20
|
+
SET_DATA_STRIDE(p4,s4,dtype,x);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
static void
|
25
|
+
<%=c_iter%>_min(na_loop_t *const lp)
|
26
|
+
{
|
27
|
+
size_t i;
|
28
|
+
char *p1, *p2, *p3;
|
29
|
+
ssize_t s1, s2, s3;
|
30
|
+
dtype x, min;
|
31
|
+
INIT_COUNTER(lp, i);
|
32
|
+
INIT_PTR(lp, 0, p1, s1);
|
33
|
+
INIT_PTR(lp, 1, p2, s2);
|
34
|
+
INIT_PTR(lp, 2, p3, s3);
|
35
|
+
for (; i--;) {
|
36
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
37
|
+
GET_DATA_STRIDE(p2,s2,dtype,min);
|
38
|
+
if (m_lt(x,min)) {x=min;}
|
39
|
+
SET_DATA_STRIDE(p3,s3,dtype,x);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
static void
|
44
|
+
<%=c_iter%>_max(na_loop_t *const lp)
|
45
|
+
{
|
46
|
+
size_t i;
|
47
|
+
char *p1, *p2, *p3;
|
48
|
+
ssize_t s1, s2, s3;
|
49
|
+
dtype x, max;
|
50
|
+
INIT_COUNTER(lp, i);
|
51
|
+
INIT_PTR(lp, 0, p1, s1);
|
52
|
+
INIT_PTR(lp, 1, p2, s2);
|
53
|
+
INIT_PTR(lp, 2, p3, s3);
|
54
|
+
for (; i--;) {
|
55
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
56
|
+
GET_DATA_STRIDE(p2,s2,dtype,max);
|
57
|
+
if (m_gt(x,max)) {x=max;}
|
58
|
+
SET_DATA_STRIDE(p3,s3,dtype,x);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
Clip array elements by [min,max].
|
64
|
+
If either of min or max is nil, one side is clipped.
|
65
|
+
@overload <%=name%>(min,max)
|
66
|
+
@param [Numo::NArray,Numeric] min
|
67
|
+
@param [Numo::NArray,Numeric] max
|
68
|
+
@return [Numo::NArray] result of clip.
|
69
|
+
|
70
|
+
@example
|
71
|
+
a = Numo::Int32.new(10).seq
|
72
|
+
p a.clip(1,8)
|
73
|
+
# Numo::Int32#shape=[10]
|
74
|
+
# [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
|
75
|
+
|
76
|
+
p a
|
77
|
+
# Numo::Int32#shape=[10]
|
78
|
+
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
79
|
+
|
80
|
+
p a.inplace.clip(3,6)
|
81
|
+
# Numo::Int32(view)#shape=[10]
|
82
|
+
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
83
|
+
|
84
|
+
p a
|
85
|
+
# Numo::Int32#shape=[10]
|
86
|
+
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
87
|
+
|
88
|
+
p a = Numo::Int32.new(10).seq
|
89
|
+
# Numo::Int32#shape=[10]
|
90
|
+
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
91
|
+
|
92
|
+
p a.clip([3,4,1,1,1,4,4,4,4,4], 8)
|
93
|
+
# Numo::Int32#shape=[10]
|
94
|
+
# [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
95
|
+
*/
|
96
|
+
static VALUE
|
97
|
+
<%=c_func(2)%>(VALUE self, VALUE min, VALUE max)
|
98
|
+
{
|
99
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{cT,0},{cT,0}};
|
100
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
101
|
+
ndfunc_t ndf_min = { <%=c_iter%>_min, STRIDE_LOOP, 2, 1, ain, aout };
|
102
|
+
ndfunc_t ndf_max = { <%=c_iter%>_max, STRIDE_LOOP, 2, 1, ain, aout };
|
103
|
+
ndfunc_t ndf_both = { <%=c_iter%>, STRIDE_LOOP, 3, 1, ain, aout };
|
104
|
+
|
105
|
+
if (RTEST(min)) {
|
106
|
+
if (RTEST(max)) {
|
107
|
+
return na_ndloop(&ndf_both, 3, self, min, max);
|
108
|
+
} else {
|
109
|
+
return na_ndloop(&ndf_min, 2, self, min);
|
110
|
+
}
|
111
|
+
} else {
|
112
|
+
if (RTEST(max)) {
|
113
|
+
return na_ndloop(&ndf_max, 2, self, max);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
rb_raise(rb_eArgError,"min and max are not given");
|
117
|
+
return Qnil;
|
118
|
+
}
|
@@ -15,7 +15,7 @@ static void
|
|
15
15
|
for (; i--;) {
|
16
16
|
GET_DATA_STRIDE(p1,s1,dtype,x);
|
17
17
|
GET_DATA_STRIDE(p2,s2,dtype,y);
|
18
|
-
b = (m_<%=
|
18
|
+
b = (m_<%=name%>(x,y)) ? 1:0;
|
19
19
|
STORE_BIT(a3,p3,b);
|
20
20
|
p3+=s3;
|
21
21
|
}
|
@@ -32,13 +32,13 @@ static VALUE
|
|
32
32
|
}
|
33
33
|
|
34
34
|
/*
|
35
|
-
Comparison <%=
|
35
|
+
Comparison <%=name%> other.
|
36
36
|
@overload <%=op_map%> other
|
37
37
|
@param [Numo::NArray,Numeric] other
|
38
|
-
@return [Numo::Bit] result of self <%=
|
38
|
+
@return [Numo::Bit] result of self <%=name%> other.
|
39
39
|
*/
|
40
40
|
static VALUE
|
41
|
-
<%=c_func%>(VALUE self, VALUE other)
|
41
|
+
<%=c_func(1)%>(VALUE self, VALUE other)
|
42
42
|
{
|
43
43
|
<% if is_object %>
|
44
44
|
return <%=c_func%>_self(self, other);
|
@@ -49,7 +49,7 @@ static VALUE
|
|
49
49
|
return <%=c_func%>_self(self, other);
|
50
50
|
} else {
|
51
51
|
v = rb_funcall(klass, id_cast, 1, self);
|
52
|
-
return rb_funcall(v,
|
52
|
+
return rb_funcall(v, <%=id_op%>, 1, other);
|
53
53
|
}
|
54
54
|
<% end %>
|
55
55
|
}
|
@@ -15,14 +15,14 @@ static void
|
|
15
15
|
if (idx1) {
|
16
16
|
for (; i--;) {
|
17
17
|
GET_DATA_INDEX(p1,idx1,dtype,x);
|
18
|
-
b = (m_<%=
|
18
|
+
b = (m_<%=name%>(x)) ? 1:0;
|
19
19
|
STORE_BIT(a2,p2,b);
|
20
20
|
p2+=s2;
|
21
21
|
}
|
22
22
|
} else {
|
23
23
|
for (; i--;) {
|
24
24
|
GET_DATA_STRIDE(p1,s1,dtype,x);
|
25
|
-
b = (m_<%=
|
25
|
+
b = (m_<%=name%>(x)) ? 1:0;
|
26
26
|
STORE_BIT(a2,p2,b);
|
27
27
|
p2+=s2;
|
28
28
|
}
|
@@ -30,12 +30,12 @@ static void
|
|
30
30
|
}
|
31
31
|
|
32
32
|
/*
|
33
|
-
Condition of <%=
|
34
|
-
@overload <%=
|
35
|
-
@return [Numo::Bit] Condition of <%=
|
33
|
+
Condition of <%=name%>.
|
34
|
+
@overload <%=name%>
|
35
|
+
@return [Numo::Bit] Condition of <%=name%>.
|
36
36
|
*/
|
37
37
|
static VALUE
|
38
|
-
<%=c_func%>(VALUE self)
|
38
|
+
<%=c_func(0)%>(VALUE self)
|
39
39
|
{
|
40
40
|
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
41
41
|
ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
|
@@ -1,5 +1,6 @@
|
|
1
|
+
<% (is_float ? ["","_nan"] : [""]).each do |j| %>
|
1
2
|
static void
|
2
|
-
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
<%=c_iter%><%=j%>(na_loop_t *const lp)
|
3
4
|
{
|
4
5
|
size_t i;
|
5
6
|
char *p1, *p2;
|
@@ -16,27 +17,35 @@ static void
|
|
16
17
|
//printf("i=%lu x=%f\n",i,x);
|
17
18
|
for (i--; i--;) {
|
18
19
|
GET_DATA_STRIDE(p1,s1,dtype,y);
|
19
|
-
|
20
|
+
m_<%=name%><%=j%>(x,y);
|
20
21
|
SET_DATA_STRIDE(p2,s2,dtype,x);
|
21
22
|
//printf("i=%lu x=%f\n",i,x);
|
22
23
|
}
|
23
24
|
}
|
25
|
+
<% end %>
|
24
26
|
|
25
27
|
/*
|
26
|
-
<%=
|
27
|
-
@overload <%=
|
28
|
-
@param [
|
29
|
-
@
|
28
|
+
<%=name%> of self.
|
29
|
+
@overload <%=name%>(axis:nil, nan:false)
|
30
|
+
@param [Numeric,Array,Range] axis Affected dimensions.
|
31
|
+
@param [TrueClass] nan If true, propagete NaN. If false, ignore NaN.
|
32
|
+
@return [Numo::<%=class_name%>] <%=name%> of self.
|
30
33
|
*/
|
31
34
|
static VALUE
|
32
|
-
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
35
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
33
36
|
{
|
37
|
+
int ignore_nan = 0;
|
34
38
|
VALUE reduce;
|
35
39
|
ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
|
36
40
|
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
37
|
-
ndfunc_t ndf = { <%=c_iter%>,
|
41
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP|NDF_FLAT_REDUCE|NDF_CUM,
|
38
42
|
2, 1, ain, aout };
|
39
43
|
|
40
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
44
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ignore_nan);
|
45
|
+
<% if is_float %>
|
46
|
+
if (ignore_nan) {
|
47
|
+
ndf.func = <%=c_iter%>_nan;
|
48
|
+
}
|
49
|
+
<% end %>
|
41
50
|
return na_ndloop(&ndf, 2, self, reduce);
|
42
51
|
}
|
@@ -27,13 +27,13 @@ void
|
|
27
27
|
/*
|
28
28
|
Calls the given block once for each element in self,
|
29
29
|
passing that element as a parameter.
|
30
|
-
@overload <%=
|
30
|
+
@overload <%=name%>
|
31
31
|
@return [Numo::NArray] self
|
32
32
|
For a block {|x| ... }
|
33
33
|
@yield [x] x is element of NArray.
|
34
34
|
*/
|
35
35
|
static VALUE
|
36
|
-
<%=c_func%>(VALUE self)
|
36
|
+
<%=c_func(0)%>(VALUE self)
|
37
37
|
{
|
38
38
|
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
39
39
|
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
@@ -48,13 +48,13 @@ void
|
|
48
48
|
/*
|
49
49
|
Invokes the given block once for each element of self,
|
50
50
|
passing that element and indices along each axis as parameters.
|
51
|
-
@overload <%=
|
51
|
+
@overload <%=name%>
|
52
52
|
@return [Numo::NArray] self
|
53
53
|
For a block {|x,i,j,...| ... }
|
54
54
|
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
55
55
|
*/
|
56
56
|
static VALUE
|
57
|
-
<%=c_func%>(VALUE self)
|
57
|
+
<%=c_func(0)%>(VALUE self)
|
58
58
|
{
|
59
59
|
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
60
60
|
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/*
|
2
|
+
Convert a data value of obj (with a single element) to dtype.
|
3
|
+
*/
|
4
|
+
static dtype
|
5
|
+
<%=c_func(:nodef)%>(VALUE obj)
|
6
|
+
{
|
7
|
+
narray_t *na;
|
8
|
+
dtype x;
|
9
|
+
char *ptr;
|
10
|
+
size_t pos;
|
11
|
+
VALUE r, klass;
|
12
|
+
|
13
|
+
if (IsNArray(obj)) {
|
14
|
+
GetNArray(obj,na);
|
15
|
+
if (na->size != 1) {
|
16
|
+
rb_raise(nary_eShapeError,"narray size should be 1");
|
17
|
+
}
|
18
|
+
klass = CLASS_OF(obj);
|
19
|
+
ptr = na_get_pointer_for_read(obj);
|
20
|
+
pos = na_get_offset(obj);
|
21
|
+
<% find_tmpl("store").definitions.select{|x| x.class==Store}.each do |x| %>
|
22
|
+
if (<%=x.condition("klass")%>) {
|
23
|
+
<%=x.extract_data("ptr","pos","x")%>;
|
24
|
+
return x;
|
25
|
+
}
|
26
|
+
<% end %>
|
27
|
+
|
28
|
+
// coerce
|
29
|
+
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
|
30
|
+
if (CLASS_OF(r)==cT) {
|
31
|
+
return <%=c_func%>(r);
|
32
|
+
}
|
33
|
+
<% if is_object %>
|
34
|
+
return obj;
|
35
|
+
<% else %>
|
36
|
+
rb_raise(nary_eCastError, "unknown conversion from %s to %s",
|
37
|
+
rb_class2name(CLASS_OF(obj)),
|
38
|
+
rb_class2name(cT));
|
39
|
+
<% end %>
|
40
|
+
}
|
41
|
+
if (TYPE(obj)==T_ARRAY) {
|
42
|
+
if (RARRAY_LEN(obj) != 1) {
|
43
|
+
rb_raise(nary_eShapeError,"array size should be 1");
|
44
|
+
}
|
45
|
+
return m_num_to_data(RARRAY_AREF(obj,0));
|
46
|
+
}
|
47
|
+
return m_num_to_data(obj);
|
48
|
+
}
|
@@ -31,15 +31,15 @@ static void
|
|
31
31
|
|
32
32
|
/*
|
33
33
|
Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
34
|
-
@overload <%=
|
34
|
+
@overload <%=name%>([element,offset])
|
35
35
|
@param [Numeric] element Diagonal element to be stored. Default is 1.
|
36
36
|
@param [Integer] offset Diagonal offset from the main diagonal. The
|
37
37
|
default is 0. k>0 for diagonals above the main diagonal, and k<0
|
38
38
|
for diagonals below the main diagonal.
|
39
|
-
@return [Numo::<%=class_name%>] <%=
|
39
|
+
@return [Numo::<%=class_name%>] <%=name%> of self.
|
40
40
|
*/
|
41
41
|
static VALUE
|
42
|
-
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
42
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
43
43
|
{
|
44
44
|
ndfunc_arg_in_t ain[1] = {{OVERWRITE,2}};
|
45
45
|
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 1,0, ain,0};
|
@@ -23,12 +23,12 @@ static void
|
|
23
23
|
|
24
24
|
/*
|
25
25
|
Fill elements with other.
|
26
|
-
@overload <%=
|
26
|
+
@overload <%=name%> other
|
27
27
|
@param [Numeric] other
|
28
28
|
@return [Numo::<%=class_name%>] self.
|
29
29
|
*/
|
30
30
|
static VALUE
|
31
|
-
<%=c_func%>(VALUE self, VALUE val)
|
31
|
+
<%=c_func(1)%>(VALUE self, VALUE val)
|
32
32
|
{
|
33
33
|
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_option}};
|
34
34
|
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
static VALUE
|
2
|
-
format_<%=
|
2
|
+
format_<%=type_name%>(VALUE fmt, dtype* x)
|
3
3
|
{
|
4
4
|
// fix-me
|
5
5
|
char s[48];
|
@@ -28,13 +28,13 @@ static void
|
|
28
28
|
if (idx1) {
|
29
29
|
for (; i--;) {
|
30
30
|
x = (dtype*)(p1+*idx1); idx1++;
|
31
|
-
y = format_<%=
|
31
|
+
y = format_<%=type_name%>(fmt, x);
|
32
32
|
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
33
33
|
}
|
34
34
|
} else {
|
35
35
|
for (; i--;) {
|
36
36
|
x = (dtype*)p1; p1+=s1;
|
37
|
-
y = format_<%=
|
37
|
+
y = format_<%=type_name%>(fmt, x);
|
38
38
|
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
39
39
|
}
|
40
40
|
}
|
@@ -42,12 +42,12 @@ static void
|
|
42
42
|
|
43
43
|
/*
|
44
44
|
Format elements into strings.
|
45
|
-
@overload <%=
|
45
|
+
@overload <%=name%> format
|
46
46
|
@param [String] format
|
47
47
|
@return [Numo::RObject] array of formated strings.
|
48
48
|
*/
|
49
49
|
static VALUE
|
50
|
-
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
50
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
51
51
|
{
|
52
52
|
VALUE fmt=Qnil;
|
53
53
|
|
@@ -16,13 +16,13 @@ static void
|
|
16
16
|
if (idx1) {
|
17
17
|
for (; i--;) {
|
18
18
|
x = (dtype*)(p1 + *idx1); idx1++;
|
19
|
-
y = format_<%=
|
19
|
+
y = format_<%=type_name%>(fmt, x);
|
20
20
|
rb_ary_push(a,y);
|
21
21
|
}
|
22
22
|
} else {
|
23
23
|
for (; i--;) {
|
24
24
|
x = (dtype*)p1; p1+=s1;
|
25
|
-
y = format_<%=
|
25
|
+
y = format_<%=type_name%>(fmt, x);
|
26
26
|
rb_ary_push(a,y);
|
27
27
|
}
|
28
28
|
}
|
@@ -30,12 +30,12 @@ static void
|
|
30
30
|
|
31
31
|
/*
|
32
32
|
Format elements into strings.
|
33
|
-
@overload <%=
|
33
|
+
@overload <%=name%> format
|
34
34
|
@param [String] format
|
35
35
|
@return [Array] array of formated strings.
|
36
36
|
*/
|
37
37
|
static VALUE
|
38
|
-
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
38
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
39
39
|
{
|
40
40
|
volatile VALUE fmt=Qnil;
|
41
41
|
ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
|