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_select.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
 
@@ -14,7 +12,7 @@
14
12
 
15
13
  VALUE rb_cCASelect;
16
14
 
17
- /* rdoc:
15
+ /* yard:
18
16
  class CASelect < CAVirtual # :nodoc:
19
17
  end
20
18
  */
@@ -22,7 +20,7 @@ VALUE rb_cCASelect;
22
20
  typedef struct {
23
21
  int16_t obj_type;
24
22
  int8_t data_type;
25
- int8_t rank;
23
+ int8_t ndim;
26
24
  int32_t flags;
27
25
  ca_size_t bytes;
28
26
  ca_size_t elements;
@@ -58,7 +56,7 @@ ca_select_setup (CASelect *ca, CArray *parent, CArray *select, int share)
58
56
  ca->obj_type = CA_OBJ_SELECT;
59
57
  ca->data_type = data_type;
60
58
  ca->flags = 0;
61
- ca->rank = 1;
59
+ ca->ndim = 1;
62
60
  ca->bytes = bytes;
63
61
 
64
62
  if ( share && ca_is_entity(select) ) {
@@ -3,16 +3,14 @@
3
3
  ca_obj_shift.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
 
15
- /* rdoc:
13
+ /* yard:
16
14
  class CAShift < CAVirtual # :nodoc:
17
15
  end
18
16
  */
@@ -22,7 +20,7 @@ static VALUE rb_cCAShift;
22
20
  typedef struct {
23
21
  int16_t obj_type;
24
22
  int8_t data_type;
25
- int8_t rank;
23
+ int8_t ndim;
26
24
  int32_t flags;
27
25
  ca_size_t bytes;
28
26
  ca_size_t elements;
@@ -47,35 +45,35 @@ int
47
45
  ca_shift_setup (CAShift *ca, CArray *parent,
48
46
  ca_size_t *shift, char *fill, int8_t *roll)
49
47
  {
50
- int8_t data_type, rank;
48
+ int8_t data_type, ndim;
51
49
  ca_size_t elements, bytes;
52
50
 
53
51
  data_type = parent->data_type;
54
52
  bytes = parent->bytes;
55
- rank = parent->rank;
53
+ ndim = parent->ndim;
56
54
  elements = parent->elements;
57
55
 
58
56
 
59
57
  ca->obj_type = CA_OBJ_SHIFT;
60
58
  ca->data_type = data_type;
61
59
  ca->flags = 0;
62
- ca->rank = rank;
60
+ ca->ndim = ndim;
63
61
  ca->bytes = bytes;
64
62
  ca->elements = elements;
65
63
  ca->ptr = NULL;
66
64
  ca->mask = NULL;
67
- ca->dim = ALLOC_N(ca_size_t, rank);
65
+ ca->dim = ALLOC_N(ca_size_t, ndim);
68
66
 
69
67
  ca->parent = parent;
70
68
  ca->attach = 0;
71
69
  ca->nosync = 0;
72
- ca->shift = ALLOC_N(ca_size_t, rank);
70
+ ca->shift = ALLOC_N(ca_size_t, ndim);
73
71
  ca->fill = ALLOC_N(char, ca->bytes);
74
- ca->roll = ALLOC_N(int8_t, rank);
72
+ ca->roll = ALLOC_N(int8_t, ndim);
75
73
 
76
- memcpy(ca->dim, parent->dim, rank * sizeof(ca_size_t));
77
- memcpy(ca->shift, shift, rank * sizeof(ca_size_t));
78
- memcpy(ca->roll, roll, rank * sizeof(int8_t));
74
+ memcpy(ca->dim, parent->dim, ndim * sizeof(ca_size_t));
75
+ memcpy(ca->shift, shift, ndim * sizeof(ca_size_t));
76
+ memcpy(ca->roll, roll, ndim * sizeof(int8_t));
79
77
 
80
78
  if ( fill ) {
81
79
  ca->fill_mask = 0;
@@ -194,7 +192,7 @@ ca_shift_func_ptr_at_index (void *ap, ca_size_t *idx)
194
192
  int8_t i;
195
193
  ca_size_t k, n;
196
194
  n = 0;
197
- for (i=0; i<ca->rank; i++) {
195
+ for (i=0; i<ca->ndim; i++) {
198
196
  k = idx[i];
199
197
  if ( roll[i] ) {
200
198
  k = ca_shift_rolled_index(ca, i, k);
@@ -230,7 +228,7 @@ ca_shift_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
230
228
  int8_t i;
231
229
  ca_size_t k, n;
232
230
  n = 0;
233
- for (i=0; i<ca->rank; i++) {
231
+ for (i=0; i<ca->ndim; i++) {
234
232
  k = idx[i];
235
233
  if ( roll[i] ) {
236
234
  k = ca_shift_rolled_index(ca, i, k);
@@ -257,7 +255,7 @@ ca_shift_func_store_index (void *ap, ca_size_t *idx, void *ptr)
257
255
  int8_t i;
258
256
  ca_size_t k, n;
259
257
  n = 0;
260
- for (i=0; i<ca->rank; i++) {
258
+ for (i=0; i<ca->ndim; i++) {
261
259
  k = idx[i];
262
260
  if ( roll[i] ) {
263
261
  k = ca_shift_rolled_index(ca, i, k);
@@ -402,7 +400,7 @@ ca_shift_attach_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx
402
400
  int8_t roll = ca->roll[level];
403
401
  ca_size_t i;
404
402
 
405
- if ( level == ca->rank - 1 ) {
403
+ if ( level == ca->ndim - 1 ) {
406
404
  if ( fill ) {
407
405
  for (i=0; i<ca->dim[level]; i++) {
408
406
  idx[level] = i;
@@ -561,7 +559,7 @@ ca_shift_sync_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
561
559
  int8_t roll = ca->roll[level];
562
560
  ca_size_t i;
563
561
 
564
- if ( level == ca->rank - 1 ) {
562
+ if ( level == ca->ndim - 1 ) {
565
563
  if ( ! shift ) {
566
564
  idx[level] = 0;
567
565
  idx0[level] = 0;
@@ -705,7 +703,7 @@ ca_shift_fill_loop (CAShift *ca, char *ptr,
705
703
  int8_t roll = ca->roll[level];
706
704
  ca_size_t i;
707
705
 
708
- if ( level == ca->rank - 1 ) {
706
+ if ( level == ca->ndim - 1 ) {
709
707
  if ( ( ! shift ) || roll ) {
710
708
  for (i=0; i<dim; i++) {
711
709
  idx0[level] = i;
@@ -828,7 +826,7 @@ rb_ca_shift_new (VALUE cary, ca_size_t *shift, char *fill, int8_t *roll)
828
826
  return obj;
829
827
  }
830
828
 
831
- /* rdoc:
829
+ /* yard:
832
830
  class CArray
833
831
  def shifted
834
832
  end
@@ -851,11 +849,11 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
851
849
  ropt = rb_pop_options(&argc, &argv);
852
850
  rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
853
851
 
854
- if ( argc != ca->rank ) {
855
- rb_raise(rb_eArgError, "# of arguments mismatch with rank");
852
+ if ( argc != ca->ndim ) {
853
+ rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
856
854
  }
857
855
 
858
- for (i=0; i<ca->rank; i++) {
856
+ for (i=0; i<ca->ndim; i++) {
859
857
  shift[i] = NUM2SIZE(argv[i]);
860
858
  }
861
859
 
@@ -889,18 +887,18 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
889
887
  }
890
888
 
891
889
  if ( NIL_P(rroll) ) {
892
- for (i=0; i<ca->rank; i++) {
890
+ for (i=0; i<ca->ndim; i++) {
893
891
  roll[i] = 0;
894
892
  }
895
893
  }
896
894
  else {
897
895
  Check_Type(rroll, T_ARRAY);
898
896
 
899
- if ( RARRAY_LEN(rroll) != ca->rank ) {
900
- rb_raise(rb_eArgError, "# of arguments mismatch with rank");
897
+ if ( RARRAY_LEN(rroll) != ca->ndim ) {
898
+ rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
901
899
  }
902
900
 
903
- for (i=0; i<ca->rank; i++) {
901
+ for (i=0; i<ca->ndim; i++) {
904
902
  roll[i] = NUM2INT(rb_ary_entry(rroll, i));
905
903
  }
906
904
  }
@@ -3,10 +3,8 @@
3
3
  ca_obj_transpose.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
 
@@ -15,7 +13,7 @@
15
13
  typedef struct {
16
14
  int16_t obj_type;
17
15
  int8_t data_type;
18
- int8_t rank;
16
+ int8_t ndim;
19
17
  int32_t flags;
20
18
  ca_size_t bytes;
21
19
  ca_size_t elements;
@@ -34,7 +32,7 @@ static int8_t CA_OBJ_TRANSPOSE;
34
32
 
35
33
  static VALUE rb_cCATrans;
36
34
 
37
- /* rdoc:
35
+ /* yard:
38
36
  class CATranspose < CAVirtual # :nodoc:
39
37
  end
40
38
  */
@@ -44,7 +42,7 @@ static VALUE rb_cCATrans;
44
42
  int
45
43
  ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
46
44
  {
47
- int8_t data_type, rank;
45
+ int8_t data_type, ndim;
48
46
  ca_size_t bytes, elements;
49
47
  ca_size_t *dim0;
50
48
  ca_size_t newdim[CA_RANK_MAX];
@@ -54,17 +52,17 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
54
52
 
55
53
  data_type = parent->data_type;
56
54
  bytes = parent->bytes;
57
- rank = parent->rank;
55
+ ndim = parent->ndim;
58
56
  elements = parent->elements;
59
57
  dim0 = parent->dim;
60
58
 
61
- for (i=0; i<rank; i++) {
59
+ for (i=0; i<ndim; i++) {
62
60
  map[i] = -1;
63
61
  }
64
62
 
65
- for (i=0; i<rank; i++) {
63
+ for (i=0; i<ndim; i++) {
66
64
  idim = imap[i];
67
- if ( idim < 0 || idim >= rank ) {
65
+ if ( idim < 0 || idim >= ndim ) {
68
66
  rb_raise(rb_eRuntimeError,
69
67
  "specified %i-th dimension number out of range", i);
70
68
  }
@@ -78,28 +76,28 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
78
76
  }
79
77
 
80
78
  step = 1;
81
- for (i=imap[rank-1]+1; i<rank; i++) {
79
+ for (i=imap[ndim-1]+1; i<ndim; i++) {
82
80
  step *= dim0[i];
83
81
  }
84
82
 
85
83
  ca->obj_type = CA_OBJ_TRANSPOSE;
86
84
  ca->data_type = data_type;
87
85
  ca->flags = 0;
88
- ca->rank = rank;
86
+ ca->ndim = ndim;
89
87
  ca->bytes = bytes;
90
88
  ca->elements = elements;
91
89
  ca->ptr = NULL;
92
90
  ca->mask = NULL;
93
- ca->dim = ALLOC_N(ca_size_t, rank);
91
+ ca->dim = ALLOC_N(ca_size_t, ndim);
94
92
 
95
93
  ca->parent = parent;
96
94
  ca->attach = 0;
97
95
  ca->nosync = 0;
98
- ca->imap = ALLOC_N(ca_size_t, rank);
96
+ ca->imap = ALLOC_N(ca_size_t, ndim);
99
97
  ca->step = step;
100
98
 
101
- memcpy(ca->dim, newdim, rank * sizeof(ca_size_t));
102
- memcpy(ca->imap, imap, rank * sizeof(ca_size_t));
99
+ memcpy(ca->dim, newdim, ndim * sizeof(ca_size_t));
100
+ memcpy(ca->imap, imap, ndim * sizeof(ca_size_t));
103
101
 
104
102
  if ( ca_has_mask(parent) ) {
105
103
  ca_create_mask(ca);
@@ -167,7 +165,7 @@ ca_trans_func_ptr_at_index (void *ap, ca_size_t *idx)
167
165
  ca_size_t *imap = ca->imap;
168
166
  ca_size_t idx0[CA_RANK_MAX];
169
167
  int8_t i;
170
- for (i=0; i<ca->rank; i++) {
168
+ for (i=0; i<ca->ndim; i++) {
171
169
  idx0[imap[i]] = idx[i];
172
170
  }
173
171
  return ca_ptr_at_index(ca->parent, idx0);
@@ -181,7 +179,7 @@ ca_trans_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
181
179
  ca_size_t *imap = ca->imap;
182
180
  ca_size_t idx0[CA_RANK_MAX];
183
181
  int8_t i;
184
- for (i=0; i<ca->rank; i++) {
182
+ for (i=0; i<ca->ndim; i++) {
185
183
  idx0[imap[i]] = idx[i];
186
184
  }
187
185
  ca_fetch_index(ca->parent, idx0, ptr);
@@ -194,7 +192,7 @@ ca_trans_func_store_index (void *ap, ca_size_t *idx, void *ptr)
194
192
  ca_size_t *imap = ca->imap;
195
193
  ca_size_t idx0[CA_RANK_MAX];
196
194
  int8_t i;
197
- for (i=0; i<ca->rank; i++) {
195
+ for (i=0; i<ca->ndim; i++) {
198
196
  idx0[imap[i]] = idx[i];
199
197
  }
200
198
  ca_store_index(ca->parent, idx0, ptr);
@@ -311,7 +309,7 @@ ca_trans_attach_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0
311
309
  ca_size_t *imap = ca->imap;
312
310
  ca_size_t i;
313
311
 
314
- if ( level == ca->rank - 1 ) {
312
+ if ( level == ca->ndim - 1 ) {
315
313
  idx[level] = 0;
316
314
  idx0[imap[level]] = 0;
317
315
  switch ( ca->bytes ) {
@@ -392,7 +390,7 @@ ca_trans_sync_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
392
390
  ca_size_t *imap = ca->imap;
393
391
  ca_size_t i;
394
392
 
395
- if ( level == ca->rank - 1 ) {
393
+ if ( level == ca->ndim - 1 ) {
396
394
  idx[level] = 0;
397
395
  idx0[imap[level]] = 0;
398
396
  switch ( ca->bytes ) {
@@ -473,7 +471,7 @@ ca_trans_fill_loop (CATrans *ca, char *ptr,
473
471
  ca_size_t *imap = ca->imap;
474
472
  ca_size_t i;
475
473
 
476
- if ( level == ca->rank - 1 ) {
474
+ if ( level == ca->ndim - 1 ) {
477
475
  for (i=0; i<ca->dim[level]; i++) {
478
476
  idx0[imap[level]] = i;
479
477
  memcpy(ca_ptr_at_index(ca->parent, idx0), ptr, ca->bytes);
@@ -511,7 +509,7 @@ rb_ca_trans_new (VALUE cary, ca_size_t *imap)
511
509
  return obj;
512
510
  }
513
511
 
514
- /* rdoc:
512
+ /* yard:
515
513
  class CArray
516
514
  def transposed
517
515
  end
@@ -529,17 +527,17 @@ rb_ca_trans (int argc, VALUE *argv, VALUE self)
529
527
  Data_Get_Struct(self, CArray, ca);
530
528
 
531
529
  if ( argc == 0 ) {
532
- for (i=0; i<ca->rank; i++) {
533
- imap[i] = ca->rank - i - 1;
530
+ for (i=0; i<ca->ndim; i++) {
531
+ imap[i] = ca->ndim - i - 1;
534
532
  }
535
533
  }
536
- else if ( argc == ca->rank ) {
537
- for (i=0; i<ca->rank; i++) {
534
+ else if ( argc == ca->ndim ) {
535
+ for (i=0; i<ca->ndim; i++) {
538
536
  imap[i] = NUM2SIZE(argv[i]);
539
537
  }
540
538
  }
541
539
  else {
542
- rb_raise(rb_eArgError, "# of arguments should be equal to rank");
540
+ rb_raise(rb_eArgError, "# of arguments should be equal to ndim");
543
541
  }
544
542
 
545
543
  obj = rb_ca_trans_new(self, imap);
@@ -3,10 +3,8 @@
3
3
  ca_obj_unbound_repeat.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
 
@@ -14,46 +12,48 @@
14
12
 
15
13
  VALUE rb_cCAUnboundRepeat;
16
14
 
17
- /* rdoc:
15
+ /* yard:
18
16
  class CAUnboundRepeat < CArray
19
17
  end
20
18
  */
21
19
 
22
20
  int
23
21
  ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
24
- int32_t rep_rank, ca_size_t *rep_dim)
22
+ int32_t rep_ndim, ca_size_t *rep_dim)
25
23
  {
26
- int8_t data_type, rank;
24
+ int8_t data_type;
27
25
  ca_size_t bytes, elements;
26
+ int8_t i;
28
27
 
29
28
  /* check arguments */
30
29
 
31
- CA_CHECK_RANK(rep_rank);
30
+ CA_CHECK_RANK(rep_ndim);
32
31
 
33
32
  data_type = parent->data_type;
34
33
  bytes = parent->bytes;
35
- rank = parent->rank;
36
34
  elements = parent->elements;
37
35
 
38
36
  ca->obj_type = CA_OBJ_UNBOUND_REPEAT;
39
37
  ca->data_type = data_type;
40
38
  ca->flags = 0;
41
- ca->rank = rank;
39
+ ca->ndim = rep_ndim;
42
40
  ca->bytes = bytes;
43
41
  ca->elements = elements;
44
42
  ca->ptr = NULL;
45
43
  ca->mask = NULL;
46
- ca->dim = ALLOC_N(ca_size_t, rank);
44
+ ca->dim = ALLOC_N(ca_size_t, rep_ndim);
47
45
 
48
46
  ca->parent = parent;
49
47
  ca->attach = 0;
50
48
  ca->nosync = 0;
51
49
 
52
- ca->rep_rank = rep_rank;
53
- ca->rep_dim = ALLOC_N(ca_size_t, rep_rank);
50
+ ca->rep_ndim = rep_ndim;
51
+ ca->rep_dim = ALLOC_N(ca_size_t, rep_ndim);
54
52
 
55
- memcpy(ca->dim, parent->dim, rank * sizeof(ca_size_t));
56
- memcpy(ca->rep_dim, rep_dim, rep_rank * sizeof(ca_size_t));
53
+ for (i=0; i<rep_ndim; i++) {
54
+ ca->rep_dim[i] = rep_dim[i];
55
+ ca->dim[i] = ( rep_dim[i] ) ? rep_dim[i] : 1;
56
+ }
57
57
 
58
58
  if ( ca_has_mask(parent) ) {
59
59
  ca_create_mask(ca);
@@ -63,10 +63,10 @@ ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
63
63
  }
64
64
 
65
65
  CAUnboundRepeat *
66
- ca_ubrep_new (CArray *parent, int32_t rep_rank, ca_size_t *rep_dim)
66
+ ca_ubrep_new (CArray *parent, int32_t rep_ndim, ca_size_t *rep_dim)
67
67
  {
68
68
  CAUnboundRepeat *ca = ALLOC(CAUnboundRepeat);
69
- ca_ubrep_setup(ca, parent, rep_rank, rep_dim);
69
+ ca_ubrep_setup(ca, parent, rep_ndim, rep_dim);
70
70
  return ca;
71
71
  }
72
72
 
@@ -88,7 +88,7 @@ static void *
88
88
  ca_ubrep_func_clone (void *ap)
89
89
  {
90
90
  CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
91
- return ca_ubrep_new(ca->parent, ca->rep_rank, ca->rep_dim);
91
+ return ca_ubrep_new(ca->parent, ca->rep_ndim, ca->rep_dim);
92
92
  }
93
93
 
94
94
  static char *
@@ -98,13 +98,6 @@ ca_ubrep_func_ptr_at_addr (void *ap, ca_size_t addr)
98
98
  return ca_ptr_at_addr(ca->parent, addr);
99
99
  }
100
100
 
101
- static char *
102
- ca_ubrep_func_ptr_at_index (void *ap, ca_size_t *idx)
103
- {
104
- CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
105
- return ca_ptr_at_index(ca->parent, idx);
106
- }
107
-
108
101
  static void
109
102
  ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
110
103
  {
@@ -112,13 +105,6 @@ ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
112
105
  ca_fetch_addr(ca->parent, addr, ptr);
113
106
  }
114
107
 
115
- static void
116
- ca_ubrep_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
117
- {
118
- CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
119
- ca_fetch_index(ca->parent, idx, ptr);
120
- }
121
-
122
108
  static void
123
109
  ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
124
110
  {
@@ -126,13 +112,6 @@ ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
126
112
  ca_store_addr(ca->parent, addr, ptr);
127
113
  }
128
114
 
129
- static void
130
- ca_ubrep_func_store_index (void *ap, ca_size_t *idx, void *ptr)
131
- {
132
- CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
133
- ca_store_index(ca->parent, idx, ptr);
134
- }
135
-
136
115
  static void
137
116
  ca_ubrep_func_allocate (void *ap)
138
117
  {
@@ -212,7 +191,7 @@ ca_ubrep_func_create_mask (void *ap)
212
191
  ca_create_mask(ca->parent);
213
192
  }
214
193
  ca->mask =
215
- (CArray *) ca_ubrep_new(ca->parent->mask, ca->rep_rank, ca->rep_dim);
194
+ (CArray *) ca_ubrep_new(ca->parent->mask, ca->rep_ndim, ca->rep_dim);
216
195
  }
217
196
 
218
197
  ca_operation_function_t ca_ubrep_func = {
@@ -221,11 +200,11 @@ ca_operation_function_t ca_ubrep_func = {
221
200
  free_ca_ubrep,
222
201
  ca_ubrep_func_clone,
223
202
  ca_ubrep_func_ptr_at_addr,
224
- ca_ubrep_func_ptr_at_index,
203
+ NULL,
225
204
  ca_ubrep_func_fetch_addr,
226
- ca_ubrep_func_fetch_index,
205
+ NULL,
227
206
  ca_ubrep_func_store_addr,
228
- ca_ubrep_func_store_index,
207
+ NULL,
229
208
  ca_ubrep_func_allocate,
230
209
  ca_ubrep_func_attach,
231
210
  ca_ubrep_func_sync,
@@ -239,14 +218,44 @@ ca_operation_function_t ca_ubrep_func = {
239
218
  /* ------------------------------------------------------------------- */
240
219
 
241
220
  VALUE
242
- rb_ca_ubrep_new (VALUE cary, int32_t rep_rank, ca_size_t *rep_dim)
221
+ rb_ca_ubrep_shave (VALUE self, VALUE other)
222
+ {
223
+ CAUnboundRepeat *ca;
224
+ CArray *co;
225
+ int8_t ndim, i;
226
+ ca_size_t dim[CA_RANK_MAX];
227
+
228
+ rb_check_carray_object(self);
229
+ rb_check_carray_object(other);
230
+
231
+ Data_Get_Struct(self, CAUnboundRepeat, ca);
232
+ Data_Get_Struct(other, CArray, co);
233
+
234
+ if ( ca->elements != co->elements ) {
235
+ rb_raise(rb_eRuntimeError, "mismatch in # of elements");
236
+ }
237
+
238
+ ndim = 0;
239
+ for (i=0; i<ca->ndim; i++) {
240
+ if ( ca->rep_dim[i] ) {
241
+ dim[ndim] = ca->rep_dim[i];
242
+ ndim += 1;
243
+ }
244
+ }
245
+
246
+ return rb_ca_refer_new(other, co->data_type, ndim, dim, co->bytes, 0);
247
+ }
248
+
249
+
250
+ VALUE
251
+ rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim)
243
252
  {
244
253
  volatile VALUE obj;
245
254
  CArray *parent;
246
255
  CAUnboundRepeat *ca;
247
256
  rb_check_carray_object(cary);
248
257
  Data_Get_Struct(cary, CArray, parent);
249
- ca = ca_ubrep_new(parent, rep_rank, rep_dim);
258
+ ca = ca_ubrep_new(parent, rep_ndim, rep_dim);
250
259
  obj = ca_wrap_struct(ca);
251
260
  rb_ca_set_parent(obj, cary);
252
261
  rb_ca_data_type_inherit(obj, cary);
@@ -257,80 +266,23 @@ VALUE
257
266
  rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
258
267
  {
259
268
  CArray *ca;
260
- ca_size_t rank, dim[CA_RANK_MAX];
261
- int32_t rep_rank;
269
+ int8_t ndim;
270
+ ca_size_t dim[CA_RANK_MAX];
271
+ int32_t rep_ndim;
262
272
  ca_size_t rep_dim[CA_RANK_MAX];
263
- ca_size_t count, i;
273
+ ca_size_t elements, count, i;
264
274
 
265
275
  Data_Get_Struct(self, CArray, ca);
266
276
 
267
- if ( argc == 1 && argv[0] == ID2SYM(rb_intern("*")) ) {
268
- CAUnboundRepeat *cr = (CAUnboundRepeat *) ca;
269
- volatile VALUE args;
270
- int repeatable = 0;
271
- args = rb_ary_new();
272
- if ( rb_obj_is_kind_of(self, rb_cCAUnboundRepeat) ) {
273
- repeatable = 1;
274
- for (i=0; i<cr->rep_rank; i++) {
275
- if ( cr->rep_dim[i] == 1 ) {
276
- rb_ary_push(args, ID2SYM(rb_intern("*")));
277
- repeatable = 1;
278
- }
279
- else if ( cr->rep_dim[i] > 1 ) {
280
- rb_ary_push(args, Qnil);
281
- }
282
- else {
283
- rb_ary_push(args, ID2SYM(rb_intern("*")));
284
- }
285
- }
286
- }
287
- else {
288
- for (i=0; i<ca->rank; i++) {
289
- if ( ca->dim[i] == 1 ) {
290
- rb_ary_push(args, ID2SYM(rb_intern("*")));
291
- repeatable = 1;
292
- }
293
- else {
294
- rb_ary_push(args, Qnil);
295
- }
296
- }
297
- }
298
- if ( ! repeatable ) {
299
- return self;
300
- }
301
- else {
302
- return rb_ca_unbound_repeat((int)RARRAY_LEN(args), RARRAY_PTR(args), self);
303
- }
304
- }
305
- else if ( argc == 2 &&
306
- argv[0] == ID2SYM(rb_intern("*")) &&
307
- rb_obj_is_carray(argv[1]) ) {
308
- volatile VALUE args, obj;
309
- args = ID2SYM(rb_intern("*"));
310
- obj = rb_ca_unbound_repeat(1, (VALUE*)&args, self);
311
- return ca_ubrep_bind_with(obj, argv[1]);
312
- }
313
- else if ( argc == 2 &&
314
- argv[1] == ID2SYM(rb_intern("*")) &&
315
- rb_obj_is_carray(argv[0]) ) {
316
- volatile VALUE args, obj;
317
- args = ID2SYM(rb_intern("*"));
318
- obj = rb_ca_unbound_repeat(1, (VALUE*)&args, self);
319
- return ca_ubrep_bind_with(obj, argv[0]);
320
- }
321
-
322
- rep_rank = argc;
277
+ rep_ndim = argc;
323
278
 
324
279
  count = 0;
325
- rank = 0;
326
-
327
- for (i=0; i<rep_rank; i++) {
328
- if ( rb_obj_is_kind_of(argv[i], rb_cSymbol) ) {
280
+ ndim = 0;
281
+ elements = 1;
282
+ for (i=0; i<rep_ndim; i++) {
283
+ if ( TYPE(argv[i]) == T_SYMBOL ) {
329
284
  if ( argv[i] == ID2SYM(rb_intern("*")) ) {
330
285
  rep_dim[i] = 0;
331
- if ( ca->dim[count] == 1 ) {
332
- count++;
333
- }
334
286
  }
335
287
  else {
336
288
  rb_raise(rb_eArgError, "unknown symbol (!= ':*') in arguments");
@@ -341,26 +293,21 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
341
293
  rb_raise(rb_eArgError, "invalid argument");
342
294
  }
343
295
  rep_dim[i] = ca->dim[count];
344
- dim[rank] = ca->dim[count];
345
- count++; rank++;
296
+ dim[ndim] = ca->dim[count];
297
+ elements *= ca->dim[count];
298
+ count++; ndim++;
346
299
  }
347
300
  }
348
301
 
349
- if ( count != ca->rank ) {
350
- rb_raise(rb_eRuntimeError, "too small # of nil");
302
+ if ( elements != ca->elements ) {
303
+ rb_raise(rb_eArgError, "mismatch in entity elements (%lli for %lli)", elements, ca->elements);
351
304
  }
352
305
 
353
- if ( rank != ca->rank ) {
354
- volatile VALUE par, obj;
355
- par = rb_ca_refer_new(self, ca->data_type, rank, dim, ca->bytes, 0);
356
- obj = rb_ca_ubrep_new(par, rep_rank, rep_dim);
357
- rb_ivar_set(obj, rb_intern("__real_parent__"), par);
358
- rb_ca_set_parent(obj, self);
359
- return obj;
360
- }
361
- else {
362
- return rb_ca_ubrep_new(self, rep_rank, rep_dim);
306
+ if ( ndim != ca->ndim ) {
307
+ rb_raise(rb_eArgError, "invalid number of nil's (%i for %i)", ndim, ca->ndim);
363
308
  }
309
+
310
+ return rb_ca_ubrep_new(self, rep_ndim, rep_dim);
364
311
  }
365
312
 
366
313
  static VALUE
@@ -378,21 +325,21 @@ rb_ca_ubrep_initialize_copy (VALUE self, VALUE other)
378
325
  Data_Get_Struct(self, CAUnboundRepeat, ca);
379
326
  Data_Get_Struct(other, CAUnboundRepeat, cs);
380
327
 
381
- ca_ubrep_setup(ca, cs->parent, cs->rep_rank, cs->rep_dim);
328
+ ca_ubrep_setup(ca, cs->parent, cs->rep_ndim, cs->rep_dim);
382
329
 
383
330
  return self;
384
331
  }
385
332
 
386
333
  /*
387
334
  static CARepeat *
388
- ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_rank, ca_size_t *new_dim)
335
+ ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_ndim, ca_size_t *new_dim)
389
336
  {
390
337
  ca_size_t rep_spec[CA_RANK_MAX];
391
338
  int i;
392
- if ( ca->rep_rank != new_rank ) {
393
- rb_raise(rb_eArgError, "invalid new_rank");
339
+ if ( ca->rep_ndim != new_ndim ) {
340
+ rb_raise(rb_eArgError, "invalid new_ndim");
394
341
  }
395
- for (i=0; i<new_rank; i++) {
342
+ for (i=0; i<new_ndim; i++) {
396
343
  if ( ca->rep_dim[i] == 0 ) {
397
344
  rep_spec[i] = new_dim[i];
398
345
  }
@@ -400,65 +347,66 @@ ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_rank, ca_size_t *new_dim)
400
347
  rep_spec[i] = 0;
401
348
  }
402
349
  }
403
- return ca_repeat_new((CArray*)ca, new_rank, rep_spec);
350
+ return ca_repeat_new((CArray*)ca, new_ndim, rep_spec);
404
351
  }
405
352
  */
406
353
 
407
354
  VALUE
408
- ca_ubrep_bind2 (VALUE self, int32_t new_rank, ca_size_t *new_dim)
355
+ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
409
356
  {
410
357
  CAUnboundRepeat *ca;
411
358
  ca_size_t rep_spec[CA_RANK_MAX];
412
359
  ca_size_t upr_spec[CA_RANK_MAX];
413
360
  ca_size_t srp_spec[CA_RANK_MAX];
414
- int uprep = 0, srp_rank;
361
+ int uprep = 0, srp_ndim;
362
+ int ndim_real;
415
363
  int i;
416
364
 
417
365
  Data_Get_Struct(self, CAUnboundRepeat, ca);
418
366
 
419
- if ( ca->rep_rank != new_rank ) {
420
- rb_raise(rb_eArgError, "invalid new_rank (%i <-> %i)",
421
- ca->rep_rank, new_rank);
367
+ if ( ca->rep_ndim != new_ndim ) {
368
+ rb_raise(rb_eArgError, "invalid new_ndim (%i <-> %i)",
369
+ ca->rep_ndim, new_ndim);
422
370
  }
423
371
 
424
- srp_rank = 0;
425
- for (i=0; i<new_rank; i++) {
372
+ srp_ndim = 0;
373
+ ndim_real = 0;
374
+ for (i=0; i<new_ndim; i++) {
426
375
  if ( ca->rep_dim[i] == 0 ) {
427
376
  if ( new_dim[i] == 0 ) {
428
377
  uprep = 1;
429
378
  }
430
379
  else {
431
- srp_spec[srp_rank++] = new_dim[i];
380
+ srp_spec[srp_ndim++] = new_dim[i];
432
381
  }
433
382
  rep_spec[i] = new_dim[i];
434
383
  upr_spec[i] = new_dim[i];
435
384
  }
436
385
  else {
386
+ ndim_real++;
437
387
  rep_spec[i] = 0;
438
- srp_spec[srp_rank++] = 0;
388
+ srp_spec[srp_ndim++] = 0;
439
389
  upr_spec[i] = ca->rep_dim[i];
440
390
  }
441
391
  }
392
+
442
393
  if ( uprep ) {
443
394
  volatile VALUE rep;
444
- if ( srp_rank >= ca->rank ) {
445
- rep = rb_ca_repeat_new(rb_ca_parent(self), srp_rank, srp_spec);
395
+ if ( srp_ndim >= ndim_real ) {
396
+ rep = rb_ca_repeat_new(rb_ca_parent(self), srp_ndim, srp_spec);
446
397
  }
447
398
  else {
448
399
  rep = rb_ca_parent(self);
449
400
  }
450
- return rb_ca_ubrep_new(rep, new_rank, upr_spec);
401
+ return rb_ca_ubrep_new(rep, new_ndim, upr_spec);
451
402
  }
452
403
  else {
453
- return rb_ca_repeat_new(self, new_rank, rep_spec);
404
+ return rb_ca_repeat_new(rb_ca_parent(self), new_ndim, rep_spec);
454
405
  }
455
406
  }
456
407
 
457
- /* rdoc:
458
- class CAUnboundRepeat
459
- def bind_with(other)
460
- end
461
- end
408
+ /* @overload bind_with (other)
409
+
462
410
  */
463
411
 
464
412
  VALUE
@@ -474,21 +422,18 @@ ca_ubrep_bind_with (VALUE self, VALUE other)
474
422
 
475
423
  if ( co->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
476
424
  Data_Get_Struct(other, CAUnboundRepeat, cup);
477
- return ca_ubrep_bind2(self, cup->rep_rank, cup->rep_dim);
425
+ return ca_ubrep_bind2(self, cup->rep_ndim, cup->rep_dim);
478
426
  }
479
427
  else if ( ca_is_scalar(co) ) {
480
428
  return self;
481
429
  }
482
430
  else {
483
- return ca_ubrep_bind2(self, co->rank, co->dim);
431
+ return ca_ubrep_bind2(self, co->ndim, co->dim);
484
432
  }
485
433
  }
486
434
 
487
- /* rdoc:
488
- class CAUnboundRepeat
489
- def bind(*index)
490
- end
491
- end
435
+ /* @overload bind (*index)
436
+
492
437
  */
493
438
 
494
439
  static VALUE
@@ -500,9 +445,10 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
500
445
 
501
446
  Data_Get_Struct(self, CAUnboundRepeat, ca);
502
447
 
503
- if ( ca->rep_rank != argc ) {
504
- rb_raise(rb_eArgError, "invalid new_rank");
448
+ if ( ca->rep_ndim != argc ) {
449
+ rb_raise(rb_eArgError, "invalid new_ndim");
505
450
  }
451
+
506
452
  for (i=0; i<argc; i++) {
507
453
  if ( ca->rep_dim[i] == 0 ) {
508
454
  rep_spec[i] = NUM2SIZE(argv[i]);
@@ -512,7 +458,7 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
512
458
  }
513
459
  }
514
460
 
515
- return rb_ca_repeat_new(self, argc, rep_spec);
461
+ return rb_ca_repeat_new(rb_ca_parent(self), argc, rep_spec);
516
462
  }
517
463
 
518
464
  static VALUE
@@ -524,8 +470,8 @@ rb_ca_ubrep_spec (VALUE self)
524
470
 
525
471
  Data_Get_Struct(self, CAUnboundRepeat, ca);
526
472
 
527
- spec = rb_ary_new2(ca->rep_rank);
528
- for (i=0; i<ca->rep_rank; i++) {
473
+ spec = rb_ary_new2(ca->rep_ndim);
474
+ for (i=0; i<ca->rep_ndim; i++) {
529
475
  if ( ca->rep_dim[i] ) {
530
476
  rb_ary_store(spec, i, SIZE2NUM(ca->rep_dim[i]));
531
477
  }