carray 3.0.0 → 3.0.2

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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/CHANGELOG.md +845 -3
  4. data/{NEWS.md → CHANGELOG.v1.md} +1 -1
  5. data/README.md +33 -33
  6. data/carray.gemspec +12 -8
  7. data/ext/ca_axis_dispatch.c +33 -4
  8. data/ext/ca_axis_group.c +256 -114
  9. data/ext/ca_binop_dispatch.c +5 -6
  10. data/ext/ca_binop_dispatch.h +0 -7
  11. data/ext/ca_categorical_iterator.c +121 -67
  12. data/ext/ca_for_each_element.h +6 -8
  13. data/ext/ca_group_iter.c +1 -1
  14. data/ext/ca_kernel_iterator.c +386 -74
  15. data/ext/ca_kernel_iterator.h +145 -45
  16. data/ext/ca_obj_array.c +62 -20
  17. data/ext/ca_obj_bincmp.c +57 -27
  18. data/ext/ca_obj_binop.c +86 -30
  19. data/ext/ca_obj_block.c +4 -4
  20. data/ext/ca_obj_const_string.c +88 -27
  21. data/ext/ca_obj_face.c +104 -0
  22. data/ext/ca_obj_face.h +48 -1
  23. data/ext/ca_obj_fake.c +11 -0
  24. data/ext/ca_obj_fixlen_string.c +21 -6
  25. data/ext/ca_obj_grid.c +11 -3
  26. data/ext/ca_obj_meld.c +125 -22
  27. data/ext/ca_obj_moncmp.c +33 -14
  28. data/ext/ca_obj_monop.c +19 -7
  29. data/ext/ca_obj_object.c +107 -4
  30. data/ext/ca_obj_record.c +3 -1
  31. data/ext/ca_obj_refer.c +30 -6
  32. data/ext/ca_obj_roll.c +13 -5
  33. data/ext/ca_obj_select.c +49 -34
  34. data/ext/ca_obj_select_axis.c +16 -6
  35. data/ext/ca_obj_shift.c +3 -3
  36. data/ext/ca_obj_stack.c +3 -8
  37. data/ext/ca_obj_stride.c +178 -24
  38. data/ext/ca_obj_string.c +11 -5
  39. data/ext/ca_obj_tile.c +13 -5
  40. data/ext/ca_obj_time.c +3 -1
  41. data/ext/ca_obj_timedelta.c +3 -1
  42. data/ext/ca_obj_transpose.c +1 -1
  43. data/ext/ca_obj_triop.c +62 -23
  44. data/ext/ca_obj_window.c +94 -19
  45. data/ext/ca_op_cmplx64.h +123 -0
  46. data/ext/ca_op_ipower.c +1 -5
  47. data/ext/ca_rng_normal.h +42 -0
  48. data/ext/ca_rng_xoshiro256pp.h +105 -0
  49. data/ext/ca_sort_kernels.h +5 -5
  50. data/ext/ca_sweep_engine.c +362 -155
  51. data/ext/ca_sweep_engine.h +39 -9
  52. data/ext/ca_transform_common.c +7 -0
  53. data/ext/carray.h +148 -132
  54. data/ext/carray_access.c +83 -49
  55. data/ext/carray_address_basis.c +590 -0
  56. data/ext/carray_bincount.c +8 -8
  57. data/ext/carray_broadcast.c +102 -9
  58. data/ext/carray_build_flags.h +3 -0
  59. data/ext/carray_call_cfunc.c +2010 -335
  60. data/ext/carray_call_cfunc.h +153 -0
  61. data/ext/carray_cast.c +184 -72
  62. data/ext/carray_conversion.c +22 -22
  63. data/ext/carray_copy.c +67 -32
  64. data/ext/carray_core.c +140 -13
  65. data/ext/carray_count.c +10 -11
  66. data/ext/carray_element.c +7 -7
  67. data/ext/carray_factorize.c +72 -51
  68. data/ext/carray_hold.c +1 -1
  69. data/ext/carray_index_classifier.c +7 -21
  70. data/ext/carray_internal.h +36 -3
  71. data/ext/carray_kernels_bincmp.c +1 -0
  72. data/ext/carray_kernels_binop.c +320 -298
  73. data/ext/carray_kernels_init.c +1095 -0
  74. data/ext/carray_kernels_map.c +1 -0
  75. data/ext/carray_kernels_moncmp.c +1 -0
  76. data/ext/carray_kernels_monop.c +412 -411
  77. data/ext/carray_kernels_reduce_aggregate.c +256 -87
  78. data/ext/carray_kernels_reduce_boolean.c +1 -0
  79. data/ext/carray_kernels_reduce_cumulative.c +324 -54
  80. data/ext/carray_kernels_reduce_extreme.c +605 -58
  81. data/ext/carray_kernels_reduce_variance.c +1 -0
  82. data/ext/carray_kernels_scan.c +5 -4
  83. data/ext/carray_kernels_search.c +187 -106
  84. data/ext/carray_kernels_sort.c +1 -0
  85. data/ext/carray_kernels_triop.c +1 -0
  86. data/ext/carray_lazy.c +175 -5
  87. data/ext/carray_loop.c +7 -1
  88. data/ext/carray_mask.c +29 -13
  89. data/ext/carray_median_percentile.c +56 -1
  90. data/ext/carray_memory_view.c +46 -21
  91. data/ext/carray_operator.c +50 -53
  92. data/ext/carray_order.c +1 -1
  93. data/ext/carray_partition.c +4 -4
  94. data/ext/carray_random.c +391 -47
  95. data/ext/carray_scatter.c +1 -1
  96. data/ext/carray_slab.c +13 -0
  97. data/ext/carray_sort.c +22 -24
  98. data/ext/carray_sort_kernel.c +10 -10
  99. data/ext/carray_test.c +1 -1
  100. data/ext/extconf.rb +18 -0
  101. data/ext/mk_call_cfunc.rb +323 -145
  102. data/ext/mkkernel.rb +651 -129
  103. data/ext/ruby_carray.c +28 -17
  104. data/ext/version.h +4 -4
  105. data/lib/carray/autoload_carray.rb +24 -3
  106. data/lib/carray/autoload_method_extension.rb +14 -1
  107. data/lib/carray/axis_group.rb +84 -7
  108. data/lib/carray/basics.rb +63 -59
  109. data/lib/carray/bincount_nd.rb +12 -12
  110. data/lib/carray/block_iterator.rb +111 -25
  111. data/lib/carray/categorical.rb +154 -37
  112. data/lib/carray/categorical_iterator.rb +300 -151
  113. data/lib/carray/conditional.rb +14 -14
  114. data/lib/carray/const_string.rb +131 -27
  115. data/lib/carray/construct.rb +61 -0
  116. data/lib/carray/core_extensions.rb +62 -5
  117. data/lib/carray/data_type_extension.rb +21 -1
  118. data/lib/carray/data_type_limits.rb +91 -0
  119. data/lib/carray/fixlen_string.rb +1 -1
  120. data/lib/carray/frame/concat.rb +3 -3
  121. data/lib/carray/frame/convert.rb +1 -1
  122. data/lib/carray/frame/csv_parser.rb +11 -4
  123. data/lib/carray/frame/frame.rb +85 -21
  124. data/lib/carray/frame/group.rb +36 -3
  125. data/lib/carray/frame/io.rb +224 -15
  126. data/lib/carray/frame/records.rb +18 -4
  127. data/lib/carray/frame/sort.rb +1 -1
  128. data/lib/carray/frame/verbs.rb +32 -12
  129. data/lib/carray/fuse_source.rb +123 -0
  130. data/lib/carray/fusion.rb +218 -0
  131. data/lib/carray/histogram.rb +16 -16
  132. data/lib/carray/inspect.rb +43 -16
  133. data/lib/carray/iterator.rb +147 -3
  134. data/lib/carray/lazy.rb +88 -73
  135. data/lib/carray/mask_gap_fill.rb +3 -1
  136. data/lib/carray/meld_reduce.rb +2 -2
  137. data/lib/carray/methods/align_addr.rb +1 -1
  138. data/lib/carray/methods/composition.rb +1 -1
  139. data/lib/carray/methods/discovery_along.rb +74 -0
  140. data/lib/carray/methods/factorize.rb +50 -0
  141. data/lib/carray/methods/is_in.rb +25 -14
  142. data/lib/carray/methods/locate_addr.rb +81 -3
  143. data/lib/carray/methods/mask_duplicates.rb +36 -2
  144. data/lib/carray/methods/meshgrid.rb +4 -5
  145. data/lib/carray/methods/mode.rb +2 -2
  146. data/lib/carray/methods/nunique.rb +23 -2
  147. data/lib/carray/methods/repeat.rb +110 -0
  148. data/lib/carray/methods/snap.rb +7 -2
  149. data/lib/carray/methods/unique.rb +44 -4
  150. data/lib/carray/methods/value_counts.rb +2 -2
  151. data/lib/carray/rng.rb +86 -0
  152. data/lib/carray/runtime.rb +0 -19
  153. data/lib/carray/slab_iterator.rb +77 -19
  154. data/lib/carray/string_operation_extension.rb +10 -6
  155. data/lib/carray/time.rb +906 -491
  156. data/lib/carray/window_iterator.rb +421 -27
  157. data/lib/carray.rb +7 -5
  158. data/yard-stubs/ca_obj_array.rb +385 -0
  159. data/yard-stubs/ca_obj_bitarray.rb +38 -0
  160. data/yard-stubs/ca_obj_bitfield.rb +43 -0
  161. data/yard-stubs/ca_obj_block.rb +68 -0
  162. data/yard-stubs/ca_obj_byte_swap.rb +56 -0
  163. data/yard-stubs/ca_obj_fake.rb +31 -0
  164. data/yard-stubs/ca_obj_farray.rb +32 -0
  165. data/yard-stubs/ca_obj_field.rb +45 -0
  166. data/yard-stubs/ca_obj_grid.rb +35 -0
  167. data/yard-stubs/ca_obj_refer.rb +72 -0
  168. data/yard-stubs/ca_obj_roll.rb +45 -0
  169. data/yard-stubs/ca_obj_shift.rb +43 -0
  170. data/yard-stubs/ca_obj_stride.rb +181 -0
  171. data/yard-stubs/ca_obj_tile.rb +29 -0
  172. data/yard-stubs/ca_obj_transpose.rb +40 -0
  173. data/yard-stubs/ca_obj_window.rb +57 -0
  174. data/yard-stubs/carray_access.rb +131 -0
  175. data/yard-stubs/carray_attribute.rb +246 -0
  176. data/yard-stubs/carray_broadcast.rb +37 -0
  177. data/yard-stubs/carray_cast.rb +489 -0
  178. data/yard-stubs/carray_class.rb +65 -0
  179. data/yard-stubs/carray_conversion.rb +76 -0
  180. data/yard-stubs/carray_copy.rb +79 -0
  181. data/yard-stubs/carray_core.rb +34 -0
  182. data/yard-stubs/carray_count.rb +84 -0
  183. data/yard-stubs/carray_element.rb +108 -0
  184. data/yard-stubs/carray_generate.rb +66 -0
  185. data/yard-stubs/carray_lazy.rb +228 -0
  186. data/yard-stubs/carray_loop.rb +140 -0
  187. data/yard-stubs/carray_mask.rb +259 -0
  188. data/yard-stubs/carray_math.rb +1615 -0
  189. data/yard-stubs/carray_mathfunc.rb +45 -0
  190. data/yard-stubs/carray_median_percentile.rb +103 -0
  191. data/yard-stubs/carray_memory_view.rb +163 -0
  192. data/yard-stubs/carray_order.rb +252 -0
  193. data/yard-stubs/carray_random.rb +89 -0
  194. data/yard-stubs/carray_scatter.rb +106 -0
  195. data/yard-stubs/carray_slab.rb +59 -0
  196. data/yard-stubs/carray_sort.rb +165 -0
  197. data/yard-stubs/carray_test.rb +85 -0
  198. data/yard-stubs/carray_undef.rb +64 -0
  199. data/yard-stubs/carray_utils.rb +97 -0
  200. data/yard-stubs/ruby_carray.rb +193 -0
  201. metadata +67 -10
  202. data/ext/ca_obj_unbound_repeat.c +0 -496
