carray 1.5.1 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/{LICENSES → LICENSE} +0 -0
  4. data/NEWS.md +83 -0
  5. data/README.md +34 -18
  6. data/Rakefile +1 -1
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +10 -7
  9. data/ext/ca_iter_block.c +3 -5
  10. data/ext/ca_iter_dimension.c +4 -5
  11. data/ext/ca_iter_window.c +2 -4
  12. data/ext/ca_obj_array.c +394 -124
  13. data/ext/ca_obj_bitarray.c +6 -11
  14. data/ext/ca_obj_bitfield.c +5 -9
  15. data/ext/ca_obj_block.c +5 -12
  16. data/ext/ca_obj_fake.c +3 -5
  17. data/ext/ca_obj_farray.c +3 -5
  18. data/ext/ca_obj_field.c +15 -17
  19. data/ext/ca_obj_grid.c +5 -6
  20. data/ext/ca_obj_mapping.c +2 -4
  21. data/ext/ca_obj_object.c +3 -5
  22. data/ext/ca_obj_reduce.c +2 -4
  23. data/ext/ca_obj_refer.c +11 -15
  24. data/ext/ca_obj_repeat.c +2 -4
  25. data/ext/ca_obj_select.c +2 -4
  26. data/ext/ca_obj_shift.c +3 -5
  27. data/ext/ca_obj_transpose.c +3 -5
  28. data/ext/ca_obj_unbound_repeat.c +68 -122
  29. data/ext/ca_obj_window.c +7 -9
  30. data/ext/carray.h +17 -8
  31. data/ext/carray_access.c +183 -58
  32. data/ext/carray_attribute.c +151 -197
  33. data/ext/carray_call_cfunc.c +1 -3
  34. data/ext/carray_cast.c +345 -144
  35. data/ext/carray_cast_func.rb +1 -2
  36. data/ext/carray_class.c +28 -36
  37. data/ext/carray_conversion.c +56 -59
  38. data/ext/carray_copy.c +16 -32
  39. data/ext/carray_core.c +73 -60
  40. data/ext/carray_element.c +25 -44
  41. data/ext/carray_generate.c +74 -53
  42. data/ext/carray_iterator.c +13 -15
  43. data/ext/carray_loop.c +53 -82
  44. data/ext/carray_mask.c +99 -119
  45. data/ext/carray_math.rb +28 -12
  46. data/ext/carray_mathfunc.c +1 -3
  47. data/ext/carray_numeric.c +42 -45
  48. data/ext/carray_operator.c +45 -32
  49. data/ext/carray_order.c +231 -65
  50. data/ext/carray_sort_addr.c +14 -21
  51. data/ext/carray_stat.c +1 -3
  52. data/ext/carray_stat_proc.rb +2 -4
  53. data/ext/carray_test.c +41 -30
  54. data/ext/carray_undef.c +1 -11
  55. data/ext/carray_utils.c +138 -51
  56. data/ext/extconf.rb +14 -2
  57. data/ext/mkmath.rb +2 -2
  58. data/ext/ruby_carray.c +15 -7
  59. data/ext/ruby_ccomplex.c +2 -4
  60. data/ext/ruby_float_func.c +1 -3
  61. data/ext/version.h +5 -7
  62. data/lib/carray.rb +9 -9
  63. data/lib/carray/autoload.rb +0 -2
  64. data/lib/carray/autoload/autoload_gem_numo_narray.rb +6 -6
  65. data/lib/carray/basic.rb +1 -3
  66. data/lib/carray/broadcast.rb +101 -0
  67. data/lib/carray/compose.rb +34 -10
  68. data/lib/carray/construct.rb +57 -18
  69. data/lib/carray/info.rb +1 -3
  70. data/lib/carray/inspect.rb +3 -5
  71. data/lib/carray/io/imagemagick.rb +1 -3
  72. data/lib/carray/iterator.rb +3 -3
  73. data/lib/carray/mask.rb +18 -7
  74. data/lib/carray/math.rb +4 -6
  75. data/lib/carray/math/histogram.rb +1 -3
  76. data/lib/carray/math/recurrence.rb +1 -3
  77. data/lib/carray/mkmf.rb +1 -3
  78. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  79. data/lib/carray/object/ca_obj_link.rb +1 -3
  80. data/lib/carray/object/ca_obj_pack.rb +1 -3
  81. data/lib/carray/obsolete.rb +1 -17
  82. data/lib/carray/ordering.rb +29 -5
  83. data/lib/carray/serialize.rb +34 -25
  84. data/lib/carray/string.rb +1 -3
  85. data/lib/carray/struct.rb +3 -5
  86. data/lib/carray/testing.rb +5 -10
  87. data/lib/carray/time.rb +1 -3
  88. data/lib/carray/transform.rb +12 -3
  89. data/misc/NOTE +16 -38
  90. data/spec/Classes/CABitfield_spec.rb +58 -0
  91. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  92. data/spec/Classes/CABlock_spec.rb +205 -0
  93. data/spec/Classes/CAField_spec.rb +39 -0
  94. data/spec/Classes/CAGrid_spec.rb +75 -0
  95. data/spec/Classes/CAMap_spec.rb +0 -0
  96. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  97. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  98. data/spec/Classes/CAObject_spec.rb +33 -0
  99. data/spec/Classes/CARefer_spec.rb +93 -0
  100. data/spec/Classes/CARepeat_spec.rb +65 -0
  101. data/spec/Classes/CASelect_spec.rb +22 -0
  102. data/spec/Classes/CAShift_spec.rb +16 -0
  103. data/spec/Classes/CAStruct_spec.rb +71 -0
  104. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  105. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  106. data/spec/Classes/CAWindow_spec.rb +54 -0
  107. data/spec/Classes/CAWrap_spec.rb +8 -0
  108. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  109. data/spec/Classes/CScalar_spec.rb +55 -0
  110. data/spec/Features/feature_130_spec.rb +19 -0
  111. data/spec/Features/feature_attributes_spec.rb +280 -0
  112. data/spec/Features/feature_boolean_spec.rb +98 -0
  113. data/spec/Features/feature_broadcast.rb +116 -0
  114. data/spec/Features/feature_cast_function.rb +19 -0
  115. data/spec/Features/feature_cast_spec.rb +33 -0
  116. data/spec/Features/feature_class_spec.rb +84 -0
  117. data/spec/Features/feature_complex_spec.rb +42 -0
  118. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  119. data/spec/Features/feature_convert_spec.rb +46 -0
  120. data/spec/Features/feature_copy_spec.rb +123 -0
  121. data/spec/Features/feature_creation_spec.rb +84 -0
  122. data/spec/Features/feature_element_spec.rb +144 -0
  123. data/spec/Features/feature_extream_spec.rb +54 -0
  124. data/spec/Features/feature_generate_spec.rb +74 -0
  125. data/spec/Features/feature_index_spec.rb +69 -0
  126. data/spec/Features/feature_mask_spec.rb +580 -0
  127. data/spec/Features/feature_math_spec.rb +97 -0
  128. data/spec/Features/feature_order_spec.rb +146 -0
  129. data/spec/Features/feature_ref_store_spec.rb +209 -0
  130. data/spec/Features/feature_serialization_spec.rb +125 -0
  131. data/spec/Features/feature_stat_spec.rb +397 -0
  132. data/spec/Features/feature_virtual_spec.rb +48 -0
  133. data/spec/Features/method_eq_spec.rb +81 -0
  134. data/spec/Features/method_is_nan_spec.rb +12 -0
  135. data/spec/Features/method_map_spec.rb +54 -0
  136. data/spec/Features/method_max_with.rb +20 -0
  137. data/spec/Features/method_min_with.rb +19 -0
  138. data/spec/Features/method_ne_spec.rb +18 -0
  139. data/spec/Features/method_project_spec.rb +188 -0
  140. data/spec/Features/method_ref_spec.rb +27 -0
  141. data/spec/Features/method_round_spec.rb +11 -0
  142. data/spec/Features/method_s_linspace_spec.rb +48 -0
  143. data/spec/Features/method_s_span_spec.rb +14 -0
  144. data/spec/Features/method_seq_spec.rb +47 -0
  145. data/spec/Features/method_sort_with.rb +43 -0
  146. data/spec/Features/method_sorted_with.rb +29 -0
  147. data/spec/Features/method_span_spec.rb +42 -0
  148. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  149. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  150. data/spec/spec_all.rb +0 -1
  151. data/utils/convert_test.rb +73 -0
  152. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  153. metadata +74 -58
  154. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  155. data/spec/CArray/bug/store_spec.rb +0 -27
  156. data/spec/CArray/index/repeat_spec.rb +0 -10
  157. data/spec/CArray/method/eq_spec.rb +0 -80
  158. data/spec/CArray/method/is_nan_spec.rb +0 -12
  159. data/spec/CArray/method/ne_spec.rb +0 -18
  160. data/spec/CArray/method/round_spec.rb +0 -11
  161. data/spec/CArray/object/_attribute_spec.rb +0 -32
  162. data/spec/CArray/object/s_new_spec.rb +0 -31
  163. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  164. data/test/test_130.rb +0 -23
  165. data/test/test_ALL.rb +0 -49
  166. data/test/test_CABitfield.rb +0 -59
  167. data/test/test_CABlock.rb +0 -208
  168. data/test/test_CAField.rb +0 -40
  169. data/test/test_CAGrid.rb +0 -76
  170. data/test/test_CAMmap.rb +0 -11
  171. data/test/test_CARefer.rb +0 -94
  172. data/test/test_CARepeat.rb +0 -66
  173. data/test/test_CASelect.rb +0 -23
  174. data/test/test_CAShift.rb +0 -17
  175. data/test/test_CAWindow.rb +0 -55
  176. data/test/test_CAWrap.rb +0 -9
  177. data/test/test_CComplex.rb +0 -83
  178. data/test/test_CScalar.rb +0 -91
  179. data/test/test_attribute.rb +0 -281
  180. data/test/test_block_iterator.rb +0 -17
  181. data/test/test_boolean.rb +0 -99
  182. data/test/test_cast.rb +0 -33
  183. data/test/test_class.rb +0 -85
  184. data/test/test_complex.rb +0 -43
  185. data/test/test_convert.rb +0 -79
  186. data/test/test_copy.rb +0 -141
  187. data/test/test_creation.rb +0 -85
  188. data/test/test_element.rb +0 -146
  189. data/test/test_extream.rb +0 -55
  190. data/test/test_generate.rb +0 -75
  191. data/test/test_index.rb +0 -71
  192. data/test/test_mask.rb +0 -578
  193. data/test/test_math.rb +0 -98
  194. data/test/test_order.rb +0 -147
  195. data/test/test_ref_store.rb +0 -211
  196. data/test/test_stat.rb +0 -406
  197. data/test/test_struct.rb +0 -72
  198. data/test/test_virtual.rb +0 -49
