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.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/CHANGELOG.md +325 -3
- data/{NEWS.md → CHANGELOG.v1.md} +1 -1
- data/README.md +32 -32
- data/carray.gemspec +12 -8
- data/ext/ca_axis_group.c +55 -19
- data/ext/ca_binop_dispatch.c +5 -6
- data/ext/ca_binop_dispatch.h +0 -7
- data/ext/ca_categorical_iterator.c +13 -13
- data/ext/ca_for_each_element.h +6 -8
- data/ext/ca_group_iter.c +1 -1
- data/ext/ca_kernel_iterator.c +69 -23
- data/ext/ca_kernel_iterator.h +3 -10
- data/ext/ca_obj_bincmp.c +57 -27
- data/ext/ca_obj_binop.c +86 -30
- data/ext/ca_obj_const_string.c +3 -1
- data/ext/ca_obj_face.c +80 -0
- data/ext/ca_obj_face.h +33 -1
- data/ext/ca_obj_fake.c +11 -0
- data/ext/ca_obj_fixlen_string.c +3 -1
- data/ext/ca_obj_grid.c +11 -3
- data/ext/ca_obj_meld.c +13 -8
- data/ext/ca_obj_moncmp.c +33 -14
- data/ext/ca_obj_monop.c +19 -7
- data/ext/ca_obj_object.c +99 -4
- data/ext/ca_obj_record.c +3 -1
- data/ext/ca_obj_refer.c +30 -6
- data/ext/ca_obj_roll.c +13 -5
- data/ext/ca_obj_select_axis.c +16 -6
- data/ext/ca_obj_shift.c +3 -3
- data/ext/ca_obj_stride.c +106 -23
- data/ext/ca_obj_string.c +3 -1
- data/ext/ca_obj_tile.c +13 -5
- data/ext/ca_obj_time.c +3 -1
- data/ext/ca_obj_timedelta.c +3 -1
- data/ext/ca_obj_transpose.c +1 -1
- data/ext/ca_obj_triop.c +62 -23
- data/ext/ca_obj_window.c +86 -17
- data/ext/ca_op_cmplx64.h +123 -0
- data/ext/ca_op_ipower.c +0 -3
- data/ext/ca_sort_kernels.h +5 -5
- data/ext/ca_sweep_engine.c +78 -35
- data/ext/ca_sweep_engine.h +13 -4
- data/ext/ca_transform_common.c +7 -0
- data/ext/carray.h +127 -130
- data/ext/carray_access.c +56 -34
- data/ext/carray_bincount.c +8 -8
- data/ext/carray_broadcast.c +99 -6
- data/ext/carray_build_flags.h +3 -0
- data/ext/carray_call_cfunc.c +1491 -0
- data/ext/carray_call_cfunc.h +153 -0
- data/ext/carray_cast.c +69 -31
- data/ext/carray_conversion.c +22 -22
- data/ext/carray_copy.c +12 -2
- data/ext/carray_core.c +57 -10
- data/ext/carray_count.c +1 -1
- data/ext/carray_element.c +7 -7
- data/ext/carray_factorize.c +28 -28
- data/ext/carray_hold.c +1 -1
- data/ext/carray_index_classifier.c +7 -21
- data/ext/carray_internal.h +19 -3
- data/ext/carray_kernels_bincmp.c +1 -0
- data/ext/carray_kernels_binop.c +320 -298
- data/ext/carray_kernels_init.c +1095 -0
- data/ext/carray_kernels_map.c +1 -0
- data/ext/carray_kernels_moncmp.c +1 -0
- data/ext/carray_kernels_monop.c +412 -411
- data/ext/carray_kernels_reduce_aggregate.c +88 -87
- data/ext/carray_kernels_reduce_boolean.c +1 -0
- data/ext/carray_kernels_reduce_cumulative.c +54 -53
- data/ext/carray_kernels_reduce_extreme.c +51 -50
- data/ext/carray_kernels_reduce_variance.c +1 -0
- data/ext/carray_kernels_scan.c +1 -0
- data/ext/carray_kernels_search.c +93 -92
- data/ext/carray_kernels_sort.c +1 -0
- data/ext/carray_kernels_triop.c +1 -0
- data/ext/carray_lazy.c +175 -5
- data/ext/carray_mask.c +6 -5
- data/ext/carray_median_percentile.c +1 -1
- data/ext/carray_memory_view.c +46 -21
- data/ext/carray_operator.c +46 -49
- data/ext/carray_partition.c +4 -4
- data/ext/carray_random.c +7 -7
- data/ext/carray_scatter.c +1 -1
- data/ext/carray_sort.c +3 -3
- data/ext/carray_sort_kernel.c +10 -10
- data/ext/carray_test.c +1 -1
- data/ext/extconf.rb +18 -0
- data/ext/mk_call_cfunc.rb +243 -52
- data/ext/mkkernel.rb +354 -100
- data/ext/ruby_carray.c +18 -16
- data/ext/version.h +4 -4
- data/lib/carray/autoload_carray.rb +19 -0
- data/lib/carray/autoload_method_extension.rb +2 -1
- data/lib/carray/axis_group.rb +7 -7
- data/lib/carray/basics.rb +59 -59
- data/lib/carray/bincount_nd.rb +12 -12
- data/lib/carray/block_iterator.rb +24 -14
- data/lib/carray/categorical.rb +4 -4
- data/lib/carray/categorical_iterator.rb +98 -76
- data/lib/carray/conditional.rb +14 -14
- data/lib/carray/construct.rb +21 -0
- data/lib/carray/core_extensions.rb +62 -5
- data/lib/carray/data_type_extension.rb +18 -1
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +1 -1
- data/lib/carray/frame/frame.rb +4 -11
- data/lib/carray/frame/io.rb +159 -2
- data/lib/carray/frame/sort.rb +1 -1
- data/lib/carray/frame/verbs.rb +18 -1
- data/lib/carray/fuse_source.rb +123 -0
- data/lib/carray/fusion.rb +218 -0
- data/lib/carray/histogram.rb +16 -16
- data/lib/carray/inspect.rb +1 -7
- data/lib/carray/iterator.rb +4 -3
- data/lib/carray/lazy.rb +125 -73
- data/lib/carray/meld_reduce.rb +2 -2
- data/lib/carray/methods/align_addr.rb +1 -1
- data/lib/carray/methods/composition.rb +1 -1
- data/lib/carray/methods/is_in.rb +12 -12
- data/lib/carray/methods/locate_addr.rb +6 -1
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +4 -5
- data/lib/carray/methods/mode.rb +2 -2
- data/lib/carray/methods/nunique.rb +1 -1
- data/lib/carray/methods/snap.rb +7 -2
- data/lib/carray/methods/unique.rb +3 -3
- data/lib/carray/methods/value_counts.rb +2 -2
- data/lib/carray/runtime.rb +0 -19
- data/lib/carray/slab_iterator.rb +20 -7
- data/lib/carray/string_operation_extension.rb +5 -5
- data/lib/carray/time.rb +890 -491
- data/lib/carray/window_iterator.rb +285 -13
- data/lib/carray.rb +5 -5
- data/yard-stubs/ca_obj_array.rb +385 -0
- data/yard-stubs/ca_obj_bitarray.rb +38 -0
- data/yard-stubs/ca_obj_bitfield.rb +43 -0
- data/yard-stubs/ca_obj_block.rb +73 -0
- data/yard-stubs/ca_obj_byte_swap.rb +56 -0
- data/yard-stubs/ca_obj_fake.rb +31 -0
- data/yard-stubs/ca_obj_farray.rb +32 -0
- data/yard-stubs/ca_obj_field.rb +45 -0
- data/yard-stubs/ca_obj_grid.rb +35 -0
- data/yard-stubs/ca_obj_refer.rb +72 -0
- data/yard-stubs/ca_obj_roll.rb +45 -0
- data/yard-stubs/ca_obj_shift.rb +43 -0
- data/yard-stubs/ca_obj_stride.rb +181 -0
- data/yard-stubs/ca_obj_tile.rb +29 -0
- data/yard-stubs/ca_obj_transpose.rb +40 -0
- data/yard-stubs/ca_obj_window.rb +49 -0
- data/yard-stubs/carray_access.rb +131 -0
- data/yard-stubs/carray_attribute.rb +246 -0
- data/yard-stubs/carray_broadcast.rb +37 -0
- data/yard-stubs/carray_cast.rb +489 -0
- data/yard-stubs/carray_class.rb +65 -0
- data/yard-stubs/carray_conversion.rb +76 -0
- data/yard-stubs/carray_copy.rb +79 -0
- data/yard-stubs/carray_core.rb +114 -0
- data/yard-stubs/carray_count.rb +79 -0
- data/yard-stubs/carray_element.rb +108 -0
- data/yard-stubs/carray_generate.rb +66 -0
- data/yard-stubs/carray_lazy.rb +23 -0
- data/yard-stubs/carray_loop.rb +140 -0
- data/yard-stubs/carray_mask.rb +259 -0
- data/yard-stubs/carray_math.rb +132 -0
- data/yard-stubs/carray_mathfunc.rb +45 -0
- data/yard-stubs/carray_median_percentile.rb +89 -0
- data/yard-stubs/carray_memory_view.rb +163 -0
- data/yard-stubs/carray_order.rb +312 -0
- data/yard-stubs/carray_random.rb +89 -0
- data/yard-stubs/carray_scatter.rb +106 -0
- data/yard-stubs/carray_slab.rb +57 -0
- data/yard-stubs/carray_sort.rb +163 -0
- data/yard-stubs/carray_test.rb +85 -0
- data/yard-stubs/carray_undef.rb +64 -0
- data/yard-stubs/carray_utils.rb +97 -0
- data/yard-stubs/ruby_carray.rb +193 -0
- metadata +59 -10
- data/ext/ca_obj_unbound_repeat.c +0 -496
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_order.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Sorting and searching
|
|
7
|
+
|
|
8
|
+
# @overload project(idx, lval = nil, uval = nil)
|
|
9
|
+
# Returns a new array whose elements are taken from `self` at
|
|
10
|
+
# the positions named by `idx`. `idx` is a CArray of flat
|
|
11
|
+
# addresses into `self`; the result has the shape of `idx`.
|
|
12
|
+
#
|
|
13
|
+
# Out-of-range positions are filled with `lval` (below-range) and
|
|
14
|
+
# `uval` (above-range); when `lval` is given alone, it fills
|
|
15
|
+
# both. Without either, out-of-range positions are masked.
|
|
16
|
+
#
|
|
17
|
+
# 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.
|
|
22
|
+
# @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).
|
|
25
|
+
# @return [CArray] a fresh array shaped like `idx`; a Face of the same
|
|
26
|
+
# type when `self` is a Face.
|
|
27
|
+
# @raise [ArgumentError] if `lval` / `uval` is given and `self` is a Face.
|
|
28
|
+
def project(idx, lval = nil, uval = nil); end
|
|
29
|
+
|
|
30
|
+
# sort / sort_copy stubs live in yard-stubs/carray_sort.rb (same
|
|
31
|
+
# file split as ext/carray_sort.c <-> ext/carray_order.c).
|
|
32
|
+
|
|
33
|
+
# @overload partition(kth, axis: 0, masked_position: :last)
|
|
34
|
+
# Returns a `CARemap` view of `self` permuted along `axis` so that
|
|
35
|
+
# the element at fiber-local position `kth` is in its final sorted
|
|
36
|
+
# place, every element before it is `<=` it, and every element
|
|
37
|
+
# after it is `>=` it. Order within the two regions is unspecified.
|
|
38
|
+
# Average `O(n)` per fiber via quickselect.
|
|
39
|
+
#
|
|
40
|
+
# Negative `kth` counts from the end of the fiber
|
|
41
|
+
# (`-self.shape[axis] <= kth < self.shape[axis]`).
|
|
42
|
+
#
|
|
43
|
+
# Supports numeric (`i8`..`f64`), boolean (as its `0`/`1` value,
|
|
44
|
+
# `false` < `true`), `CA_FIXLEN` (memcmp lexicographic order), and
|
|
45
|
+
# `CA_OBJECT` (via `<=>` per pair).
|
|
46
|
+
#
|
|
47
|
+
# Mask handling matches {#sort}: masked cells are an incomparable
|
|
48
|
+
# sentinel, excluded from the kth-selection and clustered at
|
|
49
|
+
# `masked_position:`. A `kth` landing in the masked cluster needs
|
|
50
|
+
# no selection (unspecified order, same contract as the `<` / `>`
|
|
51
|
+
# regions); a `kth` landing in the unmasked range selects properly
|
|
52
|
+
# among unmasked values.
|
|
53
|
+
#
|
|
54
|
+
# @param kth [Integer] target fiber-local position along `axis`.
|
|
55
|
+
# @param axis [Integer]
|
|
56
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
57
|
+
# @return [CArray] `CARemap` view of `self`.
|
|
58
|
+
# @raise [ArgumentError] when `kth` is out of range.
|
|
59
|
+
def partition(kth, axis: 0, masked_position: :last); end
|
|
60
|
+
|
|
61
|
+
# @overload partition_copy(kth, axis: 0, masked_position: :last)
|
|
62
|
+
# Returns a fresh entity `CArray` with the same shape as `self`,
|
|
63
|
+
# partitioned along `axis` by the same rule as {#partition}.
|
|
64
|
+
# Bypasses the `CARemap` scatter layer for cases where an entity
|
|
65
|
+
# is wanted directly. Same dispatch (numeric / boolean / `CA_FIXLEN` /
|
|
66
|
+
# `CA_OBJECT`), same `kth` and `masked_position:` semantics.
|
|
67
|
+
# Masked input delegates to {#partition} + copy.
|
|
68
|
+
#
|
|
69
|
+
# Float NaN policy: NaN cells are pre-partitioned to the tail. If
|
|
70
|
+
# `kth` falls within the finite slice, quickselect runs over the
|
|
71
|
+
# finite cells; otherwise the kth cell is already NaN.
|
|
72
|
+
#
|
|
73
|
+
# @param kth [Integer]
|
|
74
|
+
# @param axis [Integer]
|
|
75
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
76
|
+
# @return [CArray] fresh entity.
|
|
77
|
+
# @raise [ArgumentError] same conditions as {#partition}.
|
|
78
|
+
def partition_copy(kth, axis: 0, masked_position: :last); end
|
|
79
|
+
|
|
80
|
+
# @overload order(axis: nil, descending: false, method: :ordinal)
|
|
81
|
+
# Returns each cell's rank among the other cells along `axis`
|
|
82
|
+
# (`0` = smallest). When `axis` is omitted, `self` is flattened
|
|
83
|
+
# first (global rank). Sugar over `rank_index` (built on the
|
|
84
|
+
# same sort machinery as `sort_index`); the inverse relationship
|
|
85
|
+
# is `self.order == self.sort_index.sort_index`.
|
|
86
|
+
#
|
|
87
|
+
# `method:` selects how ties are ranked:
|
|
88
|
+
#
|
|
89
|
+
# - `:ordinal` (default) — every cell gets a distinct rank; ties
|
|
90
|
+
# are broken by original position (stable). This is a total
|
|
91
|
+
# order: no two cells ever compare equal.
|
|
92
|
+
# - `:dense` — tied values share one rank (no gaps). Useful as a
|
|
93
|
+
# `sort_addr` priority key: an `:ordinal` key never ties, so a
|
|
94
|
+
# lower-priority key after it is never consulted; a `:dense` key
|
|
95
|
+
# preserves the tie so it is.
|
|
96
|
+
#
|
|
97
|
+
# `descending:` negates the rank order (`(n-1) - rank`, `n` =
|
|
98
|
+
# fiber element count minus masked cells). This composes correctly
|
|
99
|
+
# with `method: :dense`: ties stay tied after the transform, and
|
|
100
|
+
# group-to-group order still reverses.
|
|
101
|
+
#
|
|
102
|
+
# Masked cells are excluded from ranking (own cell becomes UNDEF,
|
|
103
|
+
# like `rank_index`); `descending:`/`method:` apply to the
|
|
104
|
+
# remaining unmasked cells.
|
|
105
|
+
# @param axis [Integer, nil]
|
|
106
|
+
# @param descending [Boolean]
|
|
107
|
+
# @param method [Symbol] `:ordinal` (default) or `:dense`.
|
|
108
|
+
# @return [CArray] `:int64` ranks, shape == `self.shape`.
|
|
109
|
+
# @raise [ArgumentError] when `method:` is neither `:ordinal` nor `:dense`.
|
|
110
|
+
def order(axis: nil, descending: false, method: :ordinal); end
|
|
111
|
+
|
|
112
|
+
# @!endgroup
|
|
113
|
+
|
|
114
|
+
# @!group Sorting and searching
|
|
115
|
+
|
|
116
|
+
# @overload bsearch(val)
|
|
117
|
+
# Returns the flat address of `val` in `self` via binary search.
|
|
118
|
+
# `self` must be sorted along its single (flat) axis. Returns
|
|
119
|
+
# `nil` if `val` is not present. When `val` is a CArray, returns
|
|
120
|
+
# a CArray of `:int64` addresses (one per element of `val`),
|
|
121
|
+
# with `UNDEF` at positions where the value is not present.
|
|
122
|
+
# @param val [Numeric, CArray]
|
|
123
|
+
# @return [Integer, CArray, nil]
|
|
124
|
+
# @raise [RuntimeError] if `self` has any masked element.
|
|
125
|
+
# @overload bsearch(val, axis:)
|
|
126
|
+
# Per-fiber binary search along `axis`. Returns a CArray of
|
|
127
|
+
# axis-local positions, one per fiber.
|
|
128
|
+
# @param val [Numeric, CArray]
|
|
129
|
+
# @param axis [Integer]
|
|
130
|
+
# @return [CArray]
|
|
131
|
+
def bsearch(val, axis: nil); end
|
|
132
|
+
|
|
133
|
+
# @overload bsearch_addr(val)
|
|
134
|
+
# Equivalent to {#bsearch} when `axis:` is omitted (the flat
|
|
135
|
+
# case already returns a flat address).
|
|
136
|
+
# @param val [Numeric, CArray]
|
|
137
|
+
# @return [Integer, CArray, nil]
|
|
138
|
+
# @overload bsearch_addr(val, axis:)
|
|
139
|
+
# Per-fiber binary search along `axis`, returning flat addresses
|
|
140
|
+
# rather than axis-local positions.
|
|
141
|
+
# @param val [Numeric, CArray]
|
|
142
|
+
# @param axis [Integer]
|
|
143
|
+
# @return [CArray]
|
|
144
|
+
def bsearch_addr(val, axis: nil); end
|
|
145
|
+
|
|
146
|
+
# @overload search(val, eps = nil)
|
|
147
|
+
# Returns the flat address of the first element of `self` equal
|
|
148
|
+
# to `val`. For float types, `eps` (default machine epsilon)
|
|
149
|
+
# sets the tolerance. Returns `nil` if no match.
|
|
150
|
+
#
|
|
151
|
+
# `self` need not be sorted; this is a linear scan. For sorted
|
|
152
|
+
# data prefer {#bsearch}.
|
|
153
|
+
# @param val [Object]
|
|
154
|
+
# @param eps [Float, nil]
|
|
155
|
+
# @return [Integer, nil]
|
|
156
|
+
# @overload search(val, eps = nil, axis:)
|
|
157
|
+
# Per-fiber linear search along `axis`. Returns axis-local
|
|
158
|
+
# positions.
|
|
159
|
+
# @return [CArray]
|
|
160
|
+
def search(val, eps = nil, axis: nil); end
|
|
161
|
+
|
|
162
|
+
# @overload search_addr(val, eps = nil)
|
|
163
|
+
# Equivalent to {#search} when `axis:` is omitted.
|
|
164
|
+
# @return [Integer, nil]
|
|
165
|
+
# @overload search_addr(val, eps = nil, axis:)
|
|
166
|
+
# Per-fiber linear search along `axis`, returning flat
|
|
167
|
+
# addresses rather than axis-local positions.
|
|
168
|
+
# @return [CArray]
|
|
169
|
+
def search_addr(val, eps = nil, axis: nil); end
|
|
170
|
+
|
|
171
|
+
# @overload search_nearest(val)
|
|
172
|
+
# Returns the flat address of the element of `self` whose value
|
|
173
|
+
# is closest to `val`. For `:object` arrays, uses
|
|
174
|
+
# `val.distance(other)` to compare.
|
|
175
|
+
# @param val [Object]
|
|
176
|
+
# @return [Integer, nil]
|
|
177
|
+
# @overload search_nearest(val, axis:)
|
|
178
|
+
# Per-fiber nearest-value search along `axis`. Returns
|
|
179
|
+
# axis-local positions.
|
|
180
|
+
# @return [CArray]
|
|
181
|
+
def search_nearest(val, axis: nil); end
|
|
182
|
+
|
|
183
|
+
# @overload search_nearest_addr(val)
|
|
184
|
+
# Equivalent to {#search_nearest} when `axis:` is omitted.
|
|
185
|
+
# @return [Integer, nil]
|
|
186
|
+
# @overload search_nearest_addr(val, axis:)
|
|
187
|
+
# Per-fiber nearest-value search along `axis`, returning flat
|
|
188
|
+
# addresses rather than axis-local positions.
|
|
189
|
+
# @return [CArray]
|
|
190
|
+
def search_nearest_addr(val, axis: nil); end
|
|
191
|
+
|
|
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
|
+
# @!endgroup
|
|
260
|
+
|
|
261
|
+
# @!group Sorting and searching
|
|
262
|
+
|
|
263
|
+
# @overload linear_section(val, axis: nil, method: :binary)
|
|
264
|
+
# Returns the fractional position of `val` within `self` (treated
|
|
265
|
+
# as a coordinate axis), interpolating linearly between the two
|
|
266
|
+
# bracketing samples. The integer part of the returned address is
|
|
267
|
+
# the index of the lower bracket, the fractional part is the
|
|
268
|
+
# interpolation weight toward the next sample. Out-of-range `val`
|
|
269
|
+
# returns NaN.
|
|
270
|
+
#
|
|
271
|
+
# `self` is coerced to `:float64` if it is not already. When
|
|
272
|
+
# `axis: nil`, `self` is flattened to 1-D first.
|
|
273
|
+
#
|
|
274
|
+
# `method:` selects the search backend:
|
|
275
|
+
# - `:binary` (default) — bisection. `O(log N)` per query.
|
|
276
|
+
# Assumes an ascending (sorted) axis; returns NaN on
|
|
277
|
+
# descending data.
|
|
278
|
+
# - `:linear` — sign-product scan. `O(N)` per query but handles
|
|
279
|
+
# both ascending and descending monotone axes correctly.
|
|
280
|
+
#
|
|
281
|
+
# See {#linear_fetch} for the inverse operation (fractional
|
|
282
|
+
# address to interpolated value).
|
|
283
|
+
# @param val [Numeric, CArray]
|
|
284
|
+
# @param axis [Integer, nil]
|
|
285
|
+
# @param method [Symbol] `:binary` or `:linear`.
|
|
286
|
+
# @return [Float, CArray]
|
|
287
|
+
# @raise [ArgumentError] when `method:` is neither `:binary` nor
|
|
288
|
+
# `:linear`.
|
|
289
|
+
def linear_section(val, axis: nil, method: :binary); end
|
|
290
|
+
|
|
291
|
+
# @overload linear_fetch(addr, axis: nil)
|
|
292
|
+
# Returns the value of `self` (treated as a coordinate axis) at
|
|
293
|
+
# the fractional position `addr`, interpolating linearly between
|
|
294
|
+
# the two bracketing samples. The inverse of {#linear_section}.
|
|
295
|
+
#
|
|
296
|
+
# `self` is coerced to `:float64` if it is not already. When
|
|
297
|
+
# `axis: nil`, `self` is flattened to 1-D first.
|
|
298
|
+
#
|
|
299
|
+
# Out-of-range `addr` returns NaN.
|
|
300
|
+
#
|
|
301
|
+
# Because this half of the pair returns a *value* rather than a
|
|
302
|
+
# position, a Face axis gets its Face back: `CATime#linear_fetch` /
|
|
303
|
+
# `CATimedelta#linear_fetch` return a time on the axis's own unit
|
|
304
|
+
# (rounded to that grid, UNDEF out of range) instead of raw ticks.
|
|
305
|
+
# @param addr [Float, CArray] fractional position(s) into `self`.
|
|
306
|
+
# @param axis [Integer, nil]
|
|
307
|
+
# @return [Float, CArray]
|
|
308
|
+
# @see file:docs/topics/LinearInterpolation.md
|
|
309
|
+
def linear_fetch(addr, axis: nil); end
|
|
310
|
+
|
|
311
|
+
# @!endgroup
|
|
312
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_random.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Random
|
|
7
|
+
|
|
8
|
+
# @overload random!(rng: nil)
|
|
9
|
+
# A float array: samples `[0.0, 1.0)`. An integer array: raises
|
|
10
|
+
# (a range is required).
|
|
11
|
+
# @overload random!(high, rng: nil)
|
|
12
|
+
# Samples `[0, high)` (Ruby `rand` / Numo `.rand` shorthand).
|
|
13
|
+
# @overload random!(low, high, rng: nil)
|
|
14
|
+
# Samples `[low, high)` (Numo positional convention).
|
|
15
|
+
# @overload random!(range, rng: nil)
|
|
16
|
+
# Samples from a Ruby Range: `a..b` closed, `a...b` half-open.
|
|
17
|
+
# An integer array honors the endpoint distinction (dice: `1..6`
|
|
18
|
+
# yields values in `1..6` including 6; `1...6` yields `1..5`).
|
|
19
|
+
# For a float array, closed and half-open are equivalent at the
|
|
20
|
+
# sampler level (endpoint probability ≈ 2^-53), matching
|
|
21
|
+
# NumPy/SciPy convention — `..` is accepted for syntax but the
|
|
22
|
+
# endpoint is not enforced at the mantissa.
|
|
23
|
+
#
|
|
24
|
+
# Fills `self` with uniform random numbers in-place and returns
|
|
25
|
+
# `self`. Boolean arrays fill 0/1 at 50% probability, ignoring
|
|
26
|
+
# any range argument. Complex arrays sample real and imaginary
|
|
27
|
+
# parts independently from the same range.
|
|
28
|
+
#
|
|
29
|
+
# @param low [Numeric] lower bound (inclusive).
|
|
30
|
+
# @param high [Numeric] upper bound (exclusive).
|
|
31
|
+
# @param range [Range] closed (`a..b`) or half-open (`a...b`).
|
|
32
|
+
# @param rng [Random, nil] RNG instance; nil uses the per-ractor
|
|
33
|
+
# default RNG.
|
|
34
|
+
# @return [self]
|
|
35
|
+
# @raise [CArray::DataTypeError] for `:object` / `:fixlen` arrays.
|
|
36
|
+
# @raise [ArgumentError] when an integer array is called with no
|
|
37
|
+
# range, when `low >= high`, when a Range is combined with a
|
|
38
|
+
# second positional argument, or when a Range endpoint is nil.
|
|
39
|
+
def random!(*args, rng: nil); end
|
|
40
|
+
|
|
41
|
+
# @overload random(rng: nil)
|
|
42
|
+
# @overload random(high, rng: nil)
|
|
43
|
+
# @overload random(low, high, rng: nil)
|
|
44
|
+
# @overload random(range, rng: nil)
|
|
45
|
+
# Non-bang variant: returns a newly templated array filled by
|
|
46
|
+
# `random!`. Accepts the same argument forms.
|
|
47
|
+
# @return [CArray]
|
|
48
|
+
def random(*args, rng: nil); end
|
|
49
|
+
|
|
50
|
+
# @overload randomn!(rng: nil)
|
|
51
|
+
# Fills `self` with standard normal `N(0, 1)` samples via
|
|
52
|
+
# Box-Muller and returns `self`. Restricted to float / complex
|
|
53
|
+
# data types; complex fills real and imaginary parts as two
|
|
54
|
+
# independent normals per cell.
|
|
55
|
+
# @param rng [Random, nil] RNG instance; nil uses the per-ractor
|
|
56
|
+
# default RNG.
|
|
57
|
+
# @return [self]
|
|
58
|
+
# @raise [CArray::DataTypeError] for non-float / non-complex arrays.
|
|
59
|
+
def randomn!(rng: nil); end
|
|
60
|
+
|
|
61
|
+
# @overload randomn(rng: nil)
|
|
62
|
+
# Non-bang variant: returns a newly templated array filled by
|
|
63
|
+
# `randomn!`.
|
|
64
|
+
# @return [CArray]
|
|
65
|
+
def randomn(rng: nil); end
|
|
66
|
+
|
|
67
|
+
# @!endgroup
|
|
68
|
+
|
|
69
|
+
# @!group Random
|
|
70
|
+
|
|
71
|
+
# @overload shuffle!(axis: nil, rng: nil)
|
|
72
|
+
# Fisher-Yates permutes `self` in-place and returns `self`.
|
|
73
|
+
# Without `axis:`, shuffles all cells as if flattened. With
|
|
74
|
+
# `axis:`, permutes slices along that axis (the trailing
|
|
75
|
+
# sub-slab is treated as a byte chunk and swapped whole).
|
|
76
|
+
# @param axis [Integer, nil] axis to permute along; nil = flat.
|
|
77
|
+
# @param rng [Random, nil] RNG instance; nil uses the per-ractor
|
|
78
|
+
# default RNG.
|
|
79
|
+
# @return [self]
|
|
80
|
+
# @raise [ArgumentError] if `axis` is out of range.
|
|
81
|
+
def shuffle!(axis: nil, rng: nil); end
|
|
82
|
+
|
|
83
|
+
# @overload shuffle(axis: nil, rng: nil)
|
|
84
|
+
# Non-bang variant: returns a shuffled copy of `self`.
|
|
85
|
+
# @return [CArray]
|
|
86
|
+
def shuffle(axis: nil, rng: nil); end
|
|
87
|
+
|
|
88
|
+
# @!endgroup
|
|
89
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_scatter.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Scatter and generation
|
|
7
|
+
#
|
|
8
|
+
# The `scatter_*!` family applies an in-place reduction at each
|
|
9
|
+
# `addrs[i]` position from a paired `vals[i]` (or scalar). The
|
|
10
|
+
# accumulate variants (`scatter_add!` / `scatter_sub!` /
|
|
11
|
+
# `scatter_mul!` / `scatter_min!` / `scatter_max!`) apply duplicate
|
|
12
|
+
# addresses in sequence (unbuffered). {#scatter_replace!} is the
|
|
13
|
+
# last-write variant, equivalent to `self[addrs] = vals` but
|
|
14
|
+
# bypasses the CAGrid view chain.
|
|
15
|
+
#
|
|
16
|
+
# Shared contract:
|
|
17
|
+
#
|
|
18
|
+
# - `addrs` is a CArray of any integer type (coerced to
|
|
19
|
+
# `CA_SIZE`) or a Ruby Array.
|
|
20
|
+
# - `vals` is a CArray of length matching `addrs` (coerced to
|
|
21
|
+
# `self.data_type`), or a Numeric scalar broadcast to all
|
|
22
|
+
# addresses.
|
|
23
|
+
# - Out-of-range `addrs[i]` (`< 0` or `>= self.elements`) raises
|
|
24
|
+
# `IndexError`.
|
|
25
|
+
# - `self.data_type` must be numeric.
|
|
26
|
+
#
|
|
27
|
+
# Mask policy differs between the accumulate family and
|
|
28
|
+
# {#scatter_replace!}: the accumulate variants skip the pair when
|
|
29
|
+
# any of `addrs[i]`, `vals[i]`, or `self[addrs[i]]` is masked (an
|
|
30
|
+
# unknown source can't accumulate). {#scatter_replace!} instead
|
|
31
|
+
# overwrites the target (masked `vals[i]` flips the target to
|
|
32
|
+
# masked, valid `vals[i]` clears the target's mask), matching the
|
|
33
|
+
# `self[addrs] = vals` indexer.
|
|
34
|
+
|
|
35
|
+
# @overload scatter_add!(addrs, vals)
|
|
36
|
+
# For each `i`, applies `self[addrs[i]] += vals[i]`
|
|
37
|
+
# (or `+= vals` if `vals` is scalar). Mutates `self`.
|
|
38
|
+
# @param addrs [CArray, Array<Integer>]
|
|
39
|
+
# @param vals [CArray, Numeric]
|
|
40
|
+
# @return [self]
|
|
41
|
+
# @raise [IndexError] for out-of-range addresses.
|
|
42
|
+
# @raise [CArray::DataTypeError] for non-numeric `data_type`.
|
|
43
|
+
def scatter_add!(addrs, vals); end
|
|
44
|
+
|
|
45
|
+
# @overload scatter_sub!(addrs, vals)
|
|
46
|
+
# For each `i`, applies `self[addrs[i]] -= vals[i]`. Same
|
|
47
|
+
# contract as {#scatter_add!}.
|
|
48
|
+
# @param addrs [CArray, Array<Integer>]
|
|
49
|
+
# @param vals [CArray, Numeric]
|
|
50
|
+
# @return [self]
|
|
51
|
+
def scatter_sub!(addrs, vals); end
|
|
52
|
+
|
|
53
|
+
# @overload scatter_mul!(addrs, vals)
|
|
54
|
+
# For each `i`, applies `self[addrs[i]] *= vals[i]`. Duplicate
|
|
55
|
+
# addresses multiply.
|
|
56
|
+
#
|
|
57
|
+
# NaN/inf follow standard C arithmetic propagation (no
|
|
58
|
+
# `fmin`-style missing-value rule). Integer overflow wraps.
|
|
59
|
+
#
|
|
60
|
+
# Typical uses: Bayesian likelihood patch update, scatter blend,
|
|
61
|
+
# log-domain → linear product, weight composition.
|
|
62
|
+
# @param addrs [CArray, Array<Integer>]
|
|
63
|
+
# @param vals [CArray, Numeric]
|
|
64
|
+
# @return [self]
|
|
65
|
+
def scatter_mul!(addrs, vals); end
|
|
66
|
+
|
|
67
|
+
# @overload scatter_min!(addrs, vals)
|
|
68
|
+
# For each `i`, applies
|
|
69
|
+
# `self[addrs[i]] = min(self[addrs[i]], vals[i])`.
|
|
70
|
+
#
|
|
71
|
+
# For float `data_type`, NaN follows the `fmin` rule (NaN is
|
|
72
|
+
# treated as missing: `min(NaN, v) → v`, `min(x, NaN) → x`).
|
|
73
|
+
# @param addrs [CArray, Array<Integer>]
|
|
74
|
+
# @param vals [CArray, Numeric]
|
|
75
|
+
# @return [self]
|
|
76
|
+
def scatter_min!(addrs, vals); end
|
|
77
|
+
|
|
78
|
+
# @overload scatter_max!(addrs, vals)
|
|
79
|
+
# For each `i`, applies
|
|
80
|
+
# `self[addrs[i]] = max(self[addrs[i]], vals[i])`. For float
|
|
81
|
+
# `data_type`, NaN follows the `fmax` rule.
|
|
82
|
+
# @param addrs [CArray, Array<Integer>]
|
|
83
|
+
# @param vals [CArray, Numeric]
|
|
84
|
+
# @return [self]
|
|
85
|
+
def scatter_max!(addrs, vals); end
|
|
86
|
+
|
|
87
|
+
# @overload scatter_replace!(addrs, vals)
|
|
88
|
+
# For each `i`, applies `self[addrs[i]] = vals[i]` (or `= vals`
|
|
89
|
+
# if scalar). Duplicate addresses resolve to last-write-wins.
|
|
90
|
+
#
|
|
91
|
+
# Semantically equivalent to `self[addrs] = vals` but bypasses
|
|
92
|
+
# the CAGrid view chain (which snapshot-copies `addrs` and
|
|
93
|
+
# allocates view state); useful in hot loops where a scatter
|
|
94
|
+
# result is written back many times.
|
|
95
|
+
#
|
|
96
|
+
# Unlike the arithmetic `scatter_*!` family, `self` may be
|
|
97
|
+
# **boolean** (assignment does not widen), and `true` / `false`
|
|
98
|
+
# are accepted as scalar `vals` alongside numeric scalars.
|
|
99
|
+
#
|
|
100
|
+
# @param addrs [CArray, Array<Integer>]
|
|
101
|
+
# @param vals [CArray, Numeric, true, false]
|
|
102
|
+
# @return [self]
|
|
103
|
+
def scatter_replace!(addrs, vals); end
|
|
104
|
+
|
|
105
|
+
# @!endgroup
|
|
106
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_slab.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
#
|
|
5
|
+
# The slab-iteration family walks `self` in slabs (sub-arrays) taken along
|
|
6
|
+
# a chosen set of axes. See the @see links for the full walkthrough.
|
|
7
|
+
|
|
8
|
+
class CArray
|
|
9
|
+
# @!group Iteration
|
|
10
|
+
|
|
11
|
+
# @overload each_slab(axis:)
|
|
12
|
+
# Yields each slab of `self` (a view along the axes NOT in `axis`) to
|
|
13
|
+
# the block and returns `self`. The slab is a live view valid only
|
|
14
|
+
# for the duration of the block — capturing it across iterations sees
|
|
15
|
+
# the last slab's data.
|
|
16
|
+
# @overload each_slab(axis:)
|
|
17
|
+
# Returns an Enumerator when no block is given.
|
|
18
|
+
# @param axis [Integer, Array<Integer>, nil] the slab axis or axes
|
|
19
|
+
# (`nil` = the whole view as a single slab).
|
|
20
|
+
# @return [self, Enumerator]
|
|
21
|
+
# @see file:docs/SlabIterator.md SlabIterator
|
|
22
|
+
# @see file:docs/drafts/11_slab_iteration.md Slab iteration
|
|
23
|
+
def each_slab(axis:); end
|
|
24
|
+
|
|
25
|
+
# @overload map_slab(axis:, data_type: nil)
|
|
26
|
+
# Returns a new CArray built by replacing each slab of `self` with the
|
|
27
|
+
# block's result. The block receives the slab view and must return a
|
|
28
|
+
# value of the same shape as the slab (a CArray or scalar); the results
|
|
29
|
+
# are written into the output at the same positions.
|
|
30
|
+
# @param axis [Integer, Array<Integer>, nil] the slab axis or axes.
|
|
31
|
+
# @param data_type [Symbol, Integer, Class, nil] output data type
|
|
32
|
+
# (defaults to `self`'s data type).
|
|
33
|
+
# @return [CArray]
|
|
34
|
+
# @raise [ArgumentError] when the block result's shape does not match
|
|
35
|
+
# the slab.
|
|
36
|
+
# @see file:docs/SlabIterator.md SlabIterator
|
|
37
|
+
def map_slab(axis:, data_type: nil); end
|
|
38
|
+
|
|
39
|
+
# @overload reduce_slab(axis:, data_type: nil)
|
|
40
|
+
# Per-slab form (no `init:`): the block receives each slab view and
|
|
41
|
+
# returns a scalar; the scalars fill an output CArray with the slab
|
|
42
|
+
# axes collapsed. Returning a CArray from the block is an error (use
|
|
43
|
+
# `slab[0]`, `slab.sum`, etc. to extract a scalar).
|
|
44
|
+
# @overload reduce_slab(axis:, init:, data_type: nil)
|
|
45
|
+
# Per-element form (`init:` given): the block receives `(acc, x)` for
|
|
46
|
+
# each element of the slab and returns the new accumulator; the final
|
|
47
|
+
# accumulator per slab fills the output.
|
|
48
|
+
# @param axis [Integer, Array<Integer>, nil] the slab axis or axes.
|
|
49
|
+
# @param init [Object] the initial accumulator (selects the
|
|
50
|
+
# per-element form).
|
|
51
|
+
# @param data_type [Symbol, Integer, Class, nil] output data type.
|
|
52
|
+
# @return [CArray] the reduced array (slab axes collapsed).
|
|
53
|
+
# @see file:docs/SlabIterator.md SlabIterator
|
|
54
|
+
def reduce_slab(axis:, init: nil, data_type: nil); end
|
|
55
|
+
|
|
56
|
+
# @!endgroup
|
|
57
|
+
end
|