carray 3.0.2 → 3.0.3

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 (218) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +304 -0
  3. data/README.md +3 -4
  4. data/carray.gemspec +1 -1
  5. data/ext/ca_axis_dispatch.c +225 -0
  6. data/ext/ca_axis_group.c +177 -99
  7. data/ext/ca_binop_dispatch.c +54 -32
  8. data/ext/ca_binop_dispatch.h +1 -0
  9. data/ext/ca_categorical_iterator.c +66 -71
  10. data/ext/ca_compare.c +8 -2
  11. data/ext/ca_for_buffer.h +21 -68
  12. data/ext/ca_group_iter.c +27 -11
  13. data/ext/ca_kernel_iterator.c +663 -214
  14. data/ext/ca_kernel_iterator.h +231 -167
  15. data/ext/ca_monop_dispatch.c +4 -4
  16. data/ext/ca_monop_dispatch.h +4 -0
  17. data/ext/ca_obj_array.c +132 -22
  18. data/ext/ca_obj_bincmp.c +152 -121
  19. data/ext/ca_obj_binop.c +107 -210
  20. data/ext/ca_obj_bitarray.c +37 -24
  21. data/ext/ca_obj_bitfield.c +95 -62
  22. data/ext/ca_obj_block.c +1 -0
  23. data/ext/ca_obj_byte_swap.c +40 -40
  24. data/ext/ca_obj_const_string.c +96 -25
  25. data/ext/ca_obj_face.c +406 -64
  26. data/ext/ca_obj_face.h +92 -47
  27. data/ext/ca_obj_fake.c +21 -50
  28. data/ext/ca_obj_farray.c +1 -0
  29. data/ext/ca_obj_field.c +16 -3
  30. data/ext/ca_obj_fixlen_string.c +21 -21
  31. data/ext/ca_obj_grid.c +181 -124
  32. data/ext/ca_obj_meld.c +189 -107
  33. data/ext/ca_obj_moncmp.c +61 -61
  34. data/ext/ca_obj_monop.c +125 -107
  35. data/ext/ca_obj_object.c +543 -233
  36. data/ext/ca_obj_record.c +51 -16
  37. data/ext/ca_obj_reduce.c +5 -8
  38. data/ext/ca_obj_refer.c +117 -33
  39. data/ext/ca_obj_remap.c +57 -17
  40. data/ext/ca_obj_repeat.c +21 -5
  41. data/ext/ca_obj_roll.c +115 -11
  42. data/ext/ca_obj_select.c +47 -49
  43. data/ext/ca_obj_select_axis.c +58 -60
  44. data/ext/ca_obj_shift.c +22 -102
  45. data/ext/ca_obj_stack.c +223 -118
  46. data/ext/ca_obj_stride.c +195 -34
  47. data/ext/ca_obj_string.c +17 -18
  48. data/ext/ca_obj_tile.c +32 -16
  49. data/ext/ca_obj_time.c +23 -25
  50. data/ext/ca_obj_timedelta.c +21 -23
  51. data/ext/ca_obj_transpose.c +12 -3
  52. data/ext/ca_obj_triop.c +110 -117
  53. data/ext/ca_obj_window.c +149 -27
  54. data/ext/ca_op_ipower.c +24 -11
  55. data/ext/ca_op_powi.h +57 -30
  56. data/ext/ca_pow5_table.h +656 -0
  57. data/ext/ca_sort_kernels.h +70 -0
  58. data/ext/ca_sweep_engine.c +102 -79
  59. data/ext/ca_sweep_engine.h +7 -20
  60. data/ext/ca_triop_dispatch.c +4 -1
  61. data/ext/ca_triop_dispatch.h +5 -2
  62. data/ext/caframe_csv_reader.c +463 -0
  63. data/ext/carray.h +70 -27
  64. data/ext/carray_access.c +455 -211
  65. data/ext/carray_address_basis.c +177 -36
  66. data/ext/carray_attribute.c +45 -3
  67. data/ext/carray_bincount.c +32 -2
  68. data/ext/carray_broadcast.c +46 -14
  69. data/ext/carray_call_cfunc.c +0 -28
  70. data/ext/carray_cast.c +1444 -209
  71. data/ext/carray_cast_func.rb +34 -21
  72. data/ext/carray_conversion.c +197 -73
  73. data/ext/carray_copy.c +32 -11
  74. data/ext/carray_core.c +514 -122
  75. data/ext/carray_count.c +140 -87
  76. data/ext/carray_element.c +18 -27
  77. data/ext/carray_factorize.c +569 -277
  78. data/ext/carray_generate.c +76 -40
  79. data/ext/carray_histogram.c +152 -94
  80. data/ext/carray_hold.c +2 -1
  81. data/ext/carray_index_classifier.c +63 -96
  82. data/ext/carray_internal.h +385 -3
  83. data/ext/carray_lazy.c +834 -79
  84. data/ext/carray_loop.c +81 -65
  85. data/ext/carray_mask.c +682 -316
  86. data/ext/carray_math_kernel.h +1 -0
  87. data/ext/carray_median_percentile.c +221 -76
  88. data/ext/carray_memory_view.c +254 -248
  89. data/ext/carray_operator.c +1089 -359
  90. data/ext/carray_order.c +133 -69
  91. data/ext/carray_partition.c +102 -56
  92. data/ext/carray_random.c +273 -239
  93. data/ext/carray_scatter.c +308 -65
  94. data/ext/carray_segment.c +257 -0
  95. data/ext/carray_slab.c +170 -70
  96. data/ext/carray_sort.c +215 -218
  97. data/ext/carray_sort_kernel.c +8 -1
  98. data/ext/carray_struct.c +99 -21
  99. data/ext/carray_test.c +167 -64
  100. data/ext/carray_time_text.c +1182 -0
  101. data/ext/carray_utils.c +363 -98
  102. data/ext/extconf.rb +27 -2
  103. data/ext/mk_call_cfunc.rb +0 -2
  104. data/ext/mk_pow5_table.rb +35 -0
  105. data/ext/mkkernel.rb +1076 -846
  106. data/ext/ruby_carray.c +7 -1
  107. data/ext/version.h +4 -4
  108. data/ext/version.rb +4 -2
  109. data/lib/carray/attribute.rb +39 -0
  110. data/lib/carray/autoload_carray.rb +19 -0
  111. data/lib/carray/autoload_method_extension.rb +6 -0
  112. data/lib/carray/axis_group.rb +174 -26
  113. data/lib/carray/basics.rb +91 -25
  114. data/lib/carray/bincount_nd.rb +6 -0
  115. data/lib/carray/block_iterator.rb +118 -48
  116. data/lib/carray/boolean_reduce.rb +21 -29
  117. data/lib/carray/categorical.rb +94 -26
  118. data/lib/carray/categorical_iterator.rb +333 -826
  119. data/lib/carray/complex.rb +36 -29
  120. data/lib/carray/conditional.rb +94 -7
  121. data/lib/carray/const_string.rb +46 -0
  122. data/lib/carray/frame/concat.rb +157 -6
  123. data/lib/carray/frame/convert.rb +13 -7
  124. data/lib/carray/frame/csv_parser.rb +589 -82
  125. data/lib/carray/frame/describe.rb +79 -0
  126. data/lib/carray/frame/frame.rb +124 -25
  127. data/lib/carray/frame/group.rb +189 -63
  128. data/lib/carray/frame/io.rb +412 -72
  129. data/lib/carray/frame/join.rb +134 -46
  130. data/lib/carray/frame/records.rb +37 -16
  131. data/lib/carray/frame/reshape.rb +448 -0
  132. data/lib/carray/frame/sort.rb +26 -2
  133. data/lib/carray/frame/verbs.rb +715 -48
  134. data/lib/carray/frame.rb +2 -0
  135. data/lib/carray/fuse_source.rb +111 -2
  136. data/lib/carray/fusion.rb +229 -38
  137. data/lib/carray/inspect.rb +29 -11
  138. data/lib/carray/iterator.rb +14 -2
  139. data/lib/carray/lazy.rb +54 -30
  140. data/lib/carray/mask_gap_fill.rb +66 -52
  141. data/lib/carray/math.rb +32 -19
  142. data/lib/carray/meld_reduce.rb +40 -7
  143. data/lib/carray/methods/align_addr.rb +8 -4
  144. data/lib/carray/methods/bincount.rb +2 -2
  145. data/lib/carray/methods/bit_string.rb +14 -3
  146. data/lib/carray/methods/composition.rb +16 -10
  147. data/lib/carray/methods/factorize.rb +2 -2
  148. data/lib/carray/methods/gather_nd.rb +13 -2
  149. data/lib/carray/methods/insert_block.rb +9 -14
  150. data/lib/carray/methods/is_in.rb +117 -4
  151. data/lib/carray/methods/join.rb +1 -1
  152. data/lib/carray/methods/locate_addr.rb +177 -36
  153. data/lib/carray/methods/mode.rb +18 -1
  154. data/lib/carray/methods/repeat.rb +1 -20
  155. data/lib/carray/methods/resize.rb +21 -23
  156. data/lib/carray/methods/snap.rb +34 -12
  157. data/lib/carray/methods/unique.rb +11 -2
  158. data/lib/carray/record_order.rb +208 -0
  159. data/lib/carray/runtime.rb +14 -11
  160. data/lib/carray/segment_iterator.rb +990 -0
  161. data/lib/carray/serialize.rb +197 -27
  162. data/lib/carray/slab_iterator.rb +51 -27
  163. data/lib/carray/stack.rb +10 -4
  164. data/lib/carray/string_operation_extension.rb +4 -3
  165. data/lib/carray/struct.rb +142 -51
  166. data/lib/carray/struct_builder.rb +110 -14
  167. data/lib/carray/table.rb +2 -2
  168. data/lib/carray/time.rb +517 -103
  169. data/lib/carray/window_iterator.rb +127 -72
  170. data/lib/carray.rb +2 -2
  171. data/yard-stubs/ca_obj_array.rb +4 -4
  172. data/yard-stubs/ca_obj_bitarray.rb +7 -0
  173. data/yard-stubs/ca_obj_bitfield.rb +23 -12
  174. data/yard-stubs/ca_obj_fake.rb +1 -1
  175. data/yard-stubs/ca_obj_field.rb +1 -1
  176. data/yard-stubs/ca_obj_refer.rb +3 -3
  177. data/yard-stubs/ca_obj_roll.rb +0 -1
  178. data/yard-stubs/ca_obj_stride.rb +10 -7
  179. data/yard-stubs/ca_obj_transpose.rb +1 -1
  180. data/yard-stubs/ca_obj_window.rb +1 -2
  181. data/yard-stubs/carray_access.rb +5 -4
  182. data/yard-stubs/carray_broadcast.rb +1 -1
  183. data/yard-stubs/carray_cast.rb +78 -43
  184. data/yard-stubs/carray_conversion.rb +13 -1
  185. data/yard-stubs/carray_copy.rb +8 -3
  186. data/yard-stubs/carray_core.rb +3 -3
  187. data/yard-stubs/carray_count.rb +9 -0
  188. data/yard-stubs/carray_lazy.rb +5 -1
  189. data/yard-stubs/carray_loop.rb +4 -1
  190. data/yard-stubs/carray_mask.rb +34 -10
  191. data/yard-stubs/carray_math.rb +25 -13
  192. data/yard-stubs/carray_median_percentile.rb +10 -6
  193. data/yard-stubs/carray_order.rb +34 -13
  194. data/yard-stubs/carray_scatter.rb +10 -3
  195. data/yard-stubs/carray_segment.rb +72 -0
  196. data/yard-stubs/carray_slab.rb +2 -1
  197. data/yard-stubs/carray_sort.rb +43 -3
  198. data/yard-stubs/carray_test.rb +10 -0
  199. data/yard-stubs/carray_utils.rb +0 -26
  200. metadata +11 -19
  201. data/ext/ca_for_each_element.h +0 -239
  202. data/ext/carray_build_flags.h +0 -3
  203. data/ext/carray_config.h +0 -28
  204. data/ext/carray_kernels_bincmp.c +0 -4446
  205. data/ext/carray_kernels_binop.c +0 -11001
  206. data/ext/carray_kernels_init.c +0 -1131
  207. data/ext/carray_kernels_map.c +0 -3467
  208. data/ext/carray_kernels_moncmp.c +0 -2097
  209. data/ext/carray_kernels_monop.c +0 -18313
  210. data/ext/carray_kernels_reduce_aggregate.c +0 -26005
  211. data/ext/carray_kernels_reduce_boolean.c +0 -330
  212. data/ext/carray_kernels_reduce_cumulative.c +0 -14862
  213. data/ext/carray_kernels_reduce_extreme.c +0 -17494
  214. data/ext/carray_kernels_reduce_variance.c +0 -3910
  215. data/ext/carray_kernels_scan.c +0 -3693
  216. data/ext/carray_kernels_search.c +0 -32218
  217. data/ext/carray_kernels_sort.c +0 -10626
  218. data/ext/carray_kernels_triop.c +0 -1392