@@ -161,8 +161,7 @@ puts %{
161
161
  the Ruby\'s licence.
162
162
 
163
163
  This file is automatically generated from carray_math.rb.
164
-
165
- Copyright (C) 2005 Hiroki Motoyoshi
164
+ Copyright (C) 2005-2020 Hiroki Motoyoshi
166
165
 
167
166
  ---------------------------------------------------------------------------- */
168
167
 
data/ext/carray_class.c CHANGED
@@ -3,22 +3,19 @@
3
3
  carray_class.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
- /* rdoc:
16
- # returns the machine endianness.
17
- # CArray.endian #=> 0 (CA_LITTLE_ENDIAN)
18
- # CArray.endian #=> 1 (CA_BIG_ENDIAN)
13
+ /* @overload endian
19
14
 
20
- def CArray.endian
21
- end
15
+ (Inquiry)
16
+ Returns the machine endianness.
17
+ 0 (CA_LITTLE_ENDIAN)
18
+ 1 (CA_BIG_ENDIAN)
22
19
  */
23
20
 
24
21
  static VALUE
@@ -27,12 +24,10 @@ rb_ca_s_endian (VALUE klass)
27
24
  return INT2NUM(ca_endian);
28
25
  }
29
26
 
30
- /* rdoc:
31
- # returns true if the byte order of the architecture is
32
- # big endian.
33
-
34
- def CArray.big_endian?
35
- end
27
+ /* @overload big_endian?
28
+
29
+ (Inquiry)
30
+ Returns true if the byte order of the architecture is big endian.
36
31
  */
