carray 1.3.6 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/LICENSE +22 -0
  4. data/NEWS.md +65 -0
  5. data/README.md +23 -26
  6. data/Rakefile +31 -0
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +24 -31
  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} +38 -40
  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} +90 -59
  31. data/{carray_access.c → ext/carray_access.c} +244 -109
  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} +350 -149
  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} +58 -70
  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} +137 -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} +95 -114
  46. data/{carray_math.rb → ext/carray_math.rb} +47 -31
  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} +72 -36
  50. data/{carray_order.c → ext/carray_order.c} +73 -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} +59 -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} +1 -6
  58. data/{mkmath.rb → ext/mkmath.rb} +13 -3
  59. data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
  60. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +1 -3
  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 +52 -10
  65. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -8
  66. data/lib/carray/autoload/autoload_base.rb +1 -5
  67. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  68. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  69. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  70. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  71. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  72. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  73. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  74. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  75. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  76. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  77. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  78. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  79. data/lib/carray/basic.rb +191 -0
  80. data/lib/carray/broadcast.rb +82 -0
  81. data/lib/carray/compose.rb +315 -0
  82. data/lib/carray/construct.rb +460 -0
  83. data/lib/carray/convert.rb +115 -0
  84. data/lib/carray/info.rb +1 -3
  85. data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
  86. data/lib/carray/io/imagemagick.rb +2 -4
  87. data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
  88. data/lib/carray/mask.rb +102 -0
  89. data/lib/carray/{base/math.rb → math.rb} +21 -53
  90. data/lib/carray/math/histogram.rb +8 -10
  91. data/lib/carray/math/recurrence.rb +1 -3
  92. data/lib/carray/mkmf.rb +9 -3
  93. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  94. data/lib/carray/object/ca_obj_link.rb +1 -3
  95. data/lib/carray/object/ca_obj_pack.rb +9 -11
  96. data/lib/carray/obsolete.rb +270 -0
  97. data/lib/carray/ordering.rb +181 -0
  98. data/lib/carray/{base/serialize.rb → serialize.rb} +50 -66
  99. data/lib/carray/string.rb +188 -0
  100. data/lib/carray/{base/struct.rb → struct.rb} +19 -21
  101. data/lib/carray/{io/table.rb → table.rb} +1 -9
  102. data/lib/carray/testing.rb +51 -0
  103. data/lib/carray/time.rb +76 -0
  104. data/lib/carray/transform.rb +98 -0
  105. data/misc/Methods.ja.md +182 -0
  106. data/{NOTE → misc/NOTE} +0 -0
  107. data/spec/Classes/CABitfield_spec.rb +58 -0
  108. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  109. data/spec/Classes/CABlock_spec.rb +205 -0
  110. data/spec/Classes/CAField_spec.rb +39 -0
  111. data/spec/Classes/CAGrid_spec.rb +75 -0
  112. data/spec/Classes/CAMap_spec.rb +0 -0
  113. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  114. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  115. data/spec/Classes/CAObject_spec.rb +33 -0
  116. data/spec/Classes/CARefer_spec.rb +93 -0
  117. data/spec/Classes/CARepeat_spec.rb +65 -0
  118. data/spec/Classes/CASelect_spec.rb +22 -0
  119. data/spec/Classes/CAShift_spec.rb +16 -0
  120. data/spec/Classes/CAStruct_spec.rb +71 -0
  121. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  122. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  123. data/spec/Classes/CAWindow_spec.rb +54 -0
  124. data/spec/Classes/CAWrap_spec.rb +8 -0
  125. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  126. data/spec/Classes/CScalar_spec.rb +55 -0
  127. data/spec/Features/feature_130_spec.rb +19 -0
  128. data/spec/Features/feature_attributes_spec.rb +280 -0
  129. data/spec/Features/feature_boolean_spec.rb +98 -0
  130. data/spec/Features/feature_broadcast.rb +116 -0
  131. data/spec/Features/feature_cast_function.rb +19 -0
  132. data/spec/Features/feature_cast_spec.rb +33 -0
  133. data/spec/Features/feature_class_spec.rb +84 -0
  134. data/spec/Features/feature_complex_spec.rb +42 -0
  135. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  136. data/spec/Features/feature_convert_spec.rb +46 -0
  137. data/spec/Features/feature_copy_spec.rb +123 -0
  138. data/spec/Features/feature_creation_spec.rb +84 -0
  139. data/spec/Features/feature_element_spec.rb +144 -0
  140. data/spec/Features/feature_extream_spec.rb +54 -0
  141. data/spec/Features/feature_generate_spec.rb +74 -0
  142. data/spec/Features/feature_index_spec.rb +69 -0
  143. data/spec/Features/feature_mask_spec.rb +580 -0
  144. data/spec/Features/feature_math_spec.rb +97 -0
  145. data/spec/Features/feature_order_spec.rb +146 -0
  146. data/spec/Features/feature_ref_store_spec.rb +209 -0
  147. data/spec/Features/feature_serialization_spec.rb +125 -0
  148. data/spec/Features/feature_stat_spec.rb +397 -0
  149. data/spec/Features/feature_virtual_spec.rb +48 -0
  150. data/spec/Features/method_eq_spec.rb +81 -0
  151. data/spec/Features/method_is_nan_spec.rb +12 -0
  152. data/spec/Features/method_map_spec.rb +54 -0
  153. data/spec/Features/method_max_with.rb +20 -0
  154. data/spec/Features/method_min_with.rb +19 -0
  155. data/spec/Features/method_ne_spec.rb +18 -0
  156. data/spec/Features/method_project_spec.rb +188 -0
  157. data/spec/Features/method_ref_spec.rb +27 -0
  158. data/spec/Features/method_round_spec.rb +11 -0
  159. data/spec/Features/method_s_linspace_spec.rb +48 -0
  160. data/spec/Features/method_s_span_spec.rb +14 -0
  161. data/spec/Features/method_seq_spec.rb +47 -0
  162. data/spec/Features/method_sort_with.rb +43 -0
  163. data/spec/Features/method_sorted_with.rb +29 -0
  164. data/spec/Features/method_span_spec.rb +42 -0
  165. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  166. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  167. data/spec/spec_all.rb +0 -1
  168. data/utils/convert_test.rb +73 -0
  169. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  170. data/{devel → utils}/guess_shape.rb +0 -0
  171. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  172. metadata +173 -316
  173. data/COPYING +0 -56
  174. data/GPL +0 -340
  175. data/Gemfile +0 -8
  176. data/Gemfile.lock +0 -33
  177. data/LEGAL +0 -50
  178. data/Makefile +0 -451
  179. data/TODO +0 -5
  180. data/carray_cast_func.c +0 -8670
  181. data/carray_config.h +0 -26
  182. data/carray_math.c +0 -24805
  183. data/carray_random.c +0 -531
  184. data/carray_stat_proc.c +0 -12170
  185. data/ext/calculus/carray_calculus.c +0 -931
  186. data/ext/calculus/carray_interp.c +0 -358
  187. data/ext/calculus/extconf.rb +0 -12
  188. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  189. data/ext/calculus/lib/math/calculus.rb +0 -119
  190. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  191. data/ext/fortio/extconf.rb +0 -3
  192. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  193. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  194. data/ext/fortio/lib/fortio.rb +0 -3
  195. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  196. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  197. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  198. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  199. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  200. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  201. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  202. data/ext/fortio/ruby_fortio.c +0 -182
  203. data/ext/fortio/test/test_H.rb +0 -5
  204. data/ext/fortio/test/test_T.rb +0 -7
  205. data/ext/fortio/test/test_fortran_format.rb +0 -86
  206. data/ext/fortio/test/test_namelist.rb +0 -25
  207. data/ext/fortio/test/test_namelist_write.rb +0 -10
  208. data/ext/fortio/test/test_sequential.rb +0 -13
  209. data/ext/fortio/test/test_sequential2.rb +0 -13
  210. data/ext/fortio/work/test.rb +0 -10
  211. data/ext/fortio/work/test_e.rb +0 -19
  212. data/ext/fortio/work/test_ep.rb +0 -10
  213. data/ext/fortio/work/test_parse.rb +0 -12
  214. data/ext/imagemap/carray_imagemap.c +0 -495
  215. data/ext/imagemap/doc/call_graph.dot +0 -28
  216. data/ext/imagemap/draw.c +0 -567
  217. data/ext/imagemap/extconf.rb +0 -13
  218. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
  219. data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
  220. data/ext/imagemap/lib/image_map.rb +0 -4
  221. data/ext/imagemap/test/swath_index.rb +0 -83
  222. data/ext/imagemap/test/swath_warp.rb +0 -99
  223. data/ext/imagemap/test/test.rb +0 -23
  224. data/ext/imagemap/test/test_image.rb +0 -42
  225. data/ext/imagemap/test/test_line.rb +0 -14
  226. data/ext/imagemap/test/test_rotate.rb +0 -17
  227. data/ext/imagemap/test/test_triangle.rb +0 -20
  228. data/ext/imagemap/test/test_warp.rb +0 -26
  229. data/ext/mathfunc/extconf.rb +0 -18
  230. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  231. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  232. data/ext/mathfunc/test/test_hypot.rb +0 -5
  233. data/ext/mathfunc/test/test_j0.rb +0 -22
  234. data/ext/mathfunc/test/test_jn.rb +0 -8
  235. data/ext/mathfunc/test/test_sph.rb +0 -9
  236. data/ext/narray/README +0 -22
  237. data/ext/narray/ca_wrap_narray.c +0 -500
  238. data/ext/narray/carray_narray.c +0 -21
  239. data/ext/narray/extconf.rb +0 -57
  240. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  241. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  242. data/ext/narray/lib/math/narray.rb +0 -17
  243. data/ext/narray/lib/math/narray_miss.rb +0 -45
  244. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  245. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  246. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  247. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  248. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  249. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  250. data/lib/carray/base/basic.rb +0 -1090
  251. data/lib/carray/base/obsolete.rb +0 -131
  252. data/lib/carray/graphics/gnuplot.rb +0 -2131
  253. data/lib/carray/graphics/zimg.rb +0 -296
  254. data/lib/carray/io/csv.rb +0 -572
  255. data/lib/carray/io/pg.rb +0 -101
  256. data/lib/carray/io/sqlite3.rb +0 -215
  257. data/lib/carray/math/interp.rb +0 -57
  258. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  259. data/mkmf.log +0 -375
  260. data/mt19937ar.c +0 -182
  261. data/mt19937ar.h +0 -86
  262. data/rdoc_ext.rb +0 -1115
  263. data/rdoc_main.rb +0 -27
  264. data/rdoc_math.rb +0 -5
  265. data/rdoc_stat.rb +0 -31
  266. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  267. data/spec/CArray/bug/store_spec.rb +0 -27
  268. data/spec/CArray/index/repeat_spec.rb +0 -10
  269. data/spec/CArray/method/eq_spec.rb +0 -80
  270. data/spec/CArray/method/is_nan_spec.rb +0 -12
  271. data/spec/CArray/method/ne_spec.rb +0 -18
  272. data/spec/CArray/method/round_spec.rb +0 -11
  273. data/spec/CArray/object/_attribute_spec.rb +0 -32
  274. data/spec/CArray/object/s_new_spec.rb +0 -31
  275. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  276. data/test/test_130.rb +0 -23
  277. data/test/test_ALL.rb +0 -51
  278. data/test/test_CABitfield.rb +0 -59
  279. data/test/test_CABlock.rb +0 -208
  280. data/test/test_CAField.rb +0 -40
  281. data/test/test_CAGrid.rb +0 -76
  282. data/test/test_CAMmap.rb +0 -11
  283. data/test/test_CARefer.rb +0 -94
  284. data/test/test_CARepeat.rb +0 -66
  285. data/test/test_CASelect.rb +0 -23
  286. data/test/test_CAShift.rb +0 -17
  287. data/test/test_CAWindow.rb +0 -55
  288. data/test/test_CAWrap.rb +0 -9
  289. data/test/test_CComplex.rb +0 -83
  290. data/test/test_CScalar.rb +0 -91
  291. data/test/test_attribute.rb +0 -281
  292. data/test/test_block_iterator.rb +0 -17
  293. data/test/test_boolean.rb +0 -99
  294. data/test/test_cast.rb +0 -33
  295. data/test/test_class.rb +0 -85
  296. data/test/test_complex.rb +0 -43
  297. data/test/test_convert.rb +0 -79
  298. data/test/test_copy.rb +0 -141
  299. data/test/test_creation.rb +0 -85
  300. data/test/test_element.rb +0 -146
  301. data/test/test_extream.rb +0 -55
  302. data/test/test_generate.rb +0 -75
  303. data/test/test_index.rb +0 -71
  304. data/test/test_mask.rb +0 -578
  305. data/test/test_math.rb +0 -98
  306. data/test/test_narray.rb +0 -64
  307. data/test/test_order.rb +0 -147
  308. data/test/test_random.rb +0 -15
  309. data/test/test_ref_store.rb +0 -211
  310. data/test/test_stat.rb +0 -414
  311. data/test/test_struct.rb +0 -72
  312. data/test/test_virtual.rb +0 -49
  313. data/utils/create_rdoc.sh +0 -9
  314. data/utils/make_tgz.sh +0 -3
  315. 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...) */