@@ -30,13 +30,16 @@ class CArray
30
30
  # sort / sort_copy stubs live in yard-stubs/carray_sort.rb (same
31
31
  # file split as ext/carray_sort.c <-> ext/carray_order.c).
32
32
 
33
- # @overload partition(kth, axis: 0, masked_position: :last)
33
+ # @overload partition(kth, axis: nil, masked_position: :last)
34
34
  # Returns a `CARemap` view of `self` permuted along `axis` so that
35
35
  # the element at fiber-local position `kth` is in its final sorted
36
36
  # place, every element before it is `<=` it, and every element
37
37
  # after it is `>=` it. Order within the two regions is unspecified.
38
38
  # Average `O(n)` per fiber via quickselect.
39
39
  #
40
+ # Without `axis:` (or with `axis: nil`) `self` is flattened and
41
+ # treated as one fiber, as {#sort} does; the result is 1-D.
42
+ #
40
43
  # Negative `kth` counts from the end of the fiber
41
44
  # (`-self.shape[axis] <= kth < self.shape[axis]`).
42
45
  #
@@ -52,32 +55,39 @@ class CArray
52
55
  # among unmasked values.
53
56
  #
54
57
  # @param kth [Integer] target fiber-local position along `axis`.
55
- # @param axis [Integer]
58
+ # @param axis [Integer, nil] `nil` partitions the whole array.
56
59
  # @param masked_position [Symbol] `:last` (default) or `:first`.
