carray 3.0.2 → 3.0.4

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 (247) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +568 -0
  3. data/README.md +6 -6
  4. data/carray.gemspec +1 -1
  5. data/ext/ca_axis_descriptor.h +27 -24
  6. data/ext/ca_axis_dispatch.c +220 -0
  7. data/ext/ca_axis_group.c +201 -123
  8. data/ext/ca_binop_dispatch.c +46 -52
  9. data/ext/ca_binop_dispatch.h +1 -1
  10. data/ext/ca_categorical_iterator.c +249 -183
  11. data/ext/ca_compare.c +7 -12
  12. data/ext/ca_for_buffer.h +21 -68
  13. data/ext/ca_group_iter.c +38 -23
  14. data/ext/ca_kernel_iterator.c +1765 -2076
  15. data/ext/ca_kernel_iterator.h +584 -566
  16. data/ext/ca_monop_dispatch.c +86 -63
  17. data/ext/ca_monop_dispatch.h +5 -0
  18. data/ext/ca_obj_array.c +223 -56
  19. data/ext/ca_obj_bincmp.c +172 -138
  20. data/ext/ca_obj_binop.c +116 -230
  21. data/ext/ca_obj_bitarray.c +40 -26
  22. data/ext/ca_obj_bitfield.c +100 -68
  23. data/ext/ca_obj_block.c +19 -9
  24. data/ext/ca_obj_byte_swap.c +45 -46
  25. data/ext/ca_obj_const_string.c +269 -44
  26. data/ext/ca_obj_face.c +612 -89
  27. data/ext/ca_obj_face.h +111 -47
  28. data/ext/ca_obj_fake.c +36 -79
  29. data/ext/ca_obj_farray.c +7 -3
  30. data/ext/ca_obj_field.c +33 -8
  31. data/ext/ca_obj_fixlen_string.c +23 -24
  32. data/ext/ca_obj_grid.c +541 -210
  33. data/ext/ca_obj_meld.c +331 -111
  34. data/ext/ca_obj_moncmp.c +80 -65
  35. data/ext/ca_obj_monop.c +177 -149
  36. data/ext/ca_obj_object.c +664 -248
  37. data/ext/ca_obj_record.c +63 -23
  38. data/ext/ca_obj_reduce.c +18 -16
  39. data/ext/ca_obj_refer.c +140 -58
  40. data/ext/ca_obj_remap.c +85 -24
  41. data/ext/ca_obj_repeat.c +24 -9
  42. data/ext/ca_obj_roll.c +121 -16
  43. data/ext/ca_obj_select.c +61 -58
  44. data/ext/ca_obj_select_axis.c +73 -107
  45. data/ext/ca_obj_shift.c +32 -102
  46. data/ext/ca_obj_stack.c +372 -122
  47. data/ext/ca_obj_stride.c +348 -140
  48. data/ext/ca_obj_string.c +88 -22
  49. data/ext/ca_obj_tile.c +38 -21
  50. data/ext/ca_obj_time.c +45 -31
  51. data/ext/ca_obj_timedelta.c +43 -29
  52. data/ext/ca_obj_transpose.c +17 -6
  53. data/ext/ca_obj_triop.c +125 -141
  54. data/ext/ca_obj_window.c +330 -44
  55. data/ext/ca_op_ipower.c +24 -11
  56. data/ext/ca_op_powi.h +57 -30
  57. data/ext/ca_pow5_table.h +656 -0
  58. data/ext/ca_sort_kernels.h +70 -0
  59. data/ext/ca_sweep_engine.c +104 -81
  60. data/ext/ca_sweep_engine.h +7 -20
  61. data/ext/ca_triop_dispatch.c +4 -1
  62. data/ext/ca_triop_dispatch.h +5 -2
  63. data/ext/caframe_csv_reader.c +542 -0
  64. data/ext/carray.h +241 -92
  65. data/ext/carray_access.c +608 -276
  66. data/ext/carray_address_basis.c +494 -97
  67. data/ext/carray_attribute.c +129 -4
  68. data/ext/carray_bincount.c +39 -7
  69. data/ext/carray_broadcast.c +56 -19
  70. data/ext/carray_build_flags.h +1 -1
  71. data/ext/carray_call_cfunc.c +108 -28
  72. data/ext/carray_cast.c +1576 -223
  73. data/ext/carray_cast_func.rb +77 -24
  74. data/ext/carray_class.c +4 -3
  75. data/ext/carray_conversion.c +208 -75
  76. data/ext/carray_copy.c +82 -24
  77. data/ext/carray_core.c +646 -162
  78. data/ext/carray_count.c +171 -88
  79. data/ext/carray_element.c +94 -60
  80. data/ext/carray_factorize.c +670 -324
  81. data/ext/carray_generate.c +260 -83
  82. data/ext/carray_histogram.c +209 -106
  83. data/ext/carray_hold.c +14 -16
  84. data/ext/carray_index_classifier.c +422 -243
  85. data/ext/carray_internal.h +692 -3
  86. data/ext/carray_kernels_bincmp.c +7 -0
  87. data/ext/carray_kernels_binop.c +487 -120
  88. data/ext/carray_kernels_init.c +653 -50
  89. data/ext/carray_kernels_moncmp.c +15 -8
  90. data/ext/carray_kernels_monop.c +99 -43
  91. data/ext/carray_kernels_reduce_aggregate.c +3925 -6112
  92. data/ext/carray_kernels_reduce_boolean.c +112 -36
  93. data/ext/carray_kernels_reduce_cumulative.c +2127 -6903
  94. data/ext/carray_kernels_reduce_extreme.c +3032 -2892
  95. data/ext/carray_kernels_reduce_variance.c +439 -500
  96. data/ext/carray_kernels_scan.c +1097 -488
  97. data/ext/carray_kernels_search.c +3787 -2176
  98. data/ext/carray_kernels_sort.c +1200 -920
  99. data/ext/carray_kernels_triop.c +479 -7
  100. data/ext/carray_key_windows.c +216 -0
  101. data/ext/carray_lazy.c +967 -153
  102. data/ext/carray_loop.c +81 -65
  103. data/ext/carray_mask.c +910 -324
  104. data/ext/carray_math_kernel.h +1 -0
  105. data/ext/carray_median_percentile.c +299 -100
  106. data/ext/carray_memory_view.c +872 -758
  107. data/ext/carray_operator.c +1171 -364
  108. data/ext/carray_order.c +505 -133
  109. data/ext/carray_partition.c +112 -65
  110. data/ext/carray_random.c +327 -239
  111. data/ext/carray_round.c +273 -0
  112. data/ext/carray_scatter.c +346 -78
  113. data/ext/carray_segment.c +257 -0
  114. data/ext/carray_slab.c +249 -86
  115. data/ext/carray_sort.c +224 -227
  116. data/ext/carray_sort_kernel.c +8 -1
  117. data/ext/carray_struct.c +118 -39
  118. data/ext/carray_test.c +193 -69
  119. data/ext/carray_time_text.c +1182 -0
  120. data/ext/carray_undef.c +4 -0
  121. data/ext/carray_utils.c +579 -113
  122. data/ext/extconf.rb +27 -2
  123. data/ext/mk_call_cfunc.rb +19 -4
  124. data/ext/mk_pow5_table.rb +35 -0
  125. data/ext/mkkernel.rb +1202 -1014
  126. data/ext/ruby_carray.c +17 -5
  127. data/ext/version.h +4 -4
  128. data/ext/version.rb +4 -2
  129. data/lib/carray/attribute.rb +160 -17
  130. data/lib/carray/autoload_carray.rb +23 -27
  131. data/lib/carray/autoload_method_extension.rb +20 -5
  132. data/lib/carray/axis_group.rb +360 -63
  133. data/lib/carray/basics.rb +162 -28
  134. data/lib/carray/bincount_nd.rb +18 -2
  135. data/lib/carray/block_iterator.rb +231 -58
  136. data/lib/carray/boolean_reduce.rb +34 -42
  137. data/lib/carray/categorical.rb +242 -52
  138. data/lib/carray/categorical_iterator.rb +437 -827
  139. data/lib/carray/complex.rb +41 -34
  140. data/lib/carray/conditional.rb +150 -14
  141. data/lib/carray/const_string.rb +59 -4
  142. data/lib/carray/construct.rb +15 -11
  143. data/lib/carray/data_type_extension.rb +1 -0
  144. data/lib/carray/distance_limit.rb +77 -0
  145. data/lib/carray/fixlen_string.rb +7 -1
  146. data/lib/carray/frame/column_verbs.rb +70 -0
  147. data/lib/carray/frame/concat.rb +157 -6
  148. data/lib/carray/frame/convert.rb +82 -7
  149. data/lib/carray/frame/csv_parser.rb +688 -87
  150. data/lib/carray/frame/describe.rb +80 -0
  151. data/lib/carray/frame/frame.rb +369 -45
  152. data/lib/carray/frame/group.rb +631 -90
  153. data/lib/carray/frame/io.rb +506 -79
  154. data/lib/carray/frame/join.rb +411 -62
  155. data/lib/carray/frame/records.rb +116 -19
  156. data/lib/carray/frame/reshape.rb +455 -0
  157. data/lib/carray/frame/sort.rb +30 -18
  158. data/lib/carray/frame/verbs.rb +868 -61
  159. data/lib/carray/frame/windows.rb +117 -0
  160. data/lib/carray/frame.rb +4 -0
  161. data/lib/carray/fuse_source.rb +118 -2
  162. data/lib/carray/fusion.rb +257 -42
  163. data/lib/carray/histogram.rb +6 -1
  164. data/lib/carray/inspect.rb +54 -13
  165. data/lib/carray/iterator.rb +99 -9
  166. data/lib/carray/key_windows.rb +620 -0
  167. data/lib/carray/lazy.rb +216 -193
  168. data/lib/carray/mask_gap_fill.rb +112 -92
  169. data/lib/carray/math.rb +32 -19
  170. data/lib/carray/meld_reduce.rb +52 -21
  171. data/lib/carray/methods/align_addr.rb +8 -4
  172. data/lib/carray/methods/bin.rb +26 -18
  173. data/lib/carray/methods/bincount.rb +18 -2
  174. data/lib/carray/methods/bit_string.rb +15 -4
  175. data/lib/carray/methods/choose.rb +16 -3
  176. data/lib/carray/methods/composition.rb +18 -10
  177. data/lib/carray/methods/factorize.rb +2 -2
  178. data/lib/carray/methods/gather_nd.rb +25 -5
  179. data/lib/carray/methods/insert_block.rb +9 -14
  180. data/lib/carray/methods/is_between.rb +59 -0
  181. data/lib/carray/methods/is_in.rb +140 -10
  182. data/lib/carray/methods/join.rb +2 -7
  183. data/lib/carray/methods/lag.rb +49 -0
  184. data/lib/carray/methods/locate_addr.rb +182 -45
  185. data/lib/carray/methods/mode.rb +18 -1
  186. data/lib/carray/methods/nunique.rb +11 -6
  187. data/lib/carray/methods/repeat.rb +1 -20
  188. data/lib/carray/methods/resize.rb +21 -23
  189. data/lib/carray/methods/snap.rb +34 -12
  190. data/lib/carray/methods/unique.rb +11 -2
  191. data/lib/carray/methods/value_counts.rb +4 -11
  192. data/lib/carray/record_order.rb +208 -0
  193. data/lib/carray/rng.rb +3 -0
  194. data/lib/carray/runtime.rb +65 -17
  195. data/lib/carray/segment_iterator.rb +1221 -0
  196. data/lib/carray/serialize.rb +214 -30
  197. data/lib/carray/slab_iterator.rb +101 -27
  198. data/lib/carray/stack.rb +10 -4
  199. data/lib/carray/string.rb +105 -5
  200. data/lib/carray/string_operation_extension.rb +12 -4
  201. data/lib/carray/struct.rb +137 -58
  202. data/lib/carray/struct_builder.rb +124 -17
  203. data/lib/carray/time.rb +1222 -186
  204. data/lib/carray/window_iterator.rb +242 -81
  205. data/lib/carray.rb +9 -2
  206. data/yard-stubs/ca_obj_array.rb +4 -4
  207. data/yard-stubs/ca_obj_bitarray.rb +7 -0
  208. data/yard-stubs/ca_obj_bitfield.rb +23 -12
  209. data/yard-stubs/ca_obj_fake.rb +1 -1
  210. data/yard-stubs/ca_obj_field.rb +5 -1
  211. data/yard-stubs/ca_obj_grid.rb +21 -10
  212. data/yard-stubs/ca_obj_refer.rb +5 -4
  213. data/yard-stubs/ca_obj_roll.rb +2 -3
  214. data/yard-stubs/ca_obj_shift.rb +5 -1
  215. data/yard-stubs/ca_obj_stride.rb +10 -7
  216. data/yard-stubs/ca_obj_tile.rb +1 -1
  217. data/yard-stubs/ca_obj_transpose.rb +1 -1
  218. data/yard-stubs/ca_obj_window.rb +9 -5
  219. data/yard-stubs/carray_access.rb +11 -5
  220. data/yard-stubs/carray_attribute.rb +0 -5
  221. data/yard-stubs/carray_broadcast.rb +1 -1
  222. data/yard-stubs/carray_cast.rb +88 -43
  223. data/yard-stubs/carray_conversion.rb +15 -2
  224. data/yard-stubs/carray_copy.rb +12 -5
  225. data/yard-stubs/carray_core.rb +3 -3
  226. data/yard-stubs/carray_count.rb +9 -0
  227. data/yard-stubs/carray_element.rb +10 -4
  228. data/yard-stubs/carray_generate.rb +21 -1
  229. data/yard-stubs/carray_lazy.rb +5 -1
  230. data/yard-stubs/carray_loop.rb +4 -1
  231. data/yard-stubs/carray_mask.rb +60 -12
  232. data/yard-stubs/carray_math.rb +52 -14
  233. data/yard-stubs/carray_median_percentile.rb +15 -8
  234. data/yard-stubs/carray_memory_view.rb +40 -23
  235. data/yard-stubs/carray_order.rb +61 -29
  236. data/yard-stubs/carray_random.rb +13 -4
  237. data/yard-stubs/carray_scatter.rb +21 -9
  238. data/yard-stubs/carray_segment.rb +72 -0
  239. data/yard-stubs/carray_slab.rb +10 -2
  240. data/yard-stubs/carray_sort.rb +49 -8
  241. data/yard-stubs/carray_test.rb +15 -3
  242. data/yard-stubs/carray_utils.rb +0 -26
  243. metadata +19 -5
  244. data/ext/ca_for_each_element.h +0 -239
  245. data/ext/carray_kernels_map.c +0 -3467
  246. data/lib/carray/arrow_tensor.rb +0 -401
  247. data/lib/carray/table.rb +0 -108
