carray 3.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1830
- data/README.md +62 -35
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +12 -15
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +35 -0
- data/ext/ca_binop_dispatch.h +22 -46
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1504
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +92 -165
- data/ext/ca_obj_bincmp.c +65 -48
- data/ext/ca_obj_binop.c +74 -49
- data/ext/ca_obj_bitarray.c +7 -21
- data/ext/ca_obj_bitfield.c +93 -26
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +34 -34
- data/ext/ca_obj_const_string.c +464 -304
- data/ext/ca_obj_face.c +167 -121
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +127 -34
- data/ext/ca_obj_farray.c +13 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +57 -34
- data/ext/ca_obj_grid.c +149 -113
- data/ext/ca_obj_meld.c +28 -26
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +88 -73
- data/ext/ca_obj_object.c +60 -46
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +10 -14
- data/ext/ca_obj_refer.c +146 -39
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +20 -28
- data/ext/ca_obj_select.c +17 -27
- data/ext/ca_obj_select_axis.c +35 -42
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +33 -29
- data/ext/ca_obj_stride.c +99 -62
- data/ext/ca_obj_string.c +8 -20
- data/ext/ca_obj_tile.c +14 -16
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +48 -49
- data/ext/ca_obj_window.c +87 -99
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +97 -27
- data/ext/ca_op_powi.h +9 -28
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +23 -26
- data/ext/ca_sweep_engine.c +92 -26
- data/ext/ca_sweep_engine.h +22 -15
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +12 -12
- data/ext/carray.h +300 -1009
- data/ext/carray_access.c +320 -207
- data/ext/carray_address_basis.c +128 -59
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +31 -27
- data/ext/carray_call_cfunc.c +174 -285
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +1191 -351
- data/ext/carray_cast_func.rb +68 -8
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +98 -39
- data/ext/carray_copy.c +52 -26
- data/ext/carray_core.c +286 -132
- data/ext/carray_count.c +53 -22
- data/ext/carray_element.c +49 -28
- data/ext/carray_factorize.c +64 -63
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +9 -11
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +127 -230
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1364 -156
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +37 -37
- data/ext/carray_loop.c +27 -23
- data/ext/carray_mask.c +235 -150
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +106 -100
- data/ext/carray_memory_view.c +83 -69
- data/ext/carray_operator.c +490 -128
- data/ext/carray_order.c +163 -84
- data/ext/carray_partition.c +14 -16
- data/ext/carray_random.c +48 -42
- data/ext/carray_round.c +33 -5
- data/ext/carray_scatter.c +57 -39
- data/ext/carray_segment.c +42 -46
- data/ext/carray_slab.c +77 -51
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +37 -31
- data/ext/carray_sort_kernel.c +36 -10
- data/ext/carray_struct.c +44 -34
- data/ext/carray_test.c +131 -81
- data/ext/carray_time_text.c +30 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +373 -139
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +25 -31
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +819 -488
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +272 -185
- data/lib/carray/basics.rb +298 -56
- data/lib/carray/bincount_nd.rb +41 -18
- data/lib/carray/block_iterator.rb +167 -119
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +84 -59
- data/lib/carray/categorical_iterator.rb +90 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +98 -23
- data/lib/carray/const_string.rb +112 -46
- data/lib/carray/core_extensions.rb +20 -69
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +95 -12
- data/lib/carray/frame/column_verbs.rb +76 -9
- data/lib/carray/frame/concat.rb +51 -7
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +20 -5
- data/lib/carray/frame/frame.rb +73 -31
- data/lib/carray/frame/group.rb +247 -187
- data/lib/carray/frame/io.rb +36 -12
- data/lib/carray/frame/join.rb +56 -17
- data/lib/carray/frame/records.rb +7 -5
- data/lib/carray/frame/reshape.rb +27 -7
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +217 -134
- data/lib/carray/frame/windows.rb +254 -19
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +28 -23
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +104 -23
- data/lib/carray/key_windows.rb +93 -61
- data/lib/carray/lazy.rb +208 -111
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +8 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +73 -72
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +106 -103
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +183 -143
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +157 -94
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +23 -13
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +50 -20
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +195 -17
- data/lib/carray/segment_iterator.rb +262 -137
- data/lib/carray/serialize.rb +635 -566
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +14 -15
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +97 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +247 -73
- data/lib/carray/time.rb +663 -365
- data/lib/carray/window_iterator.rb +232 -155
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +6 -2
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +10 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +28 -16
- data/yard-stubs/carray_access.rb +55 -6
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +121 -162
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +10 -5
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +162 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +72 -33
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +12 -3
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_test.rb +18 -5
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +63 -25
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25387
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -261
- data/lib/carray/data_type_limits.rb +0 -91
data/ext/carray_partition.c
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
#include "ruby.h"
|
|
16
16
|
#include "carray.h"
|
|
17
|
-
#include "carray_internal.h" /* ca_normalize_axis_arg */
|
|
18
17
|
#include "ca_kernel_iterator.h" /* CA_FOR_EACH_FIBER_INOUT */
|
|
19
18
|
#include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE */
|
|
20
19
|
#include "ca_sort_kernels.h" /* ca_partition_quick_* / ca_partition_nan_* */
|
|
@@ -141,9 +140,9 @@ VALUE
|
|
|
141
140
|
rb_ca_partition_copy_c (VALUE self, VALUE vkth, VALUE vaxis)
|
|
142
141
|
{
|
|
143
142
|
/* Mask handling (= same as partition view). */
|
|
144
|
-
VALUE target = self;
|
|
143
|
+
volatile VALUE target = self; /* cat points into it; the walk can run a GC */
|
|
145
144
|
CArray *cat;
|
|
146
|
-
|
|
145
|
+
GetCArray(target, cat);
|
|
147
146
|
if ( ca_has_mask(cat) ) {
|
|
148
147
|
if ( RTEST(rb_ca_is_any_masked(target)) ) {
|
|
149
148
|
rb_raise(rb_eArgError,
|
|
@@ -151,11 +150,11 @@ rb_ca_partition_copy_c (VALUE self, VALUE vkth, VALUE vaxis)
|
|
|
151
150
|
"(use ca.value or ca.strip_mask(fill))");
|
|
152
151
|
}
|
|
153
152
|
target = rb_ca_value_array(target);
|
|
154
|
-
|
|
153
|
+
GetCArray(target, cat);
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
/* Normalize axis. */
|
|
158
|
-
int axis =
|
|
157
|
+
int axis = rb_ca_normalize_axis_arg(vaxis, cat->ndim, NULL);
|
|
159
158
|
|
|
160
159
|
ca_size_t fiber_n = cat->dim[axis];
|
|
161
160
|
ca_size_t kth = partition_kth(fiber_n, vkth);
|
|
@@ -189,7 +188,7 @@ rb_ca_partition_copy_c (VALUE self, VALUE vkth, VALUE vaxis)
|
|
|
189
188
|
INT2NUM(cat->data_type),
|
|
190
189
|
INT2NUM((int) fbytes));
|
|
191
190
|
CArray *cao;
|
|
192
|
-
|
|
191
|
+
GetCArray(vout, cao);
|
|
193
192
|
/* Two cells of scratch. ALLOCV, not the stack: a cell can be wide. */
|
|
194
193
|
volatile VALUE scratch_holder = 0;
|
|
195
194
|
char *swap_tmp = ALLOCV_N(char, scratch_holder, 2 * (size_t) fbytes);
|
|
@@ -220,7 +219,7 @@ rb_ca_partition_copy_c (VALUE self, VALUE vkth, VALUE vaxis)
|
|
|
220
219
|
INT2NUM(cat->data_type),
|
|
221
220
|
INT2NUM(0));
|
|
222
221
|
CArray *cao;
|
|
223
|
-
|
|
222
|
+
GetCArray(vout, cao);
|
|
224
223
|
|
|
225
224
|
/* Numeric path: per-type quickselect with inline cmp via the typed
|
|
226
225
|
ca_partition_quick_* kernels (avoids the function-pointer
|
|
@@ -277,22 +276,21 @@ rb_ca_partition_copy_c (VALUE self, VALUE vkth, VALUE vaxis)
|
|
|
277
276
|
* CA_FIXLEN / CA_OBJECT delegation pattern already used by sort_copy.
|
|
278
277
|
* rb_ca_partition_copy_c itself keeps raising on masked input (its
|
|
279
278
|
* other callers -- carray_median_percentile.c's flat lane -- always
|
|
280
|
-
* pre-strip the mask before calling it
|
|
281
|
-
* devel/MEMO_PER_AXIS_ORDER_STAT_MASK.md; per-axis order statistics
|
|
279
|
+
* pre-strip the mask before calling it; per-axis order statistics
|
|
282
280
|
* with mask are a separate, still-open gap).
|
|
283
281
|
*/
|
|
284
282
|
static VALUE
|
|
285
|
-
rb_ca_partition_copy_c_mp (VALUE self, VALUE vkth, VALUE vaxis, int masked_last)
|
|
283
|
+
rb_ca_partition_copy_c_mp (volatile VALUE self, VALUE vkth, VALUE vaxis, int masked_last)
|
|
286
284
|
{
|
|
287
285
|
CArray *ca;
|
|
288
|
-
|
|
286
|
+
GetCArray(self, ca);
|
|
289
287
|
if ( ! ca_has_mask(ca) ) {
|
|
290
288
|
return rb_ca_partition_copy_c(self, vkth, vaxis);
|
|
291
289
|
}
|
|
292
290
|
/* Check axis and kth here, so a bad one is reported as partition_copy's
|
|
293
291
|
rather than as the partition this delegates to. */
|
|
294
292
|
{
|
|
295
|
-
int axis =
|
|
293
|
+
int axis = rb_ca_normalize_axis_arg(vaxis, ca->ndim, NULL);
|
|
296
294
|
partition_kth(ca->dim[axis], vkth);
|
|
297
295
|
}
|
|
298
296
|
/* rb_ca_partitioned_view's rb_scan_args "1:" pattern needs call-frame
|
|
@@ -316,7 +314,7 @@ rb_ca_partition_copy_c_mp (VALUE self, VALUE vkth, VALUE vaxis, int masked_last)
|
|
|
316
314
|
/* Ruby entry: partition_copy(kth, axis: nil, masked_position: :last).
|
|
317
315
|
No axis means the whole array, as for sort_copy: flatten first. */
|
|
318
316
|
static VALUE
|
|
319
|
-
rb_ca_partition_copy_body (int argc, VALUE *argv, VALUE self)
|
|
317
|
+
rb_ca_partition_copy_body (int argc, VALUE *argv, volatile VALUE self)
|
|
320
318
|
{
|
|
321
319
|
VALUE vkth, rkw = Qnil;
|
|
322
320
|
VALUE vaxis = Qnil;
|
|
@@ -339,7 +337,7 @@ rb_ca_partition_copy_body (int argc, VALUE *argv, VALUE self)
|
|
|
339
337
|
volatile VALUE face = Qnil;
|
|
340
338
|
{
|
|
341
339
|
CArray *ca;
|
|
342
|
-
|
|
340
|
+
GetCArray(self, ca);
|
|
343
341
|
if ( ca_is_face(ca) ) {
|
|
344
342
|
if ( ca_face_orders_by_itself(self) ) {
|
|
345
343
|
VALUE kw = rb_hash_new();
|
|
@@ -385,7 +383,7 @@ rb_ca_partition_copy_body (int argc, VALUE *argv, VALUE self)
|
|
|
385
383
|
* from end).
|
|
386
384
|
*/
|
|
387
385
|
static VALUE
|
|
388
|
-
rb_ca_partitioned_view (int argc, VALUE *argv, VALUE self)
|
|
386
|
+
rb_ca_partitioned_view (int argc, VALUE *argv, volatile VALUE self)
|
|
389
387
|
{
|
|
390
388
|
VALUE vkth, rkw = Qnil;
|
|
391
389
|
VALUE vaxis = Qnil;
|
|
@@ -398,7 +396,7 @@ rb_ca_partitioned_view (int argc, VALUE *argv, VALUE self)
|
|
|
398
396
|
: ca_symbol_choice(vmasked_position, "masked_position", "first", "last", NULL);
|
|
399
397
|
|
|
400
398
|
CArray *ca;
|
|
401
|
-
|
|
399
|
+
GetCArray(self, ca);
|
|
402
400
|
|
|
403
401
|
/* CA_FIXLEN flows through the same partition_addr_ki fixlen dialect
|
|
404
402
|
as numeric; masked_position: applies uniformly across data types.
|
data/ext/carray_random.c
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
---------------------------------------------------------------------------- */
|
|
19
19
|
|
|
20
20
|
#include "carray.h"
|
|
21
|
-
#include "carray_internal.h" /* ca_attach_window */
|
|
22
21
|
#include <math.h>
|
|
23
22
|
#include <string.h>
|
|
24
23
|
#include <stdint.h>
|
|
@@ -49,7 +48,7 @@ typedef struct {
|
|
|
49
48
|
int kind;
|
|
50
49
|
VALUE rng;
|
|
51
50
|
CArray *state; /* the CArray::Rng state for CA_RNG_OWN, else NULL */
|
|
52
|
-
int64_t *cells; /* state->ptr, once the
|
|
51
|
+
int64_t *cells; /* state->ptr, once the state is attached */
|
|
53
52
|
} ca_rng_t;
|
|
54
53
|
|
|
55
54
|
static void
|
|
@@ -62,9 +61,9 @@ ca_rng_resolve (VALUE rng, ca_rng_t *source)
|
|
|
62
61
|
source->kind = CA_RNG_DEFAULT;
|
|
63
62
|
}
|
|
64
63
|
else if (rb_obj_is_kind_of(rng, rb_cCARng)) {
|
|
65
|
-
VALUE state = rb_ivar_get(rng, rb_intern("@state"));
|
|
64
|
+
volatile VALUE state = rb_ivar_get(rng, rb_intern("@state"));
|
|
66
65
|
CArray *ca;
|
|
67
|
-
|
|
66
|
+
GetCArray(state, ca);
|
|
68
67
|
source->kind = CA_RNG_OWN;
|
|
69
68
|
source->state = ca;
|
|
70
69
|
}
|
|
@@ -73,11 +72,11 @@ ca_rng_resolve (VALUE rng, ca_rng_t *source)
|
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
/* The fills below draw
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
they advanced, as it does when the fill completes. */
|
|
75
|
+
/* The fills below draw while the array and, for a CArray::Rng, the
|
|
76
|
+
generator's state are attached. A Ruby generator (rng: a ::Random or
|
|
77
|
+
anything with #rand) is called per draw and can raise part way; the
|
|
78
|
+
sync before the detach then pushes back the cells drawn so far, and the
|
|
79
|
+
state they advanced, as it does when the fill completes. */
|
|
81
80
|
|
|
82
81
|
typedef struct {
|
|
83
82
|
CArray *ca;
|
|
@@ -102,7 +101,7 @@ ca_random_run (ca_random_ctx_t *c, VALUE rng, VALUE (*fill)(VALUE))
|
|
|
102
101
|
ca_attach_window(c->mask ? 3 : 2, list, "www", fill, (VALUE) c);
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
/*
|
|
104
|
+
/* Called once ca_attach_window has attached the state. */
|
|
106
105
|
static void
|
|
107
106
|
ca_rng_bind (ca_rng_t *source)
|
|
108
107
|
{
|
|
@@ -188,29 +187,34 @@ ca_random_bang_fill (VALUE arg)
|
|
|
188
187
|
}
|
|
189
188
|
break;
|
|
190
189
|
}
|
|
190
|
+
/* The real part is drawn first. Each draw goes into a local first: C
|
|
191
|
+
does not say which operand of `+` is evaluated first, and both
|
|
192
|
+
advance the state. */
|
|
191
193
|
case CA_CMPLX128: {
|
|
192
194
|
ca_u_cmplx128_t *p = (ca_u_cmplx128_t *)ca->ptr;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
double
|
|
198
|
-
|
|
199
|
-
p[i] =
|
|
200
|
-
|
|
195
|
+
double low = is_default ? 0.0 : low_dbl;
|
|
196
|
+
double range = is_default ? 1.0 : high_dbl - low_dbl;
|
|
197
|
+
for (i = 0; i < n; i++) {
|
|
198
|
+
double re = ca_random_real(&c->source);
|
|
199
|
+
double im = ca_random_real(&c->source);
|
|
200
|
+
if (is_default)
|
|
201
|
+
p[i] = re + im * I;
|
|
202
|
+
else
|
|
203
|
+
p[i] = (low + re * range) + (low + im * range) * I;
|
|
201
204
|
}
|
|
202
205
|
break;
|
|
203
206
|
}
|
|
204
207
|
case CA_CMPLX64: {
|
|
205
208
|
ca_u_cmplx64_t *p = (ca_u_cmplx64_t *)ca->ptr;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
double
|
|
211
|
-
|
|
212
|
-
p[i] = (float)
|
|
213
|
-
|
|
209
|
+
double low = is_default ? 0.0 : low_dbl;
|
|
210
|
+
double range = is_default ? 1.0 : high_dbl - low_dbl;
|
|
211
|
+
for (i = 0; i < n; i++) {
|
|
212
|
+
double re = ca_random_real(&c->source);
|
|
213
|
+
double im = ca_random_real(&c->source);
|
|
214
|
+
if (is_default)
|
|
215
|
+
p[i] = (float)re + (float)im * I;
|
|
216
|
+
else
|
|
217
|
+
p[i] = (float)(low + re * range) + (float)(low + im * range) * I;
|
|
214
218
|
}
|
|
215
219
|
break;
|
|
216
220
|
}
|
|
@@ -306,7 +310,7 @@ ca_random_bang_fill (VALUE arg)
|
|
|
306
310
|
* Boolean fills 0/1 with 50% probability each and ignores the range
|
|
307
311
|
* argument. Rejects CA_OBJECT / CA_FIXLEN. */
|
|
308
312
|
static VALUE
|
|
309
|
-
rb_ca_random_bang(int argc, VALUE *argv, VALUE self)
|
|
313
|
+
rb_ca_random_bang(int argc, VALUE *argv, volatile VALUE self)
|
|
310
314
|
{
|
|
311
315
|
CArray *ca;
|
|
312
316
|
VALUE arg1 = Qnil, arg2 = Qnil, opts = Qnil;
|
|
@@ -318,6 +322,7 @@ rb_ca_random_bang(int argc, VALUE *argv, VALUE self)
|
|
|
318
322
|
unsigned long limit = 0;
|
|
319
323
|
VALUE rng = Qnil;
|
|
320
324
|
|
|
325
|
+
rb_ca_modify(self);
|
|
321
326
|
rb_scan_args(argc, argv, "02:", &arg1, &arg2, &opts);
|
|
322
327
|
rb_scan_options(opts, "rng", &rng);
|
|
323
328
|
|
|
@@ -345,8 +350,7 @@ rb_ca_random_bang(int argc, VALUE *argv, VALUE self)
|
|
|
345
350
|
is_default = 0;
|
|
346
351
|
}
|
|
347
352
|
|
|
348
|
-
|
|
349
|
-
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
353
|
+
GetCArray(self, ca);
|
|
350
354
|
|
|
351
355
|
if (ca->data_type == CA_OBJECT || ca->data_type == CA_FIXLEN) {
|
|
352
356
|
rb_raise(rb_eCADataTypeError,
|
|
@@ -584,17 +588,16 @@ ca_randomn_bang_fill (VALUE arg)
|
|
|
584
588
|
* Restricted to float / complex data types. Complex fills real + imag as
|
|
585
589
|
* two independent normals per cell. */
|
|
586
590
|
static VALUE
|
|
587
|
-
rb_ca_randomn_bang(int argc, VALUE *argv, VALUE self)
|
|
591
|
+
rb_ca_randomn_bang(int argc, VALUE *argv, volatile VALUE self)
|
|
588
592
|
{
|
|
589
593
|
CArray *ca;
|
|
590
|
-
VALUE opts = Qnil;
|
|
594
|
+
VALUE opts = Qnil, rng = Qnil;
|
|
591
595
|
|
|
596
|
+
rb_ca_modify(self);
|
|
592
597
|
rb_scan_args(argc, argv, "0:", &opts);
|
|
593
|
-
VALUE rng = Qnil;
|
|
594
598
|
rb_scan_options(opts, "rng", &rng);
|
|
595
599
|
|
|
596
|
-
|
|
597
|
-
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
600
|
+
GetCArray(self, ca);
|
|
598
601
|
|
|
599
602
|
if (ca->data_type != CA_FLOAT64 && ca->data_type != CA_FLOAT32 &&
|
|
600
603
|
ca->data_type != CA_CMPLX128 && ca->data_type != CA_CMPLX64) {
|
|
@@ -698,24 +701,24 @@ ca_shuffle_bang_fill (VALUE arg)
|
|
|
698
701
|
}
|
|
699
702
|
|
|
700
703
|
static VALUE
|
|
701
|
-
rb_ca_shuffle_bang(int argc, VALUE *argv, VALUE self)
|
|
704
|
+
rb_ca_shuffle_bang(int argc, VALUE *argv, volatile VALUE self)
|
|
702
705
|
{
|
|
703
706
|
CArray *ca;
|
|
704
707
|
VALUE opts = Qnil, v_axis = Qnil;
|
|
705
708
|
int axis = -1;
|
|
706
709
|
ca_random_ctx_t c = { 0 };
|
|
710
|
+
VALUE rng = Qnil;
|
|
707
711
|
|
|
712
|
+
rb_ca_modify(self);
|
|
708
713
|
rb_scan_args(argc, argv, "0:", &opts);
|
|
709
|
-
VALUE rng = Qnil;
|
|
710
714
|
rb_scan_options(opts, "rng,axis", &rng, &v_axis);
|
|
711
715
|
|
|
712
|
-
|
|
713
|
-
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
716
|
+
GetCArray(self, ca);
|
|
714
717
|
|
|
715
718
|
if (ca->elements <= 1) return self;
|
|
716
719
|
|
|
717
720
|
if (!NIL_P(v_axis)) {
|
|
718
|
-
axis =
|
|
721
|
+
axis = rb_ca_normalize_axis_arg(v_axis, ca->ndim, NULL);
|
|
719
722
|
if (ca->dim[axis] <= 1) {
|
|
720
723
|
return self;
|
|
721
724
|
}
|
|
@@ -737,6 +740,7 @@ rb_ca_shuffle_bang(int argc, VALUE *argv, VALUE self)
|
|
|
737
740
|
static VALUE
|
|
738
741
|
rb_ca_shuffle(int argc, VALUE *argv, VALUE self)
|
|
739
742
|
{
|
|
743
|
+
/* copy is called as a method, so a lazy array is evaluated as its copy is */
|
|
740
744
|
volatile VALUE copy = rb_funcall(self, rb_intern("copy"), 0);
|
|
741
745
|
return rb_ca_shuffle_bang(argc, argv, copy);
|
|
742
746
|
}
|
|
@@ -750,6 +754,7 @@ rb_ca_shuffle(int argc, VALUE *argv, VALUE self)
|
|
|
750
754
|
static VALUE
|
|
751
755
|
rb_ca_random(int argc, VALUE *argv, VALUE self)
|
|
752
756
|
{
|
|
757
|
+
/* template is called as a method, so a Face that overrides it is used */
|
|
753
758
|
volatile VALUE copy = rb_funcall(self, rb_intern("template"), 0);
|
|
754
759
|
return rb_ca_random_bang(argc, argv, copy);
|
|
755
760
|
}
|
|
@@ -759,6 +764,7 @@ rb_ca_random(int argc, VALUE *argv, VALUE self)
|
|
|
759
764
|
static VALUE
|
|
760
765
|
rb_ca_randomn(int argc, VALUE *argv, VALUE self)
|
|
761
766
|
{
|
|
767
|
+
/* template is called as a method, so a Face that overrides it is used */
|
|
762
768
|
volatile VALUE copy = rb_funcall(self, rb_intern("template"), 0);
|
|
763
769
|
return rb_ca_randomn_bang(argc, argv, copy);
|
|
764
770
|
}
|
|
@@ -791,9 +797,9 @@ static CArray *
|
|
|
791
797
|
ca_rng_cells (VALUE self, int64_t **cells)
|
|
792
798
|
{
|
|
793
799
|
CArray *ca;
|
|
794
|
-
VALUE state = rb_ivar_get(self, rb_intern("@state"));
|
|
795
|
-
|
|
796
|
-
ca_attach(ca); /*
|
|
800
|
+
volatile VALUE state = rb_ivar_get(self, rb_intern("@state"));
|
|
801
|
+
GetCArray(state, ca);
|
|
802
|
+
ca_attach(ca); /* attach: the state is an entity, whose attach holds nothing */
|
|
797
803
|
*cells = (int64_t *) ca->ptr;
|
|
798
804
|
return ca;
|
|
799
805
|
}
|
data/ext/carray_round.c
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
#include <float.h>
|
|
12
12
|
|
|
13
13
|
#include "carray.h"
|
|
14
|
-
#include "carray_internal.h"
|
|
15
14
|
#include "ca_obj_face.h"
|
|
16
15
|
|
|
17
16
|
VALUE rb_ca_round (VALUE self); /* generated: round without digits */
|
|
@@ -196,17 +195,38 @@ ca_round_entity (CArray *ca, long ndigits)
|
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
197
|
|
|
198
|
+
typedef struct {
|
|
199
|
+
CArray *ca;
|
|
200
|
+
long ndigits;
|
|
201
|
+
} ca_round_call_t;
|
|
202
|
+
|
|
203
|
+
/* The cells of an object array are asked in turn, and a cell that is an
|
|
204
|
+
array asks its own (ca_computing_run). */
|
|
205
|
+
static VALUE
|
|
206
|
+
ca_round_cells (VALUE arg)
|
|
207
|
+
{
|
|
208
|
+
ca_round_call_t *c = (ca_round_call_t *) arg;
|
|
209
|
+
ca_round_entity(c->ca, c->ndigits);
|
|
210
|
+
return Qnil;
|
|
211
|
+
}
|
|
212
|
+
|
|
199
213
|
/* The array to round: a boolean is rounded as its 0/1 int64 values, as
|
|
200
214
|
round without digits does. */
|
|
201
215
|
static VALUE
|
|
202
|
-
ca_round_source (VALUE self, VALUE vdigits, long *ndigits)
|
|
216
|
+
ca_round_source (volatile VALUE self, VALUE vdigits, long *ndigits)
|
|
203
217
|
{
|
|
204
218
|
CArray *ca;
|
|
205
219
|
*ndigits = ca_integer_arg(vdigits, "ndigits", "round");
|
|
206
220
|
ca_face_refuse_numeric(self, "round", rb_eCADataTypeError);
|
|
207
221
|
GetCArray(self, ca);
|
|
208
222
|
if ( ca->data_type == CA_BOOLEAN ) {
|
|
209
|
-
|
|
223
|
+
return rb_ca_wrap_readonly(self, INT2NUM(CA_INT64));
|
|
224
|
+
}
|
|
225
|
+
/* Refused before the copy: ca_round_entity rounds only these types. */
|
|
226
|
+
if ( ! ( ca_is_integer_type(ca) || ca_is_float_type(ca) ||
|
|
227
|
+
ca_is_object_type(ca) ) ) {
|
|
228
|
+
rb_raise(rb_eCADataTypeError, "round: not defined for data_type %s",
|
|
229
|
+
ca_type_name[ca->data_type]);
|
|
210
230
|
}
|
|
211
231
|
return self;
|
|
212
232
|
}
|
|
@@ -215,7 +235,7 @@ ca_round_source (VALUE self, VALUE vdigits, long *ndigits)
|
|
|
215
235
|
without digits does (except for objects, which are asked with the digits);
|
|
216
236
|
an integer has no digits below 10**0 to round. */
|
|
217
237
|
static VALUE
|
|
218
|
-
ca_round_copy (VALUE src, long ndigits)
|
|
238
|
+
ca_round_copy (volatile VALUE src, long ndigits)
|
|
219
239
|
{
|
|
220
240
|
volatile VALUE out;
|
|
221
241
|
CArray *ca, *co;
|
|
@@ -228,7 +248,15 @@ ca_round_copy (VALUE src, long ndigits)
|
|
|
228
248
|
if ( ndigits > 0 && ca_is_integer_type(co) ) {
|
|
229
249
|
return out;
|
|
230
250
|
}
|
|
231
|
-
|
|
251
|
+
if ( ca_is_object_type(co) ) {
|
|
252
|
+
ca_round_call_t c;
|
|
253
|
+
c.ca = co;
|
|
254
|
+
c.ndigits = ndigits;
|
|
255
|
+
ca_computing_run(1, &co, ca_round_cells, (VALUE) &c);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
ca_round_entity(co, ndigits);
|
|
259
|
+
}
|
|
232
260
|
return out;
|
|
233
261
|
}
|
|
234
262
|
|
data/ext/carray_scatter.c
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
--------------------------------------------------------------------------- */
|
|
23
23
|
|
|
24
24
|
#include "carray.h"
|
|
25
|
-
#include "carray_internal.h" /* ca_attach_window */
|
|
26
25
|
|
|
27
26
|
/* ---------- common kernel macros ----------
|
|
28
27
|
|
|
@@ -218,14 +217,13 @@ typedef union {
|
|
|
218
217
|
} \
|
|
219
218
|
} while (0)
|
|
220
219
|
|
|
221
|
-
/* A
|
|
222
|
-
|
|
223
|
-
array
|
|
220
|
+
/* A CArray or a Ruby Array is an array of values, one per address; any
|
|
221
|
+
other value is one cell for every address, stored as a cell is (so nil or
|
|
222
|
+
a String a numeric array can not read is refused there). */
|
|
224
223
|
static int
|
|
225
224
|
ca_scatter_is_scalar (VALUE v)
|
|
226
225
|
{
|
|
227
|
-
return
|
|
228
|
-
|| rb_obj_is_kind_of(v, rb_cNumeric);
|
|
226
|
+
return ! rb_obj_is_carray(v) && ! RB_TYPE_P(v, T_ARRAY);
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
/* Setup boilerplate: parse args and wrap addrs/vals.
|
|
@@ -244,15 +242,17 @@ ca_scatter_is_scalar (VALUE v)
|
|
|
244
242
|
the data_type gate has already run (arithmetic = numeric only, replace
|
|
245
243
|
= numeric or boolean). A scalar is converted the way `self[i] = v`
|
|
246
244
|
converts it, so true / false reach only a boolean self and a value that
|
|
247
|
-
does not fit raises
|
|
248
|
-
|
|
245
|
+
does not fit raises; the arithmetic, min and max families have taken
|
|
246
|
+
an Integer the type can not hold before this (AT_SETUP_OR_RETURN). A
|
|
247
|
+
scalar UNDEF is a masked value: the arithmetic family skips every pair,
|
|
248
|
+
replace masks every target. */
|
|
249
249
|
#define AT_SETUP_BODY(name) \
|
|
250
250
|
ca_check_index_array(raddrs); \
|
|
251
251
|
raddrs = rb_ca_wrap_readonly(raddrs, INT2NUM(CA_SIZE)); \
|
|
252
|
-
|
|
252
|
+
GetCArray(raddrs, ci); \
|
|
253
253
|
if ( ca_shares_root(ci, ca) ) { \
|
|
254
254
|
raddrs = rb_ca_copy(raddrs); \
|
|
255
|
-
|
|
255
|
+
GetCArray(raddrs, ci); \
|
|
256
256
|
} \
|
|
257
257
|
n = ci->elements; \
|
|
258
258
|
if ( n == 0 ) return self; \
|
|
@@ -266,12 +266,16 @@ ca_scatter_is_scalar (VALUE v)
|
|
|
266
266
|
} \
|
|
267
267
|
} \
|
|
268
268
|
else { \
|
|
269
|
+
if ( rb_obj_is_carray(rvals) ) { \
|
|
270
|
+
GetCArray(rvals, cv); \
|
|
271
|
+
ca_refuse_complex_into_real(ca, cv); \
|
|
272
|
+
} \
|
|
269
273
|
/* coerce: a store into the receiver */ \
|
|
270
274
|
rvals = rb_ca_wrap_readonly(rvals, INT2NUM(ca->data_type)); \
|
|
271
|
-
|
|
275
|
+
GetCArray(rvals, cv); \
|
|
272
276
|
if ( ca_shares_root(cv, ca) ) { \
|
|
273
277
|
rvals = rb_ca_copy(rvals); \
|
|
274
|
-
|
|
278
|
+
GetCArray(rvals, cv); \
|
|
275
279
|
} \
|
|
276
280
|
if ( cv->elements != n ) { \
|
|
277
281
|
rb_raise(rb_eArgError, \
|
|
@@ -286,17 +290,33 @@ ca_scatter_is_scalar (VALUE v)
|
|
|
286
290
|
int vals_scalar, vals_undef = 0; \
|
|
287
291
|
ca_scatter_cell_t vcell = {{0}};
|
|
288
292
|
|
|
289
|
-
|
|
293
|
+
/* how is the mode of ca_scalar_operand_for_op: + - * keep their answer
|
|
294
|
+
modulo 2 ** bits, as add! does, so an Integer the type can not hold is
|
|
295
|
+
cut to it; min and max take it as pmin and pmax do, at the type's bound
|
|
296
|
+
when it can never win and refused when it would win in every cell. */
|
|
297
|
+
#define AT_SETUP_OR_RETURN(name, how) \
|
|
290
298
|
AT_SETUP_LOCALS \
|
|
291
299
|
rb_ca_modify(self); \
|
|
292
|
-
|
|
300
|
+
GetCArray(self, ca); \
|
|
301
|
+
{ \
|
|
302
|
+
volatile VALUE scalar_vals_ = rvals; \
|
|
303
|
+
ca_scalar_operand_for_op(&scalar_vals_, self, (how)); \
|
|
304
|
+
rvals = scalar_vals_; \
|
|
305
|
+
} \
|
|
293
306
|
if ( ! ca_is_numeric_type(ca) ) { \
|
|
294
307
|
rb_raise(rb_eCADataTypeError, name " requires a numeric array"); \
|
|
295
308
|
} \
|
|
296
|
-
if ( (
|
|
309
|
+
if ( (how) != CA_SCALAR_FOR_RING && ca_is_complex_type(ca) ) { \
|
|
297
310
|
rb_raise(rb_eCADataTypeError, \
|
|
298
311
|
name " requires a real array (complex values have no order)"); \
|
|
299
312
|
} \
|
|
313
|
+
/* The values meet the receiver as add! meets its operand: one whose \
|
|
314
|
+
type the receiver's does not hold (a Float beside an integer array) \
|
|
315
|
+
is refused rather than cut. */ \
|
|
316
|
+
if ( RTEST(rb_obj_is_kind_of(rvals, rb_cNumeric)) || rb_obj_is_carray(rvals) ) { \
|
|
317
|
+
volatile VALUE self_ = self, vals_ = rvals; \
|
|
318
|
+
rb_ca_cast_other(&self_, &vals_); \
|
|
319
|
+
} \
|
|
300
320
|
AT_SETUP_BODY(name) \
|
|
301
321
|
if ( vals_undef ) return self;
|
|
302
322
|
|
|
@@ -305,7 +325,7 @@ ca_scatter_is_scalar (VALUE v)
|
|
|
305
325
|
#define AT_SETUP_OR_RETURN_REPLACE(name) \
|
|
306
326
|
AT_SETUP_LOCALS \
|
|
307
327
|
rb_ca_modify(self); \
|
|
308
|
-
|
|
328
|
+
GetCArray(self, ca); \
|
|
309
329
|
if ( ! ca_is_numeric_type(ca) && ca->data_type != CA_BOOLEAN ) { \
|
|
310
330
|
rb_raise(rb_eCADataTypeError, \
|
|
311
331
|
name " requires a numeric or boolean array"); \
|
|
@@ -374,11 +394,12 @@ typedef struct {
|
|
|
374
394
|
VALUE (*kernel)(VALUE);
|
|
375
395
|
} ca_scatter_region_arg_t;
|
|
376
396
|
|
|
377
|
-
/*
|
|
378
|
-
converting view, ...). Attaching such a self would
|
|
379
|
-
cell and push every cell back, so cells the addresses
|
|
380
|
-
make a round trip through the view -- and come back
|
|
381
|
-
view converts lossily. Only the cells named are read
|
|
397
|
+
/* ca_attach_window body for a self that does not lend its memory (a
|
|
398
|
+
selection, a converting view, ...). Attaching such a self would
|
|
399
|
+
materialise every cell and push every cell back, so cells the addresses
|
|
400
|
+
never name would make a round trip through the view -- and come back
|
|
401
|
+
changed when the view converts lossily. Only the cells named are read
|
|
402
|
+
and written.
|
|
382
403
|
|
|
383
404
|
The pairs before the first address out of range are applied, then the
|
|
384
405
|
range error is raised, as in the direct form. */
|
|
@@ -498,9 +519,6 @@ ca_scatter_region_body (VALUE varg)
|
|
|
498
519
|
ca_attach_window(vals_scalar ? 1 : 2, list_, "rr", \
|
|
499
520
|
ca_scatter_region_body, (VALUE) &ra_); \
|
|
500
521
|
} \
|
|
501
|
-
/* the views AT_SETUP_BODY made are reached only through ci and cv */ \
|
|
502
|
-
RB_GC_GUARD(raddrs); \
|
|
503
|
-
RB_GC_GUARD(rvals); \
|
|
504
522
|
} while (0)
|
|
505
523
|
|
|
506
524
|
/* --------------------------------------------------------------- */
|
|
@@ -511,9 +529,9 @@ AT_BODY(ca_scatter_add_body, DISPATCH_ARITH(OP_ADD))
|
|
|
511
529
|
* vals[i] (or += vals when scalar). Duplicate addrs accumulate
|
|
512
530
|
* (unbuffered), unlike self[addrs] += vals which is last-wins. */
|
|
513
531
|
static VALUE
|
|
514
|
-
rb_ca_scatter_add_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
532
|
+
rb_ca_scatter_add_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
515
533
|
{
|
|
516
|
-
AT_SETUP_OR_RETURN("scatter_add!",
|
|
534
|
+
AT_SETUP_OR_RETURN("scatter_add!", CA_SCALAR_FOR_RING);
|
|
517
535
|
AT_RUN(ca_scatter_add_body);
|
|
518
536
|
return self;
|
|
519
537
|
}
|
|
@@ -525,9 +543,9 @@ AT_BODY(ca_scatter_sub_body, DISPATCH_ARITH(OP_SUB))
|
|
|
525
543
|
/* CArray#scatter_sub!(addrs, vals) — for each i, self[addrs[i]] -=
|
|
526
544
|
* vals[i]. Same mask/cast/bounds policy as scatter_add!. */
|
|
527
545
|
static VALUE
|
|
528
|
-
rb_ca_scatter_sub_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
546
|
+
rb_ca_scatter_sub_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
529
547
|
{
|
|
530
|
-
AT_SETUP_OR_RETURN("scatter_sub!",
|
|
548
|
+
AT_SETUP_OR_RETURN("scatter_sub!", CA_SCALAR_FOR_RING);
|
|
531
549
|
AT_RUN(ca_scatter_sub_body);
|
|
532
550
|
return self;
|
|
533
551
|
}
|
|
@@ -541,9 +559,9 @@ AT_BODY(ca_scatter_mul_body, DISPATCH_ARITH(OP_MUL))
|
|
|
541
559
|
* missing-value rule); integer overflow wraps. Otherwise identical
|
|
542
560
|
* to scatter_add! (mask / cast / bounds). */
|
|
543
561
|
static VALUE
|
|
544
|
-
rb_ca_scatter_mul_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
562
|
+
rb_ca_scatter_mul_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
545
563
|
{
|
|
546
|
-
AT_SETUP_OR_RETURN("scatter_mul!",
|
|
564
|
+
AT_SETUP_OR_RETURN("scatter_mul!", CA_SCALAR_FOR_RING);
|
|
547
565
|
AT_RUN(ca_scatter_mul_body);
|
|
548
566
|
return self;
|
|
549
567
|
}
|
|
@@ -557,9 +575,9 @@ AT_BODY(ca_scatter_min_body, DISPATCH_ORDERED(OP_MIN_INT, OP_MIN_FLT))
|
|
|
557
575
|
* (NaN is treated as missing). Same mask/cast/bounds policy as
|
|
558
576
|
* scatter_add!. */
|
|
559
577
|
static VALUE
|
|
560
|
-
rb_ca_scatter_min_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
578
|
+
rb_ca_scatter_min_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
561
579
|
{
|
|
562
|
-
AT_SETUP_OR_RETURN("scatter_min!",
|
|
580
|
+
AT_SETUP_OR_RETURN("scatter_min!", CA_SCALAR_FOR_MIN);
|
|
563
581
|
AT_RUN(ca_scatter_min_body);
|
|
564
582
|
return self;
|
|
565
583
|
}
|
|
@@ -572,9 +590,9 @@ AT_BODY(ca_scatter_max_body, DISPATCH_ORDERED(OP_MAX_INT, OP_MAX_FLT))
|
|
|
572
590
|
* max(self[addrs[i]], vals[i]). Float types follow the fmax rule.
|
|
573
591
|
* Otherwise identical to scatter_add!. */
|
|
574
592
|
static VALUE
|
|
575
|
-
rb_ca_scatter_max_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
593
|
+
rb_ca_scatter_max_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
576
594
|
{
|
|
577
|
-
AT_SETUP_OR_RETURN("scatter_max!",
|
|
595
|
+
AT_SETUP_OR_RETURN("scatter_max!", CA_SCALAR_FOR_MAX);
|
|
578
596
|
AT_RUN(ca_scatter_max_body);
|
|
579
597
|
return self;
|
|
580
598
|
}
|
|
@@ -591,7 +609,7 @@ AT_BODY(ca_scatter_replace_body, DISPATCH_NUMERIC_REPLACE())
|
|
|
591
609
|
* mask is overwritten (masked vals[i] flips target to masked, valid
|
|
592
610
|
* vals[i] clears target's mask). */
|
|
593
611
|
static VALUE
|
|
594
|
-
rb_ca_scatter_replace_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
612
|
+
rb_ca_scatter_replace_bang (volatile VALUE self, volatile VALUE raddrs, volatile VALUE rvals)
|
|
595
613
|
{
|
|
596
614
|
/* An object or fixlen array takes the assignment through the indexer,
|
|
597
615
|
which reads and writes its cells by their own rules (a VALUE kept
|
|
@@ -599,13 +617,13 @@ rb_ca_scatter_replace_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
|
599
617
|
below is for the numeric and boolean cells. */
|
|
600
618
|
{
|
|
601
619
|
CArray *cs;
|
|
602
|
-
|
|
620
|
+
GetCArray(self, cs);
|
|
603
621
|
if ( cs->data_type == CA_OBJECT || cs->data_type == CA_FIXLEN ) {
|
|
604
622
|
rb_ca_modify(self);
|
|
605
623
|
if ( RB_TYPE_P(raddrs, T_ARRAY) ) { /* a list of addresses */
|
|
606
624
|
raddrs = rb_ca_wrap_readonly(raddrs, INT2NUM(CA_SIZE));
|
|
607
625
|
}
|
|
608
|
-
|
|
626
|
+
rb_ca_store(rb_ca_flatten(self), raddrs, rvals);
|
|
609
627
|
return self;
|
|
610
628
|
}
|
|
611
629
|
}
|
|
@@ -614,10 +632,10 @@ rb_ca_scatter_replace_bang (VALUE self, VALUE raddrs, VALUE rvals)
|
|
|
614
632
|
`self[addrs] = vals` establishes self.mask lazily the same way). */
|
|
615
633
|
if ( rb_obj_is_carray(rvals) ) {
|
|
616
634
|
CArray *cv_pre;
|
|
617
|
-
|
|
635
|
+
GetCArray(rvals, cv_pre);
|
|
618
636
|
if ( ca_has_mask(cv_pre) ) {
|
|
619
637
|
CArray *ca_pre;
|
|
620
|
-
|
|
638
|
+
GetCArray(self, ca_pre);
|
|
621
639
|
if ( ! ca_has_mask(ca_pre) ) {
|
|
622
640
|
ca_create_mask(ca_pre);
|
|
623
641
|
}
|