57
60
  # @return [CArray] `CARemap` view of `self`.
58
61
  # @raise [ArgumentError] when `kth` is out of range.
59
- def partition(kth, axis: 0, masked_position: :last); end
62
+ def partition(kth, axis: nil, masked_position: :last); end
60
63
 
61
- # @overload partition_copy(kth, axis: 0, masked_position: :last)
62
- # Returns a fresh entity `CArray` with the same shape as `self`,
63
- # partitioned along `axis` by the same rule as {#partition}.
64
+ # @overload partition_copy(kth, axis: nil, masked_position: :last)
65
+ # Returns a fresh entity `CArray` partitioned along `axis` by the
66
+ # same rule as {#partition}: the shape of `self`, or 1-D when `axis`
67
+ # is omitted.
64
68
  # Bypasses the `CARemap` scatter layer for cases where an entity
65
69
  # is wanted directly. Same dispatch (numeric / boolean / `CA_FIXLEN` /
66
70
  # `CA_OBJECT`), same `kth` and `masked_position:` semantics.
67
71
  # Masked input delegates to {#partition} + copy.
68
72
  #
73
+ # A Face partitions in its surface order and comes back as the same
74
+ # Face: one whose storage order is its surface order is selected on its
75
+ # storage, a fixlen storage by byte order. A Face whose storage order is
76
+ # not its surface order (e.g. {CACategorical}) raises.
77
+ #
69
78
  # Float NaN policy: NaN cells are pre-partitioned to the tail. If
