carray 3.0.6 → 3.1.0

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1504
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +8 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +73 -72
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. data/lib/carray/data_type_limits.rb +0 -91
@@ -23,61 +23,57 @@
23
23
  # `Enumerator::ArithmeticSequence` already carries its own step, so
24
24
  # `CA_INT32((0..6).step(2))` needs no second argument.
25
25
  #
26
+ # `nil` is refused with `TypeError`: it is no data. An empty array is
27
+ # `CA_INT32([])`.
28
+ #
29
+ # A String is read as words separated by spaces or `,`, with `;` ending a
30
+ # row and `_` for an UNDEF cell: `CA_INT32("1 2; 3 4")` is
31
+ # `[[1, 2], [3, 4]]`. Each word is read as a cell of the type reads text:
32
+ # a decimal number, or for `CA_BOOLEAN` one of `1` / `0` / `true` /
33
+ # `false` (`CA_BOOLEAN("1 0 1")` is `[true, false, true]`). A word that
34
+ # does not read raises `ArgumentError`. `CA_OBJECT` and `CA_FIXLEN` keep
35
+ # the String as one value.
36
+ #
26
37
  # `CA_FIXLEN` takes `bytes:` instead of a step; see {#CA_FIXLEN}.
27
38
  module Kernel
28
39
  # @!group CArray cast shorthands
29
40
 
30
41
  # Coerces `obj` into a `:boolean` CArray. @return [CArray]
31
- def CA_BOOLEAN(obj = nil, step = nil); end
42
+ def CA_BOOLEAN(obj, step = nil); end
32
43
  # Coerces `obj` into an `:int8` CArray. @return [CArray]
33
- def CA_INT8(obj = nil, step = nil); end
44
+ def CA_INT8(obj, step = nil); end
34
45
  # Coerces `obj` into a `:uint8` CArray. @return [CArray]
35
- def CA_UINT8(obj = nil, step = nil); end
46
+ def CA_UINT8(obj, step = nil); end
36
47
  # Coerces `obj` into an `:int16` CArray. @return [CArray]
37
- def CA_INT16(obj = nil, step = nil); end
48
+ def CA_INT16(obj, step = nil); end
38
49
  # Coerces `obj` into a `:uint16` CArray. @return [CArray]
39
- def CA_UINT16(obj = nil, step = nil); end
50
+ def CA_UINT16(obj, step = nil); end
40
51
  # Coerces `obj` into an `:int32` CArray. @return [CArray]
41
- def CA_INT32(obj = nil, step = nil); end
52
+ def CA_INT32(obj, step = nil); end
42
53
  # Coerces `obj` into a `:uint32` CArray. @return [CArray]
43
- def CA_UINT32(obj = nil, step = nil); end
54
+ def CA_UINT32(obj, step = nil); end
44
55
  # Coerces `obj` into an `:int64` CArray. @return [CArray]
45
- def CA_INT64(obj = nil, step = nil); end
56
+ def CA_INT64(obj, step = nil); end
46
57
  # Coerces `obj` into a `:uint64` CArray. @return [CArray]
47
- def CA_UINT64(obj = nil, step = nil); end
58
+ def CA_UINT64(obj, step = nil); end
48
59
  # Coerces `obj` into a `:float32` CArray. @return [CArray]
49
- def CA_FLOAT32(obj = nil, step = nil); end
60
+ def CA_FLOAT32(obj, step = nil); end
50
61
  # Coerces `obj` into a `:float64` CArray. @return [CArray]
51
- def CA_FLOAT64(obj = nil, step = nil); end
62
+ def CA_FLOAT64(obj, step = nil); end
52
63
  # Coerces `obj` into a `:cmplx64` CArray. @return [CArray]
53
- def CA_CMPLX64(obj = nil, step = nil); end
64
+ def CA_CMPLX64(obj, step = nil); end
54
65
  # Coerces `obj` into a `:cmplx128` CArray. @return [CArray]
55
- def CA_CMPLX128(obj = nil, step = nil); end
66
+ def CA_CMPLX128(obj, step = nil); end
56
67
  # Coerces `obj` into an `:object` CArray. @return [CArray]
57
- def CA_OBJECT(obj = nil, step = nil); end
68
+ def CA_OBJECT(obj, step = nil); end
58
69
  # Coerces `obj` into a `CA_SIZE` (platform native size) CArray.
