numo-narray 0.9.0.1-x86-mingw32

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.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/README.md +47 -0
  4. data/Rakefile +41 -0
  5. data/ext/numo/narray/SFMT-params.h +97 -0
  6. data/ext/numo/narray/SFMT-params19937.h +46 -0
  7. data/ext/numo/narray/SFMT.c +620 -0
  8. data/ext/numo/narray/SFMT.h +157 -0
  9. data/ext/numo/narray/array.c +525 -0
  10. data/ext/numo/narray/data.c +901 -0
  11. data/ext/numo/narray/depend.erb +33 -0
  12. data/ext/numo/narray/extconf.rb +117 -0
  13. data/ext/numo/narray/gen/bit.erb.c +811 -0
  14. data/ext/numo/narray/gen/cogen.rb +18 -0
  15. data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
  16. data/ext/numo/narray/gen/def/dfloat.rb +30 -0
  17. data/ext/numo/narray/gen/def/int16.rb +29 -0
  18. data/ext/numo/narray/gen/def/int32.rb +29 -0
  19. data/ext/numo/narray/gen/def/int64.rb +29 -0
  20. data/ext/numo/narray/gen/def/int8.rb +29 -0
  21. data/ext/numo/narray/gen/def/robject.rb +30 -0
  22. data/ext/numo/narray/gen/def/scomplex.rb +32 -0
  23. data/ext/numo/narray/gen/def/sfloat.rb +30 -0
  24. data/ext/numo/narray/gen/def/uint16.rb +29 -0
  25. data/ext/numo/narray/gen/def/uint32.rb +29 -0
  26. data/ext/numo/narray/gen/def/uint64.rb +29 -0
  27. data/ext/numo/narray/gen/def/uint8.rb +29 -0
  28. data/ext/numo/narray/gen/dtype.erb.c +328 -0
  29. data/ext/numo/narray/gen/tmpl/accum.c +36 -0
  30. data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
  31. data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
  32. data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
  33. data/ext/numo/narray/gen/tmpl/aref.c +51 -0
  34. data/ext/numo/narray/gen/tmpl/aset.c +61 -0
  35. data/ext/numo/narray/gen/tmpl/binary.c +53 -0
  36. data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
  37. data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
  38. data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
  39. data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
  40. data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
  41. data/ext/numo/narray/gen/tmpl/cast.c +37 -0
  42. data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
  43. data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
  44. data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
  45. data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
  46. data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
  47. data/ext/numo/narray/gen/tmpl/cum.c +42 -0
  48. data/ext/numo/narray/gen/tmpl/each.c +43 -0
  49. data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
  50. data/ext/numo/narray/gen/tmpl/extract.c +23 -0
  51. data/ext/numo/narray/gen/tmpl/eye.c +91 -0
  52. data/ext/numo/narray/gen/tmpl/fill.c +38 -0
  53. data/ext/numo/narray/gen/tmpl/format.c +60 -0
  54. data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
  55. data/ext/numo/narray/gen/tmpl/head.c +25 -0
  56. data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
  57. data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
  58. data/ext/numo/narray/gen/tmpl/median.c +44 -0
  59. data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
  60. data/ext/numo/narray/gen/tmpl/poly.c +49 -0
  61. data/ext/numo/narray/gen/tmpl/pow.c +74 -0
  62. data/ext/numo/narray/gen/tmpl/powint.c +17 -0
  63. data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
  64. data/ext/numo/narray/gen/tmpl/rand.c +33 -0
  65. data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
  66. data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
  67. data/ext/numo/narray/gen/tmpl/seq.c +61 -0
  68. data/ext/numo/narray/gen/tmpl/set2.c +56 -0
  69. data/ext/numo/narray/gen/tmpl/sort.c +36 -0
  70. data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
  71. data/ext/numo/narray/gen/tmpl/store.c +31 -0
  72. data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
  73. data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
  74. data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
  75. data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
  76. data/ext/numo/narray/gen/tmpl/unary.c +58 -0
  77. data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
  78. data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
  79. data/ext/numo/narray/index.c +822 -0
  80. data/ext/numo/narray/kwarg.c +79 -0
  81. data/ext/numo/narray/math.c +140 -0
  82. data/ext/numo/narray/narray.c +1539 -0
  83. data/ext/numo/narray/ndloop.c +1928 -0
  84. data/ext/numo/narray/numo/compat.h +23 -0
  85. data/ext/numo/narray/numo/intern.h +112 -0
  86. data/ext/numo/narray/numo/narray.h +411 -0
  87. data/ext/numo/narray/numo/ndloop.h +99 -0
  88. data/ext/numo/narray/numo/template.h +140 -0
  89. data/ext/numo/narray/numo/types/bit.h +19 -0
  90. data/ext/numo/narray/numo/types/complex.h +410 -0
  91. data/ext/numo/narray/numo/types/complex_macro.h +205 -0
  92. data/ext/numo/narray/numo/types/dcomplex.h +11 -0
  93. data/ext/numo/narray/numo/types/dfloat.h +12 -0
  94. data/ext/numo/narray/numo/types/float_def.h +34 -0
  95. data/ext/numo/narray/numo/types/float_macro.h +277 -0
  96. data/ext/numo/narray/numo/types/int16.h +12 -0
  97. data/ext/numo/narray/numo/types/int32.h +12 -0
  98. data/ext/numo/narray/numo/types/int64.h +12 -0
  99. data/ext/numo/narray/numo/types/int8.h +12 -0
  100. data/ext/numo/narray/numo/types/int_macro.h +34 -0
  101. data/ext/numo/narray/numo/types/robj_macro.h +218 -0
  102. data/ext/numo/narray/numo/types/robject.h +21 -0
  103. data/ext/numo/narray/numo/types/scomplex.h +11 -0
  104. data/ext/numo/narray/numo/types/sfloat.h +13 -0
  105. data/ext/numo/narray/numo/types/uint16.h +12 -0
  106. data/ext/numo/narray/numo/types/uint32.h +12 -0
  107. data/ext/numo/narray/numo/types/uint64.h +12 -0
  108. data/ext/numo/narray/numo/types/uint8.h +12 -0
  109. data/ext/numo/narray/numo/types/uint_macro.h +31 -0
  110. data/ext/numo/narray/numo/types/xint_macro.h +133 -0
  111. data/ext/numo/narray/rand.c +87 -0
  112. data/ext/numo/narray/step.c +506 -0
  113. data/ext/numo/narray/struct.c +872 -0
  114. data/lib/2.1/numo/narray.so +0 -0
  115. data/lib/2.2/numo/narray.so +0 -0
  116. data/lib/2.3/numo/narray.so +0 -0
  117. data/lib/erbpp/line_number.rb +126 -0
  118. data/lib/erbpp/narray_def.rb +338 -0
  119. data/lib/erbpp.rb +286 -0
  120. data/lib/numo/narray.rb +6 -0
  121. data/numo-narray.gemspec +35 -0
  122. data/spec/bit_spec.rb +93 -0
  123. data/spec/narray_spec.rb +249 -0
  124. metadata +238 -0