37
32
 
38
33
  static VALUE
@@ -41,12 +36,11 @@ rb_ca_s_big_endian_p (VALUE klass)
41
36
  return ( ca_endian == CA_BIG_ENDIAN ) ? Qtrue : Qfalse;
42
37
  }
43
38
 
44
- /* rdoc:
45
- # returns true if the byte order of the architecture is
46
- # little endian.
39
+ /* @overload little_endian?
47
40
 
48
- def CArray.little_endian?
49
- end
41
+ (Inquiry)
42
+ Returns true if the byte order of the architecture is
43
+ little endian.
50
44
  */
51
45
 
52
46
  static VALUE
@@ -55,15 +49,15 @@ rb_ca_s_little_endian_p (VALUE klass)
55
49
  return ( ca_endian == CA_LITTLE_ENDIAN ) ? Qtrue : Qfalse;
56
50
  }
57
51
 
58
- /* rdoc:
59
- # Returns the byte length of an element of the given data type.
60
- # Retruns <code>0</code> if data_type is equal to CA_FIXLEN.
61
- # CArray.sizeof(CA_INT32) #=> 4
62
- # CArray.sizeof(CA_DOUBLE) #=> 8
63
- # CArray.sizeof(CA_FIXLEN) #=> 0
52
+ /* @overload sizeof (data_type)
53
+
54
+ (Inquiry)
55
+ Returns the byte length of an element of the given data type.
56
+ Retruns <code>0</code> if data_type is equal to CA_FIXLEN.
57
+ CArray.sizeof(CA_INT32) #=> 4
58
+ CArray.sizeof(CA_DOUBLE) #=> 8
59
+ CArray.sizeof(CA_FIXLEN) #=> 0
64
60
 
65
- def CArray.sizeof (data_type)
66
- end
67
61
  */