59
70
  # @return [CArray]
60
- def CA_SIZE(obj = nil, step = nil); end
71
+ def CA_SIZE(obj, step = nil); end
61
72
  # Coerces `obj` into a `:fixlen` CArray. `bytes` defaults to the
62
73
  # longest top-level element of an `Array`, or `0` for `nil`.
63
74
  # @return [CArray]
64
75
  def CA_FIXLEN(obj, bytes: nil); end
65
76
 
66
- # Alias of {#CA_UINT8}. @return [CArray]
67
- def CA_BYTE(obj = nil, step = nil); end
68
- # Alias of {#CA_INT16}. @return [CArray]
69
- def CA_SHORT(obj = nil, step = nil); end
70
- # Alias of {#CA_INT32}. @return [CArray]
71
- def CA_INT(obj = nil, step = nil); end
72
- # Alias of {#CA_FLOAT32}. @return [CArray]
73
- def CA_FLOAT(obj = nil, step = nil); end
74
- # Alias of {#CA_FLOAT64}. @return [CArray]
75
- def CA_DOUBLE(obj = nil, step = nil); end
76
- # Alias of {#CA_CMPLX64}. @return [CArray]
77
- def CA_COMPLEX(obj = nil, step = nil); end
78
- # Alias of {#CA_CMPLX128}. @return [CArray]
79
- def CA_DCOMPLEX(obj = nil, step = nil); end
80
-
81
77
  # @!endgroup
82
78
  end
83
79
 
@@ -105,12 +101,21 @@ class CArray
105
101
  # float types. A cell that is not a String goes through `Integer()` /
106
102
  # `Float()` as before.
107
103
  #
104
+ # When `data_type` is `:boolean`, a String cell is read by its words:
105
+ # `1` / `0` / `true` / `false` in any case, with spaces around them
106
+ # ignored. Any other text becomes UNDEF, as does a value that is not
107
+ # `true`, `false`, `0` or `1`.
108
+ #
108
109
  # From a float or complex array to an integer type, a NaN cell (in
109
110
  # either part) becomes UNDEF. A finite value outside the integer type
110
111
  # is converted as the machine's C converts it.
111
- # @param data_type [Symbol, Integer, Class, String] target element type.
112
+ # @param data_type [Symbol, Class, String] target element type;
113
+ # a data class (from `CArray.struct`) reads fixlen cells of its size as records (a
114
+ # {CARecord}), makes records from an object array of its instances,
115
+ # and refuses other cells.
112
116
  # @param bytes [Integer, nil] element width in bytes, required for
113
- # `:fixlen`.
117
+ # `:fixlen`; another type refuses a
118
+ # width other than its own.
114
119
  # @return [CArray]
115
120
  def to_type(data_type, bytes: nil); end
116
121
 
@@ -177,28 +182,6 @@ class CArray
177
182
  # @return [CArray]
178
183
  def fixlen(bytes: nil); end
179
184
 
180
- # @overload byte
181
- # Alias of {#uint8}. @return [CArray]
182
- def byte; end
183
- # @overload short
184
- # Alias of {#int16}. @return [CArray]
185
- def short; end
186
- # @overload int
187
- # Alias of {#int32}. @return [CArray]
188
- def int; end
189
- # @overload float
190
- # Alias of {#float32}. @return [CArray]
191
- def float; end
192
- # @overload double
193
- # Alias of {#float64}. @return [CArray]
194
- def double; end
195
- # @overload complex
196
- # Alias of {#cmplx64}. @return [CArray]
197
- def complex; end
198
- # @overload dcomplex
199
- # Alias of {#cmplx128}. @return [CArray]
200
- def dcomplex; end
201
-
202
185
  # -- as_type: reinterpreting view (no copy) ---------------------------
203
186
 
204
187
  # @overload as_type(data_type, bytes: nil)
@@ -213,7 +196,8 @@ class CArray
213
196
  # Note: for an `:object` source the on-the-fly cast to a numeric type
214
197
  # uses the lenient path and does NOT mask parse failures — a
215
198
  # non-numeric string reads as `0.0` (float) and raises for an integer
