carray 1.5.1 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/{LICENSES → LICENSE} +0 -0
  4. data/NEWS.md +83 -0
  5. data/README.md +34 -18
  6. data/Rakefile +1 -1
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +10 -7
  9. data/ext/ca_iter_block.c +3 -5
  10. data/ext/ca_iter_dimension.c +4 -5
  11. data/ext/ca_iter_window.c +2 -4
  12. data/ext/ca_obj_array.c +394 -124
  13. data/ext/ca_obj_bitarray.c +6 -11
  14. data/ext/ca_obj_bitfield.c +5 -9
  15. data/ext/ca_obj_block.c +5 -12
  16. data/ext/ca_obj_fake.c +3 -5
  17. data/ext/ca_obj_farray.c +3 -5
  18. data/ext/ca_obj_field.c +15 -17
  19. data/ext/ca_obj_grid.c +5 -6
  20. data/ext/ca_obj_mapping.c +2 -4
  21. data/ext/ca_obj_object.c +3 -5
  22. data/ext/ca_obj_reduce.c +2 -4
  23. data/ext/ca_obj_refer.c +11 -15
  24. data/ext/ca_obj_repeat.c +2 -4
  25. data/ext/ca_obj_select.c +2 -4
  26. data/ext/ca_obj_shift.c +3 -5
  27. data/ext/ca_obj_transpose.c +3 -5
  28. data/ext/ca_obj_unbound_repeat.c +68 -122
  29. data/ext/ca_obj_window.c +7 -9
  30. data/ext/carray.h +17 -8
  31. data/ext/carray_access.c +183 -58
  32. data/ext/carray_attribute.c +151 -197
  33. data/ext/carray_call_cfunc.c +1 -3
  34. data/ext/carray_cast.c +345 -144
  35. data/ext/carray_cast_func.rb +1 -2
  36. data/ext/carray_class.c +28 -36
  37. data/ext/carray_conversion.c +56 -59
  38. data/ext/carray_copy.c +16 -32
  39. data/ext/carray_core.c +73 -60
  40. data/ext/carray_element.c +25 -44
  41. data/ext/carray_generate.c +74 -53
  42. data/ext/carray_iterator.c +13 -15
  43. data/ext/carray_loop.c +53 -82
  44. data/ext/carray_mask.c +99 -119
  45. data/ext/carray_math.rb +28 -12
  46. data/ext/carray_mathfunc.c +1 -3
  47. data/ext/carray_numeric.c +42 -45
  48. data/ext/carray_operator.c +45 -32
  49. data/ext/carray_order.c +231 -65
  50. data/ext/carray_sort_addr.c +14 -21
  51. data/ext/carray_stat.c +1 -3
  52. data/ext/carray_stat_proc.rb +2 -4
  53. data/ext/carray_test.c +41 -30
  54. data/ext/carray_undef.c +1 -11
  55. data/ext/carray_utils.c +138 -51
  56. data/ext/extconf.rb +14 -2
  57. data/ext/mkmath.rb +2 -2
  58. data/ext/ruby_carray.c +15 -7
  59. data/ext/ruby_ccomplex.c +2 -4
  60. data/ext/ruby_float_func.c +1 -3
  61. data/ext/version.h +5 -7
  62. data/lib/carray.rb +9 -9
  63. data/lib/carray/autoload.rb +0 -2
  64. data/lib/carray/autoload/autoload_gem_numo_narray.rb +6 -6
  65. data/lib/carray/basic.rb +1 -3
  66. data/lib/carray/broadcast.rb +101 -0
  67. data/lib/carray/compose.rb +34 -10
  68. data/lib/carray/construct.rb +57 -18
  69. data/lib/carray/info.rb +1 -3
  70. data/lib/carray/inspect.rb +3 -5
  71. data/lib/carray/io/imagemagick.rb +1 -3
  72. data/lib/carray/iterator.rb +3 -3
  73. data/lib/carray/mask.rb +18 -7
  74. data/lib/carray/math.rb +4 -6
  75. data/lib/carray/math/histogram.rb +1 -3
  76. data/lib/carray/math/recurrence.rb +1 -3
  77. data/lib/carray/mkmf.rb +1 -3
  78. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  79. data/lib/carray/object/ca_obj_link.rb +1 -3
  80. data/lib/carray/object/ca_obj_pack.rb +1 -3
  81. data/lib/carray/obsolete.rb +1 -17
  82. data/lib/carray/ordering.rb +29 -5
  83. data/lib/carray/serialize.rb +34 -25
  84. data/lib/carray/string.rb +1 -3
  85. data/lib/carray/struct.rb +3 -5
  86. data/lib/carray/testing.rb +5 -10
  87. data/lib/carray/time.rb +1 -3
  88. data/lib/carray/transform.rb +12 -3
  89. data/misc/NOTE +16 -38
  90. data/spec/Classes/CABitfield_spec.rb +58 -0
  91. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  92. data/spec/Classes/CABlock_spec.rb +205 -0
  93. data/spec/Classes/CAField_spec.rb +39 -0
  94. data/spec/Classes/CAGrid_spec.rb +75 -0
  95. data/spec/Classes/CAMap_spec.rb +0 -0
  96. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  97. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  98. data/spec/Classes/CAObject_spec.rb +33 -0
  99. data/spec/Classes/CARefer_spec.rb +93 -0
  100. data/spec/Classes/CARepeat_spec.rb +65 -0
  101. data/spec/Classes/CASelect_spec.rb +22 -0
  102. data/spec/Classes/CAShift_spec.rb +16 -0
  103. data/spec/Classes/CAStruct_spec.rb +71 -0
  104. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  105. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  106. data/spec/Classes/CAWindow_spec.rb +54 -0
  107. data/spec/Classes/CAWrap_spec.rb +8 -0
  108. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  109. data/spec/Classes/CScalar_spec.rb +55 -0
  110. data/spec/Features/feature_130_spec.rb +19 -0
  111. data/spec/Features/feature_attributes_spec.rb +280 -0
  112. data/spec/Features/feature_boolean_spec.rb +98 -0
  113. data/spec/Features/feature_broadcast.rb +116 -0
  114. data/spec/Features/feature_cast_function.rb +19 -0
  115. data/spec/Features/feature_cast_spec.rb +33 -0
  116. data/spec/Features/feature_class_spec.rb +84 -0
  117. data/spec/Features/feature_complex_spec.rb +42 -0
  118. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  119. data/spec/Features/feature_convert_spec.rb +46 -0
  120. data/spec/Features/feature_copy_spec.rb +123 -0
  121. data/spec/Features/feature_creation_spec.rb +84 -0
  122. data/spec/Features/feature_element_spec.rb +144 -0
  123. data/spec/Features/feature_extream_spec.rb +54 -0
  124. data/spec/Features/feature_generate_spec.rb +74 -0
  125. data/spec/Features/feature_index_spec.rb +69 -0
  126. data/spec/Features/feature_mask_spec.rb +580 -0
  127. data/spec/Features/feature_math_spec.rb +97 -0
  128. data/spec/Features/feature_order_spec.rb +146 -0
  129. data/spec/Features/feature_ref_store_spec.rb +209 -0
  130. data/spec/Features/feature_serialization_spec.rb +125 -0
  131. data/spec/Features/feature_stat_spec.rb +397 -0
  132. data/spec/Features/feature_virtual_spec.rb +48 -0
  133. data/spec/Features/method_eq_spec.rb +81 -0
  134. data/spec/Features/method_is_nan_spec.rb +12 -0
  135. data/spec/Features/method_map_spec.rb +54 -0
  136. data/spec/Features/method_max_with.rb +20 -0
  137. data/spec/Features/method_min_with.rb +19 -0
  138. data/spec/Features/method_ne_spec.rb +18 -0
  139. data/spec/Features/method_project_spec.rb +188 -0
  140. data/spec/Features/method_ref_spec.rb +27 -0
  141. data/spec/Features/method_round_spec.rb +11 -0
  142. data/spec/Features/method_s_linspace_spec.rb +48 -0
  143. data/spec/Features/method_s_span_spec.rb +14 -0
  144. data/spec/Features/method_seq_spec.rb +47 -0
  145. data/spec/Features/method_sort_with.rb +43 -0
  146. data/spec/Features/method_sorted_with.rb +29 -0
  147. data/spec/Features/method_span_spec.rb +42 -0
  148. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  149. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  150. data/spec/spec_all.rb +0 -1
  151. data/utils/convert_test.rb +73 -0
  152. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  153. metadata +74 -58
  154. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  155. data/spec/CArray/bug/store_spec.rb +0 -27
  156. data/spec/CArray/index/repeat_spec.rb +0 -10
  157. data/spec/CArray/method/eq_spec.rb +0 -80
  158. data/spec/CArray/method/is_nan_spec.rb +0 -12
  159. data/spec/CArray/method/ne_spec.rb +0 -18
  160. data/spec/CArray/method/round_spec.rb +0 -11
  161. data/spec/CArray/object/_attribute_spec.rb +0 -32
  162. data/spec/CArray/object/s_new_spec.rb +0 -31
  163. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  164. data/test/test_130.rb +0 -23
  165. data/test/test_ALL.rb +0 -49
  166. data/test/test_CABitfield.rb +0 -59
  167. data/test/test_CABlock.rb +0 -208
  168. data/test/test_CAField.rb +0 -40
  169. data/test/test_CAGrid.rb +0 -76
  170. data/test/test_CAMmap.rb +0 -11
  171. data/test/test_CARefer.rb +0 -94
  172. data/test/test_CARepeat.rb +0 -66
  173. data/test/test_CASelect.rb +0 -23
  174. data/test/test_CAShift.rb +0 -17
  175. data/test/test_CAWindow.rb +0 -55
  176. data/test/test_CAWrap.rb +0 -9
  177. data/test/test_CComplex.rb +0 -83
  178. data/test/test_CScalar.rb +0 -91
  179. data/test/test_attribute.rb +0 -281
  180. data/test/test_block_iterator.rb +0 -17
  181. data/test/test_boolean.rb +0 -99
  182. data/test/test_cast.rb +0 -33
  183. data/test/test_class.rb +0 -85
  184. data/test/test_complex.rb +0 -43
  185. data/test/test_convert.rb +0 -79
  186. data/test/test_copy.rb +0 -141
  187. data/test/test_creation.rb +0 -85
  188. data/test/test_element.rb +0 -146
  189. data/test/test_extream.rb +0 -55
  190. data/test/test_generate.rb +0 -75
  191. data/test/test_index.rb +0 -71
  192. data/test/test_mask.rb +0 -578
  193. data/test/test_math.rb +0 -98
  194. data/test/test_order.rb +0 -147
  195. data/test/test_ref_store.rb +0 -211
  196. data/test/test_stat.rb +0 -406
  197. data/test/test_struct.rb +0 -72
  198. data/test/test_virtual.rb +0 -49