@@ -8,10 +8,15 @@ class CArray
8
8
  # @overload copy
9
9
  # Returns a fresh entity CArray with the same shape, `data_type`,
10
10
  # element values, and mask state as `self`. Always allocates and
11
- # copies, even when `self` is already an entity.
11
+ # copies, even when `self` is already an entity. The copy gets the
12
+ # attributes `self` shows (`attrs`) as its own.
12
13
  #
13
14
  # Use `copy` when you need an array you own and can mutate
14
- # without affecting any source.
15
+ # without affecting any source. It is the only way to copy a
16
+ # CArray: `to_ca` returns `self`, and `dup` / `clone` on a view
17
+ # return another view onto the same storage, so writing to any of
18
+ # them writes to the source. Don't use `dup`, `clone` or `to_ca`
19
+ # to copy.
15
20
  # @return [CArray] independent entity.
16
21
  # @example A view's copy is independent of its source
17
22
  # a = CArray.float64(4).seq
@@ -59,17 +64,19 @@ class CArray
59
64
  # @param data_type [Symbol] target element type
60
65
  # (e.g. `:int32`, `:float64`, `:fixlen`).
61
66
  # @param bytes [Integer] element byte size; required for
62
- # `:fixlen`, ignored for numeric types.
67
+ # `:fixlen` (1 or more), ignored for numeric types.
63
68
  # @return [CArray]
