carray 3.0.7 → 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 -1940
- data/README.md +38 -32
- 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 +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- 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 -1506
- 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 +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- 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 +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- 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 +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- 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 +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- 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 +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- 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 +5 -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 +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- 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 +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- 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 +12 -12
- 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 +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- 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 +4 -3
- 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 +7 -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 +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- 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 +5 -3
- 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 +157 -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 +67 -34
- 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 +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- 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 -25337
- 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 -262
- data/lib/carray/data_type_limits.rb +0 -91
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
|
|
42
42
|
#include "ruby.h"
|
|
43
43
|
#include "carray.h"
|
|
44
|
-
#include "carray_internal.h" /* ca_integer_arg, ca_calling_method_name */
|
|
45
44
|
#include "ca_obj_face.h" /* ca_face_refuse_numeric */
|
|
46
45
|
#include <math.h>
|
|
47
46
|
|
|
@@ -116,14 +115,14 @@ mp_geometry (CArray *ca, long axis, long *OUTER, long *M, long *INNER)
|
|
|
116
115
|
/* [numeric] keep_axis: [1,1,...,1] CA_FLOAT64 entity (original ndim)
|
|
117
116
|
holding a scalar (or a single masked cell when is_undef). */
|
|
118
117
|
static VALUE
|
|
119
|
-
mp_keep_axis_full_f64 (VALUE self, double v, int is_undef)
|
|
118
|
+
mp_keep_axis_full_f64 (volatile VALUE self, double v, int is_undef)
|
|
120
119
|
{
|
|
121
120
|
CArray *ca;
|
|
122
121
|
GetCArray(self, ca);
|
|
123
122
|
int nd = ca->ndim;
|
|
124
123
|
ca_size_t *dim = ALLOCA_N(ca_size_t, nd);
|
|
125
124
|
for ( int i = 0; i < nd; i++ ) dim[i] = 1;
|
|
126
|
-
VALUE out = rb_carray_new(CA_FLOAT64, (int8_t) nd, dim, 0, NULL);
|
|
125
|
+
volatile VALUE out = rb_carray_new(CA_FLOAT64, (int8_t) nd, dim, 0, NULL);
|
|
127
126
|
CArray *co;
|
|
128
127
|
GetCArray(out, co);
|
|
129
128
|
if ( is_undef ) {
|
|
@@ -142,12 +141,12 @@ mp_keep_axis_full_f64 (VALUE self, double v, int is_undef)
|
|
|
142
141
|
does for a fiber with no present cell. keep_axis controls whether the
|
|
143
142
|
reduced axis is dropped or kept as a length-1 axis. */
|
|
144
143
|
static VALUE
|
|
145
|
-
mp_axis_all_masked (VALUE self, long axis, VALUE fill_value, int keep_axis)
|
|
144
|
+
mp_axis_all_masked (volatile VALUE self, long axis, VALUE fill_value, int keep_axis)
|
|
146
145
|
{
|
|
147
146
|
int8_t ax = (int8_t) axis;
|
|
148
147
|
CArray *ca;
|
|
149
148
|
GetCArray(self, ca);
|
|
150
|
-
VALUE out = rb_ca_new_reduced(self, &ax, 1,
|
|
149
|
+
volatile VALUE out = rb_ca_new_reduced(self, &ax, 1,
|
|
151
150
|
(ca->data_type == CA_OBJECT) ? CA_OBJECT
|
|
152
151
|
: CA_FLOAT64,
|
|
153
152
|
keep_axis);
|
|
@@ -262,19 +261,19 @@ median_fill (double *op, int8_t dt, const char *base,
|
|
|
262
261
|
|
|
263
262
|
/* [numeric] per-axis median -> reduced CA_FLOAT64 CArray. */
|
|
264
263
|
static VALUE
|
|
265
|
-
median_axis (VALUE self, long axis, long n, int keep_axis)
|
|
264
|
+
median_axis (volatile VALUE self, long axis, long n, int keep_axis)
|
|
266
265
|
{
|
|
267
266
|
CArray *ca;
|
|
268
267
|
GetCArray(self, ca);
|
|
269
268
|
int8_t dt = ca->data_type;
|
|
270
269
|
long k = (n % 2 == 0) ? (n / 2 - 1) : ((n - 1) / 2);
|
|
271
270
|
|
|
272
|
-
VALUE pp = rb_ca_partition_copy_c(self, LONG2NUM(k), LONG2NUM(axis));
|
|
271
|
+
volatile VALUE pp = rb_ca_partition_copy_c(self, LONG2NUM(k), LONG2NUM(axis));
|
|
273
272
|
CArray *cp;
|
|
274
273
|
GetCArray(pp, cp);
|
|
275
274
|
|
|
276
275
|
int8_t ax = (int8_t) axis;
|
|
277
|
-
VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
276
|
+
volatile VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
278
277
|
CArray *co;
|
|
279
278
|
GetCArray(out, co);
|
|
280
279
|
|
|
@@ -282,33 +281,31 @@ median_axis (VALUE self, long axis, long n, int keep_axis)
|
|
|
282
281
|
mp_geometry(ca, axis, &OUTER, &M, &INNER);
|
|
283
282
|
median_fill((double *) co->ptr, dt, (const char *) cp->ptr,
|
|
284
283
|
OUTER, M, INNER, n, k, (n % 2 != 0));
|
|
285
|
-
RB_GC_GUARD(pp);
|
|
286
284
|
return out;
|
|
287
285
|
}
|
|
288
286
|
|
|
289
287
|
/* [numeric] flat median scalar (double) of a 1-D numeric entity/view. */
|
|
290
288
|
static double
|
|
291
|
-
median_scalar_1d (VALUE src1d, long n)
|
|
289
|
+
median_scalar_1d (volatile VALUE src1d, long n)
|
|
292
290
|
{
|
|
293
291
|
CArray *ca;
|
|
294
292
|
GetCArray(src1d, ca);
|
|
295
293
|
long k = (n % 2 == 0) ? (n / 2 - 1) : ((n - 1) / 2);
|
|
296
|
-
VALUE pp = rb_ca_partition_copy_c(src1d, LONG2NUM(k), INT2FIX(0));
|
|
294
|
+
volatile VALUE pp = rb_ca_partition_copy_c(src1d, LONG2NUM(k), INT2FIX(0));
|
|
297
295
|
CArray *cp;
|
|
298
296
|
GetCArray(pp, cp);
|
|
299
297
|
double res;
|
|
300
298
|
median_fill(&res, ca->data_type, (const char *) cp->ptr,
|
|
301
299
|
1, n, 1, n, k, (n % 2 != 0)); /* OUTER=1, M=n, INNER=1 */
|
|
302
|
-
RB_GC_GUARD(pp);
|
|
303
300
|
return res;
|
|
304
301
|
}
|
|
305
302
|
|
|
306
303
|
/* [numeric] flat median: strip mask / honour min_count, flatten, then
|
|
307
304
|
reduce on axis 0 to a bare Float (or keep_axis [1..1] entity). */
|
|
308
305
|
static VALUE
|
|
309
|
-
median_flat (VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
306
|
+
median_flat (volatile VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
310
307
|
{
|
|
311
|
-
VALUE src = self;
|
|
308
|
+
volatile VALUE src = self;
|
|
312
309
|
int filled = 0; /* masked-out or empty -> use fill_value / UNDEF */
|
|
313
310
|
|
|
314
311
|
if ( RTEST(rb_ca_has_mask(self)) ) {
|
|
@@ -330,11 +327,10 @@ median_flat (VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
|
330
327
|
return is_undef ? CA_UNDEF : fill_value;
|
|
331
328
|
}
|
|
332
329
|
|
|
333
|
-
VALUE flat = rb_ca_flatten(src);
|
|
330
|
+
volatile VALUE flat = rb_ca_flatten(src);
|
|
334
331
|
CArray *fc;
|
|
335
332
|
GetCArray(flat, fc);
|
|
336
333
|
double scalar = median_scalar_1d(flat, (long) fc->elements);
|
|
337
|
-
RB_GC_GUARD(flat);
|
|
338
334
|
if ( keep_axis ) return mp_keep_axis_full_f64(self, scalar, 0);
|
|
339
335
|
return rb_float_new(scalar);
|
|
340
336
|
}
|
|
@@ -357,7 +353,7 @@ median_flat (VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
|
357
353
|
them on the per-axis one, so look through a CArray to an element. An
|
|
358
354
|
empty one has nothing to interpolate and passes. */
|
|
359
355
|
static int
|
|
360
|
-
mp_object_interpolates (VALUE v)
|
|
356
|
+
mp_object_interpolates (volatile VALUE v)
|
|
361
357
|
{
|
|
362
358
|
if ( rb_obj_is_kind_of(v, rb_cNumeric) ) {
|
|
363
359
|
return 1;
|
|
@@ -380,7 +376,7 @@ mp_object_interpolates (VALUE v)
|
|
|
380
376
|
/* [object] The element an interpolation refusal names: lo itself, or the
|
|
381
377
|
first element of a CArray of them that has no arithmetic. */
|
|
382
378
|
static VALUE
|
|
383
|
-
mp_first_non_numeric (VALUE v)
|
|
379
|
+
mp_first_non_numeric (volatile VALUE v)
|
|
384
380
|
{
|
|
385
381
|
if ( rb_obj_is_kind_of(v, rb_cCArray) ) {
|
|
386
382
|
CArray *ca;
|
|
@@ -454,7 +450,7 @@ obj_call_axis (VALUE recv, ID mid, VALUE raxis)
|
|
|
454
450
|
|
|
455
451
|
/* [object] arr[*spec] with spec[axis]=idx, rest nil (= drop one axis). */
|
|
456
452
|
static VALUE
|
|
457
|
-
obj_slice (VALUE arr, long axis, long idx)
|
|
453
|
+
obj_slice (volatile VALUE arr, long axis, long idx)
|
|
458
454
|
{
|
|
459
455
|
CArray *ca;
|
|
460
456
|
GetCArray(arr, ca);
|
|
@@ -467,7 +463,7 @@ obj_slice (VALUE arr, long axis, long idx)
|
|
|
467
463
|
|
|
468
464
|
/* [object] min over pp[*spec] with spec[axis] = (k+1)..(n-1) along axis. */
|
|
469
465
|
static VALUE
|
|
470
|
-
obj_min_upper (VALUE pp, long axis, long k, long n)
|
|
466
|
+
obj_min_upper (volatile VALUE pp, long axis, long k, long n)
|
|
471
467
|
{
|
|
472
468
|
CArray *ca;
|
|
473
469
|
GetCArray(pp, ca);
|
|
@@ -500,7 +496,7 @@ obj_kth_pair (VALUE self, long axis, long k, long n, VALUE *lo, VALUE *hi)
|
|
|
500
496
|
masked), in self's Face when self is one. Uses []= so UNDEF / arbitrary
|
|
501
497
|
objects store correctly. */
|
|
502
498
|
static VALUE
|
|
503
|
-
obj_keep_axis_full (VALUE self, VALUE val)
|
|
499
|
+
obj_keep_axis_full (volatile VALUE self, VALUE val)
|
|
504
500
|
{
|
|
505
501
|
CArray *ca;
|
|
506
502
|
GetCArray(self, ca);
|
|
@@ -556,7 +552,7 @@ median_object_axis (VALUE self, long axis, long n, int keep_axis)
|
|
|
556
552
|
as a slice of its partitioned copy is made an array of its own, as the
|
|
557
553
|
other reductions' answers are. */
|
|
558
554
|
static VALUE
|
|
559
|
-
mp_axis_answer (VALUE self, VALUE res, int keep_axis)
|
|
555
|
+
mp_axis_answer (volatile VALUE self, volatile VALUE res, int keep_axis)
|
|
560
556
|
{
|
|
561
557
|
CArray *ca;
|
|
562
558
|
GetCArray(self, ca);
|
|
@@ -578,9 +574,10 @@ mp_axis_answer (VALUE self, VALUE res, int keep_axis)
|
|
|
578
574
|
|
|
579
575
|
/* [object] flat median: mask-strip / min_count, flatten, axis-0 reduce. */
|
|
580
576
|
static VALUE
|
|
581
|
-
median_object_flat (VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
577
|
+
median_object_flat (volatile VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
582
578
|
{
|
|
583
|
-
VALUE src = self
|
|
579
|
+
volatile VALUE src = self;
|
|
580
|
+
VALUE result;
|
|
584
581
|
int filled = 0;
|
|
585
582
|
if ( RTEST(rb_ca_has_mask(self)) ) {
|
|
586
583
|
CArray *mc; GetCArray(self, mc);
|
|
@@ -596,11 +593,10 @@ median_object_flat (VALUE self, long min_count, VALUE fill_value, int keep_axis)
|
|
|
596
593
|
if ( filled ) {
|
|
597
594
|
result = NIL_P(fill_value) ? CA_UNDEF : fill_value;
|
|
598
595
|
} else {
|
|
599
|
-
VALUE flat = rb_ca_flatten(src);
|
|
596
|
+
volatile VALUE flat = rb_ca_flatten(src);
|
|
600
597
|
CArray *fc;
|
|
601
598
|
GetCArray(flat, fc);
|
|
602
599
|
result = median_object_axis(flat, 0, (long) fc->elements, 0);
|
|
603
|
-
RB_GC_GUARD(flat);
|
|
604
600
|
}
|
|
605
601
|
return keep_axis ? obj_keep_axis_full(self, result) : result;
|
|
606
602
|
}
|
|
@@ -673,7 +669,7 @@ pct_object_one_sorted (VALUE sorted, long axis, long n, double p, VALUE method)
|
|
|
673
669
|
/* [object] per-axis percentile -> array of (reduced CArray | scalar),
|
|
674
670
|
one entry per requested p (keep_axis wrapping done by the entry). */
|
|
675
671
|
static VALUE
|
|
676
|
-
percentile_object_axis (VALUE self, VALUE pers, long axis, VALUE method)
|
|
672
|
+
percentile_object_axis (volatile VALUE self, VALUE pers, long axis, VALUE method)
|
|
677
673
|
{
|
|
678
674
|
CArray *ca;
|
|
679
675
|
GetCArray(self, ca);
|
|
@@ -696,13 +692,12 @@ percentile_object_axis (VALUE self, VALUE pers, long axis, VALUE method)
|
|
|
696
692
|
}
|
|
697
693
|
/* multi-p: one shared sort (CA_OBJECT sort trampolines to the focused
|
|
698
694
|
Ruby per-slab helper), materialised once, then C-driven slicing. */
|
|
699
|
-
VALUE sorted = rb_funcall(obj_call_axis(self, id_sort, LONG2NUM(axis)), id_copy, 0);
|
|
695
|
+
volatile VALUE sorted = rb_funcall(obj_call_axis(self, id_sort, LONG2NUM(axis)), id_copy, 0);
|
|
700
696
|
VALUE result = rb_ary_new_capa(npers);
|
|
701
697
|
for ( long i = 0; i < npers; i++ ) {
|
|
702
698
|
double p = NUM2DBL(rb_ary_entry(pers, i));
|
|
703
699
|
rb_ary_push(result, pct_object_one_sorted(sorted, axis, n, p, method));
|
|
704
700
|
}
|
|
705
|
-
RB_GC_GUARD(sorted);
|
|
706
701
|
return result;
|
|
707
702
|
}
|
|
708
703
|
|
|
@@ -713,7 +708,7 @@ percentile_object_axis (VALUE self, VALUE pers, long axis, VALUE method)
|
|
|
713
708
|
0 (or < min_count) yields an UNDEF cell (fill_value when given); the mask
|
|
714
709
|
is created lazily, matching the numeric lane. */
|
|
715
710
|
static VALUE
|
|
716
|
-
pct_object_axis_masked_one (VALUE self, VALUE sorted, long axis, double p,
|
|
711
|
+
pct_object_axis_masked_one (VALUE self, volatile VALUE sorted, long axis, double p,
|
|
717
712
|
VALUE method, long OUTER, long M, long INNER,
|
|
718
713
|
const boolean8_t *sm, long min_count,
|
|
719
714
|
VALUE fill_value, int keep_axis)
|
|
@@ -721,7 +716,7 @@ pct_object_axis_masked_one (VALUE self, VALUE sorted, long axis, double p,
|
|
|
721
716
|
int8_t ax = (int8_t) axis;
|
|
722
717
|
/* `sorted` is an entity of self's shape (the storage, when self is a
|
|
723
718
|
Face); the answer is built on it and lifted back by the caller. */
|
|
724
|
-
VALUE out = rb_ca_new_reduced(sorted, &ax, 1, CA_OBJECT, keep_axis);
|
|
719
|
+
volatile VALUE out = rb_ca_new_reduced(sorted, &ax, 1, CA_OBJECT, keep_axis);
|
|
725
720
|
CArray *co;
|
|
726
721
|
GetCArray(out, co);
|
|
727
722
|
CArray *cs;
|
|
@@ -768,7 +763,7 @@ pct_object_axis_masked_one (VALUE self, VALUE sorted, long axis, double p,
|
|
|
768
763
|
material, then each p is a per-fiber select. Returns an Array of reduced
|
|
769
764
|
CA_OBJECT CArrays, one per p. */
|
|
770
765
|
static VALUE
|
|
771
|
-
percentile_object_axis_masked (VALUE self, VALUE pers, long axis, VALUE method,
|
|
766
|
+
percentile_object_axis_masked (volatile VALUE self, VALUE pers, long axis, VALUE method,
|
|
772
767
|
long min_count, VALUE fill_value, int keep_axis)
|
|
773
768
|
{
|
|
774
769
|
CArray *ca;
|
|
@@ -785,7 +780,7 @@ percentile_object_axis_masked (VALUE self, VALUE pers, long axis, VALUE method,
|
|
|
785
780
|
|
|
786
781
|
/* A Face (a string array) is sorted as itself and read through its
|
|
787
782
|
storage, whose cells are the values. */
|
|
788
|
-
VALUE sorted = rb_funcall(obj_call_axis(self, id_sort, LONG2NUM(axis)), id_copy, 0);
|
|
783
|
+
volatile VALUE sorted = rb_funcall(obj_call_axis(self, id_sort, LONG2NUM(axis)), id_copy, 0);
|
|
789
784
|
int is_face = ca_is_face(ca);
|
|
790
785
|
if ( is_face ) sorted = rb_ca_strip_face_value(sorted);
|
|
791
786
|
CArray *cs;
|
|
@@ -803,7 +798,6 @@ percentile_object_axis_masked (VALUE self, VALUE pers, long axis, VALUE method,
|
|
|
803
798
|
fill_value, keep_axis);
|
|
804
799
|
rb_ary_push(result, is_face ? ca_face_relift_entity(self, one) : one);
|
|
805
800
|
}
|
|
806
|
-
RB_GC_GUARD(sorted);
|
|
807
801
|
return result;
|
|
808
802
|
}
|
|
809
803
|
|
|
@@ -821,11 +815,11 @@ median_object_axis_masked (VALUE self, long axis, long min_count,
|
|
|
821
815
|
|
|
822
816
|
/* [object] flat percentile: mask-strip / min_count, flatten, axis-0. */
|
|
823
817
|
static VALUE
|
|
824
|
-
percentile_object_flat (VALUE self, VALUE pers, long min_count, VALUE fill_value,
|
|
818
|
+
percentile_object_flat (volatile VALUE self, VALUE pers, long min_count, VALUE fill_value,
|
|
825
819
|
VALUE method)
|
|
826
820
|
{
|
|
827
821
|
long npers = RARRAY_LEN(pers);
|
|
828
|
-
VALUE src = self;
|
|
822
|
+
volatile VALUE src = self;
|
|
829
823
|
int filled = 0;
|
|
830
824
|
if ( RTEST(rb_ca_has_mask(self)) ) {
|
|
831
825
|
CArray *mc; GetCArray(self, mc);
|
|
@@ -844,9 +838,8 @@ percentile_object_flat (VALUE self, VALUE pers, long min_count, VALUE fill_value
|
|
|
844
838
|
for ( long i = 0; i < npers; i++ ) rb_ary_push(result, fill);
|
|
845
839
|
return result;
|
|
846
840
|
}
|
|
847
|
-
VALUE flat = rb_ca_flatten(src);
|
|
841
|
+
volatile VALUE flat = rb_ca_flatten(src);
|
|
848
842
|
VALUE r = percentile_object_axis(flat, pers, 0, method);
|
|
849
|
-
RB_GC_GUARD(flat);
|
|
850
843
|
return r;
|
|
851
844
|
}
|
|
852
845
|
|
|
@@ -857,14 +850,14 @@ static VALUE median_axis_masked (VALUE self, long axis, long min_count,
|
|
|
857
850
|
/* [entry] median(axis:, min_count:, fill_value:, keep_axis:). Dispatches
|
|
858
851
|
fixlen -> reject, object -> object lane, numeric -> numeric lane. */
|
|
859
852
|
static VALUE
|
|
860
|
-
rb_ca_median_m_body (int argc, VALUE *argv, VALUE self)
|
|
853
|
+
rb_ca_median_m_body (int argc, VALUE *argv, volatile VALUE self)
|
|
861
854
|
{
|
|
862
855
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
863
856
|
VALUE raxis = Qnil, rmin_count = INT2FIX(0), fill_value = Qnil, rkeep = Qfalse;
|
|
864
857
|
rb_scan_options(ropt, "axis,min_count,fill_value,keep_axis",
|
|
865
858
|
&raxis, &rmin_count, &fill_value, &rkeep);
|
|
866
859
|
if ( argc != 0 )
|
|
867
|
-
rb_raise(rb_eArgError, "median: no positional
|
|
860
|
+
rb_raise(rb_eArgError, "median: takes no positional arguments (given %d); give the axis as a keyword, e.g. a.median(axis: 0)", argc);
|
|
868
861
|
|
|
869
862
|
CArray *ca;
|
|
870
863
|
GetCArray(self, ca);
|
|
@@ -904,12 +897,14 @@ rb_ca_median_m_body (int argc, VALUE *argv, VALUE self)
|
|
|
904
897
|
else if ( ! NIL_P(fill_value) && ! is_obj ) {
|
|
905
898
|
fill_value = ca_fill_as(fill_value, CA_FLOAT64);
|
|
906
899
|
}
|
|
907
|
-
int keep_axis =
|
|
900
|
+
int keep_axis = ca_bool_arg(rkeep, "keep_axis");
|
|
908
901
|
|
|
909
902
|
if ( !NIL_P(raxis) ) {
|
|
910
903
|
long axis = rb_ca_normalize_axis_value(self, raxis, "median");
|
|
911
904
|
long n = (long) ca->dim[axis];
|
|
912
|
-
if ( n == 0 )
|
|
905
|
+
if ( n == 0 )
|
|
906
|
+
return mp_axis_answer(self, mp_axis_all_masked(self, axis, fill_value, keep_axis),
|
|
907
|
+
keep_axis);
|
|
913
908
|
/* mask / min_count / fill_value require the per-fiber select (each fiber
|
|
914
909
|
has its own n_present); the plain partition path assumes a uniform n.
|
|
915
910
|
Switch ca_fast_path(CA_SC_MEDIAN_PARTITION): off, the per-fiber select. */
|
|
@@ -924,10 +919,14 @@ rb_ca_median_m_body (int argc, VALUE *argv, VALUE self)
|
|
|
924
919
|
: median_axis(self, axis, n, keep_axis);
|
|
925
920
|
return mp_axis_answer(self, res, keep_axis);
|
|
926
921
|
}
|
|
927
|
-
/* self may be the float64 view made above, read through its CArray
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
922
|
+
/* self may be the float64 view made above, read through its CArray:
|
|
923
|
+
received in a volatile variable, so that self is kept past the call */
|
|
924
|
+
{
|
|
925
|
+
volatile VALUE answer =
|
|
926
|
+
is_obj ? median_object_flat(self, min_count, fill_value, keep_axis)
|
|
927
|
+
: median_flat(self, min_count, fill_value, keep_axis);
|
|
928
|
+
return answer;
|
|
929
|
+
}
|
|
931
930
|
}
|
|
932
931
|
|
|
933
932
|
/* =====================================================================
|
|
@@ -1049,7 +1048,7 @@ pct_fill_masked (CArray *co, int8_t dt, const char *base, const boolean8_t *sm,
|
|
|
1049
1048
|
|
|
1050
1049
|
/* [numeric] single p via one partition_copy -> reduced CA_FLOAT64. */
|
|
1051
1050
|
static VALUE
|
|
1052
|
-
pct_axis_one_partition (VALUE self, long axis, long n, double p,
|
|
1051
|
+
pct_axis_one_partition (volatile VALUE self, long axis, long n, double p,
|
|
1053
1052
|
VALUE method, int keep_axis)
|
|
1054
1053
|
{
|
|
1055
1054
|
CArray *ca;
|
|
@@ -1068,19 +1067,18 @@ pct_axis_one_partition (VALUE self, long axis, long n, double p,
|
|
|
1068
1067
|
keep one partition correct, partition at the index we actually read:
|
|
1069
1068
|
if UPPER_ONLY we need sorted[k+1] -> partition at k, min-upper gives
|
|
1070
1069
|
it. pct_fill handles that via from_sorted==0. */
|
|
1071
|
-
VALUE pp = rb_ca_partition_copy_c(self, LONG2NUM(k), LONG2NUM(axis));
|
|
1070
|
+
volatile VALUE pp = rb_ca_partition_copy_c(self, LONG2NUM(k), LONG2NUM(axis));
|
|
1072
1071
|
CArray *cp;
|
|
1073
1072
|
GetCArray(pp, cp);
|
|
1074
1073
|
|
|
1075
1074
|
int8_t ax = (int8_t) axis;
|
|
1076
|
-
VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1075
|
+
volatile VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1077
1076
|
CArray *co;
|
|
1078
1077
|
GetCArray(out, co);
|
|
1079
1078
|
long OUTER, M, INNER;
|
|
1080
1079
|
mp_geometry(ca, axis, &OUTER, &M, &INNER);
|
|
1081
1080
|
pct_fill((double *) co->ptr, dt, (const char *) cp->ptr, 0,
|
|
1082
1081
|
OUTER, M, INNER, n, k, r, method, need);
|
|
1083
|
-
RB_GC_GUARD(pp);
|
|
1084
1082
|
return out;
|
|
1085
1083
|
}
|
|
1086
1084
|
|
|
@@ -1088,7 +1086,7 @@ pct_axis_one_partition (VALUE self, long axis, long n, double p,
|
|
|
1088
1086
|
sort_copy funcall is the only Ruby-surface call left on this lane; it
|
|
1089
1087
|
could be replaced by a C-callable sort_copy twin like partition_copy_c.) */
|
|
1090
1088
|
static VALUE
|
|
1091
|
-
pct_axis_multi (VALUE self, VALUE pers_ary, long axis, long n,
|
|
1089
|
+
pct_axis_multi (volatile VALUE self, VALUE pers_ary, long axis, long n,
|
|
1092
1090
|
VALUE method, int keep_axis)
|
|
1093
1091
|
{
|
|
1094
1092
|
CArray *ca;
|
|
@@ -1101,7 +1099,7 @@ pct_axis_multi (VALUE self, VALUE pers_ary, long axis, long n,
|
|
|
1101
1099
|
VALUE kw = rb_hash_new();
|
|
1102
1100
|
rb_hash_aset(kw, ID2SYM(id_axis), LONG2NUM(axis));
|
|
1103
1101
|
VALUE sc_argv[1] = { kw };
|
|
1104
|
-
VALUE sorted = rb_funcallv_kw(self, id_sort_copy, 1, sc_argv, RB_PASS_KEYWORDS);
|
|
1102
|
+
volatile VALUE sorted = rb_funcallv_kw(self, id_sort_copy, 1, sc_argv, RB_PASS_KEYWORDS);
|
|
1105
1103
|
CArray *cs;
|
|
1106
1104
|
GetCArray(sorted, cs);
|
|
1107
1105
|
|
|
@@ -1119,20 +1117,19 @@ pct_axis_multi (VALUE self, VALUE pers_ary, long axis, long n,
|
|
|
1119
1117
|
pct_need_t need = pct_need(method, k, r, n);
|
|
1120
1118
|
|
|
1121
1119
|
int8_t ax = (int8_t) axis;
|
|
1122
|
-
VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1120
|
+
volatile VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1123
1121
|
CArray *co;
|
|
1124
1122
|
GetCArray(out, co);
|
|
1125
1123
|
pct_fill((double *) co->ptr, dt, (const char *) cs->ptr, 1,
|
|
1126
1124
|
OUTER, M, INNER, n, k, r, method, need);
|
|
1127
1125
|
rb_ary_push(result, out);
|
|
1128
1126
|
}
|
|
1129
|
-
RB_GC_GUARD(sorted);
|
|
1130
1127
|
return result;
|
|
1131
1128
|
}
|
|
1132
1129
|
|
|
1133
1130
|
/* [numeric] per-axis percentile: 1 p -> partition, many p -> shared sort. */
|
|
1134
1131
|
static VALUE
|
|
1135
|
-
pct_axis (VALUE self, VALUE pers_ary, long axis, VALUE method, int keep_axis)
|
|
1132
|
+
pct_axis (volatile VALUE self, VALUE pers_ary, long axis, VALUE method, int keep_axis)
|
|
1136
1133
|
{
|
|
1137
1134
|
CArray *ca;
|
|
1138
1135
|
GetCArray(self, ca);
|
|
@@ -1160,7 +1157,7 @@ pct_axis (VALUE self, VALUE pers_ary, long axis, VALUE method, int keep_axis)
|
|
|
1160
1157
|
material, then each p is a per-fiber select honouring that fiber's own
|
|
1161
1158
|
n_present. Returns an Array of reduced CA_FLOAT64 CArrays, one per p. */
|
|
1162
1159
|
static VALUE
|
|
1163
|
-
pct_axis_masked (VALUE self, VALUE pers_ary, long axis, VALUE method,
|
|
1160
|
+
pct_axis_masked (volatile VALUE self, VALUE pers_ary, long axis, VALUE method,
|
|
1164
1161
|
long min_count, VALUE fill_value, int keep_axis)
|
|
1165
1162
|
{
|
|
1166
1163
|
CArray *ca;
|
|
@@ -1180,7 +1177,7 @@ pct_axis_masked (VALUE self, VALUE pers_ary, long axis, VALUE method,
|
|
|
1180
1177
|
VALUE kw = rb_hash_new();
|
|
1181
1178
|
rb_hash_aset(kw, ID2SYM(id_axis), LONG2NUM(axis));
|
|
1182
1179
|
VALUE sc_argv[1] = { kw };
|
|
1183
|
-
VALUE sorted = rb_funcallv_kw(self, id_sort_copy, 1, sc_argv, RB_PASS_KEYWORDS);
|
|
1180
|
+
volatile VALUE sorted = rb_funcallv_kw(self, id_sort_copy, 1, sc_argv, RB_PASS_KEYWORDS);
|
|
1184
1181
|
CArray *cs;
|
|
1185
1182
|
GetCArray(sorted, cs);
|
|
1186
1183
|
const boolean8_t *sm = cs->mask ? (const boolean8_t *) cs->mask->ptr : NULL;
|
|
@@ -1194,14 +1191,13 @@ pct_axis_masked (VALUE self, VALUE pers_ary, long axis, VALUE method,
|
|
|
1194
1191
|
for ( long i = 0; i < npers; i++ ) {
|
|
1195
1192
|
double p = NUM2DBL(rb_ary_entry(pers_ary, i));
|
|
1196
1193
|
int8_t ax = (int8_t) axis;
|
|
1197
|
-
VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1194
|
+
volatile VALUE out = rb_ca_new_reduced(self, &ax, 1, CA_FLOAT64, keep_axis);
|
|
1198
1195
|
CArray *co;
|
|
1199
1196
|
GetCArray(out, co);
|
|
1200
1197
|
pct_fill_masked(co, dt, (const char *) cs->ptr, sm,
|
|
1201
1198
|
OUTER, MM, INNER, p, method, min_count, is_undef, fillv);
|
|
1202
1199
|
rb_ary_push(result, out);
|
|
1203
1200
|
}
|
|
1204
|
-
RB_GC_GUARD(sorted);
|
|
1205
1201
|
return result;
|
|
1206
1202
|
}
|
|
1207
1203
|
|
|
@@ -1221,11 +1217,11 @@ median_axis_masked (VALUE self, long axis, long min_count, VALUE fill_value,
|
|
|
1221
1217
|
/* [numeric] flat percentile -> array of scalars (or keep_axis [1..1]
|
|
1222
1218
|
entities), one per requested p. */
|
|
1223
1219
|
static VALUE
|
|
1224
|
-
pct_flat (VALUE self, VALUE pers_ary, long min_count, VALUE fill_value,
|
|
1220
|
+
pct_flat (volatile VALUE self, VALUE pers_ary, long min_count, VALUE fill_value,
|
|
1225
1221
|
VALUE method, int keep_axis)
|
|
1226
1222
|
{
|
|
1227
1223
|
long npers = RARRAY_LEN(pers_ary);
|
|
1228
|
-
VALUE src = self;
|
|
1224
|
+
volatile VALUE src = self;
|
|
1229
1225
|
int masked_out = 0, is_undef = 0;
|
|
1230
1226
|
double fillv = 0.0;
|
|
1231
1227
|
|
|
@@ -1261,7 +1257,7 @@ pct_flat (VALUE self, VALUE pers_ary, long min_count, VALUE fill_value,
|
|
|
1261
1257
|
}
|
|
1262
1258
|
|
|
1263
1259
|
/* flatten -> 1-D, reduce on axis 0, extract op[0] per p. */
|
|
1264
|
-
VALUE flat = rb_ca_flatten(src);
|
|
1260
|
+
volatile VALUE flat = rb_ca_flatten(src);
|
|
1265
1261
|
VALUE per_axis = pct_axis(flat, pers_ary, 0, method, 0); /* array of [1] CArrays */
|
|
1266
1262
|
for ( long i = 0; i < npers; i++ ) {
|
|
1267
1263
|
CArray *r1;
|
|
@@ -1270,21 +1266,21 @@ pct_flat (VALUE self, VALUE pers_ary, long min_count, VALUE fill_value,
|
|
|
1270
1266
|
VALUE out = keep_axis ? mp_keep_axis_full_f64(self, v, 0) : rb_float_new(v);
|
|
1271
1267
|
rb_ary_push(result, out);
|
|
1272
1268
|
}
|
|
1273
|
-
RB_GC_GUARD(flat);
|
|
1274
1269
|
return result;
|
|
1275
1270
|
}
|
|
1276
1271
|
|
|
1277
|
-
/* [shared]
|
|
1278
|
-
|
|
1272
|
+
/* [shared] read the p arguments. The form the caller wrote p in decides
|
|
1273
|
+
the form of the answer; the private class methods CArray.percentile_arguments
|
|
1274
|
+
and CArray.percentile_answer (Ruby) hold that rule for the core and the
|
|
1275
|
+
iterators alike. Returns the p values as a flat
|
|
1276
|
+
Array and sets *form. Each p must be Numeric in [0,100]. */
|
|
1279
1277
|
static VALUE
|
|
1280
|
-
|
|
1278
|
+
pct_read_pers (int argc, VALUE *argv, VALUE *form)
|
|
1281
1279
|
{
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
pers = rb_funcall(first, rb_intern("to_a"), 0);
|
|
1287
|
-
}
|
|
1280
|
+
VALUE read = rb_funcall(rb_cCArray, rb_intern("percentile_arguments"), 1,
|
|
1281
|
+
rb_ary_new_from_values(argc, argv));
|
|
1282
|
+
VALUE pers = rb_ary_entry(read, 0);
|
|
1283
|
+
*form = rb_ary_entry(read, 1);
|
|
1288
1284
|
long len = RARRAY_LEN(pers);
|
|
1289
1285
|
if ( len == 0 )
|
|
1290
1286
|
rb_raise(rb_eArgError, "percentile: at least one p value required");
|
|
@@ -1301,11 +1297,11 @@ pct_flatten_validate_pers (VALUE pers)
|
|
|
1301
1297
|
return pers;
|
|
1302
1298
|
}
|
|
1303
1299
|
|
|
1304
|
-
/* [entry] percentile(
|
|
1300
|
+
/* [entry] percentile(p, axis:, min_count:, fill_value:, method:,
|
|
1305
1301
|
keep_axis:). Dispatches fixlen -> reject, object -> object lane,
|
|
1306
1302
|
numeric -> numeric lane. */
|
|
1307
1303
|
static VALUE
|
|
1308
|
-
rb_ca_percentile_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
1304
|
+
rb_ca_percentile_kw (int argc, VALUE *argv, VALUE ropt, volatile VALUE self)
|
|
1309
1305
|
{
|
|
1310
1306
|
VALUE raxis = Qnil, rmin_count = INT2FIX(0), fill_value = Qnil,
|
|
1311
1307
|
method = sym_linear, rkeep = Qfalse;
|
|
@@ -1349,21 +1345,19 @@ rb_ca_percentile_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
1349
1345
|
fill_value = ca_fill_as(fill_value, CA_FLOAT64);
|
|
1350
1346
|
}
|
|
1351
1347
|
|
|
1352
|
-
VALUE
|
|
1348
|
+
VALUE form;
|
|
1349
|
+
VALUE pers = pct_read_pers(argc, argv, &form);
|
|
1353
1350
|
pct_validate_method(method);
|
|
1354
|
-
int keep_axis =
|
|
1355
|
-
int single_p = (RARRAY_LEN(pers) == 1);
|
|
1351
|
+
int keep_axis = ca_bool_arg(rkeep, "keep_axis");
|
|
1356
1352
|
|
|
1357
1353
|
/* numeric lane bakes keep_axis into the reduced output; object lane
|
|
1358
1354
|
returns unwrapped results and is keep-wrapped here (insert_axis for
|
|
1359
1355
|
the per-axis form, obj_keep_axis_full for the flat form) -- matching
|
|
1360
1356
|
production's structure for arbitrary-object results.
|
|
1361
1357
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
flattened first and follows the same rule (length 1 unwraps). */
|
|
1366
|
-
VALUE result;
|
|
1358
|
+
The lanes answer an Array with one answer per p; the form the caller
|
|
1359
|
+
wrote p in decides what is returned (CArray.percentile_answer). */
|
|
1360
|
+
volatile VALUE result;
|
|
1367
1361
|
if ( !NIL_P(raxis) ) {
|
|
1368
1362
|
long axis = rb_ca_normalize_axis_value(self, raxis, NULL);
|
|
1369
1363
|
/* mask / min_count / fill_value require the per-fiber select (each fiber
|
|
@@ -1408,10 +1402,12 @@ rb_ca_percentile_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
1408
1402
|
}
|
|
1409
1403
|
}
|
|
1410
1404
|
/* self may be the float64 view made above, read through its CArray */
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1405
|
+
{
|
|
1406
|
+
VALUE dt = ID2SYM(rb_intern(is_obj ? "object" : "float64"));
|
|
1407
|
+
VALUE answer = rb_funcall(rb_cCArray, rb_intern("percentile_answer"), 3,
|
|
1408
|
+
result, form, dt);
|
|
1409
|
+
return answer;
|
|
1410
|
+
}
|
|
1415
1411
|
}
|
|
1416
1412
|
|
|
1417
1413
|
static VALUE
|
|
@@ -1421,22 +1417,27 @@ rb_ca_percentile_m_body (int argc, VALUE *argv, VALUE self)
|
|
|
1421
1417
|
return rb_ca_percentile_kw(argc, argv, ropt, self);
|
|
1422
1418
|
}
|
|
1423
1419
|
|
|
1424
|
-
/* [entry] quantile(axis:, keep_axis:) =
|
|
1425
|
-
|
|
1426
|
-
|
|
1420
|
+
/* [entry] quantile(axis:, keep_axis:, min_count:, fill_value:) =
|
|
1421
|
+
percentile([0, 25, 50, 75, 100], ...), with the same keywords.
|
|
1422
|
+
The five p values go in as one Array, so the answer is an Array of five:
|
|
1423
|
+
Floats (flat) or CArrays (per-axis). */
|
|
1427
1424
|
static VALUE
|
|
1428
1425
|
rb_ca_quantile_m_body (int argc, VALUE *argv, VALUE self)
|
|
1429
1426
|
{
|
|
1430
1427
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1431
1428
|
if ( argc != 0 )
|
|
1432
|
-
rb_raise(rb_eArgError, "quantile: no positional
|
|
1433
|
-
VALUE raxis = Qnil, rkeep = Qfalse;
|
|
1434
|
-
rb_scan_options(ropt, "axis,keep_axis",
|
|
1429
|
+
rb_raise(rb_eArgError, "quantile: takes no positional arguments (got %d); for the value at p percent, use percentile(p)", argc);
|
|
1430
|
+
VALUE raxis = Qnil, rkeep = Qfalse, rmin = Qnil, rfill = Qnil;
|
|
1431
|
+
rb_scan_options(ropt, "axis,keep_axis,min_count,fill_value",
|
|
1432
|
+
&raxis, &rkeep, &rmin, &rfill);
|
|
1435
1433
|
VALUE opts = rb_hash_new();
|
|
1436
1434
|
if ( !NIL_P(raxis) ) rb_hash_aset(opts, ID2SYM(rb_intern("axis")), raxis);
|
|
1437
1435
|
rb_hash_aset(opts, ID2SYM(rb_intern("keep_axis")), rkeep);
|
|
1438
|
-
|
|
1439
|
-
|
|
1436
|
+
if ( !NIL_P(rmin) ) rb_hash_aset(opts, ID2SYM(rb_intern("min_count")), rmin);
|
|
1437
|
+
if ( !NIL_P(rfill) ) rb_hash_aset(opts, ID2SYM(rb_intern("fill_value")), rfill);
|
|
1438
|
+
VALUE pa[1] = { rb_ary_new_from_args(5, INT2FIX(0), INT2FIX(25), INT2FIX(50),
|
|
1439
|
+
INT2FIX(75), INT2FIX(100)) };
|
|
1440
|
+
return rb_ca_percentile_kw(1, pa, opts, self);
|
|
1440
1441
|
}
|
|
1441
1442
|
|
|
1442
1443
|
|