numo-narray 0.9.0.4 → 0.9.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -8
  3. data/Rakefile +9 -0
  4. data/ext/numo/narray/array.c +178 -47
  5. data/ext/numo/narray/data.c +105 -97
  6. data/ext/numo/narray/depend.erb +6 -7
  7. data/ext/numo/narray/gen/cogen.rb +30 -7
  8. data/ext/numo/narray/gen/def/bit.rb +17 -14
  9. data/ext/numo/narray/gen/def/dcomplex.rb +19 -15
  10. data/ext/numo/narray/gen/def/dfloat.rb +17 -13
  11. data/ext/numo/narray/gen/def/int16.rb +16 -12
  12. data/ext/numo/narray/gen/def/int32.rb +16 -12
  13. data/ext/numo/narray/gen/def/int64.rb +16 -12
  14. data/ext/numo/narray/gen/def/int8.rb +16 -12
  15. data/ext/numo/narray/gen/def/robject.rb +18 -14
  16. data/ext/numo/narray/gen/def/scomplex.rb +19 -15
  17. data/ext/numo/narray/gen/def/sfloat.rb +17 -13
  18. data/ext/numo/narray/gen/def/uint16.rb +16 -12
  19. data/ext/numo/narray/gen/def/uint32.rb +16 -12
  20. data/ext/numo/narray/gen/def/uint64.rb +16 -12
  21. data/ext/numo/narray/gen/def/uint8.rb +16 -12
  22. data/ext/numo/narray/gen/erbpp2.rb +324 -0
  23. data/ext/numo/narray/gen/narray_def.rb +252 -0
  24. data/ext/numo/narray/gen/spec.rb +141 -71
  25. data/ext/numo/narray/gen/tmpl/accum.c +22 -9
  26. data/ext/numo/narray/gen/tmpl/accum_binary.c +29 -13
  27. data/ext/numo/narray/gen/tmpl/accum_index.c +38 -16
  28. data/ext/numo/narray/gen/tmpl/alloc_func.c +107 -0
  29. data/ext/numo/narray/gen/tmpl/allocate.c +1 -1
  30. data/ext/numo/narray/gen/tmpl/aref.c +1 -1
  31. data/ext/numo/narray/gen/tmpl/aset.c +4 -2
  32. data/ext/numo/narray/gen/tmpl/binary.c +4 -4
  33. data/ext/numo/narray/gen/tmpl/binary2.c +5 -5
  34. data/ext/numo/narray/gen/tmpl/binary_s.c +5 -5
  35. data/ext/numo/narray/gen/tmpl/bincount.c +4 -4
  36. data/ext/numo/narray/gen/tmpl/cast.c +9 -6
  37. data/ext/numo/narray/gen/tmpl/cast_array.c +4 -9
  38. data/ext/numo/narray/gen/tmpl/class.c +9 -0
  39. data/ext/numo/narray/gen/tmpl/clip.c +118 -0
  40. data/ext/numo/narray/gen/tmpl/coerce_cast.c +4 -2
  41. data/ext/numo/narray/gen/tmpl/cond_binary.c +5 -5
  42. data/ext/numo/narray/gen/tmpl/cond_unary.c +6 -6
  43. data/ext/numo/narray/gen/tmpl/cum.c +18 -9
  44. data/ext/numo/narray/gen/tmpl/each.c +2 -2
  45. data/ext/numo/narray/gen/tmpl/each_with_index.c +2 -2
  46. data/ext/numo/narray/gen/tmpl/extract.c +2 -2
  47. data/ext/numo/narray/gen/tmpl/extract_data.c +48 -0
  48. data/ext/numo/narray/gen/tmpl/eye.c +3 -3
  49. data/ext/numo/narray/gen/tmpl/fill.c +2 -2
  50. data/ext/numo/narray/gen/tmpl/format.c +5 -5
  51. data/ext/numo/narray/gen/tmpl/format_to_a.c +4 -4
  52. data/ext/numo/narray/gen/tmpl/frexp.c +37 -0
  53. data/ext/numo/narray/gen/tmpl/init_class.c +20 -0
  54. data/ext/numo/narray/gen/tmpl/init_module.c +12 -0
  55. data/ext/numo/narray/gen/tmpl/inspect.c +2 -2
  56. data/ext/numo/narray/gen/tmpl/lib.c +45 -0
  57. data/ext/numo/narray/gen/tmpl/logseq.c +1 -1
  58. data/ext/numo/narray/gen/tmpl/map_with_index.c +2 -2
  59. data/ext/numo/narray/gen/tmpl/median.c +31 -8
  60. data/ext/numo/narray/gen/tmpl/minmax.c +24 -24
  61. data/ext/numo/narray/gen/tmpl/module.c +9 -0
  62. data/ext/numo/narray/gen/tmpl/new_dim0.c +12 -0
  63. data/ext/numo/narray/gen/tmpl/poly.c +3 -3
  64. data/ext/numo/narray/gen/tmpl/pow.c +1 -1
  65. data/ext/numo/narray/gen/tmpl/powint.c +1 -1
  66. data/ext/numo/narray/gen/tmpl/qsort.c +10 -3
  67. data/ext/numo/narray/gen/tmpl/rand.c +1 -1
  68. data/ext/numo/narray/gen/tmpl/rand_norm.c +1 -1
  69. data/ext/numo/narray/gen/tmpl/seq.c +1 -1
  70. data/ext/numo/narray/gen/tmpl/set2.c +5 -5
  71. data/ext/numo/narray/gen/tmpl/sort.c +29 -14
  72. data/ext/numo/narray/gen/tmpl/sort_index.c +41 -20
  73. data/ext/numo/narray/gen/tmpl/store.c +11 -5
  74. data/ext/numo/narray/gen/tmpl/store_array.c +1 -1
  75. data/ext/numo/narray/gen/tmpl/store_bit.c +1 -1
  76. data/ext/numo/narray/gen/tmpl/store_from.c +1 -1
  77. data/ext/numo/narray/gen/tmpl/store_numeric.c +3 -16
  78. data/ext/numo/narray/gen/tmpl/to_a.c +2 -2
  79. data/ext/numo/narray/gen/tmpl/unary.c +7 -7
  80. data/ext/numo/narray/gen/tmpl/unary2.c +8 -8
  81. data/ext/numo/narray/gen/tmpl/unary_ret2.c +33 -0
  82. data/ext/numo/narray/gen/tmpl/unary_s.c +8 -8
  83. data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -5
  84. data/ext/numo/narray/gen/tmpl_bit/aref.c +1 -1
  85. data/ext/numo/narray/gen/tmpl_bit/aset.c +2 -2
  86. data/ext/numo/narray/gen/tmpl_bit/binary.c +8 -8
  87. data/ext/numo/narray/gen/tmpl_bit/bit_count.c +8 -8
  88. data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +6 -6
  89. data/ext/numo/narray/gen/tmpl_bit/each.c +2 -2
  90. data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +2 -2
  91. data/ext/numo/narray/gen/tmpl_bit/extract.c +1 -1
  92. data/ext/numo/narray/gen/tmpl_bit/fill.c +2 -2
  93. data/ext/numo/narray/gen/tmpl_bit/format.c +5 -5
  94. data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +2 -2
  95. data/ext/numo/narray/gen/tmpl_bit/inspect.c +2 -2
  96. data/ext/numo/narray/gen/tmpl_bit/mask.c +5 -5
  97. data/ext/numo/narray/gen/tmpl_bit/none_p.c +4 -4
  98. data/ext/numo/narray/gen/tmpl_bit/store_array.c +2 -2
  99. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +1 -1
  100. data/ext/numo/narray/gen/tmpl_bit/store_from.c +1 -1
  101. data/ext/numo/narray/gen/tmpl_bit/to_a.c +2 -2
  102. data/ext/numo/narray/gen/tmpl_bit/unary.c +9 -9
  103. data/ext/numo/narray/gen/tmpl_bit/where.c +6 -6
  104. data/ext/numo/narray/gen/tmpl_bit/where2.c +8 -8
  105. data/ext/numo/narray/index.c +46 -30
  106. data/ext/numo/narray/math.c +12 -6
  107. data/ext/numo/narray/narray.c +242 -218
  108. data/ext/numo/narray/ndloop.c +17 -24
  109. data/ext/numo/narray/numo/intern.h +63 -67
  110. data/ext/numo/narray/numo/narray.h +38 -13
  111. data/ext/numo/narray/numo/ndloop.h +1 -1
  112. data/ext/numo/narray/numo/template.h +1 -1
  113. data/ext/numo/narray/numo/types/complex.h +8 -4
  114. data/ext/numo/narray/numo/types/complex_macro.h +118 -1
  115. data/ext/numo/narray/numo/types/float_macro.h +283 -6
  116. data/ext/numo/narray/numo/types/robj_macro.h +261 -9
  117. data/ext/numo/narray/numo/types/xint_macro.h +35 -0
  118. data/ext/numo/narray/struct.c +34 -15
  119. data/lib/erbpp.rb +5 -1
  120. data/lib/erbpp/line_number.rb +10 -3
  121. data/lib/erbpp/narray_def.rb +55 -25
  122. data/lib/numo/narray/extra.rb +638 -219
  123. data/numo-narray.gemspec +1 -0
  124. data/spec/narray_spec.rb +2 -2
  125. metadata +17 -14
  126. data/ext/numo/narray/gen/dtype.erb.c +0 -82
  127. data/ext/numo/narray/gen/tmpl/cast_numeric.c +0 -22
  128. data/ext/numo/narray/gen/tmpl/robj_allocate.c +0 -32
  129. data/ext/numo/narray/gen/tmpl_bit/cast.c +0 -37
  130. data/ext/numo/narray/gen/tmpl_bit/cast_array.c +0 -18
  131. data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +0 -22
  132. data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +0 -8
  133. data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +0 -94
  134. data/ext/numo/narray/gen/tmpl_bit/store.c +0 -32
  135. data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +0 -22