64
69
  # @overload template { value }
65
70
  # With a 0-arity block, fills every element of the result with
66
71
  # the block's return value (broadcast). Equivalent to
67
- # `template.tap { |t| t[] = value }`.
72
+ # `template.tap { |t| t[] = value }`. On a Face the value is
73
+ # stored as a store writes it (a String for a CAString).
68
74
  # @yieldreturn [Object] value to broadcast to every element.
69
75
  # @return [CArray]
70
76
  # @overload template { |*idx| ... }
71
77
  # With a block of arity > 0, calls the block once per cell with
72
- # the multi-dimensional index `*idx` and stores the result.
78
+ # the multi-dimensional index `*idx` and stores the result, as a
79
+ # store writes it.
73
80
  # @yieldparam idx [Array<Integer>] per-axis indices.
74
81
  # @yieldreturn [Object]
75
82
  # @return [CArray]
@@ -10,7 +10,7 @@ class CArray
10
10
  # Only valid when `self` carries a `data_class` (e.g. a
11
11
  # `CARecord`).
12
12
  # @return [Array<Symbol>]
13
- # @raise [RuntimeError] if `self` has no `data_class`.
13
+ # @raise [TypeError] if `self` has no `data_class`.
14
14
  def members; end
15
15
 
16
16
  # @overload fields
