carray 3.0.0 → 3.0.1

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 (180) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/CHANGELOG.md +325 -3
  4. data/{NEWS.md → CHANGELOG.v1.md} +1 -1
  5. data/README.md +32 -32
  6. data/carray.gemspec +12 -8
  7. data/ext/ca_axis_group.c +55 -19
  8. data/ext/ca_binop_dispatch.c +5 -6
  9. data/ext/ca_binop_dispatch.h +0 -7
  10. data/ext/ca_categorical_iterator.c +13 -13
  11. data/ext/ca_for_each_element.h +6 -8
  12. data/ext/ca_group_iter.c +1 -1
  13. data/ext/ca_kernel_iterator.c +69 -23
  14. data/ext/ca_kernel_iterator.h +3 -10
  15. data/ext/ca_obj_bincmp.c +57 -27
  16. data/ext/ca_obj_binop.c +86 -30
  17. data/ext/ca_obj_const_string.c +3 -1
  18. data/ext/ca_obj_face.c +80 -0
  19. data/ext/ca_obj_face.h +33 -1
  20. data/ext/ca_obj_fake.c +11 -0
  21. data/ext/ca_obj_fixlen_string.c +3 -1
  22. data/ext/ca_obj_grid.c +11 -3
  23. data/ext/ca_obj_meld.c +13 -8
  24. data/ext/ca_obj_moncmp.c +33 -14
  25. data/ext/ca_obj_monop.c +19 -7
  26. data/ext/ca_obj_object.c +99 -4
  27. data/ext/ca_obj_record.c +3 -1
  28. data/ext/ca_obj_refer.c +30 -6
  29. data/ext/ca_obj_roll.c +13 -5
  30. data/ext/ca_obj_select_axis.c +16 -6
  31. data/ext/ca_obj_shift.c +3 -3
  32. data/ext/ca_obj_stride.c +106 -23
  33. data/ext/ca_obj_string.c +3 -1
  34. data/ext/ca_obj_tile.c +13 -5
  35. data/ext/ca_obj_time.c +3 -1
  36. data/ext/ca_obj_timedelta.c +3 -1
  37. data/ext/ca_obj_transpose.c +1 -1
  38. data/ext/ca_obj_triop.c +62 -23
  39. data/ext/ca_obj_window.c +86 -17
  40. data/ext/ca_op_cmplx64.h +123 -0
  41. data/ext/ca_op_ipower.c +0 -3
  42. data/ext/ca_sort_kernels.h +5 -5
  43. data/ext/ca_sweep_engine.c +78 -35
  44. data/ext/ca_sweep_engine.h +13 -4
  45. data/ext/ca_transform_common.c +7 -0
  46. data/ext/carray.h +127 -130
  47. data/ext/carray_access.c +56 -34
  48. data/ext/carray_bincount.c +8 -8
  49. data/ext/carray_broadcast.c +99 -6
  50. data/ext/carray_build_flags.h +3 -0
  51. data/ext/carray_call_cfunc.c +1491 -0
  52. data/ext/carray_call_cfunc.h +153 -0
  53. data/ext/carray_cast.c +69 -31
  54. data/ext/carray_conversion.c +22 -22
  55. data/ext/carray_copy.c +12 -2
  56. data/ext/carray_core.c +57 -10
  57. data/ext/carray_count.c +1 -1
  58. data/ext/carray_element.c +7 -7
  59. data/ext/carray_factorize.c +28 -28
  60. data/ext/carray_hold.c +1 -1
  61. data/ext/carray_index_classifier.c +7 -21
  62. data/ext/carray_internal.h +19 -3
  63. data/ext/carray_kernels_bincmp.c +1 -0
  64. data/ext/carray_kernels_binop.c +320 -298
  65. data/ext/carray_kernels_init.c +1095 -0
  66. data/ext/carray_kernels_map.c +1 -0
  67. data/ext/carray_kernels_moncmp.c +1 -0
  68. data/ext/carray_kernels_monop.c +412 -411
  69. data/ext/carray_kernels_reduce_aggregate.c +88 -87
  70. data/ext/carray_kernels_reduce_boolean.c +1 -0
  71. data/ext/carray_kernels_reduce_cumulative.c +54 -53
  72. data/ext/carray_kernels_reduce_extreme.c +51 -50
  73. data/ext/carray_kernels_reduce_variance.c +1 -0
  74. data/ext/carray_kernels_scan.c +1 -0
  75. data/ext/carray_kernels_search.c +93 -92
  76. data/ext/carray_kernels_sort.c +1 -0
  77. data/ext/carray_kernels_triop.c +1 -0
  78. data/ext/carray_lazy.c +175 -5
  79. data/ext/carray_mask.c +6 -5
  80. data/ext/carray_median_percentile.c +1 -1
  81. data/ext/carray_memory_view.c +46 -21
  82. data/ext/carray_operator.c +46 -49
  83. data/ext/carray_partition.c +4 -4
  84. data/ext/carray_random.c +7 -7
  85. data/ext/carray_scatter.c +1 -1
  86. data/ext/carray_sort.c +3 -3
  87. data/ext/carray_sort_kernel.c +10 -10
  88. data/ext/carray_test.c +1 -1
  89. data/ext/extconf.rb +18 -0
  90. data/ext/mk_call_cfunc.rb +243 -52
  91. data/ext/mkkernel.rb +354 -100
  92. data/ext/ruby_carray.c +18 -16
  93. data/ext/version.h +4 -4
  94. data/lib/carray/autoload_carray.rb +19 -0
  95. data/lib/carray/autoload_method_extension.rb +2 -1
  96. data/lib/carray/axis_group.rb +7 -7
  97. data/lib/carray/basics.rb +59 -59
  98. data/lib/carray/bincount_nd.rb +12 -12
  99. data/lib/carray/block_iterator.rb +24 -14
  100. data/lib/carray/categorical.rb +4 -4
  101. data/lib/carray/categorical_iterator.rb +98 -76
  102. data/lib/carray/conditional.rb +14 -14
  103. data/lib/carray/construct.rb +21 -0
  104. data/lib/carray/core_extensions.rb +62 -5
  105. data/lib/carray/data_type_extension.rb +18 -1
  106. data/lib/carray/frame/concat.rb +3 -3
  107. data/lib/carray/frame/convert.rb +1 -1
  108. data/lib/carray/frame/frame.rb +4 -11
  109. data/lib/carray/frame/io.rb +159 -2
  110. data/lib/carray/frame/sort.rb +1 -1
  111. data/lib/carray/frame/verbs.rb +18 -1
  112. data/lib/carray/fuse_source.rb +123 -0
  113. data/lib/carray/fusion.rb +218 -0
  114. data/lib/carray/histogram.rb +16 -16
  115. data/lib/carray/inspect.rb +1 -7
  116. data/lib/carray/iterator.rb +4 -3
  117. data/lib/carray/lazy.rb +125 -73
  118. data/lib/carray/meld_reduce.rb +2 -2
  119. data/lib/carray/methods/align_addr.rb +1 -1
  120. data/lib/carray/methods/composition.rb +1 -1
  121. data/lib/carray/methods/is_in.rb +12 -12
  122. data/lib/carray/methods/locate_addr.rb +6 -1
  123. data/lib/carray/methods/mask_duplicates.rb +1 -1
  124. data/lib/carray/methods/meshgrid.rb +4 -5
  125. data/lib/carray/methods/mode.rb +2 -2
  126. data/lib/carray/methods/nunique.rb +1 -1
  127. data/lib/carray/methods/snap.rb +7 -2
  128. data/lib/carray/methods/unique.rb +3 -3
  129. data/lib/carray/methods/value_counts.rb +2 -2
  130. data/lib/carray/runtime.rb +0 -19
  131. data/lib/carray/slab_iterator.rb +20 -7
  132. data/lib/carray/string_operation_extension.rb +5 -5
  133. data/lib/carray/time.rb +890 -491
  134. data/lib/carray/window_iterator.rb +285 -13
  135. data/lib/carray.rb +5 -5
  136. data/yard-stubs/ca_obj_array.rb +385 -0
  137. data/yard-stubs/ca_obj_bitarray.rb +38 -0
  138. data/yard-stubs/ca_obj_bitfield.rb +43 -0
  139. data/yard-stubs/ca_obj_block.rb +73 -0
  140. data/yard-stubs/ca_obj_byte_swap.rb +56 -0
  141. data/yard-stubs/ca_obj_fake.rb +31 -0
  142. data/yard-stubs/ca_obj_farray.rb +32 -0
  143. data/yard-stubs/ca_obj_field.rb +45 -0
  144. data/yard-stubs/ca_obj_grid.rb +35 -0
  145. data/yard-stubs/ca_obj_refer.rb +72 -0
  146. data/yard-stubs/ca_obj_roll.rb +45 -0
  147. data/yard-stubs/ca_obj_shift.rb +43 -0
  148. data/yard-stubs/ca_obj_stride.rb +181 -0
  149. data/yard-stubs/ca_obj_tile.rb +29 -0
  150. data/yard-stubs/ca_obj_transpose.rb +40 -0
  151. data/yard-stubs/ca_obj_window.rb +49 -0
  152. data/yard-stubs/carray_access.rb +131 -0
  153. data/yard-stubs/carray_attribute.rb +246 -0
  154. data/yard-stubs/carray_broadcast.rb +37 -0
  155. data/yard-stubs/carray_cast.rb +489 -0
  156. data/yard-stubs/carray_class.rb +65 -0
  157. data/yard-stubs/carray_conversion.rb +76 -0
  158. data/yard-stubs/carray_copy.rb +79 -0
  159. data/yard-stubs/carray_core.rb +114 -0
  160. data/yard-stubs/carray_count.rb +79 -0
  161. data/yard-stubs/carray_element.rb +108 -0
  162. data/yard-stubs/carray_generate.rb +66 -0
  163. data/yard-stubs/carray_lazy.rb +23 -0
  164. data/yard-stubs/carray_loop.rb +140 -0
  165. data/yard-stubs/carray_mask.rb +259 -0
  166. data/yard-stubs/carray_math.rb +132 -0
  167. data/yard-stubs/carray_mathfunc.rb +45 -0
  168. data/yard-stubs/carray_median_percentile.rb +89 -0
  169. data/yard-stubs/carray_memory_view.rb +163 -0
  170. data/yard-stubs/carray_order.rb +312 -0
  171. data/yard-stubs/carray_random.rb +89 -0
  172. data/yard-stubs/carray_scatter.rb +106 -0
  173. data/yard-stubs/carray_slab.rb +57 -0
  174. data/yard-stubs/carray_sort.rb +163 -0
  175. data/yard-stubs/carray_test.rb +85 -0
  176. data/yard-stubs/carray_undef.rb +64 -0
  177. data/yard-stubs/carray_utils.rb +97 -0
  178. data/yard-stubs/ruby_carray.rb +193 -0
  179. metadata +59 -10
  180. data/ext/ca_obj_unbound_repeat.c +0 -496