68
62
 
69
63
  static VALUE
@@ -76,11 +70,10 @@ rb_ca_s_sizeof (VALUE klass, VALUE rtype)
76
70
  }
77
71
 
78
72
 
79
- /* rdoc:
80
- # Returns true if the given data_type indicate the valid data_type.
73
+ /* @overload data_type?(data_type)
81
74
 
82
- def CArray.data_type?(data_type)
83
- end
75
+ (Inquiry)
76
+ Returns true if the given data_type indicate the valid data_type.
84
77
  */
85
78
 
86
79
  static VALUE
@@ -94,11 +87,10 @@ rb_ca_s_data_type (VALUE klass, VALUE rtype)
94
87
  return ca_valid[data_type] == 1 ? Qtrue : Qfalse;
95
88
  }
96
89
 
97
- /* rdoc:
98
- # Returns string representaion of the data_type specifier.
90
+ /* @overload data_type_name(data_type)
99
91
 
100
- def CArray.data_type_name(data_type)
101
- end
92
+ (Inquiry)
93
+ Returns string representaion of the data_type specifier.
102
94
  */
103
95
 
104
96
 
@@ -3,10 +3,8 @@
3
3
  carray_conversion.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
 
@@ -43,13 +41,12 @@ rb_ca_to_a_loop (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
43
41
  }
44
42
  }
45
43
 
46
- /* rdoc:
47
- class CArray
48
- # Converts the array to Ruby's array. For higher dimension,
49
- # the array is nested ndim-1 times.
50
- def to_a
51
- end
52
- end
44
+ /*
45
+ @overload to_a
46
+
47
+ (Conversion)
48
+ Converts the array to Ruby's array. For higher dimension,
49
+ the array is nested ndim-1 times.
53
50
  */
54
51
 
55
52
  VALUE
@@ -66,13 +63,12 @@ rb_ca_to_a (VALUE self)
66
63
  return ary;
67
64
  }
68
65
 
69
- /* rdoc:
70
- class CArray
71
- # Convert the
72
- def convert (data_type=nil, dim=nil)
73
- yield
74
- end
75
- end
66
+ /* @overload convert (data_type=nil, dim=nil) { |elem| ... }
67
+
68
+ (Conversion)
69
+ Returns new array which elements are caluculated
70
+ in the iteration block. The output array is internally created
71
+ using `CArray#template` to which the arguments is passed.
76
72
  */
77
73
 
78
74
  static VALUE
@@ -106,12 +102,10 @@ rb_ca_convert (int argc, VALUE *argv, VALUE self)
106
102
  return obj;
107
103
  }
108
104
 
109
- /* rdoc:
110
- class CArray
111
- # dumps the value array to the given IO stream
112
- def dump_binary(io)
113
- end
114
- end
105
+ /* @overload dump_binary
106
+
107
+ (IO)
108
+ Dumps the value array to the given IO stream
115
109
  */
116
110
 
117
111
  static VALUE
@@ -187,19 +181,10 @@ rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
187
181
  return io;
188
182
  }
189
183
 
190
- static VALUE
191
- rb_ca_dump (int argc, VALUE *argv, VALUE self)
192
- {
193
- rb_warn("CArray#dump will be obsolete, use CArray#dump_binary");
194
- return rb_ca_dump_binary(argc, argv, self);
195
- }
184
+ /* @overload to_s
196
185
 
197
- /* rdoc:
198
- class CArray
199
- # dumps the value array to a string.
200
- def to_s
201
- end
202
- end
186
+ (Conversion)
187
+ Dumps the value array to a string.
203
188
  */
