carray 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSES → LICENSE} +0 -0
  3. data/NEWS.md +42 -0
  4. data/README.md +5 -5
  5. data/TODO.md +16 -0
  6. data/carray.gemspec +9 -5
  7. data/ext/ca_iter_block.c +3 -5
  8. data/ext/ca_iter_dimension.c +4 -5
  9. data/ext/ca_iter_window.c +2 -4
  10. data/ext/ca_obj_array.c +394 -124
  11. data/ext/ca_obj_bitarray.c +3 -5
  12. data/ext/ca_obj_bitfield.c +3 -5
  13. data/ext/ca_obj_block.c +6 -8
  14. data/ext/ca_obj_fake.c +3 -5
  15. data/ext/ca_obj_farray.c +3 -5
  16. data/ext/ca_obj_field.c +15 -17
  17. data/ext/ca_obj_grid.c +5 -6
  18. data/ext/ca_obj_mapping.c +2 -4
  19. data/ext/ca_obj_object.c +3 -5
  20. data/ext/ca_obj_reduce.c +2 -4
  21. data/ext/ca_obj_refer.c +5 -7
  22. data/ext/ca_obj_repeat.c +2 -4
  23. data/ext/ca_obj_select.c +2 -4
  24. data/ext/ca_obj_shift.c +3 -5
  25. data/ext/ca_obj_transpose.c +3 -5
  26. data/ext/ca_obj_unbound_repeat.c +58 -81
  27. data/ext/ca_obj_window.c +7 -9
  28. data/ext/carray.h +13 -8
  29. data/ext/carray_access.c +111 -18
  30. data/ext/carray_attribute.c +136 -197
  31. data/ext/carray_call_cfunc.c +1 -3
  32. data/ext/carray_cast.c +344 -143
  33. data/ext/carray_cast_func.rb +1 -2
  34. data/ext/carray_class.c +28 -36
  35. data/ext/carray_conversion.c +49 -59
  36. data/ext/carray_copy.c +16 -32
  37. data/ext/carray_core.c +51 -44
  38. data/ext/carray_element.c +25 -44
  39. data/ext/carray_generate.c +71 -50
  40. data/ext/carray_iterator.c +13 -15
  41. data/ext/carray_loop.c +53 -82
  42. data/ext/carray_mask.c +87 -117
  43. data/ext/carray_math.rb +8 -10
  44. data/ext/carray_mathfunc.c +1 -3
  45. data/ext/carray_numeric.c +19 -3
  46. data/ext/carray_operator.c +45 -32
  47. data/ext/carray_order.c +72 -65
  48. data/ext/carray_sort_addr.c +14 -21
  49. data/ext/carray_stat.c +1 -3
  50. data/ext/carray_stat_proc.rb +2 -4
  51. data/ext/carray_test.c +28 -30
  52. data/ext/carray_undef.c +1 -3
  53. data/ext/carray_utils.c +12 -4
  54. data/ext/extconf.rb +1 -1
  55. data/ext/mkmath.rb +1 -1
  56. data/ext/ruby_carray.c +11 -6
  57. data/ext/ruby_ccomplex.c +1 -3
  58. data/ext/ruby_float_func.c +1 -3
  59. data/ext/version.h +5 -7
  60. data/lib/carray.rb +2 -0
  61. data/lib/carray/autoload/autoload_gem_numo_narray.rb +6 -6
  62. data/lib/carray/broadcast.rb +45 -0
  63. data/lib/carray/construct.rb +21 -4
  64. data/lib/carray/iterator.rb +1 -0
  65. data/lib/carray/ordering.rb +28 -2
  66. data/spec/Classes/CABitfield_spec.rb +58 -0
  67. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  68. data/spec/Classes/CABlock_spec.rb +205 -0
  69. data/spec/Classes/CAField_spec.rb +39 -0
  70. data/spec/Classes/CAGrid_spec.rb +75 -0
  71. data/spec/Classes/CAMap_spec.rb +0 -0
  72. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  73. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  74. data/spec/Classes/CAObject_spec.rb +33 -0
  75. data/spec/Classes/CARefer_spec.rb +93 -0
  76. data/spec/Classes/CARepeat_spec.rb +65 -0
  77. data/spec/Classes/CASelect_spec.rb +22 -0
  78. data/spec/Classes/CAShift_spec.rb +16 -0
  79. data/spec/Classes/CAStruct_spec.rb +71 -0
  80. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  81. data/spec/Classes/CAUnboudRepeat_spec.rb +78 -0
  82. data/spec/Classes/CAWindow_spec.rb +54 -0
  83. data/spec/Classes/CAWrap_spec.rb +8 -0
  84. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  85. data/spec/Classes/CScalar_spec.rb +55 -0
  86. data/spec/Features/feature_130_spec.rb +19 -0
  87. data/spec/Features/feature_attributes_spec.rb +280 -0
  88. data/spec/Features/feature_boolean_spec.rb +97 -0
  89. data/spec/Features/feature_broadcast.rb +100 -0
  90. data/spec/Features/feature_cast_function.rb +19 -0
  91. data/spec/Features/feature_cast_spec.rb +33 -0
  92. data/spec/Features/feature_class_spec.rb +84 -0
  93. data/spec/Features/feature_complex_spec.rb +42 -0
  94. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  95. data/spec/Features/feature_convert_spec.rb +46 -0
  96. data/spec/Features/feature_copy_spec.rb +123 -0
  97. data/spec/Features/feature_creation_spec.rb +84 -0
  98. data/spec/Features/feature_element_spec.rb +144 -0
  99. data/spec/Features/feature_extream_spec.rb +54 -0
  100. data/spec/Features/feature_generate_spec.rb +74 -0
  101. data/spec/Features/feature_index_spec.rb +69 -0
  102. data/spec/Features/feature_mask_spec.rb +574 -0
  103. data/spec/Features/feature_math_spec.rb +97 -0
  104. data/spec/Features/feature_order_spec.rb +146 -0
  105. data/spec/Features/feature_ref_store_spec.rb +209 -0
  106. data/spec/Features/feature_serialization_spec.rb +125 -0
  107. data/spec/Features/feature_stat_spec.rb +397 -0
  108. data/spec/Features/feature_virtual_spec.rb +48 -0
  109. data/spec/Features/method_eq_spec.rb +81 -0
  110. data/spec/Features/method_is_nan_spec.rb +12 -0
  111. data/spec/Features/method_map_spec.rb +54 -0
  112. data/spec/Features/method_max_with.rb +20 -0
  113. data/spec/Features/method_min_with.rb +19 -0
  114. data/spec/Features/method_ne_spec.rb +18 -0
  115. data/spec/Features/method_project_spec.rb +188 -0
  116. data/spec/Features/method_ref_spec.rb +27 -0
  117. data/spec/Features/method_round_spec.rb +11 -0
  118. data/spec/Features/method_s_linspace_spec.rb +48 -0
  119. data/spec/Features/method_s_span_spec.rb +14 -0
  120. data/spec/Features/method_seq_spec.rb +47 -0
  121. data/spec/Features/method_sort_with.rb +43 -0
  122. data/spec/Features/method_sorted_with.rb +29 -0
  123. data/spec/Features/method_span_spec.rb +42 -0
  124. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  125. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  126. data/spec/spec_all.rb +0 -1
  127. data/utils/convert_test.rb +73 -0
  128. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  129. metadata +77 -60
  130. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  131. data/spec/CArray/bug/store_spec.rb +0 -27
  132. data/spec/CArray/index/repeat_spec.rb +0 -10
  133. data/spec/CArray/method/eq_spec.rb +0 -80
  134. data/spec/CArray/method/is_nan_spec.rb +0 -12
  135. data/spec/CArray/method/ne_spec.rb +0 -18
  136. data/spec/CArray/method/round_spec.rb +0 -11
  137. data/spec/CArray/object/_attribute_spec.rb +0 -32
  138. data/spec/CArray/object/s_new_spec.rb +0 -31
  139. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  140. data/test/test_130.rb +0 -23
  141. data/test/test_ALL.rb +0 -49
  142. data/test/test_CABitfield.rb +0 -59
  143. data/test/test_CABlock.rb +0 -208
  144. data/test/test_CAField.rb +0 -40
  145. data/test/test_CAGrid.rb +0 -76
  146. data/test/test_CAMmap.rb +0 -11
  147. data/test/test_CARefer.rb +0 -94
  148. data/test/test_CARepeat.rb +0 -66
  149. data/test/test_CASelect.rb +0 -23
  150. data/test/test_CAShift.rb +0 -17
  151. data/test/test_CAWindow.rb +0 -55
  152. data/test/test_CAWrap.rb +0 -9
  153. data/test/test_CComplex.rb +0 -83
  154. data/test/test_CScalar.rb +0 -91
  155. data/test/test_attribute.rb +0 -281
  156. data/test/test_block_iterator.rb +0 -17
  157. data/test/test_boolean.rb +0 -99
  158. data/test/test_cast.rb +0 -33
  159. data/test/test_class.rb +0 -85
  160. data/test/test_complex.rb +0 -43
  161. data/test/test_convert.rb +0 -79
  162. data/test/test_copy.rb +0 -141
  163. data/test/test_creation.rb +0 -85
  164. data/test/test_element.rb +0 -146
  165. data/test/test_extream.rb +0 -55
  166. data/test/test_generate.rb +0 -75
  167. data/test/test_index.rb +0 -71
  168. data/test/test_mask.rb +0 -578
  169. data/test/test_math.rb +0 -98
  170. data/test/test_order.rb +0 -147
  171. data/test/test_ref_store.rb +0 -211
  172. data/test/test_stat.rb +0 -406
  173. data/test/test_struct.rb +0 -72
  174. data/test/test_virtual.rb +0 -49