@@ -1,5 +1,3 @@
1
- # Define ID
2
-
3
1
  def_id "cast"
4
2
  def_id "eq"
5
3
  def_id "ne"
@@ -15,7 +13,11 @@ if is_float
15
13
  def_id "nearly_eq"
16
14
  def_id "copysign"
17
15
  end
18
- if is_comparable
16
+ if is_int
17
+ def_id "<<","left_shift"
18
+ def_id ">>","right_shift"
19
+ end
20
+ if is_comparable && !is_object
19
21
  def_id "gt"
20
22
  def_id "ge"
21
23
  def_id "lt"
@@ -37,70 +39,96 @@ if is_object
37
39
  def_id "nan?"
38
40
  def_id "infinite?"
39
41
  def_id "finite?"
40
- def_id "==","op_eq"
41
- def_id "!=","op_ne"
42
- def_id ">" ,"op_gt"
43
- def_id ">=","op_ge"
44
- def_id "<" ,"op_lt"
45
- def_id "<=","op_le"
46
- def_id "<=>","op_ufo"
42
+ def_id "==","eq"
43
+ def_id "!=","ne"
44
+ def_id ">" ,"gt"
45
+ def_id ">=","ge"
46
+ def_id "<" ,"lt"
47
+ def_id "<=","le"
48
+ def_id "<=>","ufo"
47
49
  end