@@ -18,7 +18,7 @@ class CArray
18
18
  # declaration order. Each entry is a CArray sharing storage with
19
19
  # `self`.
20
20
  # @return [Array<CArray>]
21
- # @raise [RuntimeError] if `self` has no `data_class`.
21
+ # @raise [TypeError] if `self` has no `data_class`.
22
22
  def fields; end
23
23
 
24
24
  # @overload fields_at(*names)
@@ -27,7 +27,7 @@ class CArray
27
27
  # @param names [Array<Symbol, String, Integer>] member names or
28
28
  # positional indices.
29
29
  # @return [Array<CArray>]
30
- # @raise [RuntimeError] if `self` has no `data_class`.
30
+ # @raise [TypeError] if `self` has no `data_class`.
31
31
  def fields_at(*names); end
32
32
 
33
33
  # @!endgroup
@@ -26,6 +26,11 @@ class CArray
26
26
  # Mask-cardinality and value-match are distinct concepts, so the
27
27
  # overloading is unambiguous.
28
28
  #
29
+ # On an `:object` array a cell counts when it is `==` to `v` (so `1`
30
+ # and `1.0` match), as {#eq} compares; the hash-based family
31
+ # ({#is_in}, {#value_counts}) uses `eql?` instead, as Ruby's
32
+ # `Array#uniq` does.
33
+ #
29
34
  # Dispatch:
30
35
  # - no argument: forwards to {#count_not_masked} (present-cell
31
36
  # count).
@@ -41,6 +46,10 @@ class CArray
41
46
  # (`2`, `1.0`, `nil`, …) raises `TypeError`.
42
47
  # - `self` is numeric, `v` is scalar: `v` must be numeric (true /
43
48
  # false are rejected -- they are the boolean array's domain).
49
+ # `v` (a scalar or an array) is compared in the type it and the
50
+ # array match in, as {#eq} compares: `CA_INT32([1, 2]).count(1.5)`
51
+ # is `0`, `CA_UINT8([255]).count(-1)` is `0` (-1 is not 255), and an
52
+ # Integer the array's type cannot hold is counted `0` times.
44
53
  # - `self.data_type == :object`, `v` is scalar: cells equal to `v`
45
54
  # by Ruby `==`, so `count(1)` and `count(1.0)` agree, and `true` /
46
55
  # `false` / `nil` are ordinary values to count.
@@ -40,9 +40,10 @@ class CArray
40
40
  # @overload elem_fetch(idx)
41
41
  # Returns the value at position `idx` (cast back to the
42
42
  # appropriate Ruby type). Returns `UNDEF` if the cell is masked.
43
- # Returns `nil` if `self.empty?`.
43
+ # A negative index counts from the end.
44
44
  # @param idx [Integer, Array<Integer>]
45
- # @return [Object, nil]
45
+ # @return [Object]
46
+ # @raise [IndexError] if `idx` names no cell, an empty array included.
46
47
  def elem_fetch(idx); end
47
48
 
48
49
  # @overload elem_incr(idx)
@@ -67,7 +68,10 @@ class CArray
67
68
  # @param idx [Integer, Array<Integer>]
68
69
  # @param v [Numeric]
69
70
  # @return [self]
70
- # @raise [CArray::DataTypeError] for non-numeric `data_type`.
71
+ # @raise [CArray::DataTypeError] for a non-numeric or complex
72
+ # `data_type` (complex values have no order).
73
+ # @raise [RangeError] when `v` wins but does not fit the type, as
74
+ # `self[idx] = v` raises.
71
75
  def elem_min(idx, v); end
72
76
 
73
77
  # @overload elem_max(idx, v)
@@ -77,7 +81,9 @@ class CArray
77
81
  # @param idx [Integer, Array<Integer>]
78
82
  # @param v [Numeric]
79
83
  # @return [self]
80
- # @raise [CArray::DataTypeError] for non-numeric `data_type`.
84
+ # @raise [CArray::DataTypeError] for a non-numeric or complex
85
+ # `data_type`.
86
+ # @raise [RangeError] when `v` wins but does not fit the type.
81
87
  def elem_max(idx, v); end
82
88
 
83
89
  # @!endgroup
@@ -8,8 +8,12 @@ class CArray
8
8
  # @overload where
9
9
  # Returns a fresh 1-D CArray of flat addresses where `self` is
10
10
  # non-zero (or `true`). Masked positions are excluded.
11
- # Non-boolean arrays are first coerced to boolean.
11
+ # An integer, float or complex array selects its non-zero cells
12
+ # (NaN is non-zero). Any other array that is not boolean is cast to
13
+ # boolean, which takes only `0`, `1`, `true` and `false`.
12
14
  # @return [CArray] 1-D, `:int64` (`ca_size_t`).
15
+ # @raise [CArray::DataTypeError, TypeError] if an array that is not
16
+ # boolean, integer, float or complex cannot be cast to boolean.
13
17
  # @example
14
18
  # CArray.int32(5) { [0, 1, 0, 2, 0] }.where.to_a
15
19
  # # => [1, 3]
@@ -32,8 +36,15 @@ class CArray
32
36
  # Fills `self` in row-major order with `init_val`, `init_val +
33
37
  # step`, `init_val + 2*step`, ...
