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_grid.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;
@@ -32,7 +30,7 @@ typedef struct {
32
30
 
33
31
  static VALUE rb_cCAGrid;
34
32
 
35
- /* rdoc:
33
+ /* yard:
36
34
  class CAGrid < CAVirtual # :nodoc:
37
35
  end
38
36
  */
@@ -43,20 +41,21 @@ int
43
41
  ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
44
42
  CArray **grid, int8_t *contig, int share)
45
43
  {
46
- int8_t rank, data_type;
44
+ int8_t ndim, data_type;
47
45
  ca_size_t *dim0;
48
46
  ca_size_t elements, bytes;
47
+ ca_size_t j, k;
49
48
  double length;
50
- int i, j, k;
49
+ int8_t i;
51
50
 
52
51
  data_type = parent->data_type;
53
- rank = parent->rank;
52
+ ndim = parent->ndim;
54
53
  bytes = parent->bytes;
55
54
  dim0 = parent->dim;
56
55
 
57
56
  elements = 1;
58
57
  length = bytes;
59
- for (i=0; i<rank; i++) {
58
+ for (i=0; i<ndim; i++) {
60
59
  if ( dim[i] < 0 ) {
61
60
  rb_raise(rb_eRuntimeError, "negative size for %i-th dimension", i);
62
61
  }
@@ -71,12 +70,12 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
71
70
  ca->obj_type = CA_OBJ_GRID;
72
71
  ca->data_type = data_type;
73
72
  ca->flags = 0;
74
- ca->rank = rank;
73
+ ca->ndim = ndim;
75
74
  ca->bytes = bytes;
76
75
  ca->elements = elements;
77
76
  ca->ptr = NULL;
78
77
  ca->mask = NULL;
79
- ca->dim = ALLOC_N(ca_size_t, rank);
78
+ ca->dim = ALLOC_N(ca_size_t, ndim);
80
79
 
81
80
  ca->parent = parent;
82
81
  ca->attach = 0;
@@ -88,14 +87,14 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
88
87
  ca->contig = contig;
89
88
  }
90
89
  else {
91
- ca->grid = ALLOC_N(CArray *, rank);
92
- ca->contig = ALLOC_N(int8_t, rank);
90
+ ca->grid = ALLOC_N(CArray *, ndim);
91
+ ca->contig = ALLOC_N(int8_t, ndim);
93
92
  }
94
93
 
95
- memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
94
+ memcpy(ca->dim, dim, ndim * sizeof(ca_size_t));
96
95
 
97
96
  if ( ! share ) {
98
- for (i=0; i<rank; i++) {
97
+ for (i=0; i<ndim; i++) {
99
98
  if ( grid[i] ) {
100
99
  if ( ca_is_any_masked(grid[i]) ) {
101
100
  ca_size_t gsize = grid[i]->elements - ca_count_masked(grid[i]);
@@ -137,7 +136,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
137
136
  }
138
137
  }
139
138
 
140
- if ( ca->rank == 1 && ca_is_scalar(grid[0]) ) {
139
+ if ( ca->ndim == 1 && ca_is_scalar(grid[0]) ) {
141
140
  ca_set_flag(ca, CA_FLAG_SCALAR);
142
141
  }
143
142
 
@@ -169,7 +168,7 @@ free_ca_grid (void *ap)
169
168
  ca_free(ca->mask);
170
169
  if ( ! (ca->flags & CA_FLAG_SHARE_INDEX)) {
171
170
  xfree(ca->contig);
172
- for (i=0; i<ca->rank; i++) {
171
+ for (i=0; i<ca->ndim; i++) {
173
172
  ca_free(ca->grid[i]);
174
173
  }
175
174
  xfree(ca->grid);
@@ -217,7 +216,7 @@ ca_grid_func_ptr_at_index (void *ap, ca_size_t *idx)
217
216
  ca_size_t n;
218
217
 
219
218
  n = 0;
220
- for (i=0; i<ca->rank; i++) {
219
+ for (i=0; i<ca->ndim; i++) {
221
220
  n = dim0[i]*n + *(ca_size_t*) ca_ptr_at_addr(grid[i], idx[i]);
222
221
  }
223
222
 
@@ -240,7 +239,7 @@ ca_grid_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
240
239
  CArray **grid = ca->grid;
241
240
  ca_size_t idx0[CA_RANK_MAX];
242
241
  int8_t i;
243
- for (i=0; i<ca->rank; i++) {
242
+ for (i=0; i<ca->ndim; i++) {
244
243
  ca_fetch_addr(grid[i], idx[i], &idx0[i]);
245
244
  }
246
245
  ca_fetch_index(ca->parent, idx0, ptr);
@@ -253,7 +252,7 @@ ca_grid_func_store_index (void *ap, ca_size_t *idx, void *ptr)
253
252
  CArray **grid = ca->grid;
254
253
  ca_size_t idx0[CA_RANK_MAX];
255
254
  int8_t i;
256
- for (i=0; i<ca->rank; i++) {
255
+ for (i=0; i<ca->ndim; i++) {
257
256
  ca_fetch_addr(grid[i], idx[i], &idx0[i]);
258
257
  }
259
258
  ca_store_index(ca->parent, idx0, ptr);
@@ -386,7 +385,7 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
386
385
  CArray **grid = ca->grid;
387
386
  ca_size_t i, k;
388
387
 
389
- if ( level == ca->rank - 1 ) {
388
+ if ( level == ca->ndim - 1 ) {
390
389
  idx[level] = 0;
391
390
  idx0[level] = 0;
392
391
  if ( ca->contig[level] ) {
@@ -460,7 +459,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
460
459
  CArray **grid = ca->grid;
461
460
  ca_size_t i, k;
462
461
 
463
- if ( level == ca->rank - 1 ) {
462
+ if ( level == ca->ndim - 1 ) {
464
463
  idx[level] = 0;
465
464
  idx0[level] = 0;
466
465
  if ( ca->contig[level] ) {
@@ -532,7 +531,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
532
531
  {
533
532
  CArray **grid = ca->grid;
534
533
  ca_size_t i, k;
535
- if ( level == ca->rank - 1 ) {
534
+ if ( level == ca->ndim - 1 ) {
536
535
  idx0[level] = 0;
537
536
  if ( ca->contig[level] ) {
538
537
  char *p = ca_ptr_at_index(ca->parent, idx0);
@@ -602,7 +601,7 @@ rb_ca_grid_new (VALUE cary, ca_size_t *dim, CArray **grid)
602
601
  return obj;
603
602
  }
604
603
 
605
- /* rdoc:
604
+ /* yard:
606
605
  class CArray
607
606
  def grid
608
607
  end
@@ -624,21 +623,21 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
624
623
 
625
624
  ridx = rb_ary_new4(argc, argv);
626
625
 
627
- if ( RARRAY_LEN(ridx) > ca->rank ) {
628
- rb_raise(rb_eArgError, "# of arguments doesn't equal to the rank");
626
+ if ( RARRAY_LEN(ridx) > ca->ndim ) {
627
+ rb_raise(rb_eArgError, "# of arguments doesn't equal to the ndim");
629
628
  }
630
- else if ( RARRAY_LEN(ridx) < ca->rank ) {
629
+ else if ( RARRAY_LEN(ridx) < ca->ndim ) {
631
630
  volatile VALUE ref;
632
631
  CArray *cv;
633
632
  ca_size_t rdim[CA_RANK_MAX];
634
- ca_size_t rrank = RARRAY_LEN(ridx);
633
+ ca_size_t rndim = RARRAY_LEN(ridx);
635
634
  ca_size_t j = 0, k;
636
- for (i=0; i<rrank; i++) {
635
+ for (i=0; i<rndim; i++) {
637
636
  rval = rb_ary_entry(ridx, i);
638
637
  if ( rb_obj_is_carray(rval) ) {
639
638
  Data_Get_Struct(rval, CArray, cv);
640
639
  rdim[i] = 1;
641
- for (k=0; k<cv->rank; k++) {
640
+ for (k=0; k<cv->ndim; k++) {
642
641
  rdim[i] *= ca->dim[j];
643
642
  j += 1;
644
643
  }
@@ -648,10 +647,10 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
648
647
  j += 1;
649
648
  }
650
649
  }
651
- if ( j != ca->rank ) {
652
- rb_raise(rb_eArgError, "invalid total rank of args");
650
+ if ( j != ca->ndim ) {
651
+ rb_raise(rb_eArgError, "invalid total ndim of args");
653
652
  }
654
- ref = rb_ca_refer_new(self, ca->data_type, rrank, rdim, ca->bytes, 0);
653
+ ref = rb_ca_refer_new(self, ca->data_type, rndim, rdim, ca->bytes, 0);
655
654
  return rb_ca_grid(argc, argv, ref);
656
655
  }
657
656
 
@@ -3,10 +3,8 @@
3
3
  ca_obj_mapping.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
 
@@ -21,7 +19,7 @@
21
19
  typedef struct {
22
20
  int16_t obj_type;
23
21
  int8_t data_type;
24
- int8_t rank;
22
+ int8_t ndim;
25
23
  int32_t flags;
26
24
  ca_size_t bytes;
27
25
  ca_size_t elements;
@@ -39,7 +37,7 @@ static int8_t CA_OBJ_MAPPING;
39
37
 
40
38
  static VALUE rb_cCAMapping;
41
39
 
42
- /* rdoc:
40
+ /* yard:
43
41
  class CAMapping < CAVirtual # :nodoc:
44
42
  end
45
43
  */
@@ -49,7 +47,7 @@ static VALUE rb_cCAMapping;
49
47
  int
50
48
  ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
51
49
  {
52
- int8_t rank, data_type;
50
+ int8_t ndim, data_type;
53
51
  ca_size_t elements, bytes;
54
52
  ca_size_t *p;
55
53
  ca_size_t i;
@@ -66,19 +64,19 @@ ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
66
64
  ca->bytes = bytes;
67
65
  ca->ptr = NULL;
68
66
 
69
- rank = mapper->rank;
67
+ ndim = mapper->ndim;
70
68
  elements = mapper->elements;
71
69
 
72
- ca->rank = rank;
70
+ ca->ndim = ndim;
73
71
  ca->elements = elements;
74
72
  ca->mask = NULL;
75
- ca->dim = ALLOC_N(ca_size_t, rank);
73
+ ca->dim = ALLOC_N(ca_size_t, ndim);
76
74
 
77
75
  ca->parent = parent;
78
76
  ca->attach = 0;
79
77
  ca->nosync = 0;
80
78
 
81
- memcpy(ca->dim, mapper->dim, rank * sizeof(ca_size_t));
79
+ memcpy(ca->dim, mapper->dim, ndim * sizeof(ca_size_t));
82
80
 
83
81
  if ( share ) {
84
82
  ca_set_flag(ca, CA_FLAG_SHARE_INDEX);
@@ -176,7 +174,7 @@ ca_mapping_func_ptr_at_index (void *ap, ca_size_t *idx)
176
174
  int8_t i;
177
175
  ca_size_t n;
178
176
  n = idx[0];
179
- for (i=1; i<ca->rank; i++) {
177
+ for (i=1; i<ca->ndim; i++) {
180
178
  n = dim[i]*n+idx[i];
181
179
  }
182
180
  n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
@@ -200,7 +198,7 @@ ca_mapping_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
200
198
  int8_t i;
201
199
  ca_size_t n;
202
200
  n = idx[0];
203
- for (i=1; i<ca->rank; i++) {
201
+ for (i=1; i<ca->ndim; i++) {
204
202
  n = dim[i]*n+idx[i];
205
203
  }
206
204
  n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
@@ -215,7 +213,7 @@ ca_mapping_func_store_index (void *ap, ca_size_t *idx, void *ptr)
215
213
  int8_t i;
216
214
  ca_size_t n;
217
215
  n = idx[0];
218
- for (i=1; i<ca->rank; i++) {
216
+ for (i=1; i<ca->ndim; i++) {
219
217
  n = dim[i]*n+idx[i];
220
218
  }
221
219
  n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
@@ -3,10 +3,8 @@
3
3
  ca_obj_object.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
 
@@ -41,7 +39,7 @@
41
39
  VALUE rb_cCAObject;
42
40
 
43
41
 
44
- /* rdoc:
42
+ /* yard:
45
43
  class CAObject < CAVirtual # :nodoc:
46
44
  end
47
45
  */
@@ -52,17 +50,17 @@ VALUE rb_cCAObject;
52
50
  static int8_t CA_OBJ_OBJECT_MASK;
53
51
  static VALUE rb_cCAObjectMask;
54
52
 
55
- /* rdoc:
53
+ /* yard:
56
54
  class CAObjectMask < CAVirtual # :nodoc:
57
55
  end
58
56
  */
59
57
 
60
58
 
61
59
  static CAObjectMask *
62
- ca_objmask_new (VALUE array, int8_t rank, ca_size_t *dim)
60
+ ca_objmask_new (VALUE array, int8_t ndim, ca_size_t *dim)
63
61
  {
64
62
  CAObjectMask *ca = ALLOC(CAObjectMask);
65
- ca_wrap_setup_null((CArray *)ca, CA_BOOLEAN, rank, dim, 0, NULL);
63
+ ca_wrap_setup_null((CArray *)ca, CA_BOOLEAN, ndim, dim, 0, NULL);
66
64
  ca->obj_type = CA_OBJ_OBJECT_MASK;
67
65
  ca->array = array;
68
66
 
@@ -81,7 +79,7 @@ static void *
81
79
  ca_objmask_func_clone (void *ap)
82
80
  {
83
81
  CAObjectMask *ca = (CAObjectMask *) ap;
84
- return ca_objmask_new(ca->array, ca->rank, ca->dim);
82
+ return ca_objmask_new(ca->array, ca->ndim, ca->dim);
85
83
  }
86
84
 
87
85
  void
@@ -100,8 +98,8 @@ ca_objmask_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
100
98
  else if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
101
99
  ca_size_t idx[CA_RANK_MAX];
102
100
  ca_addr2index(ca, addr, idx);
103
- ridx = rb_ary_new2(ca->rank);
104
- for (i=0; i<ca->rank; i++) {
101
+ ridx = rb_ary_new2(ca->ndim);
102
+ for (i=0; i<ca->ndim; i++) {
105
103
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
106
104
  }
107
105
  rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
@@ -121,8 +119,8 @@ ca_objmask_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
121
119
  int i;
122
120
 
123
121
  if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
124
- ridx = rb_ary_new2(ca->rank);
125
- for (i=0; i<ca->rank; i++) {
122
+ ridx = rb_ary_new2(ca->ndim);
123
+ for (i=0; i<ca->ndim; i++) {
126
124
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
127
125
  }
128
126
  rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
@@ -158,8 +156,8 @@ ca_objmask_func_store_addr (void *ap, ca_size_t addr, void *ptr)
158
156
  else if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
159
157
  ca_size_t idx[CA_RANK_MAX];
160
158
  ca_addr2index(ca, addr, idx);
161
- ridx = rb_ary_new2(ca->rank);
162
- for (i=0; i<ca->rank; i++) {
159
+ ridx = rb_ary_new2(ca->ndim);
160
+ for (i=0; i<ca->ndim; i++) {
163
161
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
164
162
  }
165
163
  rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
@@ -177,8 +175,8 @@ ca_objmask_func_store_index (void *ap, ca_size_t *idx, void *ptr)
177
175
  rval = INT2NUM( *(uint8_t*)ptr );
178
176
 
179
177
  if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
180
- ridx = rb_ary_new2(ca->rank);
181
- for (i=0; i<ca->rank; i++) {
178
+ ridx = rb_ary_new2(ca->ndim);
179
+ for (i=0; i<ca->ndim; i++) {
182
180
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
183
181
  }
184
182
  rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
@@ -290,7 +288,7 @@ rb_ca_objmask_initialize_copy (VALUE self, VALUE other)
290
288
  Data_Get_Struct(self, CAObjectMask, ca);
291
289
  Data_Get_Struct(other, CAObjectMask, cs);
292
290
 
293
- carray_setup((CArray *)ca, CA_BOOLEAN, cs->rank, cs->dim, 0, NULL);
291
+ carray_setup((CArray *)ca, CA_BOOLEAN, cs->ndim, cs->dim, 0, NULL);
294
292
  ca->obj_type = CA_OBJ_OBJECT_MASK;
295
293
  ca->array = cs->array;
296
294
 
@@ -301,7 +299,7 @@ rb_ca_objmask_initialize_copy (VALUE self, VALUE other)
301
299
 
302
300
  static int
303
301
  ca_object_setup (CAObject *ca,
304
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes)
302
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes)
305
303
  {
306
304
  ca_size_t elements;
307
305
  double length;
@@ -310,15 +308,15 @@ ca_object_setup (CAObject *ca,
310
308
  /* check arguments */
311
309
 
312
310
  CA_CHECK_DATA_TYPE(data_type);
313
- CA_CHECK_RANK(rank);
314
- CA_CHECK_DIM(rank, dim);
311
+ CA_CHECK_RANK(ndim);
312
+ CA_CHECK_DIM(ndim, dim);
315
313
  CA_CHECK_BYTES(data_type, bytes);
316
314
 
317
315
  /* calculate total number of elements */
318
316
 
319
317
  elements = 1;
320
318
  length = bytes;
321
- for (i=0; i<rank; i++) {
319
+ for (i=0; i<ndim; i++) {
322
320
  elements *= dim[i];
323
321
  length *= dim[i];
324
322
  }
@@ -330,7 +328,7 @@ ca_object_setup (CAObject *ca,
330
328
  ca->obj_type = CA_OBJ_OBJECT;
331
329
  ca->data_type = data_type;
332
330
  ca->flags = 0;
333
- ca->rank = rank;
331
+ ca->ndim = ndim;
334
332
  ca->bytes = bytes;
335
333
  ca->elements = elements;
336
334
  ca->ptr = NULL;
@@ -339,20 +337,20 @@ ca_object_setup (CAObject *ca,
339
337
  ca->attach = 0;
340
338
  ca->nosync = 0;
341
339
 
342
- ca->dim = ALLOC_N(ca_size_t, rank);
340
+ ca->dim = ALLOC_N(ca_size_t, ndim);
343
341
 
344
- ca->data = ca_wrap_new_null(data_type, rank, dim, bytes, NULL);
342
+ ca->data = ca_wrap_new_null(data_type, ndim, dim, bytes, NULL);
345
343
 
346
- memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
344
+ memcpy(ca->dim, dim, ndim * sizeof(ca_size_t));
347
345
 
348
346
  return 0;
349
347
  }
350
348
 
351
349
  static CAObject *
352
- ca_object_new (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes)
350
+ ca_object_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes)
353
351
  {
354
352
  CAObject *ca = ALLOC(CAObject);
355
- ca_object_setup(ca, data_type, rank, dim, bytes);
353
+ ca_object_setup(ca, data_type, ndim, dim, bytes);
356
354
  return ca;
357
355
  }
358
356
 
@@ -373,7 +371,7 @@ static void *
373
371
  ca_object_func_clone (void *ap)
374
372
  {
375
373
  CAObject *ca = (CAObject *) ap;
376
- return ca_object_new(ca->bytes, ca->rank, ca->dim, ca->bytes);
374
+ return ca_object_new(ca->bytes, ca->ndim, ca->dim, ca->bytes);
377
375
  }
378
376
 
379
377
  #define ca_object_func_ptr_at_addr ca_array_func_ptr_at_addr
@@ -408,8 +406,8 @@ ca_object_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
408
406
  else {
409
407
  ca_size_t idx[CA_RANK_MAX];
410
408
  ca_addr2index(ca, addr, idx);
411
- ridx = rb_ary_new2(ca->rank);
412
- for (i=0; i<ca->rank; i++) {
409
+ ridx = rb_ary_new2(ca->ndim);
410
+ for (i=0; i<ca->ndim; i++) {
413
411
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
414
412
  }
415
413
  rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
@@ -439,8 +437,8 @@ ca_object_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
439
437
  volatile VALUE ridx, raddr, rval;
440
438
  int i;
441
439
  if ( rb_obj_respond_to(ca->self, rb_intern("fetch_index"), Qtrue) ) {
442
- ridx = rb_ary_new2(ca->rank);
443
- for (i=0; i<ca->rank; i++) {
440
+ ridx = rb_ary_new2(ca->ndim);
441
+ for (i=0; i<ca->ndim; i++) {
444
442
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
445
443
  }
446
444
  rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
@@ -498,8 +496,8 @@ ca_object_func_store_addr (void *ap, ca_size_t addr, void *ptr)
498
496
  else {
499
497
  ca_size_t idx[CA_RANK_MAX];
500
498
  ca_addr2index(ca, addr, idx);
501
- ridx = rb_ary_new2(ca->rank);
502
- for (i=0; i<ca->rank; i++) {
499
+ ridx = rb_ary_new2(ca->ndim);
500
+ for (i=0; i<ca->ndim; i++) {
503
501
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
504
502
  }
505
503
  rval = rb_ca_ptr2obj(ca->self, ptr);
@@ -514,8 +512,8 @@ ca_object_func_store_index (void *ap, ca_size_t *idx, void *ptr)
514
512
  volatile VALUE ridx, raddr, rval;
515
513
  int i;
516
514
  if ( rb_obj_respond_to(ca->self, rb_intern("store_index"), Qtrue) ) {
517
- ridx = rb_ary_new2(ca->rank);
518
- for (i=0; i<ca->rank; i++) {
515
+ ridx = rb_ary_new2(ca->ndim);
516
+ for (i=0; i<ca->ndim; i++) {
519
517
  rb_ary_store(ridx, i, SIZE2NUM(idx[i]));
520
518
  }
521
519
  rval = rb_ca_ptr2obj(ca->self, ptr);
@@ -634,7 +632,7 @@ ca_object_func_create_mask (void *ap)
634
632
  if ( ! ca->data->mask ) {
635
633
  ca_create_mask(ca->data);
636
634
  }
637
- ca->mask = (CArray*) ca_objmask_new(ca->self, ca->rank, ca->dim);
635
+ ca->mask = (CArray*) ca_objmask_new(ca->self, ca->ndim, ca->dim);
638
636
  ca->mask->ptr = ca->data->mask->ptr;
639
637
  rmask = ca_wrap_struct(ca->mask);
640
638
  rb_ivar_set(ca->self, rb_intern("mask"), rmask);
@@ -679,7 +677,7 @@ rb_ca_object_initialize_copy (VALUE self, VALUE other)
679
677
  Data_Get_Struct(self, CAObject, ca);
680
678
  Data_Get_Struct(other, CAObject, cs);
681
679
 
682
- ca_object_setup(ca, cs->data_type, cs->rank, cs->dim, cs->bytes);
680
+ ca_object_setup(ca, cs->data_type, cs->ndim, cs->dim, cs->bytes);
683
681
  ca->self = self;
684
682
 
685
683
  rb_ca_data_type_inherit(self, other);
@@ -703,7 +701,7 @@ rb_ca_object_initialize (int argc, VALUE *argv, VALUE self)
703
701
  {
704
702
  volatile VALUE rtype, rdim, ropt, rbytes = Qnil, rrdonly = Qnil, rparent = Qnil, rdata;
705
703
  CAObject *ca;
706
- int8_t data_type, rank;
704
+ int8_t data_type, ndim;
707
705
  ca_size_t dim[CA_RANK_MAX];
708
706
  ca_size_t bytes;
709
707
  int i;
@@ -721,13 +719,13 @@ rb_ca_object_initialize (int argc, VALUE *argv, VALUE self)
721
719
 
722
720
  Check_Type(rdim, T_ARRAY);
723
721
 
724
- rank = RARRAY_LEN(rdim);
725
- for (i=0; i<rank; i++) {
722
+ ndim = RARRAY_LEN(rdim);
723
+ for (i=0; i<ndim; i++) {
726
724
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
727
725
  }
728
726
 
729
727
  Data_Get_Struct(self, CAObject, ca);
730
- ca_object_setup(ca, data_type, rank, dim, bytes);
728
+ ca_object_setup(ca, data_type, ndim, dim, bytes);
731
729
  ca->self = self;
732
730
 
733
731
  rdata = ca_wrap_struct(ca->data);