carray 3.0.5 → 3.0.7

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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +343 -0
  3. data/README.md +25 -4
  4. data/carray.gemspec +3 -2
  5. data/ext/ca_axis_dispatch.c +6 -0
  6. data/ext/ca_axis_group.c +7 -7
  7. data/ext/ca_binop_dispatch.c +8 -0
  8. data/ext/ca_binop_dispatch.h +1 -0
  9. data/ext/ca_categorical_iterator.c +14 -14
  10. data/ext/ca_kernel_iterator.c +116 -231
  11. data/ext/ca_kernel_iterator.h +416 -258
  12. data/ext/ca_obj_array.c +4 -4
  13. data/ext/ca_obj_bincmp.c +28 -4
  14. data/ext/ca_obj_binop.c +46 -12
  15. data/ext/ca_obj_bitarray.c +2 -4
  16. data/ext/ca_obj_bitfield.c +88 -4
  17. data/ext/ca_obj_byte_swap.c +4 -4
  18. data/ext/ca_obj_const_string.c +422 -257
  19. data/ext/ca_obj_face.c +73 -33
  20. data/ext/ca_obj_fake.c +114 -13
  21. data/ext/ca_obj_farray.c +7 -1
  22. data/ext/ca_obj_fixlen_string.c +51 -17
  23. data/ext/ca_obj_grid.c +179 -19
  24. data/ext/ca_obj_meld.c +74 -118
  25. data/ext/ca_obj_moncmp.c +9 -1
  26. data/ext/ca_obj_monop.c +100 -36
  27. data/ext/ca_obj_object.c +63 -29
  28. data/ext/ca_obj_reduce.c +17 -5
  29. data/ext/ca_obj_refer.c +162 -23
  30. data/ext/ca_obj_remap.c +69 -10
  31. data/ext/ca_obj_repeat.c +1 -1
  32. data/ext/ca_obj_roll.c +3 -4
  33. data/ext/ca_obj_select.c +12 -7
  34. data/ext/ca_obj_select_axis.c +9 -6
  35. data/ext/ca_obj_shift.c +1 -0
  36. data/ext/ca_obj_stack.c +315 -116
  37. data/ext/ca_obj_stride.c +177 -53
  38. data/ext/ca_obj_string.c +20 -4
  39. data/ext/ca_obj_tile.c +3 -4
  40. data/ext/ca_obj_triop.c +24 -13
  41. data/ext/ca_obj_window.c +23 -15
  42. data/ext/ca_op_ipower.c +71 -23
  43. data/ext/ca_op_powi.h +6 -29
  44. data/ext/ca_sort_kernels.h +3 -0
  45. data/ext/ca_sweep_engine.c +90 -23
  46. data/ext/ca_sweep_engine.h +5 -6
  47. data/ext/caframe_csv_reader.c +2 -2
  48. data/ext/carray.h +5 -2
  49. data/ext/carray_access.c +125 -103
  50. data/ext/carray_address_basis.c +209 -1
  51. data/ext/carray_attribute.c +8 -0
  52. data/ext/carray_broadcast.c +5 -6
  53. data/ext/carray_build_flags.h +1 -1
  54. data/ext/carray_call_cfunc.c +5 -8
  55. data/ext/carray_cast.c +319 -48
  56. data/ext/carray_cast_func.rb +37 -5
  57. data/ext/carray_conversion.c +65 -7
  58. data/ext/carray_copy.c +24 -0
  59. data/ext/carray_core.c +874 -72
  60. data/ext/carray_count.c +28 -9
  61. data/ext/carray_element.c +22 -12
  62. data/ext/carray_factorize.c +11 -11
  63. data/ext/carray_histogram.c +27 -5
  64. data/ext/carray_index_classifier.c +7 -5
  65. data/ext/carray_internal.h +241 -12
  66. data/ext/carray_kernels_bincmp.c +2007 -3
  67. data/ext/carray_kernels_binop.c +25502 -5336
  68. data/ext/carray_kernels_init.c +22 -22
  69. data/ext/carray_kernels_monop.c +10739 -3771
  70. data/ext/carray_kernels_reduce_aggregate.c +4429 -702
  71. data/ext/carray_kernels_reduce_boolean.c +1533 -15
  72. data/ext/carray_kernels_reduce_cumulative.c +1808 -248
  73. data/ext/carray_kernels_reduce_extreme.c +4508 -511
  74. data/ext/carray_kernels_reduce_variance.c +2284 -152
  75. data/ext/carray_kernels_scan.c +240 -240
  76. data/ext/carray_kernels_search.c +4211 -264
  77. data/ext/carray_kernels_sort.c +367 -450
  78. data/ext/carray_lazy.c +63 -1
  79. data/ext/carray_loop.c +10 -3
  80. data/ext/carray_mask.c +247 -149
  81. data/ext/carray_median_percentile.c +17 -12
  82. data/ext/carray_memory_view.c +54 -29
  83. data/ext/carray_operator.c +219 -55
  84. data/ext/carray_order.c +55 -11
  85. data/ext/carray_partition.c +1 -1
  86. data/ext/carray_random.c +5 -2
  87. data/ext/carray_round.c +24 -1
  88. data/ext/carray_scatter.c +4 -0
  89. data/ext/carray_segment.c +1 -1
  90. data/ext/carray_slab.c +110 -25
  91. data/ext/carray_sort.c +7 -4
  92. data/ext/carray_sort_kernel.c +24 -0
  93. data/ext/carray_struct.c +21 -6
  94. data/ext/carray_test.c +154 -53
  95. data/ext/carray_time_text.c +8 -2
  96. data/ext/carray_utils.c +124 -54
  97. data/ext/extconf.rb +11 -0
  98. data/ext/mk_call_cfunc.rb +6 -11
  99. data/ext/mkkernel.rb +383 -121
  100. data/ext/ruby_carray.c +4 -1
  101. data/ext/version.h +4 -4
  102. data/lib/carray/attribute.rb +25 -1
  103. data/lib/carray/autoload_carray.rb +3 -3
  104. data/lib/carray/autoload_method_extension.rb +5 -3
  105. data/lib/carray/axis_group.rb +22 -13
  106. data/lib/carray/basics.rb +27 -9
  107. data/lib/carray/bincount_nd.rb +8 -2
  108. data/lib/carray/block_iterator.rb +65 -24
  109. data/lib/carray/categorical.rb +27 -16
  110. data/lib/carray/categorical_iterator.rb +4 -3
  111. data/lib/carray/complex.rb +2 -2
  112. data/lib/carray/conditional.rb +55 -6
  113. data/lib/carray/const_string.rb +74 -0
  114. data/lib/carray/construct.rb +2 -2
  115. data/lib/carray/core_extensions.rb +19 -68
  116. data/lib/carray/data_type_extension.rb +1 -0
  117. data/lib/carray/fixlen_string.rb +83 -1
  118. data/lib/carray/frame/column_verbs.rb +102 -16
  119. data/lib/carray/frame/concat.rb +50 -6
  120. data/lib/carray/frame/convert.rb +19 -0
  121. data/lib/carray/frame/csv_parser.rb +45 -36
  122. data/lib/carray/frame/describe.rb +4 -2
  123. data/lib/carray/frame/frame.rb +436 -83
  124. data/lib/carray/frame/group.rb +731 -78
  125. data/lib/carray/frame/io.rb +216 -73
  126. data/lib/carray/frame/join.rb +166 -43
  127. data/lib/carray/frame/records.rb +9 -7
  128. data/lib/carray/frame/reshape.rb +109 -11
  129. data/lib/carray/frame/sort.rb +57 -9
  130. data/lib/carray/frame/verbs.rb +448 -60
  131. data/lib/carray/frame/windows.rb +71 -9
  132. data/lib/carray/fuse_source.rb +4 -2
  133. data/lib/carray/inspect.rb +7 -2
  134. data/lib/carray/iterator.rb +40 -0
  135. data/lib/carray/key_windows.rb +10 -4
  136. data/lib/carray/lazy.rb +28 -24
  137. data/lib/carray/mask_gap_fill.rb +37 -17
  138. data/lib/carray/meld_reduce.rb +1 -1
  139. data/lib/carray/methods/bin.rb +3 -0
  140. data/lib/carray/methods/choose.rb +3 -2
  141. data/lib/carray/methods/composition.rb +1 -1
  142. data/lib/carray/methods/factorize.rb +2 -0
  143. data/lib/carray/methods/gather_nd.rb +4 -1
  144. data/lib/carray/methods/is_in.rb +23 -3
  145. data/lib/carray/methods/locate_addr.rb +63 -12
  146. data/lib/carray/methods/meshgrid.rb +3 -1
  147. data/lib/carray/methods/repeat.rb +11 -1
  148. data/lib/carray/record_order.rb +35 -6
  149. data/lib/carray/runtime.rb +57 -8
  150. data/lib/carray/segment_iterator.rb +42 -24
  151. data/lib/carray/serialize.rb +56 -17
  152. data/lib/carray/slab_iterator.rb +1 -1
  153. data/lib/carray/stack.rb +21 -9
  154. data/lib/carray/string.rb +6 -6
  155. data/lib/carray/string_operation_extension.rb +25 -4
  156. data/lib/carray/struct_builder.rb +4 -1
  157. data/lib/carray/time.rb +195 -46
  158. data/lib/carray/window_iterator.rb +64 -16
  159. data/yard-stubs/ca_obj_array.rb +26 -1
  160. data/yard-stubs/ca_obj_bitfield.rb +4 -1
  161. data/yard-stubs/ca_obj_refer.rb +3 -0
  162. data/yard-stubs/ca_obj_window.rb +2 -1
  163. data/yard-stubs/carray_access.rb +4 -2
  164. data/yard-stubs/carray_cast.rb +14 -5
  165. data/yard-stubs/carray_conversion.rb +8 -2
  166. data/yard-stubs/carray_count.rb +6 -3
  167. data/yard-stubs/carray_mask.rb +20 -1
  168. data/yard-stubs/carray_math.rb +36 -16
  169. data/yard-stubs/carray_memory_view.rb +7 -0
  170. data/yard-stubs/carray_order.rb +6 -0
  171. data/yard-stubs/carray_scatter.rb +2 -1
  172. data/yard-stubs/carray_test.rb +23 -7
  173. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccd30e8ea5b53c3a2654a86a0ab7473b3073f7feffa7db7be0e5c9aef5bc17c8