@@ -510,9 +508,15 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
510
508
  }
511
509
  }
512
510
 
513
- if ( TYPE(arg) == T_STRING ) { /* ca["field"] -> CA_REG_MEMBER */
514
- info->type = CA_REG_MEMBER;
515
- info->symbol = ID2SYM(rb_intern(StringValuePtr(arg)));
511
+ if ( TYPE(arg) == T_STRING ) {
512
+ if ( StringValuePtr(arg)[0] == '@' ) { /* ca["@name"] -> CA_REG_ATTRIBUTE */
513
+ info->type = CA_REG_ATTRIBUTE;
514
+ info->symbol = rb_str_new2(StringValuePtr(arg)+1);
515
+ }
516
+ else { /* ca["field"] -> CA_REG_MEMBER */
517
+ info->type = CA_REG_MEMBER;
518
+ info->symbol = ID2SYM(rb_intern(StringValuePtr(arg)));
519
+ }
516
520
  return;
517
521
  }
518
522
 
@@ -521,13 +525,15 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
521
525
  return;
522
526
  }
523
527
 
524
- if ( ca_rank > 1 ) { /* ca.rank > 1 */
528
+ if ( ca_ndim > 1 ) { /* ca.ndim > 1 */
525
529
  if ( rb_obj_is_kind_of(arg, rb_cInteger) ) { /* ca[n] -> CA_REG_ADDRESS */
526
530
  ca_size_t addr;
527
531
  info->type = CA_REG_ADDRESS;
528
- info->rank = 1;
532
+ info->ndim = 1;
529
533
  addr = NUM2SIZE(arg);
530
- CA_CHECK_INDEX(addr, ca_elements);
534
+ if ( info->range_check ) {
535
+ CA_CHECK_INDEX(addr, ca_elements);
536
+ }
531
537
  info->index[0].scalar = addr;
532
538
  return;
533
539
  }
@@ -563,21 +569,21 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
563
569
 
564
570
  if ( argv[i] == Qfalse ) { /* ca[--,false,--] (rubber dimension) */
565
571
  has_rubber = 1;
566
- if ( argc > ca_rank + 1 ) {
572
+ if ( argc > ca_ndim + 1 ) {
567
573
  rb_raise(rb_eIndexError,
568
- "index specification exceeds the rank of carray (%i)",
569
- ca_rank);
574
+ "index specification exceeds the ndim of carray (%i)",
575
+ ca_ndim);
570
576
  }
571
577
  }
572
578
  }
573
579
 
574
- if ( ! has_rubber && ca_rank != argc ) {
580
+ if ( ! has_rubber && ca_ndim != argc ) {
575
581
  rb_raise(rb_eIndexError,
576
- "number of indices exceeds the rank of carray (%i > %i)",
577
- (int) argc, ca_rank);
582
+ "number of indices exceeds the ndim of carray (%i > %i)",
583
+ (int) argc, ca_ndim);
578
584
  }
579
585
 
580
- info->rank = argc;
586
+ info->ndim = argc;
581
587
 
582
588
  for (i=0; i<argc; i++) {
583
589
  volatile VALUE arg = argv[i];
@@ -588,22 +594,24 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
588
594
  ca_size_t scalar;
589
595
  index_type[i] = CA_IDX_SCALAR;
590
596
  scalar = NUM2SIZE(arg);
591
- 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
+ }
592
600
  index[i].scalar = scalar;
593
601
  }