48
50
 
49
51
  if is_int && !is_object
50
52
  def_id "minlength" # for bincount
51
53
  end
52
54
 
53
- # Allocation
55
+ # Constatnts
56
+
57
+ if is_bit
58
+ def_const "ELEMENT_BIT_SIZE", "INT2FIX(1)"
59
+ def_const "ELEMENT_BYTE_SIZE", "rb_float_new(1.0/8)"
60
+ def_const "CONTIGUOUS_STRIDE", "INT2FIX(1)"
61
+ else
62
+ def_const "ELEMENT_BIT_SIZE", "INT2FIX(sizeof(dtype)*8)"
63
+ def_const "ELEMENT_BYTE_SIZE", "INT2FIX(sizeof(dtype))"
64
+ def_const "CONTIGUOUS_STRIDE", "INT2FIX(sizeof(dtype))"
65
+ end
66
+
67
+ # Un-define
54
68
 
55
69
  if is_object
56
- def_allocate "robj_allocate"
70
+ undef_singleton_method "from_binary"
71
+ undef_method "to_binary"
72
+ undef_method "swap_byte"
73
+ undef_method "to_network"
74
+ undef_method "to_vacs"
75
+ undef_method "to_host"
76
+ undef_method "to_swapped"
57
77
  end
58
- def_method "allocate", 0
78
+
79
+ # Allocation
80
+
81
+ def_alloc_func "alloc_func"
82
+ def_method "allocate"
59
83
 
