carray 1.3.5 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSES +22 -0
  3. data/README.md +18 -21
  4. data/Rakefile +31 -0
  5. data/carray.gemspec +13 -26
  6. data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
  7. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
  8. data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
  9. data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
  10. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
  11. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
  12. data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
  13. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
  14. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
  15. data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
  16. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
  17. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
  18. data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
  19. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
  20. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
  21. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
  22. data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
  23. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
  24. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
  25. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
  26. data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
  27. data/{carray.h → ext/carray.h} +77 -51
  28. data/{carray_access.c → ext/carray_access.c} +133 -91
  29. data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
  30. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
  31. data/{carray_cast.c → ext/carray_cast.c} +6 -6
  32. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
  33. data/{carray_class.c → ext/carray_class.c} +0 -0
  34. data/{carray_conversion.c → ext/carray_conversion.c} +11 -13
  35. data/{carray_copy.c → ext/carray_copy.c} +19 -19
  36. data/{carray_core.c → ext/carray_core.c} +2 -2
  37. data/ext/carray_data_type.c +66 -0
  38. data/{carray_element.c → ext/carray_element.c} +9 -9
  39. data/{carray_generate.c → ext/carray_generate.c} +67 -1
  40. data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
  41. data/{carray_loop.c → ext/carray_loop.c} +24 -24
  42. data/{carray_mask.c → ext/carray_mask.c} +17 -6
  43. data/{carray_math.rb → ext/carray_math.rb} +25 -25
  44. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
  45. data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
  46. data/{carray_operator.c → ext/carray_operator.c} +32 -9
  47. data/{carray_order.c → ext/carray_order.c} +2 -153
  48. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
  49. data/{carray_stat.c → ext/carray_stat.c} +5 -5
  50. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
  51. data/{carray_test.c → ext/carray_test.c} +22 -21
  52. data/{carray_undef.c → ext/carray_undef.c} +0 -0
  53. data/{carray_utils.c → ext/carray_utils.c} +0 -0
  54. data/{extconf.rb → ext/extconf.rb} +0 -5
  55. data/{mkmath.rb → ext/mkmath.rb} +12 -2
  56. data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
  57. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
  58. data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
  59. data/{version.h → ext/version.h} +5 -5
  60. data/{version.rb → ext/version.rb} +0 -0
  61. data/lib/carray.rb +49 -7
  62. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
  63. data/lib/carray/autoload/autoload_base.rb +1 -5
  64. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  65. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  66. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  67. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  68. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  69. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  70. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  71. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  72. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  73. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  74. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  75. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  76. data/lib/carray/basic.rb +193 -0
  77. data/lib/carray/compose.rb +291 -0
  78. data/lib/carray/construct.rb +445 -0
  79. data/lib/carray/convert.rb +115 -0
  80. data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
  81. data/lib/carray/io/imagemagick.rb +1 -1
  82. data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
  83. data/lib/carray/mask.rb +91 -0
  84. data/lib/carray/{base/math.rb → math.rb} +17 -47
  85. data/lib/carray/math/histogram.rb +7 -7
  86. data/lib/carray/mkmf.rb +8 -0
  87. data/lib/carray/object/ca_obj_pack.rb +8 -8
  88. data/lib/carray/obsolete.rb +272 -0
  89. data/lib/carray/ordering.rb +157 -0
  90. data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
  91. data/lib/carray/string.rb +190 -0
  92. data/lib/carray/{base/struct.rb → struct.rb} +20 -20
  93. data/lib/carray/{io/table.rb → table.rb} +1 -9
  94. data/lib/carray/testing.rb +56 -0
  95. data/lib/carray/time.rb +78 -0
  96. data/lib/carray/transform.rb +100 -0
  97. data/misc/Methods.ja.md +182 -0
  98. data/{NOTE → misc/NOTE} +0 -0
  99. data/test/test_ALL.rb +0 -2
  100. data/test/test_order.rb +7 -7
  101. data/test/test_ref_store.rb +13 -13
  102. data/test/test_stat.rb +7 -15
  103. data/{devel → utils}/guess_shape.rb +0 -0
  104. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  105. metadata +100 -254
  106. data/COPYING +0 -56
  107. data/GPL +0 -340
  108. data/Gemfile +0 -8
  109. data/Gemfile.lock +0 -33
  110. data/LEGAL +0 -50
  111. data/TODO +0 -5
  112. data/carray_random.c +0 -531
  113. data/ext/calculus/carray_calculus.c +0 -931
  114. data/ext/calculus/carray_interp.c +0 -358
  115. data/ext/calculus/extconf.rb +0 -12
  116. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  117. data/ext/calculus/lib/math/calculus.rb +0 -119
  118. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  119. data/ext/fortio/extconf.rb +0 -3
  120. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  121. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  122. data/ext/fortio/lib/fortio.rb +0 -3
  123. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  124. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  125. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  126. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  127. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  128. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  129. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  130. data/ext/fortio/ruby_fortio.c +0 -182
  131. data/ext/fortio/test/test_H.rb +0 -5
  132. data/ext/fortio/test/test_T.rb +0 -7
  133. data/ext/fortio/test/test_fortran_format.rb +0 -86
  134. data/ext/fortio/test/test_namelist.rb +0 -25
  135. data/ext/fortio/test/test_namelist_write.rb +0 -10
  136. data/ext/fortio/test/test_sequential.rb +0 -13
  137. data/ext/fortio/test/test_sequential2.rb +0 -13
  138. data/ext/fortio/work/test.rb +0 -10
  139. data/ext/fortio/work/test_e.rb +0 -19
  140. data/ext/fortio/work/test_ep.rb +0 -10
  141. data/ext/fortio/work/test_parse.rb +0 -12
  142. data/ext/imagemap/carray_imagemap.c +0 -495
  143. data/ext/imagemap/doc/call_graph.dot +0 -28
  144. data/ext/imagemap/draw.c +0 -567
  145. data/ext/imagemap/extconf.rb +0 -13
  146. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
  147. data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
  148. data/ext/imagemap/lib/image_map.rb +0 -4
  149. data/ext/imagemap/test/swath_index.rb +0 -83
  150. data/ext/imagemap/test/swath_warp.rb +0 -99
  151. data/ext/imagemap/test/test.rb +0 -23
  152. data/ext/imagemap/test/test_image.rb +0 -42
  153. data/ext/imagemap/test/test_line.rb +0 -14
  154. data/ext/imagemap/test/test_rotate.rb +0 -17
  155. data/ext/imagemap/test/test_triangle.rb +0 -20
  156. data/ext/imagemap/test/test_warp.rb +0 -26
  157. data/ext/mathfunc/extconf.rb +0 -18
  158. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  159. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  160. data/ext/mathfunc/test/test_hypot.rb +0 -5
  161. data/ext/mathfunc/test/test_j0.rb +0 -22
  162. data/ext/mathfunc/test/test_jn.rb +0 -8
  163. data/ext/mathfunc/test/test_sph.rb +0 -9
  164. data/ext/narray/README +0 -22
  165. data/ext/narray/ca_wrap_narray.c +0 -500
  166. data/ext/narray/carray_narray.c +0 -21
  167. data/ext/narray/extconf.rb +0 -57
  168. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  169. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  170. data/ext/narray/lib/math/narray.rb +0 -17
  171. data/ext/narray/lib/math/narray_miss.rb +0 -45
  172. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  173. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  174. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  175. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  176. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  177. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  178. data/lib/carray/base/basic.rb +0 -1090
  179. data/lib/carray/base/obsolete.rb +0 -131
  180. data/lib/carray/graphics/gnuplot.rb +0 -2131
  181. data/lib/carray/graphics/zimg.rb +0 -296
  182. data/lib/carray/io/csv.rb +0 -572
  183. data/lib/carray/io/pg.rb +0 -101
  184. data/lib/carray/io/sqlite3.rb +0 -215
  185. data/lib/carray/math/interp.rb +0 -57
  186. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  187. data/mt19937ar.c +0 -182
  188. data/mt19937ar.h +0 -86
  189. data/rdoc_main.rb +0 -27
  190. data/rdoc_math.rb +0 -5
  191. data/rdoc_stat.rb +0 -31
  192. data/test/test_narray.rb +0 -64
  193. data/test/test_random.rb +0 -15
  194. data/utils/create_rdoc.sh +0 -9
  195. data/utils/make_tgz.sh +0 -3