70
79
  # `kth` falls within the finite slice, quickselect runs over the
71
80
  # finite cells; otherwise the kth cell is already NaN.
72
81
  #
73
82
  # @param kth [Integer]
74
- # @param axis [Integer]
83
+ # @param axis [Integer, nil] `nil` partitions the whole array.
75
84
  # @param masked_position [Symbol] `:last` (default) or `:first`.
76
85
  # @return [CArray] fresh entity.
77
- # @raise [ArgumentError] same conditions as {#partition}.
78
- def partition_copy(kth, axis: 0, masked_position: :last); end
86
+ # @raise [ArgumentError] same conditions as {#partition}, or a Face that
87
+ # is not orderable by its storage.
88
+ def partition_copy(kth, axis: nil, masked_position: :last); end
79
89
 
80
- # @overload order(axis: nil, descending: false, method: :ordinal)
90
+ # @overload order(axis: nil, descending: false, method: :ordinal, kind: :quick)
81
91
  # Returns each cell's rank among the other cells along `axis`
82
92
  # (`0` = smallest). When `axis` is omitted, `self` is flattened
83
93
  # first (global rank). Sugar over `rank_index` (built on the
@@ -105,9 +115,11 @@ class CArray
105
115
  # @param axis [Integer, nil]
106
116
  # @param descending [Boolean]
107
117
  # @param method [Symbol] `:ordinal` (default) or `:dense`.
118
+ # @param kind [Symbol] `:quick` (default) or `:stable`, as for
119
+ # {#sort_index}; a performance choice only.
108
120
  # @return [CArray] `:int64` ranks, shape == `self.shape`.
109
121
  # @raise [ArgumentError] when `method:` is neither `:ordinal` nor `:dense`.
110
- def order(axis: nil, descending: false, method: :ordinal); end
122
+ def order(axis: nil, descending: false, method: :ordinal, kind: :quick); end
111
123
 
112
124
  # @!endgroup
113
125
 
@@ -121,7 +133,7 @@ class CArray
121
133
  # with `UNDEF` at positions where the value is not present.
122
134
  # @param val [Numeric, CArray]
123
135
  # @return [Integer, CArray, nil]
124
- # @raise [RuntimeError] if `self` has any masked element.
136
+ # @raise [ArgumentError] if `self` has any masked element.
125
137
  # @overload bsearch(val, axis:)
126
138
  # Per-fiber binary search along `axis`. Returns a CArray of
127
139
  # axis-local positions, one per fiber.
@@ -148,6 +160,14 @@ class CArray
148
160
  # to `val`. For float types, `eps` (default machine epsilon)
149
161
  # sets the tolerance. Returns `nil` if no match.
150
162
  #
163
+ # `val` is compared in the type both share, as `self.eq(val)`
164
+ # compares: an integer array searched with a Float is compared in
165
+ # float64 (so `3.9` does not match `3`, and `eps` applies), and an
166
+ # Integer that does not fit an integer array raises `RangeError`.
167
+ # The same holds for {#bsearch} and {#search_nearest}. On an
168
+ # `:object` array a cell matches when it is `==` to `val`, as {#eq}
169
+ # compares (so `1` matches `1.0`, which {#is_in} does not).
170
+ #
151
171
  # `self` need not be sorted; this is a linear scan. For sorted
