carray 1.4.0 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/LICENSE +22 -0
  4. data/NEWS.md +83 -0
  5. data/README.md +38 -18
  6. data/Rakefile +2 -2
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +13 -18
  9. data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
  10. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
  11. data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
  12. data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
  13. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
  14. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
  15. data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
  16. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
  17. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
  18. data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
  19. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
  20. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
  21. data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
  22. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
  23. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +44 -48
  24. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
  25. data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
  26. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
  27. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
  28. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
  29. data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
  30. data/{carray.h → ext/carray.h} +86 -59
  31. data/{carray_access.c → ext/carray_access.c} +194 -101
  32. data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
  33. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
  34. data/{carray_cast.c → ext/carray_cast.c} +351 -150
  35. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
  36. data/{carray_class.c → ext/carray_class.c} +28 -36
  37. data/{carray_conversion.c → ext/carray_conversion.c} +63 -68
  38. data/{carray_copy.c → ext/carray_copy.c} +34 -50
  39. data/{carray_core.c → ext/carray_core.c} +75 -62
  40. data/ext/carray_data_type.c +66 -0
  41. data/{carray_element.c → ext/carray_element.c} +34 -53
  42. data/{carray_generate.c → ext/carray_generate.c} +71 -50
  43. data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
  44. data/{carray_loop.c → ext/carray_loop.c} +77 -106
  45. data/{carray_mask.c → ext/carray_mask.c} +105 -114
  46. data/{carray_math.rb → ext/carray_math.rb} +29 -13
  47. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
  48. data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
  49. data/{carray_operator.c → ext/carray_operator.c} +49 -36
  50. data/{carray_order.c → ext/carray_order.c} +232 -217
  51. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
  52. data/{carray_stat.c → ext/carray_stat.c} +6 -8
  53. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
  54. data/{carray_test.c → ext/carray_test.c} +63 -51
  55. data/{carray_undef.c → ext/carray_undef.c} +1 -11
  56. data/{carray_utils.c → ext/carray_utils.c} +12 -4
  57. data/{extconf.rb → ext/extconf.rb} +10 -7
  58. data/{mkmath.rb → ext/mkmath.rb} +2 -2
  59. data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
  60. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +2 -4
  61. data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
  62. data/ext/version.h +16 -0
  63. data/{version.rb → ext/version.rb} +0 -0
  64. data/lib/carray.rb +51 -40
  65. data/lib/carray/{base/autoload.rb → autoload.rb} +1 -3
  66. data/lib/carray/autoload/autoload_base.rb +1 -1
  67. data/lib/carray/autoload/autoload_gem_numo_narray.rb +7 -6
  68. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  69. data/lib/carray/basic.rb +191 -0
  70. data/lib/carray/broadcast.rb +101 -0
  71. data/lib/carray/compose.rb +315 -0
  72. data/lib/carray/construct.rb +484 -0
  73. data/lib/carray/convert.rb +115 -0
  74. data/lib/carray/info.rb +1 -3
  75. data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
  76. data/lib/carray/io/imagemagick.rb +2 -4
  77. data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
  78. data/lib/carray/mask.rb +102 -0
  79. data/lib/carray/{base/math.rb → math.rb} +20 -52
  80. data/lib/carray/math/histogram.rb +8 -10
  81. data/lib/carray/math/recurrence.rb +1 -3
  82. data/lib/carray/mkmf.rb +9 -3
  83. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  84. data/lib/carray/object/ca_obj_link.rb +1 -3
  85. data/lib/carray/object/ca_obj_pack.rb +9 -11
  86. data/lib/carray/obsolete.rb +256 -0
  87. data/lib/carray/ordering.rb +181 -0
  88. data/lib/carray/{base/serialize.rb → serialize.rb} +60 -76
  89. data/lib/carray/{base/string.rb → string.rb} +10 -64
  90. data/lib/carray/{base/struct.rb → struct.rb} +19 -21
  91. data/lib/carray/{io/table.rb → table.rb} +1 -10
  92. data/lib/carray/testing.rb +51 -0
  93. data/lib/carray/time.rb +76 -0
  94. data/lib/carray/transform.rb +109 -0
  95. data/misc/Methods.ja.md +182 -0
  96. data/{NOTE → misc/NOTE} +16 -38
  97. data/spec/Classes/CABitfield_spec.rb +58 -0
  98. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  99. data/spec/Classes/CABlock_spec.rb +205 -0
  100. data/spec/Classes/CAField_spec.rb +39 -0
  101. data/spec/Classes/CAGrid_spec.rb +75 -0
  102. data/spec/Classes/CAMap_spec.rb +0 -0
  103. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  104. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  105. data/spec/Classes/CAObject_spec.rb +33 -0
  106. data/spec/Classes/CARefer_spec.rb +93 -0
  107. data/spec/Classes/CARepeat_spec.rb +65 -0
  108. data/spec/Classes/CASelect_spec.rb +22 -0
  109. data/spec/Classes/CAShift_spec.rb +16 -0
  110. data/spec/Classes/CAStruct_spec.rb +71 -0
  111. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  112. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  113. data/spec/Classes/CAWindow_spec.rb +54 -0
  114. data/spec/Classes/CAWrap_spec.rb +8 -0
  115. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  116. data/spec/Classes/CScalar_spec.rb +55 -0
  117. data/spec/Features/feature_130_spec.rb +19 -0
  118. data/spec/Features/feature_attributes_spec.rb +280 -0
  119. data/spec/Features/feature_boolean_spec.rb +98 -0
  120. data/spec/Features/feature_broadcast.rb +116 -0
  121. data/spec/Features/feature_cast_function.rb +19 -0
  122. data/spec/Features/feature_cast_spec.rb +33 -0
  123. data/spec/Features/feature_class_spec.rb +84 -0
  124. data/spec/Features/feature_complex_spec.rb +42 -0
  125. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  126. data/spec/Features/feature_convert_spec.rb +46 -0
  127. data/spec/Features/feature_copy_spec.rb +123 -0
  128. data/spec/Features/feature_creation_spec.rb +84 -0
  129. data/spec/Features/feature_element_spec.rb +144 -0
  130. data/spec/Features/feature_extream_spec.rb +54 -0
  131. data/spec/Features/feature_generate_spec.rb +74 -0
  132. data/spec/Features/feature_index_spec.rb +69 -0
  133. data/spec/Features/feature_mask_spec.rb +580 -0
  134. data/spec/Features/feature_math_spec.rb +97 -0
  135. data/spec/Features/feature_order_spec.rb +146 -0
  136. data/spec/Features/feature_ref_store_spec.rb +209 -0
  137. data/spec/Features/feature_serialization_spec.rb +125 -0
  138. data/spec/Features/feature_stat_spec.rb +397 -0
  139. data/spec/Features/feature_virtual_spec.rb +48 -0
  140. data/spec/Features/method_eq_spec.rb +81 -0
  141. data/spec/Features/method_is_nan_spec.rb +12 -0
  142. data/spec/Features/method_map_spec.rb +54 -0
  143. data/spec/Features/method_max_with.rb +20 -0
  144. data/spec/Features/method_min_with.rb +19 -0
  145. data/spec/Features/method_ne_spec.rb +18 -0
  146. data/spec/Features/method_project_spec.rb +188 -0
  147. data/spec/Features/method_ref_spec.rb +27 -0
  148. data/spec/Features/method_round_spec.rb +11 -0
  149. data/spec/Features/method_s_linspace_spec.rb +48 -0
  150. data/spec/Features/method_s_span_spec.rb +14 -0
  151. data/spec/Features/method_seq_spec.rb +47 -0
  152. data/spec/Features/method_sort_with.rb +43 -0
  153. data/spec/Features/method_sorted_with.rb +29 -0
  154. data/spec/Features/method_span_spec.rb +42 -0
  155. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  156. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  157. data/spec/spec_all.rb +0 -1
  158. data/utils/convert_test.rb +73 -0
  159. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  160. data/{devel → utils}/guess_shape.rb +0 -0
  161. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  162. metadata +159 -206
  163. data/COPYING +0 -56
  164. data/GPL +0 -340
  165. data/LEGAL +0 -50
  166. data/TODO +0 -5
  167. data/carray_random.c +0 -531
  168. data/devel/im2col.rb +0 -17
  169. data/ext/calculus/carray_calculus.c +0 -931
  170. data/ext/calculus/carray_interp.c +0 -358
  171. data/ext/calculus/extconf.rb +0 -12
  172. data/ext/calculus/lib/math/calculus.rb +0 -119
  173. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  174. data/ext/mathfunc/extconf.rb +0 -18
  175. data/ext/mathfunc/test/test_hypot.rb +0 -5
  176. data/ext/mathfunc/test/test_j0.rb +0 -22
  177. data/ext/mathfunc/test/test_jn.rb +0 -8
  178. data/ext/mathfunc/test/test_sph.rb +0 -9
  179. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  180. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  181. data/lib/carray/base/basic.rb +0 -1146
  182. data/lib/carray/base/obsolete.rb +0 -131
  183. data/lib/carray/math/interp.rb +0 -57
  184. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  185. data/mt19937ar.c +0 -182
  186. data/mt19937ar.h +0 -86
  187. data/rdoc_main.rb +0 -27
  188. data/rdoc_math.rb +0 -5
  189. data/rdoc_stat.rb +0 -31
  190. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  191. data/spec/CArray/bug/store_spec.rb +0 -27
  192. data/spec/CArray/index/repeat_spec.rb +0 -10
  193. data/spec/CArray/method/eq_spec.rb +0 -80
  194. data/spec/CArray/method/is_nan_spec.rb +0 -12
  195. data/spec/CArray/method/ne_spec.rb +0 -18
  196. data/spec/CArray/method/round_spec.rb +0 -11
  197. data/spec/CArray/object/_attribute_spec.rb +0 -32
  198. data/spec/CArray/object/s_new_spec.rb +0 -31
  199. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  200. data/test/test_130.rb +0 -23
  201. data/test/test_ALL.rb +0 -51
  202. data/test/test_CABitfield.rb +0 -59
  203. data/test/test_CABlock.rb +0 -208
  204. data/test/test_CAField.rb +0 -40
  205. data/test/test_CAGrid.rb +0 -76
  206. data/test/test_CAMmap.rb +0 -11
  207. data/test/test_CARefer.rb +0 -94
  208. data/test/test_CARepeat.rb +0 -66
  209. data/test/test_CASelect.rb +0 -23
  210. data/test/test_CAShift.rb +0 -17
  211. data/test/test_CAWindow.rb +0 -55
  212. data/test/test_CAWrap.rb +0 -9
  213. data/test/test_CComplex.rb +0 -83
  214. data/test/test_CScalar.rb +0 -91
  215. data/test/test_attribute.rb +0 -281
  216. data/test/test_block_iterator.rb +0 -17
  217. data/test/test_boolean.rb +0 -99
  218. data/test/test_cast.rb +0 -33
  219. data/test/test_class.rb +0 -85
  220. data/test/test_complex.rb +0 -43
  221. data/test/test_convert.rb +0 -79
  222. data/test/test_copy.rb +0 -141
  223. data/test/test_creation.rb +0 -85
  224. data/test/test_element.rb +0 -146
  225. data/test/test_extream.rb +0 -55
  226. data/test/test_generate.rb +0 -75
  227. data/test/test_index.rb +0 -71
  228. data/test/test_mask.rb +0 -578
  229. data/test/test_math.rb +0 -98
  230. data/test/test_narray.rb +0 -64
  231. data/test/test_order.rb +0 -147
  232. data/test/test_random.rb +0 -15
  233. data/test/test_ref_store.rb +0 -211
  234. data/test/test_stat.rb +0 -414
  235. data/test/test_struct.rb +0 -72
  236. data/test/test_virtual.rb +0 -49
  237. data/utils/create_rdoc.sh +0 -9
  238. data/utils/make_tgz.sh +0 -3
  239. data/version.h +0 -18