data/ext/extconf.rb CHANGED
@@ -135,11 +135,23 @@ end
135
135
  # --- check tgmath.h
136
136
 
137
137
  have_header("tgmath.h")
138
+ have_func("atan2", "math.h")
139
+ have_func("hypot", "math.h")
140
+ have_func("lgamma", "math.h")
141
+ have_func("expm1", "math.h")
138
142
 
139
143
  # --- check mergesort routine
140
144
 
141
145
  have_func("mergesort", "stdlib.h")
142
146
 
147
+ # --- check mergesort routine
148
+
149
+ have_func("strptime", "time.h")
150
+
151
+ # --- check raneg object
152
+
153
+ have_func("rb_arithmetic_sequence_extract")
154
+
143
155
  # --- setup install files
144
156
 
145
157
  $INSTALLFILES = []
@@ -153,7 +165,7 @@ $INSTALLFILES << ['carray_config.h', '$(archdir)']
153
165
  #
154
166
 
155
167
  if /cygwin|mingw/ =~ RUBY_PLATFORM
156
- sitearchdir = Config::CONFIG["sitearchdir"]
168
+ sitearchdir = RbConfig::CONFIG["sitearchdir"]
157
169
  $DLDFLAGS << " -L#{sitearchdir} -Wl,--out-implib=libcarray.a "