204
189
 
205
190
  static VALUE
@@ -208,12 +193,10 @@ rb_ca_to_s (VALUE self)
208
193
  return rb_ca_dump_binary(0, NULL, self);
209
194
  }
210
195
 
211
- /* rdoc:
212
- class CArray
213
- # loads the value array from the given IO stream
214
- def load_binary (io)
215
- end
216
- end
196
+ /* @overload load_binary (io)
197
+
198
+ (IO)
199
+ Loads the value array from the given IO stream
217
200
  */
218
201
 
219
202
  static VALUE
@@ -256,13 +239,6 @@ rb_ca_load_binary (VALUE self, VALUE io)
256
239
  return self;
257
240
  }
258
241
 
259
- static VALUE
260
- rb_ca_load (VALUE self, VALUE io)
261
- {
262
- rb_warn("CArray#load will be obsolete, use CArray#load_binary");
263
- return rb_ca_load_binary(self, io);
264
- }
265
-
266
242
  void *
267
243
  ca_to_cptr (void *ap)
268
244
  {
@@ -314,13 +290,11 @@ ca_to_cptr (void *ap)
314
290
  }
315
291
 
316
292
 
317
- /* rdoc:
318
- class CArray
319
- # Convert the
320
- def convert (data_type=nil, dim=nil)
321
- yield
322
- end
323
- end
293
+ /* @overload str_format (*fmts)
294
+
295
+ (Conversion)
296
+ Creates object type array consist of string using the "::format" method.
297
+ The Multiple format strings are given, they are applied cyclic in turn.
324
298
  */
325
299
 
326
300
 
@@ -366,9 +340,17 @@ rb_ca_format (int argc, VALUE *argv, VALUE self)
366
340
  }
367
341
 
368
342
 
369
-
370
343
  #include <time.h>
371
344
 
345
+ #ifdef HAVE_STRPTIME
346
+
347
+ /* @overload str_strptime (fmt)
348
+
349
+ (Conversion)
350
+ Creates object type array consist of Time objects
351
+ which are created by 'Time.strptime' applied to the elements of the object.
352
+ This method assumes all the elements of the objetct to be String.
353
+ */
372
354
 
373
355
  static VALUE
374
356
  rb_ca_strptime (VALUE self, VALUE rfmt)
@@ -385,6 +367,7 @@ rb_ca_strptime (VALUE self, VALUE rfmt)
385
367
  rb_raise(rb_eRuntimeError, "strptime can be applied only to object type.");
386
368
  }
387
369
 
370
+ Check_Type(rfmt, T_STRING);
388
371
  fmt = (char *) StringValuePtr(rfmt);
389
372
 
390
373
  obj = rb_ca_template(self);
@@ -423,6 +406,15 @@ rb_ca_strptime (VALUE self, VALUE rfmt)
423
406
  return obj;
424
407
  }
425
408
 
409
+ #endif
410
+
411
+ /* @overload time_strftime (fmt)
412
+
413
+ (Conversion)
414
+ Creates object type array consist of strings
415
+ which are created by 'Time#strftime' applied to the elements of the object.
416
+ This method assumes all the elements of the objetct to be Time or DateTime.
417
+ */
426
418
 
427
419
  static VALUE
428
420
  rb_ca_strftime (VALUE self, VALUE rfmt)
@@ -463,6 +455,10 @@ rb_ca_strftime (VALUE self, VALUE rfmt)
463
455
  return obj;
464
456
  }
465
457
 
458
+ /* @private
459
+
460
+ */
461
+
466
462
  static VALUE
467
463
  rb_test_ca_to_cptr (VALUE self)