216
- # target. Use {#to_type} instead for parse-with-mask (an unparseable
199
+ # or boolean target (a boolean cell reads `1` / `0` / `true` / `false`
200
+ # as {#to_type} does). Use {#to_type} instead for parse-with-mask (an unparseable
217
201
  # cell becomes UNDEF). The `CA_<TYPE>(obj)` construction shorthands
218
202
  # take this same non-masking path.
219
203
  # From a float or complex array to an integer type, reading a NaN cell
@@ -225,9 +209,13 @@ class CArray
225
209
  # descriptor instead of the string), and no view decodes a surface. Take
226
210
  # the values with {#to_type}, or the storage with `face.parent.as_type`.
227
211
  # A Numeric Face, whose surface *is* its storage, adapts as usual.
228
- # @param data_type [Symbol, Integer, Class, String] target element type.
212
+ # @param data_type [Symbol, Class, String] target element type;
213
+ # a data class (from `CArray.struct`) reads fixlen cells of its size as records (a
214
+ # {CARecord}) and refuses other cells, and a Face whose storage
215
+ # is not its values (a const string).
229
216
  # @param bytes [Integer, nil] element width in bytes, required for
230
- # `:fixlen`.
217
+ # `:fixlen`; another type refuses a
218
+ # width other than its own.
231
219
  # @return [CAMonOp, CAFake]
232
220
  # @raise [TypeError] when `self` is a Face and the request would read its
233
221
  # storage under another type.
@@ -236,72 +224,62 @@ class CArray
236
224
  def as_type(data_type, bytes: nil); end
237
225
 
238
226
  # @overload as_boolean
239
- # Returns a {CAFake} `:boolean` view of `self`. Short-hand of
227
+ # Returns a {CAMonOp} `:boolean` view of `self`. Short-hand of
240
228
  # `as_type(:boolean)`.
241
- # @return [CAFake]
229
+ # @return [CAMonOp]
242
230
  def as_boolean; end
243
231
  # @overload as_int8
244
- # Returns a {CAFake} `:int8` view of `self`. Short-hand of `as_type(:int8)`.
245
- # @return [CAFake]
232
+ # Returns a {CAMonOp} `:int8` view of `self`. Short-hand of `as_type(:int8)`.
233
+ # @return [CAMonOp]
246
234
  def as_int8; end
247
235
  # @overload as_uint8
248
- # Returns a {CAFake} `:uint8` view of `self`. Short-hand of `as_type(:uint8)`.
249
- # @return [CAFake]
236
+ # Returns a {CAMonOp} `:uint8` view of `self`. Short-hand of `as_type(:uint8)`.
237
+ # @return [CAMonOp]
250
238
  def as_uint8; end
251
239
  # @overload as_int16
252
- # Returns a {CAFake} `:int16` view of `self`. Short-hand of `as_type(:int16)`.
253
- # @return [CAFake]
240
+ # Returns a {CAMonOp} `:int16` view of `self`. Short-hand of `as_type(:int16)`.
241
+ # @return [CAMonOp]
254
242
  def as_int16; end
255
243
  # @overload as_uint16
256
- # Returns a {CAFake} `:uint16` view of `self`. Short-hand of `as_type(:uint16)`.
257
- # @return [CAFake]
244
+ # Returns a {CAMonOp} `:uint16` view of `self`. Short-hand of `as_type(:uint16)`.
245
+ # @return [CAMonOp]
258
246
  def as_uint16; end
259
247
  # @overload as_int32
260
- # Returns a {CAFake} `:int32` view of `self`. Short-hand of `as_type(:int32)`.
261
- # @return [CAFake]
248
+ # Returns a {CAMonOp} `:int32` view of `self`. Short-hand of `as_type(:int32)`.
249
+ # @return [CAMonOp]
262
250
  def as_int32; end
263
251
  # @overload as_uint32
264
- # Returns a {CAFake} `:uint32` view of `self`. Short-hand of `as_type(:uint32)`.
265
- # @return [CAFake]
252
+ # Returns a {CAMonOp} `:uint32` view of `self`. Short-hand of `as_type(:uint32)`.
253
+ # @return [CAMonOp]
266
254
  def as_uint32; end
267
255
  # @overload as_int64
268
- # Returns a {CAFake} `:int64` view of `self`. Short-hand of `as_type(:int64)`.
269
- # @return [CAFake]
256
+ # Returns a {CAMonOp} `:int64` view of `self`. Short-hand of `as_type(:int64)`.
257
+ # @return [CAMonOp]
270
258
  def as_int64; end