4
- data.tar.gz: ffcd91fe93ca10b4b12dbff035ffc25533699472b364482a59bf2aa635296032
3
+ metadata.gz: dc1e09cd60b311255af53d363b340440aa899193bbe93cd314abc5211dcd81b2
4
+ data.tar.gz: 3cb15673d7396b64a4fe4ccfa5956862c96b8f7c772194adf4059aff5086c4eb
5
5
  SHA512:
6
- metadata.gz: 53c08f4ccf6a4c25219cef4e8f27e7de9740dc8c69ee493ff8e3631c87499cd15ed121d5f7707bd1017f77e0309dc1be2628fa3611b9b3c979e0e075008842d6
7
- data.tar.gz: 2200b047a456603d6274d9dfaf8f93c011ce1cc1eb457c454fa7f9cdc9c75ea4b96c9bbe1dab0b37710f8b872ac5e8b630db5c0dacae12a9012b1b34d4c7f1ec
6
+ metadata.gz: 8d1077b9d4602707efa889976e1d60908303d7525b5238faf090aa22dd5b21d7c3b5a534775c7290dd88aa7be0db1ad2472da4a6f73d8d75d5c9fdefafcf7cb5
7
+ data.tar.gz: 1715c2a8f1dcf6dc16439f2aedde45cae012d6a9cc1713f0b84ed8be1930d1e3114f41c3100c363888fbd8395feeedbf2f96eae7443dba2495cac85dab2fb04e
data/CHANGELOG.md CHANGED
@@ -34,6 +34,349 @@ and a newer one. The 1.x history, up to the 2.0.0 release, is in
34
34
  neighbour ("as well", "the producer above") or leave unnamed the
