carray 3.0.3 → 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 (212) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +264 -0
  3. data/README.md +3 -2
  4. data/carray.gemspec +1 -1
  5. data/ext/ca_axis_descriptor.h +27 -24
  6. data/ext/ca_axis_dispatch.c +1 -6
  7. data/ext/ca_axis_group.c +27 -27
  8. data/ext/ca_binop_dispatch.c +1 -29
  9. data/ext/ca_binop_dispatch.h +0 -1
  10. data/ext/ca_categorical_iterator.c +205 -134
  11. data/ext/ca_compare.c +7 -18
  12. data/ext/ca_group_iter.c +16 -17
  13. data/ext/ca_kernel_iterator.c +1234 -1994
  14. data/ext/ca_kernel_iterator.h +391 -437
  15. data/ext/ca_monop_dispatch.c +82 -59
  16. data/ext/ca_monop_dispatch.h +1 -0
  17. data/ext/ca_obj_array.c +96 -39
  18. data/ext/ca_obj_bincmp.c +24 -21
  19. data/ext/ca_obj_binop.c +15 -26
  20. data/ext/ca_obj_bitarray.c +3 -2
  21. data/ext/ca_obj_bitfield.c +5 -6
  22. data/ext/ca_obj_block.c +18 -9
  23. data/ext/ca_obj_byte_swap.c +5 -6
  24. data/ext/ca_obj_const_string.c +173 -19
  25. data/ext/ca_obj_face.c +238 -57
  26. data/ext/ca_obj_face.h +19 -0
  27. data/ext/ca_obj_fake.c +15 -29
  28. data/ext/ca_obj_farray.c +6 -3
  29. data/ext/ca_obj_field.c +17 -5
  30. data/ext/ca_obj_fixlen_string.c +2 -3
  31. data/ext/ca_obj_grid.c +406 -132
  32. data/ext/ca_obj_meld.c +172 -34
  33. data/ext/ca_obj_moncmp.c +23 -8
  34. data/ext/ca_obj_monop.c +67 -57
  35. data/ext/ca_obj_object.c +157 -51
  36. data/ext/ca_obj_record.c +12 -7
  37. data/ext/ca_obj_reduce.c +13 -8
  38. data/ext/ca_obj_refer.c +25 -27
  39. data/ext/ca_obj_remap.c +30 -9
  40. data/ext/ca_obj_repeat.c +9 -10
  41. data/ext/ca_obj_roll.c +6 -5
  42. data/ext/ca_obj_select.c +14 -9
  43. data/ext/ca_obj_select_axis.c +15 -47
  44. data/ext/ca_obj_shift.c +11 -1
  45. data/ext/ca_obj_stack.c +179 -34
  46. data/ext/ca_obj_stride.c +162 -115
  47. data/ext/ca_obj_string.c +71 -4
  48. data/ext/ca_obj_tile.c +6 -5
  49. data/ext/ca_obj_time.c +22 -6
  50. data/ext/ca_obj_timedelta.c +22 -6
  51. data/ext/ca_obj_transpose.c +5 -3
  52. data/ext/ca_obj_triop.c +23 -32
  53. data/ext/ca_obj_window.c +190 -26
  54. data/ext/ca_sweep_engine.c +2 -2
  55. data/ext/caframe_csv_reader.c +80 -1
  56. data/ext/carray.h +181 -75
  57. data/ext/carray_access.c +184 -96
  58. data/ext/carray_address_basis.c +343 -87
  59. data/ext/carray_attribute.c +89 -6
  60. data/ext/carray_bincount.c +10 -8
  61. data/ext/carray_broadcast.c +13 -8
  62. data/ext/carray_build_flags.h +3 -0
  63. data/ext/carray_call_cfunc.c +108 -0
  64. data/ext/carray_cast.c +142 -24
  65. data/ext/carray_cast_func.rb +46 -6
  66. data/ext/carray_class.c +4 -3
  67. data/ext/carray_config.h +28 -0
  68. data/ext/carray_conversion.c +16 -7
  69. data/ext/carray_copy.c +51 -14
  70. data/ext/carray_core.c +147 -55
  71. data/ext/carray_count.c +50 -20
  72. data/ext/carray_element.c +76 -33
  73. data/ext/carray_factorize.c +118 -64
  74. data/ext/carray_generate.c +191 -50
  75. data/ext/carray_histogram.c +62 -17
  76. data/ext/carray_hold.c +12 -15
  77. data/ext/carray_index_classifier.c +388 -176
  78. data/ext/carray_internal.h +336 -29
  79. data/ext/carray_kernels_bincmp.c +4453 -0
  80. data/ext/carray_kernels_binop.c +11368 -0
  81. data/ext/carray_kernels_init.c +1734 -0
  82. data/ext/carray_kernels_moncmp.c +2104 -0
  83. data/ext/carray_kernels_monop.c +18369 -0
  84. data/ext/carray_kernels_reduce_aggregate.c +23818 -0
  85. data/ext/carray_kernels_reduce_boolean.c +406 -0
  86. data/ext/carray_kernels_reduce_cumulative.c +10086 -0
  87. data/ext/carray_kernels_reduce_extreme.c +17634 -0
  88. data/ext/carray_kernels_reduce_variance.c +3849 -0
  89. data/ext/carray_kernels_scan.c +4302 -0
  90. data/ext/carray_kernels_search.c +33829 -0
  91. data/ext/carray_kernels_sort.c +10906 -0
  92. data/ext/carray_kernels_triop.c +1864 -0
  93. data/ext/carray_key_windows.c +216 -0
  94. data/ext/carray_lazy.c +170 -111
  95. data/ext/carray_mask.c +292 -72
  96. data/ext/carray_median_percentile.c +82 -28
  97. data/ext/carray_memory_view.c +669 -561
  98. data/ext/carray_operator.c +124 -47
  99. data/ext/carray_order.c +384 -76
  100. data/ext/carray_partition.c +28 -27
  101. data/ext/carray_random.c +67 -13
  102. data/ext/carray_round.c +273 -0
  103. data/ext/carray_scatter.c +63 -38
  104. data/ext/carray_segment.c +3 -3
  105. data/ext/carray_slab.c +91 -28
  106. data/ext/carray_sort.c +35 -35
  107. data/ext/carray_struct.c +19 -18
  108. data/ext/carray_test.c +26 -5
  109. data/ext/carray_undef.c +4 -0
  110. data/ext/carray_utils.c +246 -45
  111. data/ext/mk_call_cfunc.rb +19 -2
  112. data/ext/mkkernel.rb +198 -240
  113. data/ext/ruby_carray.c +10 -4
  114. data/ext/version.h +4 -4
  115. data/lib/carray/attribute.rb +126 -22
  116. data/lib/carray/autoload_carray.rb +8 -31
  117. data/lib/carray/autoload_method_extension.rb +14 -5
  118. data/lib/carray/axis_group.rb +255 -106
  119. data/lib/carray/basics.rb +78 -10
  120. data/lib/carray/bincount_nd.rb +12 -2
  121. data/lib/carray/block_iterator.rb +126 -23
  122. data/lib/carray/boolean_reduce.rb +17 -17
  123. data/lib/carray/categorical.rb +165 -43
  124. data/lib/carray/categorical_iterator.rb +130 -27
  125. data/lib/carray/complex.rb +5 -5
  126. data/lib/carray/conditional.rb +67 -18
  127. data/lib/carray/const_string.rb +14 -5
  128. data/lib/carray/construct.rb +15 -11
  129. data/lib/carray/data_type_extension.rb +1 -0
  130. data/lib/carray/distance_limit.rb +77 -0
  131. data/lib/carray/fixlen_string.rb +7 -1
  132. data/lib/carray/frame/column_verbs.rb +70 -0
  133. data/lib/carray/frame/convert.rb +69 -0
  134. data/lib/carray/frame/csv_parser.rb +111 -17
  135. data/lib/carray/frame/describe.rb +3 -2
  136. data/lib/carray/frame/frame.rb +246 -21
  137. data/lib/carray/frame/group.rb +510 -95
  138. data/lib/carray/frame/io.rb +115 -28
  139. data/lib/carray/frame/join.rb +312 -51
  140. data/lib/carray/frame/records.rb +83 -7
  141. data/lib/carray/frame/reshape.rb +42 -35
  142. data/lib/carray/frame/sort.rb +7 -19
  143. data/lib/carray/frame/verbs.rb +188 -48
  144. data/lib/carray/frame/windows.rb +117 -0
  145. data/lib/carray/frame.rb +2 -0
  146. data/lib/carray/fuse_source.rb +11 -4
  147. data/lib/carray/fusion.rb +40 -16
  148. data/lib/carray/histogram.rb +6 -1
  149. data/lib/carray/inspect.rb +31 -8
  150. data/lib/carray/iterator.rb +85 -7
  151. data/lib/carray/key_windows.rb +620 -0
  152. data/lib/carray/lazy.rb +182 -183
  153. data/lib/carray/mask_gap_fill.rb +63 -57
  154. data/lib/carray/meld_reduce.rb +12 -14
  155. data/lib/carray/methods/bin.rb +26 -18
  156. data/lib/carray/methods/bincount.rb +16 -0
  157. data/lib/carray/methods/bit_string.rb +1 -1
  158. data/lib/carray/methods/choose.rb +16 -3
  159. data/lib/carray/methods/composition.rb +3 -1
  160. data/lib/carray/methods/gather_nd.rb +14 -5
  161. data/lib/carray/methods/insert_block.rb +2 -2
  162. data/lib/carray/methods/is_between.rb +59 -0
  163. data/lib/carray/methods/is_in.rb +53 -36
  164. data/lib/carray/methods/join.rb +1 -6
  165. data/lib/carray/methods/lag.rb +49 -0
  166. data/lib/carray/methods/locate_addr.rb +47 -51
  167. data/lib/carray/methods/mode.rb +1 -1
  168. data/lib/carray/methods/nunique.rb +11 -6
  169. data/lib/carray/methods/resize.rb +3 -3
  170. data/lib/carray/methods/value_counts.rb +4 -11
  171. data/lib/carray/record_order.rb +3 -3
  172. data/lib/carray/rng.rb +3 -0
  173. data/lib/carray/runtime.rb +53 -8
  174. data/lib/carray/segment_iterator.rb +313 -82
  175. data/lib/carray/serialize.rb +24 -10
  176. data/lib/carray/slab_iterator.rb +50 -0
  177. data/lib/carray/string.rb +105 -5
  178. data/lib/carray/string_operation_extension.rb +8 -1
  179. data/lib/carray/struct.rb +9 -21
  180. data/lib/carray/struct_builder.rb +19 -8
  181. data/lib/carray/time.rb +726 -104
  182. data/lib/carray/window_iterator.rb +122 -16
  183. data/lib/carray.rb +7 -0
  184. data/yard-stubs/ca_obj_bitfield.rb +1 -1
  185. data/yard-stubs/ca_obj_field.rb +4 -0
  186. data/yard-stubs/ca_obj_grid.rb +21 -10
  187. data/yard-stubs/ca_obj_refer.rb +2 -1
  188. data/yard-stubs/ca_obj_roll.rb +2 -2
  189. data/yard-stubs/ca_obj_shift.rb +5 -1
  190. data/yard-stubs/ca_obj_tile.rb +1 -1
  191. data/yard-stubs/ca_obj_window.rb +8 -3
  192. data/yard-stubs/carray_access.rb +6 -1
  193. data/yard-stubs/carray_attribute.rb +0 -5
  194. data/yard-stubs/carray_cast.rb +10 -0
  195. data/yard-stubs/carray_conversion.rb +2 -1
  196. data/yard-stubs/carray_copy.rb +4 -2
  197. data/yard-stubs/carray_count.rb +4 -4
  198. data/yard-stubs/carray_element.rb +10 -4
  199. data/yard-stubs/carray_generate.rb +21 -1
  200. data/yard-stubs/carray_mask.rb +26 -2
  201. data/yard-stubs/carray_math.rb +27 -1
  202. data/yard-stubs/carray_median_percentile.rb +5 -2
  203. data/yard-stubs/carray_memory_view.rb +40 -23
  204. data/yard-stubs/carray_order.rb +29 -18
  205. data/yard-stubs/carray_random.rb +13 -4
  206. data/yard-stubs/carray_scatter.rb +14 -9
  207. data/yard-stubs/carray_slab.rb +9 -2
  208. data/yard-stubs/carray_sort.rb +6 -5
  209. data/yard-stubs/carray_test.rb +5 -3
  210. metadata +25 -3
  211. data/lib/carray/arrow_tensor.rb +0 -401
  212. data/lib/carray/table.rb +0 -108
