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,17 +3,15 @@
3
3
  ca_iter_window.c
4
4
 
5
5
  This file is part of Ruby/CArray extension library.
6
- You can redistribute it and/or modify it under the terms of
7
- the Ruby Licence.
8
6
 
9
- Copyright (C) 2005 Hiroki Motoyoshi
7
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
10
8
 
11
9
  ---------------------------------------------------------------------------- */
12
10
 
13
11
  #include "carray.h"
14
12
 
15
13
  typedef struct {
16
- int8_t rank;
14
+ int8_t ndim;
17
15
  ca_size_t dim[CA_RANK_MAX];
18
16
  CArray *reference;
19
17
  CArray * (*kernel_at_addr)(void *, ca_size_t, CArray *);
@@ -27,7 +25,7 @@ typedef struct {
27
25
 
28
26
  VALUE rb_cCAWindowIterator;
29
27
 
30
- /* rdoc:
28
+ /* yard:
31
29
  class CAWindowIterator < CAIterator # :nodoc:
32
30
  end
33
31
  */
@@ -59,7 +57,7 @@ ca_vi_kernel_at_index (void *it, ca_size_t *idx, CArray *ref)
59
57
 
60
58
  ca_update_mask(kernel);
61
59
 
62
- for (i=0; i<kernel->rank; i++) {
60
+ for (i=0; i<kernel->ndim; i++) {
63
61
  j = idx[i];
64
62
  CA_CHECK_INDEX(j, vit->dim[i]);
65
63
  kernel->start[i] = j - vit->offset[i];
@@ -78,7 +76,7 @@ ca_vi_kernel_at_addr (void *it, ca_size_t addr, CArray *ref)
78
76
  ca_size_t *dim = vit->dim;
79
77
  ca_size_t idx[CA_RANK_MAX];
80
78
  int8_t i;
81
- for (i=vit->rank-1; i>=0; i--) {
79
+ for (i=vit->ndim-1; i>=0; i--) {
82
80
  idx[i] = addr % dim[i];
83
81
  addr /= dim[i];
84
82
  }
@@ -97,7 +95,7 @@ ca_vi_kernel_move_to_index (void *it, ca_size_t *idx, CArray *kern)
97
95
 
98
96
  ca_update_mask(kernel);
99
97
 
100
- for (i=0; i<kernel->rank; i++) {
98
+ for (i=0; i<kernel->ndim; i++) {
101
99
  j = idx[i];
102
100
  CA_CHECK_INDEX(j, dim[i]);
103
101
  kernel->start[i] = j - offset[i];
@@ -116,7 +114,7 @@ ca_vi_kernel_move_to_addr (void *it, ca_size_t addr, CArray *ref)
116
114
  ca_size_t *dim = vit->dim;
117
115
  ca_size_t idx[CA_RANK_MAX];
118
116
  int8_t i;
119
- for (i=vit->rank-1; i>=0; i--) {
117
+ for (i=vit->ndim-1; i>=0; i--) {
120
118
  idx[i] = addr % dim[i];
121
119
  addr /= dim[i];
122
120
  }
@@ -136,12 +134,12 @@ ca_vi_setup (VALUE self, VALUE rref, VALUE rker)
136
134
  Data_Get_Struct(rref, CArray, ref);
137
135
  Data_Get_Struct(rker, CArray, ker);
138
136
 
139
- if ( ref->rank != ker->rank ) {
140
- rb_raise(rb_eRuntimeError, "rank mismatch between reference and kernel");
137
+ if ( ref->ndim != ker->ndim ) {
138
+ rb_raise(rb_eRuntimeError, "ndim mismatch between reference and kernel");
141
139
  }
142
140
 
143
- it->rank = ref->rank;
144
- memcpy(it->dim, ref->dim, it->rank * sizeof(ca_size_t));
141
+ it->ndim = ref->ndim;
142
+ memcpy(it->dim, ref->dim, it->ndim * sizeof(ca_size_t));
145
143
  it->reference = ref;
146
144
  it->kernel = ker;
147
145
  it->kernel_at_addr = ca_vi_kernel_at_addr;
@@ -149,7 +147,7 @@ ca_vi_setup (VALUE self, VALUE rref, VALUE rker)
149
147
  it->kernel_move_to_addr = ca_vi_kernel_move_to_addr;
150
148
  it->kernel_move_to_index = ca_vi_kernel_move_to_index;
151
149
 
152
- for (i=0; i<it->rank; i++) {
150
+ for (i=0; i<it->ndim; i++) {
153
151
  it->offset[i] = -(((CAWindow*)ker)->start[i]);
154
152
  }
155
153
 
@@ -3,10 +3,8 @@
3
3
  ca_obj_array.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
 
@@ -19,7 +17,7 @@
19
17
 
20
18
  VALUE rb_cCArray, rb_cCAWrap, rb_cCScalar, rb_cCAVirtual;
21
19
 
22
- /* rdoc:
20
+ /* yard:
23
21
  class CArray
24
22
  end
25
23
  class CAWrap < CArray # :nodoc:
@@ -42,7 +40,7 @@ double ca_mem_count = 0.0;
42
40
 
43
41
  /* Threshold for forced garbage collection and its default value */
44
42
  double ca_gc_interval;
45
- const double ca_default_gc_interval = 40.0; /* 40MB */
43
+ const double ca_default_gc_interval = 100.0; /* 100MB */
46
44
 
47
45
  #define MB (1024*1024)
48
46
 
@@ -60,27 +58,22 @@ ca_check_mem_count()
60
58
  }
61
59
  }
62
60
 
63
- /* rdoc:
64
- # returns the threshold of incremented memory (MB) used by carray object
65
- # until start GC.
66
- def CArray.gc_interval ()
67
- end
68
- # set the threshold of incremented memory (MB) used by carray object
69
- # until start GC.
70
- def CArray.gc_interval= (val)
71
- end
72
- # reset the counter for the GC start when the incremented memory
73
- # get larger than `CArray.gc_interval`.
74
- def CArray.reset_gc_interval ()
75
- end
76
- */
61
+ /* @private gc_interval
77
62
 
63
+ Returns the threshold of incremented memory (MB) used by carray object
64
+ until start GC.
65
+ */
78
66
  static VALUE
79
67
  rb_ca_get_gc_interval (VALUE self)
80
68
  {
81
69
  return rb_float_new(ca_gc_interval);
82
70
  }
83
71
 
72
+ /* @private gc_interval= (val)
73
+
74
+ Sets the threshold of incremented memory (MB) used by carray object
75
+ until start GC.
76
+ */
84
77
  static VALUE
85
78
  rb_ca_set_gc_interval (VALUE self, VALUE rth)
86
79
  {
@@ -92,6 +85,11 @@ rb_ca_set_gc_interval (VALUE self, VALUE rth)
92
85
  return rb_float_new(ca_gc_interval);
93
86
  }
94
87
 
88
+ /* @private reset_gc_inverval
89
+
90
+ Reset the counter for the GC start when the incremented memory
91
+ get larger than `CArray.gc_interval`.
92
+ */
95
93
  static VALUE
96
94
  rb_ca_reset_gc_interval (VALUE self)
97
95
  {
@@ -117,7 +115,7 @@ rb_ca_reset_gc_interval (VALUE self)
117
115
 
118
116
  static int
119
117
  carray_setup_i (CArray *ca,
120
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
118
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
121
119
  CArray *mask, int allocate, int use_calloc)
122
120
  {
123
121
  ca_size_t elements;
@@ -127,14 +125,14 @@ carray_setup_i (CArray *ca,
127
125
 
128
126
  /* check arguments */
129
127
  CA_CHECK_DATA_TYPE(data_type);
130
- CA_CHECK_RANK(rank);
131
- CA_CHECK_DIM(rank, dim);
128
+ CA_CHECK_RANK(ndim);
129
+ CA_CHECK_DIM(ndim, dim);
132
130
  CA_CHECK_BYTES(data_type, bytes);
133
131
 
134
132
  /* calculate total number of elements */
135
133
  elements = 1;
136
134
  length = bytes;
137
- for (i=0; i<rank; i++) {
135
+ for (i=0; i<ndim; i++) {
138
136
  elements *= dim[i];
139
137
  length *= dim[i];
140
138
  }
@@ -153,11 +151,11 @@ carray_setup_i (CArray *ca,
153
151
 
154
152
  ca->data_type = data_type;
155
153
  ca->flags = 0;
156
- ca->rank = rank;
154
+ ca->ndim = ndim;
157
155
  ca->bytes = bytes;
158
156
  ca->elements = elements;
159
- ca->dim = ALLOC_N(ca_size_t, rank);
160
- memcpy(ca->dim, dim, rank*sizeof(ca_size_t));
157
+ ca->dim = ALLOC_N(ca_size_t, ndim);
158
+ memcpy(ca->dim, dim, ndim*sizeof(ca_size_t));
161
159
 
162
160
  if ( allocate ) { /* allocate == true */
163
161
 
@@ -201,26 +199,26 @@ carray_setup_i (CArray *ca,
201
199
 
202
200
  int
203
201
  carray_setup (CArray *ca,
204
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *mask)
202
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask)
205
203
  {
206
- return carray_setup_i(ca, data_type, rank, dim, bytes, mask, 1, 0);
204
+ return carray_setup_i(ca, data_type, ndim, dim, bytes, mask, 1, 0);
207
205
  }
208
206
 
209
207
  int
210
208
  carray_safe_setup (CArray *ca,
211
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes, CArray *mask)
209
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask)
212
210
  {
213
- return carray_setup_i(ca, data_type, rank, dim, bytes, mask, 1, 1);
211
+ return carray_setup_i(ca, data_type, ndim, dim, bytes, mask, 1, 1);
214
212
  }
215
213
 
216
214
  int
217
215
  ca_wrap_setup (CArray *ca,
218
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
216
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
219
217
  CArray *mask, char *ptr)
220
218
  {
221
219
  int ret;
222
220
 
223
- ret = carray_setup_i(ca, data_type, rank, dim, bytes, mask, 0, 0);
221
+ ret = carray_setup_i(ca, data_type, ndim, dim, bytes, mask, 0, 0);
224
222
  if ( (!ptr) && (ca->elements != 0) ) {
225
223
  rb_raise(rb_eRuntimeError, "wrapping NULL pointer with an non-empty array");
226
224
  }
@@ -230,49 +228,49 @@ ca_wrap_setup (CArray *ca,
230
228
 
231
229
  int
232
230
  ca_wrap_setup_null (CArray *ca,
233
- int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
231
+ int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
234
232
  CArray *mask)
235
233
  {
236
234
  int ret;
237
235
 
238
- ret = carray_setup_i(ca, data_type, rank, dim, bytes, mask, 0, 0);
236
+ ret = carray_setup_i(ca, data_type, ndim, dim, bytes, mask, 0, 0);
239
237
  ca->ptr = NULL;
240
238
  return ret;
241
239
  }
242
240
 
243
241
  CArray *
244
- carray_new (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
242
+ carray_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
245
243
  CArray *mask)
246
244
  {
247
245
  CArray *ca = ALLOC(CArray);
248
- carray_setup(ca, data_type, rank, dim, bytes, mask);
246
+ carray_setup(ca, data_type, ndim, dim, bytes, mask);
249
247
  return ca;
250
248
  }
251
249
 
252
250
  CArray *
253
- carray_new_safe (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
251
+ carray_new_safe (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
254
252
  CArray *mask)
255
253
  {
256
254
  CArray *ca = ALLOC(CArray);
257
- carray_safe_setup(ca, data_type, rank, dim, bytes, mask);
255
+ carray_safe_setup(ca, data_type, ndim, dim, bytes, mask);
258
256
  return ca;
259
257
  }
260
258
 
261
259
  CAWrap *
262
- ca_wrap_new (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
260
+ ca_wrap_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
263
261
  CArray *mask, char *ptr)
264
262
  {
265
263
  CAWrap *ca = ALLOC(CAWrap);
266
- ca_wrap_setup(ca, data_type, rank, dim, bytes, mask, ptr);
264
+ ca_wrap_setup(ca, data_type, ndim, dim, bytes, mask, ptr);
267
265
  return ca;
268
266
  }
269
267
 
270
268
  CAWrap *
271
- ca_wrap_new_null (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
269
+ ca_wrap_new_null (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
272
270
  CArray *mask)
273
271
  {
274
272
  CAWrap *ca = ALLOC(CAWrap);
275
- ca_wrap_setup_null(ca, data_type, rank, dim, bytes, mask);
273
+ ca_wrap_setup_null(ca, data_type, ndim, dim, bytes, mask);
276
274
  return ca;
277
275
  }
278
276
 
@@ -313,7 +311,7 @@ cscalar_setup (CScalar *ca,
313
311
  ca->obj_type = CA_OBJ_SCALAR;
314
312
  ca->data_type = data_type;
315
313
  ca->flags = 0;
316
- ca->rank = 1;
314
+ ca->ndim = 1;
317
315
  ca->bytes = bytes;
318
316
  ca->elements = 1;
319
317
  ca->dim = &(ca->_dim);
@@ -388,7 +386,7 @@ ca_array_func_clone (void *ap)
388
386
  {
389
387
  CArray *ca = (CArray *) ap;
390
388
  CArray *co;
391
- co = carray_new(ca->data_type, ca->rank, ca->dim, ca->bytes, ca->mask);
389
+ co = carray_new(ca->data_type, ca->ndim, ca->dim, ca->bytes, ca->mask);
392
390
  memcpy(co->ptr, ca->ptr, ca_length(ca));
393
391
  return co;
394
392
  }
@@ -407,9 +405,9 @@ ca_array_func_ptr_at_index (void *ap, ca_size_t *idx)
407
405
  ca_size_t *dim = ca->dim;
408
406
  int8_t i;
409
407
  ca_size_t n;
410
- n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[rank-1] */
411
- for (i=1; i<ca->rank; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[rank-1] */
412
- n = dim[i]*n+idx[i]; /* ... + idx[rank-2]*dim[1] + idx[rank-1] */
408
+ n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[ndim-1] */
409
+ for (i=1; i<ca->ndim; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[ndim-1] */
410
+ n = dim[i]*n+idx[i]; /* ... + idx[ndim-2]*dim[1] + idx[ndim-1] */
413
411
  }
414
412
  return ca->ptr + ca->bytes * n;
415
413
  }
@@ -429,7 +427,7 @@ ca_array_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
429
427
  int8_t i;
430
428
  ca_size_t n;
431
429
  n = idx[0];
432
- for (i=1; i<ca->rank; i++) {
430
+ for (i=1; i<ca->ndim; i++) {
433
431
  n = dim[i]*n+idx[i];
434
432
  }
435
433
  memcpy(ptr, ca->ptr + ca->bytes * n, ca->bytes);
@@ -450,7 +448,7 @@ ca_array_func_store_index (void *ap, ca_size_t *idx, void *ptr)
450
448
  int8_t i;
451
449
  ca_size_t n;
452
450
  n = idx[0];
453
- for (i=1; i<ca->rank; i++) {
451
+ for (i=1; i<ca->ndim; i++) {
454
452
  n = dim[i]*n+idx[i];
455
453
  }
456
454
  memcpy(ca->ptr + ca->bytes * n, ptr, ca->bytes);
@@ -547,7 +545,7 @@ void
547
545
  ca_array_func_create_mask (void *ap)
548
546
  {
549
547
  CArray *ca = (CArray *) ap;
550
- ca->mask = carray_new_safe(CA_BOOLEAN, ca->rank, ca->dim, 0, NULL);
548
+ ca->mask = carray_new_safe(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
551
549
  }
552
550
 
553
551
  ca_operation_function_t ca_array_func = {
@@ -654,18 +652,27 @@ ca_operation_function_t ca_scalar_func = {
654
652
  /* ------------------------------------------------------------------- */
655
653
 
656
654
  VALUE
657
- rb_carray_new (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
655
+ rb_carray_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
658
656
  CArray *mask)
659
657
  {
660
- CArray *ca = carray_new(data_type, rank, dim, bytes, mask);
658
+ CArray *ca = carray_new(data_type, ndim, dim, bytes, mask);
661
659
  return ca_wrap_struct(ca);
662
660
  }
663
661
 
664
662
  VALUE
665
- rb_carray_new_safe (int8_t data_type, int8_t rank, ca_size_t *dim, ca_size_t bytes,
663
+ rb_carray_new_safe (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
666
664
  CArray *mask)
667
665
  {
668
- CArray *ca = carray_new_safe(data_type, rank, dim, bytes, mask);
666
+ CArray *ca = carray_new_safe(data_type, ndim, dim, bytes, mask);
667
+ return ca_wrap_struct(ca);
668
+ }
669
+
670
+
671
+ VALUE
672
+ rb_ca_wrap_new (int8_t data_type, int8_t ndim, ca_size_t *dim, ca_size_t bytes,
673
+ CArray *mask, char *ptr)
674
+ {
675
+ CAWrap *ca = ca_wrap_new(data_type, ndim, dim, bytes, mask, ptr);
669
676
  return ca_wrap_struct(ca);
670
677
  }
671
678
 
@@ -699,20 +706,16 @@ rb_ca_s_allocate (VALUE klass)
699
706
  return Data_Make_Struct(klass, CArray, ca_mark, ca_free, ca);
700
707
  }
701
708
 
702
- /* rdoc:
703
- # call-seq:
704
- # CArray.new(data_type, dim, bytes=0) { ... }
705
- #
706
- # Constructs a new CArray object of <i>data_type</i>, which has the
707
- # rank and the dimensions specified by an <code>Array</code> of
708
- # <code>Integer</code> or an argument list of <code>Integer</code>.
709
- # The byte size of each element for the fixed length data type
710
- # (<code>data_type == CA_FIXLEN</code>) is specified optional argument
711
- # <i>bytes</i>. Otherwise, this optional argument has no
712
- # effect. If the block is given, the new CArray
713
- # object will be initialized by the value returned from the block.
714
- def CArray.new(data_type, dim, bytes=0)
715
- end
709
+ /* @overload initialize(data_type, dim, bytes=0) { ... }
710
+
711
+ Constructs a new CArray object of <i>data_type</i>, which has the
712
+ ndim and the dimensions specified by an <code>Array</code> of
713
+ <code>Integer</code> or an argument list of <code>Integer</code>.
714
+ The byte size of each element for the fixed length data type
715
+ (<code>data_type == CA_FIXLEN</code>) is specified optional argument
716
+ <i>bytes</i>. Otherwise, this optional argument has no
717
+ effect. If the block is given, the new CArray
718
+ object will be initialized by the value returned from the block.
716
719
  */
717
720
 
718
721
  static VALUE
@@ -720,7 +723,7 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
720
723
  {
721
724
  volatile VALUE rtype, rdim, ropt, rbytes = Qnil;
722
725
  CArray *ca;
723
- int8_t data_type, rank;
726
+ int8_t data_type, ndim;
724
727
  ca_size_t dim[CA_RANK_MAX];
725
728
  ca_size_t bytes;
726
729
  int8_t i;
@@ -732,13 +735,13 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
732
735
  rb_ca_data_type_import(self, rtype);
733
736
 
734
737
  Check_Type(rdim, T_ARRAY);
735
- rank = RARRAY_LEN(rdim);
736
- for (i=0; i<rank; i++) {
738
+ ndim = RARRAY_LEN(rdim);
739
+ for (i=0; i<ndim; i++) {
737
740
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
738
741
  }
739
742
 
740
743
  Data_Get_Struct(self, CArray, ca);
741
- carray_safe_setup(ca, data_type, rank, dim, bytes, NULL);
744
+ carray_safe_setup(ca, data_type, ndim, dim, bytes, NULL);
742
745
 
743
746
  if ( rb_block_given_p() ) {
744
747
  volatile VALUE rval = rb_yield(self);
@@ -750,6 +753,12 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
750
753
  return Qnil;
751
754
  }
752
755
 
756
+ /* @overload fixlen(*dim, bytes: ) { ... }
757
+
758
+ (Construction)
759
+ Short-Hand of `CArray.new(:fixlen, dim, bytes: ) { ... }`
760
+ */
761
+
753
762
  static VALUE
754
763
  rb_ca_s_fixlen (int argc, VALUE *argv, VALUE klass)
755
764
  {
@@ -759,56 +768,184 @@ rb_ca_s_fixlen (int argc, VALUE *argv, VALUE klass)
759
768
  return rb_class_new_instance(3, args, klass);
760
769
  }
761
770
 
762
- #define rb_ca_s_type(type, code) \
763
- rb_ca_s_## type (int argc, VALUE *argv, VALUE klass) \
764
- { \
765
- volatile VALUE ropt = rb_pop_options(&argc, &argv); \
766
- volatile VALUE rdim = rb_ary_new4(argc, argv); \
767
- VALUE args[3] = { INT2NUM(code), rdim, ropt }; \
768
- return rb_class_new_instance(3, args, klass); \
771
+ #define rb_ca_s_body(code) \
772
+ { \
773
+ if ( argc == 0 ) { \
774
+ return ca_data_type_class(code); \
775
+ } \
776
+ else { \
777
+ volatile VALUE ropt = rb_pop_options(&argc, &argv); \
778
+ volatile VALUE rdim = rb_ary_new4(argc, argv); \
779
+ VALUE args[3] = { INT2NUM(code), rdim, ropt }; \
780
+ return rb_class_new_instance(3, args, klass); \
781
+ } \
769
782
  }
770
783
 
771
- /*
772
- * call-seq:
773
- * CArray.int8(dim0, dim1, ...) { ... } -> CArray
774
- * CArray.uint8(dim0, dim1, ...) { ... } -> CArray
775
- * CArray.int16(dim0, dim1, ...) { ... } -> CArray
776
- * CArray.uint16(dim0, dim1, ...) { ... } -> CArray
777
- * CArray.int32(dim0, dim1, ...) { ... } -> CArray
778
- * CArray.uint32(dim0, dim1, ...) { ... } -> CArray
779
- * CArray.int64(dim0, dim1, ...) { ... } -> CArray
780
- * CArray.uint64(dim0, dim1, ...) { ... } -> CArray
781
- * CArray.float32(dim0, dim1, ...) { ... } -> CArray
782
- * CArray.float64(dim0, dim1, ...) { ... } -> CArray
783
- * CArray.float128(dim0, dim1, ...) { ... } -> CArray
784
- * CArray.cmplx64(dim0, dim1, ...) { ... } -> CArray
785
- * CArray.cmplx128(dim0, dim1, ...) { ... } -> CArray
786
- * CArray.cmplx256(dim0, dim1, ...) { ... } -> CArray
787
- * CArray.object(dim0, dim1, ...) { ... } -> CArray
788
- *
789
- */
784
+ /* @overload boolean(*dim) { ... }
785
+
786
+ (Construction)
787
+ Short-Hand of `CArray.new(:boolean, dim, bytes: bytes) { ... }`
788
+ */
789
+ static VALUE rb_ca_s_boolean (int argc, VALUE *argv, VALUE klass)
790
+ {
791
+ rb_ca_s_body(CA_BOOLEAN);
792
+ }
793
+
794
+ /* @overload int8(*dim) { ... }
795
+
796
+ (Construction)
797
+ Short-Hand of `CArray.new(:int8, dim, bytes: bytes) { ... }`
798
+ */
799
+ static VALUE rb_ca_s_int8 (int argc, VALUE *argv, VALUE klass)
800
+ {
801
+ rb_ca_s_body(CA_INT8);
802
+ }
803
+
804
+ /* @overload uint8(*dim) { ... }
805
+
806
+ (Construction)
807
+ Short-Hand of `CArray.new(:uint8, dim, bytes: bytes) { ... }`
808
+ */
809
+ static VALUE rb_ca_s_uint8 (int argc, VALUE *argv, VALUE klass)
810
+ {
811
+ rb_ca_s_body(CA_UINT8);
812
+ }
813
+
814
+ /* @overload int16(*dim) { ... }
815
+
816
+ (Construction)
817
+ Short-Hand of `CArray.new(:int16, dim, bytes: bytes) { ... }`
818
+ */
819
+ static VALUE rb_ca_s_int16 (int argc, VALUE *argv, VALUE klass)
820
+ {
821
+ rb_ca_s_body(CA_INT16);
822
+ }
823
+
824
+ /* @overload uint16(*dim) { ... }
825
+
826
+ (Construction)
827
+ Short-Hand of `CArray.new(:uint16, dim, bytes: bytes) { ... }`
828
+ */
829
+ static VALUE rb_ca_s_uint16 (int argc, VALUE *argv, VALUE klass)
830
+ {
831
+ rb_ca_s_body(CA_UINT16);
832
+ }
833
+
834
+ /* @overload int32(*dim) { ... }
835
+
836
+ (Construction)
837
+ Short-Hand of `CArray.new(:int32, dim, bytes: bytes) { ... }`
838
+ */
839
+ static VALUE rb_ca_s_int32 (int argc, VALUE *argv, VALUE klass)
840
+ {
841
+ rb_ca_s_body(CA_INT32);
842
+ }
843
+
844
+ /* @overload uint32(*dim) { ... }
845
+
846
+ (Construction)
847
+ Short-Hand of `CArray.new(:uint32, dim, bytes: bytes) { ... }`
848
+ */
849
+ static VALUE rb_ca_s_uint32 (int argc, VALUE *argv, VALUE klass)
850
+ {
851
+ rb_ca_s_body(CA_UINT32);
852
+ }
853
+
854
+ /* @overload int64(*dim) { ... }
855
+
856
+ (Construction)
857
+ Short-Hand of `CArray.new(:int64, dim, bytes: bytes) { ... }`
858
+ */
859
+ static VALUE rb_ca_s_int64 (int argc, VALUE *argv, VALUE klass)
860
+ {
861
+ rb_ca_s_body(CA_INT64);
862
+ }
863
+
864
+ /* @overload uint64(*dim) { ... }
865
+
866
+ (Construction)
867
+ Short-Hand of `CArray.new(:uint64, dim, bytes: bytes) { ... }`
868
+ */
869
+ static VALUE rb_ca_s_uint64 (int argc, VALUE *argv, VALUE klass)
870
+ {
871
+ rb_ca_s_body(CA_UINT64);
872
+ }
873
+
874
+ /* @overload float32(*dim) { ... }
875
+
876
+ (Construction)
877
+ Short-Hand of `CArray.new(:float32, dim, bytes: bytes) { ... }`
878
+ */
879
+ static VALUE rb_ca_s_float32 (int argc, VALUE *argv, VALUE klass)
880
+ {
881
+ rb_ca_s_body(CA_FLOAT32);
882
+ }
883
+
884
+ /* @overload float64(*dim) { ... }
885
+
886
+ (Construction)
887
+ Short-Hand of `CArray.new(:float64, dim, bytes: bytes) { ... }`
888
+ */
889
+ static VALUE rb_ca_s_float64 (int argc, VALUE *argv, VALUE klass)
890
+ {
891
+ rb_ca_s_body(CA_FLOAT64);
892
+ }
893
+
894
+ /* @overload float128(*dim) { ... }
895
+
896
+ (Construction)
897
+ Short-Hand of `CArray.new(:float128, dim, bytes: bytes) { ... }`
898
+ */
899
+ static VALUE rb_ca_s_float128 (int argc, VALUE *argv, VALUE klass)
900
+ {
901
+ rb_ca_s_body(CA_FLOAT128);
902
+ }
790
903
 
791
- static VALUE rb_ca_s_VALUE();
792
-
793
- static VALUE rb_ca_s_type(boolean, CA_BOOLEAN);
794
- static VALUE rb_ca_s_type(int8, CA_INT8);
795
- static VALUE rb_ca_s_type(uint8, CA_UINT8);
796
- static VALUE rb_ca_s_type(int16, CA_INT16);
797
- static VALUE rb_ca_s_type(uint16, CA_UINT16);
798
- static VALUE rb_ca_s_type(int32, CA_INT32);
799
- static VALUE rb_ca_s_type(uint32, CA_UINT32);
800
- static VALUE rb_ca_s_type(int64, CA_INT64);
801
- static VALUE rb_ca_s_type(uint64, CA_UINT64);
802
- static VALUE rb_ca_s_type(float32, CA_FLOAT32);
803
- static VALUE rb_ca_s_type(float64, CA_FLOAT64);
804
- static VALUE rb_ca_s_type(float128, CA_FLOAT128);
805
904
  #ifdef HAVE_COMPLEX_H
806
- static VALUE rb_ca_s_type(cmplx64, CA_CMPLX64);
807
- static VALUE rb_ca_s_type(cmplx128, CA_CMPLX128);
808
- static VALUE rb_ca_s_type(cmplx256, CA_CMPLX256);
905
+ /* @overload cmplx64(*dim) { ... }
906
+
907
+ (Construction)
908
+ Short-Hand of `CArray.new(:cmplx64, dim, bytes: bytes) { ... }`
909
+ */
910
+ static VALUE rb_ca_s_cmplx64 (int argc, VALUE *argv, VALUE klass)
911
+ {
912
+ rb_ca_s_body(CA_CMPLX64);
913
+ }
914
+
915
+ /* @overload cmplx128(*dim) { ... }
916
+
917
+ (Construction)
918
+ Short-Hand of `CArray.new(:cmplx128, dim, bytes: bytes) { ... }`
919
+ */
920
+ static VALUE rb_ca_s_cmplx128 (int argc, VALUE *argv, VALUE klass)
921
+ {
922
+ rb_ca_s_body(CA_CMPLX128);
923
+ }
924
+
925
+ /* @overload cmplx256(*dim) { ... }
926
+
927
+ (Construction)
928
+ Short-Hand of `CArray.new(:cmplx256, dim, bytes: bytes) { ... }`
929
+ */
930
+ static VALUE rb_ca_s_cmplx256 (int argc, VALUE *argv, VALUE klass)
931
+ {
932
+ rb_ca_s_body(CA_CMPLX256);
933
+ }
809
934
  #endif
810
- static VALUE rb_ca_s_type(VALUE, CA_OBJECT);
811
935
 
936
+ /* @overload object(*dim) { ... }
937
+
938
+ (Construction)
939
+ Short-Hand of `CArray.new(:object, dim, bytes: bytes) { ... }`
940
+ */
941
+ static VALUE rb_ca_s_VALUE (int argc, VALUE *argv, VALUE klass)
942
+ {
943
+ rb_ca_s_body(CA_OBJECT);
944
+ }
945
+
946
+ /* @overload initialize_copy(other)
947
+
948
+ */
812
949
  static VALUE
813
950
  rb_ca_initialize_copy (VALUE self, VALUE other)
814
951
  {
@@ -820,16 +957,17 @@ rb_ca_initialize_copy (VALUE self, VALUE other)
820
957
  Data_Get_Struct(other, CArray, cs);
821
958
 
822
959
  ca_update_mask(cs);
823
- carray_setup(ca, cs->data_type, cs->rank, cs->dim, cs->bytes, cs->mask);
960
+ carray_setup(ca, cs->data_type, cs->ndim, cs->dim, cs->bytes, cs->mask);
824
961
 
825
962
  memcpy(ca->ptr, cs->ptr, ca_length(cs));
826
963
 
827
964
  return self;
828
965
  }
829
966
 
830
- /* rdoc:
831
- def CArray.wrap (data_type, dim, bytes=0) # { wrapped_object }
832
- end
967
+ /* @overload wrap (data_type, dim, bytes=0) { target }
968
+
969
+ [TBD] (Construction)
970
+ target should have method "wrap_as_carray(obj)"
833
971
  */
834
972
 
835
973
  static VALUE
@@ -837,7 +975,7 @@ rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
837
975
  {
838
976
  volatile VALUE obj, target, rtype, rdim, ropt, rbytes = Qnil;
839
977
  CArray *ca;
840
- int8_t data_type, rank;
978
+ int8_t data_type, ndim;
841
979
  ca_size_t dim[CA_RANK_MAX];
842
980
  ca_size_t bytes;
843
981
  int8_t i;
@@ -848,15 +986,15 @@ rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
848
986
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
849
987
 
850
988
  Check_Type(rdim, T_ARRAY);
851
- rank = RARRAY_LEN(rdim);
852
- for (i=0; i<rank; i++) {
989
+ ndim = RARRAY_LEN(rdim);
990
+ for (i=0; i<ndim; i++) {
853
991
  dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
854
992
  }
855
993
 
856
994
  target = rb_yield_values(0);
857
995
 
858
996
  obj = Data_Make_Struct(rb_cCAWrap, CAWrap, ca_mark, ca_free, ca);
859
- ca_wrap_setup_null(ca, data_type, rank, dim, bytes, NULL);
997
+ ca_wrap_setup_null(ca, data_type, ndim, dim, bytes, NULL);
860
998
 
861
999
  rb_funcall(target, rb_intern("wrap_as_carray"), 1, obj);
862
1000
  rb_ivar_set(obj, rb_intern("referred_object"), target);
@@ -865,13 +1003,13 @@ rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
865
1003
  }
866
1004
 
867
1005
  VALUE
868
- rb_carray_wrap_ptr (int8_t data_type, int8_t rank, ca_size_t *dim,
1006
+ rb_carray_wrap_ptr (int8_t data_type, int8_t ndim, ca_size_t *dim,
869
1007
  ca_size_t bytes, CArray *mask, char *ptr, VALUE refer)
870
1008
  {
871
1009
  volatile VALUE obj;
872
1010
  CArray *ca;
873
1011
 
874
- ca = ca_wrap_new(data_type, rank, dim, bytes, mask, ptr);
1012
+ ca = ca_wrap_new(data_type, ndim, dim, bytes, mask, ptr);
875
1013
  obj = ca_wrap_struct(ca);
876
1014
 
877
1015
  rb_ivar_set(obj, rb_intern("referred_object"), refer);
@@ -888,16 +1026,16 @@ rb_cs_s_allocate (VALUE klass)
888
1026
  return Data_Make_Struct(klass, CScalar, ca_mark, ca_free, ca);
889
1027
  }
890
1028
 
891
- /* rdoc:
892
- # call-seq:
893
- # CScalar.new(data_type, bytes=0) { ... }
894
- #
895
- # Constructs a new CScalar object of <i>data_type</i>.
896
- # The byte size of each element for the fixed length data type
897
- # (<code>data_type == CA_FIXLEN</code>) is specified optional argument
898
- # <i>bytes</i>. Otherwise, this optional argument has no
899
- # effect. If the block is given, the new CScalar
900
- # object will be initialized by the value returned from the block.
1029
+ /*
1030
+ call-seq:
1031
+ CScalar.new(data_type, bytes=0) { ... }
1032
+
1033
+ Constructs a new CScalar object of <i>data_type</i>.
1034
+ The byte size of each element for the fixed length data type
1035
+ (<code>data_type == CA_FIXLEN</code>) is specified optional argument
1036
+ <i>bytes</i>. Otherwise, this optional argument has no
1037
+ effect. If the block is given, the new CScalar
1038
+ object will be initialized by the value returned from the block.
901
1039
  def CScalar.new(data_type,bytes=0)
902
1040
  end
903
1041
  */
@@ -929,6 +1067,12 @@ rb_cs_initialize (int argc, VALUE *argv, VALUE self)
929
1067
  return Qnil;
930
1068
  }
931
1069
 
1070
+ /* @overload fixlen(*dim, bytes: ) { ... }
1071
+
1072
+ (Construction)
1073
+ Short-Hand of `CScalar.new(:fixlen, bytes: ) { ... }`
1074
+ */
1075
+
932
1076
  static VALUE
933
1077
  rb_cs_s_fixlen (int argc, VALUE *argv, VALUE klass)
934
1078
  {
@@ -940,8 +1084,7 @@ rb_cs_s_fixlen (int argc, VALUE *argv, VALUE klass)
940
1084
  return rb_class_new_instance(2, args, klass);
941
1085
  }
942
1086
 
943
- #define rb_cs_s_type(type, code) \
944
- rb_cs_s_## type (int argc, VALUE *argv, VALUE klass) \
1087
+ #define rb_cs_s_body(code) \
945
1088
  { \
946
1089
  volatile VALUE ropt = rb_pop_options(&argc, &argv); \
947
1090
  VALUE args[2] = { INT2NUM(code), ropt }; \
@@ -951,47 +1094,172 @@ rb_cs_s_## type (int argc, VALUE *argv, VALUE klass) \
951
1094
  return rb_class_new_instance(2, args, klass); \
952
1095
  }
953
1096
 
954
- static VALUE rb_cs_s_type(boolean, CA_BOOLEAN);
955
- static VALUE rb_cs_s_type(int8, CA_INT8);
956
- static VALUE rb_cs_s_type(uint8, CA_UINT8);
957
- static VALUE rb_cs_s_type(int16, CA_INT16);
958
- static VALUE rb_cs_s_type(uint16, CA_UINT16);
959
- static VALUE rb_cs_s_type(int32, CA_INT32);
960
- static VALUE rb_cs_s_type(uint32, CA_UINT32);
961
- static VALUE rb_cs_s_type(int64, CA_INT64);
962
- static VALUE rb_cs_s_type(uint64, CA_UINT64);
963
- static VALUE rb_cs_s_type(float32, CA_FLOAT32);
964
- static VALUE rb_cs_s_type(float64, CA_FLOAT64);
965
- static VALUE rb_cs_s_type(float128, CA_FLOAT128);
1097
+ /* @overload boolean() { ... }
1098
+
1099
+ (Construction)
1100
+ Short-Hand of `CArray.new(:boolean) { ... }`
1101
+ */
1102
+ static VALUE
1103
+ rb_cs_s_boolean (int argc, VALUE *argv, VALUE klass) {
1104
+ rb_cs_s_body(CA_BOOLEAN);
1105
+ }
1106
+
1107
+ /* @overload int8() { ... }
1108
+
1109
+ (Construction)
1110
+ Short-Hand of `CScalar.new(:int8) { ... }`
1111
+ */
1112
+ static VALUE
1113
+ rb_cs_s_int8 (int argc, VALUE *argv, VALUE klass) {
1114
+ rb_cs_s_body(CA_INT8);
1115
+ }
1116
+
1117
+ /* @overload uint8() { ... }
1118
+
1119
+ (Construction)
1120
+ Short-Hand of `CScalar.new(:uint8) { ... }`
1121
+ */
1122
+ static VALUE
1123
+ rb_cs_s_uint8 (int argc, VALUE *argv, VALUE klass) {
1124
+ rb_cs_s_body(CA_UINT8);
1125
+ }
1126
+
1127
+
1128
+ /* @overload int16() { ... }
1129
+
1130
+ (Construction)
1131
+ Short-Hand of `CScalar.new(:int16) { ... }`
1132
+ */
1133
+ static VALUE
1134
+ rb_cs_s_int16 (int argc, VALUE *argv, VALUE klass) {
1135
+ rb_cs_s_body(CA_INT16);
1136
+ }
1137
+
1138
+ /* @overload uint16() { ... }
1139
+
1140
+ (Construction)
1141
+ Short-Hand of `CScalar.new(:uint16) { ... }`
1142
+ */
1143
+ static VALUE
1144
+ rb_cs_s_uint16 (int argc, VALUE *argv, VALUE klass) {
1145
+ rb_cs_s_body(CA_UINT16);
1146
+ }
1147
+
1148
+ /* @overload int32() { ... }
1149
+
1150
+ (Construction)
1151
+ Short-Hand of `CScalar.new(:int32) { ... }`
1152
+ */
1153
+ static VALUE
1154
+ rb_cs_s_int32 (int argc, VALUE *argv, VALUE klass) {
1155
+ rb_cs_s_body(CA_INT32);
1156
+ }
1157
+
1158
+ /* @overload uint32() { ... }
1159
+
1160
+ (Construction)
1161
+ Short-Hand of `CScalar.new(:uint32) { ... }`
1162
+ */
1163
+ static VALUE
1164
+ rb_cs_s_uint32 (int argc, VALUE *argv, VALUE klass) {
1165
+ rb_cs_s_body(CA_UINT32);
1166
+ }
1167
+
1168
+ /* @overload int64() { ... }
1169
+
1170
+ (Construction)
1171
+ Short-Hand of `CScalar.new(:int64) { ... }`
1172
+ */
1173
+ static VALUE
1174
+ rb_cs_s_int64 (int argc, VALUE *argv, VALUE klass) {
1175
+ rb_cs_s_body(CA_INT64);
1176
+ }
1177
+
1178
+ /* @overload uint64() { ... }
1179
+
1180
+ (Construction)
1181
+ Short-Hand of `CScalar.new(:uint64) { ... }`
1182
+ */
1183
+ static VALUE
1184
+ rb_cs_s_uint64 (int argc, VALUE *argv, VALUE klass) {
1185
+ rb_cs_s_body(CA_UINT64);
1186
+ }
1187
+
1188
+ /* @overload float32() { ... }
1189
+
1190
+ (Construction)
1191
+ Short-Hand of `CScalar.new(:float32) { ... }`
1192
+ */
1193
+ static VALUE
1194
+ rb_cs_s_float32 (int argc, VALUE *argv, VALUE klass) {
1195
+ rb_cs_s_body(CA_FLOAT32);
1196
+ }
1197
+
1198
+ /* @overload float64() { ... }
1199
+
1200
+ (Construction)
1201
+ Short-Hand of `CScalar.new(:float64) { ... }`
1202
+ */
1203
+ static VALUE
1204
+ rb_cs_s_float64 (int argc, VALUE *argv, VALUE klass) {
1205
+ rb_cs_s_body(CA_FLOAT64);
1206
+ }
1207
+
1208
+ /* @overload float128() { ... }
1209
+
1210
+ (Construction)
1211
+ Short-Hand of `CScalar.new(:float128) { ... }`
1212
+ */
1213
+ static VALUE
1214
+ rb_cs_s_float128 (int argc, VALUE *argv, VALUE klass) {
1215
+ rb_cs_s_body(CA_FLOAT128);
1216
+ }
1217
+
966
1218
  #ifdef HAVE_COMPLEX_H
967
- static VALUE rb_cs_s_type(cmplx64, CA_CMPLX64);
968
- static VALUE rb_cs_s_type(cmplx128, CA_CMPLX128);
969
- static VALUE rb_cs_s_type(cmplx256, CA_CMPLX256);
1219
+ /* @overload cmplx64() { ... }
1220
+
1221
+ (Construction)
1222
+ Short-Hand of `CScalar.new(:cmplx64) { ... }`
1223
+ */
1224
+ static VALUE
1225
+ rb_cs_s_cmplx64 (int argc, VALUE *argv, VALUE klass) {
1226
+ rb_cs_s_body(CA_CMPLX64);
1227
+ }
1228
+
1229
+ /* @overload cmplx128() { ... }
1230
+
1231
+ (Construction)
1232
+ Short-Hand of `CScalar.new(:cmplx128) { ... }`
1233
+ */
1234
+ static VALUE
1235
+ rb_cs_s_cmplx128 (int argc, VALUE *argv, VALUE klass) {
1236
+ rb_cs_s_body(CA_CMPLX128);
1237
+ }
1238
+
1239
+ /* @overload cmplx256() { ... }
1240
+
1241
+ (Construction)
1242
+ Short-Hand of `CScalar.new(:cmplx256) { ... }`
1243
+ */
1244
+ static VALUE
1245
+ rb_cs_s_cmplx256 (int argc, VALUE *argv, VALUE klass) {
1246
+ rb_cs_s_body(CA_CMPLX256);
1247
+ }
970
1248
  #endif
971
- static VALUE rb_cs_s_type(VALUE, CA_OBJECT);
972
1249
 
973
- /*
974
- * call-seq:
975
- * CScalar.int8() { ... } -> CScalar
976
- * CScalar.uint8() { ... } -> CScalar
977
- * CScalar.int16() { ... } -> CScalar
978
- * CScalar.uint16() { ... } -> CScalar
979
- * CScalar.int32() { ... } -> CScalar
980
- * CScalar.uint32() { ... } -> CScalar
981
- * CScalar.int64() { ... } -> CScalar
982
- * CScalar.uint64() { ... } -> CScalar
983
- * CScalar.float32() { ... } -> CScalar
984
- * CScalar.float64() { ... } -> CScalar
985
- * CScalar.float128() { ... } -> CScalar
986
- * CScalar.cmplx64() { ... } -> CScalar
987
- * CScalar.cmplx128() { ... } -> CScalar
988
- * CScalar.cmplx256() { ... } -> CScalar
989
- * CScalar.object() { ... } -> CScalar
990
- *
991
- */
1250
+ /* @overload object() { ... }
992
1251
 
993
- static VALUE
994
- rb_cs_s_VALUE();
1252
+ (Construction)
1253
+ Short-Hand of `CScalar.new(:object) { ... }`
1254
+ */
1255
+ static VALUE
1256
+ rb_cs_s_VALUE (int argc, VALUE *argv, VALUE klass) {
1257
+ rb_cs_s_body(CA_OBJECT);
1258
+ }
1259
+
1260
+ /* @overload initialize_copy(other)
1261
+
1262
+ */
995
1263
 
996
1264
  static VALUE
997
1265
  rb_cs_initialize_copy (VALUE self, VALUE other)
@@ -1026,6 +1294,10 @@ rb_cs_coerce (VALUE self, VALUE other)
1026
1294
  }
1027
1295
  */
1028
1296
 
1297
+ /* @private
1298
+ @overload mem_usage
1299
+ */
1300
+
1029
1301
  static VALUE
1030
1302
  rb_ca_mem_usage (VALUE self)
1031
1303
  {
@@ -1041,7 +1313,10 @@ Init_ca_obj_array ()
1041
1313
 
1042
1314
  /* ------------------------------------------------------------------- */
1043
1315
  ca_gc_interval = ca_default_gc_interval;
1316
+
1317
+ /* @private */
1044
1318
  rb_define_const(rb_cCArray, "DEFAULT_GC_INTERVAL", rb_float_new(ca_default_gc_interval));
1319
+
1045
1320
  rb_define_singleton_method(rb_cCArray, "gc_interval", rb_ca_get_gc_interval, 0);
1046
1321
  rb_define_singleton_method(rb_cCArray, "gc_interval=", rb_ca_set_gc_interval, 1);
1047
1322
  rb_define_singleton_method(rb_cCArray, "reset_gc_interval", rb_ca_reset_gc_interval, 0);
@@ -1130,7 +1405,7 @@ Init_ca_obj_array ()
1130
1405
  }
1131
1406
 
1132
1407
 
1133
- /* rdoc:
1408
+ /* yard:
1134
1409
  # call-seq:
1135
1410
  # CArray.boolean(...) { init_value }
1136
1411
  # CArray.int8(...) { init_value }