carray 3.0.1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +520 -0
- data/README.md +2 -2
- data/carray.gemspec +1 -1
- data/ext/ca_axis_dispatch.c +33 -4
- data/ext/ca_axis_group.c +202 -96
- data/ext/ca_categorical_iterator.c +108 -54
- data/ext/ca_kernel_iterator.c +317 -51
- data/ext/ca_kernel_iterator.h +142 -35
- data/ext/ca_obj_array.c +62 -20
- data/ext/ca_obj_block.c +4 -4
- data/ext/ca_obj_const_string.c +85 -26
- data/ext/ca_obj_face.c +24 -0
- data/ext/ca_obj_face.h +15 -0
- data/ext/ca_obj_fixlen_string.c +18 -5
- data/ext/ca_obj_meld.c +123 -25
- data/ext/ca_obj_object.c +8 -0
- data/ext/ca_obj_select.c +49 -34
- data/ext/ca_obj_stack.c +3 -8
- data/ext/ca_obj_stride.c +72 -1
- data/ext/ca_obj_string.c +8 -4
- data/ext/ca_obj_window.c +8 -2
- data/ext/ca_op_ipower.c +1 -2
- data/ext/ca_rng_normal.h +42 -0
- data/ext/ca_rng_xoshiro256pp.h +105 -0
- data/ext/ca_sweep_engine.c +307 -143
- data/ext/ca_sweep_engine.h +26 -5
- data/ext/carray.h +21 -2
- data/ext/carray_access.c +32 -20
- data/ext/carray_address_basis.c +590 -0
- data/ext/carray_broadcast.c +3 -3
- data/ext/carray_call_cfunc.c +667 -483
- data/ext/carray_cast.c +115 -41
- data/ext/carray_copy.c +55 -30
- data/ext/carray_core.c +83 -3
- data/ext/carray_count.c +9 -10
- data/ext/carray_factorize.c +46 -25
- data/ext/carray_internal.h +17 -0
- data/ext/carray_kernels_reduce_aggregate.c +168 -0
- data/ext/carray_kernels_reduce_cumulative.c +270 -1
- data/ext/carray_kernels_reduce_extreme.c +554 -8
- data/ext/carray_kernels_scan.c +4 -4
- data/ext/carray_kernels_search.c +94 -14
- data/ext/carray_loop.c +7 -1
- data/ext/carray_mask.c +23 -8
- data/ext/carray_median_percentile.c +55 -0
- data/ext/carray_operator.c +4 -4
- data/ext/carray_order.c +1 -1
- data/ext/carray_random.c +384 -40
- data/ext/carray_slab.c +13 -0
- data/ext/carray_sort.c +20 -22
- data/ext/mk_call_cfunc.rb +103 -116
- data/ext/mkkernel.rb +297 -29
- data/ext/ruby_carray.c +10 -1
- data/ext/version.h +4 -4
- data/lib/carray/autoload_carray.rb +5 -3
- data/lib/carray/autoload_method_extension.rb +12 -0
- data/lib/carray/axis_group.rb +77 -0
- data/lib/carray/basics.rb +4 -0
- data/lib/carray/block_iterator.rb +92 -16
- data/lib/carray/categorical.rb +150 -33
- data/lib/carray/categorical_iterator.rb +207 -80
- data/lib/carray/const_string.rb +131 -27
- data/lib/carray/construct.rb +40 -0
- data/lib/carray/data_type_extension.rb +3 -0
- data/lib/carray/data_type_limits.rb +91 -0
- data/lib/carray/fixlen_string.rb +1 -1
- data/lib/carray/frame/csv_parser.rb +11 -4
- data/lib/carray/frame/frame.rb +81 -10
- data/lib/carray/frame/group.rb +36 -3
- data/lib/carray/frame/io.rb +67 -15
- data/lib/carray/frame/records.rb +18 -4
- data/lib/carray/frame/verbs.rb +14 -11
- data/lib/carray/inspect.rb +42 -9
- data/lib/carray/iterator.rb +143 -0
- data/lib/carray/lazy.rb +0 -37
- data/lib/carray/mask_gap_fill.rb +3 -1
- data/lib/carray/methods/discovery_along.rb +74 -0
- data/lib/carray/methods/factorize.rb +50 -0
- data/lib/carray/methods/is_in.rb +13 -2
- data/lib/carray/methods/locate_addr.rb +75 -2
- data/lib/carray/methods/mask_duplicates.rb +35 -1
- data/lib/carray/methods/nunique.rb +22 -1
- data/lib/carray/methods/repeat.rb +110 -0
- data/lib/carray/methods/unique.rb +41 -1
- data/lib/carray/rng.rb +86 -0
- data/lib/carray/slab_iterator.rb +58 -13
- data/lib/carray/string_operation_extension.rb +5 -1
- data/lib/carray/time.rb +18 -2
- data/lib/carray/window_iterator.rb +142 -20
- data/lib/carray.rb +2 -0
- data/yard-stubs/ca_obj_block.rb +2 -7
- data/yard-stubs/ca_obj_window.rb +10 -2
- data/yard-stubs/carray_access.rb +1 -1
- data/yard-stubs/carray_broadcast.rb +1 -1
- data/yard-stubs/carray_core.rb +0 -80
- data/yard-stubs/carray_count.rb +7 -2
- data/yard-stubs/carray_lazy.rb +205 -0
- data/yard-stubs/carray_math.rb +1486 -3
- data/yard-stubs/carray_median_percentile.rb +16 -2
- data/yard-stubs/carray_order.rb +9 -69
- data/yard-stubs/carray_slab.rb +9 -7
- data/yard-stubs/carray_sort.rb +7 -5
- metadata +9 -1
|
@@ -13,6 +13,11 @@ class CArray
|
|
|
13
13
|
# result of Ruby `+` / `/` on the stored objects. Fixlen arrays
|
|
14
14
|
# raise, since no numeric midpoint is defined.
|
|
15
15
|
#
|
|
16
|
+
# An even number of elements has no middle one, only the average of
|
|
17
|
+
# two -- so an object array whose elements cannot be averaged (a
|
|
18
|
+
# column of Strings) has a median at odd length and raises at even.
|
|
19
|
+
# `percentile(50, method: :lower)` names an element either way.
|
|
20
|
+
#
|
|
16
21
|
# Masked cells are excluded. Per-axis, each fiber uses only its own
|
|
17
22
|
# present values; a fully masked fiber reduces to `UNDEF`. If the
|
|
18
23
|
# count of not-masked cells (per fiber, or over all elements in the
|
|
@@ -27,7 +32,8 @@ class CArray
|
|
|
27
32
|
# count is below `min_count`.
|
|
28
33
|
# @param keep_axis [Boolean]
|
|
29
34
|
# @return [Float, CArray, Object]
|
|
30
|
-
# @raise [CArray::DataTypeError] for fixlen data_type
|
|
35
|
+
# @raise [CArray::DataTypeError] for fixlen data_type, or for an even
|
|
36
|
+
# number of elements whose objects cannot be averaged.
|
|
31
37
|
# @raise [ArgumentError] on negative `min_count`.
|
|
32
38
|
def median(*); end
|
|
33
39
|
|
|
@@ -52,6 +58,12 @@ class CArray
|
|
|
52
58
|
# - `:nearest` — round-half-to-even to the nearer neighbor.
|
|
53
59
|
# - `:midpoint` — arithmetic mean of the two neighbors.
|
|
54
60
|
#
|
|
61
|
+
# The first three pick an element and the last two compute one, so
|
|
62
|
+
# only the first three apply to a `CA_OBJECT` array whose elements
|
|
63
|
+
# have no arithmetic: `:linear` and `:midpoint` raise there, and do
|
|
64
|
+
# so only when the requested `p` actually falls between two
|
|
65
|
+
# elements (`percentile(50)` of five Strings still answers).
|
|
66
|
+
#
|
|
55
67
|
# Numeric arrays produce `Float` results; `CA_OBJECT` arrays
|
|
56
68
|
# apply Ruby `+` / `/` / `*` on the stored objects. Fixlen
|
|
57
69
|
# arrays raise.
|
|
@@ -67,7 +79,9 @@ class CArray
|
|
|
67
79
|
# `:nearest`, `:midpoint`.
|
|
68
80
|
# @param keep_axis [Boolean]
|
|
69
81
|
# @return [Float, CArray, Object, Array<Float>, Array<CArray>, Array<Object>]
|
|
70
|
-
# @raise [CArray::DataTypeError] for fixlen data_type
|
|
82
|
+
# @raise [CArray::DataTypeError] for fixlen data_type, or when an
|
|
83
|
+
# interpolating `method` is asked to interpolate between objects
|
|
84
|
+
# that have no arithmetic.
|
|
71
85
|
# @raise [ArgumentError] on empty `p` list, `p` outside `[0, 100]`,
|
|
72
86
|
# empty axis, unknown `method`, or invalid option combinations.
|
|
73
87
|
def percentile(*); end
|
data/yard-stubs/carray_order.rb
CHANGED
|
@@ -170,10 +170,17 @@ class CArray
|
|
|
170
170
|
|
|
171
171
|
# @overload search_nearest(val)
|
|
172
172
|
# Returns the flat address of the element of `self` whose value
|
|
173
|
-
# is closest to `val`.
|
|
174
|
-
#
|
|
173
|
+
# is closest to `val`.
|
|
174
|
+
#
|
|
175
|
+
# In an `:object` array the distance is `val.distance(other)` when
|
|
176
|
+
# `val` answers `#distance`, and `(val - other).abs` when it is a
|
|
177
|
+
# number. Anything else -- a String, say -- has no distance and
|
|
178
|
+
# raises `CArray::DataTypeError`; use {#search} or {#bsearch} for an
|
|
179
|
+
# exact match.
|
|
175
180
|
# @param val [Object]
|
|
176
181
|
# @return [Integer, nil]
|
|
182
|
+
# @raise [CArray::DataTypeError] when `val` is neither a number nor
|
|
183
|
+
# answers `#distance`.
|
|
177
184
|
# @overload search_nearest(val, axis:)
|
|
178
185
|
# Per-fiber nearest-value search along `axis`. Returns
|
|
179
186
|
# axis-local positions.
|
|
@@ -189,73 +196,6 @@ class CArray
|
|
|
189
196
|
# @return [CArray]
|
|
190
197
|
def search_nearest_addr(val, axis: nil); end
|
|
191
198
|
|
|
192
|
-
# @overload locate_addr(ref)
|
|
193
|
-
# Returns, for each element of `self`, the flat address into `ref`
|
|
194
|
-
# where the value first occurs, or `UNDEF` where it is not present.
|
|
195
|
-
# Builds a value-to-first-address map from `ref` in one pass (an
|
|
196
|
-
# open-addressing hash, the same substrate as {#unique} /
|
|
197
|
-
# {#value_counts}), then probes each element of `self`; no sort,
|
|
198
|
-
# peak memory `O(distinct ref values)`.
|
|
199
|
-
#
|
|
200
|
-
# The return is `ref`'s flat address (0 to `ref.elements - 1`),
|
|
201
|
-
# so a multi-dimensional `ref` still yields a `self`-shaped
|
|
202
|
-
# result of flat addresses; downstream reads (`ref[addr]`,
|
|
203
|
-
# `model_var[addr]`, ...) apply it as a flat gather.
|
|
204
|
-
#
|
|
205
|
-
# Works on numeric, `CA_OBJECT`, and `CA_FIXLEN` values, matching
|
|
206
|
-
# the value-hash discovery family: numeric follows `==` with all
|
|
207
|
-
# NaN collapsed to one value and `-0.0 == +0.0`; object follows
|
|
208
|
-
# Ruby `hash` / `eql?` with Float NaN collapsed; fixlen follows
|
|
209
|
-
# byte equality. When `ref` holds duplicate values the returned
|
|
210
|
-
# address is the earliest (appearance-order) occurrence. Masked
|
|
211
|
-
# cells of `ref` do not enter the map but still occupy their flat
|
|
212
|
-
# address; masked cells of `self` are `UNDEF` in the result.
|
|
213
|
-
#
|
|
214
|
-
# Typical use is time-axis lookup: compute the address once
|
|
215
|
-
# against a reference axis, then reuse it to gather from many
|
|
216
|
-
# `ref`-shaped variables without repeating the lookup.
|
|
217
|
-
#
|
|
218
|
-
# Implemented in Ruby (see `lib/carray/methods/locate_addr.rb`)
|
|
219
|
-
# over the `__locate_addr__` hash-lane kernel; `self` is coerced
|
|
220
|
-
# to `ref`'s data type within the same family (cross-family raises).
|
|
221
|
-
# @param ref [CArray] reference values to match against; any
|
|
222
|
-
# shape (used as flat).
|
|
223
|
-
# @return [CArray] `:int64` flat addresses into `ref`, same shape
|
|
224
|
-
# as `self`; unmatched cells are masked.
|
|
225
|
-
def locate_addr(ref); end
|
|
226
|
-
|
|
227
|
-
# @overload locate_nearest_addr(ref, direction: :round, tolerance: nil)
|
|
228
|
-
# Returns, for each element of `self`, the flat address into `ref`
|
|
229
|
-
# of the nearest reference value. Continuous sibling of
|
|
230
|
-
# {#locate_addr}; uses `linear_section` + rounding for non-exact
|
|
231
|
-
# matching against a sorted `ref`.
|
|
232
|
-
#
|
|
233
|
-
# Out-of-range cells of `self` (outside `ref`'s span) mask through
|
|
234
|
-
# the pipeline: `linear_section` returns NaN, `mask_invalid`
|
|
235
|
-
# propagates that as `UNDEF`, rounding and the int64 cast carry
|
|
236
|
-
# the mask, and `project` scatters it into the final positions.
|
|
237
|
-
# `mask_invalid` runs before rounding because `CArray#round` maps
|
|
238
|
-
# NaN to 0 and would otherwise silently match `ref[0]`.
|
|
239
|
-
#
|
|
240
|
-
# `tolerance:` (default `nil`) sets a maximum accepted absolute
|
|
241
|
-
# distance between `self[i]` and its matched `ref` value. When
|
|
242
|
-
# `|ref[addr] - self[i]| > tolerance`, the result cell is masked.
|
|
243
|
-
# Use for accuracy-controlled matching (e.g. "an observation
|
|
244
|
-
# snaps to a time step only if within N seconds").
|
|
245
|
-
#
|
|
246
|
-
# Implemented in Ruby (see `lib/carray/methods/locate_addr.rb`).
|
|
247
|
-
# @param ref [CArray] 1-D sorted reference grid to match against.
|
|
248
|
-
# @param direction [Symbol] `:round`, `:floor`, or `:ceil` —
|
|
249
|
-
# rounding applied to the fractional position.
|
|
250
|
-
# @param tolerance [Numeric, nil] maximum accepted `|self - ref|`
|
|
251
|
-
# distance; cells beyond this are masked. `nil` disables the
|
|
252
|
-
# check.
|
|
253
|
-
# @return [CArray] `:int64` flat addresses into `ref`, same shape
|
|
254
|
-
# as `self`; out-of-range and beyond-tolerance cells are masked.
|
|
255
|
-
# @raise [ArgumentError] when `direction` is not one of the
|
|
256
|
-
# accepted symbols.
|
|
257
|
-
def locate_nearest_addr(ref, direction: :round, tolerance: nil); end
|
|
258
|
-
|
|
259
199
|
# @!endgroup
|
|
260
200
|
|
|
261
201
|
# @!group Sorting and searching
|
data/yard-stubs/carray_slab.rb
CHANGED
|
@@ -10,16 +10,18 @@ class CArray
|
|
|
10
10
|
|
|
11
11
|
# @overload each_slab(axis:)
|
|
12
12
|
# Yields each slab of `self` (a view along the axes NOT in `axis`) to
|
|
13
|
-
# the block and returns `self`. The slab is
|
|
14
|
-
#
|
|
15
|
-
#
|
|
13
|
+
# the block and returns `self`. The slab is valid only for the
|
|
14
|
+
# duration of the block — capturing it across iterations sees the last
|
|
15
|
+
# slab's data — and it is read-only: writing through it raises. To
|
|
16
|
+
# produce values per slab use `map_slab` or `reduce_slab`; to write in
|
|
17
|
+
# place, assign through the array itself.
|
|
16
18
|
# @overload each_slab(axis:)
|
|
17
19
|
# Returns an Enumerator when no block is given.
|
|
18
20
|
# @param axis [Integer, Array<Integer>, nil] the slab axis or axes
|
|
19
21
|
# (`nil` = the whole view as a single slab).
|
|
20
22
|
# @return [self, Enumerator]
|
|
21
|
-
# @see file:docs/SlabIterator.md SlabIterator
|
|
22
|
-
# @see file:
|
|
23
|
+
# @see file:docs/topics/SlabIterator.md SlabIterator
|
|
24
|
+
# @see file:guides/users/11_slab_iteration.md Slab iteration
|
|
23
25
|
def each_slab(axis:); end
|
|
24
26
|
|
|
25
27
|
# @overload map_slab(axis:, data_type: nil)
|
|
@@ -33,7 +35,7 @@ class CArray
|
|
|
33
35
|
# @return [CArray]
|
|
34
36
|
# @raise [ArgumentError] when the block result's shape does not match
|
|
35
37
|
# the slab.
|
|
36
|
-
# @see file:docs/SlabIterator.md SlabIterator
|
|
38
|
+
# @see file:docs/topics/SlabIterator.md SlabIterator
|
|
37
39
|
def map_slab(axis:, data_type: nil); end
|
|
38
40
|
|
|
39
41
|
# @overload reduce_slab(axis:, data_type: nil)
|
|
@@ -50,7 +52,7 @@ class CArray
|
|
|
50
52
|
# per-element form).
|
|
51
53
|
# @param data_type [Symbol, Integer, Class, nil] output data type.
|
|
52
54
|
# @return [CArray] the reduced array (slab axes collapsed).
|
|
53
|
-
# @see file:docs/SlabIterator.md SlabIterator
|
|
55
|
+
# @see file:docs/topics/SlabIterator.md SlabIterator
|
|
54
56
|
def reduce_slab(axis:, init: nil, data_type: nil); end
|
|
55
57
|
|
|
56
58
|
# @!endgroup
|
data/yard-stubs/carray_sort.rb
CHANGED
|
@@ -67,11 +67,13 @@ class CArray
|
|
|
67
67
|
# along `axis`. Use this when you want an independent array
|
|
68
68
|
# rather than a view.
|
|
69
69
|
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
# `
|
|
74
|
-
# `
|
|
70
|
+
# It takes whatever {#sort} takes: numeric (`i8`..`f64`),
|
|
71
|
+
# `CA_BOOLEAN`, `CA_FIXLEN` and `CA_OBJECT`, masked or not.
|
|
72
|
+
#
|
|
73
|
+
# Unmasked `i8`..`f64` uses a per-fiber gather + sort + scatter,
|
|
74
|
+
# bypassing the `CARemap` scatter layer that `sort` uses.
|
|
75
|
+
# Everything else materializes the `sort` view instead (same
|
|
76
|
+
# shape, ordering, and `masked_position:` semantics as {#sort}).
|
|
75
77
|
# @param axis [Integer, nil]
|
|
76
78
|
# @param kind [Symbol] `:quick` or `:stable`.
|
|
77
79
|
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
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.
|
|
4
|
+
version: 3.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- himotoyoshi
|
|
@@ -96,6 +96,8 @@ files:
|
|
|
96
96
|
- ext/ca_op_cmplx64.h
|
|
97
97
|
- ext/ca_op_ipower.c
|
|
98
98
|
- ext/ca_op_powi.h
|
|
99
|
+
- ext/ca_rng_normal.h
|
|
100
|
+
- ext/ca_rng_xoshiro256pp.h
|
|
99
101
|
- ext/ca_sort_kernels.h
|
|
100
102
|
- ext/ca_sweep_engine.c
|
|
101
103
|
- ext/ca_sweep_engine.h
|
|
@@ -104,6 +106,7 @@ files:
|
|
|
104
106
|
- ext/ca_triop_dispatch.h
|
|
105
107
|
- ext/carray.h
|
|
106
108
|
- ext/carray_access.c
|
|
109
|
+
- ext/carray_address_basis.c
|
|
107
110
|
- ext/carray_attribute.c
|
|
108
111
|
- ext/carray_bincount.c
|
|
109
112
|
- ext/carray_broadcast.c
|
|
@@ -186,6 +189,7 @@ files:
|
|
|
186
189
|
- lib/carray/construct.rb
|
|
187
190
|
- lib/carray/core_extensions.rb
|
|
188
191
|
- lib/carray/data_type_extension.rb
|
|
192
|
+
- lib/carray/data_type_limits.rb
|
|
189
193
|
- lib/carray/fixlen_string.rb
|
|
190
194
|
- lib/carray/frame.rb
|
|
191
195
|
- lib/carray/frame/concat.rb
|
|
@@ -214,6 +218,8 @@ files:
|
|
|
214
218
|
- lib/carray/methods/broadcast.rb
|
|
215
219
|
- lib/carray/methods/choose.rb
|
|
216
220
|
- lib/carray/methods/composition.rb
|
|
221
|
+
- lib/carray/methods/discovery_along.rb
|
|
222
|
+
- lib/carray/methods/factorize.rb
|
|
217
223
|
- lib/carray/methods/gather_nd.rb
|
|
218
224
|
- lib/carray/methods/index.rb
|
|
219
225
|
- lib/carray/methods/insert_block.rb
|
|
@@ -224,12 +230,14 @@ files:
|
|
|
224
230
|
- lib/carray/methods/meshgrid.rb
|
|
225
231
|
- lib/carray/methods/mode.rb
|
|
226
232
|
- lib/carray/methods/nunique.rb
|
|
233
|
+
- lib/carray/methods/repeat.rb
|
|
227
234
|
- lib/carray/methods/resize.rb
|
|
228
235
|
- lib/carray/methods/snap.rb
|
|
229
236
|
- lib/carray/methods/string_format.rb
|
|
230
237
|
- lib/carray/methods/unique.rb
|
|
231
238
|
- lib/carray/methods/value_counts.rb
|
|
232
239
|
- lib/carray/mkmf.rb
|
|
240
|
+
- lib/carray/rng.rb
|
|
233
241
|
- lib/carray/runtime.rb
|
|
234
242
|
- lib/carray/serialize.rb
|
|
235
243
|
- lib/carray/slab_iterator.rb
|