152
172
  # data prefer {#bsearch}.
153
173
  # @param val [Object]
@@ -206,7 +226,8 @@ class CArray
206
226
  # bracketing samples. The integer part of the returned address is
207
227
  # the index of the lower bracket, the fractional part is the
208
228
  # interpolation weight toward the next sample. Out-of-range `val`
209
- # returns NaN.
229
+ # returns NaN. A one-point axis has no segment: `val` equal to the
230
+ # point is at 0, any other value is out of range.
210
231
  #
211
232
  # `self` is coerced to `:float64` if it is not already. When
212
233
  # `axis: nil`, `self` is flattened to 1-D first.
@@ -19,10 +19,13 @@ class CArray
19
19
  # `CA_SIZE`) or a Ruby Array.
20
20
  # - `vals` is a CArray of length matching `addrs` (coerced to
21
21
  # `self.data_type`), or a Numeric scalar broadcast to all
22
- # addresses.
22
+ # addresses. A complex `self` also takes a Complex scalar.
23
23
  # - Out-of-range `addrs[i]` (`< 0` or `>= self.elements`) raises
24
- # `IndexError`.
25
- # - `self.data_type` must be numeric.
24
+ # `IndexError`. The pairs before it stay applied, through a view
25
+ # as well.
26
+ # - `self.data_type` must be numeric. Complex is accepted by
27
+ # every variant except {#scatter_min!} and {#scatter_max!},
28
+ # since complex values have no order.
26
29
  #
27
30
  # Mask policy differs between the accumulate family and
28
31
  # {#scatter_replace!}: the accumulate variants skip the pair when
@@ -73,6 +76,8 @@ class CArray
73
76
  # @param addrs [CArray, Array<Integer>]
74
77
  # @param vals [CArray, Numeric]
75
78
  # @return [self]
79
+ # @raise [CArray::DataTypeError] for a non-numeric or complex
80
+ # `data_type`.
76
81
  def scatter_min!(addrs, vals); end
77
82
 
78
83
  # @overload scatter_max!(addrs, vals)
@@ -82,6 +87,8 @@ class CArray
82
87
  # @param addrs [CArray, Array<Integer>]
83
88
  # @param vals [CArray, Numeric]
84
89
  # @return [self]
90
+ # @raise [CArray::DataTypeError] for a non-numeric or complex
91
+ # `data_type`.
85
92
  def scatter_max!(addrs, vals); end
86
93
 
87
94
  # @overload scatter_replace!(addrs, vals)