60
84
  # Type conversion
61
85
 
62
- def_method "extract", 0
63
- store_numeric
64
- store_bit "Bit"
65
- if is_complex
66
- store_from "DComplex","dcomplex","m_from_dcomplex"
67
- store_from "SComplex","scomplex","m_from_scomplex"
68
- end
69
- store_from "DFloat","double", "m_from_real"
70
- store_from "SFloat","float", "m_from_real"
71
- store_from "Int64", "int64_t", "m_from_real"
72
- store_from "Int32", "int32_t", "m_from_real"
73
- store_from "Int16", "int16_t", "m_from_real"
74
- store_from "Int8", "int8_t", "m_from_real"
75
- store_from "UInt64","u_int64_t","m_from_real"
76
- store_from "UInt32","u_int32_t","m_from_real"
77
- store_from "UInt16","u_int16_t","m_from_real"
78
- store_from "UInt8", "u_int8_t", "m_from_real"
86
+ def_method "extract"
87
+ def_method "new_dim0"
79
88
 
80
- store_from "RObject", "VALUE", "m_num_to_data"
89
+ def_method "store" do
90
+ extend StoreFrom
91
+ store_numeric
92
+ store_from "Bit"
93
+ if is_complex
94
+ store_from "DComplex","dcomplex","m_from_dcomplex"
95
+ store_from "SComplex","scomplex","m_from_scomplex"
96
+ end
97
+ store_from "DFloat","double", "m_from_real"
98
+ store_from "SFloat","float", "m_from_real"
99
+ store_from "Int64", "int64_t", "m_from_real"
100
+ store_from "Int32", "int32_t", "m_from_real"
101
+ store_from "Int16", "int16_t", "m_from_real"
102
+ store_from "Int8", "int8_t", "m_from_real"
103
+ store_from "UInt64","u_int64_t","m_from_real"
104
+ store_from "UInt32","u_int32_t","m_from_real"
105
+ store_from "UInt16","u_int16_t","m_from_real"
106
+ store_from "UInt8", "u_int8_t", "m_from_real"
107
+ store_from "RObject", "VALUE", "m_num_to_data"
108
+ store_array
109
+ end
81
110
 
82
- store_array
83
- cast_array
111
+ def_method "extract_data"
84
112
 
85
- def_method "store", 1
86
- def_singleton "cast", 1
113
+ def_method "cast_array"
114
+ def_singleton_method "cast"
87
115
 
88
- def_method "aref", -1, "aref", :op=>"[]"
89
- def_method "aset", -1, "aset", :op=>"[]="
116
+ def_method "aref", op:"[]"
117
+ def_method "aset", op:"[]="
90
118
 
91
- def_method "coerce_cast", 1
92
- def_method "to_a", 0
93
- def_method "fill", 1
94
- def_method "format", -1
95
- def_method "format_to_a", -1
96
- def_method "inspect", 0
119
+ def_method "coerce_cast"
120
+ def_method "to_a"
121
+ def_method "fill"
122
+ def_method "format"
123
+ def_method "format_to_a"
124
+ def_method "inspect"
97
125
 
98
126
 
99
127
  # Array manipulation
100
128
 
101
- def_method "each", 0
129
+ def_method "each"
102
130
  unary "map" if !is_bit
103
- def_method "each_with_index", 0
131
+ def_method "each_with_index"
104
132
 
105
133
  if is_bit
106
134
  unary "copy"
@@ -116,12 +144,13 @@ if is_bit
116
144
  def_alias "count_0","count_false"
117
145
  bit_reduce "all?", 1
118
146
  bit_reduce "any?", 0
