numo-narray 0.9.0.1-x86-mingw32 → 0.9.0.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/Rakefile +21 -6
- data/ext/numo/narray/array.c +3 -3
- data/ext/numo/narray/data.c +102 -81
- data/ext/numo/narray/depend.erb +9 -7
- data/ext/numo/narray/extconf.rb +5 -24
- data/ext/numo/narray/gen/cogen.rb +19 -4
- data/ext/numo/narray/gen/def/bit.rb +31 -0
- data/ext/numo/narray/gen/def/robject.rb +1 -1
- data/ext/numo/narray/gen/dtype.erb.c +11 -257
- data/ext/numo/narray/gen/spec.rb +294 -0
- data/ext/numo/narray/gen/tmpl/aset.c +1 -1
- data/ext/numo/narray/gen/tmpl/each_with_index.c +1 -1
- data/ext/numo/narray/gen/tmpl/eye.c +5 -5
- data/ext/numo/narray/gen/tmpl/logseq.c +82 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand.c +126 -5
- data/ext/numo/narray/gen/tmpl/seq.c +43 -12
- data/ext/numo/narray/gen/tmpl/store_bit.c +55 -0
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +28 -0
- data/ext/numo/narray/gen/tmpl_bit/aref.c +53 -0
- data/ext/numo/narray/gen/tmpl_bit/aset.c +63 -0
- data/ext/numo/narray/gen/{tmpl/bit_binary.c → tmpl_bit/binary.c} +1 -1
- data/ext/numo/narray/gen/{tmpl → tmpl_bit}/bit_count.c +5 -3
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +128 -0
- data/ext/numo/narray/gen/tmpl_bit/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl_bit/cast_array.c +80 -0
- data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl_bit/each.c +44 -0
- data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +66 -0
- data/ext/numo/narray/gen/tmpl_bit/extract.c +25 -0
- data/ext/numo/narray/gen/tmpl_bit/fill.c +65 -0
- data/ext/numo/narray/gen/tmpl_bit/format.c +61 -0
- data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +48 -0
- data/ext/numo/narray/gen/tmpl_bit/inspect.c +18 -0
- data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl_bit/mask.c +117 -0
- data/ext/numo/narray/gen/tmpl_bit/none_p.c +14 -0
- data/ext/numo/narray/gen/tmpl_bit/store.c +32 -0
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +66 -0
- data/ext/numo/narray/gen/tmpl_bit/store_from.c +56 -0
- data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl_bit/to_a.c +43 -0
- data/ext/numo/narray/gen/{tmpl/bit_unary.c → tmpl_bit/unary.c} +1 -1
- data/ext/numo/narray/gen/tmpl_bit/where.c +102 -0
- data/ext/numo/narray/gen/tmpl_bit/where2.c +37 -0
- data/ext/numo/narray/index.c +9 -7
- data/ext/numo/narray/math.c +6 -1
- data/ext/numo/narray/narray.c +307 -103
- data/ext/numo/narray/ndloop.c +21 -36
- data/ext/numo/narray/numo/intern.h +3 -3
- data/ext/numo/narray/numo/narray.h +5 -41
- data/ext/numo/narray/numo/template.h +2 -2
- data/ext/numo/narray/numo/types/bit.h +27 -13
- data/ext/numo/narray/numo/types/complex.h +2 -2
- data/ext/numo/narray/numo/types/complex_macro.h +19 -7
- data/ext/numo/narray/numo/types/dcomplex.h +9 -0
- data/ext/numo/narray/numo/types/dfloat.h +6 -0
- data/ext/numo/narray/numo/types/float_macro.h +9 -2
- data/ext/numo/narray/numo/types/int16.h +0 -1
- data/ext/numo/narray/numo/types/int32.h +0 -1
- data/ext/numo/narray/numo/types/int64.h +0 -1
- data/ext/numo/narray/numo/types/int8.h +0 -1
- data/ext/numo/narray/numo/types/int_macro.h +2 -1
- data/ext/numo/narray/numo/types/robj_macro.h +9 -2
- data/ext/numo/narray/numo/types/robject.h +6 -0
- data/ext/numo/narray/numo/types/scomplex.h +9 -0
- data/ext/numo/narray/numo/types/sfloat.h +6 -0
- data/ext/numo/narray/numo/types/uint16.h +0 -1
- data/ext/numo/narray/numo/types/uint32.h +0 -1
- data/ext/numo/narray/numo/types/uint64.h +0 -1
- data/ext/numo/narray/numo/types/uint8.h +0 -1
- data/ext/numo/narray/numo/types/uint_macro.h +2 -1
- data/ext/numo/narray/numo/types/xint_macro.h +6 -1
- data/ext/numo/narray/rand.c +2 -2
- data/ext/numo/narray/step.c +7 -7
- data/ext/numo/narray/struct.c +11 -12
- data/lib/2.0/numo/narray.so +0 -0
- data/lib/2.1/numo/narray.so +0 -0
- data/lib/2.2/numo/narray.so +0 -0
- data/lib/2.3/numo/narray.so +0 -0
- data/lib/2.4/numo/narray.so +0 -0
- data/lib/erbpp.rb +6 -2
- data/lib/erbpp/line_number.rb +1 -1
- data/lib/erbpp/narray_def.rb +23 -19
- data/numo-narray.gemspec +2 -2
- metadata +45 -10
- data/ext/numo/narray/gen/bit.erb.c +0 -811
@@ -0,0 +1,28 @@
|
|
1
|
+
static VALUE
|
2
|
+
<%=c_func%>(VALUE self)
|
3
|
+
{
|
4
|
+
narray_t *na;
|
5
|
+
char *ptr;
|
6
|
+
|
7
|
+
GetNArray(self,na);
|
8
|
+
|
9
|
+
switch(NA_TYPE(na)) {
|
10
|
+
case NARRAY_DATA_T:
|
11
|
+
ptr = NA_DATA_PTR(na);
|
12
|
+
if (na->size > 0 && ptr == NULL) {
|
13
|
+
ptr = xmalloc(((na->size-1)/sizeof(BIT_DIGIT)+1)*sizeof(BIT_DIGIT)/8);
|
14
|
+
NA_DATA_PTR(na) = ptr;
|
15
|
+
}
|
16
|
+
break;
|
17
|
+
//case NARRAY_FILEMAP_T:
|
18
|
+
// to be implemented
|
19
|
+
// ptr = ((narray_filemap_t*)na)->ptr;
|
20
|
+
// break;
|
21
|
+
case NARRAY_VIEW_T:
|
22
|
+
rb_funcall(NA_VIEW_DATA(na), rb_intern("allocate"), 0);
|
23
|
+
break;
|
24
|
+
default:
|
25
|
+
rb_raise(rb_eRuntimeError,"invalid narray type");
|
26
|
+
}
|
27
|
+
return self;
|
28
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
Array element referenece or slice view.
|
3
|
+
@overload [](dim0,...,dimL)
|
4
|
+
@param [Numeric,Range,etc] dim0,...,dimL Multi-dimensional Index.
|
5
|
+
@return [Numeric,NArray::<%=class_name%>] Element object or NArray view.
|
6
|
+
|
7
|
+
--- Returns the element at +dim0+, +dim1+, ... are Numeric indices
|
8
|
+
for each dimension, or returns a NArray View as a sliced subarray if
|
9
|
+
+dim0+, +dim1+, ... includes other than Numeric index, e.g., Range
|
10
|
+
or Array or true.
|
11
|
+
|
12
|
+
a = Numo::DFloat.new(4,5).seq
|
13
|
+
=> Numo::DFloat#shape=[4,5]
|
14
|
+
[[0, 1, 2, 3, 4],
|
15
|
+
[5, 6, 7, 8, 9],
|
16
|
+
[10, 11, 12, 13, 14],
|
17
|
+
[15, 16, 17, 18, 19]]
|
18
|
+
|
19
|
+
a[1,1]
|
20
|
+
=> 6.0
|
21
|
+
|
22
|
+
a[1..3,1]
|
23
|
+
=> Numo::DFloat#shape=[3]
|
24
|
+
[6, 11, 16]
|
25
|
+
|
26
|
+
a[1,[1,3,4]]
|
27
|
+
=> Numo::DFloat#shape=[3]
|
28
|
+
[6, 8, 9]
|
29
|
+
|
30
|
+
a[true,2].fill(99)
|
31
|
+
a
|
32
|
+
=> Numo::DFloat#shape=[4,5]
|
33
|
+
[[0, 1, 99, 3, 4],
|
34
|
+
[5, 6, 99, 8, 9],
|
35
|
+
[10, 11, 99, 13, 14],
|
36
|
+
[15, 16, 99, 18, 19]]
|
37
|
+
*/
|
38
|
+
static VALUE
|
39
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
40
|
+
{
|
41
|
+
ssize_t pos;
|
42
|
+
char *ptr;
|
43
|
+
dtype x;
|
44
|
+
|
45
|
+
pos = na_get_scalar_position(self, argc, argv, 1);
|
46
|
+
if (pos == -1) {
|
47
|
+
return na_aref_main(argc, argv, self, 0);
|
48
|
+
} else {
|
49
|
+
ptr = na_get_pointer_for_read(self);
|
50
|
+
LOAD_BIT(ptr,pos,x);
|
51
|
+
return m_data_to_num(x);
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
Array element(s) set.
|
3
|
+
@overload []=(dim0,..,dimL,val)
|
4
|
+
@param [Numeric,Range,etc] dim0,..,dimL Multi-dimensional Index.
|
5
|
+
@param [Numeric,Numo::NArray,etc] val Value(s) to be set to self.
|
6
|
+
@return [Numeric] returns val (last argument).
|
7
|
+
|
8
|
+
--- Replace element(s) at +dim0+, +dim1+, ... (index/range/array/true
|
9
|
+
for each dimention). Broadcasting mechanism is applied.
|
10
|
+
|
11
|
+
a = Numo::DFloat.new(3,4).seq
|
12
|
+
=> Numo::DFloat#shape=[3,4]
|
13
|
+
[[0, 1, 2, 3],
|
14
|
+
[4, 5, 6, 7],
|
15
|
+
[8, 9, 10, 11]]
|
16
|
+
|
17
|
+
a[1,2]=99
|
18
|
+
a
|
19
|
+
=> Numo::DFloat#shape=[3,4]
|
20
|
+
[[0, 1, 2, 3],
|
21
|
+
[4, 5, 99, 7],
|
22
|
+
[8, 9, 10, 11]]
|
23
|
+
|
24
|
+
a[1,[0,2]] = [101,102]
|
25
|
+
a
|
26
|
+
=> Numo::DFloat#shape=[3,4]
|
27
|
+
[[0, 1, 2, 3],
|
28
|
+
[101, 5, 102, 7],
|
29
|
+
[8, 9, 10, 11]]
|
30
|
+
|
31
|
+
a[1,true]=99
|
32
|
+
a
|
33
|
+
=> Numo::DFloat#shape=[3,4]
|
34
|
+
[[0, 1, 2, 3],
|
35
|
+
[99, 99, 99, 99],
|
36
|
+
[8, 9, 10, 11]]
|
37
|
+
|
38
|
+
*/
|
39
|
+
static VALUE
|
40
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
41
|
+
{
|
42
|
+
ssize_t pos;
|
43
|
+
char *ptr;
|
44
|
+
VALUE a;
|
45
|
+
dtype x;
|
46
|
+
|
47
|
+
argc--;
|
48
|
+
if (argc==0) {
|
49
|
+
<%=c_func.sub(/_aset/,"_store")%>(self, argv[argc]);
|
50
|
+
} else {
|
51
|
+
pos = na_get_scalar_position(self, argc, argv, sizeof(dtype));
|
52
|
+
if (pos == -1) {
|
53
|
+
a = na_aref_main(argc, argv, self, 0);
|
54
|
+
<%=c_func.sub(/_aset/,"_store")%>(a, argv[argc]);
|
55
|
+
} else {
|
56
|
+
ptr = na_get_pointer_for_read_write(self);
|
57
|
+
x = m_num_to_data(argv[argc]);
|
58
|
+
STORE_BIT(ptr,pos,x);
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
return argv[argc];
|
63
|
+
}
|
@@ -88,7 +88,7 @@ static VALUE
|
|
88
88
|
{
|
89
89
|
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
90
90
|
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
91
|
-
ndfunc_t ndf = { <%=c_iter%>,
|
91
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 1, ain, aout };
|
92
92
|
|
93
93
|
return na_ndloop(&ndf, 2, self, other);
|
94
94
|
}
|
@@ -64,9 +64,11 @@ static void
|
|
64
64
|
}
|
65
65
|
|
66
66
|
/*
|
67
|
-
|
68
|
-
|
69
|
-
@
|
67
|
+
Returns the number of bits.
|
68
|
+
If argument is supplied, return Int-array counted along the axes.
|
69
|
+
@overload <%=op_map%>([axis,..])
|
70
|
+
@param [Integer] axis axes to be counted.
|
71
|
+
@return [Numo::Int64]
|
70
72
|
*/
|
71
73
|
static VALUE
|
72
74
|
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
@@ -0,0 +1,128 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
BIT_DIGIT *a1, *a2;
|
6
|
+
size_t p1, p2;
|
7
|
+
ssize_t s1, s2;
|
8
|
+
size_t *idx1, *idx2;
|
9
|
+
BIT_DIGIT x=0, y=0;
|
10
|
+
|
11
|
+
INIT_COUNTER(lp, i);
|
12
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
13
|
+
INIT_PTR_BIT_IDX(lp, 1, a2, p2, s2, idx2);
|
14
|
+
if (idx2) {
|
15
|
+
if (idx1) {
|
16
|
+
for (; i--;) {
|
17
|
+
LOAD_BIT(a2, p2+*idx2, y);
|
18
|
+
if (y == <%=init_bit%>) {
|
19
|
+
LOAD_BIT(a1, p1+*idx1, x);
|
20
|
+
if (x != <%=init_bit%>) {
|
21
|
+
STORE_BIT(a2, p2+*idx2, x);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
idx1++;
|
25
|
+
idx2++;
|
26
|
+
}
|
27
|
+
} else {
|
28
|
+
for (; i--;) {
|
29
|
+
LOAD_BIT(a2, p2+*idx2, y);
|
30
|
+
if (y == <%=init_bit%>) {
|
31
|
+
LOAD_BIT(a1, p1, x);
|
32
|
+
if (x != <%=init_bit%>) {
|
33
|
+
STORE_BIT(a2, p2+*idx2, x);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
p1 += s1;
|
37
|
+
idx2++;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
} else if (s2) {
|
41
|
+
if (idx1) {
|
42
|
+
for (; i--;) {
|
43
|
+
LOAD_BIT(a2, p2, y);
|
44
|
+
if (y == <%=init_bit%>) {
|
45
|
+
LOAD_BIT(a1, p1+*idx1, x);
|
46
|
+
if (x != <%=init_bit%>) {
|
47
|
+
STORE_BIT(a2, p2, x);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
idx1++;
|
51
|
+
p2 += s2;
|
52
|
+
}
|
53
|
+
} else {
|
54
|
+
for (; i--;) {
|
55
|
+
LOAD_BIT(a2, p2, y);
|
56
|
+
if (y == <%=init_bit%>) {
|
57
|
+
LOAD_BIT(a1, p1, x);
|
58
|
+
if (x != <%=init_bit%>) {
|
59
|
+
STORE_BIT(a2, p2, x);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
p1 += s1;
|
63
|
+
p2 += s2;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
} else {
|
67
|
+
LOAD_BIT(a2, p2, x);
|
68
|
+
if (x != <%=init_bit%>) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
if (idx1) {
|
72
|
+
for (; i--;) {
|
73
|
+
LOAD_BIT(a1, p1+*idx1, y);
|
74
|
+
if (y != <%=init_bit%>) {
|
75
|
+
STORE_BIT(a2, p2, y);
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
idx1++;
|
79
|
+
}
|
80
|
+
} else {
|
81
|
+
for (; i--;) {
|
82
|
+
LOAD_BIT(a1, p1, y);
|
83
|
+
if (y != <%=init_bit%>) {
|
84
|
+
STORE_BIT(a2, p2, y);
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
p1 += s1;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
/*
|
94
|
+
<% case method
|
95
|
+
when /^any/ %>
|
96
|
+
Return true if any of bits is one (true).
|
97
|
+
<% when /^all/ %>
|
98
|
+
Return true if all of bits are one (true).
|
99
|
+
<% end %>
|
100
|
+
If argument is supplied, return Bit-array reduced along the axes.
|
101
|
+
@overload <%=op_map%>([axis,..])
|
102
|
+
@param [Integer] axis axes to be reduced.
|
103
|
+
@return [Numo::Bit] .
|
104
|
+
*/
|
105
|
+
static VALUE
|
106
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
107
|
+
{
|
108
|
+
VALUE v, reduce;
|
109
|
+
ndfunc_arg_in_t ain[3] = {{cT,0},{sym_reduce,0},{sym_init,0}};
|
110
|
+
ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
|
111
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 3,1, ain,aout};
|
112
|
+
|
113
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
114
|
+
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(<%=init_bit%>));
|
115
|
+
if (argc > 0) {
|
116
|
+
return v;
|
117
|
+
}
|
118
|
+
v = numo_bit_extract(v);
|
119
|
+
switch (v) {
|
120
|
+
case INT2FIX(0):
|
121
|
+
return Qfalse;
|
122
|
+
case INT2FIX(1):
|
123
|
+
return Qtrue;
|
124
|
+
default:
|
125
|
+
rb_bug("unexpected result");
|
126
|
+
return v;
|
127
|
+
}
|
128
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/*
|
2
|
+
Cast object to Numo::<%=class_name%>.
|
3
|
+
@overload [](elements)
|
4
|
+
@overload <%=method%>(array)
|
5
|
+
@param [Numeric,Array] elements
|
6
|
+
@param [Array] array
|
7
|
+
@return [Numo::<%=class_name%>]
|
8
|
+
*/
|
9
|
+
static VALUE
|
10
|
+
<%=c_func%>(VALUE type, VALUE obj)
|
11
|
+
{
|
12
|
+
VALUE v;
|
13
|
+
narray_t *na;
|
14
|
+
dtype x;
|
15
|
+
|
16
|
+
if (CLASS_OF(obj)==cT) {
|
17
|
+
return obj;
|
18
|
+
}
|
19
|
+
if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
|
20
|
+
x = m_num_to_data(obj);
|
21
|
+
return numo_<%=tp%>_new_dim0(x);
|
22
|
+
}
|
23
|
+
if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
|
24
|
+
return <%=find_tmpl("cast_array").c_func%>(obj);
|
25
|
+
}
|
26
|
+
if (IsNArray(obj)) {
|
27
|
+
GetNArray(obj,na);
|
28
|
+
v = rb_narray_new(cT, NA_NDIM(na), NA_SHAPE(na));
|
29
|
+
if (NA_SIZE(na) > 0) {
|
30
|
+
<%=find_tmpl("allocate").c_func%>(v);
|
31
|
+
<%=find_tmpl("store").c_func%>(v,obj);
|
32
|
+
}
|
33
|
+
return v;
|
34
|
+
}
|
35
|
+
rb_raise(nary_eCastError,"cannot cast to %s",rb_class2name(type));
|
36
|
+
return Qnil;
|
37
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, n;
|
5
|
+
size_t i1, n1;
|
6
|
+
VALUE v1, *ptr;
|
7
|
+
BIT_DIGIT *a2;
|
8
|
+
size_t p2;
|
9
|
+
size_t s2, *idx2;
|
10
|
+
VALUE x;
|
11
|
+
double y;
|
12
|
+
BIT_DIGIT z;
|
13
|
+
size_t len, c;
|
14
|
+
double beg, step;
|
15
|
+
|
16
|
+
v1 = lp->args[0].value;
|
17
|
+
ptr = &v1;
|
18
|
+
INIT_COUNTER(lp, n);
|
19
|
+
INIT_PTR_BIT_IDX(lp, 1, a2, p2, s2, idx2);
|
20
|
+
|
21
|
+
switch(TYPE(v1)) {
|
22
|
+
case T_ARRAY:
|
23
|
+
n1 = RARRAY_LEN(v1);
|
24
|
+
ptr = RARRAY_PTR(v1);
|
25
|
+
break;
|
26
|
+
case T_NIL:
|
27
|
+
n1 = 0;
|
28
|
+
break;
|
29
|
+
default:
|
30
|
+
n1 = 1;
|
31
|
+
}
|
32
|
+
if (idx2) {
|
33
|
+
<% ["STORE_BIT(a2, p2+*idx2, z); idx2++;",
|
34
|
+
"STORE_BIT(a2, p2, z); p2+=s2;"].each_with_index do |x,i| %>
|
35
|
+
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
36
|
+
x = ptr[i1];
|
37
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
|
38
|
+
nary_step_sequence(x,&len,&beg,&step);
|
39
|
+
for (c=0; c<len && i<n; c++,i++) {
|
40
|
+
y = beg + step * c;
|
41
|
+
z = m_from_double(y);
|
42
|
+
<%= x %>
|
43
|
+
}
|
44
|
+
}
|
45
|
+
if (TYPE(x) != T_ARRAY) {
|
46
|
+
if (x == Qnil) x = INT2FIX(0);
|
47
|
+
z = m_num_to_data(x);
|
48
|
+
<%= x %>
|
49
|
+
}
|
50
|
+
}
|
51
|
+
z = m_zero;
|
52
|
+
for (; i<n; i++) {
|
53
|
+
<%= x %>
|
54
|
+
}
|
55
|
+
<% if i<1 %>
|
56
|
+
} else {
|
57
|
+
<% end
|
58
|
+
end %>
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
static VALUE
|
63
|
+
<%=c_func%>(VALUE rary)
|
64
|
+
{
|
65
|
+
volatile VALUE vnc, nary;
|
66
|
+
narray_t *na;
|
67
|
+
na_compose_t *nc;
|
68
|
+
ndfunc_arg_in_t ain[2] = {{rb_cArray,0},{Qnil,0}};
|
69
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 2,0, ain,0};
|
70
|
+
|
71
|
+
vnc = na_ary_composition(rary);
|
72
|
+
Data_Get_Struct(vnc, na_compose_t, nc);
|
73
|
+
nary = rb_narray_new(cT, nc->ndim, nc->shape);
|
74
|
+
GetNArray(nary,na);
|
75
|
+
if (na->size > 0) {
|
76
|
+
<%=find_tmpl("allocate").c_func%>(nary);
|
77
|
+
na_ndloop_cast_rarray_to_narray(&ndf, rary, nary);
|
78
|
+
}
|
79
|
+
return nary;
|
80
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
static VALUE
|
2
|
+
numo_<%=tp%>_new_dim0(dtype x)
|
3
|
+
{
|
4
|
+
narray_t *na;
|
5
|
+
VALUE v;
|
6
|
+
dtype *ptr;
|
7
|
+
|
8
|
+
v = rb_narray_new(cT, 0, NULL);
|
9
|
+
GetNArray(v,na);
|
10
|
+
ptr = (dtype*)(char*)na_get_pointer_for_write(v);
|
11
|
+
*ptr = x;
|
12
|
+
na_release_lock(v);
|
13
|
+
return v;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
<%=c_func%>(VALUE x)
|
18
|
+
{
|
19
|
+
dtype y;
|
20
|
+
y = m_num_to_data(x);
|
21
|
+
return numo_<%=tp%>_new_dim0(y);
|
22
|
+
}
|