@@ -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.
@@ -91,7 +105,11 @@ class CArray
91
105
  # linearly by index from the two bracketing valid cells (numeric
92
106
  # data_type, or a time Face — `CATime` / `CATimedelta` interpolate
93
107
  # through their own `linear_fetch`, so the filled values stay on the
94
- # 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.
95
113
  # @param axis [Integer, nil] scan axis (single axis). `nil` flattens.
96
114
  # @return [self]
97
115
  def unmask(*, method: nil, axis: nil); end
@@ -164,6 +182,8 @@ class CArray
164
182
  # @param others [Array<CArray>] arrays whose mask states are
165
183
  # OR-ed into `self`. Non-CArray arguments are ignored.
166
184
  # @return [self]
185
+ # @raise [ArgumentError] if an array in `others` other than a scalar
186
+ # has fewer elements than `self`.
167
187
  def inherit_mask(*others); end
168
188
 
169
189
  # @overload inherit_mask_replace(*others)
@@ -173,6 +193,8 @@ class CArray
173
193
  # @param others [Array<CArray>] arrays whose mask states form the
174
194
  # new mask of `self`.
175
195
  # @return [self]
196
+ # @raise [ArgumentError] if an array in `others` other than a scalar
197
+ # has fewer elements than `self`.
176
198
  def inherit_mask_replace(*others); end
