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_factorize.c
CHANGED
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
|
|
79
79
|
#include "carray.h"
|
|
80
80
|
#include "ca_obj_face.h"
|
|
81
|
-
#include "carray_internal.h" /* ca_object_cells_clear */
|
|
82
81
|
#include <string.h>
|
|
83
82
|
#include <math.h>
|
|
84
83
|
|
|
@@ -101,8 +100,7 @@
|
|
|
101
100
|
storage's, so descending would answer the wrong question. CAConstString is
|
|
102
101
|
the live example -- a cell is a (start, end) byte range, so two equal strings
|
|
103
102
|
at different offsets have different storage -- and it needs its own
|
|
104
|
-
discovery surface rather than this gate
|
|
105
|
-
devel/PROPOSAL_DISCOVERY_FAMILY_FACE_GATE.md §4). */
|
|
103
|
+
discovery surface rather than this gate. */
|
|
106
104
|
|
|
107
105
|
/* The value-hash family decides whether two cells hold the same value: every
|
|
108
106
|
NaN is one value, and -0.0 is the same value as +0.0. A float cell's key
|
|
@@ -156,7 +154,7 @@ fz_canonical_float (float v)
|
|
|
156
154
|
(-0.0 as 0.0, every NaN as one NaN), with the mask kept. The fixlen lane
|
|
157
155
|
then answers equality for complex values. */
|
|
158
156
|
static VALUE
|
|
159
|
-
fz_complex_key (VALUE self)
|
|
157
|
+
fz_complex_key (volatile VALUE self)
|
|
160
158
|
{
|
|
161
159
|
volatile VALUE out;
|
|
162
160
|
CArray *ca, *co;
|
|
@@ -177,14 +175,13 @@ fz_complex_key (VALUE self)
|
|
|
177
175
|
if ( ca_has_mask(ca) ) {
|
|
178
176
|
ca_copy_mask(co, ca);
|
|
179
177
|
}
|
|
180
|
-
RB_GC_GUARD(self); /* read through ca after rb_carray_new allocates */
|
|
181
178
|
return out;
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
/* The members whose output carries no values (a mask, a count) read a
|
|
185
182
|
complex array through its keys and need nothing back. */
|
|
186
183
|
static VALUE
|
|
187
|
-
fz_complex_as_key (VALUE self)
|
|
184
|
+
fz_complex_as_key (volatile VALUE self)
|
|
188
185
|
{
|
|
189
186
|
CArray *ca;
|
|
190
187
|
GetCArray(self, ca);
|
|
@@ -199,7 +196,7 @@ fz_complex_as_key (VALUE self)
|
|
|
199
196
|
is turned into hash keys (fz_complex_key) and *pface keeps it, so the
|
|
200
197
|
re-lift reads the values back as complex. */
|
|
201
198
|
static VALUE
|
|
202
|
-
fz_face_descend (VALUE self, volatile VALUE *pface, const char *name)
|
|
199
|
+
fz_face_descend (volatile VALUE self, volatile VALUE *pface, const char *name)
|
|
203
200
|
{
|
|
204
201
|
CArray *ca;
|
|
205
202
|
GetCArray(self, ca);
|
|
@@ -232,7 +229,7 @@ fz_face_descend (VALUE self, volatile VALUE *pface, const char *name)
|
|
|
232
229
|
(ca_face_reconcile_operand). A complex reference instead turns the
|
|
233
230
|
operand into keys of its own complex type. */
|
|
234
231
|
static VALUE
|
|
235
|
-
fz_face_reconcile (VALUE reference, VALUE operand, const char *name)
|
|
232
|
+
fz_face_reconcile (volatile VALUE reference, volatile VALUE operand, const char *name)
|
|
236
233
|
{
|
|
237
234
|
CArray *ca;
|
|
238
235
|
if ( NIL_P(reference) ) {
|
|
@@ -259,7 +256,7 @@ fz_face_reconcile (VALUE reference, VALUE operand, const char *name)
|
|
|
259
256
|
/* Put the Face back on a value-carrying output, or read complex keys back
|
|
260
257
|
as complex values. */
|
|
261
258
|
static VALUE
|
|
262
|
-
fz_face_relift (VALUE out, VALUE face)
|
|
259
|
+
fz_face_relift (volatile VALUE out, volatile VALUE face)
|
|
263
260
|
{
|
|
264
261
|
CArray *cf, *co;
|
|
265
262
|
if ( NIL_P(face) ) {
|
|
@@ -344,18 +341,20 @@ fz_tmp_alloc (VALUE *store, size_t bytes)
|
|
|
344
341
|
}
|
|
345
342
|
|
|
346
343
|
static void *
|
|
347
|
-
fz_tmp_realloc (VALUE store, size_t bytes)
|
|
344
|
+
fz_tmp_realloc (volatile VALUE store, size_t bytes)
|
|
348
345
|
{
|
|
349
|
-
fz_buffer *b
|
|
346
|
+
fz_buffer *b;
|
|
347
|
+
TypedData_Get_Struct(store, fz_buffer, &fz_buffer_type, b);
|
|
350
348
|
b->buf = (char *) xrealloc(b->buf, bytes);
|
|
351
349
|
return b->buf;
|
|
352
350
|
}
|
|
353
351
|
|
|
354
352
|
/* Mark the n VALUEs at vals (inside store's buffer); they must be valid. */
|
|
355
353
|
static void
|
|
356
|
-
fz_tmp_values (VALUE store, void *vals, ca_size_t n)
|
|
354
|
+
fz_tmp_values (volatile VALUE store, void *vals, ca_size_t n)
|
|
357
355
|
{
|
|
358
|
-
fz_buffer *b
|
|
356
|
+
fz_buffer *b;
|
|
357
|
+
TypedData_Get_Struct(store, fz_buffer, &fz_buffer_type, b);
|
|
359
358
|
b->voff = (ca_size_t) ((char *) vals - b->buf);
|
|
360
359
|
b->nvals = n;
|
|
361
360
|
}
|
|
@@ -364,7 +363,9 @@ static void
|
|
|
364
363
|
fz_tmp_free (VALUE *store)
|
|
365
364
|
{
|
|
366
365
|
if ( *store ) {
|
|
367
|
-
|
|
366
|
+
/* gc: the caller holds the store */
|
|
367
|
+
fz_buffer *b;
|
|
368
|
+
TypedData_Get_Struct(*store, fz_buffer, &fz_buffer_type, b);
|
|
368
369
|
b->nvals = 0;
|
|
369
370
|
xfree(b->buf);
|
|
370
371
|
b->buf = NULL;
|
|
@@ -818,11 +819,11 @@ static VALUE
|
|
|
818
819
|
fz_factorize_appearance_body (VALUE arg)
|
|
819
820
|
{
|
|
820
821
|
fz_frame *fr = (fz_frame *) arg;
|
|
821
|
-
VALUE self = fr->self;
|
|
822
|
+
volatile VALUE self = fr->self;
|
|
822
823
|
CArray *ca;
|
|
823
824
|
volatile VALUE face;
|
|
824
825
|
fr->self = self = fz_face_descend(self, &face, "categorize");
|
|
825
|
-
|
|
826
|
+
GetCArray(self, ca);
|
|
826
827
|
|
|
827
828
|
int8_t dt = ca->data_type;
|
|
828
829
|
switch ( dt ) {
|
|
@@ -843,9 +844,9 @@ fz_factorize_appearance_body (VALUE arg)
|
|
|
843
844
|
ca_size_t N = ca->elements;
|
|
844
845
|
|
|
845
846
|
/* uint32 code scratch, same shape as self; narrowed once k is known. */
|
|
846
|
-
VALUE vu32 = rb_carray_new(CA_UINT32, ca->ndim, ca->dim, 0, NULL);
|
|
847
|
+
volatile VALUE vu32 = rb_carray_new(CA_UINT32, ca->ndim, ca->dim, 0, NULL);
|
|
847
848
|
CArray *cu32;
|
|
848
|
-
|
|
849
|
+
GetCArray(vu32, cu32);
|
|
849
850
|
|
|
850
851
|
fz_hash h;
|
|
851
852
|
fz_levels lv;
|
|
@@ -960,14 +961,14 @@ fz_factorize_appearance_body (VALUE arg)
|
|
|
960
961
|
else if ( k <= 0xFFFF ) { code_dt = CA_UINT16; }
|
|
961
962
|
else { code_dt = CA_UINT32; }
|
|
962
963
|
|
|
963
|
-
VALUE vcodes;
|
|
964
|
+
volatile VALUE vcodes;
|
|
964
965
|
if ( code_dt == CA_UINT32 ) {
|
|
965
966
|
vcodes = vu32; /* sentinel already 0xFFFFFFFF */
|
|
966
967
|
}
|
|
967
968
|
else {
|
|
968
969
|
vcodes = rb_carray_new(code_dt, ca->ndim, ca->dim, 0, NULL);
|
|
969
970
|
CArray *cco;
|
|
970
|
-
|
|
971
|
+
GetCArray(vcodes, cco);
|
|
971
972
|
const uint32_t *up = (const uint32_t *) cu32->ptr;
|
|
972
973
|
if ( code_dt == CA_UINT8 ) {
|
|
973
974
|
uint8_t *cp = (uint8_t *) cco->ptr;
|
|
@@ -987,16 +988,16 @@ fz_factorize_appearance_body (VALUE arg)
|
|
|
987
988
|
element width; numeric / object use bytes = 0. */
|
|
988
989
|
ca_size_t ldim[1];
|
|
989
990
|
ldim[0] = k;
|
|
990
|
-
VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
991
|
+
volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
991
992
|
CArray *clev;
|
|
992
|
-
|
|
993
|
+
GetCArray(vlev, clev);
|
|
993
994
|
if ( k > 0 ) {
|
|
994
995
|
memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
|
|
995
996
|
}
|
|
996
997
|
fz_levels_free(&lv);
|
|
997
998
|
|
|
998
999
|
/* codes stay plain; levels are *values* and become categorize's labels */
|
|
999
|
-
return
|
|
1000
|
+
return rb_ary_new_from_args(2, vcodes, fz_face_relift(vlev, face));
|
|
1000
1001
|
}
|
|
1001
1002
|
|
|
1002
1003
|
static VALUE
|
|
@@ -1028,10 +1029,10 @@ static VALUE
|
|
|
1028
1029
|
fz_mask_duplicates_body (VALUE arg)
|
|
1029
1030
|
{
|
|
1030
1031
|
fz_frame *fr = (fz_frame *) arg;
|
|
1031
|
-
VALUE self = fr->self;
|
|
1032
|
+
volatile VALUE self = fr->self;
|
|
1032
1033
|
VALUE vaxis = fr->a;
|
|
1033
1034
|
CArray *ca;
|
|
1034
|
-
|
|
1035
|
+
GetCArray(self, ca);
|
|
1035
1036
|
|
|
1036
1037
|
int8_t dt = ca->data_type;
|
|
1037
1038
|
switch ( dt ) {
|
|
@@ -1054,9 +1055,9 @@ fz_mask_duplicates_body (VALUE arg)
|
|
|
1054
1055
|
rb_raise(rb_eArgError, "__mask_duplicates__: axis %d out of range", axis);
|
|
1055
1056
|
}
|
|
1056
1057
|
|
|
1057
|
-
VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
1058
|
+
volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
1058
1059
|
CArray *cout;
|
|
1059
|
-
|
|
1060
|
+
GetCArray(vout, cout);
|
|
1060
1061
|
|
|
1061
1062
|
fz_hash h;
|
|
1062
1063
|
if ( dt == CA_OBJECT ) { fz_hash_init_obj(&h); }
|
|
@@ -1189,11 +1190,11 @@ static VALUE
|
|
|
1189
1190
|
fz_unique_flat_body (VALUE arg)
|
|
1190
1191
|
{
|
|
1191
1192
|
fz_frame *fr = (fz_frame *) arg;
|
|
1192
|
-
VALUE self = fr->self;
|
|
1193
|
+
volatile VALUE self = fr->self;
|
|
1193
1194
|
CArray *ca;
|
|
1194
1195
|
volatile VALUE face;
|
|
1195
1196
|
fr->self = self = fz_face_descend(self, &face, "unique");
|
|
1196
|
-
|
|
1197
|
+
GetCArray(self, ca);
|
|
1197
1198
|
|
|
1198
1199
|
int8_t dt = ca->data_type;
|
|
1199
1200
|
switch ( dt ) {
|
|
@@ -1305,9 +1306,9 @@ fz_unique_flat_body (VALUE arg)
|
|
|
1305
1306
|
ca_size_t ldim[1];
|
|
1306
1307
|
ldim[0] = k;
|
|
1307
1308
|
/* CA_FIXLEN carries its element width; numeric / object use bytes = 0. */
|
|
1308
|
-
VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
1309
|
+
volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
1309
1310
|
CArray *clev;
|
|
1310
|
-
|
|
1311
|
+
GetCArray(vlev, clev);
|
|
1311
1312
|
if ( k > 0 ) {
|
|
1312
1313
|
memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
|
|
1313
1314
|
}
|
|
@@ -1429,8 +1430,8 @@ static VALUE
|
|
|
1429
1430
|
fz_is_in_body (VALUE arg)
|
|
1430
1431
|
{
|
|
1431
1432
|
fz_frame *fr = (fz_frame *) arg;
|
|
1432
|
-
VALUE self = fr->self;
|
|
1433
|
-
VALUE rvalues = fr->a;
|
|
1433
|
+
volatile VALUE self = fr->self;
|
|
1434
|
+
volatile VALUE rvalues = fr->a;
|
|
1434
1435
|
CArray *ca, *cv;
|
|
1435
1436
|
volatile VALUE face;
|
|
1436
1437
|
fr->self = self = fz_face_descend(self, &face, "is_in");
|
|
@@ -1481,7 +1482,7 @@ fz_is_in_body (VALUE arg)
|
|
|
1481
1482
|
fz_intern_all(&fr->st[2], &h, cv, NULL);
|
|
1482
1483
|
|
|
1483
1484
|
/* ---- Phase 2: probe every cell of self, writing the boolean membership. */
|
|
1484
|
-
VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
1485
|
+
volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
1485
1486
|
CArray *cout;
|
|
1486
1487
|
GetCArray(vout, cout);
|
|
1487
1488
|
{
|
|
@@ -1592,8 +1593,8 @@ static VALUE
|
|
|
1592
1593
|
fz_locate_addr_body (VALUE arg)
|
|
1593
1594
|
{
|
|
1594
1595
|
fz_frame *fr = (fz_frame *) arg;
|
|
1595
|
-
VALUE self = fr->self;
|
|
1596
|
-
VALUE rref = fr->a;
|
|
1596
|
+
volatile VALUE self = fr->self;
|
|
1597
|
+
volatile VALUE rref = fr->a;
|
|
1597
1598
|
CArray *ca, *cr;
|
|
1598
1599
|
/* Here the *reference* is the argument (self is the query being placed on
|
|
1599
1600
|
rref), so the gate runs the other way round: rref reconciles self. The
|
|
@@ -1734,7 +1735,7 @@ fz_locate_addr_body (VALUE arg)
|
|
|
1734
1735
|
}
|
|
1735
1736
|
|
|
1736
1737
|
/* ---- Phase 2: probe every cell of self, writing the int64 address + UNDEF. */
|
|
1737
|
-
VALUE vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
|
|
1738
|
+
volatile VALUE vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
|
|
1738
1739
|
CArray *cout;
|
|
1739
1740
|
GetCArray(vout, cout);
|
|
1740
1741
|
int64_t *out = (int64_t *) cout->ptr;
|
|
@@ -1859,8 +1860,8 @@ static VALUE
|
|
|
1859
1860
|
fz_set_relation_body (VALUE arg)
|
|
1860
1861
|
{
|
|
1861
1862
|
fz_frame *fr = (fz_frame *) arg;
|
|
1862
|
-
VALUE self = fr->self;
|
|
1863
|
-
VALUE rother = fr->a;
|
|
1863
|
+
volatile VALUE self = fr->self;
|
|
1864
|
+
volatile VALUE rother = fr->a;
|
|
1864
1865
|
int keep_when_hit = fr->i;
|
|
1865
1866
|
CArray *ca, *co;
|
|
1866
1867
|
volatile VALUE face;
|
|
@@ -2010,7 +2011,7 @@ fz_set_relation_body (VALUE arg)
|
|
|
2010
2011
|
|
|
2011
2012
|
ca_size_t ldim[1];
|
|
2012
2013
|
ldim[0] = k;
|
|
2013
|
-
VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2014
|
+
volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2014
2015
|
CArray *clev;
|
|
2015
2016
|
GetCArray(vlev, clev);
|
|
2016
2017
|
if ( k > 0 ) {
|
|
@@ -2055,8 +2056,8 @@ static VALUE
|
|
|
2055
2056
|
fz_set_union_body (VALUE arg)
|
|
2056
2057
|
{
|
|
2057
2058
|
fz_frame *fr = (fz_frame *) arg;
|
|
2058
|
-
VALUE self = fr->self;
|
|
2059
|
-
VALUE rother = fr->a;
|
|
2059
|
+
volatile VALUE self = fr->self;
|
|
2060
|
+
volatile VALUE rother = fr->a;
|
|
2060
2061
|
CArray *ca, *co;
|
|
2061
2062
|
volatile VALUE face;
|
|
2062
2063
|
fr->self = self = fz_face_descend(self, &face, "union");
|
|
@@ -2113,7 +2114,7 @@ fz_set_union_body (VALUE arg)
|
|
|
2113
2114
|
|
|
2114
2115
|
ca_size_t ldim[1];
|
|
2115
2116
|
ldim[0] = k;
|
|
2116
|
-
VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2117
|
+
volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2117
2118
|
CArray *clev;
|
|
2118
2119
|
GetCArray(vlev, clev);
|
|
2119
2120
|
if ( k > 0 ) {
|
|
@@ -2149,11 +2150,11 @@ static VALUE
|
|
|
2149
2150
|
fz_value_counts_flat_body (VALUE arg)
|
|
2150
2151
|
{
|
|
2151
2152
|
fz_frame *fr = (fz_frame *) arg;
|
|
2152
|
-
VALUE self = fr->self;
|
|
2153
|
+
volatile VALUE self = fr->self;
|
|
2153
2154
|
CArray *ca;
|
|
2154
2155
|
volatile VALUE face;
|
|
2155
2156
|
fr->self = self = fz_face_descend(self, &face, "value_counts");
|
|
2156
|
-
|
|
2157
|
+
GetCArray(self, ca);
|
|
2157
2158
|
|
|
2158
2159
|
int8_t dt = ca->data_type;
|
|
2159
2160
|
switch ( dt ) {
|
|
@@ -2287,12 +2288,12 @@ fz_value_counts_flat_body (VALUE arg)
|
|
|
2287
2288
|
ca_size_t ldim[1];
|
|
2288
2289
|
ldim[0] = k;
|
|
2289
2290
|
/* CA_FIXLEN carries its element width; numeric / object use bytes = 0. */
|
|
2290
|
-
VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2291
|
+
volatile VALUE vlev = rb_carray_new(dt, 1, ldim, (dt == CA_FIXLEN) ? ca->bytes : 0, NULL);
|
|
2291
2292
|
CArray *clev;
|
|
2292
|
-
|
|
2293
|
-
VALUE vcnt = rb_carray_new(CA_INT64, 1, ldim, 0, NULL);
|
|
2293
|
+
GetCArray(vlev, clev);
|
|
2294
|
+
volatile VALUE vcnt = rb_carray_new(CA_INT64, 1, ldim, 0, NULL);
|
|
2294
2295
|
CArray *ccnt;
|
|
2295
|
-
|
|
2296
|
+
GetCArray(vcnt, ccnt);
|
|
2296
2297
|
if ( k > 0 ) {
|
|
2297
2298
|
memcpy(clev->ptr, lv.p, (size_t) k * (size_t) ca->bytes);
|
|
2298
2299
|
memcpy(ccnt->ptr, ct.p, (size_t) k * sizeof(int64_t));
|
|
@@ -2301,7 +2302,7 @@ fz_value_counts_flat_body (VALUE arg)
|
|
|
2301
2302
|
fz_levels_free(&ct);
|
|
2302
2303
|
|
|
2303
2304
|
/* values carry the Face, counts stay plain int64 */
|
|
2304
|
-
return
|
|
2305
|
+
return rb_ary_new_from_args(2, fz_face_relift(vlev, face), vcnt);
|
|
2305
2306
|
}
|
|
2306
2307
|
|
|
2307
2308
|
static VALUE
|
|
@@ -2325,11 +2326,11 @@ static VALUE
|
|
|
2325
2326
|
fz_nunique_body (VALUE arg)
|
|
2326
2327
|
{
|
|
2327
2328
|
fz_frame *fr = (fz_frame *) arg;
|
|
2328
|
-
VALUE self = fr->self;
|
|
2329
|
+
volatile VALUE self = fr->self;
|
|
2329
2330
|
VALUE vaxis = fr->a;
|
|
2330
2331
|
VALUE vkeep = fr->b;
|
|
2331
2332
|
CArray *ca;
|
|
2332
|
-
|
|
2333
|
+
GetCArray(self, ca);
|
|
2333
2334
|
|
|
2334
2335
|
int8_t dt = ca->data_type;
|
|
2335
2336
|
switch ( dt ) {
|
|
@@ -2349,11 +2350,11 @@ fz_nunique_body (VALUE arg)
|
|
|
2349
2350
|
|
|
2350
2351
|
int8_t axes[CA_RANK_MAX];
|
|
2351
2352
|
int8_t naxes = rb_ca_parse_reduce_axes_kw_ctx(vaxis, ca, axes, "nunique");
|
|
2352
|
-
int keep_axis =
|
|
2353
|
+
int keep_axis = ca_bool_arg(vkeep, "keep_axis");
|
|
2353
2354
|
|
|
2354
|
-
VALUE vout = rb_ca_new_reduced(self, axes, naxes, CA_INT64, keep_axis);
|
|
2355
|
+
volatile VALUE vout = rb_ca_new_reduced(self, axes, naxes, CA_INT64, keep_axis);
|
|
2355
2356
|
CArray *cout;
|
|
2356
|
-
|
|
2357
|
+
GetCArray(vout, cout);
|
|
2357
2358
|
int64_t *op = (int64_t *) cout->ptr;
|
|
2358
2359
|
|
|
2359
2360
|
fz_hash h;
|
|
@@ -2472,10 +2473,10 @@ static VALUE
|
|
|
2472
2473
|
fz_is_mode_body (VALUE arg)
|
|
2473
2474
|
{
|
|
2474
2475
|
fz_frame *fr = (fz_frame *) arg;
|
|
2475
|
-
VALUE self = fr->self;
|
|
2476
|
+
volatile VALUE self = fr->self;
|
|
2476
2477
|
VALUE vaxis = fr->a;
|
|
2477
2478
|
CArray *ca;
|
|
2478
|
-
|
|
2479
|
+
GetCArray(self, ca);
|
|
2479
2480
|
|
|
2480
2481
|
int8_t dt = ca->data_type;
|
|
2481
2482
|
switch ( dt ) {
|
|
@@ -2497,9 +2498,9 @@ fz_is_mode_body (VALUE arg)
|
|
|
2497
2498
|
rb_raise(rb_eArgError, "__is_mode__: axis %d out of range", axis);
|
|
2498
2499
|
}
|
|
2499
2500
|
|
|
2500
|
-
VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
2501
|
+
volatile VALUE vout = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
|
|
2501
2502
|
CArray *cout;
|
|
2502
|
-
|
|
2503
|
+
GetCArray(vout, cout);
|
|
2503
2504
|
|
|
2504
2505
|
fz_hash h;
|
|
2505
2506
|
fz_levels ct; /* int64 count per code (code == push index), reset per fiber */
|
|
@@ -2691,12 +2692,12 @@ static VALUE
|
|
|
2691
2692
|
fz_mode_axis_body (VALUE arg)
|
|
2692
2693
|
{
|
|
2693
2694
|
fz_frame *fr = (fz_frame *) arg;
|
|
2694
|
-
VALUE self = fr->self;
|
|
2695
|
+
volatile VALUE self = fr->self;
|
|
2695
2696
|
VALUE vaxis = fr->a;
|
|
2696
2697
|
CArray *ca;
|
|
2697
2698
|
volatile VALUE face;
|
|
2698
2699
|
fr->self = self = fz_face_descend(self, &face, "mode");
|
|
2699
|
-
|
|
2700
|
+
GetCArray(self, ca);
|
|
2700
2701
|
|
|
2701
2702
|
int8_t dt = ca->data_type;
|
|
2702
2703
|
switch ( dt ) {
|
|
@@ -2849,9 +2850,9 @@ fz_mode_axis_body (VALUE arg)
|
|
|
2849
2850
|
UNDEF when r has fewer than j+1 modes. K == 0 -> empty Array. */
|
|
2850
2851
|
VALUE result = rb_ary_new_capa((long) Kmax);
|
|
2851
2852
|
for ( ca_size_t j = 0; j < Kmax; j++ ) {
|
|
2852
|
-
VALUE col = rb_ca_new_reduced(self, &ax, 1, dt, 0);
|
|
2853
|
+
volatile VALUE col = rb_ca_new_reduced(self, &ax, 1, dt, 0);
|
|
2853
2854
|
CArray *cc;
|
|
2854
|
-
|
|
2855
|
+
GetCArray(col, cc);
|
|
2855
2856
|
ca_create_mask(cc);
|
|
2856
2857
|
boolean8_t *cm = (boolean8_t *) cc->mask->ptr;
|
|
2857
2858
|
char *dst = cc->ptr;
|
data/ext/carray_generate.c
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
#include "ruby.h"
|
|
11
11
|
#include "carray.h"
|
|
12
|
-
#include "carray_internal.h" /* ca_attach_window, ca_normalize_axis_arg */
|
|
13
12
|
#include "ca_obj_face.h" /* ca_face_element_to_storage */
|
|
14
13
|
|
|
15
14
|
/* ----------------------------------------------------------------- */
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
Also used internally by ext/ca_obj_grid.c when it needs to extract
|
|
24
23
|
the addresses of true cells from a boolean axis selector. */
|
|
25
24
|
VALUE
|
|
26
|
-
rb_ca_where (VALUE self)
|
|
25
|
+
rb_ca_where (volatile VALUE self)
|
|
27
26
|
{
|
|
28
27
|
volatile VALUE bool0, obj;
|
|
29
28
|
CArray *ca, *co;
|
|
@@ -31,7 +30,7 @@ rb_ca_where (VALUE self)
|
|
|
31
30
|
ca_size_t *q;
|
|
32
31
|
ca_size_t i, j, n, last, count;
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
GetCArray(self, ca);
|
|
35
34
|
if ( ca_is_boolean_type(ca) ) {
|
|
36
35
|
bool0 = self;
|
|
37
36
|
}
|
|
@@ -40,13 +39,19 @@ rb_ca_where (VALUE self)
|
|
|
40
39
|
ca_is_complex_type(ca) ) ) {
|
|
41
40
|
bool0 = rb_funcall(self, rb_intern("ne"), 1, INT2FIX(0));
|
|
42
41
|
}
|
|
42
|
+
else if ( ! ca_is_face(ca) && ca_is_object_type(ca) ) {
|
|
43
|
+
/* each cell read as a boolean cell reads a value it is given, so a cell
|
|
44
|
+
that is no truth value raises (to_type would make it UNDEF) */
|
|
45
|
+
bool0 = rb_ca_copy(rb_funcall(self, rb_intern("as_type"), 1,
|
|
46
|
+
ID2SYM(rb_intern("boolean"))));
|
|
47
|
+
}
|
|
43
48
|
else {
|
|
44
49
|
bool0 = rb_ca_to_boolean(self);
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
GetCArray(bool0, ca);
|
|
48
53
|
|
|
49
|
-
ca_attach(ca); /*
|
|
54
|
+
ca_attach(ca); /* attach: nothing raises before the detach */
|
|
50
55
|
|
|
51
56
|
/* calculate elements of output array, and the last selected cell */
|
|
52
57
|
p = (boolean8_t *) ca->ptr;
|
|
@@ -72,7 +77,7 @@ rb_ca_where (VALUE self)
|
|
|
72
77
|
|
|
73
78
|
/* create output array */
|
|
74
79
|
obj = rb_carray_new(CA_SIZE, 1, &count, 0, NULL);
|
|
75
|
-
|
|
80
|
+
GetCArray(obj, co);
|
|
76
81
|
|
|
77
82
|
/* Store the address of each selected cell. Every cell up to the last
|
|
78
83
|
selected one is written and the output position advances only on a
|
|
@@ -215,7 +220,7 @@ ca_seq_resolve_axis (CArray *ca, VALUE raxis)
|
|
|
215
220
|
"%s: axis must be a single Integer (a seq over several axes is not supported)",
|
|
216
221
|
ca_calling_method_name());
|
|
217
222
|
}
|
|
218
|
-
axis =
|
|
223
|
+
axis = rb_ca_normalize_axis_arg(raxis, ca->ndim, NULL);
|
|
219
224
|
return axis;
|
|
220
225
|
}
|
|
221
226
|
|
|
@@ -236,7 +241,8 @@ ca_seq_geometry (CArray *ca, int axis,
|
|
|
236
241
|
}
|
|
237
242
|
|
|
238
243
|
/* The object fill calls Ruby per cell (`+`, or the method given as the
|
|
239
|
-
step), which can raise part way, so it runs
|
|
244
|
+
step), which can raise part way, so it runs while the array is attached
|
|
245
|
+
(not allocated):
|
|
240
246
|
the cells filled before the raise then reach the parent with the rest
|
|
241
247
|
left as they were, as they would for an entity. */
|
|
242
248
|
|
|
@@ -371,11 +377,11 @@ ca_seq_bang_object_body (VALUE arg)
|
|
|
371
377
|
}
|
|
372
378
|
|
|
373
379
|
static VALUE
|
|
374
|
-
rb_ca_seq_bang_object (VALUE self, VALUE roffset, VALUE rstep, int axis)
|
|
380
|
+
rb_ca_seq_bang_object (volatile VALUE self, VALUE roffset, VALUE rstep, int axis)
|
|
375
381
|
{
|
|
376
382
|
ca_seq_ctx_t c;
|
|
377
383
|
|
|
378
|
-
|
|
384
|
+
GetCArray(self, c.ca);
|
|
379
385
|
|
|
380
386
|
c.self = self;
|
|
381
387
|
c.rmethod = Qnil;
|
|
@@ -392,9 +398,10 @@ rb_ca_seq_bang_object (VALUE self, VALUE roffset, VALUE rstep, int axis)
|
|
|
392
398
|
return self;
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
/* The numeric fill runs
|
|
396
|
-
|
|
397
|
-
raise: offset and step are checked to be numbers before
|
|
401
|
+
/* The numeric fill runs while the array is allocated (ca_allocate), which
|
|
402
|
+
clears an entity's mask (an entity has no separate buffer), so nothing
|
|
403
|
+
in it may raise: offset and step are checked to be numbers before the
|
|
404
|
+
allocate. */
|
|
398
405
|
static VALUE
|
|
399
406
|
ca_seq_bang_numeric_body (VALUE arg)
|
|
400
407
|
{
|
|
@@ -496,18 +503,18 @@ ca_seq_check_real_run (CArray *ca, VALUE roffset, VALUE rstep, ca_size_t n)
|
|
|
496
503
|
per-element method calls like `:succ`). Mutates self and clears any
|
|
497
504
|
existing mask. */
|
|
498
505
|
static VALUE
|
|
499
|
-
rb_ca_seq_bang_method (int argc, VALUE *argv, VALUE self)
|
|
506
|
+
rb_ca_seq_bang_method (int argc, VALUE *argv, volatile VALUE self)
|
|
500
507
|
{
|
|
501
|
-
|
|
508
|
+
VALUE roffset = Qnil, rstep = Qnil, rkw = Qnil, raxis = Qnil;
|
|
502
509
|
CArray *ca;
|
|
503
510
|
int axis;
|
|
504
511
|
|
|
505
512
|
rb_ca_modify(self);
|
|
506
|
-
|
|
513
|
+
GetCArray(self, ca);
|
|
507
514
|
|
|
508
|
-
rb_scan_args(argc, argv, "02:",
|
|
509
|
-
|
|
510
|
-
rb_scan_options(rkw, "axis",
|
|
515
|
+
rb_scan_args(argc, argv, "02:", &roffset, &rstep,
|
|
516
|
+
&rkw);
|
|
517
|
+
rb_scan_options(rkw, "axis", &raxis);
|
|
511
518
|
|
|
512
519
|
axis = ca_seq_resolve_axis(ca, raxis); /* -1 = flat; validates */
|
|
513
520
|
|
data/ext/carray_histogram.c
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
---------------------------------------------------------------------------- */
|
|
24
24
|
|
|
25
25
|
#include "carray.h"
|
|
26
|
-
#include "carray_internal.h" /* ca_attach_window */
|
|
27
26
|
#include <math.h>
|
|
28
27
|
#include <float.h>
|
|
29
28
|
|
|
@@ -59,7 +58,7 @@ histbin_check_edge_order (const double *ep, ca_size_t n, const char *name)
|
|
|
59
58
|
buffer) rather than attaching them: the walk that follows reads the
|
|
60
59
|
caller's array, and a raise there must not leave the edges attached. */
|
|
61
60
|
static VALUE
|
|
62
|
-
histbin_resolve_edges (VALUE self, VALUE redges)
|
|
61
|
+
histbin_resolve_edges (VALUE self, volatile VALUE redges)
|
|
63
62
|
{
|
|
64
63
|
CArray *ce;
|
|
65
64
|
|
|
@@ -179,10 +178,10 @@ histbin_axis_setup (histbin_axis_t *ax, const double *ep, ca_size_t ne,
|
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
static VALUE
|
|
182
|
-
rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
|
|
181
|
+
rb_ca_histbin_ki (volatile VALUE self, volatile VALUE redges, VALUE rinclude_max)
|
|
183
182
|
{
|
|
184
183
|
CArray *ca, *co, *ce;
|
|
185
|
-
VALUE
|
|
184
|
+
volatile VALUE vout;
|
|
186
185
|
volatile VALUE hedges = 0;
|
|
187
186
|
double *ep;
|
|
188
187
|
histbin_axis_t ax;
|
|
@@ -199,8 +198,7 @@ rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
|
|
|
199
198
|
ep = ALLOCV_N(double, hedges, ce->elements);
|
|
200
199
|
ca_xfer_all(ce, ep, CA_XFER_GET);
|
|
201
200
|
histbin_check_edge_order(ep, ce->elements, "bin_to");
|
|
202
|
-
histbin_axis_setup(&ax, ep, ce->elements,
|
|
203
|
-
RB_GC_GUARD(redges); /* a view made by histbin_resolve_edges is read through ce */
|
|
201
|
+
histbin_axis_setup(&ax, ep, ce->elements, ca_bool_arg(rinclude_max, "include_max"));
|
|
204
202
|
|
|
205
203
|
/* output: fresh contiguous int64, same shape as self. */
|
|
206
204
|
vout = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
|
|
@@ -259,7 +257,7 @@ rb_ca_histbin_ki (VALUE self, VALUE redges, VALUE rinclude_max)
|
|
|
259
257
|
off = fiber_base + Σ_k histbin_index(axis_k, v_{a,k}) * ext_stride[k]
|
|
260
258
|
counts[off] += 1 (or += weight when weighted)
|
|
261
259
|
=========================================================================== */
|
|
262
|
-
/* histogram_scatter_ki reads its edges
|
|
260
|
+
/* histogram_scatter_ki reads its edges while they are attached and walks
|
|
263
261
|
the samples (and the weights) with two kernel iterators, whose states
|
|
264
262
|
live here, outside the walk: a sample view that raises as it is read --
|
|
265
263
|
a lazy source meeting a cell it cannot compute -- leaves neither the
|
|
@@ -383,8 +381,8 @@ histogram_scatter_edges (VALUE arg)
|
|
|
383
381
|
}
|
|
384
382
|
|
|
385
383
|
static VALUE
|
|
386
|
-
rb_ca_histogram_scatter_ki (VALUE self, VALUE rcounts, VALUE redges,
|
|
387
|
-
VALUE rincmax, VALUE rweights)
|
|
384
|
+
rb_ca_histogram_scatter_ki (volatile VALUE self, volatile VALUE rcounts, VALUE redges,
|
|
385
|
+
VALUE rincmax, volatile VALUE rweights)
|
|
388
386
|
{
|
|
389
387
|
CArray *ca, *cc, *cw = NULL;
|
|
390
388
|
long M, nf, k;
|
|
@@ -437,7 +435,7 @@ rb_ca_histogram_scatter_ki (VALUE self, VALUE rcounts, VALUE redges,
|
|
|
437
435
|
}
|
|
438
436
|
|
|
439
437
|
for ( k = 0; k < M; k++ ) {
|
|
440
|
-
VALUE e = RARRAY_AREF(redges, k);
|
|
438
|
+
volatile VALUE e = RARRAY_AREF(redges, k);
|
|
441
439
|
GetCArray(e, edge_ca[k]);
|
|
442
440
|
histbin_check_edge_mask(edge_ca[k], "histogram");
|
|
443
441
|
}
|
|
@@ -528,7 +526,7 @@ bincount_nd_label_u64 (uint64_t x)
|
|
|
528
526
|
} while (0)
|
|
529
527
|
|
|
530
528
|
static VALUE
|
|
531
|
-
rb_ca_bincount_nd_count_ki (VALUE self, VALUE rcounts, VALUE rweights)
|
|
529
|
+
rb_ca_bincount_nd_count_ki (volatile VALUE self, volatile VALUE rcounts, volatile VALUE rweights)
|
|
532
530
|
{
|
|
533
531
|
CArray *ca, *cc, *cw = NULL;
|
|
534
532
|
long M, nf, k;
|
data/ext/carray_hold.c
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* ---------------------------------------------------------------------------
|
|
2
2
|
|
|
3
3
|
Mask gap-fill hold: carry the last valid value forward into masked cells
|
|
4
|
-
along one axis. Backing primitive for `unmask(method:)` / `strip_mask(method:)
|
|
5
|
-
(see devel/PROPOSAL_UNMASK_FILL_METHOD.md).
|
|
4
|
+
along one axis. Backing primitive for `unmask(method:)` / `strip_mask(method:)`.
|
|
6
5
|
|
|
7
6
|
Hold copies a cell's bytes into masked cells with no arithmetic and no
|
|
8
7
|
per-type behavior, so a single ca->bytes-width memcpy walk covers every
|
|
@@ -20,7 +19,6 @@
|
|
|
20
19
|
#include "carray.h"
|
|
21
20
|
#include "ca_kernel_iterator.h"
|
|
22
21
|
#include "ca_obj_face.h"
|
|
23
|
-
#include "carray_internal.h" /* ca_normalize_axis_arg */
|
|
24
22
|
|
|
25
23
|
/* Forward hold along `axis`. Per fiber along the scan axis:
|
|
26
24
|
- present cell -> output = cell value, becomes the held value;
|
|
@@ -28,7 +26,7 @@
|
|
|
28
26
|
- masked before any value (leading run) -> output stays masked (UNDEF),
|
|
29
27
|
since there is no value to carry (hold has no identity). */
|
|
30
28
|
static VALUE
|
|
31
|
-
rb_ca_hold_forward (VALUE self, int axis)
|
|
29
|
+
rb_ca_hold_forward (volatile VALUE self, int axis)
|
|
32
30
|
{
|
|
33
31
|
CArray *ca, *co;
|
|
34
32
|
GetCArray(self, ca);
|
|
@@ -111,11 +109,11 @@ rb_ca_hold_forward (VALUE self, int axis)
|
|
|
111
109
|
Integer (negative counts from the end). The Ruby wrapper composes
|
|
112
110
|
backward / flatten / linear on top of this. */
|
|
113
111
|
static VALUE
|
|
114
|
-
rb_ca_hold_method (VALUE self, VALUE raxis)
|
|
112
|
+
rb_ca_hold_method (volatile VALUE self, VALUE raxis)
|
|
115
113
|
{
|
|
116
114
|
CArray *ca;
|
|
117
115
|
GetCArray(self, ca);
|
|
118
|
-
return rb_ca_hold_forward(self,
|
|
116
|
+
return rb_ca_hold_forward(self, rb_ca_normalize_axis_arg(raxis, ca->ndim, NULL));
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
/* first / last: the reduction sibling of hold. Reduce each fiber to its
|
|
@@ -124,13 +122,13 @@ rb_ca_hold_method (VALUE self, VALUE raxis)
|
|
|
124
122
|
(all masked, or empty) yields UNDEF. A user who wants a default instead
|
|
125
123
|
of UNDEF completes at the call site: `a.first(axis: 0).strip_mask(v)`. */
|
|
126
124
|
static VALUE
|
|
127
|
-
rb_ca_first_last_reduce (VALUE self, int argc, VALUE *argv, int backward)
|
|
125
|
+
rb_ca_first_last_reduce (volatile VALUE self, int argc, VALUE *argv, int backward)
|
|
128
126
|
{
|
|
129
127
|
CArray *ca, *co;
|
|
130
128
|
GetCArray(self, ca);
|
|
131
129
|
|
|
132
130
|
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
|
133
|
-
|
|
131
|
+
VALUE raxis = Qnil, rkeep_axis = Qnil;
|
|
134
132
|
rb_scan_options(ropt, "axis,keep_axis", &raxis, &rkeep_axis);
|
|
135
133
|
if ( argc > 0 ) {
|
|
136
134
|
rb_raise(rb_eArgError,
|
|
@@ -139,7 +137,7 @@ rb_ca_first_last_reduce (VALUE self, int argc, VALUE *argv, int backward)
|
|
|
139
137
|
backward ? "last" : "first", argc,
|
|
140
138
|
backward ? "last" : "first", backward ? "last" : "first");
|
|
141
139
|
}
|
|
142
|
-
int keep_axis =
|
|
140
|
+
int keep_axis = ca_bool_arg(rkeep_axis, "keep_axis");
|
|
143
141
|
int8_t slab_axes[CA_RANK_MAX];
|
|
144
142
|
int8_t naxes = rb_ca_parse_reduce_axes_kw(raxis, ca, slab_axes);
|
|
145
143
|
|