@@ -0,0 +1,72 @@
1
+ # DOCUMENTATION ONLY — DO NOT REQUIRE.
2
+ # Stubs for methods defined in ext/carray_segment.c.
3
+ # See yard-stubs/README.md and yard-stubs/STYLE.md.
4
+
5
+ class CArray
6
+ # @!group Index and address conversion
7
+ #
8
+ # A flat sequence cut into consecutive segments has three
9
+ # representations, and these methods convert between them:
10
+ #
11
+ # lengths [2, 0, 3] one count per segment
12
+ # offsets [0, 2, 2, 5] every boundary, both ends included
13
+ # segment index [0, 0, 2, 2, 2] the segment each element is in
14
+ #
15
+ # Segment `c` spans `offsets[c]...offsets[c + 1]`, so there is no
16
+ # special case for the last segment and none for an empty one.
17
+ #
18
+ # Both methods compute in int64 and return int64, so a total beyond
19
+ # 2**53 stays exact. They accept a CArray of any integer or boolean
20
+ # data type (views included, read in flatten order) or an Array of
21
+ # Integers, and refuse masked cells: a masked length is not a count,
22
+ # and a masked offset is not a position.
23
+
24
+ # @overload segment_offsets(lengths:)
25
+ # Returns the boundaries of segments with the given lengths: `0`
26
+ # first, then the running total. `k` lengths give `k + 1` offsets,
27
+ # so no lengths give `[0]`.
28
+ #
29
+ # CArray.segment_offsets(lengths: [2, 0, 3]) # => [0, 2, 2, 5]
30
+ #
31
+ # @param lengths [CArray, Array<Integer>] one count per segment.
32
+ # @return [CArray] int64, one element more than `lengths`.
33
+ # @raise [ArgumentError] for a negative length, a masked length,
34
+ # or a non-Integer in an Array.
35
+ # @raise [CArray::DataTypeError] for a non-integer data type.
36
+ # @raise [RangeError] when the total overflows int64.
37
+ def self.segment_offsets(lengths:); end
38
+
39
+ # @overload segment_index(lengths:)
40
+ # Returns, for each element of the cut sequence, the segment it
41
+ # belongs to. A segment of length 0 contributes no elements, so
42
+ # its number does not appear.
43
+ #
44
+ # CArray.segment_index(lengths: [2, 0, 3]) # => [0, 0, 2, 2, 2]
45
+ #
46
+ # The same as `CArray.int64(k).seq.repeat(lengths)`, as an owned
47
+ # array rather than a view.
48
+ # @param lengths [CArray, Array<Integer>] one count per segment.
49
+ # @return [CArray] int64, `lengths.sum` elements.
50
+ #
51
+ # @overload segment_index(offsets:)
52
+ # The same from boundaries. The offsets need not start at 0: the
53
+ # offsets of a range cut out of a longer table start where that
54
+ # range starts, and the result then covers
55
+ # `offsets[0]...offsets[-1]` with the segments numbered from 0.
56
+ #
57
+ # CArray.segment_index(offsets: [0, 2, 2, 5]) # => [0, 0, 2, 2, 2]
58
+ # CArray.segment_index(offsets: [4, 6, 6, 9]) # => [0, 0, 2, 2, 2]
59
+ #
60
+ # @param offsets [CArray, Array<Integer>] `k + 1` non-decreasing
61
+ # boundaries.
62
+ # @return [CArray] int64, `offsets[-1] - offsets[0]` elements.
63
+ #
64
+ # @raise [ArgumentError] for a negative length, decreasing or empty
65
+ # offsets, a masked cell, a non-Integer in an Array, or unless
66
+ # exactly one of `lengths:` and `offsets:` is given.
67
+ # @raise [CArray::DataTypeError] for a non-integer data type.
68
+ # @raise [RangeError] when the total length overflows int64.
69
+ def self.segment_index(lengths: nil, offsets: nil); end
70
+
71
+ # @!endgroup
72
+ end
@@ -28,7 +28,8 @@ class CArray
28
28
  # Returns a new CArray built by replacing each slab of `self` with the
29
29
  # block's result. The block receives the slab view and must return a
30
30
  # value of the same shape as the slab (a CArray or scalar); the results
31
- # are written into the output at the same positions.
31
+ # are written into the output at the same positions, and a masked
32
+ # cell of the block's result is masked in the output.
32
33
  # @param axis [Integer, Array<Integer>, nil] the slab axis or axes.
33
34
  # @param data_type [Symbol, Integer, Class, nil] output data type
34
35
  # (defaults to `self`'s data type).
@@ -115,6 +115,43 @@ class CArray
115
115
  # `:stable`.
116
116
  def sort_addr(axis: nil, kind: :quick, masked_position: :last); end
117
117
 
118
+ # @overload sort_index(axis: nil, kind: :quick, masked_position: :last)
119
+ # Returns, for each fiber along `axis`, the positions within the
120
+ # fiber that put it in ascending order: `:int64`, shaped like
121
+ # `self`. For a 1-D array, `a[a.sort_index]` is `a` sorted.
122
+ #
123
+ # Without `axis:` (or with `axis: nil`) `self` is flattened and
124
+ # treated as one fiber, as {#sort} does: the result is 1-D with
125
+ # `self.elements` entries, and `a.flatten[a.sort_index]` is
126
+ # `a.sort`.
127
+ #
128
+ # The sort is **stable**: cells that compare equal keep their
129
+ # input order, whichever `kind:` is chosen, so sorting by one key
130
+ # and then stably by another orders by the second key first and
131
+ # the first within it. `kind:` is a performance characteristic
132
+ # only:
133
+ #
134
+ # - `:quick` (default) — introsort with mergesort escape.
135
+ # - `:stable` — bottom-up mergesort.
136
+ #
137
+ # NaN and masked cells cannot be compared with the rest and are
138
+ # placed at one end of each fiber: NaN after the numbers, masked
139
+ # cells at the end `masked_position:` names (`:last`, default, or
140
+ # `:first`). Relative order within the masked cells is unspecified.
141
+ #
142
+ # Takes numeric data types, boolean, `CA_FIXLEN` (byte order),
143
+ # `CA_OBJECT` (`<=>` per pair), and an ordered Face such as
144
+ # `CATime`. Complex values have no order.
145
+ # @param axis [Integer, nil] axis along which fibers run; negative
146
+ # counts from the end. `nil` sorts the whole array.
147
+ # @param kind [Symbol] `:quick` or `:stable`.
148
+ # @param masked_position [Symbol] `:last` (default) or `:first`.
149
+ # @return [CArray] `:int64` positions within each fiber.
150
+ # @raise [ArgumentError] when `kind:` is neither `:quick` nor
151
+ # `:stable`, or `axis` is out of range.
152
+ # @raise [CArray::DataTypeError] for a complex `data_type`.
153
+ def sort_index(axis: nil, kind: :quick, masked_position: :last); end
154
+
118
155
  # @!group Index and address conversion