177
199
 
178
200
  # @overload count_masked
@@ -226,7 +248,9 @@ class CArray
226
248
  # In-place equivalent: `ca[:eq, v] = UNDEF`.
227
249
  #
228
250
  # Replaces the removed `maskout(v)` from 2.x.
229
- # @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.
230
254
  # @return [CArray]
231
255
  def mask_eq(v); end
232
256
 
@@ -125,7 +125,33 @@ class CArray
125
125
  # keeps its sign. Masked elements stay masked. An `:object`
126
126
  # array delegates to each element's `#round`.
127
127
  # @return [CArray] same `data_type` as `self`.
128
- 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
129
155
 
130
156
  # @overload frac
131
157
  # Returns a new array of the fractional part of each element:
@@ -27,7 +27,9 @@ class CArray
27
27
  # `UNDEF` when `fill_value` is `nil`).
28
28
  #
29
29
  # With `keep_axis: true`, the reduced axis is retained with
30
- # 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`).
31
33
  # @param axis [Integer, nil]
32
34
  # @param min_count [Integer] minimum not-masked count required.
33
35
  # @param fill_value [Object, nil] replacement when the not-masked
@@ -47,7 +49,8 @@ class CArray
47
49
  # `p` may be given as individual positional arguments, a single
48
50
  # `Array<Numeric>`, or a single 1-D `CArray`. When the effective