119
- def_method "none?", -1, "none_p"
120
- def_method "where", 0
121
- def_method "where2", 0
122
- def_method "mask", 1
147
+ def_method "none?", "none_p"
148
+ def_method "where"
149
+ def_method "where2"
150
+ def_method "mask"
123
151
  else
124
- def_method "map_with_index", 0
152
+
153
+ def_method "map_with_index"
125
154
 
126
155
  # Arithmetic
127
156
 
@@ -142,6 +171,7 @@ pow
142
171
  unary "minus", "-@"
143
172
  unary "reciprocal"
144
173
  unary "sign"
174
+ unary "square"
145
175
 
146
176
  # Complex
147
177
 
@@ -157,8 +187,8 @@ if is_complex
157
187
  def_alias "imag=","set_imag"
158
188
  def_alias "real=","set_real"
159
189
  else
160
- def_alias "conj", "copy"
161
- def_alias "im", "copy"
190
+ def_alias "conj", "view"
191
+ def_alias "im", "view"
162
192
  end
163
193
 
164
194
  def_alias "conjugate","conj"
@@ -182,12 +212,14 @@ if is_int
182
212
  binary "bit_or" , "|"
183
213
  binary "bit_xor", "^"
184
214
  unary "bit_not", "~"
215
+ binary "left_shift", "<<"
216
+ binary "right_shift", ">>"
185
217
  if !is_object
186
- def_alias "floor", "copy"
187
- def_alias "round", "copy"
188
- def_alias "ceil", "copy"
189
- def_alias "trunc", "copy"
190
- def_alias "rint", "copy"
218
+ def_alias "floor", "view"
219
+ def_alias "round", "view"
220
+ def_alias "ceil", "view"
221
+ def_alias "trunc", "view"
222
+ def_alias "rint", "view"
191
223
  end
192
224
  end
193
225
 
@@ -199,6 +231,10 @@ if is_float
199
231
  if !is_object
200
232
  unary "rint"
201
233
  binary "copysign"
234
+ if !is_complex
235
+ cond_unary "signbit"
236
+ def_method "modf", "unary_ret2"
237
+ end
202
238
  end
203
239
  end
204
240
 
@@ -211,6 +247,7 @@ if is_comparable
211
247
  def_alias ">=","ge"
212
248
  def_alias "<", "lt"
213
249
  def_alias "<=","le"
250
+ def_method "clip"
214
251
  end
215
252
 
216
253
  # Float
@@ -218,6 +255,8 @@ end
218
255
  if is_float
219
256
  cond_unary "isnan"
220
257
  cond_unary "isinf"
258
+ cond_unary "isposinf"
259
+ cond_unary "isneginf"
221
260
  cond_unary "isfinite"
222
261
  end
223
262
 
@@ -237,13 +276,14 @@ end
237
276
  if is_comparable
238
277
  accum "min","dtype","cT"
239
278
  accum "max","dtype","cT"
279
+ accum "ptp","dtype","cT"
240
280
  accum_index "max_index"
241
281
  accum_index "min_index"
242
- def_method "minmax",-1
282
+ def_method "minmax"
243
283
  end
244
284
 
245
285
  if is_int && !is_object
246
- def_method "bincount",-1
286
+ def_method "bincount"
247
287
  end
248
288
 
249
289
  cum "cumsum","add"
@@ -258,33 +298,57 @@ accum_binary "mulsum"
258
298
  # shuffle
259
299
  # histogram
260
300
 
261
- def_method "seq",-1
301
+ def_method "seq"
262
302
  if is_float
263
- def_method "logseq",-1
303
+ def_method "logseq"
264
304
  end
265
- def_method "eye",-1
305
+ def_method "eye"
266
306
  def_alias "indgen", "seq"
267
307
 
268
- def_method "rand", -1
308
+ def_method "rand"
269
309
  if is_float && !is_object
270
- def_method "rand_norm", -1
310
+ def_method "rand_norm"
271
311
  end
272
312
 
273
313
  # y = a[0] + a[1]*x + a[2]*x^2 + a[3]*x^3 + ... + a[n]*x^n
274
- def_method "poly",-2
314
+ def_method "poly"
275
315
 