119
156
 
120
157
  # @overload axis2addr(indices, axis: 0)
@@ -147,15 +184,18 @@ class CArray
147
184
  #
148
185
  # `indices` data_type: any integer kind (zero-copy when
149
186
  # already `:int64`). Negative indices: Python-style
150
- # (`-1` == last). Out-of-range indices raise `RangeError`.
151
- # Negative `axis:` is Python-style.
187
+ # (`-1` == last). Out-of-range indices raise `IndexError`.
188
+ # Negative `axis:` is Python-style. A masked index gives a
189
+ # masked address (its stored value is not read), so
190
+ # `take_along_axis` answers `UNDEF` there and `put_along_axis`
191
+ # writes nothing there.
152
192
  #
153
193
  # @param indices [CArray] integer-typed axis-local positions.
154
194
  # @param axis [Integer] axis along which `indices` are
155
195
  # interpreted.
156
196
  # @return [CArray] `:int64` view-flat addresses, same shape as
157
197
  # `indices`.
158
- # @raise [RangeError] when an index is out of range after
198
+ # @raise [IndexError] when an index is out of range after
159
199
  # negative normalization.
160
200
  # @raise [ArgumentError] for shape / ndim / data_type
161
201
  # violations.
@@ -36,6 +36,13 @@ class CArray
36
36
  # `data_class`, `data_type`, mask state, and elementwise values as
37
37
  # `self`. NaN values compare unequal (IEEE semantics), so two
38
38
  # arrays with NaN at the same position are not `==`.
39
+ #
40
+ # A Face (a time, string or categorical array) equals only a Face of
41
+ # its own class, and is compared by its values: two time arrays of
42
+ # different units holding the same instants are `==`, as are two
43
+ # categoricals with the same labels at each cell whatever the order
44
+ # of their vocabularies. A Face is never `==` to an array that is not
45
+ # one, even when the bytes match.
39
46
  # @param other [Object]
40
47
  # @return [Boolean]
41
48
  def ==(other); end
@@ -46,6 +53,9 @@ class CArray
46
53
  # are compared bitwise (for numeric types) or via `Object#eql?`
47
54
  # (for `:object` arrays). Unlike `==`, `NaN.eql?(NaN)` holds, so
48
55
  # two mask-free arrays with NaN at the same positions are `eql?`.
56
+ # Two Faces are `eql?` only when they are of the same class, share
57
+ # their state (a time array's unit, a categorical's labels) and hold
58
+ # the same storage.
49
59
  #
50
60
  # Guarantees `a.eql?(b)` ⇒ `a.hash == b.hash`.
51
61
  # @param other [Object]
@@ -67,31 +67,5 @@ class CArray
67
67
  def guess_type_and_bytes(type_spec, bytes = nil); end
68
68
 
69
69
  # @!endgroup
70
-
71
- # @!group String scanning (internal)
72
-
73
- # @overload _scan_float(str, fill_value = nil)
74
- # Parses `str` as a single double-precision float. Returns
75
- # `fill_value` (or `NaN` if `fill_value` is nil) when `str` is
76
- # `nil` or unparseable. Internal helper used by text-format I/O
77
- # readers; end users should prefer Ruby's `Float()` /
78
- # `String#to_f`.
79
- # @param str [String, nil]
80
- # @param fill_value [Float, nil]
81
- # @return [Float]
82
- # @api private
83
- def _scan_float(str, fill_value = nil); end
84
-
85
- # @overload _scan_int(str, fill_value = nil)
86
- # Parses `str` as a single integer. Returns `fill_value`
87
- # (or `0` if `fill_value` is nil) when `str` is `nil` or
88
- # unparseable. Internal helper used by text-format I/O readers.
89
- # @param str [String, nil]
90
- # @param fill_value [Integer, nil]
91
- # @return [Integer]
92
- # @api private
93
- def _scan_int(str, fill_value = nil); end
94
-
95
- # @!endgroup
96
70
  end
97
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carray
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - himotoyoshi
@@ -45,7 +45,6 @@ files:
45
45
  - ext/ca_composite_dispatch.c
46
46
  - ext/ca_composite_dispatch.h
47
47
  - ext/ca_for_buffer.h
48
- - ext/ca_for_each_element.h
49
48
  - ext/ca_group_iter.c
50
49
  - ext/ca_iter_substrate.h
51
50
  - ext/ca_kernel_iterator.c
@@ -96,6 +95,7 @@ files:
96
95
  - ext/ca_op_cmplx64.h
97
96
  - ext/ca_op_ipower.c
98
97
  - ext/ca_op_powi.h
98
+ - ext/ca_pow5_table.h
99
99
  - ext/ca_rng_normal.h