271
259
  # @overload as_uint64
272
- # Returns a {CAFake} `:uint64` view of `self`. Short-hand of `as_type(:uint64)`.
273
- # @return [CAFake]
260
+ # Returns a {CAMonOp} `:uint64` view of `self`. Short-hand of `as_type(:uint64)`.
261
+ # @return [CAMonOp]
274
262
  def as_uint64; end
275
263
  # @overload as_float32
276
- # Returns a {CAFake} `:float32` view of `self`. Short-hand of
264
+ # Returns a {CAMonOp} `:float32` view of `self`. Short-hand of
277
265
  # `as_type(:float32)`.
278
- # @return [CAFake]
266
+ # @return [CAMonOp]
279
267
  def as_float32; end
280
268
  # @overload as_float64
281
- # Returns a {CAFake} `:float64` view of `self`. Short-hand of
269
+ # Returns a {CAMonOp} `:float64` view of `self`. Short-hand of
282
270
  # `as_type(:float64)`.
283
- # @return [CAFake]
271
+ # @return [CAMonOp]
284
272
  def as_float64; end
285
- # @overload as_float128
286
- # Returns a {CAFake} `:float128` view of `self`. Short-hand of
287
- # `as_type(:float128)`.
288
- # @return [CAFake]
289
- def as_float128; end
290
273
  # @overload as_cmplx64
291
- # Returns a {CAFake} `:cmplx64` view of `self`. Short-hand of
274
+ # Returns a {CAMonOp} `:cmplx64` view of `self`. Short-hand of
292
275
  # `as_type(:cmplx64)`.
293
- # @return [CAFake]
276
+ # @return [CAMonOp]
294
277
  def as_cmplx64; end
295
278
  # @overload as_cmplx128
296
- # Returns a {CAFake} `:cmplx128` view of `self`. Short-hand of
279
+ # Returns a {CAMonOp} `:cmplx128` view of `self`. Short-hand of
297
280
  # `as_type(:cmplx128)`.
298
- # @return [CAFake]
281
+ # @return [CAMonOp]
299
282
  def as_cmplx128; end
300
- # @overload as_cmplx256
301
- # Returns a {CAFake} `:cmplx256` view of `self`. Short-hand of
302
- # `as_type(:cmplx256)`.
303
- # @return [CAFake]
304
- def as_cmplx256; end
305
283
  # @overload as_object
306
284
  # Returns a {CAFake} `:object` view of `self`. Short-hand of
307
285
  # `as_type(:object)`.
@@ -314,53 +292,6 @@ class CArray
314
292
  # @return [CAFake]
315
293
  def as_fixlen(bytes: nil); end
316
294
 
317
- # @overload as_byte
318
- # Alias of {#as_uint8}. @return [CAFake]
319
- def as_byte; end
320
- # @overload as_short
321
- # Alias of {#as_int16}. @return [CAFake]
322
- def as_short; end
323
- # @overload as_int
324
- # Alias of {#as_int32}. @return [CAFake]
325
- def as_int; end
326
- # @overload as_float
327
- # Alias of {#as_float32}. @return [CAFake]
328
- def as_float; end
329
- # @overload as_double
330
- # Alias of {#as_float64}. @return [CAFake]
331
- def as_double; end
332
- # @overload as_complex
333
- # Alias of {#as_cmplx64}. @return [CAFake]
334
- def as_complex; end
335
- # @overload as_dcomplex
336
- # Alias of {#as_cmplx128}. @return [CAFake]
337
- def as_dcomplex; end
338
-
339
- # -- clip-then-cast ---------------------------------------------------
340
-
341
- # @!method clip_int8
342
- # Returns an `:int8` copy of `self` with values clamped to the
343
- # `:int8` range (-128..127) before casting. @return [CArray]
344
- # @!method clip_uint8
345
- # Returns a `:uint8` copy clamped to 0..255. @return [CArray]
346
- # @!method clip_int16
347
- # Returns an `:int16` copy clamped to -32768..32767.
348
- # @return [CArray]
349
- # @!method clip_uint16
350
- # Returns a `:uint16` copy clamped to 0..65535. @return [CArray]
351
- # @!method clip_int32
352
- # Returns an `:int32` copy clamped to the `:int32` range.
353
- # @return [CArray]
354
- # @!method clip_uint32
355
- # Returns a `:uint32` copy clamped to 0..4294967295.
356
- # @return [CArray]
357
- # @!method clip_int64
358
- # Returns an `:int64` copy clamped to the `:int64` range.
359
- # @return [CArray]
360
- # @!method clip_uint64
361
- # Returns a `:uint64` copy clamped to the `:uint64` range.
362
- # @return [CArray]
363
-
364
295
  # -- coercion ---------------------------------------------------------
