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,79 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_copy.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Copy and conversion
|
|
7
|
+
|
|
8
|
+
# @overload copy
|
|
9
|
+
# Returns a fresh entity CArray with the same shape, `data_type`,
|
|
10
|
+
# element values, and mask state as `self`. Always allocates and
|
|
11
|
+
# copies, even when `self` is already an entity.
|
|
12
|
+
#
|
|
13
|
+
# Use `copy` when you need an array you own and can mutate
|
|
14
|
+
# without affecting any source.
|
|
15
|
+
# @return [CArray] independent entity.
|
|
16
|
+
# @example A view's copy is independent of its source
|
|
17
|
+
# a = CArray.float64(4).seq
|
|
18
|
+
# v = a[1..2]
|
|
19
|
+
# b = v.copy
|
|
20
|
+
# b[0] = 99
|
|
21
|
+
# a # => [0.0, 1.0, 2.0, 3.0] # untouched
|
|
22
|
+
def copy; end
|
|
23
|
+
|
|
24
|
+
# @overload to_ca(writable: false)
|
|
25
|
+
# Returns `self` as a CArray, doing the least work possible.
|
|
26
|
+
#
|
|
27
|
+
# For a CArray (entity or data view), `to_ca` returns `self`
|
|
28
|
+
# unchanged — **no copy is made**. Use {#copy} when you need an
|
|
29
|
+
# independent owned array. Mutating the result of `to_ca` may
|
|
30
|
+
# therefore mutate the source.
|
|
31
|
+
#
|
|
32
|
+
# `to_ca` is the universal "give me a CArray" entry point. It is
|
|
33
|
+
# also defined on `Array` / `Range` / `Enumerator::ArithmeticSequence`
|
|
34
|
+
# (each builds a 1-D CArray) and on lazy views (`CAMonOp`, `CABinOp`,
|
|
35
|
+
# …) where it forces evaluation into a fresh entity.
|
|
36
|
+
#
|
|
37
|
+
# Because it converts as cheaply as it can — sharing storage where it
|
|
38
|
+
# can, copying where it must — the result alone does not tell you
|
|
39
|
+
# whether writes to it reach the source. `writable: true` is how a
|
|
40
|
+
# caller states that they do have to: an implementation that can only
|
|
41
|
+
# hand back a detached copy raises instead of returning one, so a
|
|
42
|
+
# write is never swallowed silently. For a CArray, `self` shares its
|
|
43
|
+
# storage by construction, so the only refusal here is a read-only
|
|
44
|
+
# receiver. This is the contract {CArray.wrap_writable} duck-types on.
|
|
45
|
+
# @param writable [Boolean] when true, demand a result whose writes
|
|
46
|
+
# reach the source.
|
|
47
|
+
# @return [CArray] `self` (no copy).
|
|
48
|
+
# @raise [RuntimeError] when `writable: true` and `self` is read-only.
|
|
49
|
+
def to_ca(writable: false); end
|
|
50
|
+
|
|
51
|
+
# @overload template
|
|
52
|
+
# Returns a freshly allocated CArray with the same shape and
|
|
53
|
+
# `data_type` as `self`, filled with zeros. The new array is an
|
|
54
|
+
# entity and carries no mask.
|
|
55
|
+
# @return [CArray]
|
|
56
|
+
# @overload template(data_type, bytes: 0)
|
|
57
|
+
# Returns a freshly allocated CArray with the same shape as
|
|
58
|
+
# `self` but the given `data_type`, filled with zeros.
|
|
59
|
+
# @param data_type [Symbol] target element type
|
|
60
|
+
# (e.g. `:int32`, `:float64`, `:fixlen`).
|
|
61
|
+
# @param bytes [Integer] element byte size; required for
|
|
62
|
+
# `:fixlen`, ignored for numeric types.
|
|
63
|
+
# @return [CArray]
|
|
64
|
+
# @overload template { value }
|
|
65
|
+
# With a 0-arity block, fills every element of the result with
|
|
66
|
+
# the block's return value (broadcast). Equivalent to
|
|
67
|
+
# `template.tap { |t| t[] = value }`.
|
|
68
|
+
# @yieldreturn [Object] value to broadcast to every element.
|
|
69
|
+
# @return [CArray]
|
|
70
|
+
# @overload template { |*idx| ... }
|
|
71
|
+
# With a block of arity > 0, calls the block once per cell with
|
|
72
|
+
# the multi-dimensional index `*idx` and stores the result.
|
|
73
|
+
# @yieldparam idx [Array<Integer>] per-axis indices.
|
|
74
|
+
# @yieldreturn [Object]
|
|
75
|
+
# @return [CArray]
|
|
76
|
+
def template(*, **, &block); end
|
|
77
|
+
|
|
78
|
+
# @!endgroup
|
|
79
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_core.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Attach lifecycle
|
|
7
|
+
#
|
|
8
|
+
# The `attach` / `attach!` family is an internal lifecycle API used
|
|
9
|
+
# by library authors writing CArray-aware C extensions. End users
|
|
10
|
+
# should not normally need to call these methods — view algebra and
|
|
11
|
+
# `CArray#[]` / `[]=` handle attach/sync transparently.
|
|
12
|
+
#
|
|
13
|
+
# The block-form `attach` (no sync on exit) and `attach!` (sync on
|
|
14
|
+
# exit) wrap a body of code so that the underlying memory block is
|
|
15
|
+
# guaranteed to be materialized while the block runs and is
|
|
16
|
+
# released afterward. The dunder forms (`__attach__`, `__sync__`,
|
|
17
|
+
# `__detach__`) expose the raw three-step protocol for callers that
|
|
18
|
+
# cannot use a block.
|
|
19
|
+
|
|
20
|
+
# @overload attach { ... }
|
|
21
|
+
# Attaches `self`, yields, and detaches on block exit. No sync
|
|
22
|
+
# is performed.
|
|
23
|
+
# @yield
|
|
24
|
+
# @return [Object] the block's return value.
|
|
25
|
+
def attach; end
|
|
26
|
+
|
|
27
|
+
# @overload attach! { ... }
|
|
28
|
+
# Attaches `self`, yields, then syncs and detaches on block exit.
|
|
29
|
+
# Use this form when the block mutates `self.ptr` and you need
|
|
30
|
+
# the changes flushed back to the parent.
|
|
31
|
+
# @yield
|
|
32
|
+
# @return [Object] the block's return value.
|
|
33
|
+
def attach!; end
|
|
34
|
+
|
|
35
|
+
# @private
|
|
36
|
+
# @overload __attach__
|
|
37
|
+
# Raw attach: materializes the memory block of `self` and leaves
|
|
38
|
+
# it attached. Caller is responsible for the matching
|
|
39
|
+
# `__detach__` (and `__sync__`, if changes were made).
|
|
40
|
+
#
|
|
41
|
+
# Prefer the block form {#attach!} unless block scope is
|
|
42
|
+
# impossible.
|
|
43
|
+
# @return [self]
|
|
44
|
+
# @api private
|
|
45
|
+
def __attach__; end
|
|
46
|
+
|
|
47
|
+
# @private
|
|
48
|
+
# @overload __sync__
|
|
49
|
+
# Raw sync: writes any pending changes in `self.ptr` back to the
|
|
50
|
+
# parent. Requires `self` to be currently attached.
|
|
51
|
+
# @return [self]
|
|
52
|
+
# @api private
|
|
53
|
+
def __sync__; end
|
|
54
|
+
|
|
55
|
+
# @private
|
|
56
|
+
# @overload __detach__
|
|
57
|
+
# Raw detach: releases the memory block paired with `__attach__`.
|
|
58
|
+
# @return [self]
|
|
59
|
+
# @api private
|
|
60
|
+
def __detach__; end
|
|
61
|
+
|
|
62
|
+
# @!endgroup
|
|
63
|
+
|
|
64
|
+
# @!group Attributes
|
|
65
|
+
|
|
66
|
+
# @overload members
|
|
67
|
+
# Returns the ordered list of member names for `self.data_class`.
|
|
68
|
+
# Only valid when `self` carries a `data_class` (e.g. a
|
|
69
|
+
# `CARecord`).
|
|
70
|
+
# @return [Array<Symbol>]
|
|
71
|
+
# @raise [RuntimeError] if `self` has no `data_class`.
|
|
72
|
+
def members; end
|
|
73
|
+
|
|
74
|
+
# @overload fields
|
|
75
|
+
# Returns one field view per member of `self.data_class`, in
|
|
76
|
+
# declaration order. Each entry is a CArray sharing storage with
|
|
77
|
+
# `self`.
|
|
78
|
+
# @return [Array<CArray>]
|
|
79
|
+
# @raise [RuntimeError] if `self` has no `data_class`.
|
|
80
|
+
def fields; end
|
|
81
|
+
|
|
82
|
+
# @overload fields_at(*names)
|
|
83
|
+
# Returns the field views for the named members of
|
|
84
|
+
# `self.data_class`, in the given order.
|
|
85
|
+
# @param names [Array<Symbol, String, Integer>] member names or
|
|
86
|
+
# positional indices.
|
|
87
|
+
# @return [Array<CArray>]
|
|
88
|
+
# @raise [RuntimeError] if `self` has no `data_class`.
|
|
89
|
+
def fields_at(*names); end
|
|
90
|
+
|
|
91
|
+
# @!endgroup
|
|
92
|
+
|
|
93
|
+
class << self
|
|
94
|
+
# @!group Attach lifecycle
|
|
95
|
+
|
|
96
|
+
# @overload attach(*arrays) { ... }
|
|
97
|
+
# Attaches every CArray in `arrays`, yields, and detaches them
|
|
98
|
+
# in reverse order on block exit. No sync is performed.
|
|
99
|
+
# @param arrays [Array<CArray>]
|
|
100
|
+
# @yield
|
|
101
|
+
# @return [Object] the block's return value.
|
|
102
|
+
def attach(*arrays); end
|
|
103
|
+
|
|
104
|
+
# @overload attach!(*arrays) { ... }
|
|
105
|
+
# Attaches every CArray in `arrays`, yields, then syncs and
|
|
106
|
+
# detaches each on block exit.
|
|
107
|
+
# @param arrays [Array<CArray>]
|
|
108
|
+
# @yield
|
|
109
|
+
# @return [Object] the block's return value.
|
|
110
|
+
def attach!(*arrays); end
|
|
111
|
+
|
|
112
|
+
# @!endgroup
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stub for CArray#count defined in ext/carray_count.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Statistics
|
|
7
|
+
|
|
8
|
+
# @overload count(axis: nil)
|
|
9
|
+
# With no value argument, returns the number of present (not-masked)
|
|
10
|
+
# cells — the arity-0 rung of the dispatch ladder, answering "how
|
|
11
|
+
# many are there". Forwards to {#count_not_masked} (which stays as
|
|
12
|
+
# an explicit, self-documenting named method).
|
|
13
|
+
#
|
|
14
|
+
# @param axis [Integer, Array<Integer>, nil] reduction axis or
|
|
15
|
+
# axes; `nil` reduces fully.
|
|
16
|
+
# @return [Integer, CArray] `Integer` when `axis` is `nil`,
|
|
17
|
+
# otherwise a `CArray` of int64 with the given axes collapsed.
|
|
18
|
+
#
|
|
19
|
+
# @overload count(v, axis: nil, min_count: 0, fill_value: nil)
|
|
20
|
+
# Returns the number of cells of `self` that equal `v`, with
|
|
21
|
+
# mask-aware reduction along `axis`.
|
|
22
|
+
#
|
|
23
|
+
# `count` is an orthogonal arity-dispatch ladder (like Ruby's
|
|
24
|
+
# `Array#count`): no argument counts present cells, `count(UNDEF)`
|
|
25
|
+
# counts masked cells, and `count(v)` counts cells equal to `v`.
|
|
26
|
+
# Mask-cardinality and value-match are distinct concepts, so the
|
|
27
|
+
# overloading is unambiguous.
|
|
28
|
+
#
|
|
29
|
+
# Dispatch:
|
|
30
|
+
# - no argument: forwards to {#count_not_masked} (present-cell
|
|
31
|
+
# count).
|
|
32
|
+
# - `v == UNDEF`: forwards to {#count_masked} (UNDEF is mask-state
|
|
33
|
+
# vocabulary, not a value).
|
|
34
|
+
# - `v` is a CArray: broadcasts; each `v[k]` is counted
|
|
35
|
+
# independently and stacked into a result whose trailing axes
|
|
36
|
+
# have shape `v.shape`. Not supported when `self.data_type` is
|
|
37
|
+
# `:boolean`.
|
|
38
|
+
# - `self.data_type == :boolean`: `v` must be `true` / `false`, or
|
|
39
|
+
# the integer literal `1` (= true) / `0` (= false) — boolean
|
|
40
|
+
# stores 0/1, so `count(1)` == `count(true)`. Any other value
|
|
41
|
+
# (`2`, `1.0`, `nil`, …) raises `TypeError`.
|
|
42
|
+
# - `self` is numeric, `v` is scalar: `v` must be numeric (true /
|
|
43
|
+
# false are rejected).
|
|
44
|
+
#
|
|
45
|
+
# When `axis` is `nil` (default), reduces over all axes and
|
|
46
|
+
# returns an `Integer`. Otherwise reduces along the given
|
|
47
|
+
# axis / axes and returns a `CArray`.
|
|
48
|
+
#
|
|
49
|
+
# An empty or fully-masked reduction returns `0`: a count has
|
|
50
|
+
# identity `0`, so the count over no cells is `0`, not `UNDEF`
|
|
51
|
+
# (pass `min_count:` to get `UNDEF` below a threshold instead).
|
|
52
|
+
#
|
|
53
|
+
# `:fixlen` and `:object` data types raise `CArray::DataTypeError`.
|
|
54
|
+
#
|
|
55
|
+
# A time array counts by its own values: `CATime` / `CATimedelta`
|
|
56
|
+
# descend to their storage and reconcile `v` into their unit, so `v`
|
|
57
|
+
# may be an element of the array, another time array (in any unit that
|
|
58
|
+
# converts exactly), or a Ruby `Time` / `DateTime`. A bare storage
|
|
59
|
+
# number is refused — use `ca.parent.count(n)` to count raw ticks.
|
|
60
|
+
#
|
|
61
|
+
# @param v [Object, CArray] value (or array of values) to count.
|
|
62
|
+
# `UNDEF` is treated as a mask-state query.
|
|
63
|
+
# @param axis [Integer, Array<Integer>, nil] reduction axis or
|
|
64
|
+
# axes; `nil` reduces fully.
|
|
65
|
+
# @param min_count [Integer] minimum number of non-masked cells
|
|
66
|
+
# required per reduced slice; slices below the threshold come
|
|
67
|
+
# back masked. Accepted only by the value-argument form
|
|
68
|
+
# (`count(v)`); the no-argument form accepts `axis:` only.
|
|
69
|
+
# @param fill_value [Object, nil] replacement for masked output
|
|
70
|
+
# cells; `nil` leaves them masked. Value-argument form only.
|
|
71
|
+
# @return [Integer, CArray]
|
|
72
|
+
# @raise [TypeError] when `v`'s type does not match the dispatch
|
|
73
|
+
# rule above.
|
|
74
|
+
# @raise [CArray::DataTypeError] when `self.data_type` is
|
|
75
|
+
# `:fixlen` or `:object`.
|
|
76
|
+
def count(*args, axis: nil, min_count: 0, fill_value: nil); end
|
|
77
|
+
|
|
78
|
+
# @!endgroup
|
|
79
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_element.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Element access
|
|
7
|
+
#
|
|
8
|
+
# `elem_*` methods are low-level single-cell operations. They
|
|
9
|
+
# accept `idx` as either an Integer (flat address into the
|
|
10
|
+
# row-major element sequence) or an `Array<Integer>` (one index
|
|
11
|
+
# per axis). They bypass the broadcasting and view-construction
|
|
12
|
+
# paths used by `[]` / `[]=`, and are the right tool for
|
|
13
|
+
# tight per-cell loops where allocation matters.
|
|
14
|
+
|
|
15
|
+
# @overload elem_swap(idx1, idx2)
|
|
16
|
+
# Exchanges the values (and mask states, if any) at positions
|
|
17
|
+
# `idx1` and `idx2`. Mutates `self`.
|
|
18
|
+
# @param idx1 [Integer, Array<Integer>]
|
|
19
|
+
# @param idx2 [Integer, Array<Integer>]
|
|
20
|
+
# @return [self]
|
|
21
|
+
def elem_swap(idx1, idx2); end
|
|
22
|
+
|
|
23
|
+
# @overload elem_copy(idx1, idx2)
|
|
24
|
+
# Copies the value (and mask state) at `idx1` into the cell at
|
|
25
|
+
# `idx2`. The source cell is unchanged. Mutates `self`.
|
|
26
|
+
# @param idx1 [Integer, Array<Integer>] source position.
|
|
27
|
+
# @param idx2 [Integer, Array<Integer>] destination position.
|
|
28
|
+
# @return [self]
|
|
29
|
+
def elem_copy(idx1, idx2); end
|
|
30
|
+
|
|
31
|
+
# @overload elem_store(idx, value)
|
|
32
|
+
# Stores `value` (cast to `self.data_type`) at position `idx`,
|
|
33
|
+
# clearing the mask state at that cell. Passing `UNDEF` masks
|
|
34
|
+
# the cell.
|
|
35
|
+
# @param idx [Integer, Array<Integer>]
|
|
36
|
+
# @param value [Object]
|
|
37
|
+
# @return [Object] `value`.
|
|
38
|
+
def elem_store(idx, value); end
|
|
39
|
+
|
|
40
|
+
# @overload elem_fetch(idx)
|
|
41
|
+
# Returns the value at position `idx` (cast back to the
|
|
42
|
+
# appropriate Ruby type). Returns `UNDEF` if the cell is masked.
|
|
43
|
+
# Returns `nil` if `self.empty?`.
|
|
44
|
+
# @param idx [Integer, Array<Integer>]
|
|
45
|
+
# @return [Object, nil]
|
|
46
|
+
def elem_fetch(idx); end
|
|
47
|
+
|
|
48
|
+
# @overload elem_incr(idx)
|
|
49
|
+
# Increments the value at `idx` by 1 in place. Mutates `self`.
|
|
50
|
+
# Masked cells are skipped.
|
|
51
|
+
# @param idx [Integer, Array<Integer>]
|
|
52
|
+
# @return [self]
|
|
53
|
+
def elem_incr(idx); end
|
|
54
|
+
|
|
55
|
+
# @overload elem_decr(idx)
|
|
56
|
+
# Decrements the value at `idx` by 1 in place. Mutates `self`.
|
|
57
|
+
# Masked cells are skipped.
|
|
58
|
+
# @param idx [Integer, Array<Integer>]
|
|
59
|
+
# @return [self]
|
|
60
|
+
def elem_decr(idx); end
|
|
61
|
+
|
|
62
|
+
# @overload elem_min(idx, v)
|
|
63
|
+
# Updates the cell at `idx` to `min(self[idx], v)`. Mutates `self`.
|
|
64
|
+
#
|
|
65
|
+
# Masked cells are skipped. NaN follows the `fmin` rule (NaN is
|
|
66
|
+
# treated as missing: `min(NaN, v) == v`, `min(x, NaN) == x`).
|
|
67
|
+
# @param idx [Integer, Array<Integer>]
|
|
68
|
+
# @param v [Numeric]
|
|
69
|
+
# @return [self]
|
|
70
|
+
# @raise [CArray::DataTypeError] for non-numeric `data_type`.
|
|
71
|
+
def elem_min(idx, v); end
|
|
72
|
+
|
|
73
|
+
# @overload elem_max(idx, v)
|
|
74
|
+
# Updates the cell at `idx` to `max(self[idx], v)`. Mutates `self`.
|
|
75
|
+
#
|
|
76
|
+
# Masked cells are skipped. NaN follows the `fmax` rule.
|
|
77
|
+
# @param idx [Integer, Array<Integer>]
|
|
78
|
+
# @param v [Numeric]
|
|
79
|
+
# @return [self]
|
|
80
|
+
# @raise [CArray::DataTypeError] for non-numeric `data_type`.
|
|
81
|
+
def elem_max(idx, v); end
|
|
82
|
+
|
|
83
|
+
# @!endgroup
|
|
84
|
+
|
|
85
|
+
# @!group Element access
|
|
86
|
+
|
|
87
|
+
# @overload elem_masked?(idx)
|
|
88
|
+
# Returns `true` if the cell at `idx` is masked.
|
|
89
|
+
# @param idx [Integer, Array<Integer>]
|
|
90
|
+
# @return [Boolean]
|
|
91
|
+
def elem_masked?(idx); end
|
|
92
|
+
|
|
93
|
+
# @overload elem_mask(idx)
|
|
94
|
+
# Marks the cell at `idx` as masked. Allocates the mask array if
|
|
95
|
+
# `self` does not yet have one. Mutates `self`.
|
|
96
|
+
# @param idx [Integer, Array<Integer>]
|
|
97
|
+
# @return [self]
|
|
98
|
+
def elem_mask(idx); end
|
|
99
|
+
|
|
100
|
+
# @overload elem_unmask(idx)
|
|
101
|
+
# Clears the mask state at `idx`, leaving the stored data
|
|
102
|
+
# unchanged. Mutates `self`.
|
|
103
|
+
# @param idx [Integer, Array<Integer>]
|
|
104
|
+
# @return [self]
|
|
105
|
+
def elem_unmask(idx); end
|
|
106
|
+
|
|
107
|
+
# @!endgroup
|
|
108
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_generate.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Scatter and generation
|
|
7
|
+
|
|
8
|
+
# @overload where
|
|
9
|
+
# Returns a fresh 1-D CArray of flat addresses where `self` is
|
|
10
|
+
# non-zero (or `true`). Masked positions are excluded.
|
|
11
|
+
# Non-boolean arrays are first coerced to boolean.
|
|
12
|
+
# @return [CArray] 1-D, `:int64` (`ca_size_t`).
|
|
13
|
+
# @example
|
|
14
|
+
# CArray.int32(5) { [0, 1, 0, 2, 0] }.where.to_a
|
|
15
|
+
# # => [1, 3]
|
|
16
|
+
def where; end
|
|
17
|
+
|
|
18
|
+
# @!endgroup
|
|
19
|
+
|
|
20
|
+
# @!group Scatter and generation
|
|
21
|
+
|
|
22
|
+
# @overload seq!
|
|
23
|
+
# Fills `self` in row-major order with `0, 1, 2, ...`. Mutates
|
|
24
|
+
# `self` and clears any mask.
|
|
25
|
+
# @return [self]
|
|
26
|
+
# @overload seq!(init_val)
|
|
27
|
+
# Fills `self` in row-major order with `init_val`, `init_val + 1`,
|
|
28
|
+
# `init_val + 2`, ... Mutates `self`.
|
|
29
|
+
# @param init_val [Numeric]
|
|
30
|
+
# @return [self]
|
|
31
|
+
# @overload seq!(init_val, step)
|
|
32
|
+
# Fills `self` in row-major order with `init_val`, `init_val +
|
|
33
|
+
# step`, `init_val + 2*step`, ...
|
|
34
|
+
#
|
|
35
|
+
# For `:object` arrays only, `step` may be a Symbol naming the
|
|
36
|
+
# stepping method to invoke on the previous element (e.g. `:succ`).
|
|
37
|
+
# @param init_val [Numeric, Object]
|
|
38
|
+
# @param step [Numeric, Symbol]
|
|
39
|
+
# @return [self]
|
|
40
|
+
# @overload seq!(init_val = 0, step = 1, axis:)
|
|
41
|
+
# Fills `self` with a progression that runs along `axis` and repeats
|
|
42
|
+
# across the other axes: the cell value depends only on its
|
|
43
|
+
# coordinate along `axis`. `axis` must be a single integer (a
|
|
44
|
+
# negative value counts from the end); multi-axis fills are not
|
|
45
|
+
# supported.
|
|
46
|
+
# @param init_val [Numeric, Object]
|
|
47
|
+
# @param step [Numeric, Symbol]
|
|
48
|
+
# @param axis [Integer] the axis the progression runs along.
|
|
49
|
+
# @return [self]
|
|
50
|
+
# @raise [ArgumentError] if `axis` is out of range or not a single
|
|
51
|
+
# integer.
|
|
52
|
+
def seq!(*); end
|
|
53
|
+
|
|
54
|
+
# @overload seq(init_val = 0, step = 1, axis: nil)
|
|
55
|
+
# Equivalent to `dup.seq!(init_val, step, axis: axis)`. Returns a
|
|
56
|
+
# fresh array of the same shape and `data_type` as `self`, filled
|
|
57
|
+
# with a sequence (flat by default, or along `axis` when given).
|
|
58
|
+
# @param init_val [Numeric, Object]
|
|
59
|
+
# @param step [Numeric, Symbol]
|
|
60
|
+
# @param axis [Integer, nil] the axis the progression runs along,
|
|
61
|
+
# or `nil` for a flat row-major fill.
|
|
62
|
+
# @return [CArray]
|
|
63
|
+
def seq(*); end
|
|
64
|
+
|
|
65
|
+
# @!endgroup
|
|
66
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_lazy.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
# Zero-cost marker view that dispatches subsequent element-wise ops
|
|
6
|
+
# into the lazy CAMonOp / CABinOp tree instead of evaluating eagerly.
|
|
7
|
+
# Read-only; `.to_ca` materialises.
|
|
8
|
+
class CALazyMarker < CAView
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class CArray
|
|
12
|
+
# @!group Views
|
|
13
|
+
# @overload lazy
|
|
14
|
+
# Returns a {CALazyMarker} view wrapping `self`. Subsequent
|
|
15
|
+
# element-wise ops on the marker (`m.sqrt`, `m + 1`, ...) build
|
|
16
|
+
# a lazy expression tree; call `.to_ca` on the result to
|
|
17
|
+
# materialise. The marker is transient — a Ruby reference can
|
|
18
|
+
# re-consume it (`m = a.lazy; m.sqrt + m.sin`) without side
|
|
19
|
+
# effects on `self`.
|
|
20
|
+
# @return [CALazyMarker]
|
|
21
|
+
def lazy; end
|
|
22
|
+
# @!endgroup
|
|
23
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# DOCUMENTATION ONLY — DO NOT REQUIRE.
|
|
2
|
+
# Stubs for methods defined in ext/carray_loop.c.
|
|
3
|
+
# See yard-stubs/README.md and yard-stubs/STYLE.md.
|
|
4
|
+
|
|
5
|
+
class CArray
|
|
6
|
+
# @!group Iteration
|
|
7
|
+
|
|
8
|
+
# @overload each
|
|
9
|
+
# Yields each element of `self` once in row-major (flat address)
|
|
10
|
+
# order. Returns an Enumerator when no block is given.
|
|
11
|
+
# @yieldparam elem [Object]
|
|
12
|
+
# @return [self, Enumerator]
|
|
13
|
+
def each; end
|
|
14
|
+
|
|
15
|
+
# @overload each_addr
|
|
16
|
+
# Yields each flat address `0...elements` once. Returns an
|
|
17
|
+
# Enumerator when no block is given.
|
|
18
|
+
# @yieldparam addr [Integer]
|
|
19
|
+
# @return [self, Enumerator]
|
|
20
|
+
def each_addr; end
|
|
21
|
+
|
|
22
|
+
# @overload each_index
|
|
23
|
+
# Yields each multi-dimensional index of `self` once in row-major
|
|
24
|
+
# order. Block receives one Integer per axis (variadic, not a
|
|
25
|
+
# single Array); use `|*idx|` to collect them. Returns an
|
|
26
|
+
# Enumerator when no block is given.
|
|
27
|
+
# @yieldparam idx [Integer] one Integer per axis.
|
|
28
|
+
# @return [self, Enumerator]
|
|
29
|
+
def each_index; end
|
|
30
|
+
|
|
31
|
+
# @overload each_with_addr
|
|
32
|
+
# Yields each `(element, flat-address)` pair in row-major order.
|
|
33
|
+
# Returns an Enumerator when no block is given.
|
|
34
|
+
# @yieldparam elem [Object]
|
|
35
|
+
# @yieldparam addr [Integer]
|
|
36
|
+
# @return [self, Enumerator]
|
|
37
|
+
def each_with_addr; end
|
|
38
|
+
|
|
39
|
+
# @overload each_with_index
|
|
40
|
+
# Yields each element followed by its multi-dimensional index
|
|
41
|
+
# components in row-major order. Block signature is
|
|
42
|
+
# `|elem, i, j, ...|` (one Integer per axis, not a single Array);
|
|
43
|
+
# use `|elem, *idx|` to collect them. Returns an Enumerator when
|
|
44
|
+
# no block is given.
|
|
45
|
+
# @yieldparam elem [Object]
|
|
46
|
+
# @yieldparam idx [Integer] one Integer per axis.
|
|
47
|
+
# @return [self, Enumerator]
|
|
48
|
+
def each_with_index; end
|
|
49
|
+
|
|
50
|
+
# @!endgroup
|
|
51
|
+
|
|
52
|
+
# @!group Iteration
|
|
53
|
+
|
|
54
|
+
# @overload map!
|
|
55
|
+
# Replaces each element of `self` with the block's return value.
|
|
56
|
+
# Mutates `self`.
|
|
57
|
+
# @yieldparam elem [Object]
|
|
58
|
+
# @yieldreturn [Object] new value for the cell.
|
|
59
|
+
# @return [self]
|
|
60
|
+
def map!; end
|
|
61
|
+
|
|
62
|
+
# @overload map_addr!
|
|
63
|
+
# Replaces each element of `self` with the block's return value;
|
|
64
|
+
# the block receives the flat address rather than the current
|
|
65
|
+
# value. Mutates `self`.
|
|
66
|
+
# @yieldparam addr [Integer]
|
|
67
|
+
# @yieldreturn [Object]
|
|
68
|
+
# @return [self]
|
|
69
|
+
def map_addr!; end
|
|
70
|
+
|
|
71
|
+
# @overload map_index!
|
|
72
|
+
# Replaces each element of `self` with the block's return value;
|
|
73
|
+
# the block receives the multi-dimensional index components
|
|
74
|
+
# (`|i, j, ...|`, one Integer per axis; use `|*idx|` to collect
|
|
75
|
+
# them) rather than the current value. Mutates `self`.
|
|
76
|
+
# @yieldparam idx [Integer] one Integer per axis.
|
|
77
|
+
# @yieldreturn [Object]
|
|
78
|
+
# @return [self]
|
|
79
|
+
def map_index!; end
|
|
80
|
+
|
|
81
|
+
# @overload map_with_addr!
|
|
82
|
+
# Replaces each element of `self` with the block's return value;
|
|
83
|
+
# the block receives `(element, flat-address)`. Mutates `self`.
|
|
84
|
+
# @yieldparam elem [Object]
|
|
85
|
+
# @yieldparam addr [Integer]
|
|
86
|
+
# @yieldreturn [Object]
|
|
87
|
+
# @return [self]
|
|
88
|
+
def map_with_addr!; end
|
|
89
|
+
|
|
90
|
+
# @overload map_with_index!
|
|
91
|
+
# Replaces each element of `self` with the block's return value;
|
|
92
|
+
# the block receives the element followed by its multi-dim index
|
|
93
|
+
# components (`|elem, i, j, ...|`; use `|elem, *idx|` to collect
|
|
94
|
+
# the index). Mutates `self`.
|
|
95
|
+
# @yieldparam elem [Object]
|
|
96
|
+
# @yieldparam idx [Integer] one Integer per axis.
|
|
97
|
+
# @yieldreturn [Object]
|
|
98
|
+
# @return [self]
|
|
99
|
+
def map_with_index!; end
|
|
100
|
+
|
|
101
|
+
# @overload collect!
|
|
102
|
+
# Alias of {#map!}.
|
|
103
|
+
def collect!; end
|
|
104
|
+
|
|
105
|
+
# @overload collect_addr!
|
|
106
|
+
# Alias of {#map_addr!}.
|
|
107
|
+
def collect_addr!; end
|
|
108
|
+
|
|
109
|
+
# @overload collect_index!
|
|
110
|
+
# Alias of {#map_index!}.
|
|
111
|
+
def collect_index!; end
|
|
112
|
+
|
|
113
|
+
# @overload collect_with_addr!
|
|
114
|
+
# Alias of {#map_with_addr!}.
|
|
115
|
+
def collect_with_addr!; end
|
|
116
|
+
|
|
117
|
+
# @overload collect_with_index!
|
|
118
|
+
# Alias of {#map_with_index!}.
|
|
119
|
+
def collect_with_index!; end
|
|
120
|
+
|
|
121
|
+
# @!endgroup
|
|
122
|
+
|
|
123
|
+
class << self
|
|
124
|
+
# @!group Iteration
|
|
125
|
+
|
|
126
|
+
# @overload each_index(*shape) { |*idx| ... }
|
|
127
|
+
# Yields each multi-dimensional index inside the box `0...d`
|
|
128
|
+
# for each `d` in `shape`, in row-major order. Independent of
|
|
129
|
+
# any CArray instance.
|
|
130
|
+
# @param shape [Array<Integer>] one extent per axis.
|
|
131
|
+
# @yieldparam idx [Array<Integer>] one index per axis.
|
|
132
|
+
# @return [Object] the block's last return value.
|
|
133
|
+
# @example
|
|
134
|
+
# CArray.each_index(3, 2) { |i, j| print "(#{i} #{j}) " }
|
|
135
|
+
# # (0 0) (0 1) (1 0) (1 1) (2 0) (2 1)
|
|
136
|
+
def each_index(*shape); end
|
|
137
|
+
|
|
138
|
+
# @!endgroup
|
|
139
|
+
end
|
|
140
|
+
end
|