49
51
  # `p` count (after flattening) is 1, the result is unwrapped:
50
- # 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}).
51
54
  # With 2 or more `p` values the result is an `Array` whose length
52
55
  # matches the number of requested `p` values.
53
56
  #
@@ -7,13 +7,14 @@ class CArray
7
7
  # @!group MemoryView interop
8
8
 
9
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.
10
+ # Returns `true` if `obj` is a MemoryView producer (Ruby's
11
+ # `rb_memory_view_available_p`). Lightweight probe used to gate
12
+ # {.from_memory_view} / {.wrap_memory_view} calls; it does not
13
+ # acquire a view.
13
14
  #
14
- # Returning `true` does not guarantee acquisition will succeed —
15
- # a producer may still refuse a particular flag combination at
16
- # acquisition time.
15
+ # Returning `true` does not guarantee the import succeeds — the
16
+ # producer may still refuse the view, or offer a format CArray
17
+ # does not read.
17
18
  # @param obj [Object] any object (typically a foreign array such
18
19
  # as `Numo::NArray`, `Arrow::Array`, a `bytearray`, or a
19
20
  # CArray).
@@ -26,6 +27,7 @@ class CArray
26
27
  # @overload memory_view_reject_reason(obj)
27
28
  # Returns a String explaining why CArray's MemoryView producer
28
29
  # refuses to export `obj`, or `nil` if no problem is detected.
30
+ # For an object that is not a CArray it returns `nil`.
29
31
  #
30
32
  # Diagnostic only; useful when {.memory_view_available?} returns
31
33
  # `false` on a CArray and the generic "memory view not available"
@@ -34,8 +36,8 @@ class CArray
34
36
  # (mask propagation, non-contiguous strided view, etc.) call this
35
37
  # to print a human-readable reason.
36
38
  # @param obj [Object]
37
- # @return [String, nil] reason text, or `nil` when acquisition
38
- # would succeed.
39
+ # @return [String, nil] reason text, or `nil` when the export
40
+ # would succeed or `obj` is not a CArray.
39
41
  def memory_view_reject_reason(obj); end
40
42
 
41
43
  # @overload from_memory_view(src, data_type: nil, mask: nil)
@@ -46,15 +48,20 @@ class CArray
46
48
  #
47
49
  # For typeless producers (format `nil`, e.g. byte blobs from
48
50
  # `IO#read`), `data_type:` is required and the byte buffer is
49
- # reinterpreted as that data type with `ndim = 1`. For typed
51
+ # reinterpreted as that data type with `ndim = 1`; a typeless
52
+ # producer whose own layout is strided is refused. For typed
50
53
  # producers `data_type:` is optional; when given it must match
51
54
  # the producer's format.
52
55
  #
53
56
  # `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
57
+ # matches `src` and whose item size is 1 (`?` / `B` / `C` /
58
+ # `b` / `c`). The mask bytes are copied into the canonical
56
59
  # `CA_BOOLEAN` mask slot with non-zero coerced to `1`. The copy
57
- # is independent of both buffers after the call.
60
+ # is independent of both buffers after the call. A boolean
61
+ # producer's bytes other than 0 and 1 are read as true.
62
+ #
63
+ # The result is a plain `CArray` whatever the receiver; a
64
+ # receiver other than `CArray` or a `CAWrap` raises `TypeError`.
58
65
  # @param src [Object] any MemoryView producer.
59
66
  # @param data_type [Symbol, Integer, Class, nil] target data
60
67
  # type. Required for typeless producers; optional (must match
@@ -63,7 +70,11 @@ class CArray
63
70
  # source. Must match `src.shape` and use a 1-byte/element
64
71
  # format.
65
72
  # @return [CArray] independent copy; not a `CAWrap`.
73
+ # @raise [TypeError] if the receiver is neither `CArray` nor a
74
+ # `CAWrap`.
66
75
  # @raise [ArgumentError] if `src` is not a MemoryView producer,
76
+ # if its shape is negative, too large, or does not fit in the
77
+ # bytes it reports,
67
78
  # if `data_type:` is missing for a typeless source, if
68
79
  # `data_type:` conflicts with the producer's format, or if
69
80
  # the supplied `mask:` fails shape / data type / contiguity
@@ -92,19 +103,23 @@ class CArray
92
103
  # when the wrap is garbage-collected.
93
104
  #
94
105
  # 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
106
+ # producers return a `CAStride` over a byte `CAWrap` of the
107
+ # bytes its elements reach, preserving the full stride pattern
97
108
  # (including negative strides where the producer offers them).
98
109
  # Typeless producers (format `nil`) require `data_type:` and are
99
- # reinterpreted with `ndim = 1`.
110
+ # reinterpreted with `ndim = 1`; a strided typeless producer is
111
+ # refused. A boolean producer must hold 0 or 1 in every byte.
100
112
  #
101
113
  # `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.