468
464
  {
@@ -497,10 +493,8 @@ Init_carray_conversion ()
497
493
  rb_define_method(rb_cCArray, "to_a", rb_ca_to_a, 0);
498
494
  rb_define_method(rb_cCArray, "convert", rb_ca_convert, -1);
499
495
 
500
- rb_define_method(rb_cCArray, "dump", rb_ca_dump, -1);
501
496
  rb_define_method(rb_cCArray, "dump_binary", rb_ca_dump_binary, -1);
502
497
  rb_define_method(rb_cCArray, "to_s", rb_ca_to_s, 0);
503
- rb_define_method(rb_cCArray, "load", rb_ca_load, 1);
504
498
  rb_define_method(rb_cCArray, "load_binary", rb_ca_load_binary, 1);
505
499
 
506
500
  /* DO NOT define CArray#to_ary, it makes trouble with various situations */
@@ -508,8 +502,11 @@ Init_carray_conversion ()
508
502
 
509
503
  rb_define_method(rb_cCArray, "str_format", rb_ca_format, -1);
510
504
 
505
+ #ifdef HAVE_STRPTIME
511
506
  rb_define_method(rb_cCArray, "str_strptime", rb_ca_strptime, 1);
512
- rb_define_method(rb_cCArray, "str_strftime", rb_ca_strftime, 1);
507
+ #endif
508
+
509
+ rb_define_method(rb_cCArray, "time_strftime", rb_ca_strftime, 1);
513
510
 
514
511
  rb_define_method(rb_cCArray, "test_ca_to_cptr", rb_test_ca_to_cptr, 0);
515
512
 
data/ext/carray_copy.c CHANGED
@@ -3,10 +3,8 @@
3
3
  carray_copy.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
 
@@ -43,12 +41,9 @@ ca_copy (void *ap)
43
41
  return co;
44
42
  }
45
43
 
46
- /* rdoc:
47
- class CArray
48
- # create CArray object from `self` with same contents includes mask state.
49
- def to_ca
50
- end
51
- end
44
+ /* @overload to_ca
45
+
46
+ (Copy) Creates CArray object from `self` with same contents includes mask state.
52
47
  */
53
48
 
54
49
  VALUE
@@ -101,15 +96,12 @@ ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes)
101
96
  }
102
97
  }
103
98
 
104
- /* rdoc:
105
- class CArray
106
- # returns CArray object with same dimension with `self`
107
- # The data type of the new carray object can be specified by `data_type`.
108
- # For fixlen data type, the option `:bytes` is used to specified the
109
- # data length.
110
- def template(data_type=self.data_type, options={:bytes=>0})
111
- end
112
- end
99
+ /* @overload template(data_type=self.data_type, bytes: 0)
100
+
101
+ (Copy) Returns CArray object with same dimension with `self`
102
+ The data type of the new carray object can be specified by `data_type`.
103
+ For fixlen data type, the option `:bytes` is used to specified the
104
+ data length.
113
105
  */
114
106
 
115
107
  static VALUE
@@ -284,14 +276,10 @@ ca_paste (void *ap, ca_size_t *offset, void *sp)
284
276
  ca_detach_n(2, ca, cs);
285
277
  }
286
278
 
287
- /* rdoc:
288
- class CArray
289
- # pastes `ary` to `self` at the index `idx`.
290
- # `idx` should be Array object with the length same as `self.ndim`.
291
- # `ary` should have same shape with `self`.
292
- def paste (idx, ary)
293
- end
294
- end
279
+ /* @overload paste (idx, ary)
280
+ (Copy) Pastes `ary` to `self` at the index `idx`.
281
+ `idx` should be Array object with the length same as `self.ndim`.
282
+ `ary` should have same shape with `self`.
295
283
  */
296
284
 
297
285
  static VALUE
@@ -402,12 +390,8 @@ ca_clip (void *ap, ca_size_t *offset, void *sp)
402
390
  ca_detach_n(2, ca, cs);
403
391
  }
404
392
 
405
- /* rdoc:
406
- class CArray
407
- # clips the data at `idx` from `self` to `ary`.
408
- def clip (idx, ary)
409
- end
410
- end
393
+ /* @overload clip (idx, ary)
394
+ (copy) Clips the data at `idx` from `self` to `ary`.
411
395
  */
412
396
 
413
397
  static VALUE
data/ext/carray_core.c CHANGED
@@ -3,10 +3,8 @@
3
3
  carray_core.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
 
@@ -998,10 +996,13 @@ rb_ca_s_ensure_detach (VALUE list)
998
996
  return Qnil;
999
997
  }
1000
998
 
1001
- /* rdoc:
1002
- def CArray.attach(*argv) # :nodoc:
1003
- yield
1004
- end
999
+ /* @overload attach (*arrays)
1000
+
1001
+ (Internal) Guarantees that the reference memory block is attached.
1002
+ The memory block is detached at the end of the block evaluation.
1003
+ It is not ensured the syncing the memory block at the end of the block evaluation.
1004
+
1005
+ @yield
1005
1006
  */
1006
1007
 
1007
1008
  static VALUE
@@ -1035,10 +1036,13 @@ rb_ca_s_ensure_sync_detach (VALUE list)
1035
1036
  return Qnil;
1036
1037
  }
1037
1038
 