34
38
  #
39
+ # On an integer array an `init_val` or `step` that is not an Integer
40
+ # (a Float, a Rational) makes each cell `init_val + step*i` cut
41
+ # toward zero, as a store takes a float: `int32.seq(0.5, 0.5)` is
42
+ # `[0, 1, 1, 2]`. The first and last values must fit the type.
43
+ #
35
44
  # For `:object` arrays only, `step` may be a Symbol naming the
36
45
  # stepping method to invoke on the previous element (e.g. `:succ`).
46
+ # A CAString takes only a run of Strings (`s.seq!("a", :succ)`), as a
47
+ # store into it does.
37
48
  # @param init_val [Numeric, Object]
38
49
  # @param step [Numeric, Symbol]
39
50
  # @return [self]
@@ -49,6 +60,15 @@ class CArray
49
60
  # @return [self]
50
61
  # @raise [ArgumentError] if `axis` is out of range or not a single
51
62
  # integer.
63
+ # @raise [RangeError] for an integer array, if `init_val` does not fit
64
+ # its type, or an Integer `step` is larger than the type can hold. An
65
+ # unsigned array takes a negative step (a descending run). A run of
66
+ # Integers that passes the end of the type wraps, as integer
67
+ # arithmetic does; a real run (a Float or Rational argument) whose
68
+ # first or last value does not fit raises.
69
+ # @raise [FloatDomainError] for an integer array given a NaN argument.
70
+ # @raise [TypeError] if `init_val` or `step` is not a number (a Symbol
71
+ # `step` on an `:object` array excepted).
52
72
  def seq!(*); end
53
73
 
54
74
  # @overload seq(init_val = 0, step = 1, axis: nil)
@@ -17,7 +17,11 @@ class CArray
17
17
  # materialise. The marker is transient — a Ruby reference can
18
18
  # re-consume it (`m = a.lazy; m.sqrt + m.sin`) without side
19
19
  # effects on `self`.
20
- # @return [CALazyMarker]
20
+ #
21
+ # A Face (`CATime`, `CACategorical`, a string array, ...) returns
22
+ # `self`: a lazy tree computes on storage and would drop what the
23
+ # Face means, so operations on a Face stay eager.
24
+ # @return [CALazyMarker, CArray] the marker, or `self` for a Face
21
25
  def lazy; end
22
26
  # @!endgroup
23
27
  end
@@ -53,7 +53,10 @@ class CArray
53
53
 
54
54
  # @overload map!
55
55
  # Replaces each element of `self` with the block's return value.
56
- # Mutates `self`.
56
+ # Mutates `self`. When the block raises or breaks part way, or
57
+ # returns a value that cannot be stored, the cells already replaced
58
+ # stay replaced -- through a view as well, which writes them back to
59
+ # its parent. The same holds for every `map_*!` below.
57
60
  # @yieldparam elem [Object]
58
61
  # @yieldreturn [Object] new value for the cell.
59
62
  # @return [self]
@@ -27,6 +27,9 @@ class CArray
27
27
  # mask (`value_array? == true`).
28
28
  #
29
29
  # Use this to read or write the data slot of masked elements.
30
+ # Nothing in a value array is masked, so `unmask` on it does nothing,
31
+ # while a write that would mask a cell (`UNDEF`, `mask=`,
32
+ # `invert_mask`) raises TypeError.
30
33
  # @return [CArray]
31
34
  def value; end
32
35
 
@@ -35,6 +38,11 @@ class CArray
35
38
  # element is `1` where `self` is masked and `0` where it is not.
36
39
  # The returned view itself cannot carry a mask.
37
40
  #
41
+ # The mask of a view is a view over its parent's mask: it follows
42
+ # later changes to the parent's mask, and so does its `dup` or
43
+ # `clone`, which is another view onto the same parent mask (a write
44
+ # to it lands in the parent's mask). Use `copy` for a mask of its own.
45
+ #
38
46
  # Returns `0` (Integer) if `self` has no mask array attached.
39
47
  # @return [CArray, Integer]
40
48
  def mask; end
@@ -43,6 +51,12 @@ class CArray
43
51
  # Sets the mask array of `self` to `new_mask`. Allocates the mask
44
52
  # array first if `self` does not yet have one. Cannot be called on
45
53
  # a value array or a mask array.
54
+ #
55
+ # `mask=` replaces the whole mask with `new_mask`. A masked cell of
56
+ # `new_mask` makes the cell masked, as a masked value does in any
57
+ # store. To mask the cells where a condition holds, prefer
58
+ # `self[cond] = UNDEF`. There a masked cell of `cond` selects nothing,
59
+ # as it does in any index.
46
60
  # @param new_mask [CArray, Boolean, Integer] mask values. A
47
61
  # non-CArray value is broadcast and stored elementwise; a CArray
48
62
  # of any type is coerced to boolean.
@@ -74,7 +88,8 @@ class CArray
74
88
  # Clears the mask state and overwrites the data at previously
75
89
  # masked positions with `fill_value`. Mutates `self`.
76
90
  # @param fill_value [Object] value to store at each previously
77
- # masked position. Cast to `self.data_type`.
91
+ # masked position, converted as a store into `self` converts it.
92
+ # `UNDEF` leaves the masked cells masked.
78
93
  # @return [self]
79
94
  # @overload unmask(method:, axis: nil)
80
95
  # Fills masked cells in place from neighbouring valid cells along
@@ -90,7 +105,11 @@ class CArray
90
105
  # linearly by index from the two bracketing valid cells (numeric
91
106
  # data_type, or a time Face — `CATime` / `CATimedelta` interpolate
92
107
  # through their own `linear_fetch`, so the filled values stay on the