114
+ # matches `src` and whose item size is 1 (`?` / `B` / `C` /
115
+ # `b` / `c`), holding 0 or 1 in every byte. The mask buffer is
116
+ # borrowed; writes to either side propagate, and the mask
117
+ # MemoryView is released when the wrap is collected. In this
118
+ # release, `mask:` requires a row-major contiguous data source
119
+ # and a row-major contiguous mask buffer that shares no bytes
120
+ # with the data. A read-only mask makes the whole array
121
+ # read-only, since a store writes the mask cell of each element
122
+ # it stores.
108
123
  #
109
124
  # The receiver picks the class of the result. Called on `CArray`
110
125
  # it builds a `CAWrap`; called on a subclass of `CAWrap` it
@@ -132,10 +147,12 @@ class CArray
132
147
  # @raise [TypeError] if the receiver is neither `CArray` nor a
133
148
  # subclass of `CAWrap`.
134
149
  # @raise [ArgumentError] if `src` is not a MemoryView producer,
135
- # if `data_type:` is missing for a typeless source, if
150
+ # if its shape is negative, too large, or does not fit in the
151
+ # bytes it reports, if a boolean buffer holds a byte other than
152
+ # 0 and 1, if `data_type:` is missing for a typeless source, if
136
153
  # `data_type:` conflicts with the producer's format, or if
137
154
  # the supplied `mask:` fails validation (shape / ndim /
138
- # data type / item_size / contiguity). Also raises when `mask:`
155
+ # data type / item_size / contiguity / overlap with the data). Also raises when `mask:`
139
156
  # is combined with a strided data source — that combination
140
157
  # is not supported in this release.
141
158
  # @example Zero-copy write propagation
@@ -12,16 +12,15 @@ class CArray
12
12
  #
13
13
  # Out-of-range positions are filled with `lval` (below-range) and
14
14
  # `uval` (above-range); when `lval` is given alone, it fills
15
- # both. Without either, out-of-range positions are masked.
15
+ # both. Without either, out-of-range positions are masked, and so
16
+ # they are with a fill of `UNDEF`.
16
17
  #
17
18
  # When `self` is a Face (CATime / CATimedelta / CACategorical),
18
- # the result is the same Face type, carrying the unit / labels; the
19
- # gather runs on the underlying storage and misses become UNDEF. Fill
20
- # (`lval` / `uval`) is not supported for a Face and raises ArgumentError
21
- # — omit the fill args to get UNDEF at misses.
19
+ # the result is the same Face type, carrying the unit / labels, and a
20
+ # fill is one of its values (a time for a CATime).
22
21
  # @param idx [CArray] flat addresses, of any shape.
23
- # @param lval [Object, nil] fill for indices `< 0` (non-Face only).
24
- # @param uval [Object, nil] fill for indices `>= self.elements` (non-Face only).
22
+ # @param lval [Object, nil] fill for indices `< 0`.
23
+ # @param uval [Object, nil] fill for indices `>= self.elements`.
25
24
  # @return [CArray] a fresh array shaped like `idx`; a Face of the same
26
25
  # type when `self` is a Face.
27
26
  # @raise [ArgumentError] if `lval` / `uval` is given and `self` is a Face.
@@ -97,17 +96,19 @@ class CArray
97
96
  # `method:` selects how ties are ranked:
98
97
  #
99
98
  # - `:ordinal` (default) — every cell gets a distinct rank; ties
100
- # are broken by original position (stable). This is a total
101
- # order: no two cells ever compare equal.
102
- # - `:dense` — tied values share one rank (no gaps). Useful as a
103
- # `sort_addr` priority key: an `:ordinal` key never ties, so a
104
- # lower-priority key after it is never consulted; a `:dense` key
99
+ # are broken by original position (stable), the earlier cell first
100
+ # in both directions. This is a total order: no two cells ever
101
+ # compare equal.
102
+ # - `:dense` — tied values share one rank (no gaps). Every NaN is
103
+ # one value and shares one rank, placed after the numbers. Useful
104
+ # as a `sort_addr` priority key: an `:ordinal` key never ties, so
105
+ # a lower-priority key after it is never consulted; a `:dense` key
105
106
  # preserves the tie so it is.
106
107
  #
107
- # `descending:` negates the rank order (`(n-1) - rank`, `n` =
108
- # fiber element count minus masked cells). This composes correctly
109
- # with `method: :dense`: ties stay tied after the transform, and
110
- # group-to-group order still reverses.
108
+ # `descending:` ranks the largest value `0`; NaN comes after the
109
+ # numbers in both directions. Tied cells keep their
110
+ # original order under `:ordinal` and share a rank under `:dense`, so
111
+ # dense ranks stay without gaps.
111
112
  #
112
113
  # Masked cells are excluded from ranking (own cell becomes UNDEF,
113
114
  # like `rank_index`); `descending:`/`method:` apply to the
@@ -162,12 +163,22 @@ class CArray
162
163
  #
163
164
  # `val` is compared in the type both share, as `self.eq(val)`
164
165
  # compares: an integer array searched with a Float is compared in
