carray 3.0.4 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +205 -0
- data/carray.gemspec +1 -1
- data/ext/ca_array_pool.c +25 -1
- data/ext/ca_axis_dispatch.c +13 -20
- data/ext/ca_categorical_iterator.c +27 -20
- data/ext/ca_compare.c +4 -4
- data/ext/ca_composite_dispatch.c +9 -9
- data/ext/ca_kernel_iterator.c +6 -6
- data/ext/ca_kernel_iterator.h +112 -83
- data/ext/ca_obj_array.c +69 -19
- data/ext/ca_obj_bincmp.c +1 -0
- data/ext/ca_obj_binop.c +1 -0
- data/ext/ca_obj_bitarray.c +5 -1
- data/ext/ca_obj_bitfield.c +58 -43
- data/ext/ca_obj_byte_swap.c +2 -1
- data/ext/ca_obj_const_string.c +15 -3
- data/ext/ca_obj_face.c +42 -1
- data/ext/ca_obj_field.c +13 -3
- data/ext/ca_obj_grid.c +52 -5
- data/ext/ca_obj_monop.c +46 -10
- data/ext/ca_obj_object.c +64 -12
- data/ext/ca_obj_record.c +3 -0
- data/ext/ca_obj_reduce.c +4 -0
- data/ext/ca_obj_refer.c +18 -9
- data/ext/ca_obj_roll.c +26 -6
- data/ext/ca_obj_select.c +34 -5
- data/ext/ca_obj_shift.c +31 -7
- data/ext/ca_obj_stack.c +1 -0
- data/ext/ca_obj_stride.c +28 -19
- data/ext/ca_obj_string.c +11 -2
- data/ext/ca_obj_tile.c +27 -7
- data/ext/ca_obj_transpose.c +8 -4
- data/ext/ca_obj_triop.c +3 -0
- data/ext/ca_obj_window.c +79 -50
- data/ext/ca_op_ipower.c +4 -4
- data/ext/ca_sort_kernels.h +6 -3
- data/ext/carray.h +33 -0
- data/ext/carray_access.c +16 -3
- data/ext/carray_attribute.c +24 -0
- data/ext/carray_cast.c +243 -82
- data/ext/carray_cast_func.rb +56 -26
- data/ext/carray_conversion.c +2 -2
- data/ext/carray_core.c +3 -0
- data/ext/carray_count.c +6 -0
- data/ext/carray_element.c +9 -4
- data/ext/carray_factorize.c +20 -20
- data/ext/carray_generate.c +8 -2
- data/ext/carray_histogram.c +1 -1
- data/ext/carray_index_classifier.c +4 -4
- data/ext/carray_internal.h +12 -0
- data/ext/carray_kernels_bincmp.c +168 -168
- data/ext/carray_kernels_binop.c +900 -900
- data/ext/carray_kernels_init.c +4 -4
- data/ext/carray_kernels_moncmp.c +96 -96
- data/ext/carray_kernels_monop.c +1984 -1984
- data/ext/carray_kernels_reduce_aggregate.c +1733 -1733
- data/ext/carray_kernels_reduce_cumulative.c +642 -642
- data/ext/carray_kernels_reduce_extreme.c +1150 -1150
- data/ext/carray_kernels_reduce_variance.c +258 -258
- data/ext/carray_kernels_scan.c +128 -128
- data/ext/carray_kernels_search.c +340 -340
- data/ext/carray_kernels_sort.c +295 -304
- data/ext/carray_kernels_triop.c +114 -114
- data/ext/carray_key_windows.c +4 -0
- data/ext/carray_mask.c +45 -22
- data/ext/carray_memory_view.c +2 -2
- data/ext/carray_operator.c +5 -5
- data/ext/carray_order.c +227 -8
- data/ext/carray_random.c +18 -18
- data/ext/carray_scatter.c +24 -7
- data/ext/carray_slab.c +32 -9
- data/ext/carray_sort.c +224 -16
- data/ext/carray_sort_kernel.c +5 -7
- data/ext/carray_struct.c +35 -43
- data/ext/carray_time_text.c +4 -2
- data/ext/carray_utils.c +63 -21
- data/ext/mkkernel.rb +210 -115
- data/ext/version.h +4 -4
- data/lib/carray/attribute.rb +17 -4
- data/lib/carray/basics.rb +27 -7
- data/lib/carray/categorical.rb +30 -16
- data/lib/carray/categorical_iterator.rb +6 -6
- data/lib/carray/const_string.rb +10 -0
- data/lib/carray/data_type_extension.rb +8 -1
- data/lib/carray/fixlen_string.rb +41 -2
- data/lib/carray/frame/column_verbs.rb +4 -3
- data/lib/carray/frame/concat.rb +17 -3
- data/lib/carray/frame/frame.rb +6 -7
- data/lib/carray/frame/group.rb +100 -13
- data/lib/carray/frame/io.rb +3 -1
- data/lib/carray/fuse_source.rb +31 -2
- data/lib/carray/lazy.rb +35 -0
- data/lib/carray/methods/is_in.rb +8 -1
- data/lib/carray/segment_iterator.rb +12 -8
- data/lib/carray/serialize.rb +19 -2
- data/lib/carray/stack.rb +15 -12
- data/lib/carray/string.rb +8 -0
- data/lib/carray/string_operation_extension.rb +13 -5
- data/lib/carray/struct_builder.rb +5 -3
- data/lib/carray/time.rb +107 -68
- data/yard-stubs/ca_obj_transpose.rb +5 -4
- data/yard-stubs/carray_attribute.rb +3 -1
- data/yard-stubs/carray_cast.rb +2 -0
- data/yard-stubs/carray_conversion.rb +5 -1
- data/yard-stubs/carray_element.rb +7 -6
- data/yard-stubs/carray_mask.rb +8 -3
- data/yard-stubs/carray_math.rb +14 -4
- data/yard-stubs/carray_order.rb +100 -4
- data/yard-stubs/carray_scatter.rb +7 -5
- metadata +1 -1
data/yard-stubs/carray_math.rb
CHANGED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
# builds a node in the expression tree instead of evaluating, and the
|
|
12
12
|
# eager and lazy paths are required to agree element for element.
|
|
13
13
|
#
|
|
14
|
+
# The transcendental functions call the platform's C math library, so
|
|
15
|
+
# their last bits, and the complex functions' answers at special values
|
|
16
|
+
# (signed zeros, infinities, NaN), follow that library and can differ
|
|
17
|
+
# between operating systems.
|
|
18
|
+
#
|
|
14
19
|
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
15
20
|
|
|
16
21
|
class CArray
|
|
@@ -598,6 +603,8 @@ class CArray
|
|
|
598
603
|
# Returns each element of `self` with the magnitude it already has
|
|
599
604
|
# and the sign of the matching element of `other`. The sign of a
|
|
600
605
|
# zero is respected, so `copysign` distinguishes `-0.0` from `0.0`.
|
|
606
|
+
# The sign of a NaN that a computation produced (`sqrt(-1)`,
|
|
607
|
+
# `Inf * 0`) depends on the CPU: x86 sets it, ARM does not.
|
|
601
608
|
# Accepts float and `:object` arrays only, as {#atan2}.
|
|
602
609
|
# @param other [CArray, Numeric] sign source, broadcast to
|
|
603
610
|
# `self.shape`.
|
|
@@ -683,8 +690,8 @@ class CArray
|
|
|
683
690
|
# @overload pmax(other)
|
|
684
691
|
# Returns the element-wise larger of `self` and `other`, ignoring
|
|
685
692
|
# `NaN`: where one element is `NaN` the other is returned, and only
|
|
686
|
-
# two `NaN`s give `NaN`.
|
|
687
|
-
# a `NaN` win see {#maximum}.
|
|
693
|
+
# two `NaN`s give `NaN`. Of `-0.0` and `0.0` the result is `0.0`,
|
|
694
|
+
# in either order. For the form that lets a `NaN` win see {#maximum}.
|
|
688
695
|
# @param other [CArray, Numeric] the other operand, broadcast to
|
|
689
696
|
# `self.shape`.
|
|
690
697
|
# @return [CArray] result of the promoted `data_type` of the two
|
|
@@ -697,7 +704,8 @@ class CArray
|
|
|
697
704
|
|
|
698
705
|
# @overload pmin(other)
|
|
699
706
|
# Returns the element-wise smaller of `self` and `other`, ignoring
|
|
700
|
-
# `NaN`.
|
|
707
|
+
# `NaN`. Of `-0.0` and `0.0` the result is `-0.0`, in either order.
|
|
708
|
+
# The counterpart of {#pmax}.
|
|
701
709
|
# @param other [CArray, Numeric] the other operand.
|
|
702
710
|
# @return [CArray]
|
|
703
711
|
# @raise [CArray::DataTypeError] for a complex array.
|
|
@@ -929,7 +937,9 @@ class CArray
|
|
|
929
937
|
# @overload signbit
|
|
930
938
|
# Returns a boolean array that is true where an element carries a
|
|
931
939
|
# negative sign bit. A negative zero is true, which distinguishes
|
|
932
|
-
# `-0.0` from `0.0` where a `< 0` comparison cannot.
|
|
940
|
+
# `-0.0` from `0.0` where a `< 0` comparison cannot. On a NaN that a
|
|
941
|
+
# computation produced (`sqrt(-1)`, `Inf * 0`) the answer depends on
|
|
942
|
+
# the CPU: x86 sets the sign bit, ARM does not.
|
|
933
943
|
# @return [CArray] `:boolean`.
|
|
934
944
|
# @raise [CArray::DataTypeError] for a complex array.
|
|
935
945
|
# @example
|
data/yard-stubs/carray_order.rb
CHANGED
|
@@ -128,7 +128,8 @@ class CArray
|
|
|
128
128
|
|
|
129
129
|
# @overload bsearch(val)
|
|
130
130
|
# Returns the flat address of `val` in `self` via binary search.
|
|
131
|
-
# `self` must be sorted along its single (flat) axis.
|
|
131
|
+
# `self` must be sorted along its single (flat) axis. Of several
|
|
132
|
+
# equal cells, the first one's address is returned. Returns
|
|
132
133
|
# `nil` if `val` is not present. When `val` is a CArray, returns
|
|
133
134
|
# a CArray of `:int64` addresses (one per element of `val`),
|
|
134
135
|
# with `UNDEF` at positions where the value is not present.
|
|
@@ -159,7 +160,8 @@ class CArray
|
|
|
159
160
|
# @overload search(val, eps = nil)
|
|
160
161
|
# Returns the flat address of the first element of `self` equal
|
|
161
162
|
# to `val`. For float types, `eps` (default machine epsilon)
|
|
162
|
-
# sets the tolerance
|
|
163
|
+
# sets the tolerance; a negative or NaN `eps` raises
|
|
164
|
+
# `ArgumentError`. Returns `nil` if no match.
|
|
163
165
|
#
|
|
164
166
|
# `val` is compared in the type both share, as `self.eq(val)`
|
|
165
167
|
# compares: an integer array searched with a Float is compared in
|
|
@@ -201,7 +203,10 @@ class CArray
|
|
|
201
203
|
|
|
202
204
|
# @overload search_nearest(val)
|
|
203
205
|
# Returns the flat address of the element of `self` whose value
|
|
204
|
-
# is closest to `val`.
|
|
206
|
+
# is closest to `val`. Of several equally close elements, the one
|
|
207
|
+
# at the lowest address wins, as {#search} answers the first match
|
|
208
|
+
# (`[0, 2, 4].search_nearest(1)` is 0). {#locate_nearest_addr}
|
|
209
|
+
# rounds a position instead, and answers the larger value on a tie.
|
|
205
210
|
#
|
|
206
211
|
# In an `:object` array the distance is `val.distance(other)` when
|
|
207
212
|
# `val` answers `#distance`, and `(val - other).abs` when it is a
|
|
@@ -268,7 +273,9 @@ class CArray
|
|
|
268
273
|
# `self` is coerced to `:float64` if it is not already. When
|
|
269
274
|
# `axis: nil`, `self` is flattened to 1-D first.
|
|
270
275
|
#
|
|
271
|
-
#
|
|
276
|
+
# A position with no answer -- out of range, or between samples one
|
|
277
|
+
# of which is NaN -- gives `nil` for a scalar `addr` and NaN in the
|
|
278
|
+
# cell of an array result.
|
|
272
279
|
#
|
|
273
280
|
# Because this half of the pair returns a *value* rather than a
|
|
274
281
|
# position, a Face axis gets its Face back: `CATime#linear_fetch` /
|
|
@@ -280,5 +287,94 @@ class CArray
|
|
|
280
287
|
# @see file:docs/topics/LinearInterpolation.md
|
|
281
288
|
def linear_fetch(addr, axis: nil); end
|
|
282
289
|
|
|
290
|
+
# @overload nlargest(n, axis: nil)
|
|
291
|
+
# Returns the `n` largest values, largest first. Without `axis:` the
|
|
292
|
+
# array is read flat; with it, each fiber along `axis` gives its own
|
|
293
|
+
# `n` and the axis keeps length `n`. A NaN and a masked cell lose to
|
|
294
|
+
# every value; when fewer cells remain than `n`, the result is
|
|
295
|
+
# shorter (or, per fiber, ends in UNDEF).
|
|
296
|
+
# @param n [Integer] how many values, 0 or more.
|
|
297
|
+
# @param axis [Integer, nil]
|
|
298
|
+
# @return [CArray]
|
|
299
|
+
# @raise [ArgumentError] when `n` is negative.
|
|
300
|
+
def nlargest(n, axis: nil); end
|
|
301
|
+
|
|
302
|
+
# @overload nsmallest(n, axis: nil)
|
|
303
|
+
# Returns the `n` smallest values, smallest first. As {#nlargest}
|
|
304
|
+
# otherwise.
|
|
305
|
+
# @param n [Integer]
|
|
306
|
+
# @param axis [Integer, nil]
|
|
307
|
+
# @return [CArray]
|
|
308
|
+
# @raise [ArgumentError] when `n` is negative.
|
|
309
|
+
def nsmallest(n, axis: nil); end
|
|
310
|
+
|
|
311
|
+
# @overload nlargest_index(n, axis:)
|
|
312
|
+
# Returns, along `axis`, the axis-local positions of each fiber's `n`
|
|
313
|
+
# largest values, largest first (`take_along_axis` reads the values
|
|
314
|
+
# back). `axis:` is required.
|
|
315
|
+
# @param n [Integer]
|
|
316
|
+
# @param axis [Integer]
|
|
317
|
+
# @return [CArray] `:int64` positions.
|
|
318
|
+
# @raise [ArgumentError] when `axis:` is missing or `n` is negative.
|
|
319
|
+
def nlargest_index(n, axis:); end
|
|
320
|
+
|
|
321
|
+
# @overload nsmallest_index(n, axis:)
|
|
322
|
+
# As {#nlargest_index}, for the `n` smallest values.
|
|
323
|
+
# @param n [Integer]
|
|
324
|
+
# @param axis [Integer]
|
|
325
|
+
# @return [CArray] `:int64` positions.
|
|
326
|
+
# @raise [ArgumentError] when `axis:` is missing or `n` is negative.
|
|
327
|
+
def nsmallest_index(n, axis:); end
|
|
328
|
+
|
|
329
|
+
# @overload sort_by_key(key, axis: 0)
|
|
330
|
+
# Returns `self` reordered along `axis` by the order of `key` (an
|
|
331
|
+
# array of `self`'s shape): `self[key.sort_addr(axis:)]`.
|
|
332
|
+
# @param key [CArray] the values to order by.
|
|
333
|
+
# @param axis [Integer]
|
|
334
|
+
# @return [CArray]
|
|
335
|
+
# @raise [ArgumentError] when `key`'s shape differs from `self`'s.
|
|
336
|
+
def sort_by_key(key, axis: 0); end
|
|
337
|
+
|
|
338
|
+
# @overload max_by_key(key, axis: nil)
|
|
339
|
+
# Returns the value of `self` where `key` is largest: one value, or
|
|
340
|
+
# one per fiber along `axis`. UNDEF where there is no cell to compare.
|
|
341
|
+
# @param key [CArray] the values to compare, of `self`'s shape.
|
|
342
|
+
# @param axis [Integer, nil]
|
|
343
|
+
# @return [Object, CArray]
|
|
344
|
+
# @raise [ArgumentError] when `key`'s shape differs from `self`'s.
|
|
345
|
+
def max_by_key(key, axis: nil); end
|
|
346
|
+
|
|
347
|
+
# @overload min_by_key(key, axis: nil)
|
|
348
|
+
# As {#max_by_key}, where `key` is smallest.
|
|
349
|
+
# @param key [CArray]
|
|
350
|
+
# @param axis [Integer, nil]
|
|
351
|
+
# @return [Object, CArray]
|
|
352
|
+
# @raise [ArgumentError] when `key`'s shape differs from `self`'s.
|
|
353
|
+
def min_by_key(key, axis: nil); end
|
|
354
|
+
|
|
355
|
+
# @overload take_along_axis(indices, axis: 0)
|
|
356
|
+
# Returns the values of `self` at axis-local `indices` along `axis`
|
|
357
|
+
# (`indices` has `self`'s shape except along `axis`), as the
|
|
358
|
+
# `*_index(axis:)` methods answer them. A masked index reads UNDEF.
|
|
359
|
+
# @param indices [CArray] integer positions along `axis`.
|
|
360
|
+
# @param axis [Integer]
|
|
361
|
+
# @return [CArray]
|
|
362
|
+
def take_along_axis(indices, axis: 0); end
|
|
363
|
+
|
|
364
|
+
# @overload put_along_axis(indices, values, axis: 0)
|
|
365
|
+
# Writes `values` into `self` at axis-local `indices` along `axis`,
|
|
366
|
+
# the inverse of {#take_along_axis}. A masked index writes nothing.
|
|
367
|
+
# @param indices [CArray] integer positions along `axis`.
|
|
368
|
+
# @param values [CArray, Object]
|
|
369
|
+
# @param axis [Integer]
|
|
370
|
+
# @return [self]
|
|
371
|
+
def put_along_axis(indices, values, axis: 0); end
|
|
372
|
+
|
|
373
|
+
# @overload range
|
|
374
|
+
# Returns `min..max` of `self` from one pass (`UNDEF..UNDEF` when no
|
|
375
|
+
# cell takes part).
|
|
376
|
+
# @return [Range]
|
|
377
|
+
def range; end
|
|
378
|
+
|
|
283
379
|
# @!endgroup
|
|
284
380
|
end
|
|
@@ -104,13 +104,15 @@ class CArray
|
|
|
104
104
|
# allocates view state); useful in hot loops where a scatter
|
|
105
105
|
# result is written back many times.
|
|
106
106
|
#
|
|
107
|
-
# Unlike the arithmetic `scatter_*!` family, `self` may be
|
|
108
|
-
#
|
|
109
|
-
# `1` / `0`)
|
|
110
|
-
#
|
|
107
|
+
# Unlike the arithmetic `scatter_*!` family, `self` may be of any
|
|
108
|
+
# type (assignment does not widen): **boolean**, with `true` /
|
|
109
|
+
# `false` (or `1` / `0`) as its scalar values, and **object** or
|
|
110
|
+
# **fixlen**, written as `self.flatten[addrs] = vals` writes them
|
|
111
|
+
# (as `put_nd` and `put_along_axis` take them). A scalar `UNDEF`
|
|
112
|
+
# masks every addressed cell.
|
|
111
113
|
#
|
|
112
114
|
# @param addrs [CArray, Array<Integer>]
|
|
113
|
-
# @param vals [CArray,
|
|
115
|
+
# @param vals [CArray, Object, UNDEF]
|
|
114
116
|
# @return [self]
|
|
115
117
|
def scatter_replace!(addrs, vals); end
|
|
116
118
|
|