@@ -0,0 +1,140 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for methods defined in ext/carray_loop.c.
3
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
4
+
5
+ class CArray
6
+ # @!group Iteration
7
+
8
+ # @overload each
9
+ # Yields each element of `self` once in row-major (flat address)
10
+ # order. Returns an Enumerator when no block is given.
11
+ # @yieldparam elem [Object]
12
+ # @return [self, Enumerator]
13
+ def each; end
14
+
15
+ # @overload each_addr
16
+ # Yields each flat address `0...elements` once. Returns an
17
+ # Enumerator when no block is given.
18
+ # @yieldparam addr [Integer]
19
+ # @return [self, Enumerator]
20
+ def each_addr; end
21
+
22
+ # @overload each_index
23
+ # Yields each multi-dimensional index of `self` once in row-major
24
+ # order. Block receives one Integer per axis (variadic, not a
25
+ # single Array); use `|*idx|` to collect them. Returns an
26
+ # Enumerator when no block is given.
27
+ # @yieldparam idx [Integer] one Integer per axis.
28
+ # @return [self, Enumerator]
29
+ def each_index; end
30
+
31
+ # @overload each_with_addr
32
+ # Yields each `(element, flat-address)` pair in row-major order.
33
+ # Returns an Enumerator when no block is given.
34
+ # @yieldparam elem [Object]
35
+ # @yieldparam addr [Integer]
36
+ # @return [self, Enumerator]
37
+ def each_with_addr; end
38
+
39
+ # @overload each_with_index
40
+ # Yields each element followed by its multi-dimensional index
41
+ # components in row-major order. Block signature is
42
+ # `|elem, i, j, ...|` (one Integer per axis, not a single Array);
43
+ # use `|elem, *idx|` to collect them. Returns an Enumerator when
44
+ # no block is given.
45
+ # @yieldparam elem [Object]
46
+ # @yieldparam idx [Integer] one Integer per axis.
47
+ # @return [self, Enumerator]
48
+ def each_with_index; end
49
+
50
+ # @!endgroup
51
+
52
+ # @!group Iteration
53
+
54
+ # @overload map!
55
+ # Replaces each element of `self` with the block's return value.
56
+ # Mutates `self`.
57
+ # @yieldparam elem [Object]
58
+ # @yieldreturn [Object] new value for the cell.
59
+ # @return [self]
60
+ def map!; end
61
+
62
+ # @overload map_addr!
63
+ # Replaces each element of `self` with the block's return value;
64
+ # the block receives the flat address rather than the current
65
+ # value. Mutates `self`.
66
+ # @yieldparam addr [Integer]
67
+ # @yieldreturn [Object]
68
+ # @return [self]
69
+ def map_addr!; end
70
+
71
+ # @overload map_index!
72
+ # Replaces each element of `self` with the block's return value;
73
+ # the block receives the multi-dimensional index components
74
+ # (`|i, j, ...|`, one Integer per axis; use `|*idx|` to collect
75
+ # them) rather than the current value. Mutates `self`.
76
+ # @yieldparam idx [Integer] one Integer per axis.
77
+ # @yieldreturn [Object]
78
+ # @return [self]
79
+ def map_index!; end
80
+
81
+ # @overload map_with_addr!
82
+ # Replaces each element of `self` with the block's return value;
83
+ # the block receives `(element, flat-address)`. Mutates `self`.
84
+ # @yieldparam elem [Object]
85
+ # @yieldparam addr [Integer]
86
+ # @yieldreturn [Object]
87
+ # @return [self]
88
+ def map_with_addr!; end
89
+
90
+ # @overload map_with_index!
91
+ # Replaces each element of `self` with the block's return value;
92
+ # the block receives the element followed by its multi-dim index
93
+ # components (`|elem, i, j, ...|`; use `|elem, *idx|` to collect
94
+ # the index). Mutates `self`.
95
+ # @yieldparam elem [Object]
96
+ # @yieldparam idx [Integer] one Integer per axis.
97
+ # @yieldreturn [Object]
98
+ # @return [self]
99
+ def map_with_index!; end
100
+
101
+ # @overload collect!
102
+ # Alias of {#map!}.
103
+ def collect!; end
104
+
105
+ # @overload collect_addr!
106
+ # Alias of {#map_addr!}.
107
+ def collect_addr!; end
108
+
109
+ # @overload collect_index!
110
+ # Alias of {#map_index!}.
111
+ def collect_index!; end
112
+
113
+ # @overload collect_with_addr!
114
+ # Alias of {#map_with_addr!}.
115
+ def collect_with_addr!; end
116
+
117
+ # @overload collect_with_index!
118
+ # Alias of {#map_with_index!}.
119
+ def collect_with_index!; end
120
+
121
+ # @!endgroup
122
+
123
+ class << self
124
+ # @!group Iteration
125
+
126
+ # @overload each_index(*shape) { |*idx| ... }
127
+ # Yields each multi-dimensional index inside the box `0...d`
128
+ # for each `d` in `shape`, in row-major order. Independent of
129
+ # any CArray instance.
130
+ # @param shape [Array<Integer>] one extent per axis.
131
+ # @yieldparam idx [Array<Integer>] one index per axis.
132
+ # @return [Object] the block's last return value.
133
+ # @example
134
+ # CArray.each_index(3, 2) { |i, j| print "(#{i} #{j}) " }
135
+ # # (0 0) (0 1) (1 0) (1 1) (2 0) (2 1)
136
+ def each_index(*shape); end
137
+
138
+ # @!endgroup
139
+ end
140
+ end
@@ -0,0 +1,259 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for methods defined in ext/carray_mask.c.
3
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
4
+
5
+ class CArray
6
+ # @!group Masking
7
+
8
+ # @overload has_mask?
9
+ # Returns `true` if `self` has a mask array attached. Note that a
10
+ # present mask may still have every entry set to "not masked".
11
+ # @return [Boolean]
12
+ def has_mask?; end
13
+
14
+ # @overload any_masked?
15
+ # Returns `true` if at least one element of `self` is masked.
16
+ # @return [Boolean]
17
+ def any_masked?; end
18
+
19
+ # @overload all_masked?
20
+ # Returns `true` if every element of `self` is masked.
21
+ # @return [Boolean]
22
+ def all_masked?; end
23
+
24
+ # @overload value
25
+ # Returns a new view that exposes the underlying data of `self`,
26
+ # bypassing the mask. The returned view itself cannot carry a
27
+ # mask (`value_array? == true`).
28
+ #
29
+ # Use this to read or write the data slot of masked elements.
30
+ # @return [CArray]
31
+ def value; end
32
+
33
+ # @overload mask
34
+ # Returns a new boolean view of the mask state of `self`. Each
35
+ # element is `1` where `self` is masked and `0` where it is not.
36
+ # The returned view itself cannot carry a mask.
37
+ #
38
+ # Returns `0` (Integer) if `self` has no mask array attached.
39
+ # @return [CArray, Integer]
40
+ def mask; end
41
+
42
+ # @overload mask=(new_mask)
43
+ # Sets the mask array of `self` to `new_mask`. Allocates the mask
44
+ # array first if `self` does not yet have one. Cannot be called on
45
+ # a value array or a mask array.
46
+ # @param new_mask [CArray, Boolean, Integer] mask values. A
47
+ # non-CArray value is broadcast and stored elementwise; a CArray
48
+ # of any type is coerced to boolean.
49
+ # @return [Object] `new_mask`.
50
+ def mask=(new_mask); end
51
+
52
+ # @overload is_masked
53
+ # Returns a new boolean CArray of the same shape as `self`, with
54
+ # `1` at masked positions and `0` elsewhere.
55
+ # @return [CArray]
56
+ def is_masked; end
57
+
58
+ # @overload is_not_masked
59
+ # Returns a new boolean CArray of the same shape as `self`, with
60
+ # `1` at not-masked positions and `0` elsewhere.
61
+ # @return [CArray]
62
+ def is_not_masked; end
63
+
64
+ # `unmask` clears a mask by *supplying values*. The value source is
65
+ # either a constant (the positional `fill_value`) or a scan `method:`
66
+ # that derives values from neighbouring valid cells (mask gap-fill).
67
+ # The two are mutually exclusive: passing both raises `ArgumentError`.
68
+ #
69
+ # @overload unmask
70
+ # Clears the mask state of every element of `self`, leaving the
71
+ # stored data values untouched. Mutates `self`.
72
+ # @return [self]
73
+ # @overload unmask(fill_value)
74
+ # Clears the mask state and overwrites the data at previously
75
+ # masked positions with `fill_value`. Mutates `self`.
76
+ # @param fill_value [Object] value to store at each previously
77
+ # masked position. Cast to `self.data_type`.
78
+ # @return [self]
79
+ # @overload unmask(method:, axis: nil)
80
+ # Fills masked cells in place from neighbouring valid cells along
81
+ # `axis` (gap-fill), then clears the filled cells' mask. Mutates
82
+ # `self`. Leading (`:forward`) / trailing (`:backward`) runs of
83
+ # masked cells with no value to carry, and cells outside the valid
84
+ # range (`:linear`), stay masked — so a mask may remain.
85
+ # @param method [Symbol] fill rule:
86
+ # `:forward` / `:ffill` carries the last valid value forward;
87
+ # `:backward` / `:bfill` carries the next valid value backward
88
+ # (defined for every data_type — numeric, complex, bool, object,
89
+ # fixlen, and Face); `:linear` interpolates each masked cell
90
+ # linearly by index from the two bracketing valid cells (numeric
91
+ # data_type, or a time Face — `CATime` / `CATimedelta` interpolate
92
+ # through their own `linear_fetch`, so the filled values stay on the
93
+ # array's unit and are rounded to it).
94
+ # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
95
+ # @return [self]
96
+ def unmask(*, method: nil, axis: nil); end
97
+
98
+ # `strip_mask` is the copy form of `unmask`: it returns a new array
99
+ # rather than mutating `self`, supplying values either from a constant
100
+ # `fill_value` or a scan `method:`. The two are mutually exclusive.
101
+ #
102
+ # @overload strip_mask(fill_value)
103
+ # Returns a new array with the same shape and `data_type` as
104
+ # `self`, with no mask attached, and `fill_value` substituted at
105
+ # positions that were masked in `self`. `self` is not modified.
106
+ #
107
+ # Replaces the removed `unmask_copy(fill)` from 2.x.
108
+ # @param fill_value [Object] value to substitute at masked
109
+ # positions. Cast to `self.data_type`.
110
+ # @return [CArray]
111
+ # @overload strip_mask(method:, axis: nil)
112
+ # Returns a new array with masked cells filled from neighbouring
113
+ # valid cells along `axis` (gap-fill). `self` is not modified.
114
+ # Residual (leading / trailing / out-of-range) masked cells that
115
+ # cannot be filled stay masked in the returned array.
116
+ # @param method [Symbol] fill rule: `:forward` / `:ffill`,
117
+ # `:backward` / `:bfill` (any data_type), or `:linear` (numeric or a
118
+ # time Face). See {#unmask} for the full description.
119
+ # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
120
+ # @return [CArray]
121
+ def strip_mask(*, method: nil, axis: nil); end
122
+
123
+ # `first` / `last` are the reduction sibling of the `:forward` / `:backward`
124
+ # hold (see {#unmask}): instead of filling a whole fiber they return the one
125
+ # first / last **valid** (unmasked) value. For an unmasked array they
126
+ # degrade to the first / last element. Works for every data_type.
127
+ #
128
+ # @overload first(axis: nil, keep_axis: false)
129
+ # Returns the first valid (unmasked) value along `axis`, skipping masked
130
+ # cells. Identity-less: a fiber with no valid cell (all masked, or empty)
131
+ # yields UNDEF. To substitute a default instead, complete at the call
132
+ # site — `a.first(axis: 0).strip_mask(v)`.
133
+ # @param axis [Integer, Array<Integer>, nil] reduce axis / axes; `nil`
134
+ # reduces the whole array to a scalar.
135
+ # @param keep_axis [Boolean] keep the reduced axis as a size-1 axis.
136
+ # @return [Object, CArray] a scalar for a full reduce (UNDEF if no valid
137
+ # cell), otherwise a reduced CArray.
138
+ def first(axis: nil, keep_axis: false); end
139
+
140
+ # @overload last(axis: nil, keep_axis: false)
141
+ # Returns the last valid (unmasked) value along `axis` (the backward
142
+ # counterpart of {#first}).
143
+ # @param axis [Integer, Array<Integer>, nil] reduce axis / axes; `nil`
144
+ # reduces the whole array to a scalar.
145
+ # @param keep_axis [Boolean] keep the reduced axis as a size-1 axis.
146
+ # @return [Object, CArray] a scalar for a full reduce (UNDEF if no valid
147
+ # cell), otherwise a reduced CArray.
148
+ def last(axis: nil, keep_axis: false); end
149
+
150
+ # @overload invert_mask
151
+ # Flips the mask state of every element of `self` in place
152
+ # (masked ↔ not masked). Mutates `self`.
153
+ # @return [self]
154
+ def invert_mask; end
155
+
156
+ # @overload inherit_mask(*others)
157
+ # Sets the mask of `self` to the logical OR of the current mask
158
+ # of `self` and the masks of each array in `others`. Mutates
159
+ # `self`.
160
+ # @param others [Array<CArray>] arrays whose mask states are
161
+ # OR-ed into `self`. Non-CArray arguments are ignored.
162
+ # @return [self]
163
+ def inherit_mask(*others); end
164
+
165
+ # @overload inherit_mask_replace(*others)
166
+ # Sets the mask of `self` to the logical OR of the masks of the
167
+ # arrays in `others` only (the current mask of `self` is
168
+ # discarded, in contrast to {#inherit_mask}). Mutates `self`.
169
+ # @param others [Array<CArray>] arrays whose mask states form the
170
+ # new mask of `self`.
171
+ # @return [self]
172
+ def inherit_mask_replace(*others); end
173
+
174
+ # @overload count_masked
175
+ # Returns the total number of masked elements in `self`.
176
+ # @return [Integer]
177
+ # @overload count_masked(axis:)
178
+ # Returns the per-slice count of masked elements along the given
179
+ # axis or axes. The result is an int64 CArray with `axis` removed
180
+ # from `shape`.
181
+ # @param axis [Integer, Array<Integer>] axis or axes to reduce.
182
+ # @return [CArray] int64 CArray.
183
+ def count_masked(*, **); end
184
+
185
+ # @overload count_not_masked
186
+ # Returns the total number of not-masked elements in `self`.
187
+ # @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`.
192
+ # @param axis [Integer, Array<Integer>] axis or axes to reduce.
193
+ # @return [CArray] int64 CArray.
194
+ def count_not_masked(*, **); end
195
+
196
+ # @!endgroup
197
+
198
+ # @!group Masking
199
+
200
+ # @overload mask_eq(v)
201
+ # Returns a copy of `self` with every element equal to `v` masked.
202
+ # In-place equivalent: `ca[:eq, v] = UNDEF`.
203
+ #
204
+ # Replaces the removed `maskout(v)` from 2.x.
205
+ # @param v [Object] value to mask. Cast to `self.data_type`.
206
+ # @return [CArray]
207
+ def mask_eq(v); end
208
+
209
+ # @overload mask_invalid
210
+ # Returns a copy of `self` with every NaN or Inf element masked.
211
+ # For integer or boolean arrays this is a plain copy (no element
212
+ # is invalid by `is_finite.not` semantics).
213
+ # In-place equivalent: `ca[:is_invalid] = UNDEF`.
214
+ # @return [CArray]
215
+ def mask_invalid; end
216
+
217
+ # @overload mask_where(key, *args)
218
+ # Returns a copy of `self` with elements matching the given indexer
219
+ # predicate masked. Mirrors the indexer key set:
220
+ #
221
+ # ```ruby
222
+ # ca.mask_where(:lt, v) # same as: copy then ca[:lt, v] = UNDEF
223
+ # ca.mask_where(:is_invalid) # same as: copy then ca[:is_invalid] = UNDEF
224
+ # ca.mask_where(bool_array) # same as: copy then ca[bool_array] = UNDEF
225
+ # ```
226
+ #
227
+ # At least one argument is required. For in-place mutation use the
228
+ # indexer idiom directly: `ca[key, *args] = UNDEF`.
229
+ # @param key [Symbol, CArray] indexer key or boolean condition array.
230
+ # @param args [Array] additional arguments required by the predicate.
231
+ # @return [CArray]
232
+ def mask_where(*args); end
233
+
234
+ # @!endgroup
235
+
236
+ class << self
237
+ # @!group Masking
238
+
239
+ # @overload guard_undef(*values, fill_value: UNDEF)
240
+ # Returns `fill_value` immediately if any element of `values` is
241
+ # `UNDEF`; otherwise yields all `values` to the block and returns
242
+ # the block's result.
243
+ #
244
+ # ```ruby
245
+ # CArray.guard_undef(a, b) { |x, y| x / y } # UNDEF if a or b masked
246
+ # CArray.guard_undef(v, fill_value: 0.0) { |x| Math.sqrt(x) }
247
+ # ```
248
+ #
249
+ # @param values [Array<Object>] scalar values to test.
250
+ # @param fill_value [Object] value returned on short-circuit.
251
+ # Defaults to `UNDEF`.
252
+ # @yieldparam values [Array<Object>] the non-UNDEF values.
253
+ # @yieldreturn [Object] computation result.
254
+ # @return [Object]
255
+ def guard_undef(*values, fill_value: UNDEF); end
256
+
257
+ # @!endgroup
258
+ end
259
+ end