165
- # float64 (so `3.9` does not match `3`, and `eps` applies), and an
166
- # Integer that does not fit an integer array raises `RangeError`.
166
+ # float64 (so `3.9` does not match `3`, and `eps` applies), a pair of
167
+ # mixed sign is compared by value (`-1` does not find `255`), and an
168
+ # Integer an integer array cannot hold matches nothing.
167
169
  # The same holds for {#bsearch} and {#search_nearest}. On an
168
170
  # `:object` array a cell matches when it is `==` to `val`, as {#eq}
169
171
  # compares (so `1` matches `1.0`, which {#is_in} does not).
170
172
  #
173
+ # An `UNDEF` `val`, or a masked cell of a CArray `val`, finds
174
+ # nothing: `nil`, or `UNDEF` in that cell of the result. The same
175
+ # holds for {#bsearch} and {#search_nearest}.
176
+ #
177
+ # A time array (`CATime`, `CATimedelta`) takes a value of another
178
+ # unit, a `Time` or a String: when it is off the array's grid the
179
+ # two are compared in the finer unit, so it matches nothing (and
180
+ # {#search_nearest} finds the nearest cell).
181
+ #
171
182
  # `self` need not be sorted; this is a linear scan. For sorted
172
183
  # data prefer {#bsearch}.
173
184
  # @param val [Object]
@@ -24,7 +24,10 @@ class CArray
24
24
  # Fills `self` with uniform random numbers in-place and returns
25
25
  # `self`. Boolean arrays fill 0/1 at 50% probability, ignoring
26
26
  # any range argument. Complex arrays sample real and imaginary
27
- # parts independently from the same range.
27
+ # parts independently from the same range. An integer array takes
28
+ # Integer bounds whose every value fits its type (the whole range
29
+ # of the type included); a float array takes finite bounds. Every
30
+ # cell gets a value, so the mask is cleared, as by `seq!` or `fill`.
28
31
  #
29
32
  # @param low [Numeric] lower bound (inclusive).
30
33
  # @param high [Numeric] upper bound (exclusive).
@@ -35,7 +38,11 @@ class CArray
35
38
  # @raise [CArray::DataTypeError] for `:object` / `:fixlen` arrays.
36
39
  # @raise [ArgumentError] when an integer array is called with no
37
40
  # range, when `low >= high`, when a Range is combined with a
38
- # second positional argument, or when a Range endpoint is nil.
41
+ # second positional argument, when a Range endpoint is nil, or
42
+ # when a float bound is NaN or infinite.
43
+ # @raise [TypeError] when an integer array is given a non-Integer
44
+ # bound.
45
+ # @raise [RangeError] when the integer range does not fit the type.
39
46
  def random!(*args, rng: nil); end
40
47
 
41
48
  # @overload random(rng: nil)
@@ -51,7 +58,7 @@ class CArray
51
58
  # Fills `self` with standard normal `N(0, 1)` samples via
52
59
  # Box-Muller and returns `self`. Restricted to float / complex
53
60
  # data types; complex fills real and imaginary parts as two
54
- # independent normals per cell.
61
+ # independent normals per cell. The mask is cleared.
55
62
  # @param rng [Random, nil] RNG instance; nil uses the per-ractor
56
63
  # default RNG.
57
64
  # @return [self]
@@ -72,7 +79,9 @@ class CArray
72
79
  # Fisher-Yates permutes `self` in-place and returns `self`.
73
80
  # Without `axis:`, shuffles all cells as if flattened. With
74
81
  # `axis:`, permutes slices along that axis (the trailing
75
- # sub-slab is treated as a byte chunk and swapped whole).
82
+ # sub-slab is treated as a byte chunk and swapped whole). The mask
83
+ # moves with the values: a masked cell stays masked wherever it
84
+ # lands.
76
85
  # @param axis [Integer, nil] axis to permute along; nil = flat.
77
86
  # @param rng [Random, nil] RNG instance; nil uses the per-ractor
78
87
  # default RNG.
@@ -16,13 +16,17 @@ class CArray
16
16
  # Shared contract:
17
17
  #
18
18
  # - `addrs` is a CArray of any integer type (coerced to
19
- # `CA_SIZE`) or a Ruby Array.
19
+ # `CA_SIZE`) or a Ruby Array. A float or complex CArray is
20
+ # refused with `IndexError`, as `self[addrs]` refuses it.
20
21
  # - `vals` is a CArray of length matching `addrs` (coerced to
21
- # `self.data_type`), or a Numeric scalar broadcast to all
22
- # addresses. A complex `self` also takes a Complex scalar.
23
- # - Out-of-range `addrs[i]` (`< 0` or `>= self.elements`) raises
24
- # `IndexError`. The pairs before it stay applied, through a view
25
- # as well.
22
+ # `self.data_type`), or a scalar broadcast to all addresses: any
23
+ # Numeric, `true` / `false`, or `UNDEF`. The scalar is converted as
24
+ # `self[i] = v` converts it, so a value that does not fit the type
25
+ # raises (`RangeError`, `FloatDomainError` for NaN into an integer
26
+ # type). A scalar `UNDEF` is a masked value.
27
+ # - A negative `addrs[i]` counts from the end. One out of range
28
+ # raises `IndexError`; the pairs before it stay applied, through a
29
+ # view as well.
26
30
  # - `self.data_type` must be numeric. Complex is accepted by