@@ -0,0 +1,55 @@
1
+ static void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i, n;
5
+ char *p1, *p2, *p3, *p4;
6
+ ssize_t s1, s2, s3, s4;
7
+ dtype x, y, a, b;
8
+ INIT_COUNTER(lp, n);
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=n; i--;) {
14
+ GET_DATA_STRIDE(p1,s1,dtype,x);
15
+ GET_DATA_STRIDE(p2,s2,dtype,y);
16
+ <% if is_int and %w[divmod].include? method %>
17
+ if (y==0) {
18
+ lp->err_type = rb_eZeroDivError;
19
+ return;
20
+ }
21
+ <% end %>
22
+ m_<%=method%>(x,y,a,b);
23
+ SET_DATA_STRIDE(p3,s3,dtype,a);
24
+ SET_DATA_STRIDE(p4,s4,dtype,b);
25
+ }
26
+ }
27
+
28
+ static VALUE
29
+ <%=c_func%>_self(VALUE self, VALUE other)
30
+ {
31
+ ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
32
+ ndfunc_arg_out_t aout[2] = {{cT,0},{cT,0}};
33
+ ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 2, ain, aout };
34
+
35
+ return na_ndloop(&ndf, 2, self, other);
36
+ }
37
+
38
+ /*
39
+ Binary <%=method%>.
40
+ @overload <%=op_map%> other
41
+ @param [Numo::NArray,Numeric] other
42
+ @return [Numo::NArray] <%=method%> of self and other.
43
+ */
44
+ static VALUE
45
+ <%=c_func%>(VALUE self, VALUE other)
46
+ {
47
+ VALUE klass, v;
48
+ klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
49
+ if (klass==cT) {
50
+ return <%=c_func%>_self(self, other);
51
+ } else {
52
+ v = rb_funcall(klass, id_cast, 1, self);
53
+ return rb_funcall(v, <%=id_op%>, 1, other);
54
+ }
55
+ }
@@ -0,0 +1,34 @@
1
+ static void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i;
5
+ char *p1, *p2, *p3;
6
+ ssize_t s1, s2, s3;
7
+ dtype x, y;
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
+ for (; i--;) {
13
+ GET_DATA_STRIDE(p1,s1,dtype,x);
14
+ GET_DATA_STRIDE(p2,s2,dtype,y);
15
+ x = m_<%=method%>(x,y);
16
+ SET_DATA_STRIDE(p3,s3,dtype,x);
17
+ }
18
+ }
19
+
20
+ /*
21
+ Calculate <%=method%>(a1,a2).
22
+ @overload <%=method%>(a1,a2)
23
+ @param [Numo::NArray,Numeric] a1 first value
24
+ @param [Numo::NArray,Numeric] a2 second value
25
+ @return [Numo::<%=class_name%>] <%=method%>(a1,a2).
26
+ */
27
+ static VALUE
28
+ <%=c_func%>(VALUE mod, VALUE a1, VALUE a2)
29
+ {
30
+ ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
31
+ ndfunc_arg_out_t aout[1] = {{cT,0}};
32
+ ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 1, ain, aout };
33
+ return na_ndloop(&ndf, 2, a1, a2);
34
+ }
@@ -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,8 @@
1
+ /*
2
+ @return [nil]
3
+ */
4
+ static VALUE
5
+ <%=c_func %>(VALUE value, VALUE type)
6
+ {
7
+ return Qnil;
8
+ }
@@ -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
+ }
@@ -0,0 +1,45 @@
1
+ static void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i;
5
+ char *p1;
6
+ BIT_DIGIT *a2;
7
+ size_t p2;
8
+ ssize_t s1, s2;
9
+ size_t *idx1;
10
+ dtype x;
11
+ BIT_DIGIT b;
12
+ INIT_COUNTER(lp, i);
13
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
14
+ INIT_PTR_BIT(lp, 1, a2, p2, s2);
15
+ if (idx1) {
16
+ for (; i--;) {
17
+ GET_DATA_INDEX(p1,idx1,dtype,x);
18
+ b = (m_<%=method%>(x)) ? 1:0;
19
+ STORE_BIT(a2,p2,b);
20
+ p2+=s2;
21
+ }
22
+ } else {
23
+ for (; i--;) {
24
+ GET_DATA_STRIDE(p1,s1,dtype,x);
25
+ b = (m_<%=method%>(x)) ? 1:0;
26
+ STORE_BIT(a2,p2,b);
27
+ p2+=s2;
28
+ }
29
+ }
30
+ }
31
+
32
+ /*
33
+ Condition of <%=method%>.
34
+ @overload <%=method%>
35
+ @return [Numo::Bit] Condition of <%=method%>.
36
+ */
37
+ static VALUE
38
+ <%=c_func%>(VALUE self)
39
+ {
40
+ ndfunc_arg_in_t ain[1] = {{cT,0}};
41
+ ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
42
+ ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 1, ain, aout };
43
+
44
+ return na_ndloop(&ndf, 1, self);
45
+ }
@@ -0,0 +1,42 @@
1
+ static void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i;
5
+ char *p1, *p2;
6
+ ssize_t s1, s2;
7
+ dtype x, y;
8
+
9
+ INIT_COUNTER(lp, i);
10
+ INIT_PTR(lp, 0, p1, s1);
11
+ INIT_PTR(lp, 1, p2, s2);
12
+ //printf("i=%lu p1=%lx s1=%lu p2=%lx s2=%lu\n",i,(size_t)p1,s1,(size_t)p2,s2);
13
+
14
+ GET_DATA_STRIDE(p1,s1,dtype,x);
15
+ SET_DATA_STRIDE(p2,s2,dtype,x);
16
+ //printf("i=%lu x=%f\n",i,x);
17
+ for (i--; i--;) {
18
+ GET_DATA_STRIDE(p1,s1,dtype,y);
19
+ x = m_<%=cmacro%>(x,y);
20
+ SET_DATA_STRIDE(p2,s2,dtype,x);
21
+ //printf("i=%lu x=%f\n",i,x);
22
+ }
23
+ }
24
+
25
+ /*
26
+ <%=method.capitalize%> of self.
27
+ @overload <%=method%>(*args)
28
+ @param [Array of Numeric,Range] args Affected dimensions.
29
+ @return [Numo::<%=class_name%>] <%=method%> of self.
30
+ */
31
+ static VALUE
32
+ <%=c_func%>(int argc, VALUE *argv, VALUE self)
33
+ {
34
+ VALUE reduce;
35
+ ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
36
+ ndfunc_arg_out_t aout[1] = {{cT,0}};
37
+ ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE|NDF_CUM,
38
+ 2, 1, ain, aout };
39
+
40
+ reduce = na_reduce_dimension(argc, argv, 1, &self);
41
+ return na_ndloop(&ndf, 2, self, reduce);
42
+ }
@@ -0,0 +1,43 @@
1
+ void
2
+ <%=c_iter%>(na_loop_t *const lp)
3
+ {
4
+ size_t i, s1;
5
+ char *p1;
6
+ size_t *idx1;
7
+ dtype x;
8
+ VALUE y;
9
+
10
+ INIT_COUNTER(lp, i);
11
+ INIT_PTR_IDX(lp, 0, p1, s1, idx1);
12
+ if (idx1) {
13
+ for (; i--;) {
14
+ GET_DATA_INDEX(p1,idx1,dtype,x);
15
+ y = m_data_to_num(x);
16
+ rb_yield(y);
17
+ }
18
+ } else {
19
+ for (; i--;) {
20
+ GET_DATA_STRIDE(p1,s1,dtype,x);
21
+ y = m_data_to_num(x);
22
+ rb_yield(y);
23
+ }
24
+ }
25
+ }
26
+
27
+ /*
28
+ Calls the given block once for each element in self,
29
+ passing that element as a parameter.
30
+ @overload <%=method%>
31
+ @return [Numo::NArray] self
32
+ For a block {|x| ... }
33
+ @yield [x] x is element of NArray.
34
+ */
35
+ static VALUE
36
+ <%=c_func%>(VALUE self)
37
+ {
38
+ ndfunc_arg_in_t ain[1] = {{Qnil,0}};
39
+ ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
40
+
41
+ na_ndloop(&ndf, 1, self);
42
+ return self;
43
+ }