1038
- /* rdoc:
1039
- def CArray.attach!(*argv) # :nodoc:
1040
- yield
1041
- end
1039
+ /* @overload attach! (*arrays)
1040
+
1041
+ (Internal) Guarantees that the reference memory block is attached.
1042
+ The memory block is detached at the end of the block evaluation.
1043
+ It is ensured the syncing the memory block at the end of the block evaluation.
1044
+
1045
+ @yield
1042
1046
  */
1043
1047
 
1044
1048
  static VALUE
@@ -1065,12 +1069,13 @@ rb_ca_ensure_detach (VALUE self)
1065
1069
  return Qnil;
1066
1070
  }
1067
1071
 
1068
- /* rdoc:
1069
- class CArray
1070
- def attach () # :nodoc:
1071
- yield
1072
- end
1073
- end
1072
+ /* @overload attach
1073
+
1074
+ (Internal) Guarantees that the reference memory block is attached.
1075
+ The memory block is detached at the end of the block evaluation.
1076
+ It is ensured the syncing the memory block at the end of the block evaluation.
1077
+
1078
+ @yield
1074
1079
  */
1075
1080
 
1076
1081
  static VALUE
@@ -1088,12 +1093,13 @@ rb_ca_ensure_sync_detach (VALUE self)
1088
1093
  return Qnil;
1089
1094
  }
1090
1095
 
1091
- /* rdoc:
1092
- class CArray
1093
- def attach! () # :nodoc:
1094
- yield
1095
- end
1096
- end
1096
+ /* @overload attach!
1097
+
1098
+ (Internal) Guarantees that the reference memory block is attached.
1099
+ The memory block is detached at the end of the block evaluation.
1100
+ It is ensured the syncing the memory block at the end of the block evaluation.
1101
+
1102
+ @yield
1097
1103
  */
1098
1104
 
1099
1105
  static VALUE
@@ -1104,7 +1110,11 @@ rb_ca_attach_bang (VALUE self)
1104
1110
  return rb_ensure(rb_yield, self, rb_ca_ensure_sync_detach, self);
1105
1111
  }
1106
1112
 
1107
- /* CArray#__attach__ */
1113
+ /* @overload __attach__
1114
+
1115
+ (Internal, DevelopperOnly) Attaches the reference memory block.
1116
+ User must call "CArray#__detach__" appropreate timing.
1117
+ */
1108
1118
 
1109
1119
  static VALUE
1110
1120
  rb_ca__attach__ (VALUE self)
@@ -1113,7 +1123,10 @@ rb_ca__attach__ (VALUE self)
1113
1123
  return self;
1114
1124
  }
1115
1125
 
1116
- /* CArray#__sync__ */
1126
+ /* @overload __detach__
1127
+
1128
+ (Internal, DevelopperOnly) Syncs the reference memory block to the parent array.
1129
+ */
1117
1130
 
1118
1131
  static VALUE
1119
1132
  rb_ca__sync__ (VALUE self)
@@ -1123,7 +1136,10 @@ rb_ca__sync__ (VALUE self)
1123
1136
  return self;
1124
1137
  }
1125
1138
 
1126
- /* CArray#__detach__ */
1139
+ /* @overload __detach__
1140
+
1141
+ (Internal, DevelopperOnly) Detaches the reference memory block.
1142
+ */
1127
1143
 
1128
1144
  static VALUE
1129
1145
  rb_ca__detach__ (VALUE self)
@@ -1162,18 +1178,15 @@ rb_ca_data_class_encode (VALUE self, VALUE obj)
1162
1178
 
1163
1179
  /* ------------------------------------------------------------------- */
1164
1180
 
1165
- /* rdoc:
1166
- class CArray
1167
- # Returns data class member names
1168
- def members
1169
- end
1170
- end
1181
+ /* @overload members
1182
+
1183
+ (Inquiry) Returns data class member names
1171
1184
  */
1172
1185
 
1173
1186
  VALUE
1174
1187
  rb_ca_members (VALUE self)