365
296
 
366
297
  # @overload cast_with(other)
@@ -387,8 +318,7 @@ class CArray
387
318
  #
388
319
  # The name is a statement of intent, not a property of the result: you are
389
320
  # declaring that writes are coming, so only sources that can actually take
390
- # a write are accepted — a writable CArray, `nil` (a zero-filled CScalar),
391
- # an object whose `#to_ca` honours `writable: true`, or a writable
321
+ # a write are accepted — a writable CArray, an object whose `#to_ca` honours `writable: true`, or a writable
392
322
  # MemoryView producer (wrapped zero-copy). Anything that would have to be
393
323
  # *copied* to become a CArray is refused up front, because a copy would
394
324
  # swallow the writes silently. That is the whole difference from
@@ -406,14 +336,16 @@ class CArray
406
336
  # through to the source. A Face is refused for that same reason the
407
337
  # other way round: the writes would land on the storage its surface
408
338
  # hides. Wrap `face.parent` when that is what you mean.
409
- # @param other [CArray, nil, Object] source to wrap.
410
- # @param data_type [Symbol, Integer, Class, nil] target element type;
411
- # `nil` keeps the source type (or `:object` when `other` is `nil`).
339
+ # @param other [CArray, Object] source to wrap.
340
+ # @param data_type [Symbol, Class, nil] target element type;
341
+ # `nil` keeps the source type; a data class (from `CArray.struct`) reads fixlen cells of its size as records (a
342
+ # {CARecord}) and refuses other cells, and a Face whose storage
343
+ # is not its values (a const string).
412
344
  # @return [CArray]
413
345
  # @raise [RuntimeError] when `other` is read-only, its MemoryView is
414
346
  # read-only, or its `to_ca` refuses `writable: true`.
415
- # @raise [TypeError] when `other` cannot be wrapped as a CArray, or
416
- # `other#to_ca` returns something that is not a CArray.
347
+ # @raise [TypeError] when `other` is `nil` or cannot be wrapped as a
348
+ # CArray, or `other#to_ca` returns something that is not a CArray.
417
349
  # @raise [ArgumentError] when `other#to_ca` does not accept `writable:`.
418
350
  # @raise [TypeError] when `other` is a Face and `data_type` differs from
419
351
  # its surface type.
@@ -427,7 +359,7 @@ class CArray
427
359
  # declaring that nothing will be written back, which frees this call to
428
360
  # convert as widely as it can — a conversion that copies is fine when
429
361
  # nobody writes to it. So on top of everything {.wrap_writable} takes
430
- # (a CArray, `nil`, an object responding to `#to_ca`, a MemoryView
362
+ # (a CArray, an object responding to `#to_ca`, a MemoryView
431
363
  # producer) this also accepts an Array (via `to_ca`) and a Numeric /
432
364
  # String / arbitrary object, which become a one-element CScalar. It calls
433
365
  # `to_ca` with no arguments, so a copy is welcome here.
@@ -439,7 +371,8 @@ class CArray
439
371
  #
440
372
  # Two conversions are worth knowing before you rely on them: with a
441
373
  # numeric `data_type` a String is reinterpreted as **raw bytes** (a copy),
442
- # not parsed, so `"abcd"` with `:uint8` gives four elements; and with
374
+ # not parsed, so `"abcd"` with `:uint8` gives four elements (a length
375
+ # that is no whole number of cells is refused); and with
443
376
  # `data_type` omitted, anything that is not already CArray-shaped lands on
444
377
  # `:object` rather than a guessed numeric type, so pass `data_type`
445
378
  # explicitly when the value is headed for a numeric kernel.
@@ -447,12 +380,16 @@ class CArray
447
380
  # nothing here promises a view: its surface values for `:object`, and its