93
- # array's unit and are rounded to it).
108
+ # array's unit and are rounded to it). An integer array takes the
109
+ # nearest integer, half away from zero (`[190, _, _, 341]` fills
110
+ # `240, 291`). The interpolation runs in float64, so in an int64
111
+ # array with values beyond 2**53 the filled cells may be off by the
112
+ # float64 spacing there; the valid cells are not touched.
94
113
  # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
95
114
  # @return [self]
96
115
  def unmask(*, method: nil, axis: nil); end
@@ -106,7 +125,8 @@ class CArray
106
125
  #
107
126
  # Replaces the removed `unmask_copy(fill)` from 2.x.
108
127
  # @param fill_value [Object] value to substitute at masked
109
- # positions. Cast to `self.data_type`.
128
+ # positions, converted as a store into `self` converts it.
129
+ # `UNDEF` leaves them masked (the copy keeps the mask).
110
130
  # @return [CArray]
111
131
  # @overload strip_mask(method:, axis: nil)
112
132
  # Returns a new array with masked cells filled from neighbouring
@@ -151,6 +171,8 @@ class CArray
151
171
  # Flips the mask state of every element of `self` in place
152
172
  # (masked ↔ not masked). Mutates `self`.
153
173
  # @return [self]
174
+ # @raise [FrozenError] if `self` is frozen or a view of a frozen array.
175
+ # @raise [RuntimeError] if `self` is read-only (a lazy expression, for one).
154
176
  def invert_mask; end
155
177
 
156
178
  # @overload inherit_mask(*others)
@@ -160,6 +182,8 @@ class CArray
160
182
  # @param others [Array<CArray>] arrays whose mask states are
161
183
  # OR-ed into `self`. Non-CArray arguments are ignored.
162
184
  # @return [self]
185
+ # @raise [ArgumentError] if an array in `others` other than a scalar
186
+ # has fewer elements than `self`.
163
187
  def inherit_mask(*others); end
164
188
 
165
189
  # @overload inherit_mask_replace(*others)
@@ -169,28 +193,50 @@ class CArray
169
193
  # @param others [Array<CArray>] arrays whose mask states form the
170
194
  # new mask of `self`.
171
195
  # @return [self]
196
+ # @raise [ArgumentError] if an array in `others` other than a scalar
197
+ # has fewer elements than `self`.
172
198
  def inherit_mask_replace(*others); end
173
199
 
174
200
  # @overload count_masked
175
201
  # Returns the total number of masked elements in `self`.
176
202
  # @return [Integer]
177
- # @overload count_masked(axis:)
203
+ # @overload count_masked(axis:, keep_axis: false, min_count: nil, fill_value: nil)
178
204
  # Returns the per-slice count of masked elements along the given
179
205
  # axis or axes. The result is an int64 CArray with `axis` removed
180
- # from `shape`.
206
+ # from `shape` (kept as length 1 with `keep_axis: true`). Naming
207
+ # every axis without `keep_axis:` returns an Integer, as the form
208
+ # without `axis:` does. The answer is the same whether or not
209
+ # `self` has a mask.
181
210
  # @param axis [Integer, Array<Integer>] axis or axes to reduce.
182
- # @return [CArray] int64 CArray.
211
+ # @param keep_axis [Boolean] keep the reduced axes as length 1.
212
+ # @param min_count [Integer, nil] cells with fewer than this many
213
+ # elements are UNDEF. A count of the mask reads every element,
214
+ # masked or not, so this compares with the slice size.
215
+ # @param fill_value [Object, nil] value written into UNDEF cells.
216
+ # @return [CArray, Integer]
217
+ # @raise [ArgumentError] if an axis is out of range, repeated, or
218
+ # the axis list is empty.
183
219
  def count_masked(*, **); end
184
220
 
185
221
  # @overload count_not_masked
186
222
  # Returns the total number of not-masked elements in `self`.
187
223
  # @return [Integer]
188
- # @overload count_not_masked(axis:)
189
- # Returns the per-slice count of not-masked elements along the
190
- # given axis or axes. The result is an int64 CArray with `axis`
191
- # removed from `shape`.
224
+ # @overload count_not_masked(axis:, keep_axis: false, min_count: nil, fill_value: nil)
225
+ # Returns the per-slice count of not-masked elements along the given
226
+ # axis or axes. The result is an int64 CArray with `axis` removed
227
+ # from `shape` (kept as length 1 with `keep_axis: true`). Naming
228
+ # every axis without `keep_axis:` returns an Integer, as the form
229
+ # without `axis:` does. The answer is the same whether or not
230
+ # `self` has a mask.
192
231
  # @param axis [Integer, Array<Integer>] axis or axes to reduce.
193
- # @return [CArray] int64 CArray.
232
+ # @param keep_axis [Boolean] keep the reduced axes as length 1.
233
+ # @param min_count [Integer, nil] cells with fewer than this many
234
+ # elements are UNDEF. A count of the mask reads every element,
235
+ # masked or not, so this compares with the slice size.
236
+ # @param fill_value [Object, nil] value written into UNDEF cells.
237
+ # @return [CArray, Integer]
238
+ # @raise [ArgumentError] if an axis is out of range, repeated, or
239
+ # the axis list is empty.
194
240
  def count_not_masked(*, **); end
195
241
 
196
242
  # @!endgroup
@@ -202,7 +248,9 @@ class CArray
202
248
  # In-place equivalent: `ca[:eq, v] = UNDEF`.
203
249
  #
204
250
  # Replaces the removed `maskout(v)` from 2.x.
205
- # @param v [Object] value to mask. Cast to `self.data_type`.
251
+ # `v` is compared as {#eq} compares it, by value: `1.5` masks nothing
252
+ # in an integer array, and `-1` does not mask `255` in a `uint8` one.
253
+ # @param v [Object] value to mask.
206
254
  # @return [CArray]