27
31
  # every variant except {#scatter_min!} and {#scatter_max!},
28
32
  # since complex values have no order.
@@ -101,11 +105,12 @@ class CArray
101
105
  # result is written back many times.
102
106
  #
103
107
  # Unlike the arithmetic `scatter_*!` family, `self` may be
104
- # **boolean** (assignment does not widen), and `true` / `false`
105
- # are accepted as scalar `vals` alongside numeric scalars.
108
+ # **boolean** (assignment does not widen); `true` / `false` (or
109
+ # `1` / `0`) are its scalar values. A scalar `UNDEF` masks every
110
+ # addressed cell.
106
111
  #
107
112
  # @param addrs [CArray, Array<Integer>]
108
- # @param vals [CArray, Numeric, true, false]
113
+ # @param vals [CArray, Numeric, true, false, UNDEF]
109
114
  # @return [self]
110
115
  def scatter_replace!(addrs, vals); end
111
116
 
@@ -14,7 +14,8 @@ class CArray
14
14
  # duration of the block — capturing it across iterations sees the last
15
15
  # slab's data — and it is read-only: writing through it raises. To
16
16
  # produce values per slab use `map_slab` or `reduce_slab`; to write in
17
- # place, assign through the array itself.
17
+ # place, assign through the array itself. Over a Face (`CATime`, a
18
+ # record type) the slab is that Face.
18
19
  # @overload each_slab(axis:)
19
20
  # Returns an Enumerator when no block is given.
20
21
  # @param axis [Integer, Array<Integer>, nil] the slab axis or axes
@@ -29,7 +30,9 @@ class CArray
29
30
  # block's result. The block receives the slab view and must return a
30
31
  # value of the same shape as the slab (a CArray or scalar); the results
31
32
  # are written into the output at the same positions, and a masked
32
- # cell of the block's result is masked in the output.
33
+ # cell of the block's result is masked in the output. Over a Face the
34
+ # slab is that Face, and the output is too unless `data_type:` is
35
+ # given; a read-only Face answers in `:object` cells.
33
36
  # @param axis [Integer, Array<Integer>, nil] the slab axis or axes.
34
37
  # @param data_type [Symbol, Integer, Class, nil] output data type
35
38
  # (defaults to `self`'s data type).
@@ -48,6 +51,10 @@ class CArray
48
51
  # Per-element form (`init:` given): the block receives `(acc, x)` for
49
52
  # each element of the slab and returns the new accumulator; the final
50
53
  # accumulator per slab fills the output.
54
+ #
55
+ # `UNDEF` from the block masks that output cell. Over a Face the slab
56
+ # (and each element) is that Face's, and the output is that Face unless
57
+ # `data_type:` is given; a read-only Face answers in `:object` cells.
51
58
  # @param axis [Integer, Array<Integer>, nil] the slab axis or axes.
52
59
  # @param init [Object] the initial accumulator (selects the
53
60
  # per-element form).
@@ -179,8 +179,8 @@ class CArray
179
179
  # is a one-liner on top of `flatten[axis2addr(...)]`.
180
180
  #
181
181
  # Shape rule: `indices.ndim == self.ndim`, and
182
- # `indices.dim[j] == self.dim[j]` for all `j != axis`;
183
- # `indices.dim[axis]` is free.
182
+ # `indices.shape[j] == self.shape[j]` for all `j != axis`;
183
+ # `indices.shape[axis]` is free.
184
184
  #
185
185
  # `indices` data_type: any integer kind (zero-copy when
186
186
  # already `:int64`). Negative indices: Python-style
@@ -196,9 +196,10 @@ class CArray
196
196
  # @return [CArray] `:int64` view-flat addresses, same shape as
197
197
  # `indices`.
198
198
  # @raise [IndexError] when an index is out of range after
199
- # negative normalization.
200
- # @raise [ArgumentError] for shape / ndim / data_type
201
- # violations.
199
+ # negative normalization, or `indices` is a float or complex
200
+ # array.
201
+ # @raise [ArgumentError] for shape / ndim violations, or a
202
+ # boolean / object `indices`.
202
203
  def axis2addr(indices, axis: 0); end
203
204
 
204
205
  # @!endgroup
@@ -6,8 +6,9 @@ class CArray
6
6
  # @!group Index and address conversion
7
7
 
8
8
  # @overload valid_index?(*idx)
9
- # Returns `true` if the given index tuple is in range for `self`.
10
- # The number of indices must equal `ndim`.
9
+ # Returns `true` if the given index tuple names a cell of `self`,
10
+ # that is, if `self[*idx]` would not raise. A negative index counts
11
+ # from the end of its axis. The number of indices must equal `ndim`.
11
12
  # @param idx [Array<Integer>] one index per axis.
12
13
  # @return [Boolean]
13
14
  # @raise [ArgumentError] if the number of indices does not match
@@ -15,7 +16,8 @@ class CArray
15
16
  def valid_index?(*idx); end
16
17
 
17
18
  # @overload valid_addr?(addr)