448
381
  # own `#to_numeric` for a numeric type. Reading its storage instead is
449
382
  # `face.parent`.
450
- # @param other [CArray, Numeric, String, Array, nil, Object] source to
451
- # wrap.
452
- # @param data_type [Symbol, Integer, Class, nil] target element type;
383
+ # @param other [CArray, Numeric, String, Array, Object] source to wrap.
384
+ # @param data_type [Symbol, Class, nil] target element type;
453
385
  # `nil` keeps the source type for a CArray-shaped source, and is
454
- # `:object` otherwise.
386
+ # `:object` otherwise; a data class (from `CArray.struct`) reads fixlen cells of its size as records (a
387
+ # {CARecord}) and refuses other cells, and a Face whose storage
388
+ # is not its values (a const string).
455
389
  # @return [CArray]
390
+ # @raise [TypeError] when `other` is `nil` (an empty array is `[]`).
391
+ # @raise [ArgumentError] when `other` is a String whose length is no
392
+ # whole number of cells of a numeric `data_type`.
456
393
  # @raise [TypeError] when `other` is a Face asked for a numeric type and
457
394
  # it declares no `#to_numeric`.
458
395
  def self.wrap_readonly(other, data_type = nil); end
@@ -480,16 +417,32 @@ class CArray
480
417
  # - Integer / Float / Complex / true / false / nil / Object -> *value*,
481
418
  # data_type inferred (3 -> `:int64`, 3.14 -> `:float64`,
482
419
  # 1+2i -> `:cmplx128`, ...)
420
+ # - Ruby Array -> no data type: beside an object array it is one more
421
+ # object value, otherwise it is refused (make it a CArray of the type
422
+ # you mean)
483
423
  #
484
424
  # The arrays and data_type representations promote together. A
485
425
  # scalar (a value, or a CScalar) then joins their type the way it
486
426
  # does beside an operator: one of the same kind takes that type
487
427
  # (`result_type(float32_array, 0.1)` is `:float32`, as
488
428
  # `float32_array + 0.1` is), one of another kind promotes
489
- # (`result_type(int32_array, 1.5)` is `:float64`), and an Integer
490
- # that does not fit an integer type takes `:int64`. With no array or
429
+ # (`result_type(int32_array, 1.5)` is `:float64`), a Complex beside a
430
+ # float32 array keeps the width (`:cmplx64`), and an Integer
431
+ # that does not fit an integer type takes a type that holds it and the
432
+ # array's values (`:int64`, or `:object` where no integer type does,
433
+ # as for `2**64`). Beside a boolean array an Integer meets the numbers
434
+ # 0 and 1 as an operator reads them: `:int64`, or `:object` past the
435
+ # int64 range. With no array or
491
436
  # data_type representation, every argument promotes by its own type.
492
437
  #
438
+ # This is the type an operator computes in: `int32_array + float32_array`
439
+ # is `:float32`. Arrays joined value for value ({CArray.stack},
440
+ # {CArray.meld}, {CArray.concatenate}) refuse that pair through
441
+ # {.promote_list}, since `float32` does not hold every `int32` exactly,
442
+ # and ask for `data_type:`. They join an `int64` or `uint64` array with
443
+ # a `float64` or `cmplx128` one in that type while its integers are
444
+ # within 2**53, and refuse the list when one is past it.
445
+ #
493
446
  # Integer args are interpreted as *values*, not as data_type codes:
494
447
  # `result_type(8)` returns `:int64` because the value 8 is an Integer,
495
448
  # not because a data_type code equals 8. Use `result_type(:int64)` or
@@ -497,6 +450,7 @@ class CArray
497
450
  # @param args [Array<CArray, Symbol, String, Class, Object>] operands.
498
451
  # @return [Symbol]
499
452
  # @raise [ArgumentError] when called with no arguments.
453
+ # @raise [TypeError] when a Ruby Array is given beside no object array.
500
454
  # @raise [CArray::DataTypeError] when two inputs are mutually incompatible
501
455
  # (e.g. `:object` with `:fixlen`).
502
456
  # @example
@@ -517,12 +471,15 @@ class CArray
517
471
  # elements passes through (CAStack lifts it), unless the class is not
518
472
  # portable (CAConstString) or the elements disagree on state