594
602
  else if ( NIL_P(arg) ) { /* ca[--,nil,--] */
595
603
  index_type[i] = CA_IDX_ALL;
596
604
  }
597
605
  else if ( arg == Qfalse ) { /* ca[--,false,--] */
598
- int8_t rrank = ca_rank - argc + 1;
606
+ int8_t rndim = ca_ndim - argc + 1;
599
607
  int8_t j;
600
- for (j=0; j<rrank; j++) {
608
+ for (j=0; j<rndim; j++) {
601
609
  index_type[i+j] = CA_IDX_ALL;
602
610
  }
603
- i += rrank-1;
604
- argv -= rrank-1;
605
- argc = ca_rank;
606
- info->rank = ca_rank;
611
+ i += rndim-1;
612
+ argv -= rndim-1;
613
+ argc = ca_ndim;
614
+ info->ndim = ca_ndim;
607
615
  }
608
616
  else if ( rb_obj_is_kind_of(arg, rb_cRange) ) { /* ca[--,i..j,--] */
609
617
  ca_size_t first, last, excl, count, step;
@@ -612,10 +620,23 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
612
620
  iv_end = RANGE_END(arg);
613
621
  iv_excl = RANGE_EXCL(arg);
614
622
  index_type[i] = CA_IDX_BLOCK; /* convert to block */
615
- first = NUM2SIZE(iv_beg);
616
- last = NUM2SIZE(iv_end);
623
+ if ( NIL_P(iv_beg) ) {
624
+ first = 0;
625
+ }
626
+ else {
627
+ first = NUM2SIZE(iv_beg);
628
+ }
629
+ if ( NIL_P(iv_end) ) {
630
+ last = -1;
631
+ }
632
+ else {
633
+ last = NUM2SIZE(iv_end);
634
+ }
617
635
  excl = RTEST(iv_excl);
618
- 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
+ }
619
640
 
620
641
  if ( last < 0 ) { /* don't use CA_CHECK_INDEX for excl */
621
642
  last += ca_dim[i];
@@ -629,10 +650,12 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
629
650
  if ( excl ) {
630
651
  last += ( (last>=first) ? -1 : 1 );
631
652
  }
632
- if ( last < 0 || last >= ca_dim[i] ) {
633
- rb_raise(rb_eIndexError,
634
- "index %lld is out of range (0..%lld) at %i-dim",
635
- (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
+ }
636
659
  }
637
660
  index[i].block.start = first;
638
661
  index[i].block.count = count = llabs(last - first) + 1;
@@ -687,9 +710,23 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
687
710
  }
688
711
  else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* ca[--,[i..j,k],--]*/
689
712
  ca_size_t start, last, excl, count, step, bound;
690
- start = NUM2SIZE(RANGE_BEG(arg0));
691
- last = NUM2SIZE(RANGE_END(arg0));
692
- excl = RTEST(RANGE_EXCL(arg0));
713
+ volatile VALUE iv_beg, iv_end, iv_excl;
714
+ iv_beg = RANGE_BEG(arg0);
715
+ iv_end = RANGE_END(arg0);
716
+ iv_excl = RANGE_EXCL(arg0);
717
+ if ( NIL_P(iv_beg) ) {
718
+ start = 0;
719
+ }
720
+ else {
721
+ start = NUM2SIZE(iv_beg);
722
+ }
723
+ if ( NIL_P(iv_end) ) {
724
+ last = -1;
725
+ }
726
+ else {
727
+ last = NUM2SIZE(iv_end);
728
+ }
729
+ excl = RTEST(iv_excl);
693
730
  step = NUM2SIZE(arg1);
694
731
  if ( step == 0 ) {
695
732
  rb_raise(rb_eRuntimeError,
@@ -797,10 +834,10 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
797
834
  }
798
835
  }
799
836
 
800
- if ( ca_rank != info->rank ) {
837
+ if ( ca_ndim != info->ndim ) {
801
838
  rb_raise(rb_eIndexError,
802
- "number of indices does not equal to the rank (%i != %i)",
803
- info->rank, ca_rank);
839
+ "number of indices does not equal to the ndim (%i != %i)",
840
+ info->ndim, ca_ndim);
804
841
  }
805
842
 
806
843
  is_point = 1;
@@ -808,7 +845,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
808
845
  is_iterator = 0;
809
846
  is_grid = 0;
810
847
 
811
- for (i=0; i<info->rank; i++) {
848
+ for (i=0; i<info->ndim; i++) {
812
849
  switch ( info->index_type[i] ) {
813
850
  case CA_IDX_SCALAR:
814
851
  is_all = 0;
@@ -850,7 +887,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
850
887
  }
851
888
 
852
889
  if ( info->type == CA_REG_ITERATOR ) {
853
- for (i=0; i<info->rank; i++) {
890
+ for (i=0; i<info->ndim; i++) {
854
891
  if ( info->index_type[i] == CA_IDX_SCALAR ) {
855
892
  ca_size_t start = info->index[i].scalar;
856
893
  info->index_type[i] = CA_IDX_BLOCK;
@@ -898,7 +935,7 @@ rb_ca_ref_point (VALUE self, CAIndexInfo *info)
898
935
  ca_size_t idx[CA_RANK_MAX];
899
936
  int8_t i;
900
937
  Data_Get_Struct(self, CArray, ca);
901
- for (i=0; i<ca->rank; i++) {
938
+ for (i=0; i<ca->ndim; i++) {
902
939
  idx[i] = info->index[i].scalar;
903
940
  }
904
941
  return rb_ca_fetch_index(self, idx);
@@ -911,7 +948,7 @@ rb_ca_store_point (VALUE self, CAIndexInfo *info, volatile VALUE val)
911
948
  ca_size_t idx[CA_RANK_MAX];
912
949
  int8_t i;
913
950
  Data_Get_Struct(self, CArray, ca);
914
- for (i=0; i<ca->rank; i++) {
951
+ for (i=0; i<ca->ndim; i++) {
915
952
  idx[i] = info->index[i].scalar;
916
953
  }
917
954
  if ( rb_obj_is_cscalar(val) ) {
@@ -1041,7 +1078,7 @@ rb_ca_store_all (VALUE self, VALUE rval)
1041
1078
  }
1042
1079
 
1043
1080
  static void
1044
- 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,
1045
1082
  ca_size_t *start, ca_size_t *step, ca_size_t *count,
1046
1083
  ca_size_t *offsetp)
1047
1084
  {
@@ -1050,31 +1087,31 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1050
1087
  ca_size_t step0[CA_RANK_MAX];
1051
1088
  ca_size_t count0[CA_RANK_MAX];
1052
1089
  ca_size_t idx[CA_RANK_MAX];
1053
- int16_t rank0, rank;
1090
+ int16_t ndim0, ndim;
1054
1091
  ca_size_t offset0, offset, length;
1055
1092
  ca_size_t k, n;
1056
1093
  ca_size_t i, j, m;
1057
1094
 
1058
- rank0 = *rankp;
1095
+ ndim0 = *ndimp;
1059
1096
  offset0 = *offsetp;
1060
1097
 
1061
1098
  /* store original start, step, count to start0, step0, count0 */
1062
- memcpy(dim0, dim, sizeof(ca_size_t) * rank0);
1063
- memcpy(start0, start, sizeof(ca_size_t) * rank0);
1064
- memcpy(step0, step, sizeof(ca_size_t) * rank0);
1065
- 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);
1066
1103
 
1067
- /* classify and calc rank */
1104
+ /* classify and calc ndim */
1068
1105
  n = -1;
1069
- for (i=0; i<rank0; i++) {
1106
+ for (i=0; i<ndim0; i++) {
1070
1107
  if ( ! shrink[i] ) {
1071
1108
  n += 1;
1072
1109
  }
1073
1110
  idx[i] = n;
1074
1111
  }
1075
- rank = n + 1;
1112
+ ndim = n + 1;
1076
1113
 
1077
- *rankp = rank;
1114
+ *ndimp = ndim;
1078
1115
 
1079
1116
  /* calc offset */
1080
1117
 
@@ -1092,7 +1129,7 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1092
1129
  }
1093
1130
 
1094
1131
  length = 1;
1095
- for (i=j; i<rank0; i++) {
1132
+ for (i=j; i<ndim0; i++) {
1096
1133
  length *= dim0[i];
1097
1134
  }
1098
1135
 
@@ -1103,13 +1140,13 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1103
1140
 
1104
1141
  /* calc dim, start, step, count */
1105
1142
 
1106
- for (i=0; i<rank0; i++) {
1143
+ for (i=0; i<ndim0; i++) {
1107
1144
  n = idx[i];
1108
1145
  if ( n == -1) {
1109
1146
  continue;
1110
1147
  }
1111
1148
 
1112
- 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++) {
1113
1150
  ;
1114
1151
  }
1115
1152
 
@@ -1142,7 +1179,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1142
1179
  ca_size_t step[CA_RANK_MAX];
1143
1180
  ca_size_t count[CA_RANK_MAX];
1144
1181
  ca_size_t shrink[CA_RANK_MAX];
1145
- int16_t rank = 0;
1182
+ int16_t ndim = 0;
1146
1183
  ca_size_t offset = 0;
1147
1184
  ca_size_t flag = 0;
1148
1185
  ca_size_t elements;
@@ -1150,10 +1187,10 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1150
1187
 
1151
1188
  Data_Get_Struct(self, CArray, ca);
1152
1189
 
1153
- rank = info->rank;
1190
+ ndim = info->ndim;
1154
1191
 
1155
1192
  elements = 1;
1156
- for (i=0; i<info->rank; i++) {
1193
+ for (i=0; i<info->ndim; i++) {
1157
1194
  dim[i] = ca->dim[i];
1158
1195
  switch ( info->index_type[i] ) {
1159
1196
  case CA_IDX_SCALAR:
@@ -1170,7 +1207,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1170
1207
  }
1171
1208
  }
1172
1209
 
1173
- for (i=0; i<info->rank; i++) {
1210
+ for (i=0; i<info->ndim; i++) {
1174
1211
  switch ( info->index_type[i] ) {
1175
1212
  case CA_IDX_SCALAR:
1176
1213
  start[i] = info->index[i].scalar;
@@ -1193,7 +1230,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1193
1230
  }
1194
1231
  }
1195
1232
 
1196
- for (i=0; i<rank; i++) {
1233
+ for (i=0; i<ndim; i++) {
1197
1234
  if ( shrink[i] ) {
1198
1235
  flag = 1;
1199
1236
  break;
@@ -1201,16 +1238,16 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1201
1238
  }
1202
1239
 
1203
1240
  refer = self;
1204
- rank = ca->rank;
1241
+ ndim = ca->ndim;
1205
1242
 
1206
1243
  offset = 0;
1207
1244
 
1208
1245
  if ( flag ) {
1209
- rb_ca_index_restruct_block(&rank, shrink,
1246
+ rb_ca_index_restruct_block(&ndim, shrink,
1210
1247
  dim, start, step, count, &offset);
1211
1248
  }
1212
1249
 
1213
- 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);
1214
1251
  }
1215
1252
 
1216
1253
  static VALUE
@@ -1224,7 +1261,7 @@ rb_ca_refer_new_flatten (VALUE self)
1224
1261
  return rb_ca_refer_new(self, ca->data_type, 1, &dim0, ca->bytes, 0);
1225
1262
  }
1226
1263
 
1227
- /* rdoc:
1264
+ /* yard:
1228
1265
  class CArray
1229
1266
  def [] (*spec)
1230
1267
  end
@@ -1241,7 +1278,9 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1241
1278
  retry:
1242
1279
 
1243
1280
  Data_Get_Struct(self, CArray, ca);
1244
- 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);
1245
1284
 
1246
1285
  switch ( info.type ) {
1247
1286
  case CA_REG_ADDRESS_COMPLEX:
@@ -1298,6 +1337,90 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1298
1337
  }
1299
1338
  break;
1300
1339
  }
1340
+ case CA_REG_ATTRIBUTE: {
1341
+ obj = rb_funcall(self, rb_intern("attribute"), 0);
1342
+ obj = rb_hash_aref(obj, info.symbol);
1343
+ break;
1344
+ }
1345
+ default:
1346
+ rb_raise(rb_eIndexError, "invalid index specified");
1347
+ }
1348
+
1349
+ return obj;
1350
+ }
1351
+
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
+ }
1301
1424
  default:
1302
1425
  rb_raise(rb_eIndexError, "invalid index specified");
1303
1426
  }
@@ -1305,7 +1428,7 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1305
1428
  return obj;
1306
1429
  }
1307
1430
 
1308
- /* rdoc:
1431
+ /* yard:
1309
1432
  class CArray
1310
1433
  def []= (*spec)
1311
1434
  end
@@ -1328,7 +1451,8 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
1328
1451
 
1329
1452
  Data_Get_Struct(self, CArray, ca);
1330
1453
 
1331
- 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);
1332
1456
 
1333
1457
  switch ( info.type ) {
1334
1458
  case CA_REG_ADDRESS_COMPLEX:
@@ -1403,6 +1527,11 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
1403
1527
  }
1404
1528
  break;
1405
1529
  }
1530
+ case CA_REG_ATTRIBUTE: {
1531
+ obj = rb_funcall(self, rb_intern("attribute"), 0);
1532
+ obj = rb_hash_aset(obj, info.symbol, rval);
1533
+ break;
1534
+ }
1406
1535
  }
1407
1536
  return obj;
1408
1537
  }
@@ -1447,7 +1576,7 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
1447
1576
  return rb_ca_store_method((int)RARRAY_LEN(index), RARRAY_PTR(index), self);
1448
1577
  }
1449
1578
 
1450
- /* rdoc:
1579
+ /* yard:
1451
1580
  def CArray.scan_index(dim, idx)
1452
1581
  end
1453
1582
  */
@@ -1455,9 +1584,9 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
1455
1584
  static VALUE
1456
1585
  rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1457
1586
  {
1458
- volatile VALUE rtype, rrank, rindex;
1587
+ volatile VALUE rtype, rndim, rindex;
1459
1588
  CAIndexInfo info;
1460
- int rank;
1589
+ int ndim;
1461
1590
  ca_size_t dim[CA_RANK_MAX];
1462
1591
  ca_size_t elements;
1463
1592
  int i;
@@ -1466,21 +1595,22 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1466
1595
  Check_Type(ridx, T_ARRAY);
1467
1596
 
1468
1597
  elements = 1;
1469
- rank = (int) RARRAY_LEN(rdim);
1470
- for (i=0; i<rank; i++) {
1598
+ ndim = (int) RARRAY_LEN(rdim);
1599
+ for (i=0; i<ndim; i++) {
1471
1600
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
1472
1601
  elements *= dim[i];
1473
1602
  }
1474
1603
 
1475
- CA_CHECK_RANK(rank);
1476
- CA_CHECK_DIM(rank, dim);
1604
+ CA_CHECK_RANK(ndim);
1605
+ CA_CHECK_DIM(ndim, dim);
1477
1606
 
1478
- rb_ca_scan_index(rank, dim, elements,
1607
+ info.range_check = 1;
1608
+ rb_ca_scan_index(ndim, dim, elements,
1479
1609
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1480
1610
 
1481
1611
  rtype = INT2NUM(info.type);
1482
- rrank = INT2NUM(info.rank);
1483
- rindex = rb_ary_new2(info.rank);
1612
+ rndim = INT2NUM(info.ndim);
1613
+ rindex = rb_ary_new2(info.ndim);
1484
1614
 
1485
1615
  switch ( info.type ) {
1486
1616
  case CA_REG_NONE:
@@ -1494,7 +1624,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1494
1624
  case CA_REG_ADDRESS_COMPLEX: {
1495
1625
  volatile VALUE rinfo;
1496
1626
  ca_size_t elements = 1;
1497
- for (i=0; i<rank; i++) {
1627
+ for (i=0; i<ndim; i++) {
1498
1628
  elements *= dim[i];
1499
1629
  }
1500
1630
  rinfo = rb_ca_s_scan_index(self, rb_ary_new3(1, SIZE2NUM(elements)), ridx);
@@ -1503,7 +1633,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1503
1633
  break;
1504
1634
  }
1505
1635
  case CA_REG_POINT:
1506
- for (i=0; i<rank; i++) {
1636
+ for (i=0; i<ndim; i++) {
1507
1637
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1508
1638
  }
1509
1639
  break;
@@ -1511,7 +1641,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1511
1641
  break;
1512
1642
  case CA_REG_BLOCK:
1513
1643
  case CA_REG_ITERATOR:
1514
- for (i=0; i<rank; i++) {
1644
+ for (i=0; i<ndim; i++) {
1515
1645
  switch ( info.index_type[i] ) {
1516
1646
  case CA_IDX_SCALAR:
1517
1647
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1547,6 +1677,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1547
1677
  case CA_REG_METHOD_CALL:
1548
1678
  case CA_REG_UNBOUND_REPEAT:
1549
1679
  case CA_REG_MEMBER:
1680
+ case CA_REG_ATTRIBUTE:
1550
1681
  break;
1551
1682
  default:
1552
1683
  rb_raise(rb_eArgError, "unknown index specification");
@@ -1555,7 +1686,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1555
1686
  return rb_struct_new(S_CAInfo, rtype, rindex);
1556
1687
  }
1557
1688
 
1558
- /* rdoc:
1689
+ /* yard:
1559
1690
  class CArray
1560
1691
  def normalize_index (idx)
1561
1692
  end
@@ -1573,26 +1704,27 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
1573
1704
  Data_Get_Struct(self, CArray, ca);
1574
1705
  Check_Type(ridx, T_ARRAY);
1575
1706
 
1576
- 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,
1577
1709
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1578
1710
 
1579
1711
  switch ( info.type ) {
1580
1712
  case CA_REG_ALL:
1581
1713
  case CA_REG_SELECT:
1582
1714
  case CA_REG_ADDRESS:
1583
- rindex = rb_ary_new2(info.rank);
1715
+ rindex = rb_ary_new2(info.ndim);
1584
1716
  rb_ary_store(rindex, 0, SIZE2NUM(info.index[0].scalar));
1585
1717
  return rindex;
1586
1718
  case CA_REG_POINT:
1587
- rindex = rb_ary_new2(info.rank);
1588
- for (i=0; i<ca->rank; i++) {
1719
+ rindex = rb_ary_new2(info.ndim);
1720
+ for (i=0; i<ca->ndim; i++) {
1589
1721
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1590
1722
  }
1591
1723
  return rindex;
1592
1724
  case CA_REG_BLOCK:
1593
1725
  case CA_REG_ITERATOR:
1594
- rindex = rb_ary_new2(info.rank);
1595
- for (i=0; i<ca->rank; i++) {
1726
+ rindex = rb_ary_new2(info.ndim);
1727
+ for (i=0; i<ca->ndim; i++) {
1596
1728
  switch ( info.index_type[i] ) {
1597
1729
  case CA_IDX_SCALAR:
1598
1730
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1627,7 +1759,7 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
1627
1759
 
1628
1760
  /* ------------------------------------------------------------------- */
1629
1761
 
1630
- /* rdoc:
1762
+ /* yard:
1631
1763
  class CArray
1632
1764
  # converts addr to index
1633
1765
  def addr2index (addr)
@@ -1653,8 +1785,8 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
1653
1785
  (ca_size_t) addr, (ca_size_t) (ca->elements-1));
1654
1786
  }
1655
1787
  dim = ca->dim;
1656
- out = rb_ary_new2(ca->rank);
1657
- 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 */
1658
1790
  rb_ary_store(out, i, SIZE2NUM(addr % dim[i]));
1659
1791
  addr /= dim[i];
1660
1792
  }
@@ -1662,7 +1794,7 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
1662
1794
  return out;
1663
1795
  }
1664
1796
 
1665
- /* rdoc:
1797
+ /* yard:
1666
1798
  class CArray
1667
1799
  def index2addr (*index)
1668
1800
  end
@@ -1684,11 +1816,11 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1684
1816
 
1685
1817
  Data_Get_Struct(self, CArray, ca);
1686
1818
 
1687
- if ( argc != ca->rank ) {
1688
- rb_raise(rb_eRuntimeError, "invalid rank of index");
1819
+ if ( argc != ca->ndim ) {
1820
+ rb_raise(rb_eRuntimeError, "invalid ndim of index");
1689
1821
  }
1690
1822
 
1691
- for (i=0; i<ca->rank; i++) {
1823
+ for (i=0; i<ca->ndim; i++) {
1692
1824
  if ( ! rb_obj_is_kind_of(argv[i], rb_cInteger) ) {
1693
1825
  all_number = 0;
1694
1826
  break;
@@ -1698,7 +1830,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1698
1830
  if ( all_number ) {
1699
1831
  dim = ca->dim;
1700
1832
  addr = 0;
1701
- for (i=0; i<ca->rank; i++) {
1833
+ for (i=0; i<ca->ndim; i++) {
1702
1834
  k = NUM2SIZE(argv[i]);
1703
1835
  CA_CHECK_INDEX(k, dim[i]);
1704
1836
  addr = dim[i] * addr + k;
@@ -1707,7 +1839,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1707
1839
  }
1708
1840
 
1709
1841
  elements = 1;
1710
- for (i=0; i<ca->rank; i++) {
1842
+ for (i=0; i<ca->ndim; i++) {
1711
1843
  cidx[i] = ca_wrap_readonly(argv[i], CA_SIZE);
1712
1844
  if ( ! ca_is_scalar(cidx[i]) ) {
1713
1845
  if ( elements == 1 ) {
@@ -1719,7 +1851,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1719
1851
  }
1720
1852
  }
1721
1853
 
1722
- for (i=0; i<ca->rank; i++) {
1854
+ for (i=0; i<ca->ndim; i++) {
1723
1855
  ca_attach(cidx[i]);
1724
1856
  ca_set_iterator(1, cidx[i], &p[i], &s[i]);
1725
1857
  }
@@ -1729,7 +1861,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1729
1861
 
1730
1862
  q = (ca_size_t *) co->ptr;
1731
1863
 
1732
- ca_copy_mask_overwrite_n(co, elements, ca->rank, cidx);
1864
+ ca_copy_mask_overwrite_n(co, elements, ca->ndim, cidx);
1733
1865
  m = ( co->mask ) ? (boolean8_t *) co->mask->ptr : NULL;
1734
1866
 
1735
1867
  dim = ca->dim;
@@ -1739,7 +1871,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1739
1871
  while ( n-- ) {
1740
1872
  if ( !*m ) {
1741
1873
  addr = 0;
1742
- for (i=0; i<ca->rank; i++) {
1874
+ for (i=0; i<ca->ndim; i++) {
1743
1875
  k = *(p[i]);
1744
1876
  p[i]+=s[i];
1745
1877
  CA_CHECK_INDEX(k, dim[i]);
@@ -1748,7 +1880,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1748
1880
  *q = addr;
1749
1881
  }
1750
1882
  else {
1751
- for (i=0; i<ca->rank; i++) {
1883
+ for (i=0; i<ca->ndim; i++) {
1752
1884
  p[i]+=s[i];
1753
1885
  }
1754
1886
  }
@@ -1759,7 +1891,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1759
1891
  n = elements;
1760
1892
  while ( n-- ) {
1761
1893
  addr = 0;
1762
- for (i=0; i<ca->rank; i++) {
1894
+ for (i=0; i<ca->ndim; i++) {
1763
1895
  k = *(p[i]);
1764
1896
  p[i]+=s[i];
1765
1897
  CA_CHECK_INDEX(k, dim[i]);
@@ -1770,7 +1902,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1770
1902
  }
1771
1903
  }
1772
1904
 
1773
- for (i=0; i<ca->rank; i++) {
1905
+ for (i=0; i<ca->ndim; i++) {
1774
1906
  ca_detach(cidx[i]);
1775
1907
  }
1776
1908
 
@@ -1797,6 +1929,8 @@ Init_carray_access ()
1797
1929
  rb_define_method(rb_cCArray, "[]", rb_ca_fetch_method, -1);
1798
1930
  rb_define_method(rb_cCArray, "[]=", rb_ca_store_method, -1);
1799
1931
 
1932
+ rb_define_method(rb_cCScalar, "[]", rb_cs_fetch_method, -1);
1933
+
1800
1934
  rb_define_method(rb_cCArray, "fill", rb_ca_fill, 1);
1801
1935
  rb_define_method(rb_cCArray, "fill_copy", rb_ca_fill_copy, 1);
1802
1936
 
@@ -1828,6 +1962,7 @@ Init_carray_access ()
1828
1962
  rb_define_const(rb_cObject, "CA_REG_UNBOUND_REPEAT",
1829
1963
  INT2NUM(CA_REG_UNBOUND_REPEAT));
1830
1964
  rb_define_const(rb_cObject, "CA_REG_MEMBER", INT2NUM(CA_REG_MEMBER));
1965
+ rb_define_const(rb_cObject, "CA_REG_ATTRIBUTE", INT2NUM(CA_REG_ATTRIBUTE));
1831
1966
 
1832
1967
  }
1833
1968