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
  carray_access.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
 
@@ -208,7 +206,7 @@ rb_ca_fetch_addr (VALUE self, ca_size_t addr)
208
206
  return out;
209
207
  }
210
208
 
211
- /* rdoc:
209
+ /* yard:
212
210
  class CArray
213
211
  def fill
214
212
  end
@@ -293,7 +291,7 @@ ary_guess_shape (VALUE ary, int level, int *max_level, ca_size_t *dim)
293
291
  }
294
292
  }
295
293
 
296
- /* rdoc:
294
+ /* yard:
297
295
  def CArray.guess_array_shape (arg)
298
296
  end
299
297
  */
@@ -380,11 +378,11 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
380
378
  }
381
379
  else {
382
380
  same_shape = 1;
383
- if ( max_level+1 < ca->rank ) {
381
+ if ( max_level+1 < ca->ndim ) {
384
382
  same_shape = 0;
385
383
  }
386
384
  else {
387
- for (i=0; i<ca->rank; i++) {
385
+ for (i=0; i<ca->ndim; i++) {
388
386
  if ( ca->dim[i] != dim[i] ) {
389
387
  same_shape = 0;
390
388
  break;
@@ -395,7 +393,7 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
395
393
  if ( same_shape ) {
396
394
  VALUE out = rb_ary_new2(0);
397
395
  int len = 0;
398
- ary_flatten_upto_level(ary, ca->rank-1, 0, out, &len);
396
+ ary_flatten_upto_level(ary, ca->ndim-1, 0, out, &len);
399
397
 
400
398
  if ( len != elements ) {
401
399
  return Qnil;
@@ -443,12 +441,12 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
443
441
  }
444
442
 
445
443
  void
446
- rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
444
+ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
447
445
  long argc, VALUE *argv, CAIndexInfo *info)
448
446
  {
449
447
  int32_t i;
450
448
 
451
- info->rank = 0;
449
+ info->ndim = 0;
452
450
  info->select = NULL;
453
451
 
454
452
  if ( argc == 0 ) { /* ca[] -> CA_REG_ALL */
@@ -481,7 +479,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
481
479
  Data_Get_Struct(arg, CArray, cs);
482
480
  if ( ca_is_integer_type(cs) ) {
483
481
  #if 0
484
- if ( ca_rank == 1 && cs->rank == 1 ) { /* ca[g] -> CA_REG_GRID (1d) */
482
+ if ( ca_ndim == 1 && cs->ndim == 1 ) { /* ca[g] -> CA_REG_GRID (1d) */
485
483
  info->type = CA_REG_GRID;
486
484
  }
487
485
  else { /* ca[m] -> CA_REG_MAPPER (2d...) */
@@ -527,13 +525,15 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
527
525
  return;
528
526
  }
529
527
 
530
- if ( ca_rank > 1 ) { /* ca.rank > 1 */
528
+ if ( ca_ndim > 1 ) { /* ca.ndim > 1 */
531
529
  if ( rb_obj_is_kind_of(arg, rb_cInteger) ) { /* ca[n] -> CA_REG_ADDRESS */
532
530
  ca_size_t addr;
533
531
  info->type = CA_REG_ADDRESS;
534
- info->rank = 1;
532
+ info->ndim = 1;
535
533
  addr = NUM2SIZE(arg);
536
- CA_CHECK_INDEX(addr, ca_elements);
534
+ if ( info->range_check ) {
535
+ CA_CHECK_INDEX(addr, ca_elements);
536
+ }
537
537
  info->index[0].scalar = addr;
538
538
  return;
539
539
  }
@@ -569,21 +569,21 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
569
569
 
570
570
  if ( argv[i] == Qfalse ) { /* ca[--,false,--] (rubber dimension) */
571
571
  has_rubber = 1;
572
- if ( argc > ca_rank + 1 ) {
572
+ if ( argc > ca_ndim + 1 ) {
573
573
  rb_raise(rb_eIndexError,
574
- "index specification exceeds the rank of carray (%i)",
575
- ca_rank);
574
+ "index specification exceeds the ndim of carray (%i)",
575
+ ca_ndim);
576
576
  }
577
577
  }
578
578
  }
579
579
 
580
- if ( ! has_rubber && ca_rank != argc ) {
580
+ if ( ! has_rubber && ca_ndim != argc ) {
581
581
  rb_raise(rb_eIndexError,
582
- "number of indices exceeds the rank of carray (%i > %i)",
583
- (int) argc, ca_rank);
582
+ "number of indices exceeds the ndim of carray (%i > %i)",
583
+ (int) argc, ca_ndim);
584
584
  }
585
585
 
586
- info->rank = argc;
586
+ info->ndim = argc;
587
587
 
588
588
  for (i=0; i<argc; i++) {
589
589
  volatile VALUE arg = argv[i];
@@ -594,22 +594,24 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
594
594
  ca_size_t scalar;
595
595
  index_type[i] = CA_IDX_SCALAR;
596
596
  scalar = NUM2SIZE(arg);
597
- CA_CHECK_INDEX_AT(scalar, ca_dim[i], i);
597
+ if ( info->range_check ) {
598
+ CA_CHECK_INDEX_AT(scalar, ca_dim[i], i);
599
+ }
598
600
  index[i].scalar = scalar;
599
601
  }
600
602
  else if ( NIL_P(arg) ) { /* ca[--,nil,--] */
601
603
  index_type[i] = CA_IDX_ALL;
602
604
  }
603
605
  else if ( arg == Qfalse ) { /* ca[--,false,--] */
604
- int8_t rrank = ca_rank - argc + 1;
606
+ int8_t rndim = ca_ndim - argc + 1;
605
607
  int8_t j;
606
- for (j=0; j<rrank; j++) {
608
+ for (j=0; j<rndim; j++) {
607
609
  index_type[i+j] = CA_IDX_ALL;
608
610
  }
609
- i += rrank-1;
610
- argv -= rrank-1;
611
- argc = ca_rank;
612
- info->rank = ca_rank;
611
+ i += rndim-1;
612
+ argv -= rndim-1;
613
+ argc = ca_ndim;
614
+ info->ndim = ca_ndim;
613
615
  }
614
616
  else if ( rb_obj_is_kind_of(arg, rb_cRange) ) { /* ca[--,i..j,--] */
615
617
  ca_size_t first, last, excl, count, step;
@@ -631,7 +633,10 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
631
633
  last = NUM2SIZE(iv_end);
632
634
  }
633
635
  excl = RTEST(iv_excl);
634
- CA_CHECK_INDEX_AT(first, ca_dim[i], i);
636
+
637
+ if ( info->range_check ) {
638
+ CA_CHECK_INDEX_AT(first, ca_dim[i], i);
639
+ }
635
640
 
636
641
  if ( last < 0 ) { /* don't use CA_CHECK_INDEX for excl */
637
642
  last += ca_dim[i];
@@ -645,10 +650,12 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
645
650
  if ( excl ) {
646
651
  last += ( (last>=first) ? -1 : 1 );
647
652
  }
648
- if ( last < 0 || last >= ca_dim[i] ) {
649
- rb_raise(rb_eIndexError,
650
- "index %lld is out of range (0..%lld) at %i-dim",
651
- (ca_size_t) last, (ca_size_t) (ca_dim[i]-1), i);
653
+ if ( info->range_check ) {
654
+ if ( last < 0 || last >= ca_dim[i] ) {
655
+ rb_raise(rb_eIndexError,
656
+ "index %lld is out of range (0..%lld) at %i-dim",
657
+ (ca_size_t) last, (ca_size_t) (ca_dim[i]-1), i);
658
+ }
652
659
  }
653
660
  index[i].block.start = first;
654
661
  index[i].block.count = count = llabs(last - first) + 1;
@@ -827,10 +834,10 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
827
834
  }
828
835
  }
829
836
 
830
- if ( ca_rank != info->rank ) {
837
+ if ( ca_ndim != info->ndim ) {
831
838
  rb_raise(rb_eIndexError,
832
- "number of indices does not equal to the rank (%i != %i)",
833
- info->rank, ca_rank);
839
+ "number of indices does not equal to the ndim (%i != %i)",
840
+ info->ndim, ca_ndim);
834
841
  }
835
842
 
836
843
  is_point = 1;
@@ -838,7 +845,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
838
845
  is_iterator = 0;
839
846
  is_grid = 0;
840
847
 
841
- for (i=0; i<info->rank; i++) {
848
+ for (i=0; i<info->ndim; i++) {
842
849
  switch ( info->index_type[i] ) {
843
850
  case CA_IDX_SCALAR:
844
851
  is_all = 0;
@@ -880,7 +887,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
880
887
  }
881
888
 
882
889
  if ( info->type == CA_REG_ITERATOR ) {
883
- for (i=0; i<info->rank; i++) {
890
+ for (i=0; i<info->ndim; i++) {
884
891
  if ( info->index_type[i] == CA_IDX_SCALAR ) {
885
892
  ca_size_t start = info->index[i].scalar;
886
893
  info->index_type[i] = CA_IDX_BLOCK;
@@ -928,7 +935,7 @@ rb_ca_ref_point (VALUE self, CAIndexInfo *info)
928
935
  ca_size_t idx[CA_RANK_MAX];
929
936
  int8_t i;
930
937
  Data_Get_Struct(self, CArray, ca);
931
- for (i=0; i<ca->rank; i++) {
938
+ for (i=0; i<ca->ndim; i++) {
932
939
  idx[i] = info->index[i].scalar;
933
940
  }
934
941
  return rb_ca_fetch_index(self, idx);
@@ -941,7 +948,7 @@ rb_ca_store_point (VALUE self, CAIndexInfo *info, volatile VALUE val)
941
948
  ca_size_t idx[CA_RANK_MAX];
942
949
  int8_t i;
943
950
  Data_Get_Struct(self, CArray, ca);
944
- for (i=0; i<ca->rank; i++) {
951
+ for (i=0; i<ca->ndim; i++) {
945
952
  idx[i] = info->index[i].scalar;
946
953
  }
947
954
  if ( rb_obj_is_cscalar(val) ) {
@@ -1071,7 +1078,7 @@ rb_ca_store_all (VALUE self, VALUE rval)
1071
1078
  }
1072
1079
 
1073
1080
  static void
1074
- rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1081
+ rb_ca_index_restruct_block (int16_t *ndimp, ca_size_t *shrink, ca_size_t *dim,
1075
1082
  ca_size_t *start, ca_size_t *step, ca_size_t *count,
1076
1083
  ca_size_t *offsetp)
1077
1084
  {
@@ -1080,31 +1087,31 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1080
1087
  ca_size_t step0[CA_RANK_MAX];
1081
1088
  ca_size_t count0[CA_RANK_MAX];
1082
1089
  ca_size_t idx[CA_RANK_MAX];
1083
- int16_t rank0, rank;
1090
+ int16_t ndim0, ndim;
1084
1091
  ca_size_t offset0, offset, length;
1085
1092
  ca_size_t k, n;
1086
1093
  ca_size_t i, j, m;
1087
1094
 
1088
- rank0 = *rankp;
1095
+ ndim0 = *ndimp;
1089
1096
  offset0 = *offsetp;
1090
1097
 
1091
1098
  /* store original start, step, count to start0, step0, count0 */
1092
- memcpy(dim0, dim, sizeof(ca_size_t) * rank0);
1093
- memcpy(start0, start, sizeof(ca_size_t) * rank0);
1094
- memcpy(step0, step, sizeof(ca_size_t) * rank0);
1095
- memcpy(count0, count, sizeof(ca_size_t) * rank0);
1099
+ memcpy(dim0, dim, sizeof(ca_size_t) * ndim0);
1100
+ memcpy(start0, start, sizeof(ca_size_t) * ndim0);
1101
+ memcpy(step0, step, sizeof(ca_size_t) * ndim0);
1102
+ memcpy(count0, count, sizeof(ca_size_t) * ndim0);
1096
1103
 
1097
- /* classify and calc rank */
1104
+ /* classify and calc ndim */
1098
1105
  n = -1;
1099
- for (i=0; i<rank0; i++) {
1106
+ for (i=0; i<ndim0; i++) {
1100
1107
  if ( ! shrink[i] ) {
1101
1108
  n += 1;
1102
1109
  }
1103
1110
  idx[i] = n;
1104
1111
  }
1105
- rank = n + 1;
1112
+ ndim = n + 1;
1106
1113
 
1107
- *rankp = rank;
1114
+ *ndimp = ndim;
1108
1115
 
1109
1116
  /* calc offset */
1110
1117
 
@@ -1122,7 +1129,7 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1122
1129
  }
1123
1130
 
1124
1131
  length = 1;
1125
- for (i=j; i<rank0; i++) {
1132
+ for (i=j; i<ndim0; i++) {
1126
1133
  length *= dim0[i];
1127
1134
  }
1128
1135
 
@@ -1133,13 +1140,13 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1133
1140
 
1134
1141
  /* calc dim, start, step, count */
1135
1142
 
1136
- for (i=0; i<rank0; i++) {
1143
+ for (i=0; i<ndim0; i++) {
1137
1144
  n = idx[i];
1138
1145
  if ( n == -1) {
1139
1146
  continue;
1140
1147
  }
1141
1148
 
1142
- for (j=i+1, m=i; j<rank0 && (idx[j] == n); j++) {
1149
+ for (j=i+1, m=i; j<ndim0 && (idx[j] == n); j++) {
1143
1150
  ;
1144
1151
  }
1145
1152
 
@@ -1172,7 +1179,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1172
1179
  ca_size_t step[CA_RANK_MAX];
1173
1180
  ca_size_t count[CA_RANK_MAX];
1174
1181
  ca_size_t shrink[CA_RANK_MAX];
1175
- int16_t rank = 0;
1182
+ int16_t ndim = 0;
1176
1183
  ca_size_t offset = 0;
1177
1184
  ca_size_t flag = 0;
1178
1185
  ca_size_t elements;
@@ -1180,10 +1187,10 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1180
1187
 
1181
1188
  Data_Get_Struct(self, CArray, ca);
1182
1189
 
1183
- rank = info->rank;
1190
+ ndim = info->ndim;
1184
1191
 
1185
1192
  elements = 1;
1186
- for (i=0; i<info->rank; i++) {
1193
+ for (i=0; i<info->ndim; i++) {
1187
1194
  dim[i] = ca->dim[i];
1188
1195
  switch ( info->index_type[i] ) {
1189
1196
  case CA_IDX_SCALAR:
@@ -1200,7 +1207,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1200
1207
  }
1201
1208
  }
1202
1209
 
1203
- for (i=0; i<info->rank; i++) {
1210
+ for (i=0; i<info->ndim; i++) {
1204
1211
  switch ( info->index_type[i] ) {
1205
1212
  case CA_IDX_SCALAR:
1206
1213
  start[i] = info->index[i].scalar;
@@ -1223,7 +1230,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1223
1230
  }
1224
1231
  }
1225
1232
 
1226
- for (i=0; i<rank; i++) {
1233
+ for (i=0; i<ndim; i++) {
1227
1234
  if ( shrink[i] ) {
1228
1235
  flag = 1;
1229
1236
  break;
@@ -1231,16 +1238,16 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1231
1238
  }
1232
1239
 
1233
1240
  refer = self;
1234
- rank = ca->rank;
1241
+ ndim = ca->ndim;
1235
1242
 
1236
1243
  offset = 0;
1237
1244
 
1238
1245
  if ( flag ) {
1239
- rb_ca_index_restruct_block(&rank, shrink,
1246
+ rb_ca_index_restruct_block(&ndim, shrink,
1240
1247
  dim, start, step, count, &offset);
1241
1248
  }
1242
1249
 
1243
- return rb_ca_block_new(refer, rank, dim, start, step, count, offset);
1250
+ return rb_ca_block_new(refer, ndim, dim, start, step, count, offset);
1244
1251
  }
1245
1252
 
1246
1253
  static VALUE
@@ -1254,7 +1261,7 @@ rb_ca_refer_new_flatten (VALUE self)
1254
1261
  return rb_ca_refer_new(self, ca->data_type, 1, &dim0, ca->bytes, 0);
1255
1262
  }
1256
1263
 
1257
- /* rdoc:
1264
+ /* yard:
1258
1265
  class CArray
1259
1266
  def [] (*spec)
1260
1267
  end
@@ -1271,7 +1278,9 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1271
1278
  retry:
1272
1279
 
1273
1280
  Data_Get_Struct(self, CArray, ca);
1274
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements, argc, argv, &info);
1281
+
1282
+ info.range_check = 1;
1283
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
1275
1284
 
1276
1285
  switch ( info.type ) {
1277
1286
  case CA_REG_ADDRESS_COMPLEX:
@@ -1340,7 +1349,86 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1340
1349
  return obj;
1341
1350
  }
1342
1351
 
1343
- /* rdoc:
1352
+ static VALUE
1353
+ rb_cs_fetch_method (int argc, VALUE *argv, VALUE self)
1354
+ {
1355
+ volatile VALUE obj = Qnil;
1356
+ CArray *ca;
1357
+ CAIndexInfo info;
1358
+
1359
+ Data_Get_Struct(self, CArray, ca);
1360
+
1361
+ info.range_check = 0;
1362
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
1363
+
1364
+ switch ( info.type ) {
1365
+ case CA_REG_ADDRESS_COMPLEX:
1366
+ obj = rb_ca_fetch_addr(self, 0);
1367
+ break;
1368
+ case CA_REG_ADDRESS:
1369
+ obj = rb_ca_fetch_addr(self, 0);
1370
+ break;
1371
+ case CA_REG_FLATTEN:
1372
+ obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
1373
+ break;
1374
+ case CA_REG_POINT:
1375
+ obj = rb_ca_fetch_addr(self, 0);
1376
+ break;
1377
+ case CA_REG_ALL:
1378
+ obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
1379
+ break;
1380
+ case CA_REG_BLOCK:
1381
+ obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
1382
+ break;
1383
+ case CA_REG_SELECT:
1384
+ obj = rb_ca_select_new(self, argv[0]);
1385
+ break;
1386
+ case CA_REG_ITERATOR:
1387
+ obj = rb_dim_iter_new(self, &info);
1388
+ break;
1389
+ case CA_REG_REPEAT:
1390
+ obj = rb_ca_repeat(argc, argv, self);
1391
+ break;
1392
+ case CA_REG_UNBOUND_REPEAT:
1393
+ obj = rb_funcall2(self, rb_intern("unbound_repeat"), (int) argc, argv);
1394
+ break;
1395
+ case CA_REG_MAPPING:
1396
+ obj = rb_ca_mapping(argc, argv, self);
1397
+ break;
1398
+ case CA_REG_GRID:
1399
+ obj = rb_ca_grid(argc, argv, self);
1400
+ break;
1401
+ case CA_REG_METHOD_CALL: {
1402
+ volatile VALUE idx;
1403
+ idx = rb_funcall2(self, SYM2ID(info.symbol), argc-1, argv+1);
1404
+ obj = rb_ca_fetch(self, idx);
1405
+ break;
1406
+ }
1407
+ case CA_REG_MEMBER: {
1408
+ volatile VALUE data_class = rb_ca_data_class(self);
1409
+ if ( ! NIL_P(data_class) ) {
1410
+ obj = rb_ca_field_as_member(self, info.symbol);
1411
+ break;
1412
+ }
1413
+ else {
1414
+ rb_raise(rb_eIndexError,
1415
+ "can't refer member of carray doesn't have data_class");
1416
+ }
1417
+ break;
1418
+ }
1419
+ case CA_REG_ATTRIBUTE: {
1420
+ obj = rb_funcall(self, rb_intern("attribute"), 0);
1421
+ obj = rb_hash_aref(obj, info.symbol);
1422
+ break;
1423
+ }
1424
+ default:
1425
+ rb_raise(rb_eIndexError, "invalid index specified");
1426
+ }
1427
+
1428
+ return obj;
1429
+ }
1430
+
1431
+ /* yard:
1344
1432
  class CArray
1345
1433
  def []= (*spec)
1346
1434
  end
@@ -1363,7 +1451,8 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
1363
1451
 
1364
1452
  Data_Get_Struct(self, CArray, ca);
1365
1453
 
1366
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements, argc, argv, &info);
1454
+ info.range_check = 1;
1455
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
1367
1456
 
1368
1457
  switch ( info.type ) {
1369
1458
  case CA_REG_ADDRESS_COMPLEX:
@@ -1487,7 +1576,7 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
1487
1576
  return rb_ca_store_method((int)RARRAY_LEN(index), RARRAY_PTR(index), self);
1488
1577
  }
1489
1578
 
1490
- /* rdoc:
1579
+ /* yard:
1491
1580
  def CArray.scan_index(dim, idx)
1492
1581
  end
1493
1582
  */
@@ -1495,9 +1584,9 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
1495
1584
  static VALUE
1496
1585
  rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1497
1586
  {
1498
- volatile VALUE rtype, rrank, rindex;
1587
+ volatile VALUE rtype, rndim, rindex;
1499
1588
  CAIndexInfo info;
1500
- int rank;
1589
+ int ndim;
1501
1590
  ca_size_t dim[CA_RANK_MAX];
1502
1591
  ca_size_t elements;
1503
1592
  int i;
@@ -1506,21 +1595,22 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1506
1595
  Check_Type(ridx, T_ARRAY);
1507
1596
 
1508
1597
  elements = 1;
1509
- rank = (int) RARRAY_LEN(rdim);
1510
- for (i=0; i<rank; i++) {
1598
+ ndim = (int) RARRAY_LEN(rdim);
1599
+ for (i=0; i<ndim; i++) {
1511
1600
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
1512
1601
  elements *= dim[i];
1513
1602
  }
1514
1603
 
1515
- CA_CHECK_RANK(rank);
1516
- CA_CHECK_DIM(rank, dim);
1604
+ CA_CHECK_RANK(ndim);
1605
+ CA_CHECK_DIM(ndim, dim);
1517
1606
 
1518
- rb_ca_scan_index(rank, dim, elements,
1607
+ info.range_check = 1;
1608
+ rb_ca_scan_index(ndim, dim, elements,
1519
1609
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1520
1610
 
1521
1611
  rtype = INT2NUM(info.type);
1522
- rrank = INT2NUM(info.rank);
1523
- rindex = rb_ary_new2(info.rank);
1612
+ rndim = INT2NUM(info.ndim);
1613
+ rindex = rb_ary_new2(info.ndim);
1524
1614
 
1525
1615
  switch ( info.type ) {
1526
1616
  case CA_REG_NONE:
@@ -1534,7 +1624,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1534
1624
  case CA_REG_ADDRESS_COMPLEX: {
1535
1625
  volatile VALUE rinfo;
1536
1626
  ca_size_t elements = 1;
1537
- for (i=0; i<rank; i++) {
1627
+ for (i=0; i<ndim; i++) {
1538
1628
  elements *= dim[i];
1539
1629
  }
1540
1630
  rinfo = rb_ca_s_scan_index(self, rb_ary_new3(1, SIZE2NUM(elements)), ridx);
@@ -1543,7 +1633,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1543
1633
  break;
1544
1634
  }
1545
1635
  case CA_REG_POINT:
1546
- for (i=0; i<rank; i++) {
1636
+ for (i=0; i<ndim; i++) {
1547
1637
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1548
1638
  }
1549
1639
  break;
@@ -1551,7 +1641,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1551
1641
  break;
1552
1642
  case CA_REG_BLOCK:
1553
1643
  case CA_REG_ITERATOR:
1554
- for (i=0; i<rank; i++) {
1644
+ for (i=0; i<ndim; i++) {
1555
1645
  switch ( info.index_type[i] ) {
1556
1646
  case CA_IDX_SCALAR:
1557
1647
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1596,7 +1686,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1596
1686
  return rb_struct_new(S_CAInfo, rtype, rindex);
1597
1687
  }
1598
1688
 
1599
- /* rdoc:
1689
+ /* yard:
1600
1690
  class CArray
1601
1691
  def normalize_index (idx)
1602
1692
  end
@@ -1614,26 +1704,27 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
1614
1704
  Data_Get_Struct(self, CArray, ca);
1615
1705
  Check_Type(ridx, T_ARRAY);
1616
1706
 
1617
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements,
1707
+ info.range_check = 1;
1708
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements,
1618
1709
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1619
1710
 
1620
1711
  switch ( info.type ) {
1621
1712
  case CA_REG_ALL:
1622
1713
  case CA_REG_SELECT:
1623
1714
  case CA_REG_ADDRESS:
1624
- rindex = rb_ary_new2(info.rank);
1715
+ rindex = rb_ary_new2(info.ndim);
1625
1716
  rb_ary_store(rindex, 0, SIZE2NUM(info.index[0].scalar));
1626
1717
  return rindex;
1627
1718
  case CA_REG_POINT:
1628
- rindex = rb_ary_new2(info.rank);
1629
- for (i=0; i<ca->rank; i++) {
1719
+ rindex = rb_ary_new2(info.ndim);
1720
+ for (i=0; i<ca->ndim; i++) {
1630
1721
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1631
1722
  }
1632
1723
  return rindex;
1633
1724
  case CA_REG_BLOCK:
1634
1725
  case CA_REG_ITERATOR:
1635
- rindex = rb_ary_new2(info.rank);
1636
- for (i=0; i<ca->rank; i++) {
1726
+ rindex = rb_ary_new2(info.ndim);
1727
+ for (i=0; i<ca->ndim; i++) {
1637
1728
  switch ( info.index_type[i] ) {
1638
1729
  case CA_IDX_SCALAR:
1639
1730
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1668,7 +1759,7 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
1668
1759
 
1669
1760
  /* ------------------------------------------------------------------- */
1670
1761
 
1671
- /* rdoc:
1762
+ /* yard:
1672
1763
  class CArray
1673
1764
  # converts addr to index
1674
1765
  def addr2index (addr)
@@ -1694,8 +1785,8 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
1694
1785
  (ca_size_t) addr, (ca_size_t) (ca->elements-1));
1695
1786
  }
1696
1787
  dim = ca->dim;
1697
- out = rb_ary_new2(ca->rank);
1698
- for (i=ca->rank-1; i>=0; i--) { /* in descending order */
1788
+ out = rb_ary_new2(ca->ndim);
1789
+ for (i=ca->ndim-1; i>=0; i--) { /* in descending order */
1699
1790
  rb_ary_store(out, i, SIZE2NUM(addr % dim[i]));
1700
1791
  addr /= dim[i];
1701
1792
  }
@@ -1703,7 +1794,7 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
1703
1794
  return out;
1704
1795
  }
1705
1796
 
1706
- /* rdoc:
1797
+ /* yard:
1707
1798
  class CArray
1708
1799
  def index2addr (*index)
1709
1800
  end
@@ -1725,11 +1816,11 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1725
1816
 
1726
1817
  Data_Get_Struct(self, CArray, ca);
1727
1818
 
1728
- if ( argc != ca->rank ) {
1729
- rb_raise(rb_eRuntimeError, "invalid rank of index");
1819
+ if ( argc != ca->ndim ) {
1820
+ rb_raise(rb_eRuntimeError, "invalid ndim of index");
1730
1821
  }
1731
1822
 
1732
- for (i=0; i<ca->rank; i++) {
1823
+ for (i=0; i<ca->ndim; i++) {
1733
1824
  if ( ! rb_obj_is_kind_of(argv[i], rb_cInteger) ) {
1734
1825
  all_number = 0;
1735
1826
  break;
@@ -1739,7 +1830,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1739
1830
  if ( all_number ) {
1740
1831
  dim = ca->dim;
1741
1832
  addr = 0;
1742
- for (i=0; i<ca->rank; i++) {
1833
+ for (i=0; i<ca->ndim; i++) {
1743
1834
  k = NUM2SIZE(argv[i]);
1744
1835
  CA_CHECK_INDEX(k, dim[i]);
1745
1836
  addr = dim[i] * addr + k;
@@ -1748,7 +1839,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1748
1839
  }
1749
1840
 
1750
1841
  elements = 1;
1751
- for (i=0; i<ca->rank; i++) {
1842
+ for (i=0; i<ca->ndim; i++) {
1752
1843
  cidx[i] = ca_wrap_readonly(argv[i], CA_SIZE);
1753
1844
  if ( ! ca_is_scalar(cidx[i]) ) {
1754
1845
  if ( elements == 1 ) {
@@ -1760,7 +1851,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1760
1851
  }
1761
1852
  }
1762
1853
 
1763
- for (i=0; i<ca->rank; i++) {
1854
+ for (i=0; i<ca->ndim; i++) {
1764
1855
  ca_attach(cidx[i]);
1765
1856
  ca_set_iterator(1, cidx[i], &p[i], &s[i]);
1766
1857
  }
@@ -1770,7 +1861,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1770
1861
 
1771
1862
  q = (ca_size_t *) co->ptr;
1772
1863
 
1773
- ca_copy_mask_overwrite_n(co, elements, ca->rank, cidx);
1864
+ ca_copy_mask_overwrite_n(co, elements, ca->ndim, cidx);
1774
1865
  m = ( co->mask ) ? (boolean8_t *) co->mask->ptr : NULL;
1775
1866
 
1776
1867
  dim = ca->dim;
@@ -1780,7 +1871,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1780
1871
  while ( n-- ) {
1781
1872
  if ( !*m ) {
1782
1873
  addr = 0;
1783
- for (i=0; i<ca->rank; i++) {
1874
+ for (i=0; i<ca->ndim; i++) {
1784
1875
  k = *(p[i]);
1785
1876
  p[i]+=s[i];
1786
1877
  CA_CHECK_INDEX(k, dim[i]);
@@ -1789,7 +1880,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1789
1880
  *q = addr;
1790
1881
  }
1791
1882
  else {
1792
- for (i=0; i<ca->rank; i++) {
1883
+ for (i=0; i<ca->ndim; i++) {
1793
1884
  p[i]+=s[i];
1794
1885
  }
1795
1886
  }
@@ -1800,7 +1891,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1800
1891
  n = elements;
1801
1892
  while ( n-- ) {
1802
1893
  addr = 0;
1803
- for (i=0; i<ca->rank; i++) {
1894
+ for (i=0; i<ca->ndim; i++) {
1804
1895
  k = *(p[i]);
1805
1896
  p[i]+=s[i];
1806
1897
  CA_CHECK_INDEX(k, dim[i]);
@@ -1811,7 +1902,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1811
1902
  }
1812
1903
  }
1813
1904
 
1814
- for (i=0; i<ca->rank; i++) {
1905
+ for (i=0; i<ca->ndim; i++) {
1815
1906
  ca_detach(cidx[i]);
1816
1907
  }
1817
1908
 
@@ -1838,6 +1929,8 @@ Init_carray_access ()
1838
1929
  rb_define_method(rb_cCArray, "[]", rb_ca_fetch_method, -1);
1839
1930
  rb_define_method(rb_cCArray, "[]=", rb_ca_store_method, -1);
1840
1931
 
1932
+ rb_define_method(rb_cCScalar, "[]", rb_cs_fetch_method, -1);
1933
+
1841
1934
  rb_define_method(rb_cCArray, "fill", rb_ca_fill, 1);
1842
1935
  rb_define_method(rb_cCArray, "fill_copy", rb_ca_fill_copy, 1);
1843
1936