18
- # Returns `true` if `addr` is in range `0...elements` for `self`.
19
+ # Returns `true` if `addr` names a cell of `self`: `0...elements`, or
20
+ # a negative address counting from the end (`-elements..-1`).
19
21
  # @param addr [Integer] flat address into the contiguous element
20
22
  # sequence.
21
23
  # @return [Boolean]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carray
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - himotoyoshi
@@ -111,11 +111,13 @@ files:
111
111
  - ext/carray_attribute.c
112
112
  - ext/carray_bincount.c
113
113
  - ext/carray_broadcast.c
114
+ - ext/carray_build_flags.h
114
115
  - ext/carray_call_cfunc.c
115
116
  - ext/carray_call_cfunc.h
116
117
  - ext/carray_cast.c
117
118
  - ext/carray_cast_func.rb
118
119
  - ext/carray_class.c
120
+ - ext/carray_config.h
119
121
  - ext/carray_conversion.c
120
122
  - ext/carray_copy.c
121
123
  - ext/carray_core.c
@@ -129,6 +131,21 @@ files:
129
131
  - ext/carray_index_classifier.c
130
132
  - ext/carray_index_classifier.h
131
133
  - ext/carray_internal.h
134
+ - ext/carray_kernels_bincmp.c
135
+ - ext/carray_kernels_binop.c
136
+ - ext/carray_kernels_init.c
137
+ - ext/carray_kernels_moncmp.c
138
+ - ext/carray_kernels_monop.c
139
+ - ext/carray_kernels_reduce_aggregate.c
140
+ - ext/carray_kernels_reduce_boolean.c
141
+ - ext/carray_kernels_reduce_cumulative.c
142
+ - ext/carray_kernels_reduce_extreme.c
143
+ - ext/carray_kernels_reduce_variance.c
144
+ - ext/carray_kernels_scan.c
145
+ - ext/carray_kernels_search.c
146
+ - ext/carray_kernels_sort.c
147
+ - ext/carray_kernels_triop.c
148
+ - ext/carray_key_windows.c
132
149
  - ext/carray_lazy.c
133
150
  - ext/carray_loop.c
134
151
  - ext/carray_mask.c
@@ -140,6 +157,7 @@ files:
140
157
  - ext/carray_order.c
141
158
  - ext/carray_partition.c
142
159
  - ext/carray_random.c
160
+ - ext/carray_round.c
143
161
  - ext/carray_scatter.c
144
162
  - ext/carray_segment.c
145
163
  - ext/carray_slab.c
@@ -159,7 +177,6 @@ files:
159
177
  - ext/version.h
160
178
  - ext/version.rb
161
179
  - lib/carray.rb
162
- - lib/carray/arrow_tensor.rb
163
180
  - lib/carray/attribute.rb
164
181
  - lib/carray/autoload_carray.rb
165
182
  - lib/carray/autoload_method_extension.rb
@@ -177,8 +194,10 @@ files:
177
194
  - lib/carray/core_extensions.rb
178
195
  - lib/carray/data_type_extension.rb
179
196
  - lib/carray/data_type_limits.rb
197
+ - lib/carray/distance_limit.rb
180
198
  - lib/carray/fixlen_string.rb
181
199
  - lib/carray/frame.rb
200
+ - lib/carray/frame/column_verbs.rb
182
201
  - lib/carray/frame/concat.rb
183
202
  - lib/carray/frame/convert.rb
184
203
  - lib/carray/frame/csv_parser.rb
@@ -191,11 +210,13 @@ files:
191
210
  - lib/carray/frame/reshape.rb
192
211
  - lib/carray/frame/sort.rb
193
212
  - lib/carray/frame/verbs.rb
213
+ - lib/carray/frame/windows.rb
194
214
  - lib/carray/fuse_source.rb
195
215
  - lib/carray/fusion.rb
196
216
  - lib/carray/histogram.rb
197
217
  - lib/carray/inspect.rb
198
218
  - lib/carray/iterator.rb
219
+ - lib/carray/key_windows.rb
199
220
  - lib/carray/lazy.rb
200
221
  - lib/carray/mask_gap_fill.rb
201
222
  - lib/carray/math.rb
@@ -212,8 +233,10 @@ files:
212
233
  - lib/carray/methods/gather_nd.rb
213
234
  - lib/carray/methods/index.rb
214
235
  - lib/carray/methods/insert_block.rb
236
+ - lib/carray/methods/is_between.rb
215
237
  - lib/carray/methods/is_in.rb
216
238
  - lib/carray/methods/join.rb
239
+ - lib/carray/methods/lag.rb
217
240
  - lib/carray/methods/locate_addr.rb
218
241
  - lib/carray/methods/mask_duplicates.rb
219
242
  - lib/carray/methods/meshgrid.rb
@@ -237,7 +260,6 @@ files:
237
260
  - lib/carray/string_operation_extension.rb
238
261
  - lib/carray/struct.rb
239
262
  - lib/carray/struct_builder.rb
240
- - lib/carray/table.rb
241
263
  - lib/carray/time.rb
242
264
  - lib/carray/window_iterator.rb
243
265
  - yard-stubs/ca_obj_array.rb