207
255
  def mask_eq(v); end
208
256
 
@@ -25,12 +25,15 @@ class CArray
25
25
  # division is true division, as Ruby's `Float#/` is, so that
26
26
  # identity is an integer one. Boolean arrays participate as their
27
27
  # 0/1 storage. Masked elements stay masked, and a masked cell is
28
- # never divided.
28
+ # never divided. The signed minimum divided by `-1` does not fit and
29
+ # is answered as the wrapped negation: `MIN / -1` is `MIN`.
29
30
  # @param other [CArray, Numeric] divisor, broadcast to `self.shape`.
30
31
  # @return [CArray] result of the promoted `data_type` of the two
31
32
  # operands.
32
33
  # @raise [ZeroDivisionError] when an integer divisor is `0`. Float
33
34
  # division returns `Infinity` or `NaN` instead.
35
+ # @raise [RangeError] when an Integer `other` does not fit the
36
+ # integer `data_type` of `self`.
34
37
  # @example
35
38
  # CA_INT32([-7, -1, 7]) / 3 # => [ -3, -1, 2 ]
36
39
  # CA_DOUBLE([-7.0]) / 3.0 # => [ -2.3333333333333335 ]
@@ -122,7 +125,33 @@ class CArray
122
125
  # keeps its sign. Masked elements stay masked. An `:object`
123
126
  # array delegates to each element's `#round`.
124
127
  # @return [CArray] same `data_type` as `self`.
125
- def round; end
128
+ # @overload round(ndigits)
129
+ # Returns a new array with each element rounded to `ndigits` decimal
130
+ # digits, to the value Ruby's `Float#round(ndigits)` gives for a float
131
+ # element and `Integer#round(ndigits)` for an integer one, half away
132
+ # from zero: `CA_FLOAT64([1.005, 2.675]).round(2)` is `[1.01, 2.68]`,
133
+ # as `1.005.round(2)` and `2.675.round(2)` are. A negative `ndigits`
134
+ # rounds to tens, hundreds, ...: `CA_INT32([125, -125]).round(-1)` is
135
+ # `[130, -130]`. The result keeps `self`'s `data_type`, so a float
136
+ # array stays float for every `ndigits`, and a `:float32` element is
137
+ # rounded from its own value. `NaN` and the infinities are left as
138
+ # they are. Masked elements stay masked. An `:object` array calls
139
+ # each element's `round(ndigits)`. `round(0)` is `round`.
140
+ # @param ndigits [Integer] decimal digits to keep; negative rounds to
141
+ # the left of the decimal point.
142
+ # @return [CArray] same `data_type` as `self`.
143
+ # @raise [TypeError] if `ndigits` is not an Integer.
144
+ # @raise [RangeError] if a rounded integer does not fit the
145
+ # `data_type` (`CA_INT8([125]).round(-1)`).
146
+ # @raise [CArray::DataTypeError] for a complex or fixed-length array.
147
+ def round(ndigits = nil); end
148
+
149
+ # @overload round!(ndigits = nil)
150
+ # Rounds `self` in place, as {#round} does. A boolean array can not
151
+ # hold the rounded values and raises when `ndigits` is given.
152
+ # @param ndigits [Integer, nil] decimal digits to keep.
153
+ # @return [self]
154
+ def round!(ndigits = nil); end
126
155
 
127
156
  # @overload frac
128
157
  # Returns a new array of the fractional part of each element:
@@ -215,7 +244,7 @@ class CArray
215
244
  # @overload rcp_mul(other)
216
245
  # Returns `other` divided element-wise by `self` -- the reciprocal
217
246
  # of {#/} in operand order, so that scaling a constant by an array
218
- # needs no temporary.
247
+ # needs no temporary. Integer division floors, as {#/} does.
219
248
  # @param other [CArray, Numeric] dividend, broadcast to `self.shape`.
220
249
  # @return [CArray] result of the promoted `data_type` of the two
221
250
  # operands.
@@ -241,12 +270,12 @@ class CArray
241
270
  #
242
271
  # A numeric array keeps its `data_type`; a complex array returns the
243
272
  # real magnitude at that complex type's own width, so a `:cmplx64`
244
- # yields `:float32` just as {#real} and {#imag} do. For the form
245
- # that keeps a complex array complex (magnitude with a zero
246
- # imaginary part) use {#abs_i}, which also accepts `:object`.
247
- # @return [CArray] `self`'s `data_type` for numeric input; the real
248
- # component type for complex input.
249
- # @raise [CArray::DataTypeError] for a boolean or `:object` array.
273
+ # yields `:float32` just as {#real} and {#imag} do. An `:object`
274
+ # array calls each cell's `abs`. For the form that keeps a complex
275
+ # array complex (magnitude with a zero imaginary part) use {#abs_i}.
276
+ # @return [CArray] `self`'s `data_type` for numeric and `:object`
277
+ # input; the real component type for complex input.
278
+ # @raise [CArray::DataTypeError] for a boolean array.
250
279
  # @example
251
280
  # CA_CMPLX64([Complex(3, 4)]).abs # => [ 5.0 ] (:float32)
252
281
  def abs; end
@@ -738,7 +767,8 @@ class CArray
738
767
  # comparison) and `:object` (Ruby `==`) `data_type`. A masked
739
768
  # element yields a masked result rather than `false`. Floating
740
769
  # point equality is exact here; for a tolerant comparison see
741
- # {#is_close} (absolute) or {#is_equiv} (relative).
770
+ # {#is_close} (absolute) or {#is_equiv} (relative). Integers compare
771
+ # by value, as for {#<}.
742
772
  # @param other [CArray, Numeric, Object] comparand, broadcast to
743
773
  # `self.shape`.
