carray 3.0.7 → 3.1.0
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 +1 -1
- data/CHANGELOG.md +7 -1940
- data/README.md +38 -32
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1506
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +5 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +12 -12
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +4 -3
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +7 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +5 -3
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +157 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +67 -34
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25337
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -262
- data/lib/carray/data_type_limits.rb +0 -91
data/yard-stubs/carray_order.rb
CHANGED
|
@@ -5,27 +5,29 @@
|
|
|
5
5
|
class CArray
|
|
6
6
|
# @!group Sorting and searching
|
|
7
7
|
|
|
8
|
-
# @overload project(idx,
|
|
8
|
+
# @overload project(idx, fill_value: nil, lfill: nil, ufill: nil)
|
|
9
9
|
# Returns a new array whose elements are taken from `self` at
|
|
10
10
|
# the positions named by `idx`. `idx` is a CArray of flat
|
|
11
11
|
# addresses into `self`; the result has the shape of `idx`.
|
|
12
12
|
#
|
|
13
|
-
# Out-of-range positions are filled with `
|
|
14
|
-
# `
|
|
15
|
-
#
|
|
16
|
-
#
|
|
13
|
+
# Out-of-range positions are filled with `lfill` (below-range) and
|
|
14
|
+
# `ufill` (above-range), each defaulting to `fill_value`. Without a
|
|
15
|
+
# fill, out-of-range positions are masked, and so they are with a
|
|
16
|
+
# fill of `UNDEF`.
|
|
17
17
|
#
|
|
18
18
|
# When `self` is a Face (CATime / CATimedelta / CACategorical),
|
|
19
19
|
# the result is the same Face type, carrying the unit / labels, and a
|
|
20
20
|
# fill is one of its values (a time for a CATime).
|
|
21
21
|
# @param idx [CArray] flat addresses, of any shape.
|
|
22
|
-
# @param
|
|
23
|
-
# @param
|
|
22
|
+
# @param fill_value [Object, nil] fill for out-of-range indices at both ends.
|
|
23
|
+
# @param lfill [Object, nil] fill for indices `< 0`.
|
|
24
|
+
# @param ufill [Object, nil] fill for indices `>= self.elements`.
|
|
24
25
|
# @return [CArray] a fresh array shaped like `idx`; a Face of the same
|
|
25
26
|
# type when `self` is a Face.
|
|
26
|
-
# @raise [ArgumentError]
|
|
27
|
+
# @raise [ArgumentError] for a fill a Face can not hold (a label a
|
|
28
|
+
# categorical does not have).
|
|
27
29
|
# @raise [IndexError] when `idx` is float, complex, object or boolean.
|
|
28
|
-
def project(idx,
|
|
30
|
+
def project(idx, fill_value: nil, lfill: nil, ufill: nil); end
|
|
29
31
|
|
|
30
32
|
# sort / sort_copy stubs live in yard-stubs/carray_sort.rb (same
|
|
31
33
|
# file split as ext/carray_sort.c <-> ext/carray_order.c).
|
|
@@ -87,12 +89,29 @@ class CArray
|
|
|
87
89
|
# is not orderable by its storage.
|
|
88
90
|
def partition_copy(kth, axis: nil, masked_position: :last); end
|
|
89
91
|
|
|
90
|
-
# @overload
|
|
92
|
+
# @overload partition_index(kth, axis: nil, masked_position: :last)
|
|
93
|
+
# Returns the positions that partition `self` around `kth`: an
|
|
94
|
+
# int64 `CArray` shaped like `self` (1-D when `axis` is `nil`).
|
|
95
|
+
# Reading the fibers of `self` at these positions gives what
|
|
96
|
+
# {#partition} returns, so for a 1-D array `a[a.partition_index(k)]`
|
|
97
|
+
# is `a.partition(k)`.
|
|
98
|
+
#
|
|
99
|
+
# `kth`, `axis`, masked cells and the data types taken are as in
|
|
100
|
+
# {#partition}.
|
|
101
|
+
# @param kth [Integer] target fiber-local position along `axis`.
|
|
102
|
+
# @param axis [Integer, nil] `nil` partitions the whole array.
|
|
103
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
104
|
+
# @return [CArray] `:int64` positions within each fiber.
|
|
105
|
+
# @raise [ArgumentError] when `kth` is out of range.
|
|
106
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
107
|
+
def partition_index(kth, axis: nil, masked_position: :last); end
|
|
108
|
+
|
|
109
|
+
# @overload rank_index(axis: nil, descending: false, method: :ordinal, kind: :quick)
|
|
91
110
|
# Returns each cell's rank among the other cells along `axis`
|
|
92
111
|
# (`0` = smallest). When `axis` is omitted, `self` is flattened
|
|
93
|
-
# first (global rank).
|
|
94
|
-
#
|
|
95
|
-
#
|
|
112
|
+
# first (global rank). It is built on the same sort machinery as
|
|
113
|
+
# `sort_index`, and is its inverse:
|
|
114
|
+
# `self.rank_index == self.sort_index.sort_index`.
|
|
96
115
|
#
|
|
97
116
|
# `method:` selects how ties are ranked:
|
|
98
117
|
#
|
|
@@ -111,9 +130,8 @@ class CArray
|
|
|
111
130
|
# original order under `:ordinal` and share a rank under `:dense`, so
|
|
112
131
|
# dense ranks stay without gaps.
|
|
113
132
|
#
|
|
114
|
-
# Masked cells are excluded from ranking (own cell becomes UNDEF
|
|
115
|
-
#
|
|
116
|
-
# remaining unmasked cells.
|
|
133
|
+
# Masked cells are excluded from ranking (own cell becomes UNDEF);
|
|
134
|
+
# `descending:`/`method:` apply to the remaining unmasked cells.
|
|
117
135
|
# @param axis [Integer, nil]
|
|
118
136
|
# @param descending [Boolean]
|
|
119
137
|
# @param method [Symbol] `:ordinal` (default) or `:dense`.
|
|
@@ -121,7 +139,7 @@ class CArray
|
|
|
121
139
|
# {#sort_index}; a performance choice only.
|
|
122
140
|
# @return [CArray] `:int64` ranks, shape == `self.shape`.
|
|
123
141
|
# @raise [ArgumentError] when `method:` is neither `:ordinal` nor `:dense`.
|
|
124
|
-
def
|
|
142
|
+
def rank_index(axis: nil, descending: false, method: :ordinal, kind: :quick); end
|
|
125
143
|
|
|
126
144
|
# @!endgroup
|
|
127
145
|
|
|
@@ -158,15 +176,16 @@ class CArray
|
|
|
158
176
|
# @return [CArray]
|
|
159
177
|
def bsearch_addr(val, axis: nil); end
|
|
160
178
|
|
|
161
|
-
# @overload search(val,
|
|
179
|
+
# @overload search(val, tol: nil)
|
|
162
180
|
# Returns the flat address of the first element of `self` equal
|
|
163
|
-
# to `val`. For float types, `
|
|
164
|
-
#
|
|
181
|
+
# to `val`. For float and complex types, `tol:` sets the largest
|
|
182
|
+
# accepted distance `|cell - val|` (the modulus for a complex array);
|
|
183
|
+
# without it, a cell within machine epsilon times `|val|` matches. A negative or NaN `tol:` raises
|
|
165
184
|
# `ArgumentError`. Returns `nil` if no match.
|
|
166
185
|
#
|
|
167
186
|
# `val` is compared in the type both share, as `self.eq(val)`
|
|
168
187
|
# compares: an integer array searched with a Float is compared in
|
|
169
|
-
# float64 (so `3.9` does not match `3`, and `
|
|
188
|
+
# float64 (so `3.9` does not match `3`, and `tol:` applies), a pair of
|
|
170
189
|
# mixed sign is compared by value (`-1` does not find `255`), and an
|
|
171
190
|
# Integer an integer array cannot hold matches nothing.
|
|
172
191
|
# The same holds for {#bsearch} and {#search_nearest}. On an
|
|
@@ -180,7 +199,11 @@ class CArray
|
|
|
180
199
|
# `nil` is no value of an array that is not `:object`, so it finds
|
|
181
200
|
# nothing there; an `:object` array looks for it like any other value.
|
|
182
201
|
# {#bsearch} and {#search_nearest} need an order or a distance, which
|
|
183
|
-
# `nil` does not have, and raise.
|
|
202
|
+
# `nil` does not have, and raise. A `Complex` with an imaginary part
|
|
203
|
+
# is no value of an integer or float array either: {#search} finds
|
|
204
|
+
# nothing, and {#bsearch} and {#search_nearest} raise `TypeError`,
|
|
205
|
+
# since it has no place in the array's order. One whose imaginary
|
|
206
|
+
# part is `0` is its real part.
|
|
184
207
|
#
|
|
185
208
|
# A time array (`CATime`, `CATimedelta`) takes a value of another
|
|
186
209
|
# unit, a `Time` or a String: when it is off the array's grid the
|
|
@@ -190,22 +213,22 @@ class CArray
|
|
|
190
213
|
# `self` need not be sorted; this is a linear scan. For sorted
|
|
191
214
|
# data prefer {#bsearch}.
|
|
192
215
|
# @param val [Object]
|
|
193
|
-
# @param
|
|
216
|
+
# @param tol [Float, nil]
|
|
194
217
|
# @return [Integer, nil]
|
|
195
|
-
# @overload search(val,
|
|
218
|
+
# @overload search(val, tol: nil, axis:)
|
|
196
219
|
# Per-fiber linear search along `axis`. Returns axis-local
|
|
197
220
|
# positions.
|
|
198
221
|
# @return [CArray]
|
|
199
|
-
def search(val,
|
|
222
|
+
def search(val, tol: nil, axis: nil); end
|
|
200
223
|
|
|
201
|
-
# @overload search_addr(val,
|
|
224
|
+
# @overload search_addr(val, tol: nil)
|
|
202
225
|
# Equivalent to {#search} when `axis:` is omitted.
|
|
203
226
|
# @return [Integer, nil]
|
|
204
|
-
# @overload search_addr(val,
|
|
227
|
+
# @overload search_addr(val, tol: nil, axis:)
|
|
205
228
|
# Per-fiber linear search along `axis`, returning flat
|
|
206
229
|
# addresses rather than axis-local positions.
|
|
207
230
|
# @return [CArray]
|
|
208
|
-
def search_addr(val,
|
|
231
|
+
def search_addr(val, tol: nil, axis: nil); end
|
|
209
232
|
|
|
210
233
|
# @overload search_nearest(val)
|
|
211
234
|
# Returns the flat address of the element of `self` whose value
|
|
@@ -299,6 +322,9 @@ class CArray
|
|
|
299
322
|
# `n` and the axis keeps length `n`. A NaN and a masked cell lose to
|
|
300
323
|
# every value; when fewer cells remain than `n`, the result is
|
|
301
324
|
# shorter (or, per fiber, ends in UNDEF).
|
|
325
|
+
#
|
|
326
|
+
# The result is a view of `self`, as {#sort} is: writing to it writes
|
|
327
|
+
# the cells of `self` it reads. `copy` makes an array of it.
|
|
302
328
|
# @param n [Integer] how many values, 0 or more.
|
|
303
329
|
# @param axis [Integer, nil]
|
|
304
330
|
# @return [CArray]
|
|
@@ -332,14 +358,21 @@ class CArray
|
|
|
332
358
|
# @raise [ArgumentError] when `axis:` is missing or `n` is negative.
|
|
333
359
|
def nsmallest_index(n, axis:); end
|
|
334
360
|
|
|
335
|
-
# @overload sort_by_key(key, axis:
|
|
336
|
-
# Returns `self` reordered
|
|
337
|
-
#
|
|
361
|
+
# @overload sort_by_key(key, axis: nil, masked_position: :last)
|
|
362
|
+
# Returns `self` reordered by the order of `key` (an array of `self`'s
|
|
363
|
+
# shape). Without `axis` the whole array is ordered and the answer is
|
|
364
|
+
# flat, as {#sort} answers; with `axis` each fiber along it is ordered
|
|
365
|
+
# and the shape is kept
|
|
366
|
+
# (`self[key.sort_addr(axis:, masked_position:)]`). The cells whose
|
|
367
|
+
# key is masked go to the end, or to the front with
|
|
368
|
+
# `masked_position: :first`.
|
|
338
369
|
# @param key [CArray] the values to order by.
|
|
339
|
-
# @param axis [Integer]
|
|
370
|
+
# @param axis [Integer, nil]
|
|
371
|
+
# @param masked_position [Symbol] `:last` (default) or `:first`.
|
|
340
372
|
# @return [CArray]
|
|
341
|
-
# @raise [ArgumentError] when `key`'s shape differs from `self`'s
|
|
342
|
-
|
|
373
|
+
# @raise [ArgumentError] when `key`'s shape differs from `self`'s, or
|
|
374
|
+
# `masked_position:` is neither `:first` nor `:last`.
|
|
375
|
+
def sort_by_key(key, axis: nil, masked_position: :last); end
|
|
343
376
|
|
|
344
377
|
# @overload max_by_key(key, axis: nil)
|
|
345
378
|
# Returns the value of `self` where `key` is largest: one value, or
|
data/yard-stubs/carray_random.rb
CHANGED
|
@@ -32,8 +32,8 @@ class CArray
|
|
|
32
32
|
# @param low [Numeric] lower bound (inclusive).
|
|
33
33
|
# @param high [Numeric] upper bound (exclusive).
|
|
34
34
|
# @param range [Range] closed (`a..b`) or half-open (`a...b`).
|
|
35
|
-
# @param rng [Random, nil]
|
|
36
|
-
# default
|
|
35
|
+
# @param rng [Random, CArray::Rng, nil] the generator to draw from; nil draws from
|
|
36
|
+
# Ruby's default generator. {CArray::Rng} says what a seed repeats.
|
|
37
37
|
# @return [self]
|
|
38
38
|
# @raise [CArray::DataTypeError] for `:object` / `:fixlen` arrays.
|
|
39
39
|
# @raise [ArgumentError] when an integer array is called with no
|
|
@@ -59,8 +59,8 @@ class CArray
|
|
|
59
59
|
# Box-Muller and returns `self`. Restricted to float / complex
|
|
60
60
|
# data types; complex fills real and imaginary parts as two
|
|
61
61
|
# independent normals per cell. The mask is cleared.
|
|
62
|
-
# @param rng [Random, nil]
|
|
63
|
-
# default
|
|
62
|
+
# @param rng [Random, CArray::Rng, nil] the generator to draw from; nil draws from
|
|
63
|
+
# Ruby's default generator. {CArray::Rng} says what a seed repeats.
|
|
64
64
|
# @return [self]
|
|
65
65
|
# @raise [CArray::DataTypeError] for non-float / non-complex arrays.
|
|
66
66
|
def randomn!(rng: nil); end
|
|
@@ -83,8 +83,8 @@ class CArray
|
|
|
83
83
|
# moves with the values: a masked cell stays masked wherever it
|
|
84
84
|
# lands.
|
|
85
85
|
# @param axis [Integer, nil] axis to permute along; nil = flat.
|
|
86
|
-
# @param rng [Random, nil]
|
|
87
|
-
# default
|
|
86
|
+
# @param rng [Random, CArray::Rng, nil] the generator to draw from; nil draws from
|
|
87
|
+
# Ruby's default generator. {CArray::Rng} says what a seed repeats.
|
|
88
88
|
# @return [self]
|
|
89
89
|
# @raise [ArgumentError] if `axis` is out of range.
|
|
90
90
|
def shuffle!(axis: nil, rng: nil); end
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for the reductions and scans generated by ext/mkkernel.rb
|
|
3
|
+
# (sum, prod, mean, min, max, minmax, variance, stddev, accumulate,
|
|
4
|
+
# wsum, wmean, min_index, max_index, and the cumulative scans). The
|
|
5
|
+
# generated kernels carry no C docstring, so the documentation lives
|
|
6
|
+
# here. See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
7
|
+
|
|
8
|
+
class CArray
|
|
9
|
+
# @!group Statistics
|
|
10
|
+
|
|
11
|
+
# @overload sum(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
12
|
+
# Returns the sum of `self` over all elements, or along `axis`.
|
|
13
|
+
#
|
|
14
|
+
# Without `axis`, the result is a single value. With `axis` (an
|
|
15
|
+
# Integer, or an Array of them; negative counts from the end) the
|
|
16
|
+
# named axes are reduced and a `CArray` of the remaining shape is
|
|
17
|
+
# returned. Naming every axis gives a single value, as no `axis`
|
|
18
|
+
# does. With `keep_axis: true` the reduced axes stay, with length 1.
|
|
19
|
+
#
|
|
20
|
+
# Masked cells are left out. A sum with no cells to add (an empty
|
|
21
|
+
# array, or every cell masked) is `0`. When fewer than `min_count`
|
|
22
|
+
# cells are not masked, the answer is `fill_value`, or `UNDEF` when
|
|
23
|
+
# `fill_value` is `nil`. These rules are the same for every
|
|
24
|
+
# reduction below; only the answer for no cells differs.
|
|
25
|
+
#
|
|
26
|
+
# The sum of an integer array is an integer: int64 for a signed
|
|
27
|
+
# type, uint64 for an unsigned type and for boolean (where the sum
|
|
28
|
+
# counts the true cells). A total that does not fit in that type is
|
|
29
|
+
# returned as a float64 near the exact value; with `axis`, the whole
|
|
30
|
+
# result is float64 when any one cell does not fit. Float input
|
|
31
|
+
# (float32 included) sums in float64, complex input in cmplx128, and
|
|
32
|
+
# an `:object` array uses its elements' own `+`. To add in the
|
|
33
|
+
# array's own type, wrapping at its width, use {#accumulate}.
|
|
34
|
+
#
|
|
35
|
+
# Float sums are close to, but not always bit for bit equal to, a
|
|
36
|
+
# sum taken left to right: the additions may be grouped differently.
|
|
37
|
+
# @param axis [Integer, Array<Integer>, nil] axes to reduce.
|
|
38
|
+
# @param keep_axis [Boolean] keep the reduced axes with length 1.
|
|
39
|
+
# @param min_count [Integer] the fewest not-masked cells that give an
|
|
40
|
+
# answer.
|
|
41
|
+
# @param fill_value [Object, nil] the answer when there are fewer
|
|
42
|
+
# than `min_count` cells.
|
|
43
|
+
# @return [Integer, Float, Complex, Object, CArray]
|
|
44
|
+
# @raise [ArgumentError] when `axis` is out of range or repeated.
|
|
45
|
+
# @example
|
|
46
|
+
# a = CA_INT32([[1, 2, 3], [4, 5, 6]])
|
|
47
|
+
# a.sum # => 21
|
|
48
|
+
# a.sum(axis: 0) # => [ 5, 7, 9 ] (int64)
|
|
49
|
+
# CA_FLOAT64([]).sum # => 0.0
|
|
50
|
+
def sum(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
51
|
+
|
|
52
|
+
# @overload prod(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
53
|
+
# Returns the product of `self` over all elements, or along `axis`.
|
|
54
|
+
#
|
|
55
|
+
# The keywords and masked cells work as in {#sum}. A product with no
|
|
56
|
+
# cells is `1`. The type of the answer follows the same rule as
|
|
57
|
+
# {#sum}: int64 or uint64 for an integer array, float64 when the
|
|
58
|
+
# product does not fit, float64 for float input, cmplx128 for
|
|
59
|
+
# complex input, and the elements' own `*` for an `:object` array.
|
|
60
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
61
|
+
# @param keep_axis [Boolean]
|
|
62
|
+
# @param min_count [Integer]
|
|
63
|
+
# @param fill_value [Object, nil]
|
|
64
|
+
# @return [Integer, Float, Complex, Object, CArray]
|
|
65
|
+
def prod(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
66
|
+
|
|
67
|
+
# @overload mean(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
68
|
+
# Returns the arithmetic mean of `self` over all elements, or along
|
|
69
|
+
# `axis`.
|
|
70
|
+
#
|
|
71
|
+
# The keywords and masked cells work as in {#sum}; the mean divides
|
|
72
|
+
# by the number of cells that are not masked. With no cells the mean
|
|
73
|
+
# is `UNDEF`.
|
|
74
|
+
#
|
|
75
|
+
# Integer, float and boolean input answer in float64 (a boolean mean
|
|
76
|
+
# is the share of true cells), complex input in cmplx128. An
|
|
77
|
+
# `:object` array uses its elements' own `+`, and divides the total
|
|
78
|
+
# by the count with `quo` where the total has it (`/` otherwise), so
|
|
79
|
+
# Integer and Rational elements give an exact Rational
|
|
80
|
+
# (`CA_OBJECT([1, 2]).mean` is `(3/2)`) and Float or BigDecimal ones
|
|
81
|
+
# stay in their kind.
|
|
82
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
83
|
+
# @param keep_axis [Boolean]
|
|
84
|
+
# @param min_count [Integer]
|
|
85
|
+
# @param fill_value [Object, nil]
|
|
86
|
+
# @return [Float, Complex, Object, CArray]
|
|
87
|
+
def mean(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
88
|
+
|
|
89
|
+
# @overload min(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
90
|
+
# Returns the smallest element of `self`, or the smallest along
|
|
91
|
+
# `axis`.
|
|
92
|
+
#
|
|
93
|
+
# The keywords and masked cells work as in {#sum}. With no cells the
|
|
94
|
+
# minimum is `UNDEF`. The answer is in `self`'s own type, except that
|
|
95
|
+
# a boolean array answers as uint64. A NaN is never the minimum while
|
|
96
|
+
# any other value is present; a fiber of NaN only gives NaN. An
|
|
97
|
+
# `:object` array compares its elements with `<=>`.
|
|
98
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
99
|
+
# @param keep_axis [Boolean]
|
|
100
|
+
# @param min_count [Integer]
|
|
101
|
+
# @param fill_value [Object, nil]
|
|
102
|
+
# @return [Integer, Float, Object, CArray]
|
|
103
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`, which has
|
|
104
|
+
# no order.
|
|
105
|
+
def min(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
106
|
+
|
|
107
|
+
# @overload max(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
108
|
+
# Returns the largest element of `self`, or the largest along
|
|
109
|
+
# `axis`. Works as {#min} does, for the largest value.
|
|
110
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
111
|
+
# @param keep_axis [Boolean]
|
|
112
|
+
# @param min_count [Integer]
|
|
113
|
+
# @param fill_value [Object, nil]
|
|
114
|
+
# @return [Integer, Float, Object, CArray]
|
|
115
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
116
|
+
def max(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
117
|
+
|
|
118
|
+
# @overload minmax(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
119
|
+
# Returns `[min, max]` in one pass over `self`.
|
|
120
|
+
#
|
|
121
|
+
# Each of the two is what {#min} and {#max} return with the same
|
|
122
|
+
# arguments: two values without `axis`, two `CArray`s with it. With
|
|
123
|
+
# no cells the answer is `[UNDEF, UNDEF]`.
|
|
124
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
125
|
+
# @param keep_axis [Boolean]
|
|
126
|
+
# @param min_count [Integer]
|
|
127
|
+
# @param fill_value [Object, nil]
|
|
128
|
+
# @return [Array]
|
|
129
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
130
|
+
# @example
|
|
131
|
+
# CA_FLOAT64([1, 5, 3]).minmax # => [1.0, 5.0]
|
|
132
|
+
def minmax(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
133
|
+
|
|
134
|
+
# @overload variance(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
135
|
+
# Returns the sample variance of `self` (divided by `n - 1`), over
|
|
136
|
+
# all elements or along `axis`.
|
|
137
|
+
#
|
|
138
|
+
# The keywords and masked cells work as in {#sum}. With fewer than
|
|
139
|
+
# two cells the sample variance is `UNDEF`. Integer, float and
|
|
140
|
+
# boolean input answer in float64; complex input answers in float64
|
|
141
|
+
# as the variance of the distance from the complex mean. An `:object`
|
|
142
|
+
# array uses its elements' own arithmetic and divides with `quo` as
|
|
143
|
+
# {#mean} does, so Integer and Rational elements give an exact
|
|
144
|
+
# Rational.
|
|
145
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
146
|
+
# @param keep_axis [Boolean]
|
|
147
|
+
# @param min_count [Integer]
|
|
148
|
+
# @param fill_value [Object, nil]
|
|
149
|
+
# @return [Float, Object, CArray]
|
|
150
|
+
def variance(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
151
|
+
|
|
152
|
+
# @overload variancep(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
153
|
+
# Returns the population variance of `self` (divided by `n`). Works
|
|
154
|
+
# as {#variance} does; one cell gives `0.0`, no cells give `UNDEF`.
|
|
155
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
156
|
+
# @param keep_axis [Boolean]
|
|
157
|
+
# @param min_count [Integer]
|
|
158
|
+
# @param fill_value [Object, nil]
|
|
159
|
+
# @return [Float, Object, CArray]
|
|
160
|
+
def variancep(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
161
|
+
|
|
162
|
+
# @overload stddev(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
163
|
+
# Returns the sample standard deviation of `self`, the square root of
|
|
164
|
+
# {#variance}. The answer is float64, also for an `:object` array.
|
|
165
|
+
# With fewer than two cells it is `UNDEF`.
|
|
166
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
167
|
+
# @param keep_axis [Boolean]
|
|
168
|
+
# @param min_count [Integer]
|
|
169
|
+
# @param fill_value [Object, nil]
|
|
170
|
+
# @return [Float, CArray]
|
|
171
|
+
def stddev(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
172
|
+
|
|
173
|
+
# @overload stddevp(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
174
|
+
# Returns the population standard deviation of `self`, the square
|
|
175
|
+
# root of {#variancep}. The answer is float64.
|
|
176
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
177
|
+
# @param keep_axis [Boolean]
|
|
178
|
+
# @param min_count [Integer]
|
|
179
|
+
# @param fill_value [Object, nil]
|
|
180
|
+
# @return [Float, CArray]
|
|
181
|
+
def stddevp(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
182
|
+
|
|
183
|
+
# @overload accumulate(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
184
|
+
# Returns the sum of `self` kept in `self`'s own `data_type`.
|
|
185
|
+
#
|
|
186
|
+
# Where {#sum} widens an integer total to int64 or uint64,
|
|
187
|
+
# `accumulate` adds in the array's type and wraps at its width, with
|
|
188
|
+
# nothing to say that it did (`CA_INT8([127, 1]).accumulate` is
|
|
189
|
+
# `-128`). For a boolean array it is the parity of the true cells
|
|
190
|
+
# (exclusive or): a single answer is the number `1` or `0`, and an
|
|
191
|
+
# array answer (with `axis` or `keep_axis`) stays boolean, so that an
|
|
192
|
+
# `accumulate` of it along another axis is still the parity. The keywords and masked cells work as in {#sum};
|
|
193
|
+
# with no cells the answer is `0`.
|
|
194
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
195
|
+
# @param keep_axis [Boolean]
|
|
196
|
+
# @param min_count [Integer]
|
|
197
|
+
# @param fill_value [Object, nil]
|
|
198
|
+
# @return [Integer, Float, Complex, Object, CArray]
|
|
199
|
+
def accumulate(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
200
|
+
|
|
201
|
+
# @overload wsum(weights, axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
202
|
+
# Returns the weighted sum `sum(self * weights)`, over all elements
|
|
203
|
+
# or along `axis`.
|
|
204
|
+
#
|
|
205
|
+
# `weights` is a scalar, a `CArray` of the shape of the reduced axes
|
|
206
|
+
# (one weight per position along them), or a `CArray` of
|
|
207
|
+
# `self.shape`. An integer array with integer (or boolean) weights
|
|
208
|
+
# gives an integer total as {#sum} does: int64, or uint64 when the
|
|
209
|
+
# values and the weights are unsigned (an Integer weight counts as
|
|
210
|
+
# unsigned when it is not negative), and float64 near the exact
|
|
211
|
+
# value when the total does not fit (with `axis`, the whole result is
|
|
212
|
+
# float64 when any one cell does not fit). A boolean array weighs its
|
|
213
|
+
# cells as 0 / 1 and answers as a uint8 array does. A float weight or a
|
|
214
|
+
# float array gives float64, and an `:object` array the elements' own
|
|
215
|
+
# arithmetic. The keywords and masked cells work as in {#sum}. A
|
|
216
|
+
# masked weight is a masked `CArray` (a `CScalar` that is masked masks
|
|
217
|
+
# every weight); `UNDEF` itself is no weight and is refused, as `nil`
|
|
218
|
+
# is.
|
|
219
|
+
# @param weights [Numeric, CArray]
|
|
220
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
221
|
+
# @param keep_axis [Boolean]
|
|
222
|
+
# @param min_count [Integer]
|
|
223
|
+
# @param fill_value [Object, nil]
|
|
224
|
+
# @return [Integer, Float, Object, CArray]
|
|
225
|
+
# @raise [TypeError] when `weights` is `UNDEF` or `nil`.
|
|
226
|
+
# @raise [ArgumentError] when `weights` has another shape.
|
|
227
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
228
|
+
def wsum(weights, axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
229
|
+
|
|
230
|
+
# @overload wmean(weights, axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
231
|
+
# Returns the weighted mean `sum(self * weights) / sum(weights)`.
|
|
232
|
+
#
|
|
233
|
+
# `weights` takes the forms {#wsum} takes. A cell that is masked in
|
|
234
|
+
# `self` or in `weights` is left out of both sums. With no cells, or
|
|
235
|
+
# a zero sum of weights, the answer is `UNDEF`. The answer is float64
|
|
236
|
+
# for integer, boolean (cells as 0 / 1) and float input; an `:object`
|
|
237
|
+
# array divides with `quo` as {#mean} does.
|
|
238
|
+
# @param weights [Numeric, CArray]
|
|
239
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
240
|
+
# @param keep_axis [Boolean]
|
|
241
|
+
# @param min_count [Integer]
|
|
242
|
+
# @param fill_value [Object, nil]
|
|
243
|
+
# @return [Float, Object, CArray]
|
|
244
|
+
# @raise [TypeError] when `weights` is `UNDEF` or `nil`.
|
|
245
|
+
# @raise [ArgumentError] when `weights` has another shape.
|
|
246
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
247
|
+
def wmean(weights, axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
248
|
+
|
|
249
|
+
# @!endgroup
|
|
250
|
+
|
|
251
|
+
# @!group Sorting and searching
|
|
252
|
+
|
|
253
|
+
# @overload min_index(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
254
|
+
# Returns the position of the smallest element of `self`.
|
|
255
|
+
#
|
|
256
|
+
# Without `axis`, the answer is one Integer: the flat position, in
|
|
257
|
+
# row-major order, of the first smallest element. With `axis`, an
|
|
258
|
+
# int64 `CArray` holds, for each fiber along `axis`, the position of
|
|
259
|
+
# its smallest element within the fiber. Masked cells and NaN are
|
|
260
|
+
# passed over as {#min} passes over them; a fiber with no cells gives
|
|
261
|
+
# `UNDEF`. The other keywords work as in {#sum}.
|
|
262
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
263
|
+
# @param keep_axis [Boolean]
|
|
264
|
+
# @param min_count [Integer]
|
|
265
|
+
# @param fill_value [Object, nil]
|
|
266
|
+
# @return [Integer, CArray]
|
|
267
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
268
|
+
# @example
|
|
269
|
+
# m = CA_INT32([[3, 1, 4], [1, 5, 9]])
|
|
270
|
+
# m.min_index # => 1
|
|
271
|
+
# m.min_index(axis: 0) # => [ 1, 0, 0 ]
|
|
272
|
+
def min_index(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
273
|
+
|
|
274
|
+
# @overload max_index(axis: nil, keep_axis: false, min_count: 0, fill_value: nil)
|
|
275
|
+
# Returns the position of the largest element of `self`. Works as
|
|
276
|
+
# {#min_index} does, for the largest value.
|
|
277
|
+
# @param axis [Integer, Array<Integer>, nil]
|
|
278
|
+
# @param keep_axis [Boolean]
|
|
279
|
+
# @param min_count [Integer]
|
|
280
|
+
# @param fill_value [Object, nil]
|
|
281
|
+
# @return [Integer, CArray]
|
|
282
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
283
|
+
def max_index(axis: nil, keep_axis: false, min_count: 0, fill_value: nil); end
|
|
284
|
+
|
|
285
|
+
# @!endgroup
|
|
286
|
+
|
|
287
|
+
# @!group Statistics
|
|
288
|
+
|
|
289
|
+
# @overload cumsum(axis: nil)
|
|
290
|
+
# Returns the running sum of `self` along `axis`.
|
|
291
|
+
#
|
|
292
|
+
# With `axis` (one Integer) the result has `self`'s shape, and each
|
|
293
|
+
# fiber along `axis` is summed from its start. Without `axis` `self`
|
|
294
|
+
# is read flat, and the result is 1-D with `self.elements` cells. To
|
|
295
|
+
# run along several axes, chain the calls
|
|
296
|
+
# (`a.cumsum(axis: 0).cumsum(axis: 1)`).
|
|
297
|
+
#
|
|
298
|
+
# A masked cell adds nothing: its result cell holds the running value
|
|
299
|
+
# so far, and the result has no mask, as a reduction leaves masked
|
|
300
|
+
# cells out (a scan is the reduction up to each cell). To keep the
|
|
301
|
+
# masked places in the result, take the mask over:
|
|
302
|
+
# `c = a.cumsum; c.inherit_mask(a)`. A signed integer array answers in int64 and an unsigned one in
|
|
303
|
+
# uint64, as {#sum} does; when a running value is out of that range the
|
|
304
|
+
# whole answer is float64 (close, not exact) rather than a wrapped value.
|
|
305
|
+
# Float input answers in float64, complex input in cmplx128, boolean
|
|
306
|
+
# input in uint64, and an `:object` array uses its elements' own `+`.
|
|
307
|
+
# @param axis [Integer, nil]
|
|
308
|
+
# @return [CArray]
|
|
309
|
+
# @raise [ArgumentError] when `axis` is an Array or out of range.
|
|
310
|
+
# @example
|
|
311
|
+
# CA_INT32([1, 2, 3, 4]).cumsum # => [ 1, 3, 6, 10 ] (:int64)
|
|
312
|
+
def cumsum(axis: nil); end
|
|
313
|
+
|
|
314
|
+
# @overload cumprod(axis: nil)
|
|
315
|
+
# Returns the running product of `self` along `axis`. Works as
|
|
316
|
+
# {#cumsum} does, with `*`; a masked cell multiplies by nothing.
|
|
317
|
+
# @param axis [Integer, nil]
|
|
318
|
+
# @return [CArray]
|
|
319
|
+
# @raise [ArgumentError] when `axis` is an Array or out of range.
|
|
320
|
+
def cumprod(axis: nil); end
|
|
321
|
+
|
|
322
|
+
# @overload cummax(axis: nil)
|
|
323
|
+
# Returns the running maximum of `self` along `axis`. Works as
|
|
324
|
+
# {#cumsum} does; the result is in `self`'s own type (uint64 for a
|
|
325
|
+
# boolean array). A run of masked cells at the start of a fiber has
|
|
326
|
+
# no value to hold yet, so those cells are `UNDEF`.
|
|
327
|
+
# @param axis [Integer, nil]
|
|
328
|
+
# @return [CArray]
|
|
329
|
+
# @raise [ArgumentError] when `axis` is an Array or out of range.
|
|
330
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
331
|
+
def cummax(axis: nil); end
|
|
332
|
+
|
|
333
|
+
# @overload cummin(axis: nil)
|
|
334
|
+
# Returns the running minimum of `self` along `axis`. Works as
|
|
335
|
+
# {#cummax} does, for the smallest value.
|
|
336
|
+
# @param axis [Integer, nil]
|
|
337
|
+
# @return [CArray]
|
|
338
|
+
# @raise [ArgumentError] when `axis` is an Array or out of range.
|
|
339
|
+
# @raise [CArray::DataTypeError] for a complex `data_type`.
|
|
340
|
+
def cummin(axis: nil); end
|
|
341
|
+
|
|
342
|
+
# @overload cumcount(axis: nil)
|
|
343
|
+
# Returns, for each cell, how many cells along `axis` up to and
|
|
344
|
+
# including it are not masked: an int64 `CArray`. Works as
|
|
345
|
+
# {#cumsum} does for `axis`. It reads only the mask, so it takes
|
|
346
|
+
# every `data_type`.
|
|
347
|
+
# @param axis [Integer, nil]
|
|
348
|
+
# @return [CArray]
|
|
349
|
+
# @raise [ArgumentError] when `axis` is an Array or out of range.
|
|
350
|
+
def cumcount(axis: nil); end
|
|
351
|
+
|
|
352
|
+
# @!endgroup
|
|
353
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for CArray::Rng, defined in ext/carray_random.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
|
|
7
|
+
# A random number generator with its own state, for `rng:` on
|
|
8
|
+
# {CArray#random!}, {CArray#randomn!} and {CArray#shuffle!}.
|
|
9
|
+
#
|
|
10
|
+
# r = CArray::Rng.new(seed: 42)
|
|
11
|
+
# a = CArray.float64(1000).random!(rng: r)
|
|
12
|
+
# b = CArray.int32(10).random!(1..6, rng: r) # continues the sequence
|
|
13
|
+
#
|
|
14
|
+
# The generator is xoshiro256++ 1.0 (Blackman and Vigna), with the state
|
|
15
|
+
# made from the seed by splitmix64, as its authors prescribe. The state
|
|
16
|
+
# is four int64 cells ({#state}).
|
|
17
|
+
#
|
|
18
|
+
# == What a seed repeats
|
|
19
|
+
#
|
|
20
|
+
# For a given seed, {#bits} and {#random} give the same sequence in every
|
|
21
|
+
# version of CArray and on every machine.
|
|
22
|
+
#
|
|
23
|
+
# A fill with `rng:` takes its draws cell by cell in the row-major order
|
|
24
|
+
# of the receiver (for a view, the view's own order), the real part of a
|
|
25
|
+
# complex cell before the imaginary part. {CArray#random!} and
|
|
26
|
+
# {CArray#shuffle!} use only exact arithmetic on the draws, so the same
|
|
27
|
+
# seed fills the same values on every machine. From CArray 3.1, a change
|
|
28
|
+
# to these values is named in the CHANGELOG.
|
|
29
|
+
#
|
|
30
|
+
# {#randomn} and {CArray#randomn!} take exactly two draws for each normal
|
|
31
|
+
# value, so the generator is in the same place afterwards everywhere. The
|
|
32
|
+
# value itself goes through `log`, `sqrt` and `cos`, and may differ
|
|
33
|
+
# between machines in the last place.
|
|
34
|
+
#
|
|
35
|
+
# With a Ruby `Random` as `rng:`, the draws are the ones that Ruby gives.
|
|
36
|
+
# Without `rng:`, a fill draws from Ruby's default generator and cannot
|
|
37
|
+
# be repeated.
|
|
38
|
+
class Rng
|
|
39
|
+
|
|
40
|
+
# @overload initialize(generator = :xoshiro256pp, seed: nil)
|
|
41
|
+
# Makes a generator. Without `seed:`, one is taken from
|
|
42
|
+
# `Random.new_seed`, so two generators made this way differ.
|
|
43
|
+
# @param generator [Symbol] `:xoshiro256pp`, the only one.
|
|
44
|
+
# @param seed [Integer, nil] any Integer; a negative one or one wider
|
|
45
|
+
# than 64 bits is reduced to its low 64 bits.
|
|
46
|
+
# @raise [ArgumentError] for an unknown generator.
|
|
47
|
+
def initialize(generator = :xoshiro256pp, seed: nil); end
|
|
48
|
+
|
|
49
|
+
# @overload reset(seed = nil)
|
|
50
|
+
# Starts the sequence over, from `seed` if given and otherwise from
|
|
51
|
+
# the seed this generator already has, so `reset` with no argument
|
|
52
|
+
# repeats a run. A new seed is kept for later resets.
|
|
53
|
+
# @param seed [Integer, nil]
|
|
54
|
+
# @return [self]
|
|
55
|
+
def reset(seed = nil); end
|
|
56
|
+
|
|
57
|
+
# @overload random
|
|
58
|
+
# One draw in `[0.0, 1.0)`: the top 53 bits of the next word,
|
|
59
|
+
# times 2**-53. The same draw that {CArray#random!} takes for one
|
|
60
|
+
# float cell.
|
|
61
|
+
# @return [Float]
|
|
62
|
+
def random; end
|
|
63
|
+
|
|
64
|
+
# @overload randomn
|
|
65
|
+
# One standard normal value, by Box-Muller from two draws. The same
|
|
66
|
+
# value that {CArray#randomn!} writes into one float cell.
|
|
67
|
+
# @return [Float]
|
|
68
|
+
def randomn; end
|
|
69
|
+
|
|
70
|
+
# @overload bits
|
|
71
|
+
# The next word of the generator, as an unsigned 64-bit Integer.
|
|
72
|
+
# This is the sequence published by the generator's authors, for
|
|
73
|
+
# checking this generator against it.
|
|
74
|
+
# @return [Integer]
|
|
75
|
+
def bits; end
|
|
76
|
+
|
|
77
|
+
# @return [Symbol] the generator, `:xoshiro256pp`.
|
|
78
|
+
attr_reader :generator
|
|
79
|
+
|
|
80
|
+
# @return [CArray] the state, a CA_INT64 array of four cells. Draws
|
|
81
|
+
# advance it in place.
|
|
82
|
+
attr_reader :state
|
|
83
|
+
|
|
84
|
+
# @return [Integer] the seed the sequence was started from.
|
|
85
|
+
attr_reader :seed
|
|
86
|
+
|
|
87
|
+
# @overload inspect
|
|
88
|
+
# Returns the generator and the seed as text, without the state.
|
|
89
|
+
# @return [String]
|
|
90
|
+
def inspect; end
|
|
91
|
+
end
|
|
92
|
+
end
|