1175
1188
  {
1176
- VALUE data_class = rb_ca_data_class(self);
1189
+ volatile VALUE data_class = rb_ca_data_class(self);
1177
1190
  if ( NIL_P(data_class) ) {
1178
1191
  rb_raise(rb_eRuntimeError, "carray doesn't have data class");
1179
1192
  }
@@ -1185,9 +1198,9 @@ rb_ca_members (VALUE self)
1185
1198
  VALUE
1186
1199
  rb_ca_field_as_member (VALUE self, VALUE sym)
1187
1200
  {
1188
- VALUE data_class = rb_ca_data_class(self);
1189
- VALUE member;
1190
- VALUE obj;
1201
+ volatile VALUE data_class = rb_ca_data_class(self);
1202
+ volatile VALUE member;
1203
+ volatile VALUE obj;
1191
1204
 
1192
1205
  if ( NIL_P(data_class) ) {
1193
1206
  rb_raise(rb_eRuntimeError, "carray doesn't have data class");
@@ -1201,23 +1214,29 @@ rb_ca_field_as_member (VALUE self, VALUE sym)
1201
1214
  "for data_class array");
1202
1215
  }
1203
1216
 
1204
- if ( TYPE(sym) == T_SYMBOL ) {
1205
- sym = rb_funcall(sym, rb_intern("to_s"), 0);
1206
- }
1207
- else if ( rb_obj_is_kind_of(sym, rb_cInteger) ) {
1208
- VALUE member_names = rb_const_get(data_class, rb_intern("MEMBERS"));
1209
- sym = rb_ary_entry(member_names, NUM2SIZE(sym));
1217
+ if ( rb_obj_is_kind_of(sym, rb_cInteger) ) {
1218
+ volatile VALUE member_names = rb_const_get(data_class, rb_intern("MEMBERS"));
1219
+ sym = rb_ary_entry(member_names, NUM2SIZE(sym));
1220
+ obj = rb_hash_aref(member, sym);
1221
+ }
1222
+ else {
1223
+ obj = rb_hash_aref(member, sym);
1224
+ if ( NIL_P(obj) ) {
1225
+ sym = rb_funcall(sym, rb_intern("to_s"), 0);
1226
+ obj = rb_hash_aref(member, sym);
1227
+ }
1210
1228
  }
1211
1229
 
1212
- obj = rb_hash_aref(member, sym);
1213
-
1214
1230
  if ( rb_obj_is_carray(obj) ) {
1215
1231
  return obj;
1216
1232
  }
1217
1233
  else {
1218
- VALUE MEMBER_TABLE = rb_const_get(data_class, rb_intern("MEMBER_TABLE"));
1219
- VALUE info = rb_hash_aref(MEMBER_TABLE, sym);
1234
+ volatile VALUE MEMBER_TABLE = rb_const_get(data_class, rb_intern("MEMBER_TABLE"));
1235
+ volatile VALUE info = rb_hash_aref(MEMBER_TABLE, sym);
1220
1236
  if ( NIL_P(info) ) {
1237
+ if ( TYPE(sym) != T_STRING ) {
1238
+ sym = rb_funcall(sym, rb_intern("to_s"), 0);
1239
+ }
1221
1240
  rb_raise(rb_eRuntimeError,
1222
1241
  "can't find data_member named <%s>", StringValuePtr(sym));
1223
1242
  }
@@ -1228,18 +1247,15 @@ rb_ca_field_as_member (VALUE self, VALUE sym)
1228
1247
  }
1229
1248
  }
1230
1249
 
1231
- /* rdoc:
1232
- class CArray
1233
- # Returns an array of data class members (fields)
1234
- def fields
1235
- end
1236
- end
1250
+ /* @overload fields
1251
+
1252
+ (Reference) Returns an array of data class members (fields)
1237
1253
  */
1238
1254
 
1239
1255
  VALUE
1240
1256
  rb_ca_fields (VALUE self)
1241
1257
  {
1242
- VALUE data_class = rb_ca_data_class(self);
1258
+ volatile VALUE data_class = rb_ca_data_class(self);
1243
1259
  volatile VALUE member_names, list;
1244
1260
  int i;
1245
1261
  if ( NIL_P(data_class) ) {
@@ -1254,18 +1270,15 @@ rb_ca_fields (VALUE self)
1254
1270
  return list;
1255
1271
  }
1256
1272
 
1257
- /* rdoc:
1258
- class CArray
1259
- # Returns an array of data class members (fields) with names specified
1260
- def fields_at (*names)
1261
- end
1262
- end
1273
+ /* @overload fields_at (*names)
1274
+
1275
+ Returns an array of data class members (fields) with names specified
1263
1276
  */
1264
1277
 
1265
1278
  VALUE
1266
1279
  rb_ca_fields_at (int argc, VALUE *argv, VALUE self)
1267
1280
  {
1268
- VALUE data_class = rb_ca_data_class(self);
1281
+ volatile VALUE data_class = rb_ca_data_class(self);
1269
1282
  volatile VALUE member_names, list;
1270
1283
  int i;
1271
1284
  if ( NIL_P(data_class) ) {