519
473
  # (CATime with different units); a list of primitives is
520
- # promoted via {.result_type} + {.wrap_readonly}, except that a list
521
- # mixing signed and unsigned integers takes a type that holds both
522
- # (`uint8` with `int8` is `int16`, 64-bit pairs are `:object`), and an
523
- # integer of 32 bits or more beside `float32` takes `float64`, since
524
- # the arrays are joined value for value; a mix of Face and non-Face,
525
- # or heterogeneous Face classes, is rejected.
474
+ # promoted via {.result_type} + {.wrap_readonly}; a mix of Face and
475
+ # non-Face, or heterogeneous Face classes, is rejected. The arrays are
476
+ # joined value for value, so a pair whose common type would change
477
+ # some of their values is refused: signed with unsigned integers
478
+ # (`uint8` with `int8` meet in `uint8`, where -1 reads as 255) and an
479
+ # integer of 32 bits or more with `float32` (which holds integers only
480
+ # up to 2**24). Give `data_type:` to join them; the message names the
481
+ # type that holds both (`int16`, `:object` for a 64-bit pair,
482
+ # `float64`).
526
483
  #
527
484
  # With an explicit primitive `data_type`: all-primitive elements are
528
485
  # wrapped read-only to the requested type; any Face element is
@@ -532,7 +489,9 @@ class CArray
532
489
  # @param data_type [Symbol, nil] target element type, or `nil` to
533
490
  # auto-detect.
534
491
  # @return [Array<CArray>]
535
- # @raise [ArgumentError] on an empty list or any of the reject cases.
492
+ # @raise [ArgumentError] on an empty list or a Face reject case.
493
+ # @raise [CArray::DataTypeError] when the common type would change
494
+ # some values and no `data_type:` is given.
536
495
  def self.promote_list(list, data_type: nil); end
537
496
 
538
497
  # @!endgroup
@@ -7,10 +7,9 @@ class CArray
7
7
  # @!group Platform inquiries
8
8
 
9
9
  # @overload endian
10
- # Returns the host byte order as an Integer: `0`
11
- # (`CA_LITTLE_ENDIAN`) or `1` (`CA_BIG_ENDIAN`). Prefer
12
- # {.big_endian?} / {.little_endian?} for predicate use.
13
- # @return [Integer]
10
+ # Returns the host byte order, `:little` or `:big`.
11
+ # {.big_endian?} / {.little_endian?} ask the same as a predicate.
12
+ # @return [Symbol]
14
13
  def endian; end
15
14
 
16
15
  # @overload big_endian?
@@ -27,7 +27,7 @@ class CArray
27
27
  #
28
28
  # Masked cells skip the block; if the block returns
29
29
  # `CArray::UNDEF`, the corresponding output cell is masked.
30
- # @param data_type [Symbol, Integer, Class, String, nil]
30
+ # @param data_type [Symbol, String, nil]
31
31
  # @param bytes [Integer, nil] element byte size for `:fixlen`.
32
32
  # @yieldparam elem [Object] one element of `self`.
33
33
  # @yieldreturn [Object] value to store in the result.
@@ -62,12 +62,11 @@ class CArray
62
62
  def dump_binary(io = nil); end
63
63
 
64
64
  # @overload to_s
65
- # Equivalent to `dump_binary` with no arguments. Returns the raw
66
- # element bytes of `self` as a binary String. Ruby uses `to_s` where
67
- # it puts an object into text, so such text holds the bytes: a
68
- # `Ractor.make_shareable` refusal of a view, for one, raises
69
- # `ArgumentError: string contains null byte` in place of its own
70
- # message. Use `inspect` for a readable form.
65
+ # Returns the same text as `inspect`. Ruby uses `to_s` where it puts
66
+ # an object into text (string interpolation, `puts`, error messages),
67
+ # so those show the readable form. Writing an array to an IO
68
+ # (`io.write(a)`, `File.write(path, a)`) therefore writes this text;
69
+ # for the element bytes, use `dump_binary`.
71
70
  # @return [String]
72
71
  def to_s; end
73
72
 
@@ -64,7 +64,8 @@ class CArray
64
64
  # @param data_type [Symbol] target element type
65
65
  # (e.g. `:int32`, `:float64`, `:fixlen`).
66
66
  # @param bytes [Integer] element byte size; required for