276
316
  if is_comparable && !is_object
277
- qsort type_name,"dtype","*(dtype*)"
278
- def_method "sort",-1
279
- qsort type_name+"_index","dtype*","**(dtype**)"
280
- def_method "sort_index",-1
281
- def_method "median",-1
317
+ if is_float
318
+ qsort type_name,"dtype","*(dtype*)","_prnan"
319
+ qsort type_name,"dtype","*(dtype*)","_ignan"
320
+ else
321
+ qsort type_name,"dtype","*(dtype*)"
322
+ end
323
+ def_method "sort"
324
+ if is_float
325
+ qsort type_name+"_index","dtype*","**(dtype**)","_prnan"
326
+ qsort type_name+"_index","dtype*","**(dtype**)","_ignan"
327
+ else
328
+ qsort type_name+"_index","dtype*","**(dtype**)"
329
+ end
330
+ def_method "sort_index"
331
+ def_method "median"
282
332
  end
283
333
 
284
334
  # Math
285
335
  # histogram
286
336
 
287
337
  if has_math
338
+ fn = get(:full_class_name)
339
+ cn = get(:class_name)
340
+ nm = get(:name)
341
+ is_c = is_complex
342
+
343
+ def_module do
344
+ extend NMathMethod
345
+ set ns_var: "cT"
346
+ set class_name: cn
347
+ set name: "#{nm}_math"
348
+ set full_module_name: fn+"::NMath"
349
+ set module_name: "Math"
350
+ set module_var: "mTM"
351
+
288
352
  math "sqrt"
289
353
  math "cbrt"
290
354
  math "log"
@@ -305,12 +369,18 @@ if has_math
305
369
  math "asinh"
306
370
  math "acosh"
307
371
  math "atanh"
308
- if !is_complex
372
+ math "sinc"
373
+ if !is_c
309
374
  math "atan2",2
310
375
  math "hypot",2
311
376
  math "erf"
312
377
  math "erfc"
378
+ math "log1p"
379
+ math "expm1"
313
380
  math "ldexp",2
381
+ math "frexp",1,"frexp"
314
382
  end
315
383
  end
316
384
  end
385
+
386
+ end # other than Bit
@@ -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 n;
5
6
  char *p1, *p2;
@@ -9,27 +10,39 @@ static void
9
10
  INIT_PTR(lp, 0, p1, s1);
10
11
  p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
11
12
 
12
- *(<%=dtype%>*)p2 = f_<%=method%>(n,p1,s1);
13
+ *(<%=dtype%>*)p2 = f_<%=name%><%=j%>(n,p1,s1);
13
14
  }
15
+ <% end %>
14
16
 
15
17
  /*
16
- <%=method.capitalize%> of self.
17
- @overload <%=method%>(*args)
18
- @param [Array of Numeric,Range] args Affected dimensions.
19
- @return [Numo::<%=class_name%>] <%=method%> of self.
18
+ <%=name%> of self.
19
+ <% if is_float %>
20
+ @overload <%=name%>(axis:nil, nan:false)
21
+ @param [TrueClass] nan If true, propagete NaN. If false, ignore NaN.
22
+ <% else %>
23
+ @overload <%=name%>(axis:nil)
24
+ <% end %>
25
+ @param [Numeric,Array,Range] axis Affected dimensions.
26
+ @return [Numo::<%=class_name%>] returns result of <%=name%>.
20
27
  */
21
28
  static VALUE
22
- <%=c_func%>(int argc, VALUE *argv, VALUE self)
29
+ <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
23
30
  {
31
+ int ignore_nan = 0;
24
32
  VALUE v, reduce;
25
33
  ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
26
34
  ndfunc_arg_out_t aout[1] = {{<%=tpclass%>,0}};
27
35
  ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };
28
36
 
29
- reduce = na_reduce_dimension(argc, argv, 1, &self);
37
+ reduce = na_reduce_dimension(argc, argv, 1, &self, &ignore_nan);
38
+ <% if is_float %>
39
+ if (ignore_nan) {
40
+ ndf.func = <%=c_iter%>_nan;
41
+ }
42
+ <% end %>
30
43
  v = na_ndloop(&ndf, 2, self, reduce);