@@ -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
@@ -0,0 +1,132 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for the elementwise arithmetic generated by ext/mkkernel.rb --
3
+ # the division and modulo binops and the rounding monops. These
4
+ # generated kernels carry no C docstring, so the documentation lives
5
+ # here. See yard-stubs/README.md and yard-stubs/STYLE.md.
6
+
7
+ class CArray
8
+ # @!group Elementwise math
9
+
10
+ # @overload /(other)
11
+ # Returns the element-wise quotient of `self` and `other`.
12
+ #
13
+ # Integer division floors toward negative infinity, so that
14
+ # `(a / b) * b + a % b == a` holds for every combination of signs
15
+ # -- the same convention as Ruby's `Integer#/`. Float and complex
16
+ # division is true division, as Ruby's `Float#/` is, so that
17
+ # identity is an integer one. Boolean arrays participate as their
18
+ # 0/1 storage. Masked elements stay masked, and a masked cell is
19
+ # never divided.
20
+ # @param other [CArray, Numeric] divisor, broadcast to `self.shape`.
21
+ # @return [CArray] result of the promoted `data_type` of the two
22
+ # operands.
23
+ # @raise [ZeroDivisionError] when an integer divisor is `0`. Float
24
+ # division returns `Infinity` or `NaN` instead.
25
+ # @example
26
+ # CA_INT32([-7, -1, 7]) / 3 # => [ -3, -1, 2 ]
27
+ # CA_DOUBLE([-7.0]) / 3.0 # => [ -2.3333333333333335 ]
28
+ def /(other); end
29
+
30
+ # @overload div(other)
31
+ # Alias of {#/}.
32
+ # @param other [CArray, Numeric] divisor.
33
+ # @return [CArray]
34
+ def div(other); end
35
+
36
+ # @overload div!(other)
37
+ # Divides `self` by `other` in place, keeping `self`'s `data_type`.
38
+ # @param other [CArray, Numeric] divisor.
39
+ # @return [self]
40
+ def div!(other); end
41
+
42
+ # @overload %(other)
43
+ # Returns the element-wise remainder of `self` divided by `other`,
44
+ # carrying the sign of the divisor.
45
+ #
46
+ # This is the floored modulo, the pair of the floored `/` above and
47
+ # the same convention as Ruby's `%`: `-7 % 3` is `2`, and `7 % -3`
48
+ # is `-2`. A float remainder of zero takes the divisor's sign, so
49
+ # the rule holds without exception. For the truncated form that C
50
+ # gives -- the sign of the dividend -- use {#fmod}. Complex arrays
51
+ # have no modulo. Masked elements stay masked.
52
+ # @param other [CArray, Numeric] divisor, broadcast to `self.shape`.
53
+ # @return [CArray] result of the promoted `data_type` of the two
54
+ # operands.
55
+ # @raise [ZeroDivisionError] when an integer divisor is `0`. A float
56
+ # divisor of `0.0` yields `NaN`.
57
+ # @raise [CArray::DataTypeError] for a complex array.
58
+ # @example
59
+ # CA_INT32([-7, -1, 7]) % 3 # => [ 2, 2, 1 ]
60
+ # CA_INT32([7]) % -3 # => [ -2 ]
61
+ # CA_DOUBLE([-0.4]) % 1.0 # => [ 0.6 ]
62
+ def %(other); end
63
+
64
+ # @overload mod(other)
65
+ # Alias of {#%}.
66
+ # @param other [CArray, Numeric] divisor.
67
+ # @return [CArray]
68
+ def mod(other); end
69
+
70
+ # @overload mod!(other)
71
+ # Replaces `self` with the remainder in place, keeping `self`'s
72
+ # `data_type`.
73
+ # @param other [CArray, Numeric] divisor.
74
+ # @return [self]
75
+ def mod!(other); end
76
+
77
+ # @overload fmod(other)
78
+ # Returns the element-wise truncated remainder of `self` divided by
79
+ # `other`, carrying the sign of the dividend.
80
+ #
81
+ # This is C's `fmod` and `%`: the quotient is truncated toward zero
82
+ # rather than floored, so `fmod(-7, 3)` is `-1` where `-7 % 3` is
83
+ # `2`. Integer arrays are accepted as well as floats. Complex
84
+ # arrays have no remainder. An `:object` array delegates to each
85
+ # element's `#remainder`, so an Integer element yields an Integer.
86
+ # Masked elements stay masked.
87
+ # @param other [CArray, Numeric] divisor, broadcast to `self.shape`.
88
+ # @return [CArray] result of the promoted `data_type` of the two
89
+ # operands.
90
+ # @raise [ZeroDivisionError] when an integer divisor is `0`. A float
91
+ # divisor of `0.0` yields `NaN`.
92
+ # @raise [CArray::DataTypeError] for a complex array.
93
+ # @example
94
+ # CA_INT32([-7, -1, 7]).fmod(3) # => [ -1, -1, 1 ]
95
+ # CA_DOUBLE([-0.4]).fmod(1.0) # => [ -0.4 ]
96
+ def fmod(other); end
97
+
98
+ # @overload fmod!(other)
99
+ # Replaces `self` with the truncated remainder in place, keeping
100
+ # `self`'s `data_type`.
101
+ # @param other [CArray, Numeric] divisor.
102
+ # @return [self]
103
+ def fmod!(other); end
104
+
105
+ # @overload round
106
+ # Returns a new array with each element rounded to the nearest
107
+ # integer value, half rounded away from zero (`2.5` -> `3.0`,
108
+ # `-2.5` -> `-3.0`). The result keeps `self`'s `data_type`.
109
+ #
110
+ # Integer arrays are returned unchanged. For a `:float64` /
111
+ # `:float32` array the value stays floating-point (e.g. `1.4` ->
112
+ # `1.0`); a `NaN` element is passed through as `NaN`, and `-0.0`
113
+ # keeps its sign. Masked elements stay masked. An `:object`
114
+ # array delegates to each element's `#round`.
115
+ # @return [CArray] same `data_type` as `self`.
116
+ def round; end
117
+
118
+ # @overload frac
119
+ # Returns a new array of the fractional part of each element:
120
+ # `self - self.truncated_toward_zero`, so the result keeps the
121
+ # sign of the input (`1.25` -> `0.25`, `-1.25` -> `-0.25`). The
122
+ # result keeps `self`'s `data_type`.
123
+ #
124
+ # Integer arrays yield all zeros. For a floating-point array a
125
+ # `NaN` element is passed through as `NaN`, and `±0.0` keeps its
126
+ # sign. Masked elements stay masked. An `:object` array
127
+ # delegates to each element's `#frac`.
128
+ # @return [CArray] same `data_type` as `self`.
129
+ def frac; end
130
+
131
+ # @!endgroup
132
+ end
@@ -0,0 +1,45 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for the CAMath module functions defined in
3
+ # ext/carray_mathfunc.c. Most CAMath entries (atan2 / hypot / expm1
4
+ # / log1p / copysign / logaddexp / nextafter / fmod / min / max) live
5
+ # in lib/carray/math.rb and are documented at the source. This file
6
+ # covers only the C-defined module functions.
7
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
8
+
9
+ # Namespace for math module functions that operate on CArray (and
10
+ # auto-wrappable scalar) inputs.
11
+ module CAMath
12
+ module_function
13
+
14
+ # @overload spherical_to_xyz(r, theta, phi)
15
+ # Returns three CArrays `[x, y, z]` of cartesian coordinates
16
+ # converted from spherical coordinates. All inputs are coerced
17
+ # to `:float64`; outputs are `:float64`.
18
+ #
19
+ # `theta` is the polar angle from the `+z` axis in radians;
20
+ # `phi` is the azimuthal angle in the `xy` plane in radians.
21
+ # @param r [CArray, Numeric] radial distance.
22
+ # @param theta [CArray, Numeric] polar angle (radians).
23
+ # @param phi [CArray, Numeric] azimuthal angle (radians).
24
+ # @return [Array<CArray>] `[x, y, z]`.
25
+ def spherical_to_xyz(r, theta, phi); end
26
+
27
+ # @overload xyz_to_spherical(x, y, z)
28
+ # Returns three CArrays `[r, theta, phi]` of spherical
29
+ # coordinates converted from cartesian coordinates. All inputs
30
+ # are coerced to `:float64`; outputs are `:float64`.
31
+ # @param x [CArray, Numeric]
32
+ # @param y [CArray, Numeric]
33
+ # @param z [CArray, Numeric]
34
+ # @return [Array<CArray>] `[r, theta, phi]`.
35
+ # @raise [RuntimeError] when the build lacks `atan2`.
36
+ def xyz_to_spherical(x, y, z); end
37
+
38
+ # @overload lgamma(x)
39
+ # Returns a `:float64` CArray of `log(|Γ(x)|)` for each element of
40
+ # `x`. `x` is coerced to `:float64`.
41
+ # @param x [CArray, Numeric]
42
+ # @return [CArray]
43
+ # @raise [RuntimeError] when the build lacks `lgamma`.
44
+ def lgamma(x); end
45
+ end
@@ -0,0 +1,89 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for methods defined in ext/carray_median_percentile.c.
3
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
4
+
5
+ class CArray
6
+ # @!group Statistics
7
+
8
+ # @overload median(axis: nil, min_count: 0, fill_value: nil, keep_axis: false)
9
+ # Returns the median of `self` along `axis` (or over all elements
10
+ # when `axis` is `nil`).
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.
15
+ #
16
+ # Masked cells are excluded. Per-axis, each fiber uses only its own
17
+ # present values; a fully masked fiber reduces to `UNDEF`. If the
18
+ # count of not-masked cells (per fiber, or over all elements in the
19
+ # flat form) is below `min_count`, that cell is `fill_value` (or
20
+ # `UNDEF` when `fill_value` is `nil`).
21
+ #
22
+ # With `keep_axis: true`, the reduced axis is retained with
23
+ # length 1 rather than dropped.
24
+ # @param axis [Integer, nil]
25
+ # @param min_count [Integer] minimum not-masked count required.
26
+ # @param fill_value [Object, nil] replacement when the not-masked
27
+ # count is below `min_count`.
28
+ # @param keep_axis [Boolean]
29
+ # @return [Float, CArray, Object]
30
+ # @raise [CArray::DataTypeError] for fixlen data_type.
31
+ # @raise [ArgumentError] on negative `min_count`.
32
+ def median(*); end
33
+
34
+ # @overload percentile(*p, axis: nil, min_count: 0, fill_value: nil,
35
+ # method: :linear, keep_axis: false)
36
+ # Returns percentile values at each `p` (each in `[0, 100]`)
37
+ # along `axis` or over all elements.
38
+ #
39
+ # `p` may be given as individual positional arguments, a single
40
+ # `Array<Numeric>`, or a single 1-D `CArray`. When the effective
41
+ # `p` count (after flattening) is 1, the result is unwrapped:
42
+ # flat form returns a `Float`, per-axis form returns a `CArray`.
43
+ # With 2 or more `p` values the result is an `Array` whose length
44
+ # matches the number of requested `p` values.
45
+ #
46
+ # `method` picks the interpolation rule between adjacent order
47
+ # statistics:
48
+ #
49
+ # - `:linear` (default) — linear interpolation.
50
+ # - `:lower` — floor to the smaller neighbor.
51
+ # - `:higher` — ceil to the larger neighbor.
52
+ # - `:nearest` — round-half-to-even to the nearer neighbor.
53
+ # - `:midpoint` — arithmetic mean of the two neighbors.
54
+ #
55
+ # Numeric arrays produce `Float` results; `CA_OBJECT` arrays
56
+ # apply Ruby `+` / `/` / `*` on the stored objects. Fixlen
57
+ # arrays raise.
58
+ #
59
+ # Masking, `min_count`, `fill_value`, and `keep_axis` follow the
60
+ # same rules as {#median}.
61
+ # @param p [Numeric, Array<Numeric>, CArray] percentile targets in
62
+ # `[0, 100]`.
63
+ # @param axis [Integer, nil]
64
+ # @param min_count [Integer]
65
+ # @param fill_value [Object, nil]
66
+ # @param method [Symbol] one of `:linear`, `:lower`, `:higher`,
67
+ # `:nearest`, `:midpoint`.
68
+ # @param keep_axis [Boolean]
69
+ # @return [Float, CArray, Object, Array<Float>, Array<CArray>, Array<Object>]
70
+ # @raise [CArray::DataTypeError] for fixlen data_type.
71
+ # @raise [ArgumentError] on empty `p` list, `p` outside `[0, 100]`,
72
+ # empty axis, unknown `method`, or invalid option combinations.
73
+ def percentile(*); end
74
+
75
+ # @overload quantile(axis: nil, keep_axis: false)
76
+ # Returns the five quartile percentiles
77
+ # `[p0, p25, p50, p75, p100]` — shorthand for
78
+ # `percentile(0, 25, 50, 75, 100, axis: axis, keep_axis: keep_axis)`.
79
+ # Accepts no positional arguments. Flat form returns
80
+ # `Array<Float>` of length 5; per-axis form returns `Array<CArray>`
81
+ # of length 5, each CArray reduced along `axis`.
82
+ # @param axis [Integer, nil]
83
+ # @param keep_axis [Boolean]
84
+ # @return [Array<Float>, Array<CArray>]
85
+ # @raise [ArgumentError] on any positional argument.
86
+ def quantile(*); end
87
+
88
+ # @!endgroup
89
+ end
@@ -0,0 +1,163 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for singleton methods defined in ext/carray_memory_view.c.
3
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
4
+
5
+ class CArray
6
+ class << self
7
+ # @!group MemoryView interop
8
+
9
+ # @overload memory_view_available?(obj)
10
+ # Returns `true` if `obj` exposes the Ruby `rb_memory_view`
11
+ # protocol and a view can be acquired from it. Lightweight probe
12
+ # used to gate {.from_memory_view} / {.wrap_memory_view} calls.
13
+ #
14
+ # Returning `true` does not guarantee acquisition will succeed —
15
+ # a producer may still refuse a particular flag combination at
16
+ # acquisition time.
17
+ # @param obj [Object] any object (typically a foreign array such
18
+ # as `Numo::NArray`, `Arrow::Array`, a `bytearray`, or a
19
+ # CArray).
20
+ # @return [Boolean]
21
+ # @example
22
+ # CArray.memory_view_available?(CArray.int32(3)) # => true
23
+ # CArray.memory_view_available?("plain string") # => false
24
+ def memory_view_available?(obj); end
25
+
26
+ # @overload memory_view_reject_reason(obj)
27
+ # Returns a String explaining why CArray's MemoryView producer
28
+ # refuses to export `obj`, or `nil` if no problem is detected.
29
+ #
30
+ # Diagnostic only; useful when {.memory_view_available?} returns
31
+ # `false` on a CArray and the generic "memory view not available"
32
+ # error does not say which link in the parent chain caused the
33
+ # reject. Consumers that need to debug an alias-chain reject
34
+ # (mask propagation, non-contiguous strided view, etc.) call this
35
+ # to print a human-readable reason.
36
+ # @param obj [Object]
37
+ # @return [String, nil] reason text, or `nil` when acquisition
38
+ # would succeed.
39
+ def memory_view_reject_reason(obj); end
40
+
41
+ # @overload from_memory_view(src, data_type: nil, mask: nil)
42
+ # Returns a new `CArray` that owns an independent copy of `src`'s
43
+ # buffer. Accepts both contiguous and strided producers; strided
44
+ # sources are gathered into a freshly allocated row-major
45
+ # buffer.
46
+ #
47
+ # For typeless producers (format `nil`, e.g. byte blobs from
48
+ # `IO#read`), `data_type:` is required and the byte buffer is
49
+ # reinterpreted as that data type with `ndim = 1`. For typed
50
+ # producers `data_type:` is optional; when given it must match
51
+ # the producer's format.
52
+ #
53
+ # `mask:` accepts a paired buffer-protocol source whose shape
54
+ # matches `src` and whose item size is 1 (PEP 3118 `?` / `B` /
55
+ # `b`). The mask bytes are copied into the canonical
56
+ # `CA_BOOLEAN` mask slot with non-zero coerced to `1`. The copy
57
+ # is independent of both buffers after the call.
58
+ # @param src [Object] any MemoryView producer.
59
+ # @param data_type [Symbol, Integer, Class, nil] target data
60
+ # type. Required for typeless producers; optional (must match
61
+ # producer format) for typed ones.
62
+ # @param mask [Object, nil] optional paired mask MemoryView
63
+ # source. Must match `src.shape` and use a 1-byte/element
64
+ # format.
65
+ # @return [CArray] independent copy; not a `CAWrap`.
66
+ # @raise [ArgumentError] if `src` is not a MemoryView producer,
67
+ # if `data_type:` is missing for a typeless source, if
68
+ # `data_type:` conflicts with the producer's format, or if
69
+ # the supplied `mask:` fails shape / data type / contiguity
70
+ # validation.
71
+ # @example Copy from a strided source
72
+ # a = CArray.int32(4, 3).seq
73
+ # b = CArray.from_memory_view(a.transpose)
74
+ # b.shape # => [3, 4]
75
+ # b.equal?(a) # => false
76
+ # @example Copy paired (data, mask) — independent of source
77
+ # data = CArray.uint8(3) { |i| i }
78
+ # mask = CArray.boolean(3) { |i| i.zero? ? 1 : 0 }
79
+ # c = CArray.from_memory_view(data, mask: mask)
80
+ # c.has_mask? # => true
81
+ # data[0] = 99 # source change does not reach c
82
+ def from_memory_view(src, data_type: nil, mask: nil); end
83
+
84
+ # @overload wrap_memory_view(src, data_type: nil, mask: nil)
85
+ # Returns a `CAWrap` (or `CAStride` for strided producers) that
86
+ # borrows `src`'s buffer zero-copy. Writes through the wrap
87
+ # reach the source buffer; external changes to the source are
88
+ # visible through the wrap.
89
+ #
90
+ # The borrowed view is kept alive for the lifetime of the
91
+ # returned object via internal ivars; the source is released
92
+ # when the wrap is garbage-collected.
93
+ #
94
+ # Contiguous typed producers return a `CAWrap`. Strided typed
95
+ # producers return a `CAStride` layered on an inner `CAWrap` of
96
+ # the producer's first byte, preserving the full stride pattern
97
+ # (including negative strides where the producer offers them).
98
+ # Typeless producers (format `nil`) require `data_type:` and are
99
+ # reinterpreted with `ndim = 1`.
100
+ #
101
+ # `mask:` accepts a paired buffer-protocol source whose shape
102
+ # matches `src` and whose item size is 1 (PEP 3118 `?` / `B` /
103
+ # `b`). The mask buffer is borrowed; writes to either side
104
+ # propagate, and the mask MemoryView is released when the wrap
105
+ # is collected. In this release, `mask:` requires a row-major
106
+ # contiguous data source and a row-major contiguous mask
107
+ # buffer.
108
+ #
109
+ # The receiver picks the class of the result. Called on `CArray`
110
+ # it builds a `CAWrap`; called on a subclass of `CAWrap` it
111
+ # builds that subclass, so a gem bridging a foreign buffer can
112
+ # name where the array came from without writing a C extension.
113
+ # Any other receiver raises `TypeError`, and a strided producer
114
+ # raises `ArgumentError` when a subclass was asked for, since the
115
+ # result would be a `CAStride` rather than the named class.
116
+ #
117
+ # The class marks the provenance of the returned object only. A
118
+ # view derived from it is a `CABlock` or a `CAStride` like any
119
+ # other — a slice of a borrowed image is no longer that image —
120
+ # so do not build an API that expects the class to survive view
121
+ # algebra. For semantic identity that does survive it, see
122
+ # {file:docs/topics/CAFace.md CAFace}.
123
+ # @param src [Object] any MemoryView producer.
124
+ # @param data_type [Symbol, Integer, Class, nil] target data
125
+ # type, same rules as {.from_memory_view}.
126
+ # @param mask [Object, nil] optional paired mask MemoryView
127
+ # source.
128
+ # @return [CAWrap, CAStride] zero-copy borrowed view of `src`.
129
+ # A `CAStride` is returned when `src` is strided (and `mask:`
130
+ # is not given); otherwise a `CAWrap`, or the subclass of
131
+ # `CAWrap` the method was called on.
132
+ # @raise [TypeError] if the receiver is neither `CArray` nor a
133
+ # subclass of `CAWrap`.
134
+ # @raise [ArgumentError] if `src` is not a MemoryView producer,
135
+ # if `data_type:` is missing for a typeless source, if
136
+ # `data_type:` conflicts with the producer's format, or if
137
+ # the supplied `mask:` fails validation (shape / ndim /
138
+ # data type / item_size / contiguity). Also raises when `mask:`
139
+ # is combined with a strided data source — that combination
140
+ # is not supported in this release.
141
+ # @example Zero-copy write propagation
142
+ # a = CArray.int32(4).seq
143
+ # w = CArray.wrap_memory_view(a)
144
+ # w[0] = 999
145
+ # a[0] # => 999
146
+ # @example Paired masked wrap
147
+ # data = CArray.uint8(3) { |i| i + 10 }
148
+ # mask = CArray.boolean(3) { 0 }
149
+ # w = CArray.wrap_memory_view(data, mask: mask)
150
+ # w[1] = UNDEF # writes the source mask buffer
151
+ # mask[1] # => 1
152
+ # @example Naming where a borrowed buffer came from
153
+ # class VipsPixels < CAWrap
154
+ # def image ; instance_variable_get(:@vips_image) ; end
155
+ # end
156
+ # v = VipsPixels.wrap_memory_view(bmv)
157
+ # v.class # => VipsPixels
158
+ # v[0..1, nil].class # => CABlock (the class does not descend)
159
+ def wrap_memory_view(src, data_type: nil, mask: nil); end
160
+
161
+ # @!endgroup
162
+ end
163
+ end