@@ -3,10 +3,8 @@
3
3
  carray_sort_addr.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -151,16 +149,14 @@ qcmp_func (struct cmp_data *a, struct cmp_data *b)
151
149
  return ( ia > ib ) ? 1 : -1; /* for stable sort */
152
150
  }
153
151
 
154
- /* rdoc:
155
- # returns index table for index sort
156
- #
157
- # idx = CA.sort_addr(a, b, c) ### priority a > b > c
158
- # a[idx]
159
- # b[idx]
160
- # c[idx]
152
+ /* @overload sort_addr (*args)
161
153
 
162
- def CA.sort_addr (*args)
163
- end
154
+ (Sort) Returns index table for index sort
155
+
156
+ idx = CA.sort_addr(a, b, c) ### priority a > b > c
157
+ a[idx]
158
+ b[idx]
159
+ c[idx]
164
160
  */
165
161
 
166
162
  static VALUE
@@ -234,15 +230,12 @@ rb_ca_s_sort_addr (int argc, VALUE *argv, VALUE self)
234
230
  return out;
235
231
  }
236
232
 
237
- /* rdoc:
238
- class CArray
239
- # returns index table for index sort
240
- # This method same as,
241
- #
242
- # idx = CA.sort_addr(self, *args)
243
- def sort_addr (*args)
244
- end
245
- end
233
+ /* @overload sort_addr (*args)
234
+
235
+ (Sort) Returns index table for index sort
236
+ This method same as,
237
+
238
+ idx = CA.sort_addr(self, *args)
246
239
  */