158
170
  unless File.exist? "libcarray.a"
159
171
  $TOUCHED_LIBCARRAY_A = true
@@ -219,7 +231,7 @@ carray_stat_proc.c: carray_stat_proc.rb
219
231
  carray_math.c: carray_math.rb
220
232
  ${RUBY} carray_math.rb
221
233
 
222
- rdoc:
234
+ yard:
223
235
  sh utils/create_rdoc.sh
224
236
 
225
237
  clean-generated:
data/ext/mkmath.rb CHANGED
@@ -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
@@ -385,7 +385,7 @@ ca_moncmp_#{name}_#{type} (ca_size_t n, boolean8_t *m, char *ptr1, ca_size_t i1,
385
385
  io.puts "};"
386
386
  io.puts
387
387
  io.print %{
388
- static VALUE rb_ca_#{name} (VALUE self, VALUE other)
388
+ static VALUE rb_ca_#{name} (VALUE self)
389
389
  { return rb_ca_call_moncmp(self, ca_moncmp_#{name}); }
390
390
  }
391
391
  DEFINITIONS << io.string
data/ext/ruby_carray.c CHANGED
@@ -3,16 +3,16 @@
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
 
13
11
  #include "carray.h"
14
12
  #include "version.h"
15
13
 
14
+ VALUE rb_cArithSeq;
15
+
16
16
  VALUE rb_eCADataTypeError;
17
17
  VALUE rb_mCA;
18
18
 
@@ -72,13 +72,14 @@ void Init_ca_iter_window ();
72
72
 
73
73
  void Init_carray_mathfunc ();
74
74
 
75
-
76
75
  void
77
76
  Init_carray_ext ()
78
77
  {
79
78
 
80
79
  /* Classes and Modules */
81
80
 
81
+ rb_cArithSeq = rb_const_get(rb_cEnumerator, rb_intern("ArithmeticSequence"));
82
+
82
83
  /* -- CArray class -- */
83
84
 
84
85
  rb_cCArray = rb_define_class("CArray", rb_cObject);
@@ -97,7 +98,7 @@ Init_carray_ext ()
97
98
  rb_eCADataTypeError =
98
99
  rb_define_class_under(rb_cCArray, "DataTypeError", rb_eStandardError);
99
100
 
100
- /* rdoc:
101
+ /* yard:
101
102
  class CArray::DataTypeError # :nodoc:
102
103
  end
103
104
  */
@@ -111,7 +112,7 @@ Init_carray_ext ()
111
112
 
112
113
  /* -- version -- */
113
114
 
114
- /* rdoc:
115
+ /* yard:
115
116
  class CArray
116
117
  VERSION = nil # :nodoc:
117
118
  VERSION_CODE = nil # :nodoc:
@@ -122,11 +123,17 @@ Init_carray_ext ()
122
123
  end
123
124
  */
124
125
 
126
+ /* @private */
125
127
  rb_define_const(rb_cCArray, "VERSION", rb_str_new2(CA_VERSION));
128
+ /* @private */
126
129
  rb_define_const(rb_cCArray, "VERSION_CODE", INT2NUM(CA_VERSION_CODE));
130
+ /* @private */
127
131
  rb_define_const(rb_cCArray, "VERSION_MAJOR", INT2NUM(CA_VERSION_MAJOR));
132
+ /* @private */
128
133
  rb_define_const(rb_cCArray, "VERSION_MINOR", INT2NUM(CA_VERSION_MINOR));
134
+ /* @private */
129
135
  rb_define_const(rb_cCArray, "VERSION_TEENY", INT2NUM(CA_VERSION_TEENY));
136
+ /* @private */
130
137
  rb_define_const(rb_cCArray, "VERSION_DATE", rb_str_new2(CA_VERSION_DATE));
131
138
 
132
139
  /* -- system -- */
@@ -135,8 +142,10 @@ Init_carray_ext ()
135
142
  rb_define_const(rb_cObject, "CA_NIL", CA_NIL);
136
143
 
137
144
  #ifdef HAVE_COMPLEX_H
145
+ /* @private */
138
146
  rb_define_const(rb_cCArray, "HAVE_COMPLEX", Qtrue);
139
147
  #else
148
+ /* @private */
140
149
  rb_define_const(rb_cCArray, "HAVE_COMPLEX", Qfalse);
141
150
  #endif
142
151
 
@@ -169,7 +178,6 @@ Init_carray_ext ()
169
178
  rb_define_const(rb_cObject, "CA_DCOMPLEX", INT2NUM(CA_DCOMPLEX));
170
179
  rb_define_const(rb_cObject, "CA_SIZE", INT2NUM(CA_SIZE));
171
180
 
172
-
173
181
  rb_define_const(rb_cObject, "CA_ALIGN_VOIDP", INT2NUM(CA_ALIGN_VOIDP));
174
182
  rb_define_const(rb_cObject, "CA_ALIGN_FIXLEN", INT2NUM(CA_ALIGN_INT8));
175
183
  rb_define_const(rb_cObject, "CA_ALIGN_BOOLEAN", INT2NUM(CA_ALIGN_INT8));
data/ext/ruby_ccomplex.c CHANGED
@@ -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
 
@@ -462,7 +460,7 @@ Init_ccomplex ()
462
460
  rb_define_method(rb_cCComplex, "coerce", rb_cc_coerce, 1);
463
461
 
464
462
  rb_define_method(rb_cCComplex, "==", rb_cc_equal, 1);
465
- rb_define_method(rb_cCComplex, "-@", rb_cc_uminus, 1);
463
+ rb_define_method(rb_cCComplex, "-@", rb_cc_uminus, 0);
466
464
  rb_define_method(rb_cCComplex, "+", rb_cc_plus, 1);
467
465
  rb_define_method(rb_cCComplex, "-", rb_cc_minus, 1);
468
466
  rb_define_method(rb_cCComplex, "*", rb_cc_asterisk, 1);
@@ -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
 
data/ext/version.h CHANGED
@@ -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.6"
12
+ #define CA_VERSION_CODE 156
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 6
16
+ #define CA_VERSION_DATE "2021/02/25"
data/lib/carray.rb CHANGED
@@ -3,10 +3,8 @@
3
3
  # lib/carray.rb
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
 
@@ -32,6 +30,7 @@ require 'carray/transform'
32
30
  require 'carray/convert'
33
31
  require 'carray/testing'
34
32
  require 'carray/ordering'
33
+ require 'carray/broadcast'
35
34
 
36
35
  require 'carray/math'
37
36
  require 'carray/iterator'
@@ -46,6 +45,7 @@ require 'carray/obsolete'
46
45
  # autoload
47
46
 
48
47
  unless $CARRAY_NO_AUTOLOAD
48
+
49
49
  require 'carray/autoload'
50
50
  require 'carray/autoload/autoload_base'
51
51
  require 'carray/autoload/autoload_io_imagemagick'
@@ -59,12 +59,12 @@ unless $CARRAY_NO_AUTOLOAD
59
59
  require 'carray/autoload/autoload_gem_gnuplot'
60
60
  require 'carray/autoload/autoload_gem_narray'
61
61
  require 'carray/autoload/autoload_gem_numo_narray'
62
- require 'carray/autoload/autoload_gem_io_csv'
63
- require 'carray/autoload/autoload_gem_io_sqlite3'
64
- require 'carray/autoload/autoload_gem_rmagick'
65
- require 'carray/autoload/autoload_gem_cairo'
66
- require 'carray/autoload/autoload_gem_opencv'
67
- require 'carray/autoload/autoload_gem_ffi'
62
+ # require 'carray/autoload/autoload_gem_io_csv'
63
+ # require 'carray/autoload/autoload_gem_io_sqlite3'
64
+ # require 'carray/autoload/autoload_gem_rmagick'
65
+ # require 'carray/autoload/autoload_gem_cairo'
66
+ # require 'carray/autoload/autoload_gem_opencv'
67
+ # require 'carray/autoload/autoload_gem_ffi'
68
68
 
69
69
  undef autoload_method
70
70
  end
@@ -3,8 +3,6 @@
3
3
  # carray/autoload.rb
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
7
  # Copyright (C) 2005-2010 Hiroki Motoyoshi
10
8
  #
@@ -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
data/lib/carray/basic.rb CHANGED
@@ -3,10 +3,8 @@
3
3
  # carray/basic.rb
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
 
@@ -0,0 +1,101 @@
1
+ # ----------------------------------------------------------------------------
2
+ #
3
+ # carray/broadcast.rb
4
+ #
5
+ # This file is part of Ruby/CArray extension library.
6
+ #
7
+ # Copyright (C) 2005-2020 Hiroki Motoyoshi
8
+ #
9
+ # ----------------------------------------------------------------------------
10
+
11
+ class CArray
12
+
13
+ def broadcast_to (*newdim)
14
+
15
+ if newdim.size < ndim
16
+ raise "(Broadcasting) can't broadcast to #{newdim.inspect} because too small rank is specified"
17
+ end
18
+
19
+ #
20
+ # Try to build unbound repeat index (includes :*)
21
+ # with broadcasting rule in Numpy.
22
+ #
23
+ repdim = []
24
+ shape = []
25
+
26
+ srcdim = dim.dup
27
+ dstdim = newdim.dup
28
+ sd = srcdim.pop
29
+ dd = dstdim.pop
30
+ while dd
31
+ if sd == dd
32
+ repdim.unshift nil
33
+ shape.unshift(dd)
34
+ sd = srcdim.pop
35
+ elsif dd == 1
36
+ repdim.unshift :*
37
+ elsif sd == 1
38
+ repdim.unshift :*
39
+ sd = srcdim.pop
40
+ else
41
+ raise "(Broadcasting) can't broadcast to #{newdim.inspect} "
42
+ end
43
+ dd = dstdim.pop
44
+ end
45
+
46
+ #
47
+ # Call Unbound repeat's bind
48
+ #
49
+ return self.reshape(*shape)[*repdim].bind(*newdim) if repdim.include?(:*)
50
+
51
+ self
52
+ end
53
+
54
+ end
55
+
56
+ class CScalar
57
+
58
+ def broadcast_to (*newdim)
59
+ out = CArray.new(data_type, newdim, bytes: bytes)
60
+ out[] = self
61
+ out
62
+ end
63
+
64
+ end
65
+
66
+ class CAUnboundRepeat
67
+
68
+ alias broadcast_to bind
69
+
70
+ end
71
+
72
+ def CArray.broadcast (*argv, expand_scalar: false, &block)
73
+
74
+ sel = argv.select { |arg| arg.is_a?(CArray) }
75
+ return argv if sel.empty?
76
+
77
+ dim = []
78
+ ndim = sel.map(&:ndim).max
79
+ ndim.times do |k|
80
+ dim[k] = sel.map { |arg| arg.dim[k] || 1 }.max
81
+ end
82
+
83
+ if not expand_scalar
84
+ list = argv.map { |arg|
85
+ case arg
86
+ when CScalar
87
+ arg
88
+ when CArray
89
+ arg.broadcast_to(*dim)
90
+ else
91
+ arg
92
+ end
93
+ }
94
+ else
95
+ list = argv.map { |arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
96
+ end
97
+
98
+ return block.call(*list) if block
99
+ return list
100
+ end
101
+
@@ -3,10 +3,8 @@
3
3
  # carray/composition.rb
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
 
@@ -34,6 +32,7 @@ class CArray
34
32
  end
35
33
  end
36
34
  out = CArray.new(data_type, newdim, &block)
35
+ out.data_class = data_class if has_data_class?
37
36
  if out.has_mask?
38
37
  out.mask.paste(offset, self.false)
39
38
  end
@@ -63,6 +62,7 @@ class CArray
63
62
  grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
64
63
  end
65
64
  out = CArray.new(data_type, newdim)
65
+ out.data_class = data_class if has_data_class?
66
66
  if block_given?
67
67
  sel = out.true
68
68
  sel[*grids] = 0
@@ -114,7 +114,14 @@ class CArray
114
114
  return self[*grids].to_ca
115
115
  end
116
116
 
117
- def self.combine (data_type, tdim, list, at = 0)
117
+ def self.combine (data_type, tdim, list, at = 0, bytes: nil)
118
+ if CArray.data_class?(data_type)
119
+ data_class = data_type
120
+ data_type = :fixlen
121
+ bytes = data_class::DATA_SIZE
122
+ else
123
+ data_class = nil
124
+ end
118
125
  has_fill_value = false
119
126
  if block_given?
120
127
  fill_value = yield
@@ -168,6 +175,7 @@ class CArray
168
175
  else
169
176
  obj = CArray.new(data_type, newdim)
170
177
  end
178
+ out.data_class = data_class if data_class
171
179
  idx = newdim.map{0}
172
180
  block.each_with_index do |item, tidx|
173
181
  (at...at+tndim).each_with_index do |d,i|
@@ -178,11 +186,18 @@ class CArray
178
186
  obj
179
187
  end
180
188
 
181
- def self.bind (data_type, list, at = 0)
182
- return CArray.combine(data_type, [list.size], list, at)
189
+ def self.bind (data_type, list, at = 0, bytes: nil)
190
+ return CArray.combine(data_type, [list.size], list, at, bytes: bytes)
183
191
  end
184
192
 
185
- def self.composite (data_type, tdim, list, at = 0)
193
+ def self.composite (data_type, tdim, list, at = 0, bytes: nil)
194
+ if CArray.data_class?(data_type)
195
+ data_class = data_type
196
+ data_type = :fixlen
197
+ bytes = data_class::DATA_SIZE
198
+ else
199
+ data_class = nil
200
+ end
186
201
  if not tdim.is_a?(Array) or tdim.size == 0
187
202
  raise "invalid tiling dimension"
188
203
  end
@@ -213,7 +228,8 @@ class CArray
213
228
  end
214
229
  newdim = dim.clone
215
230
  newdim[at,0] = tdim
216
- obj = CArray.new(data_type, newdim)
231
+ obj = CArray.new(data_type, newdim, bytes: bytes)
232
+ out.data_class = data_class if data_class
217
233
  idx = Array.new(ndim+tndim) { nil }
218
234
  CArray.each_index(*tdim) do |*tidx|
219
235
  idx[at,tndim] = tidx
@@ -222,13 +238,21 @@ class CArray
222
238
  obj
223
239
  end
224
240
 
225
- def self.merge (data_type, list, at = -1)
226
- return CArray.composite(data_type, [list.size], list, at)
241
+ def self.merge (data_type, list, at = -1, bytes: nil)
242
+ return CArray.composite(data_type, [list.size], list, at, bytes: bytes)
227
243
  end
228
244
 
229
245
  def self.join (*argv)
230
246
  # get options
231
247
  case argv.first
248
+ when Class
249
+ if CArray.data_class?(argv.first)
250
+ data_class = argv.shift
251
+ data_type = "fixlen"
252
+ bytes = data_class::DATA_SIZE
253
+ else
254
+ raise "#{argv.first} can not to be a data_class for CArray"
255
+ end
232
256
  when Integer, Symbol, String
233
257
  type, = *CArray.guess_type_and_bytes(argv.shift, 0)
234
258
  else