31
44
  <% if tpclass == "cT" %>
32
- return numo_<%=tp%>_extract(v);
45
+ return <%=type_name%>_extract(v);
33
46
  <% else %>
34
47
  return rb_funcall(v,rb_intern("extract"),0);
35
48
  <% end %>
@@ -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, *p3;
@@ -16,7 +17,7 @@ static void
16
17
  for (; i--;) {
17
18
  GET_DATA_STRIDE(p1,s1,dtype,x);
18
19
  GET_DATA_STRIDE(p2,s2,dtype,y);
19
- m_<%=method%>(x,y,z);
20
+ m_<%=name%><%=j%>(x,y,z);
20
21
  }
21
22
  SET_DATA(p3,dtype,z);
22
23
  } else {
@@ -24,16 +25,17 @@ static void
24
25
  GET_DATA_STRIDE(p1,s1,dtype,x);
25
26
  GET_DATA_STRIDE(p2,s2,dtype,y);
26
27
  GET_DATA(p3,dtype,z);
27
- m_<%=method%>(x,y,z);
28
+ m_<%=name%><%=j%>(x,y,z);
28
29
  SET_DATA_STRIDE(p3,s3,dtype,z);
29
30
  }
30
31
  }
31
32
  }
32
-
33
+ <% end %>
33
34
 
34
35
  static VALUE
35
36
  <%=c_func%>_self(int argc, VALUE *argv, VALUE self)
36
37
  {
38
+ int ignore_nan = 0;
37
39
  VALUE v, reduce;
38
40
  VALUE naryv[2];
39
41
  ndfunc_arg_in_t ain[4] = {{cT,0},{cT,0},{sym_reduce,0},{sym_init,0}};
@@ -46,20 +48,34 @@ static VALUE
46
48
  // should fix below: [self.ndim,other.ndim].max or?
47
49
  naryv[0] = self;
48
50
  naryv[1] = argv[0];
49
- reduce = na_reduce_dimension(argc-1, argv+1, 2, naryv);
50
- v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_<%=method%>_init);
51
- return numo_<%=tp%>_extract(v);
51
+ reduce = na_reduce_dimension(argc-1, argv+1, 2, naryv, &ignore_nan);
52
+ <% if is_float %>
53
+ if (ignore_nan) {
54
+ ndf.func = <%=c_iter%>_nan;
55
+ }
56
+ <% end %>
57
+ v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_<%=name%>_init);
58
+ return <%=type_name%>_extract(v);
52
59
  }
53
60
 
54
-
55
61
  /*
56
- Binary <%=method%>.
57
- @overload <%=op_map%> other
62
+ Binary <%=name%>.
63
+
64
+ <% if is_float %>
65
+ @overload <%=op_map%>(other, axis:nil, nan:false)
66
+ @param [TrueClass] nan If true, propagete NaN. If false, ignore NaN.
67
+ <% else %>
68
+ @overload <%=op_map%>(other, axis:nil)
69
+ <% end %>
58
70
  @param [Numo::NArray,Numeric] other
59
- @return [Numo::NArray] <%=method%> of self and other.
71
+ @param [Numeric,Array,Range] axis Affected dimensions.
72
+ <% if is_float %>
73
+ @param [TrueClass] nan If true, propagete NaN. If false, ignore NaN.
74
+ <% end %>
75
+ @return [Numo::NArray] <%=name%> of self and other.
60
76
  */
61
77
  static VALUE
62
- <%=c_func%>(int argc, VALUE *argv, VALUE self)
78
+ <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
63
79
  {
64
80
  <% if !is_object %>
65
81
  VALUE klass, v;
@@ -75,7 +91,7 @@ static VALUE
75
91
  return <%=c_func%>_self(argc, argv, self);
76
92
  } else {
77
93
  v = rb_funcall(klass, id_cast, 1, self);
78
- return rb_funcall2(v, rb_intern("<%=method%>"), argc, argv);
94
+ return rb_funcall2(v, rb_intern("<%=name%>"), argc, argv);
79
95
  }
80
96
  <% end %>
81
97
  }