247
240
 
248
241
  static VALUE
@@ -3,10 +3,8 @@
3
3
  carray_stat.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -286,12 +286,10 @@ header = <
286
286
  carray_stat_proc.c
287
287
 
288
288
  This file is part of Ruby/CArray extension library.
289
- You can redistribute it and/or modify it under the terms of
290
- the Ruby Licence.
291
289
 
292
- This file is automatically generated from carray_stat_proc.rb
293
290
 
294
- Copyright (C) 2005 Hiroki Motoyoshi
291
+ This file is automatically generated from carray_stat_proc.rb
292
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
295
293
 
296
294
  ---------------------------------------------------------------------------- */
297
295
 
@@ -3,10 +3,8 @@
3
3
  carray_test.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  This file includes the modified routine (ca_mem_hash) from
12
10
 
@@ -220,11 +218,10 @@ rb_obj_is_data_class (VALUE rtype)
220
218
 
221
219
  /* ------------------------------------------------------------- */
222
220
 
223
- /* rdoc:
224
- class CArray
225
- def valid_index? (*index)
226
- end
227
- end
221
+ /* @overload valid_index? (*idx)
222
+
223
+ (Inquiry)
224
+ Returns true if the given number list is valid as array index for the object
228
225
  */
229
226
 
230
227
  static VALUE