744
774
  # @return [CArray] `:boolean`, same shape as `self`.
@@ -760,6 +790,11 @@ class CArray
760
790
  # Accepts numeric, boolean, `:fixlen` (byte order, shorter first on
761
791
  # a common prefix) and `:object` (Ruby `<`) `data_type`s. Complex
762
792
  # arrays have no ordering and raise.
793
+ #
794
+ # Integers compare by value: an unsigned array against a signed one
795
+ # answers as the Integers would (`CA_UINT64([7]) < CA_INT64([-7])`
796
+ # is false), and so does an Integer the array's type cannot hold
797
+ # (`CA_UINT8([0]) > -1` is true).
763
798
  # @param other [CArray, Numeric, Object] comparand, broadcast to
764
799
  # `self.shape`.
765
800
  # @return [CArray] `:boolean`, same shape as `self`.
@@ -861,8 +896,11 @@ class CArray
861
896
  # Returns a boolean array that is true where an element is `NaN`.
862
897
  # @return [CArray] `:boolean`, same shape as `self`.
863
898
  # @raise [CArray::DataTypeError] for a boolean array.
864
- # @raise [NoMethodError] for an `:object` array whose elements do
865
- # not respond to `#nan?`.
899
+ # On an `:object` array an Integer or a Rational element is never
900
+ # `NaN`; other elements answer through `#nan?`.
901
+ # @raise [NoMethodError] for an `:object` array with an element that
902
+ # is not an Integer, a Rational or a Float and does not respond to
903
+ # `#nan?`.
866
904
  def is_nan; end
867
905
 
868
906
  # @overload is_inf
@@ -1043,7 +1081,7 @@ class CArray
1043
1081
  # Applies {#abs} to `self` in place, keeping `self`'s
1044
1082
  # `data_type`.
1045
1083
  # @return [self]
1046
- # @raise [RuntimeError] for a boolean array.
1084
+ # @raise [CArray::DataTypeError] for a boolean array.
1047
1085
  def abs!; end
1048
1086
 
1049
1087
  # @overload abs_i!
@@ -1093,7 +1131,7 @@ class CArray
1093
1131
  # Applies {#arg} to `self` in place, keeping `self`'s
1094
1132
  # `data_type`.
1095
1133
  # @return [self]
1096
- # @raise [RuntimeError] for an integer or boolean array, whose
1134
+ # @raise [CArray::DataTypeError] for an integer or boolean array, whose
1097
1135
  # `data_type` cannot hold the widened result -- {#arg} promotes it
1098
1136
  # instead of raising.
1099
1137
  def arg!; end
@@ -9,9 +9,11 @@ class CArray
9
9
  # Returns the median of `self` along `axis` (or over all elements
10
10
  # when `axis` is `nil`).
11
11
  #
12
- # Numeric arrays return a `Float`; `CA_OBJECT` arrays return the
13
- # result of Ruby `+` / `/` on the stored objects. Fixlen arrays
14
- # raise, since no numeric midpoint is defined.
12
+ # Numeric arrays return a `Float`. A `CA_OBJECT` array answers in
13
+ # its elements' own terms: the middle element itself, or the
14
+ # average of two as `(lo + hi) * (1/2)`, so an Integer, Rational or
15
+ # BigDecimal median is exact (`CA_OBJECT([1, 2]).median` is `3/2`).
16
+ # Fixlen arrays raise, since no numeric midpoint is defined.
15
17
  #
16
18
  # An even number of elements has no middle one, only the average of
17
19
  # two -- so an object array whose elements cannot be averaged (a
@@ -25,7 +27,9 @@ class CArray
25
27
  # `UNDEF` when `fill_value` is `nil`).
26
28
  #
27
29
  # With `keep_axis: true`, the reduced axis is retained with
28
- # length 1 rather than dropped.
30
+ # length 1 rather than dropped. Along the only axis of a 1-D array
31
+ # the result is a bare value, as `sum(axis: 0)` is (a one-cell array
32
+ # with `keep_axis: true`).
29
33
  # @param axis [Integer, nil]
30
34
  # @param min_count [Integer] minimum not-masked count required.
31
35
  # @param fill_value [Object, nil] replacement when the not-masked
@@ -45,7 +49,8 @@ class CArray
45
49
  # `p` may be given as individual positional arguments, a single
46
50
  # `Array<Numeric>`, or a single 1-D `CArray`. When the effective
47
51
  # `p` count (after flattening) is 1, the result is unwrapped:
48
- # flat form returns a `Float`, per-axis form returns a `CArray`.
52
+ # flat form returns a `Float`, per-axis form returns a `CArray`
53
+ # (a bare value along the only axis of a 1-D array, as {#median}).
49
54
  # With 2 or more `p` values the result is an `Array` whose length
50
55
  # matches the number of requested `p` values.
51
56
  #
@@ -64,9 +69,11 @@ class CArray
64
69
  # so only when the requested `p` actually falls between two
65
70
  # elements (`percentile(50)` of five Strings still answers).
66
71
  #
67
- # Numeric arrays produce `Float` results; `CA_OBJECT` arrays
68
- # apply Ruby `+` / `/` / `*` on the stored objects. Fixlen
69
- # arrays raise.
72
+ # Numeric arrays produce `Float` results. A `CA_OBJECT` array
73
+ # answers in its elements' own terms: a pick (`:lower`, `:higher`,
74
+ # `:nearest`) is the element itself, and `:linear` / `:midpoint`
75
+ # use the elements' arithmetic with an exact Rational weight, so an
76
+ # exact element gives an exact answer. Fixlen arrays raise.
70
77
  #
71
78
  # Masking, `min_count`, `fill_value`, and `keep_axis` follow the
72
79
  # same rules as {#median}.