carray 3.0.0 → 3.0.2

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.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/CHANGELOG.md +845 -3
  4. data/{NEWS.md → CHANGELOG.v1.md} +1 -1
  5. data/README.md +33 -33
  6. data/carray.gemspec +12 -8
  7. data/ext/ca_axis_dispatch.c +33 -4
  8. data/ext/ca_axis_group.c +256 -114
  9. data/ext/ca_binop_dispatch.c +5 -6
  10. data/ext/ca_binop_dispatch.h +0 -7
  11. data/ext/ca_categorical_iterator.c +121 -67
  12. data/ext/ca_for_each_element.h +6 -8
  13. data/ext/ca_group_iter.c +1 -1
  14. data/ext/ca_kernel_iterator.c +386 -74
  15. data/ext/ca_kernel_iterator.h +145 -45
  16. data/ext/ca_obj_array.c +62 -20
  17. data/ext/ca_obj_bincmp.c +57 -27
  18. data/ext/ca_obj_binop.c +86 -30
  19. data/ext/ca_obj_block.c +4 -4
  20. data/ext/ca_obj_const_string.c +88 -27
  21. data/ext/ca_obj_face.c +104 -0
  22. data/ext/ca_obj_face.h +48 -1
  23. data/ext/ca_obj_fake.c +11 -0
  24. data/ext/ca_obj_fixlen_string.c +21 -6
  25. data/ext/ca_obj_grid.c +11 -3
  26. data/ext/ca_obj_meld.c +125 -22
  27. data/ext/ca_obj_moncmp.c +33 -14
  28. data/ext/ca_obj_monop.c +19 -7
  29. data/ext/ca_obj_object.c +107 -4
  30. data/ext/ca_obj_record.c +3 -1
  31. data/ext/ca_obj_refer.c +30 -6
  32. data/ext/ca_obj_roll.c +13 -5
  33. data/ext/ca_obj_select.c +49 -34
  34. data/ext/ca_obj_select_axis.c +16 -6
  35. data/ext/ca_obj_shift.c +3 -3
  36. data/ext/ca_obj_stack.c +3 -8
  37. data/ext/ca_obj_stride.c +178 -24
  38. data/ext/ca_obj_string.c +11 -5
  39. data/ext/ca_obj_tile.c +13 -5
  40. data/ext/ca_obj_time.c +3 -1
  41. data/ext/ca_obj_timedelta.c +3 -1
  42. data/ext/ca_obj_transpose.c +1 -1
  43. data/ext/ca_obj_triop.c +62 -23
  44. data/ext/ca_obj_window.c +94 -19
  45. data/ext/ca_op_cmplx64.h +123 -0
  46. data/ext/ca_op_ipower.c +1 -5
  47. data/ext/ca_rng_normal.h +42 -0
  48. data/ext/ca_rng_xoshiro256pp.h +105 -0
  49. data/ext/ca_sort_kernels.h +5 -5
  50. data/ext/ca_sweep_engine.c +362 -155
  51. data/ext/ca_sweep_engine.h +39 -9
  52. data/ext/ca_transform_common.c +7 -0
  53. data/ext/carray.h +148 -132
  54. data/ext/carray_access.c +83 -49
  55. data/ext/carray_address_basis.c +590 -0
  56. data/ext/carray_bincount.c +8 -8
  57. data/ext/carray_broadcast.c +102 -9
  58. data/ext/carray_build_flags.h +3 -0
  59. data/ext/carray_call_cfunc.c +2010 -335
  60. data/ext/carray_call_cfunc.h +153 -0
  61. data/ext/carray_cast.c +184 -72
  62. data/ext/carray_conversion.c +22 -22
  63. data/ext/carray_copy.c +67 -32
  64. data/ext/carray_core.c +140 -13
  65. data/ext/carray_count.c +10 -11
  66. data/ext/carray_element.c +7 -7
  67. data/ext/carray_factorize.c +72 -51
  68. data/ext/carray_hold.c +1 -1
  69. data/ext/carray_index_classifier.c +7 -21
  70. data/ext/carray_internal.h +36 -3
  71. data/ext/carray_kernels_bincmp.c +1 -0
  72. data/ext/carray_kernels_binop.c +320 -298
  73. data/ext/carray_kernels_init.c +1095 -0
  74. data/ext/carray_kernels_map.c +1 -0
  75. data/ext/carray_kernels_moncmp.c +1 -0
  76. data/ext/carray_kernels_monop.c +412 -411
  77. data/ext/carray_kernels_reduce_aggregate.c +256 -87
  78. data/ext/carray_kernels_reduce_boolean.c +1 -0
  79. data/ext/carray_kernels_reduce_cumulative.c +324 -54
  80. data/ext/carray_kernels_reduce_extreme.c +605 -58
  81. data/ext/carray_kernels_reduce_variance.c +1 -0
  82. data/ext/carray_kernels_scan.c +5 -4
  83. data/ext/carray_kernels_search.c +187 -106
  84. data/ext/carray_kernels_sort.c +1 -0
  85. data/ext/carray_kernels_triop.c +1 -0
  86. data/ext/carray_lazy.c +175 -5
  87. data/ext/carray_loop.c +7 -1
  88. data/ext/carray_mask.c +29 -13
  89. data/ext/carray_median_percentile.c +56 -1
  90. data/ext/carray_memory_view.c +46 -21
  91. data/ext/carray_operator.c +50 -53
  92. data/ext/carray_order.c +1 -1
  93. data/ext/carray_partition.c +4 -4
  94. data/ext/carray_random.c +391 -47
  95. data/ext/carray_scatter.c +1 -1
  96. data/ext/carray_slab.c +13 -0
  97. data/ext/carray_sort.c +22 -24
  98. data/ext/carray_sort_kernel.c +10 -10
  99. data/ext/carray_test.c +1 -1
  100. data/ext/extconf.rb +18 -0
  101. data/ext/mk_call_cfunc.rb +323 -145
  102. data/ext/mkkernel.rb +651 -129
  103. data/ext/ruby_carray.c +28 -17
  104. data/ext/version.h +4 -4
  105. data/lib/carray/autoload_carray.rb +24 -3
  106. data/lib/carray/autoload_method_extension.rb +14 -1
  107. data/lib/carray/axis_group.rb +84 -7
  108. data/lib/carray/basics.rb +63 -59
  109. data/lib/carray/bincount_nd.rb +12 -12
  110. data/lib/carray/block_iterator.rb +111 -25
  111. data/lib/carray/categorical.rb +154 -37
  112. data/lib/carray/categorical_iterator.rb +300 -151
  113. data/lib/carray/conditional.rb +14 -14
  114. data/lib/carray/const_string.rb +131 -27
  115. data/lib/carray/construct.rb +61 -0
  116. data/lib/carray/core_extensions.rb +62 -5
  117. data/lib/carray/data_type_extension.rb +21 -1
  118. data/lib/carray/data_type_limits.rb +91 -0
  119. data/lib/carray/fixlen_string.rb +1 -1
  120. data/lib/carray/frame/concat.rb +3 -3
  121. data/lib/carray/frame/convert.rb +1 -1
  122. data/lib/carray/frame/csv_parser.rb +11 -4
  123. data/lib/carray/frame/frame.rb +85 -21
  124. data/lib/carray/frame/group.rb +36 -3
  125. data/lib/carray/frame/io.rb +224 -15
  126. data/lib/carray/frame/records.rb +18 -4
  127. data/lib/carray/frame/sort.rb +1 -1
  128. data/lib/carray/frame/verbs.rb +32 -12
  129. data/lib/carray/fuse_source.rb +123 -0
  130. data/lib/carray/fusion.rb +218 -0
  131. data/lib/carray/histogram.rb +16 -16
  132. data/lib/carray/inspect.rb +43 -16
  133. data/lib/carray/iterator.rb +147 -3
  134. data/lib/carray/lazy.rb +88 -73
  135. data/lib/carray/mask_gap_fill.rb +3 -1
  136. data/lib/carray/meld_reduce.rb +2 -2
  137. data/lib/carray/methods/align_addr.rb +1 -1
  138. data/lib/carray/methods/composition.rb +1 -1
  139. data/lib/carray/methods/discovery_along.rb +74 -0
  140. data/lib/carray/methods/factorize.rb +50 -0
  141. data/lib/carray/methods/is_in.rb +25 -14
  142. data/lib/carray/methods/locate_addr.rb +81 -3
  143. data/lib/carray/methods/mask_duplicates.rb +36 -2
  144. data/lib/carray/methods/meshgrid.rb +4 -5
  145. data/lib/carray/methods/mode.rb +2 -2
  146. data/lib/carray/methods/nunique.rb +23 -2
  147. data/lib/carray/methods/repeat.rb +110 -0
  148. data/lib/carray/methods/snap.rb +7 -2
  149. data/lib/carray/methods/unique.rb +44 -4
  150. data/lib/carray/methods/value_counts.rb +2 -2
  151. data/lib/carray/rng.rb +86 -0
  152. data/lib/carray/runtime.rb +0 -19
  153. data/lib/carray/slab_iterator.rb +77 -19
  154. data/lib/carray/string_operation_extension.rb +10 -6
  155. data/lib/carray/time.rb +906 -491
  156. data/lib/carray/window_iterator.rb +421 -27
  157. data/lib/carray.rb +7 -5
  158. data/yard-stubs/ca_obj_array.rb +385 -0
  159. data/yard-stubs/ca_obj_bitarray.rb +38 -0
  160. data/yard-stubs/ca_obj_bitfield.rb +43 -0
  161. data/yard-stubs/ca_obj_block.rb +68 -0
  162. data/yard-stubs/ca_obj_byte_swap.rb +56 -0
  163. data/yard-stubs/ca_obj_fake.rb +31 -0
  164. data/yard-stubs/ca_obj_farray.rb +32 -0
  165. data/yard-stubs/ca_obj_field.rb +45 -0
  166. data/yard-stubs/ca_obj_grid.rb +35 -0
  167. data/yard-stubs/ca_obj_refer.rb +72 -0
  168. data/yard-stubs/ca_obj_roll.rb +45 -0
  169. data/yard-stubs/ca_obj_shift.rb +43 -0
  170. data/yard-stubs/ca_obj_stride.rb +181 -0
  171. data/yard-stubs/ca_obj_tile.rb +29 -0
  172. data/yard-stubs/ca_obj_transpose.rb +40 -0
  173. data/yard-stubs/ca_obj_window.rb +57 -0
  174. data/yard-stubs/carray_access.rb +131 -0
  175. data/yard-stubs/carray_attribute.rb +246 -0
  176. data/yard-stubs/carray_broadcast.rb +37 -0
  177. data/yard-stubs/carray_cast.rb +489 -0
  178. data/yard-stubs/carray_class.rb +65 -0
  179. data/yard-stubs/carray_conversion.rb +76 -0
  180. data/yard-stubs/carray_copy.rb +79 -0
  181. data/yard-stubs/carray_core.rb +34 -0
  182. data/yard-stubs/carray_count.rb +84 -0
  183. data/yard-stubs/carray_element.rb +108 -0
  184. data/yard-stubs/carray_generate.rb +66 -0
  185. data/yard-stubs/carray_lazy.rb +228 -0
  186. data/yard-stubs/carray_loop.rb +140 -0
  187. data/yard-stubs/carray_mask.rb +259 -0
  188. data/yard-stubs/carray_math.rb +1615 -0
  189. data/yard-stubs/carray_mathfunc.rb +45 -0
  190. data/yard-stubs/carray_median_percentile.rb +103 -0
  191. data/yard-stubs/carray_memory_view.rb +163 -0
  192. data/yard-stubs/carray_order.rb +252 -0
  193. data/yard-stubs/carray_random.rb +89 -0
  194. data/yard-stubs/carray_scatter.rb +106 -0
  195. data/yard-stubs/carray_slab.rb +59 -0
  196. data/yard-stubs/carray_sort.rb +165 -0
  197. data/yard-stubs/carray_test.rb +85 -0
  198. data/yard-stubs/carray_undef.rb +64 -0
  199. data/yard-stubs/carray_utils.rb +97 -0
  200. data/yard-stubs/ruby_carray.rb +193 -0
  201. metadata +67 -10
  202. 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,34 @@
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 Attributes
7
+
8
+ # @overload members
9
+ # Returns the ordered list of member names for `self.data_class`.
10
+ # Only valid when `self` carries a `data_class` (e.g. a
11
+ # `CARecord`).
12
+ # @return [Array<Symbol>]
13
+ # @raise [RuntimeError] if `self` has no `data_class`.
14
+ def members; end
15
+
16
+ # @overload fields
17
+ # Returns one field view per member of `self.data_class`, in
18
+ # declaration order. Each entry is a CArray sharing storage with
19
+ # `self`.
20
+ # @return [Array<CArray>]
21
+ # @raise [RuntimeError] if `self` has no `data_class`.
22
+ def fields; end
23
+
24
+ # @overload fields_at(*names)
25
+ # Returns the field views for the named members of
26
+ # `self.data_class`, in the given order.
27
+ # @param names [Array<Symbol, String, Integer>] member names or
28
+ # positional indices.
29
+ # @return [Array<CArray>]
30
+ # @raise [RuntimeError] if `self` has no `data_class`.
31
+ def fields_at(*names); end
32
+
33
+ # @!endgroup
34
+ end
@@ -0,0 +1,84 @@
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 -- they are the boolean array's domain).
44
+ # - `self.data_type == :object`, `v` is scalar: cells equal to `v`
45
+ # by Ruby `==`, so `count(1)` and `count(1.0)` agree, and `true` /
46
+ # `false` / `nil` are ordinary values to count.
47
+ #
48
+ # When `axis` is `nil` (default), reduces over all axes and
49
+ # returns an `Integer`. Otherwise reduces along the given
50
+ # axis / axes and returns a `CArray`.
51
+ #
52
+ # An empty or fully-masked reduction returns `0`: a count has
53
+ # identity `0`, so the count over no cells is `0`, not `UNDEF`
54
+ # (pass `min_count:` to get `UNDEF` below a threshold instead).
55
+ #
56
+ # `:fixlen` compares the whole cell by `memcmp`, with a short String
57
+ # query padded out to the cell width -- so a 4-byte cell holding
58
+ # `"a\0\0\0"` is counted by `count("a")`.
59
+ #
60
+ # A time array counts by its own values: `CATime` / `CATimedelta`
61
+ # descend to their storage and reconcile `v` into their unit, so `v`
62
+ # may be an element of the array, another time array (in any unit that
63
+ # converts exactly), or a Ruby `Time` / `DateTime`. A bare storage
64
+ # number is refused — use `ca.parent.count(n)` to count raw ticks.
65
+ #
66
+ # @param v [Object, CArray] value (or array of values) to count.
67
+ # `UNDEF` is treated as a mask-state query.
68
+ # @param axis [Integer, Array<Integer>, nil] reduction axis or
69
+ # axes; `nil` reduces fully.
70
+ # @param min_count [Integer] minimum number of non-masked cells
71
+ # required per reduced slice; slices below the threshold come
72
+ # back masked. Accepted only by the value-argument form
73
+ # (`count(v)`); the no-argument form accepts `axis:` only.
74
+ # @param fill_value [Object, nil] replacement for masked output
75
+ # cells; `nil` leaves them masked. Value-argument form only.
76
+ # @return [Integer, CArray]
77
+ # @raise [TypeError] when `v`'s type does not match the dispatch
78
+ # rule above.
79
+ # @raise [CArray::DataTypeError] when `self.data_type` is
80
+ # `:fixlen` or `:object`.
81
+ def count(*args, axis: nil, min_count: 0, fill_value: nil); end
82
+
83
+ # @!endgroup
84
+ 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,228 @@
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
24
+
25
+ class CAMonOp
26
+ # @!group Copy and conversion
27
+
28
+ # @overload to_ca
29
+ # Evaluates the expression and returns the result as a new entity.
30
+ #
31
+ # A one-operand element-wise operation holds no data of its own, so there is nothing to
32
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
33
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
34
+ # lazy `force` convention.
35
+ #
36
+ # The entity is detached from the operands, so writes to it reach
37
+ # nothing. `writable: true` is therefore refused rather than
38
+ # answered with a result that would swallow them.
39
+ # @param writable [Boolean] whether the caller needs writes to
40
+ # land back in the source; only `false` can be satisfied.
41
+ # @return [CArray] a newly evaluated entity.
42
+ # @raise [RuntimeError] when `writable: true` is requested.
43
+ def to_ca(writable: false); end
44
+
45
+ # @overload copy
46
+ # Evaluates the expression and returns the result as a new entity.
47
+ #
48
+ # If an expression evaluator is registered through
49
+ # {CArray.expression_evaluator} it is asked first; the ordinary
50
+ # element-wise walk is what happens when it declines, when none is
51
+ # registered, or when the array is small enough that walking is
52
+ # the faster answer.
53
+ # @return [CArray] a newly evaluated entity.
54
+ def copy; end
55
+
56
+ # @!endgroup
57
+ end
58
+
59
+ class CABinOp
60
+ # @!group Copy and conversion
61
+
62
+ # @overload to_ca
63
+ # Evaluates the expression and returns the result as a new entity.
64
+ #
65
+ # A two-operand element-wise operation holds no data of its own, so there is nothing to
66
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
67
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
68
+ # lazy `force` convention.
69
+ #
70
+ # The entity is detached from the operands, so writes to it reach
71
+ # nothing. `writable: true` is therefore refused rather than
72
+ # answered with a result that would swallow them.
73
+ # @param writable [Boolean] whether the caller needs writes to
74
+ # land back in the source; only `false` can be satisfied.
75
+ # @return [CArray] a newly evaluated entity.
76
+ # @raise [RuntimeError] when `writable: true` is requested.
77
+ def to_ca(writable: false); end
78
+
79
+ # @overload copy
80
+ # Evaluates the expression and returns the result as a new entity.
81
+ #
82
+ # If an expression evaluator is registered through
83
+ # {CArray.expression_evaluator} it is asked first; the ordinary
84
+ # element-wise walk is what happens when it declines, when none is
85
+ # registered, or when the array is small enough that walking is
86
+ # the faster answer.
87
+ # @return [CArray] a newly evaluated entity.
88
+ def copy; end
89
+
90
+ # @!endgroup
91
+ end
92
+
93
+ class CATriOp
94
+ # @!group Copy and conversion
95
+
96
+ # @overload to_ca
97
+ # Evaluates the expression and returns the result as a new entity.
98
+ #
99
+ # A three-operand element-wise operation holds no data of its own, so there is nothing to
100
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
101
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
102
+ # lazy `force` convention.
103
+ #
104
+ # The entity is detached from the operands, so writes to it reach
105
+ # nothing. `writable: true` is therefore refused rather than
106
+ # answered with a result that would swallow them.
107
+ # @param writable [Boolean] whether the caller needs writes to
108
+ # land back in the source; only `false` can be satisfied.
109
+ # @return [CArray] a newly evaluated entity.
110
+ # @raise [RuntimeError] when `writable: true` is requested.
111
+ def to_ca(writable: false); end
112
+
113
+ # @overload copy
114
+ # Evaluates the expression and returns the result as a new entity.
115
+ #
116
+ # If an expression evaluator is registered through
117
+ # {CArray.expression_evaluator} it is asked first; the ordinary
118
+ # element-wise walk is what happens when it declines, when none is
119
+ # registered, or when the array is small enough that walking is
120
+ # the faster answer.
121
+ # @return [CArray] a newly evaluated entity.
122
+ def copy; end
123
+
124
+ # @!endgroup
125
+ end
126
+
127
+ class CAMonCmp
128
+ # @!group Copy and conversion
129
+
130
+ # @overload to_ca
131
+ # Evaluates the expression and returns the result as a new entity.
132
+ #
133
+ # A one-operand element-wise predicate holds no data of its own, so there is nothing to
134
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
135
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
136
+ # lazy `force` convention.
137
+ #
138
+ # The entity is detached from the operands, so writes to it reach
139
+ # nothing. `writable: true` is therefore refused rather than
140
+ # answered with a result that would swallow them.
141
+ # @param writable [Boolean] whether the caller needs writes to
142
+ # land back in the source; only `false` can be satisfied.
143
+ # @return [CArray] a newly evaluated entity.
144
+ # @raise [RuntimeError] when `writable: true` is requested.
145
+ def to_ca(writable: false); end
146
+
147
+ # @overload copy
148
+ # Evaluates the expression and returns the result as a new entity.
149
+ #
150
+ # If an expression evaluator is registered through
151
+ # {CArray.expression_evaluator} it is asked first; the ordinary
152
+ # element-wise walk is what happens when it declines, when none is
153
+ # registered, or when the array is small enough that walking is
154
+ # the faster answer.
155
+ # @return [CArray] a newly evaluated entity.
156
+ def copy; end
157
+
158
+ # @!endgroup
159
+ end
160
+
161
+ class CABinCmp
162
+ # @!group Copy and conversion
163
+
164
+ # @overload to_ca
165
+ # Evaluates the expression and returns the result as a new entity.
166
+ #
167
+ # A two-operand element-wise comparison holds no data of its own, so there is nothing to
168
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
169
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
170
+ # lazy `force` convention.
171
+ #
172
+ # The entity is detached from the operands, so writes to it reach
173
+ # nothing. `writable: true` is therefore refused rather than
174
+ # answered with a result that would swallow them.
175
+ # @param writable [Boolean] whether the caller needs writes to
176
+ # land back in the source; only `false` can be satisfied.
177
+ # @return [CArray] a newly evaluated entity.
178
+ # @raise [RuntimeError] when `writable: true` is requested.
179
+ def to_ca(writable: false); end
180
+
181
+ # @overload copy
182
+ # Evaluates the expression and returns the result as a new entity.
183
+ #
184
+ # If an expression evaluator is registered through
185
+ # {CArray.expression_evaluator} it is asked first; the ordinary
186
+ # element-wise walk is what happens when it declines, when none is
187
+ # registered, or when the array is small enough that walking is
188
+ # the faster answer.
189
+ # @return [CArray] a newly evaluated entity.
190
+ def copy; end
191
+
192
+ # @!endgroup
193
+ end
194
+
195
+ class CALazyMarker
196
+ # @!group Copy and conversion
197
+
198
+ # @overload to_ca
199
+ # Evaluates the expression and returns the result as a new entity.
200
+ #
201
+ # A lazy marker holds no data of its own, so there is nothing to
202
+ # hand over unevaluated: unlike `CArray#to_ca`, which returns
203
+ # `self`, this materialises -- the Ruby `Enumerable#to_a` /
204
+ # lazy `force` convention.
205
+ #
206
+ # The entity is detached from the operands, so writes to it reach
207
+ # nothing. `writable: true` is therefore refused rather than
208
+ # answered with a result that would swallow them.
209
+ # @param writable [Boolean] whether the caller needs writes to
210
+ # land back in the source; only `false` can be satisfied.
211
+ # @return [CArray] a newly evaluated entity.
212
+ # @raise [RuntimeError] when `writable: true` is requested.
213
+ def to_ca(writable: false); end
214
+
215
+ # @overload copy
216
+ # Evaluates the expression and returns the result as a new entity.
217
+ #
218
+ # If an expression evaluator is registered through
219
+ # {CArray.expression_evaluator} it is asked first; the ordinary
220
+ # element-wise walk is what happens when it declines, when none is
221
+ # registered, or when the array is small enough that walking is
222
+ # the faster answer.
223
+ # @return [CArray] a newly evaluated entity.
224
+ def copy; end
225
+
226
+ # @!endgroup
227
+ end
228
+