67
- # `:fixlen` (1 or more), ignored for numeric types.
67
+ # `:fixlen` (1 or more); another type refuses a width
68
+ # other than its own.
68
69
  # @return [CArray]
69
70
  # @overload template { value }
70
71
  # With a 0-arity block, fills every element of the result with
@@ -7,7 +7,7 @@ class CArray
7
7
 
8
8
  # @overload count(axis: nil)
9
9
  # With no value argument, returns the number of present (not-masked)
10
- # cells — the arity-0 rung of the dispatch ladder, answering "how
10
+ # cells — the arity-0 case of dispatch by arity, answering "how
11
11
  # many are there". Forwards to {#count_not_masked} (which stays as
12
12
  # an explicit, self-documenting named method).
13
13
  #
@@ -20,7 +20,7 @@ class CArray
20
20
  # Returns the number of cells of `self` that equal `v`, with
21
21
  # mask-aware reduction along `axis`.
22
22
  #
23
- # `count` is an orthogonal arity-dispatch ladder (like Ruby's
23
+ # `count` dispatches by arity (like Ruby's
24
24
  # `Array#count`): no argument counts present cells, `count(UNDEF)`
25
25
  # counts masked cells, and `count(v)` counts cells equal to `v`.
26
26
  # Mask-cardinality and value-match are distinct concepts, so the
@@ -36,6 +36,11 @@ class CArray
36
36
  # count).
37
37
  # - `v == UNDEF`: forwards to {#count_masked} (UNDEF is mask-state
38
38
  # vocabulary, not a value).
39
+ # - `v` is `nil`, a String, a Symbol or another value that is not a
40
+ # number, on an array that is not `:object` or `:fixlen`: `0`. It
41
+ # is no value of such an array, so no cell equals it. So is a
42
+ # `Complex` with an imaginary part on an integer or float array.
43
+ # - `self` is complex: cells equal to `v`, as {#eq} compares.
39
44
  # - `v` is a CArray: broadcasts; each `v[k]` is counted
40
45
  # independently and stacked into a result whose trailing axes
41
46
  # have shape `v.shape`. Not supported when `self.data_type` is
@@ -43,9 +48,9 @@ class CArray
43
48
  # - `self.data_type == :boolean`: `v` must be `true` / `false`, or
44
49
  # the integer literal `1` (= true) / `0` (= false) — boolean
45
50
  # stores 0/1, so `count(1)` == `count(true)`. Any other value
46
- # (`2`, `1.0`, `nil`, …) raises `TypeError`.
47
- # - `self` is numeric, `v` is scalar: `v` must be numeric (true /
48
- # false are rejected -- they are the boolean array's domain).
51
+ # (`2`, `1.0`, …) raises `TypeError`.
52
+ # - `self` is numeric, `v` is scalar: `true` and `false` are the
53
+ # numbers `1` and `0`, as they are to {#eq}.
49
54
  # `v` (a scalar or an array) is compared in the type it and the
50
55
  # array match in, as {#eq} compares: `CA_INT32([1, 2]).count(1.5)`
51
56
  # is `0`, `CA_UINT8([255]).count(-1)` is `0` (-1 is not 255), and an
@@ -71,8 +71,8 @@ class CArray
71
71
  # @return [self]
72
72
  # @raise [CArray::DataTypeError] for a non-numeric or complex
73
73
  # `data_type` (complex values have no order).
74
- # @raise [RangeError] when `v` wins but does not fit the type, as
75
- # `self[idx] = v` raises.
74
+ # @raise [RangeError] when an Integer `v` is below the type, as `pmin`
75
+ # refuses it. One above the type leaves the cell as it is.
76
76
  def elem_min(idx, v); end
77
77
 
78
78
  # @overload elem_max(idx, v)
@@ -84,7 +84,8 @@ class CArray
84
84
  # @return [self]
85
85
  # @raise [CArray::DataTypeError] for a non-numeric or complex
86
86
  # `data_type`.
87
- # @raise [RangeError] when `v` wins but does not fit the type.
87
+ # @raise [RangeError] when an Integer `v` is above the type, as `pmax`
88
+ # refuses it. One below the type leaves the cell as it is.
88
89
  def elem_max(idx, v); end
89
90
 
90
91
  # @!endgroup