35
35
  method, class or keyword it is about. -->
36
36
 
37
+ ## 3.0.7
38
+
39
+ - New: `CATime` and `CATimedelta` take the word forms of their operators
40
+ (`add`, `sub`; on a duration also `mul`, `div`, `neg`). A duration array
41
+ divided by one duration gives the ratios as numbers, a number may stand
42
+ left of a duration (`2 * d`), a duration element has `-@` and `abs`, and
43
+ a duration array has `to_seconds`. A duration's comparisons and stores
44
+ take a String such as `"3 days"`.
45
+
46
+ - New: `pmax` and `pmin` (with `maximum`, `minimum`, `fmax`, `fmin`) on
47
+ `CATimedelta`, `CAFixlenString` and `CAConstString`. `CAConstString`
48
+ also has `match`, `bsearch`, `bsearch_addr`, `search_addr`, `min_addr`
49
+ and `max_addr`.
50
+
51
+ - New: a `CAFixlenString` carries the encoding of its text
52
+ (`a.encoding`), and its cells read in that encoding: UTF-8 when the
53
+ strings were ASCII, `BINARY` when they disagreed. `to_const_string`
54
+ keeps it, so non-ASCII text comes back from `to_fixlen_string`. Two
55
+ arrays of different text encodings no longer stack.
56
+
57
+ - New: `CAFrame#resample` takes a `CArray` as `by:`, and a windowed
58
+ reduction takes a Hash of column name to value as `fill_value:`.
59
+ `CACategorical#count` takes the keywords of `CArray#count`, and the
60
+ `all` and `any` of a categorical iterator take `axis:`.
61
+
62
+ - New: `CArray.from_memory_view` and `wrap_memory_view` take an item of
63
+ several members (a record) as raw bytes, a `fixlen` array of the item's
64
+ size.
65
+
66
+ - Change: a Float is refused as a shape, a size or a count
67
+ (`CArray.int32(2.5)`, `blocks(2.5)`, the counts of `repeat`), whole or
68
+ not; it was cut down to an Integer. A Float key of `[]` still reads as a
69
+ position.
70
+
71
+ - Change: a data type name must match whole. `:complex128`, `:float16` or
72
+ `:int128` raise `ArgumentError`; they were read as the type whose name
73
+ they begin with (`:complex128` gave `cmplx64`). Write `:cmplx128`.
74
+ `CArray::Complex64::TypeSymbol` and `CArray::Complex128::TypeSymbol` are
75
+ `:cmplx64` and `:cmplx128`.
76
+
77
+ - Change: a keyword given with a String key (`a.sum("axis" => 0)`) raises
78
+ `ArgumentError`; it was ignored. Write `axis: 0`.
79
+
80
+ - Change: storing complex cells into a real array raises; the imaginary
81
+ parts were dropped. Convert with `to_type` first.
82
+
83
+ - Change: an object or boolean array given where addresses are expected
84
+ (`project`, `scatter_add!` and the other `scatter_*!`, `addr2index`)
85
+ raises `IndexError`. A boolean array still selects in `[]`.
86
+
87
+ - Change: a value a numeric or boolean array cannot hold (`nil`, a String,
88
+ a Symbol, another object) is answered alike for every data type: an
89
+ operator raises `TypeError`, an ordering (`<`, `pmax` and its kin)
90
+ raises `ArgumentError`, and `eq`, `ne`, `count`, `search` and `is_in`
91
+ find no cell. `search("2")` on a numeric array used to read the text.
92
+ `true` and `false` are 1 and 0, so `count(true)` counts the cells
93
+ holding 1. An object array still looks such values up as values.
94
+
95
+ - Change: `UNDEF` beside an array in an operation is a masked scalar of the
96
+ array's own type, so `CA_INT32([1, 2]) + UNDEF` is an all-masked `int32`
97
+ array; integer, boolean and fixlen arrays gave an object array.
98
+
99
+ - Change: `to_type` to an integer type gives `UNDEF` for an object Float,
100
+ Rational, BigDecimal or Complex the type cannot hold, and keeps the low
101
+ bytes of an object Integer wider than 64 bits, as `int64` to `int8` does.
102
+ A store and a view still refuse such values.
103
+
104
+ - Change: `x ** k` with an Integer `k` from -2 to 4 is computed by at most
105
+ two multiplications or divisions (`x ** 2` is `x * x`), and other Integer
106
+ exponents through `pow`, for a scalar and an array exponent alike,
107
+ eagerly and lazily. Float and complex results can differ from 3.0.6 in
108
+ the last bit.
109
+
110
+ - Change: a time or a date with a year past four digits is written with
111
+ its sign (`"+12345-01-01"`), in `to_s` and in CSV, so it reads back.
112
+
113
+ - Change: `join`, `join_asof`, `align`, `CAFrame.concatenate`, `stack` and
114
+ `stack_columns` refuse integers that the float type they meet would
115
+ round (past 2**53 beside `float64`), in a key or in the pieces of a
116
+ column; such integers matched or merged with neighbouring values. Cast
117
+ one side to the other's type first.
118
+
119
+ - Change: the frames that `GroupedFrame`, the windows and a frame's own
120
+ verbs return hold a copy of the index, so a write to the result's index
121
+ does not reach the source frame.
122
+
123
+ - Change: `CAFrame` refuses, with an `ArgumentError` that names the verb,
124
+ a `GroupedFrame#table` or `#filter` without a block, a `lag` step that is
125
+ not an Integer, a `columns:` Range that selects no column, a
126
+ `fill_value:` Hash naming no column, a row-wise group verb with no column
127
+ left to compute, and a splice of a frame without an index into one with
128
+ an index.
129
+
130
+ - Change: CSV type inference reads a column as text when a float would
131
+ round one of its integers, and an object column of Integers past 2**53
132
+ beside a Float is not inferred as `float64`.
133
+
134
+ - Change: a walk into object cells (`unique`, `hash`, `Marshal.dump`,
135
+ computations over the cells) raises past 256 levels of nesting. A cell
136
+ holding a lazy expression over the array that holds the cell made these
137
+ run without end.
138
+
139
+ - Change: a String Face (`CAString`, `CAFixlenString`, `CAConstString`)
140
+ refuses an ordering with a value that is not a String, and a Face
141
+ refuses a single Ruby object as the operand of an operator the Face does
142
+ not define.
143
+
144
+ - Change (C extensions and carray-jit): `CArray::AddressBasis.sweep` and
145
+ the sweep bridge refuse a `CScalar` output beside an array operand.
146
+
147
+ ## 3.0.6
148
+
149
+ - New: `CAFrame` answers the column reductions itself, as a frame of one
150
+ row (`df.mean`, `df.sum("rain", "temp")`), and the running values down
151
+ all its rows (`df.cumsum("rain")`, `order`), as a grouped frame does
152
+ down each group. `percentile(p, *names)` and `quantile` (a column per
153
+ quartile, `"rain_p0"` ... `"rain_p100"`) are added to the frame, groups
154
+ and windows.
155
+
156
+ - New: `CAFrame` row picks: `nlargest` / `nsmallest` (also on
157
+ `GroupedFrame`), `drop_masked` for the rows with no masked cell,
158
+ `GroupedFrame#head` / `#tail` for the first and last rows of each group,
159
+ and `filter` given a boolean selector directly (`df.filter(df["n"] > 3)`).
160
+
161
+ - New: `CAFrame#transform` computes columns with a block, keeping their
162
+ names and the index. `select`, `drop`, `transform` and `describe` pick
163
+ columns by a Range of names, a Regexp, a kind (`:float`, `:integer`,
164
+ `:complex`, `:timedelta`, ...) or a data type.
165
+
166
+ - New: `CAFrame#value_counts` (how many rows hold each value, as a
167
+ frame), `#strip_mask` (the masked cells filled, in a new frame), `#to_a`
168
+ (the rows as Arrays, masked cells `UNDEF`), `#shape`, `#empty?`, and
169
+ `GroupedFrame#each` and `#size`. `CAFrame#==` compares two frames by
170
+ their table: names, columns, index and row axis name.
171
+
172
+ - New: `CAFrame#lag` and `GroupedFrame#lag` take a distance of the key,
173
+ `before: "1 hour"` or `after:`, giving each row the value of the row at
174
+ exactly that distance (`UNDEF` where there is none). The key is the
175
+ index or the column `on:` names: a time, a duration or a number.
176
+
177
+ - New: `join` and `join_asof` take a key named differently on the two
178
+ sides, and `view: :full`, which gives every column of the result as a
179
+ view, with holes for the unmatched rows, so a write reaches either
180
+ frame.
181
+
182
+ - New: `df[name] = value` with a single value repeats it on every row.
183
+ `fill` takes several columns, an Array of names or a Hash of column =>
184
+ value; `rename` takes a block, can exchange two names, and renames the
185
+ index under its name. `sort_by_key` and `sort_by` take `descending:`.
186
+
187
+ - New: `CAFrame#set_column_attrs` gives columns their names and common
188
+ attributes; `CArray#attrs_symkey` and `CAFrame#attrs_symkey` return the
189
+ attributes with Symbol keys. `CAFrame#to_csv` takes `precision:`.
190
+
191
+ - New: `GroupedFrame#fill(name, :linear)` interpolates within each group.
192
+ On a frame, `:linear` reads an index that is not in order as one series
193
+ in index order.
194
+
195
+ - New: `melt` brings number columns of different types (an `int64` and a
196
+ `float64` column) to their common type, still as a view. A mixture no
197
+ type holds without changing a value (`int64` beside `uint64`), or one
198
+ with text or time, is refused; cast the columns first.
199
+
200
+ - New: `wsum` and `wmean` take weights shaped as the reduced axes, matched
201
+ in ascending axis order, besides a scalar and weights of the receiver's
202
+ shape.
203
+
204
+ - New (C extensions and carray-jit): `CArray::AddressBasis.sweep(function,
205
+ fsync, arrays, *parts)` runs a chunked element-wise sweep
206
+ (`ca_call_cslab_N_r`, arities 1 to 7) from Ruby, handing the slab
207
+ pointers to the parts' own String bytes. An `fsync` character other than
208
+ `0` or `1` is refused.
209
+
210
+ - Change: CArray requires Ruby 3.2 or later, up from 3.0. On an older
211
+ Ruby, `gem install carray` does not offer this release; install a
212
+ newer Ruby with a version manager such as rbenv or mise, or stay on
213
+ 3.0.5.
214
+
215
+ - Change: CSV reading and writing are split by what they take.
216
+ `CAFrame.read_csv` and `#write_csv` take a path or an IO;
217
+ `CAFrame.from_csv` takes CSV text as a String and `#to_csv` returns it.
218
+ Code that gave `from_csv` a path or an IO calls `read_csv`, and
219
+ `to_csv(path)` becomes `write_csv(path)`. No aliases are kept.
220
+
221
+ - Change: `read_csv` and `from_csv` infer the column types by default
222
+ (`int64`, `float64`, `boolean`, `time`, otherwise text); `types:` names
223
+ some columns and the rest are still inferred. Pass `types: :string` to
224
+ read every column as text, as before. A column with a blank but present
225
+ value (a quoted `""`) stays text.
226
+
227
+ - Change: `CAFrame#set_index`, `#reset_index`, `#cast`, `#promote`,
228
+ `#parse_to_time` and `#to_time` return a new frame and leave the
229
+ receiver as it is (the two share their columns). Assign the result:
230
+ `df = df.set_index("time")`.
231
+
232
+ - Change: a `GroupedFrame` reduction given column names returns a frame of
233
+ those columns, one row per group, labelled as without names; it
234
+ returned the `CArray` (one name) or an `Array` of them. Take the column
235
+ (`grp.mean("temp")["temp"]`) or reduce the group iterator
236
+ (`grp["temp"].mean`) for the values alone.
237
+
238
+ - Change: a `GroupedFrame` or window value on the frame's rows given
239
+ several column names (`keep_rows: true`, the running values, `lag`,
240
+ `w.mean("a", "b")`) returns a frame of them on the frame's rows and
241
+ index, instead of an `Array`. One name still gives the `CArray`.
242
+
243
+ - Change: `CAFrame#filter` no longer takes `keep_masked:`, so every row
244
+ selection is a view. To keep the rows whose condition is undetermined,
245
+ say so in the selector: `df.filter(cond.is_masked)` or
246
+ `df.filter(cond.strip_mask(true))`.
247
+
248
+ - Change: `df[sel] = ...` refuses a Ruby Array as the row selector, as
249
+ `df[]` does; the column indexer would read `[0, 2]` as two rows from
250
+ row 0. Write `df[CA_INT64([0, 2])]` for rows 0 and 2.
251
+
252
+ - Change: a group key named in a `GroupedFrame` reduction, and the index's
253
+ name given to a verb that reads or changes columns (`df[...]`,
254
+ `select`, `fill`, `cast`, the reductions), raise and point at `size`
255
+ or `df.index`. A key argument (`group_by`, `sort_by_key`, `join(on:)`)
256
+ still names the index.
257
+
258
+ - Change: an `:inner` or `:right` `join` gives the other frame's columns
259
+ as views picked by row, not copies, so a write to them reaches that
260
+ frame. Call `copy` on the result to keep it apart.
261
+
262
+ - Change: a `CScalar` takes only `s[]` and `s[0]`, reading or writing its
263
+ one cell; any other index (`s[3]`, a range, `nil`, an index array)
264
+ raises. A view such as `s.refer(s.data_type, [1])` takes the usual
265
+ indexes.
266
+
267
+ - Change: `CArray.stack` and `CArray.meld` refuse a value array
268
+ (`a.value`) or a mask array (`a.mask`) as a part. Pass a copy
269
+ (`a.value.copy`), or `a.is_masked` for the mask's values.
270
+
271
+ - Change: `CArray#==` finds a NaN equal to a NaN, so an array holding NaN
272
+ equals its copy and the array read back from a file. The cell-by-cell
273
+ IEEE comparison is `eq`; `eql?` still compares bits.
274
+
275
+ - Change: `CARemap#mapper` returns a read-only array; writing it raises.
276
+ The index array given to `a[idx]` is not affected.
277
+
278
+ - Change: `Marshal.dump` of a `CAWrap` (from `CArray.wrap_memory_view`)
279
+ writes its values, and the load gives a plain array owning a copy of
280
+ them, as for a view of the wrap; it raised `TypeError`.
281
+
282
+ - Change: `as_type` returns a view also when the data type is the
283
+ receiver's own, and `CATime#to_unit` / `CATimedelta#to_unit` return a
284
+ new array when the unit does not change, so an attribute set on, or a
285
+ freeze of, the result does not reach the receiver.
286
+
287
+ - Change: `wmean` gives `UNDEF` where the weights sum to zero, on every
288
+ path; numeric arrays gave NaN or an infinity. A weight array with one
289
+ element is no longer read as a scalar: give a Ruby number or a
290
+ `CScalar`.
291
+
292
+ - Change: a computation over an object array that comes back into the
293
+ array (a cell holding the array, or a view of it) raises, as reading
294
+ such a cell does; it recursed until the process died. A lazy
295
+ expression over such an array (a cell holding `x + 1` for the array `x`)
296
+ raises the same way instead of overflowing the stack or not ending, and
297
+ so does `Marshal.dump` of an object view whose cells lead back to its
298
+ root.
299
+
300
+ - Change (CAObject authors): a `CAObject` without `create_mask` raises
301
+ `TypeError` when its `copy_data` writes `UNDEF`, as it does when a
302
+ fetcher answers `UNDEF`; the `UNDEF` was dropped and read as a value.
303
+
304
+ - Change (C extensions): `ca_install_obj_type` refuses an operation table
305
+ without `allocate`, `attach`, `sync` and `detach` slots;
306
+ `ca_iter_register_source_kind` refuses carray's own types; and the
307
+ kernel iterator's `FIBER_PAIR` forms refuse `CA_KERNEL_WRITE`.
308
+
309
+ - Fix: `require "carray"` works on Ruby 4.0; it raised
310
+ `Ractor::IsolationError` since 3.0.4.
311
+
312
+ - Fix: `CArray.fuse` works on Ruby 3.2 and 3.3. The gem now depends on
313
+ prism 1.0 or later, which `gem install` and Bundler bring in on Ruby
314
+ 3.2, which ships none, and 3.3, whose own prism is too old; Ruby 3.4
315
+ and later already ship it.
316
+
317
+ - Fix: a block of a reshape over a strided view
318
+ (`a[1..2, 1..3].reshape(3, 2)[0..1, nil]`) read and wrote past the end
319
+ of a row, outside the buffer at the edges.
320
+
321
+ - Fix: a frozen object array shared between Ractors can be computed over
322
+ in several at once; it was refused as cyclic. A cell holding a view of
323
+ other cells of the same array is no longer refused.
324
+
325
+ - Fix: a record array (`CARecord`) exports through MemoryView from a
326
+ Ractor other than the main one; it raised `Ractor::IsolationError`.
327
+
328
+ - Fix: `Marshal.dump` of a view no longer writes its whole parent (a
329
+ one-cell view of a 100,000-cell array dumped about 400 KB), and an
330
+ array's mask marshals as a plain boolean array.
331
+
332
+ - Fix: an `each_slab` Enumerator stopped part way with `next` leaves no
333
+ array attached once its Fiber is collected.
334
+
335
+ - Fix: a window or block iterator reads its source afresh on each call;
336
+ after the source changed, a later reduction mixed new sums with old
337
+ counts.
338
+
339
+ - Fix: a frozen or read-only `CArray.meld` refuses writes through a meld
340
+ of it (`CArray.meld(m, m)` wrote into the frozen root).
341
+
342
+ - Fix: a write to a `CArray.stack` or `CArray.meld` whose parts share
343
+ cells (`CArray.meld(a, a)`) gives those cells the value, or the mask, of
344
+ the last part; `add!` could leave an earlier part's result, and a mask
345
+ write masked the cells of every part.
346
+
347
+ - Fix: a write to a `CArray.stack` or `CArray.meld` that one part refuses
348
+ (a value outside a part's data type) writes nothing; the parts before
349
+ it were written.
350
+
351
+ - Fix: `blocks(...).sort_addr` works when the source holds more than one
352
+ tile; it failed with `IndexError`.
353
+
354
+ - Fix: `elem_fetch` answers a boolean cell with `true` or `false` when given
355
+ an index array over a view, as `[]` does; it answered `0` or `1`.
356
+
357
+ - Fix: `CAFrame#fill(:linear)` leaves a row with no coordinate out of the
358
+ interpolation; it was filled with 0.
359
+
360
+ - Fix: `bin_to` and `histogram1d` put a value next to an edge in the bin
361
+ that edge bounds when the edges are nearly but not exactly equally
362
+ spaced.
363
+
364
+ - Fix: `float ** Integer` takes any exponent that fits 64 bits, eagerly
365
+ as lazily, and `x.lazy.pow(k)` answers as `x.pow(k)`. A lazy array
366
+ compared with `UNDEF` (`eq`, `ne`) answers as the eager one does.
367
+
368
+ - Fix: writing `UNDEF` through a widening `refer` (`r.refer(:float64,
369
+ ...)`) no longer masks parent cells outside the written cells, and a
370
+ mask written onto a `CAObject` without mask hooks survives the next
371
+ read of its values.
372
+
373
+ - Fix: a masked cell that is not a String reads as `""` when a `CAString`
374
+ wraps a view, as it does over an entity.
375
+
376
+ - Fix (CASource authors): a source that leaves its `ptr` NULL at rest no
377
+ longer crashes `elem_*`, `dump_binary` to a File or `nlargest` over a
378
+ whole axis.
379
+
37
380
  ## 3.0.5
38
381
 
39
382
  - New: `GroupedFrame#aggregate` takes a block instead of a spec. The block
data/README.md CHANGED
@@ -30,7 +30,7 @@ Or add it to your `Gemfile`:
30
30
  gem "carray"
31
31
  ```
32
32
 
33
- Requires Ruby 3.0 or later.
33
+ Requires Ruby 3.2 or later.
34
34
 
35
35
  On a multi-core machine, parallel `make` cuts install time noticeably:
36
36
 
@@ -109,18 +109,39 @@ b.strip_mask(Float::NAN).sum(axis: 0)
109
109
 
110
110
  ## Documentation
111
111
 
112
+ #### Basics
113
+
112
114
  * [Introduction](guides/users/introduction.md) — what Ruby/CArray is
113
115
  * [Getting started](guides/users/00_getting_started.md) — install, and a first array
114
116
  * [Creating arrays](guides/users/01_creating_arrays.md) — constructors, data types, filling
115
117
  * [Indexing and slicing](guides/users/02_indexing_and_slicing.md) — elements, rows, blocks, conditions
116
- * [Indexer reference](guides/users/16_indexer_reference.md) — every form `[]` accepts
117
118
  * [Element-wise operations](guides/users/03_elementwise.md) — arithmetic and mathematical functions
118
- * [Broadcasting](guides/users/07_broadcasting.md) — shapes that differ
119
- * [Views](guides/users/06_views.md) — referring to data without copying
120
119
  * [Reduction and statistics](guides/users/04_reduction_and_statistics.md) — summaries, whole or per axis
121
120
  * [Masks and missing values](guides/users/05_masks.md) — undefined elements, and how calculations treat them
121
+ * [Views](guides/users/06_views.md) — referring to data without copying
122
+ * [Broadcasting](guides/users/07_broadcasting.md) — shapes that differ
123
+
124
+ #### Using arrays
125
+
126
+ * [Indexer reference](guides/users/16_indexer_reference.md) — every form `[]` accepts
127
+
128
+ #### Data that is not plain numbers
129
+
130
+ * [Object arrays](guides/users/13_object_arrays.md) — arrays whose cells hold Ruby objects
131
+ * [Faces](guides/users/12_faces.md) — arrays that read their data as times, categories or strings
132
+
133
+ #### Processing along axes
134
+
135
+ * [Slab iteration](guides/users/11_slab_iteration.md) — running a Ruby block on each slab along an axis
136
+
137
+ #### Data frames
138
+
122
139
  * [Data frames](guides/dataframe/README.md) — tables of named columns, each column a CArray
123
140
 
141
+ #### Appendix
142
+
143
+ * [Vocabulary](guides/users/08_vocabulary.md) — the terms used in these documents
144
+
124
145
  ## Contributing
125
146
 
126
147
  Bug reports and feature requests are welcome — please open an issue.
data/carray.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "carray"
3
- s.version = "3.0.5"
3
+ s.version = "3.0.7"
4
4
  s.authors = ["himotoyoshi"]
5
5
  s.email = ["himotoyoshi@users.noreply.github.com"]
6
6
  s.summary = "Multi-dimensional numerical array class for Ruby"
@@ -17,7 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.homepage = "https://github.com/himotoyoshi/carray"
18
18
  s.license = "MIT"
19
19
  s.platform = Gem::Platform::RUBY
20
- s.required_ruby_version = ">= 3.0"
20
+ s.required_ruby_version = ">= 3.2"
21
+ s.add_dependency "prism", ">= 1.0"
21
22
  s.files = [
22
23
  *Dir.glob("lib/**/*.rb"),
23
24
  *Dir.glob("yard-stubs/**/*.rb"),
@@ -1101,6 +1101,12 @@ ca_axis_view_xfer_all (void *ap, ca_axis_view_fast_t fast, int region_ok,
1101
1101
  if ( ca_attach_is_alias(parent) ) {
1102
1102
  ca_attach(parent); /* window: an alias attach, cannot raise */
1103
1103
  fast(ca, (char *) data, dir);
1104
+ /* An entity that keeps no buffer at rest (the mask of a CAObject, a
1105
+ CASource) attaches a copy, which only its sync writes back; for
1106
+ memory it lends, the sync does nothing. */
1107
+ if ( dir == CA_XFER_PUT ) {
1108
+ ca_sync(parent);
1109
+ }
1104
1110
  ca_detach(parent);
1105
1111
  return;
1106
1112
  }
data/ext/ca_axis_group.c CHANGED
@@ -25,7 +25,7 @@
25
25
  (see the section comment above `rb_ca_axis_group_scan`).
26
26
 
27
27
  Group codes outside [0, k) at any bundle mark the slab element unassigned
28
- (skipped, contributing to no group) — mirrors digitize OOB.
28
+ (skipped, contributing to no group) — mirrors bin_to OOB.
29
29
 
30
30
  Float reductions carry the CArray ε-close contract: relative error bounded,
31
31
  not bit-exact.
@@ -377,8 +377,8 @@ rb_ca_axis_group_reduce (VALUE self, VALUE vgaxes, VALUE vbundles, VALUE vop)
377
377
  ca_size_t k = (ca_size_t) NUM2LONG(RARRAY_AREF(bundle, 1));
378
378
  VALUE vbaxes = RARRAY_AREF(bundle, 2);
379
379
  Check_Type(vbaxes, T_ARRAY);
380
- if ( k <= 0 ) {
381
- rb_raise(rb_eArgError, "axis_group_reduce: bundle k must be positive");
380
+ if ( k < 0 ) {
381
+ rb_raise(rb_eArgError, "axis_group_reduce: bundle k must not be negative");
382
382
  }
383
383
 
384
384
  /* The code table is copied out and the source let go of at once, rather
@@ -390,7 +390,7 @@ rb_ca_axis_group_reduce (VALUE self, VALUE vgaxes, VALUE vbundles, VALUE vop)
390
390
  that the unwind collects. Not a String: a String held only by `keep`
391
391
  can be moved by compaction, taking the bytes under bundle_codes with
392
392
  it. */
393
- VALUE v32 = rb_ca_wrap_readonly(vcodes, INT2NUM(CA_INT32));
393
+ volatile VALUE v32 = rb_ca_wrap_readonly(vcodes, INT2NUM(CA_INT32));
394
394
  rb_ary_push((VALUE) keep, v32);
395
395
  GetCArray(v32, bundle_ca[bi]);
396
396
  h_codes[bi] = 0;
@@ -1212,8 +1212,8 @@ rb_ca_axis_group_scan (VALUE self, VALUE vgaxes, VALUE vbundles, VALUE vop)
1212
1212
  ca_size_t k = (ca_size_t) NUM2LONG(RARRAY_AREF(bundle, 1));
1213
1213
  VALUE vbaxes = RARRAY_AREF(bundle, 2);
1214
1214
  Check_Type(vbaxes, T_ARRAY);
1215
- if ( k <= 0 ) {
1216
- rb_raise(rb_eArgError, "axis_group_scan: bundle k must be positive");
1215
+ if ( k < 0 ) {
1216
+ rb_raise(rb_eArgError, "axis_group_scan: bundle k must not be negative");
1217
1217
  }
1218
1218
 
1219
1219
  /* The code table is copied out and the source let go of at once, rather
@@ -1225,7 +1225,7 @@ rb_ca_axis_group_scan (VALUE self, VALUE vgaxes, VALUE vbundles, VALUE vop)
1225
1225
  that the unwind collects. Not a String: a String held only by `keep`
1226
1226
  can be moved by compaction, taking the bytes under bundle_codes with
1227
1227
  it. */
1228
- VALUE v32 = rb_ca_wrap_readonly(vcodes, INT2NUM(CA_INT32));
1228
+ volatile VALUE v32 = rb_ca_wrap_readonly(vcodes, INT2NUM(CA_INT32));
1229
1229
  rb_ary_push((VALUE) keep, v32);
1230
1230
  GetCArray(v32, bundle_ca[bi]);
1231
1231
  h_codes[bi] = 0;
@@ -79,6 +79,14 @@ ca_binop_op_id_of_table (ca_binop_func_t table[])
79
79
  return -1;
80
80
  }
81
81
 
82
+ /* pmax, pmin, maximum and minimum pick one operand by order. */
83
+ int
84
+ ca_binop_picks_by_order (int op_id)
85
+ {
86
+ return op_id == CA_BINOP_PMAX || op_id == CA_BINOP_PMIN ||
87
+ op_id == CA_BINOP_MAXIMUM || op_id == CA_BINOP_MINIMUM;
88
+ }
89
+
82
90
  /* ------------------------------------------------------------------- */
83
91
  /* output data_type rule */
84
92
  /* ------------------------------------------------------------------- */
@@ -148,5 +148,6 @@ void ca_binop_kernel_input_data_types (uint16_t op_id, int8_t l_dt, int8_t r_dt,
148
148
  a slab mask to the kernel so masked cells are skipped (otherwise
149
149
  masked-zero divisors crash with SIGFPE). See §3.4 rev3. */
150
150
  int ca_binop_op_id_of_table (ca_binop_func_t table[]);
151
+ int ca_binop_picks_by_order (int op_id);
151
152
 
152
153
  #endif /* CA_BINOP_DISPATCH_H */
@@ -46,7 +46,7 @@
46
46
  } while (0)
47
47
 
48
48
  static VALUE
49
- rb_ca_addresses_by_category (VALUE self, VALUE rcursor, VALUE rk, VALUE rnvalid)
49
+ rb_ca_addresses_by_category (VALUE self, volatile VALUE rcursor, VALUE rk, VALUE rnvalid)
50
50
  {
51
51
  CArray *codes, *cursor, *result;
52
52
  VALUE rresult;
@@ -264,7 +264,7 @@ rb_ca_addresses_by_category (VALUE self, VALUE rcursor, VALUE rk, VALUE rnvalid)
264
264
 
265
265
  static VALUE
266
266
  rb_ca_reduceat_moments (VALUE self, VALUE roffsets, VALUE rcounts,
267
- VALUE rsums, VALUE rmins, VALUE rmaxs)
267
+ VALUE rsums, volatile VALUE rmins, volatile VALUE rmaxs)
268
268
  {
269
269
  CArray *grouped, *offsets, *counts, *sums, *mins, *maxs;
270
270
  int64_t k, *offs, *countp;
@@ -397,7 +397,7 @@ ca_nth_element_double (double *a, ca_size_t n, ca_size_t kth)
397
397
  } while (0)
398
398
 
399
399
  static VALUE
400
- rb_ca_reduceat_percentile (VALUE self, VALUE roffsets, VALUE rp, VALUE rout)
400
+ rb_ca_reduceat_percentile (VALUE self, volatile VALUE roffsets, VALUE rp, volatile VALUE rout)
401
401
  {
402
402
  CArray *grouped, *offsets, *out;
403
403
  int64_t k, *offs;
@@ -503,7 +503,7 @@ rb_ca_reduceat_percentile (VALUE self, VALUE roffsets, VALUE rp, VALUE rout)
503
503
 
504
504
  static VALUE
505
505
  rb_ca_reduceat_variance (VALUE self, VALUE roffsets, VALUE rmeans,
506
- VALUE rcounts, VALUE rout, VALUE rddof)
506
+ VALUE rcounts, volatile VALUE rout, VALUE rddof)
507
507
  {
508
508
  int64_t ddof = NUM2LL(rddof);
509
509
  CArray *grouped, *offsets, *means, *counts, *out;
@@ -649,7 +649,7 @@ rb_ca_reduceat_prod (VALUE self, VALUE roffsets, VALUE rout)
649
649
  } while (0)
650
650
 
651
651
  static VALUE
652
- rb_ca_reduceat_argminmax (VALUE self, VALUE roffsets, VALUE rminidx, VALUE rmaxidx)
652
+ rb_ca_reduceat_argminmax (VALUE self, VALUE roffsets, volatile VALUE rminidx, volatile VALUE rmaxidx)
653
653
  {
654
654
  CArray *grouped, *offsets, *minidx, *maxidx;
655
655
  int64_t k, *offs, *minp, *maxp;
@@ -850,9 +850,8 @@ rb_ca_reduceat_quantile (VALUE self, VALUE roffsets, VALUE rp0, VALUE rp25,
850
850
  group order (float64, weight mask propagated). A cell contributes iff its
851
851
  value AND its weight are present. wsum_out = Sum(v*w) (0.0 for a segment with
852
852
  no present pair, the additive identity). wmean_out = Sum(v*w)/Sum(w), masked
853
- when the segment has no present pair (matching CArray#wmean UNDEF); a present
854
- segment whose weights sum to zero yields NaN/Inf from the division (core's
855
- 0/0 contract). */
853
+ when the segment has no present pair or its weights sum to zero, as
854
+ CArray#wmean leaves both undefined. */
856
855
  #define REDUCEAT_WSUM_BODY(T) \
857
856
  do { \
858
857
  const T *gp = (const T *) grouped->ptr; \
@@ -866,14 +865,14 @@ rb_ca_reduceat_quantile (VALUE self, VALUE roffsets, VALUE rp0, VALUE rp25,
866
865
  { double wv = wp[j]; svw += (double) gp[j] * wv; sw += wv; cnt++; } \
867
866
  } \
868
867
  wsp[c] = svw; \
869
- if ( cnt == 0 ) { wmp[c] = 0.0; wmm[c] = 1; } /* no present pair */ \
868
+ if ( cnt == 0 || sw == 0.0 ) { wmp[c] = 0.0; wmm[c] = 1; } /* undefined */ \
870
869
  else wmp[c] = svw / sw; \
871
870
  } \
872
871
  } while (0)
873
872
 
874
873
  static VALUE
875
- rb_ca_reduceat_wsum_wmean (VALUE self, VALUE roffsets, VALUE rwg,
876
- VALUE rwsum, VALUE rwmean)
874
+ rb_ca_reduceat_wsum_wmean (VALUE self, VALUE roffsets, volatile VALUE rwg,
875
+ VALUE rwsum, volatile VALUE rwmean)
877
876
  {
878
877
  CArray *grouped, *offsets, *wg, *wsum, *wmean;
879
878
  int64_t k, *offs;
@@ -1452,15 +1451,16 @@ rb_ca_fiber_scatter_wsum_wmean (VALUE self, VALUE rcodes, VALUE rweights,
1452
1451
  h->data_type);
1453
1452
  }
1454
1453
 
1455
- /* Compute wmean = wsum / sum-of-weights; mask cells with no present pair. */
1454
+ /* Compute wmean = wsum / sum-of-weights; mask cells with no present pair
1455
+ and cells whose weights sum to zero, as CArray#wmean does. */
1456
1456
  ca_create_mask(wmean);
1457
1457
  wmm = (boolean8_t *) wmean->mask->ptr;
1458
1458
  for ( cell = 0; cell < total; cell++ ) {
1459
- if ( cntp[cell] == 0 ) {
1459
+ if ( cntp[cell] == 0 || wsw[cell] == 0.0 ) {
1460
1460
  wmp[cell] = 0.0;
1461
1461
  wmm[cell] = 1;
1462
1462
  } else {
1463
- wmp[cell] = wsp[cell] / wsw[cell]; /* 0/0 -> NaN naturally (core contract) */
1463
+ wmp[cell] = wsp[cell] / wsw[cell];
1464
1464
  }
1465
1465
  }
1466
1466