numo-narray 0.9.0.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +41 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +46 -0
- data/ext/numo/narray/SFMT.c +620 -0
- data/ext/numo/narray/SFMT.h +157 -0
- data/ext/numo/narray/array.c +525 -0
- data/ext/numo/narray/data.c +901 -0
- data/ext/numo/narray/depend.erb +33 -0
- data/ext/numo/narray/extconf.rb +117 -0
- data/ext/numo/narray/gen/bit.erb.c +811 -0
- data/ext/numo/narray/gen/cogen.rb +18 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
- data/ext/numo/narray/gen/def/dfloat.rb +30 -0
- data/ext/numo/narray/gen/def/int16.rb +29 -0
- data/ext/numo/narray/gen/def/int32.rb +29 -0
- data/ext/numo/narray/gen/def/int64.rb +29 -0
- data/ext/numo/narray/gen/def/int8.rb +29 -0
- data/ext/numo/narray/gen/def/robject.rb +30 -0
- data/ext/numo/narray/gen/def/scomplex.rb +32 -0
- data/ext/numo/narray/gen/def/sfloat.rb +30 -0
- data/ext/numo/narray/gen/def/uint16.rb +29 -0
- data/ext/numo/narray/gen/def/uint32.rb +29 -0
- data/ext/numo/narray/gen/def/uint64.rb +29 -0
- data/ext/numo/narray/gen/def/uint8.rb +29 -0
- data/ext/numo/narray/gen/dtype.erb.c +328 -0
- data/ext/numo/narray/gen/tmpl/accum.c +36 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
- data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
- data/ext/numo/narray/gen/tmpl/aref.c +51 -0
- data/ext/numo/narray/gen/tmpl/aset.c +61 -0
- data/ext/numo/narray/gen/tmpl/binary.c +53 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
- data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
- data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
- data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
- data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
- data/ext/numo/narray/gen/tmpl/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
- data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
- data/ext/numo/narray/gen/tmpl/cum.c +42 -0
- data/ext/numo/narray/gen/tmpl/each.c +43 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
- data/ext/numo/narray/gen/tmpl/extract.c +23 -0
- data/ext/numo/narray/gen/tmpl/eye.c +91 -0
- data/ext/numo/narray/gen/tmpl/fill.c +38 -0
- data/ext/numo/narray/gen/tmpl/format.c +60 -0
- data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
- data/ext/numo/narray/gen/tmpl/head.c +25 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl/median.c +44 -0
- data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/numo/narray/gen/tmpl/poly.c +49 -0
- data/ext/numo/narray/gen/tmpl/pow.c +74 -0
- data/ext/numo/narray/gen/tmpl/powint.c +17 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
- data/ext/numo/narray/gen/tmpl/rand.c +33 -0
- data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
- data/ext/numo/narray/gen/tmpl/seq.c +61 -0
- data/ext/numo/narray/gen/tmpl/set2.c +56 -0
- data/ext/numo/narray/gen/tmpl/sort.c +36 -0
- data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
- data/ext/numo/narray/gen/tmpl/store.c +31 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
- data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
- data/ext/numo/narray/gen/tmpl/unary.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
- data/ext/numo/narray/index.c +822 -0
- data/ext/numo/narray/kwarg.c +79 -0
- data/ext/numo/narray/math.c +140 -0
- data/ext/numo/narray/narray.c +1539 -0
- data/ext/numo/narray/ndloop.c +1928 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +112 -0
- data/ext/numo/narray/numo/narray.h +411 -0
- data/ext/numo/narray/numo/ndloop.h +99 -0
- data/ext/numo/narray/numo/template.h +140 -0
- data/ext/numo/narray/numo/types/bit.h +19 -0
- data/ext/numo/narray/numo/types/complex.h +410 -0
- data/ext/numo/narray/numo/types/complex_macro.h +205 -0
- data/ext/numo/narray/numo/types/dcomplex.h +11 -0
- data/ext/numo/narray/numo/types/dfloat.h +12 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +277 -0
- data/ext/numo/narray/numo/types/int16.h +12 -0
- data/ext/numo/narray/numo/types/int32.h +12 -0
- data/ext/numo/narray/numo/types/int64.h +12 -0
- data/ext/numo/narray/numo/types/int8.h +12 -0
- data/ext/numo/narray/numo/types/int_macro.h +34 -0
- data/ext/numo/narray/numo/types/robj_macro.h +218 -0
- data/ext/numo/narray/numo/types/robject.h +21 -0
- data/ext/numo/narray/numo/types/scomplex.h +11 -0
- data/ext/numo/narray/numo/types/sfloat.h +13 -0
- data/ext/numo/narray/numo/types/uint16.h +12 -0
- data/ext/numo/narray/numo/types/uint32.h +12 -0
- data/ext/numo/narray/numo/types/uint64.h +12 -0
- data/ext/numo/narray/numo/types/uint8.h +12 -0
- data/ext/numo/narray/numo/types/uint_macro.h +31 -0
- data/ext/numo/narray/numo/types/xint_macro.h +133 -0
- data/ext/numo/narray/rand.c +87 -0
- data/ext/numo/narray/step.c +506 -0
- data/ext/numo/narray/struct.c +872 -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/erbpp.rb +286 -0
- data/lib/erbpp/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/numo/narray.rb +6 -0
- data/numo-narray.gemspec +35 -0
- data/spec/bit_spec.rb +93 -0
- data/spec/narray_spec.rb +249 -0
- metadata +238 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
size_t p1, p2, p3;
|
6
|
+
ssize_t s1, s2, s3;
|
7
|
+
size_t *idx1, *idx2, *idx3;
|
8
|
+
int o1, o2, l1, l2, r1, r2, len;
|
9
|
+
BIT_DIGIT *a1, *a2, *a3;
|
10
|
+
BIT_DIGIT x, y;
|
11
|
+
|
12
|
+
INIT_COUNTER(lp, n);
|
13
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
14
|
+
INIT_PTR_BIT_IDX(lp, 1, a2, p2, s2, idx2);
|
15
|
+
INIT_PTR_BIT_IDX(lp, 2, a3, p3, s3, idx3);
|
16
|
+
if (s1!=1 || s2!=1 || s3!=1 || idx1 || idx2 || idx3) {
|
17
|
+
for (; n--;) {
|
18
|
+
LOAD_BIT_STEP(a1, p1, s1, idx1, x);
|
19
|
+
LOAD_BIT_STEP(a2, p2, s2, idx2, y);
|
20
|
+
x = m_<%=method%>(x,y);
|
21
|
+
STORE_BIT_STEP(a3, p3, s3, idx3, x);
|
22
|
+
}
|
23
|
+
} else {
|
24
|
+
o1 = p1 % NB;
|
25
|
+
o1 -= p3;
|
26
|
+
o2 = p2 % NB;
|
27
|
+
o2 -= p3;
|
28
|
+
l1 = NB+o1;
|
29
|
+
r1 = NB-o1;
|
30
|
+
l2 = NB+o2;
|
31
|
+
r2 = NB-o2;
|
32
|
+
if (p3>0 || n<NB) {
|
33
|
+
len = NB - p3;
|
34
|
+
if ((int)n<len) len=n;
|
35
|
+
if (o1>=0) x = *a1>>o1;
|
36
|
+
else x = *a1<<-o1;
|
37
|
+
if (p1+len>NB) x |= *(a1+1)<<r1;
|
38
|
+
a1++;
|
39
|
+
if (o2>=0) y = *a2>>o2;
|
40
|
+
else y = *a2<<-o2;
|
41
|
+
if (p2+len>NB) y |= *(a2+1)<<r2;
|
42
|
+
a2++;
|
43
|
+
x = m_<%=method%>(x,y);
|
44
|
+
*a3 = (x & (SLB(len)<<p3)) | (*a3 & ~(SLB(len)<<p3));
|
45
|
+
a3++;
|
46
|
+
n -= len;
|
47
|
+
}
|
48
|
+
if (o1==0 && o2==0) {
|
49
|
+
for (; n>=NB; n-=NB) {
|
50
|
+
x = *(a1++);
|
51
|
+
y = *(a2++);
|
52
|
+
x = m_<%=method%>(x,y);
|
53
|
+
*(a3++) = x;
|
54
|
+
}
|
55
|
+
} else {
|
56
|
+
for (; n>=NB; n-=NB) {
|
57
|
+
x = *a1>>o1;
|
58
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
59
|
+
if (o1>0) x |= *(a1+1)<<r1;
|
60
|
+
a1++;
|
61
|
+
y = *a2>>o2;
|
62
|
+
if (o2<0) y |= *(a2-1)>>l2;
|
63
|
+
if (o2>0) y |= *(a2+1)<<r2;
|
64
|
+
a2++;
|
65
|
+
x = m_<%=method%>(x,y);
|
66
|
+
*(a3++) = x;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
if (n>0) {
|
70
|
+
x = *a1>>o1;
|
71
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
72
|
+
y = *a2>>o2;
|
73
|
+
if (o2<0) y |= *(a2-1)>>l2;
|
74
|
+
x = m_<%=method%>(x,y);
|
75
|
+
*a3 = (x & SLB(n)) | (*a3 & BALL<<n);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
/*
|
81
|
+
Binary <%=method%>.
|
82
|
+
@overload <%=op_map%> other
|
83
|
+
@param [Numo::NArray,Numeric] other
|
84
|
+
@return [Numo::NArray] <%=method%> of self and other.
|
85
|
+
*/
|
86
|
+
static VALUE
|
87
|
+
<%=c_func%>(VALUE self, VALUE other)
|
88
|
+
{
|
89
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
90
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
91
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 1, ain, aout };
|
92
|
+
|
93
|
+
return na_ndloop(&ndf, 2, self, other);
|
94
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#undef int_t
|
2
|
+
#define int_t int64_t
|
3
|
+
|
4
|
+
static void
|
5
|
+
<%=c_iter%>(na_loop_t *const lp)
|
6
|
+
{
|
7
|
+
size_t i;
|
8
|
+
BIT_DIGIT *a1;
|
9
|
+
size_t p1;
|
10
|
+
char *p2;
|
11
|
+
ssize_t s1, s2;
|
12
|
+
size_t *idx1;
|
13
|
+
BIT_DIGIT x=0;
|
14
|
+
int_t y;
|
15
|
+
|
16
|
+
INIT_COUNTER(lp, i);
|
17
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
18
|
+
INIT_PTR(lp, 1, p2, s2);
|
19
|
+
if (s2==0) {
|
20
|
+
GET_DATA(p2, int_t, y);
|
21
|
+
if (idx1) {
|
22
|
+
for (; i--;) {
|
23
|
+
LOAD_BIT(a1, p1+*idx1, x);
|
24
|
+
idx1++;
|
25
|
+
if (m_<%=method%>(x)) {
|
26
|
+
y++;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
for (; i--;) {
|
31
|
+
LOAD_BIT(a1, p1, x);
|
32
|
+
p1 += s1;
|
33
|
+
if (m_<%=method%>(x)) {
|
34
|
+
y++;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
*(int_t*)p2 = y;
|
39
|
+
} else {
|
40
|
+
if (idx1) {
|
41
|
+
for (; i--;) {
|
42
|
+
LOAD_BIT(a1, p1+*idx1, x);
|
43
|
+
idx1++;
|
44
|
+
if (m_<%=method%>(x)) {
|
45
|
+
GET_DATA(p2, int_t, y);
|
46
|
+
y++;
|
47
|
+
SET_DATA(p2, int_t, y);
|
48
|
+
}
|
49
|
+
p2+=s2;
|
50
|
+
}
|
51
|
+
} else {
|
52
|
+
for (; i--;) {
|
53
|
+
LOAD_BIT(a1, p1, x);
|
54
|
+
p1+=s1;
|
55
|
+
if (m_<%=method%>(x)) {
|
56
|
+
GET_DATA(p2, int_t, y);
|
57
|
+
y++;
|
58
|
+
SET_DATA(p2, int_t, y);
|
59
|
+
}
|
60
|
+
p2+=s2;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
<%=method%>.
|
68
|
+
@overload <%=method%>
|
69
|
+
@return [Numo::Int64] the number of true bits.
|
70
|
+
*/
|
71
|
+
static VALUE
|
72
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
73
|
+
{
|
74
|
+
VALUE v, reduce;
|
75
|
+
ndfunc_arg_in_t ain[3] = {{cT,0},{sym_reduce,0},{sym_init,0}};
|
76
|
+
ndfunc_arg_out_t aout[1] = {{numo_cInt64,0}};
|
77
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 3, 1, ain, aout };
|
78
|
+
|
79
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
80
|
+
v = na_ndloop(&ndf, 3, self, reduce, INT2FIX(0));
|
81
|
+
return rb_funcall(v,rb_intern("extract"),0);
|
82
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
size_t p1, p3;
|
6
|
+
ssize_t s1, s3;
|
7
|
+
size_t *idx1, *idx3;
|
8
|
+
int o1, l1, r1, len;
|
9
|
+
BIT_DIGIT *a1, *a3;
|
10
|
+
BIT_DIGIT x;
|
11
|
+
BIT_DIGIT y;
|
12
|
+
|
13
|
+
INIT_COUNTER(lp, n);
|
14
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
15
|
+
INIT_PTR_BIT_IDX(lp, 1, a3, p3, s3, idx3);
|
16
|
+
if (s1!=1 || s3!=1 || idx1 || idx3) {
|
17
|
+
for (; n--;) {
|
18
|
+
LOAD_BIT_STEP(a1, p1, s1, idx1, x);
|
19
|
+
y = m_<%=method%>(x);
|
20
|
+
STORE_BIT_STEP(a3, p3, s3, idx3, y);
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
o1 = p1 % NB;
|
24
|
+
o1 -= p3;
|
25
|
+
l1 = NB+o1;
|
26
|
+
r1 = NB-o1;
|
27
|
+
if (p3>0 || n<NB) {
|
28
|
+
len = NB - p3;
|
29
|
+
if ((int)n<len) len=n;
|
30
|
+
if (o1>=0) x = *a1>>o1;
|
31
|
+
else x = *a1<<-o1;
|
32
|
+
if (p1+len>NB) x |= *(a1+1)<<r1;
|
33
|
+
a1++;
|
34
|
+
y = m_<%=method%>(x);
|
35
|
+
*a3 = (y & (SLB(len)<<p3)) | (*a3 & ~(SLB(len)<<p3));
|
36
|
+
a3++;
|
37
|
+
n -= len;
|
38
|
+
}
|
39
|
+
if (o1==0) {
|
40
|
+
for (; n>=NB; n-=NB) {
|
41
|
+
x = *(a1++);
|
42
|
+
y = m_<%=method%>(x);
|
43
|
+
*(a3++) = y;
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
for (; n>=NB; n-=NB) {
|
47
|
+
x = *a1>>o1;
|
48
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
49
|
+
if (o1>0) x |= *(a1+1)<<r1;
|
50
|
+
a1++;
|
51
|
+
y = m_<%=method%>(x);
|
52
|
+
*(a3++) = y;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
if (n>0) {
|
56
|
+
x = *a1>>o1;
|
57
|
+
if (o1<0) x |= *(a1-1)>>l1;
|
58
|
+
y = m_<%=method%>(x);
|
59
|
+
*a3 = (y & SLB(n)) | (*a3 & BALL<<n);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
Unary <%=method%>.
|
66
|
+
@overload <%=method%>
|
67
|
+
@return [Numo::<%=class_name%>] <%=method%> of self.
|
68
|
+
*/
|
69
|
+
static VALUE
|
70
|
+
<%=c_func%>(VALUE self)
|
71
|
+
{
|
72
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
73
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
74
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 1, 1, ain, aout };
|
75
|
+
|
76
|
+
return na_ndloop(&ndf, 1, self);
|
77
|
+
}
|
@@ -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,79 @@
|
|
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
|
+
char *p2;
|
8
|
+
size_t s2, *idx2;
|
9
|
+
VALUE x;
|
10
|
+
double y;
|
11
|
+
dtype z;
|
12
|
+
size_t len, c;
|
13
|
+
double beg, step;
|
14
|
+
|
15
|
+
v1 = lp->args[0].value;
|
16
|
+
ptr = &v1;
|
17
|
+
INIT_COUNTER(lp, n);
|
18
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
19
|
+
|
20
|
+
switch(TYPE(v1)) {
|
21
|
+
case T_ARRAY:
|
22
|
+
n1 = RARRAY_LEN(v1);
|
23
|
+
ptr = RARRAY_PTR(v1);
|
24
|
+
break;
|
25
|
+
case T_NIL:
|
26
|
+
n1 = 0;
|
27
|
+
break;
|
28
|
+
default:
|
29
|
+
n1 = 1;
|
30
|
+
}
|
31
|
+
if (idx2) {
|
32
|
+
<% ["SET_DATA_INDEX(p2, idx2, dtype, z)",
|
33
|
+
"SET_DATA_STRIDE(p2, s2, dtype, z)"].each_with_index do |x,i| %>
|
34
|
+
for (i=i1=0; i1<n1 && i<n; i++,i1++) {
|
35
|
+
x = ptr[i1];
|
36
|
+
if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
|
37
|
+
nary_step_sequence(x,&len,&beg,&step);
|
38
|
+
for (c=0; c<len && i<n; c++,i++) {
|
39
|
+
y = beg + step * c;
|
40
|
+
z = m_from_double(y);
|
41
|
+
<%= x %>
|
42
|
+
}
|
43
|
+
}
|
44
|
+
else if (TYPE(x) != T_ARRAY) {
|
45
|
+
if (x == Qnil) x = INT2FIX(0);
|
46
|
+
z = m_num_to_data(x);
|
47
|
+
<%= x %>
|
48
|
+
}
|
49
|
+
}
|
50
|
+
z = m_zero;
|
51
|
+
for (; i<n; i++) {
|
52
|
+
<%= x %>
|
53
|
+
}
|
54
|
+
<% if i<1 %>
|
55
|
+
} else {
|
56
|
+
<% end
|
57
|
+
end %>
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE
|
62
|
+
<%=c_func%>(VALUE rary)
|
63
|
+
{
|
64
|
+
volatile VALUE vnc, nary;
|
65
|
+
narray_t *na;
|
66
|
+
na_compose_t *nc;
|
67
|
+
ndfunc_arg_in_t ain[2] = {{rb_cArray,0},{Qnil,0}};
|
68
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
69
|
+
|
70
|
+
vnc = na_ary_composition(rary);
|
71
|
+
Data_Get_Struct(vnc, na_compose_t, nc);
|
72
|
+
nary = rb_narray_new(cT, nc->ndim, nc->shape);
|
73
|
+
GetNArray(nary,na);
|
74
|
+
if (na->size > 0) {
|
75
|
+
<%=find_tmpl("allocate").c_func%>(nary);
|
76
|
+
na_ndloop_cast_rarray_to_narray(&ndf, rary, nary);
|
77
|
+
}
|
78
|
+
return nary;
|
79
|
+
}
|
@@ -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
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2;
|
6
|
+
BIT_DIGIT *a3;
|
7
|
+
size_t p3;
|
8
|
+
ssize_t s1, s2, s3;
|
9
|
+
dtype x, y;
|
10
|
+
BIT_DIGIT b;
|
11
|
+
INIT_COUNTER(lp, i);
|
12
|
+
INIT_PTR(lp, 0, p1, s1);
|
13
|
+
INIT_PTR(lp, 1, p2, s2);
|
14
|
+
INIT_PTR_BIT(lp, 2, a3, p3, s3);
|
15
|
+
for (; i--;) {
|
16
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
17
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
18
|
+
b = (m_<%=method%>(x,y)) ? 1:0;
|
19
|
+
STORE_BIT(a3,p3,b);
|
20
|
+
p3+=s3;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE
|
25
|
+
<%=c_func%>_self(VALUE self, VALUE other)
|
26
|
+
{
|
27
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
28
|
+
ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
|
29
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 1, ain, aout };
|
30
|
+
|
31
|
+
return na_ndloop(&ndf, 2, self, other);
|
32
|
+
}
|
33
|
+
|
34
|
+
/*
|
35
|
+
Comparison <%=method%> other.
|
36
|
+
@overload <%=op_map%> other
|
37
|
+
@param [Numo::NArray,Numeric] other
|
38
|
+
@return [Numo::Bit] result of self <%=method%> other.
|
39
|
+
*/
|
40
|
+
static VALUE
|
41
|
+
<%=c_func%>(VALUE self, VALUE other)
|
42
|
+
{
|
43
|
+
VALUE klass, v;
|
44
|
+
klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
|
45
|
+
if (klass==cT) {
|
46
|
+
return <%=c_func%>_self(self, other);
|
47
|
+
} else {
|
48
|
+
v = rb_funcall(klass, id_cast, 1, self);
|
49
|
+
return rb_funcall(v, id_<%=method%>, 1, other);
|
50
|
+
}
|
51
|
+
}
|