@@ -253,11 +250,10 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
253
250
  return Qtrue;
254
251
  }
255
252
 
256
- /* rdoc:
257
- class CArray
258
- def valid_addr? (addr)
259
- end
260
- end
253
+ /* @overload valid_addr? (*addr)
254
+
255
+ (Inquiry)
256
+ Returns true if the given number is valid as array address for the object
261
257
  */
262
258
 
263
259
  static VALUE
@@ -279,11 +275,10 @@ rb_ca_is_valid_addr (VALUE self, VALUE raddr)
279
275
  }
280
276
  }
281
277
 
282
- /* rdoc:
283
- class CArray
284
- def has_same_shape? (other)
285
- end
286
- end
278
+ /* @overload has_same_shape?
279
+
280
+ (Inquiry)
281
+ Returns true if the object has the same shape with the given array.
287
282
  */
288
283
 
289
284
  static VALUE
@@ -453,12 +448,10 @@ ca_equal (void *ap, void *bp)
453
448
  return flag;
454
449
  }
455
450
 
456
- /* rdoc:
457
- class CArray
458
- def == (other)
459
- end
460
- alias eql? ==
461
- end
451
+ /* @overload == (other)
452
+
453
+ (Inquiry)
454
+ Returns true if the object equals the given array.
462
455
  */
463
456
 
464
457
  static VALUE
@@ -545,11 +538,10 @@ ca_hash (CArray *ca)
545
538
  return hash;
546
539
  }
547
540
 
548
- /* rdoc:
549
- class CArray
550
- def hash
551
- end
552
- end
541
+ /* @overload hash
542
+
543
+ (Inquiry)
544
+ Returns the hash value of the object.
553
545
  */
554
546
 
555
547
  VALUE
@@ -578,6 +570,12 @@ rb_ca_modify (VALUE self)
578
570
  */
579
571
  }
580
572
 
573
+ /* @overload freeze
574
+
575
+ Freeze the object.
576
+
577
+ */
578
+
581
579
  VALUE
582
580
  rb_ca_freeze (VALUE self)
583
581
  {
@@ -598,6 +596,6 @@ Init_carray_test ()
598
596
  rb_define_method(rb_cCArray, "freeze", rb_ca_freeze, 0);
599
597
 
600
598
  rb_define_method(rb_cCArray, "==", rb_ca_equal, 1);
601
- rb_define_method(rb_cCArray, "eql?", rb_ca_equal, 1);
599
+ rb_define_alias(rb_cCArray, "eql?", "==");
602
600
  rb_define_method(rb_cCArray, "hash", rb_ca_hash, 0);
603
601
  }
@@ -3,10 +3,8 @@
3
3
  carray_undef.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -3,10 +3,8 @@
3
3
  carray_utils.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -422,6 +420,11 @@ ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k)
422
420
  }
423
421
  }
424
422
 
423
+ /* @private
424
+ @overload scan_float (str, fill_value=nil)
425
+
426
+ */
427
+
425
428
  static VALUE
426
429
  rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
427
430
  {
@@ -447,6 +450,11 @@ rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
447
450
  }
448
451
  }
449
452
 
453
+ /* @private
454
+ @overload scan_int (str, fill_value=nil)
455
+
456
+ */
457
+
450
458
  static VALUE
451
459
  rb_ca_s_scan_int (int argc, VALUE *argv, VALUE self)
452
460
  {
@@ -564,7 +572,7 @@ rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
564
572
  }
565
573
  }
566
574
 
567
- /* rdoc:
575
+ /* @private
568
576
  def CArray.guess_type_and_bytes (type, bytes=0)
569
577
  end
570
578
  */
