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,163 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_sort.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Sorting and searching
|
|
7
|
+
|
|
8
|
+
# @overload sort_addr(*keys, masked_position: :last)
|
|
9
|
+
# Returns a 1-D CArray of `:int64` indices that lex-sort `keys`
|
|
10
|
+
# in priority order (`keys[0]` is highest priority,
|
|
11
|
+
# `keys[1]` breaks ties, etc.). All `keys` must share the same
|
|
12
|
+
# element count.
|
|
13
|
+
#
|
|
14
|
+
# Masked cells are an incomparable sentinel clustered at
|
|
15
|
+
# `masked_position:` (`:last`, default, or `:first`), applied
|
|
16
|
+
# uniformly across all `keys`. Ties are broken by original index
|
|
17
|
+
# (stable).
|
|
18
|
+
#
|
|
19
|
+
# @example
|
|
20
|
+
# idx = CArray.sort_addr(a, b, c) # priority: a > b > c
|
|
21
|
+
# a[idx]; b[idx]; c[idx]
|
|
22
|
+
#
|
|
23
|
+
# @param keys [Array<CArray>] one or more CArrays, all of the
|
|
24
|
+
# same element count.
|
|
25
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
26
|
+
# @return [CArray] flat `:int64` indices, shape `[a.elements]`.
|
|
27
|
+
# @raise [ArgumentError] when no key is given or element counts
|
|
28
|
+
# differ.
|
|
29
|
+
def self.sort_addr(*keys, masked_position: :last); end
|
|
30
|
+
|
|
31
|
+
# @overload sort(axis: nil, kind: :quick, masked_position: :last)
|
|
32
|
+
# Returns a `CARemap` view of `self` whose elements are sorted
|
|
33
|
+
# along `axis`. When `axis` is omitted, `self` is first
|
|
34
|
+
# flattened to 1-D and the entire array is sorted (so the
|
|
35
|
+
# result is a 1-D view regardless of `self.ndim`).
|
|
36
|
+
#
|
|
37
|
+
# `kind:` selects the sorting algorithm. Both kinds are stable
|
|
38
|
+
# (tie-broken by fiber-local index); the choice is a
|
|
39
|
+
# performance characteristic only:
|
|
40
|
+
#
|
|
41
|
+
# - `:quick` (default) — portable textbook introsort with
|
|
42
|
+
# mergesort escape. Faster on random data.
|
|
43
|
+
# - `:stable` — portable bottom-up mergesort with insertion
|
|
44
|
+
# pre-pass. Predictable worst case.
|
|
45
|
+
#
|
|
46
|
+
# Masked cells are an incomparable sentinel (the same role NaN
|
|
47
|
+
# plays for float data types): they are excluded from the value
|
|
48
|
+
# comparison and clustered at one end of each fiber.
|
|
49
|
+
# `masked_position:` picks which end (`:last`, default, or
|
|
50
|
+
# `:first`); relative order within the masked cluster is
|
|
51
|
+
# unspecified. Masked cells keep their masked-ness at the
|
|
52
|
+
# clustered position (the `CARemap` gather carries the mask bit
|
|
53
|
+
# through, no separate output-mask step needed).
|
|
54
|
+
#
|
|
55
|
+
# Supports numeric (`i8`..`f64`), `CA_FIXLEN` (via memcmp
|
|
56
|
+
# lexicographic order), and `CA_OBJECT` (via `<=>` per pair) --
|
|
57
|
+
# all through the same view path, `masked_position:` included.
|
|
58
|
+
# @param axis [Integer, nil]
|
|
59
|
+
# @param kind [Symbol] `:quick` or `:stable`.
|
|
60
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
61
|
+
# @return [CArray] sorted view.
|
|
62
|
+
def sort(axis: nil, kind: :quick, masked_position: :last); end
|
|
63
|
+
|
|
64
|
+
# @overload sort_copy(axis: nil, kind: :quick, masked_position: :last)
|
|
65
|
+
# Eager-copy counterpart of {#sort}: returns a fresh entity
|
|
66
|
+
# CArray with the same shape and `data_type` as `self`, sorted
|
|
67
|
+
# along `axis`. Use this when you want an independent array
|
|
68
|
+
# rather than a view.
|
|
69
|
+
#
|
|
70
|
+
# Unmasked numeric paths use a per-fiber gather + sort +
|
|
71
|
+
# scatter, bypassing the `CARemap` scatter layer that `sort`
|
|
72
|
+
# uses. `CA_FIXLEN` and masked input both materialize the
|
|
73
|
+
# `sort` view instead (same shape, ordering, and
|
|
74
|
+
# `masked_position:` semantics as {#sort}).
|
|
75
|
+
# @param axis [Integer, nil]
|
|
76
|
+
# @param kind [Symbol] `:quick` or `:stable`.
|
|
77
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
78
|
+
# @return [CArray]
|
|
79
|
+
def sort_copy(axis: nil, kind: :quick, masked_position: :last); end
|
|
80
|
+
|
|
81
|
+
# @overload sort_addr(axis: nil, kind: :quick, masked_position: :last)
|
|
82
|
+
# Returns view-flat addresses that index a sort.
|
|
83
|
+
#
|
|
84
|
+
# - With no kwarg (`a.sort_addr`): returns a CArray of `:int64`
|
|
85
|
+
# flat addresses shaped like `self` (NOT flattened -- the
|
|
86
|
+
# legacy 1-key case of `CArray.sort_addr`'s multi-key lex
|
|
87
|
+
# sort). `kind:` has no effect on this form.
|
|
88
|
+
# - With `axis:` (e.g. `a.sort_addr(axis: 0)`): returns
|
|
89
|
+
# per-fiber view-flat addresses along the given axis, output
|
|
90
|
+
# shape == `self.shape`.
|
|
91
|
+
#
|
|
92
|
+
# `kind:` selects the sort algorithm for the `axis:` path:
|
|
93
|
+
#
|
|
94
|
+
# - `:quick` (default) — introsort with mergesort escape.
|
|
95
|
+
# - `:stable` — bottom-up mergesort.
|
|
96
|
+
#
|
|
97
|
+
# Both kinds are algorithmically stable (pair sort with index
|
|
98
|
+
# tie-break); `kind:` chooses the performance characteristic.
|
|
99
|
+
#
|
|
100
|
+
# `masked_position:` (`:last` default, or `:first`) picks which
|
|
101
|
+
# end masked cells cluster to. Effective on both forms: the
|
|
102
|
+
# `axis:` path forwards to the `sort`/`sort_index` kernel family;
|
|
103
|
+
# the no-`axis:` path forwards to `CArray.sort_addr`'s own
|
|
104
|
+
# masked-position-aware comparator.
|
|
105
|
+
#
|
|
106
|
+
# Companion of {#axis2addr} (axis-local indices to view-flat
|
|
107
|
+
# addresses) and {#sort} (the view counterpart).
|
|
108
|
+
# @param axis [Integer, nil]
|
|
109
|
+
# @param kind [Symbol] `:quick` or `:stable`.
|
|
110
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
111
|
+
# @return [CArray] `:int64` addresses.
|
|
112
|
+
# @raise [ArgumentError] when `kind:` is neither `:quick` nor
|
|
113
|
+
# `:stable`.
|
|
114
|
+
def sort_addr(axis: nil, kind: :quick, masked_position: :last); end
|
|
115
|
+
|
|
116
|
+
# @!group Index and address conversion
|
|
117
|
+
|
|
118
|
+
# @overload axis2addr(indices, axis: 0)
|
|
119
|
+
# Converts per-fiber axis-local indices into row-major
|
|
120
|
+
# view-flat addresses into `self`. For each cell at coord
|
|
121
|
+
# `c = (c_0, ..., c_(n-1))` in `indices`:
|
|
122
|
+
#
|
|
123
|
+
# addr[c] = sum over `j != axis` of c_j * stride_j +
|
|
124
|
+
# indices[c] * stride_axis
|
|
125
|
+
#
|
|
126
|
+
# where strides are row-major over `self.shape`.
|
|
127
|
+
#
|
|
128
|
+
# Canonical converter between the two axis-position
|
|
129
|
+
# representations the `*_index` / `*_addr` kernel families
|
|
130
|
+
# produce:
|
|
131
|
+
#
|
|
132
|
+
# @example
|
|
133
|
+
# a.min_index(axis: k) # axis-local scalar per fiber
|
|
134
|
+
# a.min_addr(axis: k) # view-flat address per fiber
|
|
135
|
+
# flat = key.axis2addr(key.min_index(axis: k), axis: k)
|
|
136
|
+
# # flat == key.min_addr(axis: k)
|
|
137
|
+
#
|
|
138
|
+
# Sits underneath `#take_along_axis`: the heavy "axis-local
|
|
139
|
+
# -> view-flat" arithmetic lives here, and `take_along_axis`
|
|
140
|
+
# is a one-liner on top of `flatten[axis2addr(...)]`.
|
|
141
|
+
#
|
|
142
|
+
# Shape rule: `indices.ndim == self.ndim`, and
|
|
143
|
+
# `indices.dim[j] == self.dim[j]` for all `j != axis`;
|
|
144
|
+
# `indices.dim[axis]` is free.
|
|
145
|
+
#
|
|
146
|
+
# `indices` data_type: any integer kind (zero-copy when
|
|
147
|
+
# already `:int64`). Negative indices: Python-style
|
|
148
|
+
# (`-1` == last). Out-of-range indices raise `RangeError`.
|
|
149
|
+
# Negative `axis:` is Python-style.
|
|
150
|
+
#
|
|
151
|
+
# @param indices [CArray] integer-typed axis-local positions.
|
|
152
|
+
# @param axis [Integer] axis along which `indices` are
|
|
153
|
+
# interpreted.
|
|
154
|
+
# @return [CArray] `:int64` view-flat addresses, same shape as
|
|
155
|
+
# `indices`.
|
|
156
|
+
# @raise [RangeError] when an index is out of range after
|
|
157
|
+
# negative normalization.
|
|
158
|
+
# @raise [ArgumentError] for shape / ndim / data_type
|
|
159
|
+
# violations.
|
|
160
|
+
def axis2addr(indices, axis: 0); end
|
|
161
|
+
|
|
162
|
+
# @!endgroup
|
|
163
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_test.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Index and address conversion
|
|
7
|
+
|
|
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`.
|
|
11
|
+
# @param idx [Array<Integer>] one index per axis.
|
|
12
|
+
# @return [Boolean]
|
|
13
|
+
# @raise [ArgumentError] if the number of indices does not match
|
|
14
|
+
# `ndim`.
|
|
15
|
+
def valid_index?(*idx); end
|
|
16
|
+
|
|
17
|
+
# @overload valid_addr?(addr)
|
|
18
|
+
# Returns `true` if `addr` is in range `0...elements` for `self`.
|
|
19
|
+
# @param addr [Integer] flat address into the contiguous element
|
|
20
|
+
# sequence.
|
|
21
|
+
# @return [Boolean]
|
|
22
|
+
def valid_addr?(addr); end
|
|
23
|
+
|
|
24
|
+
# @overload same_shape?(other)
|
|
25
|
+
# Returns `true` if `other` has the same shape as `self`.
|
|
26
|
+
# @param other [CArray]
|
|
27
|
+
# @return [Boolean]
|
|
28
|
+
def same_shape?(other); end
|
|
29
|
+
|
|
30
|
+
# @!endgroup
|
|
31
|
+
|
|
32
|
+
# @!group Equality and hashing
|
|
33
|
+
|
|
34
|
+
# @overload ==(other)
|
|
35
|
+
# Returns `true` if `other` is a CArray with the same shape,
|
|
36
|
+
# `data_class`, `data_type`, mask state, and elementwise values as
|
|
37
|
+
# `self`. NaN values compare unequal (IEEE semantics), so two
|
|
38
|
+
# arrays with NaN at the same position are not `==`.
|
|
39
|
+
# @param other [Object]
|
|
40
|
+
# @return [Boolean]
|
|
41
|
+
def ==(other); end
|
|
42
|
+
|
|
43
|
+
# @overload eql?(other)
|
|
44
|
+
# Returns `true` under Hash-invariant semantics: `data_class`,
|
|
45
|
+
# `data_type`, shape, and mask state must all match, and elements
|
|
46
|
+
# are compared bitwise (for numeric types) or via `Object#eql?`
|
|
47
|
+
# (for `:object` arrays). Unlike `==`, `NaN.eql?(NaN)` holds, so
|
|
48
|
+
# two mask-free arrays with NaN at the same positions are `eql?`.
|
|
49
|
+
#
|
|
50
|
+
# Guarantees `a.eql?(b)` ⇒ `a.hash == b.hash`.
|
|
51
|
+
# @param other [Object]
|
|
52
|
+
# @return [Boolean]
|
|
53
|
+
def eql?(other); end
|
|
54
|
+
|
|
55
|
+
# @overload hash
|
|
56
|
+
# Returns the Hash key value for `self`. Mixes `data_type`,
|
|
57
|
+
# `ndim`, `bytes`, `elements`, shape, scalar-ness, and mask
|
|
58
|
+
# presence; for unmasked arrays, samples the leading 64 bytes of
|
|
59
|
+
# data. Masked arrays skip the data sample.
|
|
60
|
+
# @return [Integer]
|
|
61
|
+
def hash; end
|
|
62
|
+
|
|
63
|
+
# @!endgroup
|
|
64
|
+
|
|
65
|
+
# @!group Equality and hashing
|
|
66
|
+
|
|
67
|
+
# @overload freeze
|
|
68
|
+
# Freezes `self` and marks it read-only. Subsequent mutations
|
|
69
|
+
# raise `FrozenError`.
|
|
70
|
+
# @return [self]
|
|
71
|
+
def freeze; end
|
|
72
|
+
|
|
73
|
+
# @overload set_read_only_flag
|
|
74
|
+
# Marks `self` read-only (sets `CA_FLAG_READ_ONLY`) without
|
|
75
|
+
# freezing the Ruby object, so subsequent mutations raise
|
|
76
|
+
# `RuntimeError` while `frozen?` stays false and views / Faces
|
|
77
|
+
# derived from `self` can still memoise. One-way: there is no
|
|
78
|
+
# method to clear the flag. Use `#copy` for a writable copy (a
|
|
79
|
+
# copy does not inherit the flag). Contrast `#freeze`, which also
|
|
80
|
+
# freezes the Ruby object.
|
|
81
|
+
# @return [self]
|
|
82
|
+
def set_read_only_flag; end
|
|
83
|
+
|
|
84
|
+
# @!endgroup
|
|
85
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for the UNDEF sentinel and UndefClass defined in
|
|
3
|
+
# ext/carray_undef.c. See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Singleton class of the {UNDEF} sentinel value. Not instantiable
|
|
6
|
+
# (`UndefClass.new` is undef'd after the single instance is created
|
|
7
|
+
# in `Init_carray_undef`).
|
|
8
|
+
#
|
|
9
|
+
# The class is private API in practice: read and write the sentinel
|
|
10
|
+
# through the top-level `UNDEF` constant rather than touching the
|
|
11
|
+
# class directly.
|
|
12
|
+
class UndefClass
|
|
13
|
+
# @overload inspect
|
|
14
|
+
# Returns the literal string `"UNDEF"`.
|
|
15
|
+
# @return [String]
|
|
16
|
+
def inspect; end
|
|
17
|
+
|
|
18
|
+
# @overload to_s
|
|
19
|
+
# Returns the literal string `"UNDEF"`. Display works (so
|
|
20
|
+
# `puts UNDEF` shows `"UNDEF"`); numeric coercion via {#to_f}
|
|
21
|
+
# / {#to_i} raises.
|
|
22
|
+
# @return [String]
|
|
23
|
+
def to_s; end
|
|
24
|
+
|
|
25
|
+
# @overload to_f
|
|
26
|
+
# Raises `TypeError`. Numeric coercion of UNDEF is rejected so
|
|
27
|
+
# that accidental arithmetic on a masked sentinel surfaces as an
|
|
28
|
+
# error rather than silently producing `0.0` / `NaN`.
|
|
29
|
+
# @raise [TypeError]
|
|
30
|
+
def to_f; end
|
|
31
|
+
|
|
32
|
+
# @overload to_i
|
|
33
|
+
# Raises `TypeError`. Same rationale as {#to_f}.
|
|
34
|
+
# @raise [TypeError]
|
|
35
|
+
def to_i; end
|
|
36
|
+
|
|
37
|
+
# @overload to_int
|
|
38
|
+
# Alias of {#to_i}. Raises `TypeError`.
|
|
39
|
+
# @raise [TypeError]
|
|
40
|
+
def to_int; end
|
|
41
|
+
|
|
42
|
+
# @overload ==(other)
|
|
43
|
+
# Returns `true` only when `other` is the same UNDEF singleton
|
|
44
|
+
# (identity comparison). No coercion or value equality.
|
|
45
|
+
# @param other [Object]
|
|
46
|
+
# @return [Boolean]
|
|
47
|
+
def ==(other); end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Top-level sentinel used by mask-bearing CArray APIs to mean
|
|
51
|
+
# "masked / no value here" without choosing a numeric sentinel
|
|
52
|
+
# (NaN, `-1`, etc.) that might collide with valid data.
|
|
53
|
+
#
|
|
54
|
+
# Identity semantics: every reference to `UNDEF` is the same Ruby
|
|
55
|
+
# object, pinned against the compacting GC so the C extension can
|
|
56
|
+
# safely use raw pointer comparison to detect it.
|
|
57
|
+
#
|
|
58
|
+
# @example mask a cell during construction
|
|
59
|
+
# a = CArray.int32(3) { |i| (i == 1) ? UNDEF : i * 10 }
|
|
60
|
+
# a.to_a # => [0, nil, 20] # UNDEF surfaces as nil after to_a
|
|
61
|
+
#
|
|
62
|
+
# @example check whether an element is masked
|
|
63
|
+
# a[1] == UNDEF # => true
|
|
64
|
+
UNDEF = UndefClass.new
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_utils.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Index and address conversion
|
|
7
|
+
|
|
8
|
+
# @overload normalize_axis(axis, name = nil)
|
|
9
|
+
# Returns the canonical non-negative integer axis index in
|
|
10
|
+
# `[0, ndim)` for `self`. Accepts Python-style negative indices
|
|
11
|
+
# (`-1` ⇒ `ndim-1`).
|
|
12
|
+
# @param axis [Integer] axis index, possibly negative.
|
|
13
|
+
# @param name [String, nil] argument name to embed in error
|
|
14
|
+
# messages (e.g. `"axis"`, `"at"`).
|
|
15
|
+
# @return [Integer]
|
|
16
|
+
# @raise [ArgumentError] if `axis` is outside `[-ndim, ndim)`.
|
|
17
|
+
def normalize_axis(axis, name = nil); end
|
|
18
|
+
|
|
19
|
+
# @overload normalize_axes(axes, name = nil)
|
|
20
|
+
# Returns an Array of canonical non-negative axis indices in
|
|
21
|
+
# input order. Accepts:
|
|
22
|
+
#
|
|
23
|
+
# - `nil` ⇒ all axes `[0, 1, ..., ndim-1]`
|
|
24
|
+
# - `Integer` ⇒ `[normalize_axis(axis)]`
|
|
25
|
+
# - `Array<Integer>` ⇒ each normalized, preserving input order
|
|
26
|
+
#
|
|
27
|
+
# @param axes [Integer, Array<Integer>, nil]
|
|
28
|
+
# @param name [String, nil] argument name for error messages.
|
|
29
|
+
# @return [Array<Integer>]
|
|
30
|
+
# @raise [ArgumentError] on out-of-range or duplicate axes.
|
|
31
|
+
def normalize_axes(axes, name = nil); end
|
|
32
|
+
|
|
33
|
+
# @!endgroup
|
|
34
|
+
|
|
35
|
+
class << self
|
|
36
|
+
# @!group Index and address conversion
|
|
37
|
+
|
|
38
|
+
# @overload normalize_axis(axis, ndim, name = nil)
|
|
39
|
+
# Class-method form of {CArray#normalize_axis} that operates on
|
|
40
|
+
# an explicit `ndim` rather than a CArray instance. Range is
|
|
41
|
+
# `[0, ndim)`.
|
|
42
|
+
#
|
|
43
|
+
# For an insertion position (valid range `[0, old_ndim]`
|
|
44
|
+
# inclusive), pass `old_ndim + 1` as `ndim`. Used by class-level
|
|
45
|
+
# callers such as `CArray.stack(list, axis:)` that must
|
|
46
|
+
# normalize before any instance is available, and by
|
|
47
|
+
# composition helpers in `lib/carray/compose.rb`.
|
|
48
|
+
# @param axis [Integer]
|
|
49
|
+
# @param ndim [Integer]
|
|
50
|
+
# @param name [String, nil]
|
|
51
|
+
# @return [Integer]
|
|
52
|
+
def normalize_axis(axis, ndim, name = nil); end
|
|
53
|
+
|
|
54
|
+
# @!endgroup
|
|
55
|
+
|
|
56
|
+
# @!group Type guessing
|
|
57
|
+
|
|
58
|
+
# @overload guess_type_and_bytes(type_spec, bytes = nil)
|
|
59
|
+
# Resolves a user-supplied type spec into the pair
|
|
60
|
+
# `[data_type_code, bytes]`. `data_type_code` is the internal
|
|
61
|
+
# `int8_t` numeric code (see {CArray.data_type_code}); `bytes`
|
|
62
|
+
# is the per-element byte size (`0` for non-`:fixlen`).
|
|
63
|
+
# @param type_spec [Symbol, Integer, Class, String]
|
|
64
|
+
# @param bytes [Integer, nil] element byte size, used only for
|
|
65
|
+
# `:fixlen`.
|
|
66
|
+
# @return [Array(Integer, Integer)]
|
|
67
|
+
def guess_type_and_bytes(type_spec, bytes = nil); end
|
|
68
|
+
|
|
69
|
+
# @!endgroup
|
|
70
|
+
|
|
71
|
+
# @!group String scanning (internal)
|
|
72
|
+
|
|
73
|
+
# @overload _scan_float(str, fill_value = nil)
|
|
74
|
+
# Parses `str` as a single double-precision float. Returns
|
|
75
|
+
# `fill_value` (or `NaN` if `fill_value` is nil) when `str` is
|
|
76
|
+
# `nil` or unparseable. Internal helper used by text-format I/O
|
|
77
|
+
# readers; end users should prefer Ruby's `Float()` /
|
|
78
|
+
# `String#to_f`.
|
|
79
|
+
# @param str [String, nil]
|
|
80
|
+
# @param fill_value [Float, nil]
|
|
81
|
+
# @return [Float]
|
|
82
|
+
# @api private
|
|
83
|
+
def _scan_float(str, fill_value = nil); end
|
|
84
|
+
|
|
85
|
+
# @overload _scan_int(str, fill_value = nil)
|
|
86
|
+
# Parses `str` as a single integer. Returns `fill_value`
|
|
87
|
+
# (or `0` if `fill_value` is nil) when `str` is `nil` or
|
|
88
|
+
# unparseable. Internal helper used by text-format I/O readers.
|
|
89
|
+
# @param str [String, nil]
|
|
90
|
+
# @param fill_value [Integer, nil]
|
|
91
|
+
# @return [Integer]
|
|
92
|
+
# @api private
|
|
93
|
+
def _scan_int(str, fill_value = nil); end
|
|
94
|
+
|
|
95
|
+
# @!endgroup
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for class hierarchy and constants declared in
|
|
3
|
+
# ext/ruby_carray.c. See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Multi-dimensional numeric array.
|
|
6
|
+
#
|
|
7
|
+
# See `docs/Tutorial.md` for a guided tour, the per-topic guides under
|
|
8
|
+
# `docs/guides/`, and the method index below for the full reference.
|
|
9
|
+
class CArray < Object
|
|
10
|
+
# Library semantic version, e.g. `"3.0.0.dev"`.
|
|
11
|
+
VERSION = ""
|
|
12
|
+
|
|
13
|
+
# Sentinel marking "the caller did not give this argument", used by
|
|
14
|
+
# C entry points whose fill value may legitimately be `nil` (so `nil`
|
|
15
|
+
# itself cannot mark absence). Never pass it in.
|
|
16
|
+
# @api private
|
|
17
|
+
UNSPECIFIED = nil
|
|
18
|
+
|
|
19
|
+
# `true` when the build links `<complex.h>`; `false` otherwise.
|
|
20
|
+
# Complex array types (`:cmplx64`, `:cmplx128`) require this to be
|
|
21
|
+
# `true`.
|
|
22
|
+
HAVE_COMPLEX = nil
|
|
23
|
+
|
|
24
|
+
# Raised when a method is invoked on a CArray whose `data_type` is
|
|
25
|
+
# incompatible with the operation (e.g. binary I/O on `:object`,
|
|
26
|
+
# quickselect on `:fixlen`).
|
|
27
|
+
class DataTypeError < StandardError
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Untyped external-memory wrapper. Created via
|
|
32
|
+
# {CArray.wrap_memory_view} for zero-copy interop with NumPy / Numo /
|
|
33
|
+
# Arrow.
|
|
34
|
+
class CAWrap < CArray
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Zero-dimensional CArray. One element, broadcasts like a scalar in
|
|
38
|
+
# elementwise ops.
|
|
39
|
+
class CScalar < CArray
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Base class of all virtual (view) CArrays. Has a `parent` and an
|
|
43
|
+
# `attach` lifecycle; `entity? == false`.
|
|
44
|
+
class CAView < CArray
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# General strided view. Common base for views expressible as
|
|
48
|
+
# `parent.ptr + base_offset + Σ idx[k] * strides[k]`.
|
|
49
|
+
class CAStride < CAView
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# `CArray#reshape` / `CArray#flatten` view. Also used for type or
|
|
53
|
+
# byte-size reinterpretation.
|
|
54
|
+
class CARefer < CAStride
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Rectangular slice / sub-array view (`a[r1, r2, ...]`).
|
|
58
|
+
class CABlock < CAStride
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Member-of-fixlen view (`a.field(offset, type)`).
|
|
62
|
+
class CAField < CAStride
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Boolean / fancy-index gather view.
|
|
66
|
+
class CASelect < CAView
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Per-element Ruby callback bridge view.
|
|
70
|
+
class CAObject < CAView
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Repeat-broadcast view (`a.repeat(n0, n1, ...)`).
|
|
74
|
+
class CARepeat < CAStride
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Ragged concatenation view (`CArray.meld(*arrays, axis:)`). Welds
|
|
78
|
+
# K parents along one of their existing axes with (potentially) uneven
|
|
79
|
+
# segment lengths. Prefix-sum table {#seg_offsets} keeps segment
|
|
80
|
+
# boundaries explicit so segment resolution stays per-segment rather
|
|
81
|
+
# than per-cell. Ruby entry: {CArray.meld} / {CArray#meld}
|
|
82
|
+
# (`lib/carray/stack.rb`).
|
|
83
|
+
#
|
|
84
|
+
# See `docs/objects/CAMeld.md` for the user-facing overview.
|
|
85
|
+
class CAMeld < CAView
|
|
86
|
+
# Returns the number of parent arrays welded by `self`.
|
|
87
|
+
# @return [Integer]
|
|
88
|
+
def n_parents; end
|
|
89
|
+
|
|
90
|
+
# Returns the parent arrays welded by `self`. The Array holds
|
|
91
|
+
# references to the constructor's inputs; identity is preserved.
|
|
92
|
+
# @return [Array<CArray>]
|
|
93
|
+
def parents; end
|
|
94
|
+
|
|
95
|
+
# Returns the axis along which the parents are welded (the
|
|
96
|
+
# ragged axis). Non-meld axes have uniform length across parents.
|
|
97
|
+
# @return [Integer] in `[0, ndim)`.
|
|
98
|
+
def meld_axis; end
|
|
99
|
+
|
|
100
|
+
# Returns the prefix-sum offsets along {#meld_axis}. Length
|
|
101
|
+
# `n_parents + 1`; `seg_offsets[k]` is the starting position of
|
|
102
|
+
# parent `k` in the view, and `seg_offsets[n_parents]` equals
|
|
103
|
+
# `shape[meld_axis]`.
|
|
104
|
+
# @return [Array<Integer>]
|
|
105
|
+
# @example
|
|
106
|
+
# a = CArray.int32(3, 4) { 0 }
|
|
107
|
+
# b = CArray.int32(5, 4) { 0 }
|
|
108
|
+
# c = CArray.int32(1, 4) { 0 }
|
|
109
|
+
# CArray.meld(a, b, c, axis: 0).seg_offsets # => [0, 3, 8, 9]
|
|
110
|
+
def seg_offsets; end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Namespace for CArray utility module functions.
|
|
114
|
+
module CA
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# --- Top-level constants (defined on Object in ext/ruby_carray.c) ---
|
|
118
|
+
|
|
119
|
+
# Maximum supported `ndim`.
|
|
120
|
+
CA_RANK_MAX = nil
|
|
121
|
+
|
|
122
|
+
# @!group Data type symbols
|
|
123
|
+
#
|
|
124
|
+
# Each constant is a `Symbol` matching the canonical `data_type`
|
|
125
|
+
# name. Aliases share Symbol identity with their canonical form
|
|
126
|
+
# (e.g. `CA_DOUBLE == CA_FLOAT64` via Symbol equality).
|
|
127
|
+
|
|
128
|
+
# `:fixlen` — fixed-length opaque byte blob; element byte size set
|
|
129
|
+
# per array.
|
|
130
|
+
CA_FIXLEN = :fixlen
|
|
131
|
+
# `:boolean` — 8-bit boolean.
|
|
132
|
+
CA_BOOLEAN = :boolean
|
|
133
|
+
# `:int8` — signed 8-bit integer.
|
|
134
|
+
CA_INT8 = :int8
|
|
135
|
+
# `:uint8` — unsigned 8-bit integer.
|
|
136
|
+
CA_UINT8 = :uint8
|
|
137
|
+
# `:int16` — signed 16-bit integer.
|
|
138
|
+
CA_INT16 = :int16
|
|
139
|
+
# `:uint16` — unsigned 16-bit integer.
|
|
140
|
+
CA_UINT16 = :uint16
|
|
141
|
+
# `:int32` — signed 32-bit integer.
|
|
142
|
+
CA_INT32 = :int32
|
|
143
|
+
# `:uint32` — unsigned 32-bit integer.
|
|
144
|
+
CA_UINT32 = :uint32
|
|
145
|
+
# `:int64` — signed 64-bit integer.
|
|
146
|
+
CA_INT64 = :int64
|
|
147
|
+
# `:uint64` — unsigned 64-bit integer.
|
|
148
|
+
CA_UINT64 = :uint64
|
|
149
|
+
# `:float32` — IEEE-754 single-precision float.
|
|
150
|
+
CA_FLOAT32 = :float32
|
|
151
|
+
# `:float64` — IEEE-754 double-precision float.
|
|
152
|
+
CA_FLOAT64 = :float64
|
|
153
|
+
# `:cmplx64` — single-precision complex (two `float32` packed).
|
|
154
|
+
CA_CMPLX64 = :cmplx64
|
|
155
|
+
# `:cmplx128` — double-precision complex.
|
|
156
|
+
CA_CMPLX128 = :cmplx128
|
|
157
|
+
# `:object` — boxed Ruby object slot.
|
|
158
|
+
CA_OBJECT = :object
|
|
159
|
+
|
|
160
|
+
# Alias of {CA_UINT8}.
|
|
161
|
+
CA_BYTE = :uint8
|
|
162
|
+
# Alias of {CA_INT16}.
|
|
163
|
+
CA_SHORT = :int16
|
|
164
|
+
# Alias of {CA_INT32}.
|
|
165
|
+
CA_INT = :int32
|
|
166
|
+
# Alias of {CA_FLOAT32}.
|
|
167
|
+
CA_FLOAT = :float32
|
|
168
|
+
# Alias of {CA_FLOAT64}.
|
|
169
|
+
CA_DOUBLE = :float64
|
|
170
|
+
# Alias of {CA_CMPLX64}.
|
|
171
|
+
CA_COMPLEX = :cmplx64
|
|
172
|
+
# Alias of {CA_DCOMPLEX}.
|
|
173
|
+
CA_DCOMPLEX = :cmplx128
|
|
174
|
+
# Platform-native size type alias; resolves to `:int64` on 64-bit
|
|
175
|
+
# builds and `:int32` on 32-bit builds.
|
|
176
|
+
CA_SIZE = :int64
|
|
177
|
+
|
|
178
|
+
# @!endgroup
|
|
179
|
+
|
|
180
|
+
# Byte alignment of each element type, used by `CArray.wrap` and
|
|
181
|
+
# MemoryView interop helpers. Internal, not part of the user surface.
|
|
182
|
+
CA_ALIGN_VOIDP = nil # :nodoc:
|
|
183
|
+
CA_ALIGN_FIXLEN = nil # :nodoc:
|
|
184
|
+
CA_ALIGN_BOOLEAN = nil # :nodoc:
|
|
185
|
+
CA_ALIGN_INT8 = nil # :nodoc:
|
|
186
|
+
CA_ALIGN_INT16 = nil # :nodoc:
|
|
187
|
+
CA_ALIGN_INT32 = nil # :nodoc:
|
|
188
|
+
CA_ALIGN_INT64 = nil # :nodoc:
|
|
189
|
+
CA_ALIGN_FLOAT32 = nil # :nodoc:
|
|
190
|
+
CA_ALIGN_FLOAT64 = nil # :nodoc:
|
|
191
|
+
CA_ALIGN_CMPLX64 = nil # :nodoc:
|
|
192
|
+
CA_ALIGN_CMPLX128 = nil # :nodoc:
|
|
193
|
+
CA_ALIGN_OBJECT = nil # :nodoc:
|