@@ -380,11 +380,11 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
380
380
  }
381
381
  else {
382
382
  same_shape = 1;
383
- if ( max_level+1 < ca->rank ) {
383
+ if ( max_level+1 < ca->ndim ) {
384
384
  same_shape = 0;
385
385
  }
386
386
  else {
387
- for (i=0; i<ca->rank; i++) {
387
+ for (i=0; i<ca->ndim; i++) {
388
388
  if ( ca->dim[i] != dim[i] ) {
389
389
  same_shape = 0;
390
390
  break;
@@ -395,7 +395,7 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
395
395
  if ( same_shape ) {
396
396
  VALUE out = rb_ary_new2(0);
397
397
  int len = 0;
398
- ary_flatten_upto_level(ary, ca->rank-1, 0, out, &len);
398
+ ary_flatten_upto_level(ary, ca->ndim-1, 0, out, &len);
399
399
 
400
400
  if ( len != elements ) {
401
401
  return Qnil;
@@ -443,12 +443,12 @@ rb_ary_flatten_for_elements (VALUE ary, ca_size_t elements, void *ap)
443
443
  }
444
444
 
445
445
  void
446
- rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
446
+ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
447
447
  long argc, VALUE *argv, CAIndexInfo *info)
448
448
  {
449
449
  int32_t i;
450
450
 
451
- info->rank = 0;
451
+ info->ndim = 0;
452
452
  info->select = NULL;
453
453
 
454
454
  if ( argc == 0 ) { /* ca[] -> CA_REG_ALL */
@@ -481,7 +481,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
481
481
  Data_Get_Struct(arg, CArray, cs);
482
482
  if ( ca_is_integer_type(cs) ) {
483
483
  #if 0
484
- if ( ca_rank == 1 && cs->rank == 1 ) { /* ca[g] -> CA_REG_GRID (1d) */
484
+ if ( ca_ndim == 1 && cs->ndim == 1 ) { /* ca[g] -> CA_REG_GRID (1d) */
485
485
  info->type = CA_REG_GRID;
486
486
  }
487
487
  else { /* ca[m] -> CA_REG_MAPPER (2d...) */
@@ -510,9 +510,15 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
510
510
  }
511
511
  }
512
512
 
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)));
513
+ if ( TYPE(arg) == T_STRING ) {
514
+ if ( StringValuePtr(arg)[0] == '@' ) { /* ca["@name"] -> CA_REG_ATTRIBUTE */
515
+ info->type = CA_REG_ATTRIBUTE;
516
+ info->symbol = rb_str_new2(StringValuePtr(arg)+1);
517
+ }
518
+ else { /* ca["field"] -> CA_REG_MEMBER */
519
+ info->type = CA_REG_MEMBER;
520
+ info->symbol = ID2SYM(rb_intern(StringValuePtr(arg)));
521
+ }
516
522
  return;
517
523
  }
518
524
 
@@ -521,11 +527,11 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
521
527
  return;
522
528
  }
523
529
 
524
- if ( ca_rank > 1 ) { /* ca.rank > 1 */
530
+ if ( ca_ndim > 1 ) { /* ca.ndim > 1 */
525
531
  if ( rb_obj_is_kind_of(arg, rb_cInteger) ) { /* ca[n] -> CA_REG_ADDRESS */
526
532
  ca_size_t addr;
527
533
  info->type = CA_REG_ADDRESS;
528
- info->rank = 1;
534
+ info->ndim = 1;
529
535
  addr = NUM2SIZE(arg);
530
536
  CA_CHECK_INDEX(addr, ca_elements);
531
537
  info->index[0].scalar = addr;
@@ -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];
@@ -595,15 +601,15 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
595
601
  index_type[i] = CA_IDX_ALL;
596
602
  }
597
603
  else if ( arg == Qfalse ) { /* ca[--,false,--] */
598
- int8_t rrank = ca_rank - argc + 1;
604
+ int8_t rndim = ca_ndim - argc + 1;
599
605
  int8_t j;
600
- for (j=0; j<rrank; j++) {
606
+ for (j=0; j<rndim; j++) {
601
607
  index_type[i+j] = CA_IDX_ALL;
602
608
  }
603
- i += rrank-1;
604
- argv -= rrank-1;
605
- argc = ca_rank;
606
- info->rank = ca_rank;
609
+ i += rndim-1;
610
+ argv -= rndim-1;
611
+ argc = ca_ndim;
612
+ info->ndim = ca_ndim;
607
613
  }
608
614
  else if ( rb_obj_is_kind_of(arg, rb_cRange) ) { /* ca[--,i..j,--] */
609
615
  ca_size_t first, last, excl, count, step;
@@ -612,8 +618,18 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
612
618
  iv_end = RANGE_END(arg);
613
619
  iv_excl = RANGE_EXCL(arg);
614
620
  index_type[i] = CA_IDX_BLOCK; /* convert to block */
615
- first = NUM2SIZE(iv_beg);
616
- last = NUM2SIZE(iv_end);
621
+ if ( NIL_P(iv_beg) ) {
622
+ first = 0;
623
+ }
624
+ else {
625
+ first = NUM2SIZE(iv_beg);
626
+ }
627
+ if ( NIL_P(iv_end) ) {
628
+ last = -1;
629
+ }
630
+ else {
631
+ last = NUM2SIZE(iv_end);
632
+ }
617
633
  excl = RTEST(iv_excl);
618
634
  CA_CHECK_INDEX_AT(first, ca_dim[i], i);
619
635
 
@@ -687,9 +703,23 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
687
703
  }
688
704
  else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* ca[--,[i..j,k],--]*/
689
705
  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));
706
+ volatile VALUE iv_beg, iv_end, iv_excl;
707
+ iv_beg = RANGE_BEG(arg0);
708
+ iv_end = RANGE_END(arg0);
709
+ iv_excl = RANGE_EXCL(arg0);
710
+ if ( NIL_P(iv_beg) ) {
711
+ start = 0;
712
+ }
713
+ else {
714
+ start = NUM2SIZE(iv_beg);
715
+ }
716
+ if ( NIL_P(iv_end) ) {
717
+ last = -1;
718
+ }
719
+ else {
720
+ last = NUM2SIZE(iv_end);
721
+ }
722
+ excl = RTEST(iv_excl);
693
723
  step = NUM2SIZE(arg1);
694
724
  if ( step == 0 ) {
695
725
  rb_raise(rb_eRuntimeError,
@@ -797,10 +827,10 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
797
827
  }
798
828
  }
799
829
 
800
- if ( ca_rank != info->rank ) {
830
+ if ( ca_ndim != info->ndim ) {
801
831
  rb_raise(rb_eIndexError,
802
- "number of indices does not equal to the rank (%i != %i)",
803
- info->rank, ca_rank);
832
+ "number of indices does not equal to the ndim (%i != %i)",
833
+ info->ndim, ca_ndim);
804
834
  }
805
835
 
806
836
  is_point = 1;
@@ -808,7 +838,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
808
838
  is_iterator = 0;
809
839
  is_grid = 0;
810
840
 
811
- for (i=0; i<info->rank; i++) {
841
+ for (i=0; i<info->ndim; i++) {
812
842
  switch ( info->index_type[i] ) {
813
843
  case CA_IDX_SCALAR:
814
844
  is_all = 0;
@@ -850,7 +880,7 @@ rb_ca_scan_index (int ca_rank, ca_size_t *ca_dim, ca_size_t ca_elements,
850
880
  }
851
881
 
852
882
  if ( info->type == CA_REG_ITERATOR ) {
853
- for (i=0; i<info->rank; i++) {
883
+ for (i=0; i<info->ndim; i++) {
854
884
  if ( info->index_type[i] == CA_IDX_SCALAR ) {
855
885
  ca_size_t start = info->index[i].scalar;
856
886
  info->index_type[i] = CA_IDX_BLOCK;
@@ -898,7 +928,7 @@ rb_ca_ref_point (VALUE self, CAIndexInfo *info)
898
928
  ca_size_t idx[CA_RANK_MAX];
899
929
  int8_t i;
900
930
  Data_Get_Struct(self, CArray, ca);
901
- for (i=0; i<ca->rank; i++) {
931
+ for (i=0; i<ca->ndim; i++) {
902
932
  idx[i] = info->index[i].scalar;
903
933
  }
904
934
  return rb_ca_fetch_index(self, idx);
@@ -911,7 +941,7 @@ rb_ca_store_point (VALUE self, CAIndexInfo *info, volatile VALUE val)
911
941
  ca_size_t idx[CA_RANK_MAX];
912
942
  int8_t i;
913
943
  Data_Get_Struct(self, CArray, ca);
914
- for (i=0; i<ca->rank; i++) {
944
+ for (i=0; i<ca->ndim; i++) {
915
945
  idx[i] = info->index[i].scalar;
916
946
  }
917
947
  if ( rb_obj_is_cscalar(val) ) {
@@ -1041,7 +1071,7 @@ rb_ca_store_all (VALUE self, VALUE rval)
1041
1071
  }
1042
1072
 
1043
1073
  static void
1044
- rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1074
+ rb_ca_index_restruct_block (int16_t *ndimp, ca_size_t *shrink, ca_size_t *dim,
1045
1075
  ca_size_t *start, ca_size_t *step, ca_size_t *count,
1046
1076
  ca_size_t *offsetp)
1047
1077
  {
@@ -1050,31 +1080,31 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1050
1080
  ca_size_t step0[CA_RANK_MAX];
1051
1081
  ca_size_t count0[CA_RANK_MAX];
1052
1082
  ca_size_t idx[CA_RANK_MAX];
1053
- int16_t rank0, rank;
1083
+ int16_t ndim0, ndim;
1054
1084
  ca_size_t offset0, offset, length;
1055
1085
  ca_size_t k, n;
1056
1086
  ca_size_t i, j, m;
1057
1087
 
1058
- rank0 = *rankp;
1088
+ ndim0 = *ndimp;
1059
1089
  offset0 = *offsetp;
1060
1090
 
1061
1091
  /* 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);
1092
+ memcpy(dim0, dim, sizeof(ca_size_t) * ndim0);
1093
+ memcpy(start0, start, sizeof(ca_size_t) * ndim0);
1094
+ memcpy(step0, step, sizeof(ca_size_t) * ndim0);
1095
+ memcpy(count0, count, sizeof(ca_size_t) * ndim0);
1066
1096
 
1067
- /* classify and calc rank */
1097
+ /* classify and calc ndim */
1068
1098
  n = -1;
1069
- for (i=0; i<rank0; i++) {
1099
+ for (i=0; i<ndim0; i++) {
1070
1100
  if ( ! shrink[i] ) {
1071
1101
  n += 1;
1072
1102
  }
1073
1103
  idx[i] = n;
1074
1104
  }
1075
- rank = n + 1;
1105
+ ndim = n + 1;
1076
1106
 
1077
- *rankp = rank;
1107
+ *ndimp = ndim;
1078
1108
 
1079
1109
  /* calc offset */
1080
1110
 
@@ -1092,7 +1122,7 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1092
1122
  }
1093
1123
 
1094
1124
  length = 1;
1095
- for (i=j; i<rank0; i++) {
1125
+ for (i=j; i<ndim0; i++) {
1096
1126
  length *= dim0[i];
1097
1127
  }
1098
1128
 
@@ -1103,13 +1133,13 @@ rb_ca_index_restruct_block (int16_t *rankp, ca_size_t *shrink, ca_size_t *dim,
1103
1133
 
1104
1134
  /* calc dim, start, step, count */
1105
1135
 
1106
- for (i=0; i<rank0; i++) {
1136
+ for (i=0; i<ndim0; i++) {
1107
1137
  n = idx[i];
1108
1138
  if ( n == -1) {
1109
1139
  continue;
1110
1140
  }
1111
1141
 
1112
- for (j=i+1, m=i; j<rank0 && (idx[j] == n); j++) {
1142
+ for (j=i+1, m=i; j<ndim0 && (idx[j] == n); j++) {
1113
1143
  ;
1114
1144
  }
1115
1145
 
@@ -1142,7 +1172,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1142
1172
  ca_size_t step[CA_RANK_MAX];
1143
1173
  ca_size_t count[CA_RANK_MAX];
1144
1174
  ca_size_t shrink[CA_RANK_MAX];
1145
- int16_t rank = 0;
1175
+ int16_t ndim = 0;
1146
1176
  ca_size_t offset = 0;
1147
1177
  ca_size_t flag = 0;
1148
1178
  ca_size_t elements;
@@ -1150,10 +1180,10 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1150
1180
 
1151
1181
  Data_Get_Struct(self, CArray, ca);
1152
1182
 
1153
- rank = info->rank;
1183
+ ndim = info->ndim;
1154
1184
 
1155
1185
  elements = 1;
1156
- for (i=0; i<info->rank; i++) {
1186
+ for (i=0; i<info->ndim; i++) {
1157
1187
  dim[i] = ca->dim[i];
1158
1188
  switch ( info->index_type[i] ) {
1159
1189
  case CA_IDX_SCALAR:
@@ -1170,7 +1200,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1170
1200
  }
1171
1201
  }
1172
1202
 
1173
- for (i=0; i<info->rank; i++) {
1203
+ for (i=0; i<info->ndim; i++) {
1174
1204
  switch ( info->index_type[i] ) {
1175
1205
  case CA_IDX_SCALAR:
1176
1206
  start[i] = info->index[i].scalar;
@@ -1193,7 +1223,7 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1193
1223
  }
1194
1224
  }
1195
1225
 
1196
- for (i=0; i<rank; i++) {
1226
+ for (i=0; i<ndim; i++) {
1197
1227
  if ( shrink[i] ) {
1198
1228
  flag = 1;
1199
1229
  break;
@@ -1201,16 +1231,16 @@ rb_ca_ref_block (VALUE self, CAIndexInfo *info)
1201
1231
  }
1202
1232
 
1203
1233
  refer = self;
1204
- rank = ca->rank;
1234
+ ndim = ca->ndim;
1205
1235
 
1206
1236
  offset = 0;
1207
1237
 
1208
1238
  if ( flag ) {
1209
- rb_ca_index_restruct_block(&rank, shrink,
1239
+ rb_ca_index_restruct_block(&ndim, shrink,
1210
1240
  dim, start, step, count, &offset);
1211
1241
  }
1212
1242
 
1213
- return rb_ca_block_new(refer, rank, dim, start, step, count, offset);
1243
+ return rb_ca_block_new(refer, ndim, dim, start, step, count, offset);
1214
1244
  }
1215
1245
 
1216
1246
  static VALUE
@@ -1241,7 +1271,7 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1241
1271
  retry:
1242
1272
 
1243
1273
  Data_Get_Struct(self, CArray, ca);
1244
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements, argc, argv, &info);
1274
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
1245
1275
 
1246
1276
  switch ( info.type ) {
1247
1277
  case CA_REG_ADDRESS_COMPLEX:
@@ -1298,6 +1328,11 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
1298
1328
  }
1299
1329
  break;
1300
1330
  }
1331
+ case CA_REG_ATTRIBUTE: {
1332
+ obj = rb_funcall(self, rb_intern("attribute"), 0);
1333
+ obj = rb_hash_aref(obj, info.symbol);
1334
+ break;
1335
+ }
1301
1336
  default:
1302
1337
  rb_raise(rb_eIndexError, "invalid index specified");
1303
1338
  }
@@ -1328,7 +1363,7 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
1328
1363
 
1329
1364
  Data_Get_Struct(self, CArray, ca);
1330
1365
 
1331
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements, argc, argv, &info);
1366
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
1332
1367
 
1333
1368
  switch ( info.type ) {
1334
1369
  case CA_REG_ADDRESS_COMPLEX:
@@ -1403,6 +1438,11 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
1403
1438
  }
1404
1439
  break;
1405
1440
  }
1441
+ case CA_REG_ATTRIBUTE: {
1442
+ obj = rb_funcall(self, rb_intern("attribute"), 0);
1443
+ obj = rb_hash_aset(obj, info.symbol, rval);
1444
+ break;
1445
+ }
1406
1446
  }
1407
1447
  return obj;
1408
1448
  }
@@ -1455,9 +1495,9 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
1455
1495
  static VALUE
1456
1496
  rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1457
1497
  {
1458
- volatile VALUE rtype, rrank, rindex;
1498
+ volatile VALUE rtype, rndim, rindex;
1459
1499
  CAIndexInfo info;
1460
- int rank;
1500
+ int ndim;
1461
1501
  ca_size_t dim[CA_RANK_MAX];
1462
1502
  ca_size_t elements;
1463
1503
  int i;
@@ -1466,21 +1506,21 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1466
1506
  Check_Type(ridx, T_ARRAY);
1467
1507
 
1468
1508
  elements = 1;
1469
- rank = (int) RARRAY_LEN(rdim);
1470
- for (i=0; i<rank; i++) {
1509
+ ndim = (int) RARRAY_LEN(rdim);
1510
+ for (i=0; i<ndim; i++) {
1471
1511
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
1472
1512
  elements *= dim[i];
1473
1513
  }
1474
1514
 
1475
- CA_CHECK_RANK(rank);
1476
- CA_CHECK_DIM(rank, dim);
1515
+ CA_CHECK_RANK(ndim);
1516
+ CA_CHECK_DIM(ndim, dim);
1477
1517
 
1478
- rb_ca_scan_index(rank, dim, elements,
1518
+ rb_ca_scan_index(ndim, dim, elements,
1479
1519
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1480
1520
 
1481
1521
  rtype = INT2NUM(info.type);
1482
- rrank = INT2NUM(info.rank);
1483
- rindex = rb_ary_new2(info.rank);
1522
+ rndim = INT2NUM(info.ndim);
1523
+ rindex = rb_ary_new2(info.ndim);
1484
1524
 
1485
1525
  switch ( info.type ) {
1486
1526
  case CA_REG_NONE:
@@ -1494,7 +1534,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1494
1534
  case CA_REG_ADDRESS_COMPLEX: {
1495
1535
  volatile VALUE rinfo;
1496
1536
  ca_size_t elements = 1;
1497
- for (i=0; i<rank; i++) {
1537
+ for (i=0; i<ndim; i++) {
1498
1538
  elements *= dim[i];
1499
1539
  }
1500
1540
  rinfo = rb_ca_s_scan_index(self, rb_ary_new3(1, SIZE2NUM(elements)), ridx);
@@ -1503,7 +1543,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1503
1543
  break;
1504
1544
  }
1505
1545
  case CA_REG_POINT:
1506
- for (i=0; i<rank; i++) {
1546
+ for (i=0; i<ndim; i++) {
1507
1547
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1508
1548
  }
1509
1549
  break;
@@ -1511,7 +1551,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1511
1551
  break;
1512
1552
  case CA_REG_BLOCK:
1513
1553
  case CA_REG_ITERATOR:
1514
- for (i=0; i<rank; i++) {
1554
+ for (i=0; i<ndim; i++) {
1515
1555
  switch ( info.index_type[i] ) {
1516
1556
  case CA_IDX_SCALAR:
1517
1557
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1547,6 +1587,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
1547
1587
  case CA_REG_METHOD_CALL:
1548
1588
  case CA_REG_UNBOUND_REPEAT:
1549
1589
  case CA_REG_MEMBER:
1590
+ case CA_REG_ATTRIBUTE:
1550
1591
  break;
1551
1592
  default:
1552
1593
  rb_raise(rb_eArgError, "unknown index specification");
@@ -1573,26 +1614,26 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
1573
1614
  Data_Get_Struct(self, CArray, ca);
1574
1615
  Check_Type(ridx, T_ARRAY);
1575
1616
 
1576
- rb_ca_scan_index(ca->rank, ca->dim, ca->elements,
1617
+ rb_ca_scan_index(ca->ndim, ca->dim, ca->elements,
1577
1618
  RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
1578
1619
 
1579
1620
  switch ( info.type ) {
1580
1621
  case CA_REG_ALL:
1581
1622
  case CA_REG_SELECT:
1582
1623
  case CA_REG_ADDRESS:
1583
- rindex = rb_ary_new2(info.rank);
1624
+ rindex = rb_ary_new2(info.ndim);
1584
1625
  rb_ary_store(rindex, 0, SIZE2NUM(info.index[0].scalar));
1585
1626
  return rindex;
1586
1627
  case CA_REG_POINT:
1587
- rindex = rb_ary_new2(info.rank);
1588
- for (i=0; i<ca->rank; i++) {
1628
+ rindex = rb_ary_new2(info.ndim);
1629
+ for (i=0; i<ca->ndim; i++) {
1589
1630
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
1590
1631
  }
1591
1632
  return rindex;
1592
1633
  case CA_REG_BLOCK:
1593
1634
  case CA_REG_ITERATOR:
1594
- rindex = rb_ary_new2(info.rank);
1595
- for (i=0; i<ca->rank; i++) {
1635
+ rindex = rb_ary_new2(info.ndim);
1636
+ for (i=0; i<ca->ndim; i++) {
1596
1637
  switch ( info.index_type[i] ) {
1597
1638
  case CA_IDX_SCALAR:
1598
1639
  rb_ary_store(rindex, i, SIZE2NUM(info.index[i].scalar));
@@ -1653,8 +1694,8 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
1653
1694
  (ca_size_t) addr, (ca_size_t) (ca->elements-1));
1654
1695
  }
1655
1696
  dim = ca->dim;
1656
- out = rb_ary_new2(ca->rank);
1657
- for (i=ca->rank-1; i>=0; i--) { /* in descending order */
1697
+ out = rb_ary_new2(ca->ndim);
1698
+ for (i=ca->ndim-1; i>=0; i--) { /* in descending order */
1658
1699
  rb_ary_store(out, i, SIZE2NUM(addr % dim[i]));
1659
1700
  addr /= dim[i];
1660
1701
  }
@@ -1684,11 +1725,11 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1684
1725
 
1685
1726
  Data_Get_Struct(self, CArray, ca);
1686
1727
 
1687
- if ( argc != ca->rank ) {
1688
- rb_raise(rb_eRuntimeError, "invalid rank of index");
1728
+ if ( argc != ca->ndim ) {
1729
+ rb_raise(rb_eRuntimeError, "invalid ndim of index");
1689
1730
  }
1690
1731
 
1691
- for (i=0; i<ca->rank; i++) {
1732
+ for (i=0; i<ca->ndim; i++) {
1692
1733
  if ( ! rb_obj_is_kind_of(argv[i], rb_cInteger) ) {
1693
1734
  all_number = 0;
1694
1735
  break;
@@ -1698,7 +1739,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1698
1739
  if ( all_number ) {
1699
1740
  dim = ca->dim;
1700
1741
  addr = 0;
1701
- for (i=0; i<ca->rank; i++) {
1742
+ for (i=0; i<ca->ndim; i++) {
1702
1743
  k = NUM2SIZE(argv[i]);
1703
1744
  CA_CHECK_INDEX(k, dim[i]);
1704
1745
  addr = dim[i] * addr + k;
@@ -1707,7 +1748,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1707
1748
  }
1708
1749
 
1709
1750
  elements = 1;
1710
- for (i=0; i<ca->rank; i++) {
1751
+ for (i=0; i<ca->ndim; i++) {
1711
1752
  cidx[i] = ca_wrap_readonly(argv[i], CA_SIZE);
1712
1753
  if ( ! ca_is_scalar(cidx[i]) ) {
1713
1754
  if ( elements == 1 ) {
@@ -1719,7 +1760,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1719
1760
  }
1720
1761
  }
1721
1762
 
1722
- for (i=0; i<ca->rank; i++) {
1763
+ for (i=0; i<ca->ndim; i++) {
1723
1764
  ca_attach(cidx[i]);
1724
1765
  ca_set_iterator(1, cidx[i], &p[i], &s[i]);
1725
1766
  }
@@ -1729,7 +1770,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1729
1770
 
1730
1771
  q = (ca_size_t *) co->ptr;
1731
1772
 
1732
- ca_copy_mask_overwrite_n(co, elements, ca->rank, cidx);
1773
+ ca_copy_mask_overwrite_n(co, elements, ca->ndim, cidx);
1733
1774
  m = ( co->mask ) ? (boolean8_t *) co->mask->ptr : NULL;
1734
1775
 
1735
1776
  dim = ca->dim;
@@ -1739,7 +1780,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1739
1780
  while ( n-- ) {
1740
1781
  if ( !*m ) {
1741
1782
  addr = 0;
1742
- for (i=0; i<ca->rank; i++) {
1783
+ for (i=0; i<ca->ndim; i++) {
1743
1784
  k = *(p[i]);
1744
1785
  p[i]+=s[i];
1745
1786
  CA_CHECK_INDEX(k, dim[i]);
@@ -1748,7 +1789,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1748
1789
  *q = addr;
1749
1790
  }
1750
1791
  else {
1751
- for (i=0; i<ca->rank; i++) {
1792
+ for (i=0; i<ca->ndim; i++) {
1752
1793
  p[i]+=s[i];
1753
1794
  }
1754
1795
  }
@@ -1759,7 +1800,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1759
1800
  n = elements;
1760
1801
  while ( n-- ) {
1761
1802
  addr = 0;
1762
- for (i=0; i<ca->rank; i++) {
1803
+ for (i=0; i<ca->ndim; i++) {
1763
1804
  k = *(p[i]);
1764
1805
  p[i]+=s[i];
1765
1806
  CA_CHECK_INDEX(k, dim[i]);
@@ -1770,7 +1811,7 @@ rb_ca_index2addr (int argc, VALUE *argv, VALUE self)
1770
1811
  }
1771
1812
  }
1772
1813
 
1773
- for (i=0; i<ca->rank; i++) {
1814
+ for (i=0; i<ca->ndim; i++) {
1774
1815
  ca_detach(cidx[i]);
1775
1816
  }
1776
1817
 
@@ -1828,6 +1869,7 @@ Init_carray_access ()
1828
1869
  rb_define_const(rb_cObject, "CA_REG_UNBOUND_REPEAT",
1829
1870
  INT2NUM(CA_REG_UNBOUND_REPEAT));
1830
1871
  rb_define_const(rb_cObject, "CA_REG_MEMBER", INT2NUM(CA_REG_MEMBER));
1872
+ rb_define_const(rb_cObject, "CA_REG_ATTRIBUTE", INT2NUM(CA_REG_ATTRIBUTE));
1831
1873
 
1832
1874
  }
1833
1875