@@ -219,7 +219,7 @@ carray_stat_proc.c: carray_stat_proc.rb
219
219
  carray_math.c: carray_math.rb
220
220
  ${RUBY} carray_math.rb
221
221
 
222
- rdoc:
222
+ yard:
223
223
  sh utils/create_rdoc.sh
224
224
 
225
225
  clean-generated:
@@ -305,7 +305,7 @@ static VALUE rb_ca_#{name}_bang (VALUE self, VALUE other)
305
305
  }
306
306
  end
307
307
  METHODS << %{
308
- rb_define_method(rb_cCArray, "#{op}!", rb_ca_#{name}_bang, 1);
308
+ rb_define_method(rb_cCArray, "#{name}!", rb_ca_#{name}_bang, 1);
309
309
  }
310
310
 
311
311
  end
@@ -3,10 +3,8 @@
3
3
  ruby_carray.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -97,7 +95,7 @@ Init_carray_ext ()
97
95
  rb_eCADataTypeError =
98
96
  rb_define_class_under(rb_cCArray, "DataTypeError", rb_eStandardError);
99
97
 
100
- /* rdoc:
98
+ /* yard:
101
99
  class CArray::DataTypeError # :nodoc:
102
100
  end
103
101
  */
@@ -111,7 +109,7 @@ Init_carray_ext ()
111
109
 
112
110
  /* -- version -- */
113
111
 
114
- /* rdoc:
112
+ /* yard:
115
113
  class CArray
116
114
  VERSION = nil # :nodoc:
117
115
  VERSION_CODE = nil # :nodoc:
@@ -122,11 +120,17 @@ Init_carray_ext ()
122
120
  end
123
121
  */
124
122
 
123
+ /* @private */
125
124
  rb_define_const(rb_cCArray, "VERSION", rb_str_new2(CA_VERSION));
125
+ /* @private */
126
126
  rb_define_const(rb_cCArray, "VERSION_CODE", INT2NUM(CA_VERSION_CODE));
127
+ /* @private */
127
128
  rb_define_const(rb_cCArray, "VERSION_MAJOR", INT2NUM(CA_VERSION_MAJOR));
129
+ /* @private */
128
130
  rb_define_const(rb_cCArray, "VERSION_MINOR", INT2NUM(CA_VERSION_MINOR));
131
+ /* @private */
129
132
  rb_define_const(rb_cCArray, "VERSION_TEENY", INT2NUM(CA_VERSION_TEENY));
133
+ /* @private */
130
134
  rb_define_const(rb_cCArray, "VERSION_DATE", rb_str_new2(CA_VERSION_DATE));
131
135
 
132
136
  /* -- system -- */
@@ -135,8 +139,10 @@ Init_carray_ext ()
135
139
  rb_define_const(rb_cObject, "CA_NIL", CA_NIL);
136
140
 
137
141
  #ifdef HAVE_COMPLEX_H
142
+ /* @private */
138
143
  rb_define_const(rb_cCArray, "HAVE_COMPLEX", Qtrue);
139
144
  #else
145
+ /* @private */
140
146
  rb_define_const(rb_cCArray, "HAVE_COMPLEX", Qfalse);
141
147
  #endif
142
148
 
@@ -169,7 +175,6 @@ Init_carray_ext ()
169
175
  rb_define_const(rb_cObject, "CA_DCOMPLEX", INT2NUM(CA_DCOMPLEX));
170
176
  rb_define_const(rb_cObject, "CA_SIZE", INT2NUM(CA_SIZE));
171
177
 
172
-
173
178
  rb_define_const(rb_cObject, "CA_ALIGN_VOIDP", INT2NUM(CA_ALIGN_VOIDP));
174
179
  rb_define_const(rb_cObject, "CA_ALIGN_FIXLEN", INT2NUM(CA_ALIGN_INT8));
175
180
  rb_define_const(rb_cObject, "CA_ALIGN_BOOLEAN", INT2NUM(CA_ALIGN_INT8));
@@ -3,10 +3,8 @@
3
3
  ruby_ccomplex.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -3,10 +3,8 @@
3
3
  ruby_numeric.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
@@ -3,16 +3,14 @@
3
3
  version.h
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
13
- #define CA_VERSION "1.5.1"
14
- #define CA_VERSION_CODE 151
11
+ #define CA_VERSION "1.5.2"
12
+ #define CA_VERSION_CODE 152
15
13
  #define CA_VERSION_MAJOR 1
16
14
  #define CA_VERSION_MINOR 5
17
- #define CA_VERSION_TEENY 1
18
- #define CA_VERSION_DATE "2020/07/01"
15
+ #define CA_VERSION_TEENY 2
16
+ #define CA_VERSION_DATE "2020/07/22"
@@ -32,6 +32,7 @@ require 'carray/transform'
32
32
  require 'carray/convert'
33
33
  require 'carray/testing'
34
34
  require 'carray/ordering'
35
+ require 'carray/broadcast'
35
36
 
36
37
  require 'carray/math'
37
38
  require 'carray/iterator'
@@ -46,6 +47,7 @@ require 'carray/obsolete'
46
47
  # autoload
47
48
 
48
49
  unless $CARRAY_NO_AUTOLOAD
50
+
49
51
  require 'carray/autoload'
50
52
  require 'carray/autoload/autoload_base'
51
53
  require 'carray/autoload/autoload_io_imagemagick'
@@ -1,15 +1,15 @@
1
1
  class CArray
2
- autoload_method :to_numo, "carray-numo-narray"
3
- autoload_method :numo, "carray-numo-narray"
4
- autoload_method "self.as_numo", "carray-numo-narray"
2
+ autoload_method :to_numo, "carray-numo-narray"
3
+ autoload_method :numo, "carray-numo-narray"
4
+ autoload_method "self.as_numo", "carray-numo-narray"
5
5
  autoload_method "self.as_numo!", "carray-numo-narray"
6
- autoload_method :as_numo, "carray-numo-narray"
7
- autoload_method :as_numo!, "carray-numo-narray"
6
+ autoload_method :as_numo, "carray-numo-narray"
7
+ autoload_method :as_numo!, "carray-numo-narray"
8
8
  end
9
9
 
10
10
  module Numo
11
11
  class NArray
12
12
  autoload_method :to_ca, "carray-numo-narray"
13
- autoload_method :ca, "carray-numo-narray"
13
+ autoload_method :ca, "carray-numo-narray"
14
14
  end
15
15
  end
@@ -0,0 +1,45 @@
1
+
2
+ class CArray
3
+ def broadcast_to (*new_dim)
4
+ if new_dim.size < ndim
5
+ raise "can't broadcast to #{new_dim.inspect} because of mismatch in rank"
6
+ end
7
+ flag_unbound_repeat = false
8
+ sdim = []
9
+ ([1]*(new_dim.size-ndim) + dim).each_with_index do |d, k|
10
+ if new_dim[k] == 1
11
+ sdim << 1
12
+ elsif d == 1
13
+ flag_unbound_repeat = true
14
+ sdim << :*
15
+ elsif d != new_dim[k]
16
+ raise "can't broadcast to #{new_dim.inspect} because of mismatch in #{d} for #{new_dim[k]} in #{k}th dim"
17
+ else
18
+ sdim << nil
19
+ end
20
+ end
21
+ return self[*sdim].bind(*new_dim) if flag_unbound_repeat
22
+ return self
23
+ end
24
+ end
25
+
26
+ class CScalar
27
+ def broadcast_to (*new_dim)
28
+ return self
29
+ end
30
+ end
31
+
32
+ class CAUnboundRepeat
33
+ alias broadcast_to bind
34
+ end
35
+
36
+ def CArray.broadcast (*argv)
37
+ sel = argv.select {|arg| arg.is_a?(CArray) }
38
+ return argv if sel.empty?
39
+ dim = []
40
+ ndim = sel.map(&:ndim).max
41
+ ndim.times do |k|
42
+ dim[k] = sel.map{|arg| arg.dim[k] || 1 }.max
43
+ end
44
+ return argv.map{|arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
45
+ end