@@ -3,10 +3,8 @@
3
3
  ca_obj_window.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
 
@@ -17,7 +15,7 @@
17
15
  VALUE rb_cCAWindow;
18
16
  int8_t CA_OBJ_WINDOW;
19
17
 
20
- /* rdoc:
18
+ /* yard:
21
19
  class CAWindow < CAVirtual # :nodoc:
22
20
  end
23
21
  */
@@ -29,18 +27,18 @@ int
29
27
  ca_window_setup (CAWindow *ca, CArray *parent,
30
28
  ca_size_t *start, ca_size_t *count, int8_t bounds, char *fill)
31
29
  {
32
- int8_t data_type, rank;
30
+ int8_t data_type, ndim;
33
31
  ca_size_t *dim;
34
32
  ca_size_t bytes, elements;
35
33
  int i;
36
34
 
37
35
  data_type = parent->data_type;
38
- rank = parent->rank;
36
+ ndim = parent->ndim;
39
37
  bytes = parent->bytes;
40
38
  dim = parent->dim;
41
39
 
42
40
  elements = 1;
43
- for (i=0; i<rank; i++) {
41
+ for (i=0; i<ndim; i++) {
44
42
  if ( count[i] <= 0 ) {
45
43
  rb_raise(rb_eIndexError,
46
44
  "invalid size for %i-th dimension (negative or zero)", i);
@@ -51,7 +49,7 @@ ca_window_setup (CAWindow *ca, CArray *parent,
51
49
  ca->obj_type = CA_OBJ_WINDOW;
52
50
  ca->data_type = data_type;
53
51
  ca->flags = 0;
54
- ca->rank = rank;
52
+ ca->ndim = ndim;
55
53
  ca->bytes = bytes;
56
54
  ca->elements = elements;
57
55
  ca->ptr = NULL;
@@ -62,16 +60,16 @@ ca_window_setup (CAWindow *ca, CArray *parent,
62
60
  ca->attach = 0;
63
61
  ca->nosync = 0;
64
62
  ca->bounds = bounds;
65
- ca->start = ALLOC_N(ca_size_t, rank);
66
- ca->count = ALLOC_N(ca_size_t, rank);
67
- ca->size0 = ALLOC_N(ca_size_t, rank);
63
+ ca->start = ALLOC_N(ca_size_t, ndim);
64
+ ca->count = ALLOC_N(ca_size_t, ndim);
65
+ ca->size0 = ALLOC_N(ca_size_t, ndim);
68
66
  ca->fill = ALLOC_N(char, ca->bytes);
69
67
 
70
68
  ca->dim = ca->count;
71
69
 
72
- memcpy(ca->start, start, rank * sizeof(ca_size_t));
73
- memcpy(ca->count, count, rank * sizeof(ca_size_t));
74
- memcpy(ca->size0, dim, rank * sizeof(ca_size_t));
70
+ memcpy(ca->start, start, ndim * sizeof(ca_size_t));
71
+ memcpy(ca->count, count, ndim * sizeof(ca_size_t));
72
+ memcpy(ca->size0, dim, ndim * sizeof(ca_size_t));
75
73
 
76
74
  if ( fill ) {
77
75
  memcpy(ca->fill, fill, ca->bytes);
@@ -157,7 +155,7 @@ ca_window_func_ptr_at_index (void *ap, ca_size_t *idx)
157
155
  int8_t i;
158
156
  ca_size_t n;
159
157
  n = 0;
160
- for (i=0; i<ca->rank; i++) {
158
+ for (i=0; i<ca->ndim; i++) {
161
159
  k = start[i] + idx[i];
162
160
  k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
163
161
  if ( k < 0 || k >= size0[i] ) {
@@ -187,7 +185,7 @@ ca_window_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
187
185
  ca_size_t idx0[CA_RANK_MAX];
188
186
  int8_t i;
189
187
  ca_size_t k;
190
- for (i=0; i<ca->rank; i++) {
188
+ for (i=0; i<ca->ndim; i++) {
191
189
  k = start[i] + idx[i];
192
190
  k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
193
191
  if ( k < 0 || k >= size0[i] ) {
@@ -208,7 +206,7 @@ ca_window_func_store_index (void *ap, ca_size_t *idx, void *ptr)
208
206
  ca_size_t idx0[CA_RANK_MAX];
209
207
  int8_t i;
210
208
  ca_size_t k;
211
- for (i=0; i<ca->rank; i++) {
209
+ for (i=0; i<ca->ndim; i++) {
212
210
  k = start[i] + idx[i];
213
211
  k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
214
212
  if ( k < 0 || k >= size0[i] ) {
@@ -397,7 +395,7 @@ ca_window_attach_loop (CAWindow *cb, int8_t level,
397
395
  ca_size_t count = cb->count[level];
398
396
  ca_size_t i, k;
399
397
 
400
- if ( level == cb->rank - 1 ) {
398
+ if ( level == cb->ndim - 1 ) {
401
399
  switch ( cb->data_type ) {
402
400
  case CA_BOOLEAN:
403
401
  case CA_INT8: proc_window_attach_get(int8_t); break;
@@ -525,7 +523,7 @@ ca_window_sync_loop (CAWindow *cb, int8_t level,
525
523
  ca_size_t size0 = cb->size0[level];
526
524
  ca_size_t i, k;
527
525
 
528
- if ( level == cb->rank - 1 ) {
526
+ if ( level == cb->ndim - 1 ) {
529
527
  switch ( cb->data_type ) {
530
528
  case CA_BOOLEAN:
531
529
  case CA_INT8: proc_window_sync_set(int8_t); break;
@@ -629,7 +627,7 @@ ca_window_fill_loop (CAWindow *cb, char *ptr,
629
627
  ca_size_t size0 = cb->size0[level];
630
628
  ca_size_t i, k;
631
629
 
632
- if ( level == cb->rank - 1 ) {
630
+ if ( level == cb->ndim - 1 ) {
633
631
  switch ( cb->data_type ) {
634
632
  case CA_BOOLEAN:
635
633
  case CA_INT8: proc_window_fill_set(int8_t); break;
@@ -703,7 +701,7 @@ rb_ca_window_new (VALUE cary,
703
701
  return obj;
704
702
  }
705
703
 
706
- /* rdoc:
704
+ /* yard:
707
705
  class CArray
708
706
  def window (*argv)
709
707
  end
@@ -728,8 +726,8 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
728
726
  ropt = rb_pop_options(&argc, &argv);
729
727
  rb_scan_options(ropt, "bounds,fill_value", &rbounds, &rfval);
730
728
 
731
- if ( argc != ca->rank ) {
732
- rb_raise(rb_eArgError, "rank mismatch");
729
+ if ( argc != ca->ndim ) {
730
+ rb_raise(rb_eArgError, "ndim mismatch");
733
731
  }
734
732
 
735
733
  for (i=0; i<argc; i++) {
@@ -837,7 +835,7 @@ rb_ca_window_initialize_copy (VALUE self, VALUE other)
837
835
  return self;
838
836
  }
839
837
 
840
- /* rdoc:
838
+ /* yard:
841
839
  class CAWindow
842
840
  def index2addr0 (idx)
843
841
  end
@@ -854,13 +852,13 @@ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
854
852
 
855
853
  Data_Get_Struct(self, CAWindow, cw);
856
854
 
857
- if ( argc != cw->rank ) {
855
+ if ( argc != cw->ndim ) {
858
856
  rb_raise(rb_eArgError,
859
- "invalid # of arguments (should be <%i>)", cw->rank);
857
+ "invalid # of arguments (should be <%i>)", cw->ndim);
860
858
  }
861
859
 
862
860
  addr = 0;
863
- for (i=0; i<cw->rank; i++) {
861
+ for (i=0; i<cw->ndim; i++) {
864
862
  idxi = NUM2SIZE(argv[i]);
865
863
  CA_CHECK_INDEX(idxi, cw->dim[i]);
866
864
  addr = cw->size0[i] * addr + cw->start[i] + idxi;
@@ -874,7 +872,7 @@ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
874
872
  }
875
873
  }
876
874
 
877
- /* rdoc:
875
+ /* yard:
878
876
  class CAWindow
879
877
  def addr2addr0 (addr)
880
878
  end
@@ -894,7 +892,7 @@ rb_ca_window_addr2addr0 (VALUE self, VALUE raddr)
894
892
  ca_addr2index((CArray*)cw, addr, idx);
895
893
 
896
894
  addr = 0;
897
- for (i=0; i<cw->rank; i++) {
895
+ for (i=0; i<cw->ndim; i++) {
898
896
  addr *= cw->size0[i];
899
897
  addr += cw->start[i] + idx[i];
900
898
  }
@@ -912,12 +910,12 @@ rb_ca_window_move (int argc, VALUE *argv, VALUE self)
912
910
 
913
911
  Data_Get_Struct(self, CAWindow, cw);
914
912
 
915
- if ( argc != cw->rank ) {
913
+ if ( argc != cw->ndim ) {
916
914
  rb_raise(rb_eArgError, "invalid # of arguments");
917
915
  }
918
916
 
919
917
  ca_update_mask(cw);
920
- for (i=0; i<cw->rank; i++) {
918
+ for (i=0; i<cw->ndim; i++) {
921
919
  start = NUM2SIZE(argv[i]);
922
920
  cw->start[i] = start;
923
921
  if ( cw->mask ) {
@@ -928,7 +926,7 @@ rb_ca_window_move (int argc, VALUE *argv, VALUE self)
928
926
  return self;
929
927
  }
930
928
 
931
- /* rdoc:
929
+ /* yard:
932
930
  class CAWindow
933
931
  def fill_value
934
932
  end
@@ -969,14 +967,14 @@ rb_ca_window_get_bounds (VALUE self)
969
967
  CAWindow *cw; \
970
968
  int8_t i; \
971
969
  Data_Get_Struct(self, CAWindow, cw); \
972
- ary = rb_ary_new2(cw->rank); \
973
- for (i=0; i<cw->rank; i++) { \
970
+ ary = rb_ary_new2(cw->ndim); \
971
+ for (i=0; i<cw->ndim; i++) { \
974
972
  rb_ary_store(ary, i, SIZE2NUM(cw->name[i])); \
975
973
  } \
976
974
  return ary; \
977
975
  }
978
976
 
979
- /* rdoc:
977
+ /* yard:
980
978
  class CAWindow
981
979
  def size0
982
980
  end
@@ -3,10 +3,8 @@
3
3
  carray.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
 
@@ -198,7 +196,8 @@ typedef int8_t boolean8_t;
198
196
  /* -------------------------------------------------------------------- */
199
197
 
200
198
  #define CA_OBJ_TYPE_MAX 256
201
- #define CA_RANK_MAX 16
199
+ #define CA_DIM_MAX 16
200
+ #define CA_RANK_MAX CA_DIM_MAX
202
201
  #define CA_ATTACH_MAX 0x80000000
203
202
 
204
203
  #define CA_FLAG_SCALAR 1
@@ -337,21 +336,21 @@ typedef struct _CArray CArray;
337
336
  struct _CArray {
338
337
  int16_t obj_type;
339
338
  int8_t data_type;
340
- int8_t rank;
339
+ int8_t ndim;
341
340
  int32_t flags;
342
341
  ca_size_t bytes;
343
342
  ca_size_t elements;
344
343
  ca_size_t *dim;
345
344
  char *ptr;
346
345
  CArray *mask;
347
- }; /* 28 + 4*rank (bytes) */
346
+ }; /* 28 + 4*ndim (bytes) */
348
347
 
349
348
  typedef CArray CAWrap;
350
349
 
351
350
  typedef struct {
352
351
  int16_t obj_type;
353
352
  int8_t data_type;
354
- int8_t rank;
353
+ int8_t ndim;
355
354
  int32_t flags;
356
355
  ca_size_t bytes;
357
356
  ca_size_t elements;
@@ -364,7 +363,7 @@ typedef struct {
364
363
  typedef struct {
365
364
  int16_t obj_type;
366
365
  int8_t data_type;
367
- int8_t rank;
366
+ int8_t ndim;
368
367
  int32_t flags;
369
368
  ca_size_t bytes;
370
369
  ca_size_t elements;
@@ -374,12 +373,12 @@ typedef struct {
374
373
  CArray *parent;
375
374
  uint32_t attach;
376
375
  uint8_t nosync;
377
- } CAVirtual; /* 40 + 4*(rank) (bytes) */
376
+ } CAVirtual; /* 40 + 4*(ndim) (bytes) */
378
377
 
379
378
  typedef struct {
380
379
  int16_t obj_type;
381
380
  int8_t data_type;
382
- int8_t rank;
381
+ int8_t ndim;
383
382
  int32_t flags;
384
383
  ca_size_t bytes;
385
384
  ca_size_t elements;
@@ -397,12 +396,12 @@ typedef struct {
397
396
  ca_size_t ratio;
398
397
  ca_size_t offset;
399
398
  CArray *mask0;
400
- } CARefer; /* 52 + 4*(rank) (bytes) */
399
+ } CARefer; /* 52 + 4*(ndim) (bytes) */
401
400
 
402
401
  typedef struct {
403
402
  int16_t obj_type;
404
403
  int8_t data_type;
405
- int8_t rank;
404
+ int8_t ndim;
406
405
  int32_t flags;
407
406
  ca_size_t bytes;
408
407
  ca_size_t elements;
@@ -421,12 +420,12 @@ typedef struct {
421
420
  ca_size_t *step;
422
421
  ca_size_t *count;
423
422
  ca_size_t *size0;
424
- } CABlock; /* 68 + 20*(rank) (bytes) */
423
+ } CABlock; /* 68 + 20*(ndim) (bytes) */
425
424
 
426
425
  typedef struct {
427
426
  int16_t obj_type;
428
427
  int8_t data_type;
429
- int8_t rank;
428
+ int8_t ndim;
430
429
  int32_t flags;
431
430
  ca_size_t bytes;
432
431
  ca_size_t elements;
@@ -442,12 +441,12 @@ typedef struct {
442
441
  ca_size_t *count;
443
442
  ca_size_t *size0;
444
443
  char *fill;
445
- } CAWindow; /* 56 + 16*(rank) + 1*(bytes) (bytes) */
444
+ } CAWindow; /* 56 + 16*(ndim) + 1*(bytes) (bytes) */
446
445
 
447
446
  typedef struct {
448
447
  int16_t obj_type;
449
448
  int8_t data_type;
450
- int8_t rank;
449
+ int8_t ndim;
451
450
  int32_t flags;
452
451
  ca_size_t bytes;
453
452
  ca_size_t elements;
@@ -460,7 +459,7 @@ typedef struct {
460
459
  /* -------------*/
461
460
  CArray *data;
462
461
  VALUE self;
463
- } CAObject; /* 48 + 4*(rank) (bytes) */
462
+ } CAObject; /* 48 + 4*(ndim) (bytes) */
464
463
 
465
464
  /*
466
465
  CAObjectMask is an internal class
@@ -470,7 +469,7 @@ typedef struct {
470
469
  typedef struct {
471
470
  int16_t obj_type;
472
471
  int8_t data_type;
473
- int8_t rank;
472
+ int8_t ndim;
474
473
  int32_t flags;
475
474
  ca_size_t bytes;
476
475
  ca_size_t elements;
@@ -484,7 +483,7 @@ typedef struct {
484
483
  typedef struct {
485
484
  int16_t obj_type;
486
485
  int8_t data_type;
487
- int8_t rank;
486
+ int8_t ndim;
488
487
  int32_t flags;
489
488
  ca_size_t bytes;
490
489
  ca_size_t elements;
@@ -500,12 +499,12 @@ typedef struct {
500
499
  ca_size_t repeat_num;
501
500
  ca_size_t contig_level;
502
501
  ca_size_t contig_num;
503
- } CARepeat; /* 60 + 8*(rank) (bytes) */
502
+ } CARepeat; /* 60 + 8*(ndim) (bytes) */
504
503
 
505
504
  typedef struct {
506
505
  int16_t obj_type;
507
506
  int8_t data_type;
508
- int8_t rank;
507
+ int8_t ndim;
509
508
  int32_t flags;
510
509
  ca_size_t bytes;
511
510
  ca_size_t elements;
@@ -516,9 +515,9 @@ typedef struct {
516
515
  uint32_t attach;
517
516
  uint8_t nosync;
518
517
  /* -------------*/
519
- int8_t rep_rank;
518
+ int8_t rep_ndim;
520
519
  ca_size_t *rep_dim;
521
- } CAUnboundRepeat; /* 44 + 8*(rank) (bytes) */
520
+ } CAUnboundRepeat; /* 44 + 8*(ndim) (bytes) */
522
521
 
523
522
  /*
524
523
  CAReduce is an internal class
@@ -528,7 +527,7 @@ typedef struct {
528
527
  typedef struct {
529
528
  int16_t obj_type;
530
529
  int8_t data_type;
531
- int8_t rank;
530
+ int8_t ndim;
532
531
  int32_t flags;
533
532
  ca_size_t bytes;
534
533
  ca_size_t elements;
@@ -546,7 +545,7 @@ typedef struct {
546
545
  /* -------------------------------------------------------------------- */
547
546
 
548
547
  typedef struct {
549
- int8_t rank;
548
+ int8_t ndim;
550
549
  ca_size_t dim[CA_RANK_MAX];
551
550
  CArray *reference;
552
551
  CArray * (*kernel_at_addr)(void *, ca_size_t, CArray *);
@@ -573,6 +572,23 @@ extern VALUE rb_mCA;
573
572
  extern VALUE rb_mCAMath;
574
573
  extern VALUE rb_eCADataTypeError;
575
574
 
575
+ extern VALUE rb_cCArrayBoolean;
576
+ extern VALUE rb_cCArrayUInt8;
577
+ extern VALUE rb_cCArrayUInt16;
578
+ extern VALUE rb_cCArrayUInt32;
579
+ extern VALUE rb_cCArrayUInt64;
580
+ extern VALUE rb_cCArrayInt8;
581
+ extern VALUE rb_cCArrayInt16;
582
+ extern VALUE rb_cCArrayInt32;
583
+ extern VALUE rb_cCArrayInt64;
584
+ extern VALUE rb_cCArrayFloat32;
585
+ extern VALUE rb_cCArrayFloat64;
586
+ extern VALUE rb_cCArrayFloat128;
587
+ extern VALUE rb_cCArrayCmplx64;
588
+ extern VALUE rb_cCArrayCmplx128;
589
+ extern VALUE rb_cCArrayCmplx256;
590
+ extern VALUE rb_cCArrayObject;
591
+
576
592
  /* -------------------------------------------------------------------- */
577
593
 
578
594
  extern const int ca_endian;
@@ -607,15 +623,15 @@ extern int ca_obj_num;
607
623
  rb_raise(rb_eRuntimeError, "invalid numeric data type"); \
608
624
  }
609
625
 
610
- #define CA_CHECK_RANK(rank) \
611
- if ( rank <= 0 || rank > CA_RANK_MAX ) { \
612
- rb_raise(rb_eRuntimeError, "invalid rank"); \
626
+ #define CA_CHECK_RANK(ndim) \
627
+ if ( ndim <= 0 || ndim > CA_RANK_MAX ) { \
628
+ rb_raise(rb_eRuntimeError, "invalid ndim"); \
613
629
  }
614
630
 
615
- #define CA_CHECK_DIM(rank, dim) \
631
+ #define CA_CHECK_DIM(ndim, dim) \
616
632
  { \
617
633
  int8_t i_; \
618
- for (i_=0; i_<rank; i_++) { \
634
+ for (i_=0; i_<ndim; i_++) { \
619
635
  if ( dim[i_] < 0 ) { \
620
636
  rb_raise(rb_eRuntimeError, "negative size dimension at %i-dim", i_); \
621
637
  } \
@@ -646,7 +662,7 @@ extern int ca_obj_num;
646
662
  #define CA_CHECK_BOUND(ca, idx) \
647
663
  { \
648
664
  int8_t i; \
649
- for (i=0; i<ca->rank; i++) { \
665
+ for (i=0; i<ca->ndim; i++) { \
650
666
  if ( idx[i] < 0 || idx[i] >= ca->dim[i] ) { \
651
667
  rb_raise(rb_eRuntimeError, "index out of range at %i-dim ( %i <=> 0..%i )", i, idx[i], ca->dim[i]-1); \
652
668
  } \
@@ -736,12 +752,13 @@ typedef union {
736
752
 
737
753
  typedef struct {
738
754
  int16_t type;
739
- int16_t rank;
755
+ int16_t ndim;
740
756
  int32_t index_type[CA_RANK_MAX];
741
757
  CAIndex index[CA_RANK_MAX];
742
758
  CArray *select;
743
759
  VALUE block;
744
760
  VALUE symbol;
761
+ int8_t range_check;
745
762
  } CAIndexInfo;
746
763
 
747
764
  /* -------------------------------------------------------------------- */
@@ -767,10 +784,10 @@ VALUE rb_ca_call_binop (VALUE self, VALUE other, ca_binop_func_t func[]);
767
784
  VALUE rb_ca_call_binop_bang (VALUE self, VALUE other, ca_binop_func_t func[]);
768
785
  VALUE rb_ca_call_moncmp (VALUE self, ca_moncmp_func_t func[]);
769
786
  VALUE rb_ca_call_bincmp (VALUE self, VALUE other, ca_bincmp_func_t func[]);
770
- void ca_monop_not_implement(ca_size_t n, char *ptr1, char *ptr2);
771
- void ca_binop_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3);
772
- void ca_moncmp_not_implement(ca_size_t n, char *ptr1, char *ptr2);
773
- void ca_bincmp_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3);
787
+ void ca_monop_not_implement(ca_size_t n, char *ptr1, char *ptr2) __attribute__((noreturn));
788
+ void ca_binop_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3) __attribute__((noreturn));
789
+ void ca_moncmp_not_implement(ca_size_t n, char *ptr1, char *ptr2) __attribute__((noreturn));
790
+ void ca_bincmp_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3) __attribute__((noreturn));
774
791
  VALUE ca_math_call (VALUE mod, VALUE arg, ID id);
775
792
 
776
793
  /* -------------------------------------------------------------------- */
@@ -778,35 +795,38 @@ VALUE ca_math_call (VALUE mod, VALUE arg, ID id);
778
795
  /* --- ca_obj_array.c --- */
779
796
 
780
797
  int carray_setup (CArray *ca,
781
- int8_t data_type, int8_t rank, ca_size_t *dim,
798
+ int8_t data_type, int8_t ndim, ca_size_t *dim,
782
799
  ca_size_t bytes, CArray *mask);
783
800
 
784
801
  int carray_safe_setup (CArray *ca,
785
- int8_t data_type, int8_t rank, ca_size_t *dim,
802
+ int8_t data_type, int8_t ndim, ca_size_t *dim,
786
803
  ca_size_t bytes, CArray *mask);
787
804
 
788
805
  int ca_wrap_setup_null (CArray *ca,
789
- int8_t data_type, int8_t rank, ca_size_t *dim,
806
+ int8_t data_type, int8_t ndim, ca_size_t *dim,
790
807
  ca_size_t bytes, CArray *mask);
791
808
 
792
809
  void free_carray (void *ap);
793
810
  void free_ca_wrap (void *ap);
794
811
 
795
812
  CArray *carray_new (int8_t data_type,
796
- int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *ma);
813
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *ma);
797
814
  CArray *carray_new_safe (int8_t data_type,
798
- int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *mask);
815
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask);
799
816
  VALUE rb_carray_new (int8_t data_type,
800
- int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *mask);
817
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask);
801
818
  VALUE rb_carray_new_safe (int8_t data_type,
802
- int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *mask);
819
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask);
820
+
821
+ VALUE rb_ca_wrap_new (int8_t data_type,
822
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask, char *ptr);
803
823
 
804
824
  CAWrap *ca_wrap_new (int8_t data_type,
805
- int8_t rank, ca_size_t *dim, ca_size_t bytes,
825
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes,
806
826
  CArray *mask, char *ptr);
807
827
 
808
828
  CAWrap *ca_wrap_new_null (int8_t data_type,
809
- int8_t rank, ca_size_t *dim, ca_size_t bytes,
829
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes,
810
830
  CArray *mask);
811
831
 
812
832
  CScalar *cscalar_new (int8_t data_type, ca_size_t bytes, CArray *ma);
@@ -817,10 +837,10 @@ VALUE rb_cscalar_new_with_value (int8_t data_type, ca_size_t bytes, VALUE rva
817
837
  /* --- ca_obj_refer.c --- */
818
838
 
819
839
  CARefer *ca_refer_new (CArray *ca,
820
- int8_t data_type, int8_t rank, ca_size_t *dim,
840
+ int8_t data_type, int8_t ndim, ca_size_t *dim,
821
841
  ca_size_t bytes, ca_size_t offset);
822
842
  VALUE rb_ca_refer_new (VALUE self,
823
- int8_t data_type, int8_t rank, ca_size_t *dim,
843
+ int8_t data_type, int8_t ndim, ca_size_t *dim,
824
844
  ca_size_t bytes, ca_size_t offset);
825
845
 
826
846
  /* --- ca_obj_farray.c --- */
@@ -830,10 +850,10 @@ VALUE rb_ca_farray (VALUE self);
830
850
  /* --- ca_obj_block.c --- */
831
851
 
832
852
  CABlock *ca_block_new (CArray *carray,
833
- int8_t rank, ca_size_t *dim,
853
+ int8_t ndim, ca_size_t *dim,
834
854
  ca_size_t *start, ca_size_t *step, ca_size_t *count,
835
855
  ca_size_t offset);
836
- VALUE rb_ca_block_new (VALUE cary, int8_t rank, ca_size_t *dim,
856
+ VALUE rb_ca_block_new (VALUE cary, int8_t ndim, ca_size_t *dim,
837
857
  ca_size_t *start, ca_size_t *step, ca_size_t *count,
838
858
  ca_size_t offset);
839
859
 
@@ -865,12 +885,15 @@ VALUE rb_ca_fake_type (VALUE self, VALUE rtype, VALUE rbytes);
865
885
 
866
886
  /* --- ca_obj_repeat.c --- */
867
887
 
868
- CARepeat *ca_repeat_new (CArray *carray, int8_t rank, ca_size_t *count);
888
+ CARepeat *ca_repeat_new (CArray *carray, int8_t ndim, ca_size_t *count);
869
889
 
870
- VALUE rb_ca_repeat_new (VALUE cary, int8_t rank, ca_size_t *count);
890
+ VALUE rb_ca_repeat_new (VALUE cary, int8_t ndim, ca_size_t *count);
871
891
  VALUE rb_ca_repeat (int argc, VALUE *argv, VALUE self);
872
892
 
873
- VALUE rb_ca_ubrep_new (VALUE cary, int32_t rep_rank, ca_size_t *rep_dim);
893
+ /* --- ca_obj_unbound_repeat.c --- */
894
+
895
+ VALUE rb_ca_ubrep_shave (VALUE self, VALUE other);
896
+ VALUE rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim);
874
897
  VALUE ca_ubrep_bind_with (VALUE self, VALUE other);
875
898
 
876
899
  /* --- ca_obj_reduce.c --- */
@@ -888,6 +911,7 @@ VALUE rb_dim_iter_new (VALUE vca, CAIndexInfo *info);
888
911
  void * malloc_with_check(size_t size);
889
912
 
890
913
  int ca_install_obj_type (VALUE klass, ca_operation_function_t func);
914
+ VALUE ca_data_type_class (int8_t data_type);
891
915
 
892
916
  void ca_mark (void *ap);
893
917
  void ca_free (void *ap);
@@ -922,16 +946,19 @@ int ca_is_object_type (void *ap);
922
946
 
923
947
  void ca_check_type (void *ap, int8_t data_type);
924
948
  #define ca_check_data_type(ap, data_type) ca_check_type(ap, data_type)
925
- void ca_check_rank (void *ap, int rank);
926
- void ca_check_shape (void *ap, int rank, ca_size_t *dim);
949
+ void ca_check_ndim (void *ap, int ndim);
950
+ void ca_check_shape (void *ap, int ndim, ca_size_t *dim);
927
951
  void ca_check_same_data_type (void *ap1, void *ap2);
928
- void ca_check_same_rank (void *ap1, void *ap2);
952
+ void ca_check_same_ndim (void *ap1, void *ap2);
929
953
  void ca_check_same_elements (void *ap1, void *ap2);
930
954
  void ca_check_same_shape (void *ap1, void *ap2);
931
955
  void ca_check_index (void *ap, ca_size_t *idx);
932
956
  void ca_check_data_class (VALUE rtype);
933
957
  int ca_is_valid_index (void *ap, ca_size_t *idx);
934
958
 
959
+ #define ca_ndim(ca) ((ca)->ndim)
960
+ #define ca_shape(ca) ((ca)->dim)
961
+
935
962
  /* API : allocate, attach, update, sync, detach */
936
963
 
937
964
  void ca_allocate (void *ap);
@@ -1022,7 +1049,7 @@ void ca_block_from_carray(CArray *cs,
1022
1049
  (obj = rb_ca_wrap_readonly(obj, INT2NUM(data_type)), (CArray*) DATA_PTR(obj))
1023
1050
 
1024
1051
  VALUE rb_carray_wrap_ptr (int8_t data_type,
1025
- int8_t rank, ca_size_t *dim, ca_size_t bytes,
1052
+ int8_t ndim, ca_size_t *dim, ca_size_t bytes,
1026
1053
  CArray *mask, char *ptr, VALUE refer);
1027
1054
 
1028
1055
  void * ca_to_cptr (void *ap);
@@ -1042,7 +1069,7 @@ void ca_parse_range_without_check (VALUE arg, ca_size_t size,
1042
1069
  ca_size_t *offset, ca_size_t *count, ca_size_t *step);
1043
1070
 
1044
1071
  int ca_equal (void *ap, void *bp);
1045
- void ca_zerodiv(void);
1072
+ void ca_zerodiv(void) __attribute__((noreturn));
1046
1073
  int32_t ca_rand (double rmax);
1047
1074
  ca_size_t ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k);
1048
1075
 
@@ -1068,7 +1095,7 @@ void rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
1068
1095
  int rb_ca_is_type (VALUE arg, int type);
1069
1096
 
1070
1097
  /* scan index */
1071
- void rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t elements,
1098
+ void rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t elements,
1072
1099
  long argc, VALUE *argv, CAIndexInfo *info);
1073
1100
 
1074
1101
 
@@ -1095,7 +1122,7 @@ void rb_ca_modify (VALUE self);
1095
1122
  /* attributes */
1096
1123
  VALUE rb_ca_obj_type (VALUE self);
1097
1124
  VALUE rb_ca_data_type (VALUE self);
1098
- VALUE rb_ca_rank (VALUE self);
1125
+ VALUE rb_ca_ndim (VALUE self);
1099
1126
  VALUE rb_ca_bytes (VALUE self);
1100
1127
  VALUE rb_ca_elements (VALUE self);
1101
1128
  VALUE rb_ca_dim (VALUE self);