100
100
  - ext/ca_rng_xoshiro256pp.h
101
101
  - ext/ca_sort_kernels.h
@@ -104,19 +104,18 @@ files:
104
104
  - ext/ca_transform_common.c
105
105
  - ext/ca_triop_dispatch.c
106
106
  - ext/ca_triop_dispatch.h
107
+ - ext/caframe_csv_reader.c
107
108
  - ext/carray.h
108
109
  - ext/carray_access.c
109
110
  - ext/carray_address_basis.c
110
111
  - ext/carray_attribute.c
111
112
  - ext/carray_bincount.c
112
113
  - ext/carray_broadcast.c
113
- - ext/carray_build_flags.h
114
114
  - ext/carray_call_cfunc.c
115
115
  - ext/carray_call_cfunc.h
116
116
  - ext/carray_cast.c
117
117
  - ext/carray_cast_func.rb
118
118
  - ext/carray_class.c
119
- - ext/carray_config.h
120
119
  - ext/carray_conversion.c
121
120
  - ext/carray_copy.c
122
121
  - ext/carray_core.c
@@ -130,21 +129,6 @@ files:
130
129
  - ext/carray_index_classifier.c
131
130
  - ext/carray_index_classifier.h
132
131
  - ext/carray_internal.h
133
- - ext/carray_kernels_bincmp.c
134
- - ext/carray_kernels_binop.c
135
- - ext/carray_kernels_init.c
136
- - ext/carray_kernels_map.c
137
- - ext/carray_kernels_moncmp.c
138
- - ext/carray_kernels_monop.c
139
- - ext/carray_kernels_reduce_aggregate.c
140
- - ext/carray_kernels_reduce_boolean.c
141
- - ext/carray_kernels_reduce_cumulative.c
142
- - ext/carray_kernels_reduce_extreme.c
143
- - ext/carray_kernels_reduce_variance.c
144
- - ext/carray_kernels_scan.c
145
- - ext/carray_kernels_search.c
146
- - ext/carray_kernels_sort.c
147
- - ext/carray_kernels_triop.c
148
132
  - ext/carray_lazy.c
149
133
  - ext/carray_loop.c
150
134
  - ext/carray_mask.c
@@ -157,16 +141,19 @@ files:
157
141
  - ext/carray_partition.c
158
142
  - ext/carray_random.c
159
143
  - ext/carray_scatter.c
144
+ - ext/carray_segment.c
160
145
  - ext/carray_slab.c
161
146
  - ext/carray_slab.h
162
147
  - ext/carray_sort.c
163
148
  - ext/carray_sort_kernel.c
164
149
  - ext/carray_struct.c
165
150
  - ext/carray_test.c
151
+ - ext/carray_time_text.c
166
152
  - ext/carray_undef.c
167
153
  - ext/carray_utils.c
168
154
  - ext/extconf.rb
169
155
  - ext/mk_call_cfunc.rb
156
+ - ext/mk_pow5_table.rb
170
157
  - ext/mkkernel.rb
171
158
  - ext/ruby_carray.c
172
159
  - ext/version.h
@@ -195,11 +182,13 @@ files:
195
182
  - lib/carray/frame/concat.rb
196
183
  - lib/carray/frame/convert.rb
197
184
  - lib/carray/frame/csv_parser.rb
185
+ - lib/carray/frame/describe.rb
198
186
  - lib/carray/frame/frame.rb
199
187
  - lib/carray/frame/group.rb
200
188
  - lib/carray/frame/io.rb
201
189
  - lib/carray/frame/join.rb
202
190
  - lib/carray/frame/records.rb
191
+ - lib/carray/frame/reshape.rb
203
192
  - lib/carray/frame/sort.rb
204
193
  - lib/carray/frame/verbs.rb
205
194
  - lib/carray/fuse_source.rb
@@ -237,8 +226,10 @@ files:
237
226
  - lib/carray/methods/unique.rb
238
227
  - lib/carray/methods/value_counts.rb
239
228
  - lib/carray/mkmf.rb
229
+ - lib/carray/record_order.rb
240
230
  - lib/carray/rng.rb
241
231
  - lib/carray/runtime.rb
232
+ - lib/carray/segment_iterator.rb
242
233
  - lib/carray/serialize.rb
243
234
  - lib/carray/slab_iterator.rb
244
235
  - lib/carray/stack.rb
@@ -286,6 +277,7 @@ files:
286
277
  - yard-stubs/carray_order.rb
287
278
  - yard-stubs/carray_random.rb
288
279
  - yard-stubs/carray_scatter.rb
280
+ - yard-stubs/carray_segment.rb
289
281
  - yard-stubs/carray_slab.rb
290
282
  - yard-stubs/carray_sort.rb
291
283
  - yard-stubs/carray_test.rb