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_order.c
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#include "ruby.h"
|
|
2
2
|
#include "carray.h"
|
|
3
|
-
#include "carray_internal.h" /* ca_integer_arg */
|
|
4
3
|
#include "ca_kernel_iterator.h"
|
|
5
4
|
#include "ca_obj_face.h"
|
|
6
5
|
#include <math.h>
|
|
@@ -9,7 +8,7 @@
|
|
|
9
8
|
|
|
10
9
|
/* Interned IDs used by the dispatchers below. rb_funcall is retained
|
|
11
10
|
* only where there is no clean C entry: `-` (operator dispatch in
|
|
12
|
-
*
|
|
11
|
+
* rb_ca_rank_index handles Integer vs CArray uniformly via method dispatch)
|
|
13
12
|
* and Symbol tag comparison for `method:` kwarg. */
|
|
14
13
|
static ID id_axis, id_sub,
|
|
15
14
|
id_sym_binary, id_sym_linear;
|
|
@@ -128,7 +127,7 @@ ca_project (CArray *ca, CArray *ci, char *lfill, char *ufill)
|
|
|
128
127
|
obj = rb_carray_new(ca->data_type, ci->ndim, ci->dim, ca->bytes, NULL);
|
|
129
128
|
GetCArray(obj, co);
|
|
130
129
|
|
|
131
|
-
ca_attach_n(2, ca, ci); /*
|
|
130
|
+
ca_attach_n(2, ca, ci); /* attach: nothing raises before the detach */
|
|
132
131
|
ca_project_loop(co, ca, ci, lfill, ufill);
|
|
133
132
|
ca_detach_n(2, ca, ci); /* DETACH */
|
|
134
133
|
|
|
@@ -169,7 +168,7 @@ ca_project (CArray *ca, CArray *ci, char *lfill, char *ufill)
|
|
|
169
168
|
else CA_COUNT_BELOW_LOOP(T, <)
|
|
170
169
|
|
|
171
170
|
static VALUE
|
|
172
|
-
rb_ca_count_below (VALUE self, VALUE vq, VALUE vinclusive)
|
|
171
|
+
rb_ca_count_below (volatile VALUE self, volatile VALUE vq, VALUE vinclusive)
|
|
173
172
|
{
|
|
174
173
|
volatile VALUE vout;
|
|
175
174
|
CArray *cr, *cq, *co;
|
|
@@ -203,7 +202,7 @@ rb_ca_count_below (VALUE self, VALUE vq, VALUE vinclusive)
|
|
|
203
202
|
GetCArray(vout, co);
|
|
204
203
|
out = (int64_t *) co->ptr;
|
|
205
204
|
|
|
206
|
-
ca_attach_n(2, cr, cq); /*
|
|
205
|
+
ca_attach_n(2, cr, cq); /* attach: nothing raises before the detach */
|
|
207
206
|
switch ( cr->data_type ) {
|
|
208
207
|
case CA_BOOLEAN:
|
|
209
208
|
case CA_UINT8: CA_COUNT_BELOW(uint8_t); break;
|
|
@@ -225,32 +224,35 @@ rb_ca_count_below (VALUE self, VALUE vq, VALUE vinclusive)
|
|
|
225
224
|
#undef CA_COUNT_BELOW
|
|
226
225
|
#undef CA_COUNT_BELOW_LOOP
|
|
227
226
|
|
|
228
|
-
/* project(idx,
|
|
229
|
-
* pick `self[idx[i]]`. Returns an entity CArray shaped
|
|
227
|
+
/* project(idx, fill_value: nil, lfill: nil, ufill: nil) — gather: for each
|
|
228
|
+
* element of `idx`, pick `self[idx[i]]`. Returns an entity CArray shaped
|
|
229
|
+
* like `idx`.
|
|
230
230
|
*
|
|
231
231
|
* Out-of-range index handling: negative or >= self.elements indices
|
|
232
|
-
* produce `
|
|
233
|
-
* the output cell. Masked inputs (`idx` mask or `self` mask) also
|
|
232
|
+
* produce `lfill` (lower) / `ufill` (upper), each defaulting to
|
|
233
|
+
* `fill_value`, otherwise mask the output cell. Masked inputs (`idx` mask or `self` mask) also
|
|
234
234
|
* propagate as masked output.
|
|
235
235
|
*/
|
|
236
236
|
VALUE
|
|
237
|
-
rb_ca_project (int argc, VALUE *argv, VALUE self)
|
|
237
|
+
rb_ca_project (int argc, VALUE *argv, volatile VALUE self)
|
|
238
238
|
{
|
|
239
|
-
volatile VALUE obj
|
|
239
|
+
volatile VALUE obj;
|
|
240
|
+
VALUE ridx;
|
|
241
|
+
volatile VALUE vlfval, vufval, vstorage;
|
|
240
242
|
volatile VALUE hlfval = 0, hufval = 0;
|
|
241
243
|
CArray *ca, *ci, *co;
|
|
242
244
|
char *lfval, *ufval;
|
|
243
245
|
int self_is_face;
|
|
244
246
|
|
|
245
247
|
{
|
|
246
|
-
VALUE ropt = Qnil;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
VALUE ropt = Qnil, vfill = Qnil, vl = Qnil, vu = Qnil;
|
|
249
|
+
rb_scan_args(argc, argv, "1:", &ridx, &ropt);
|
|
250
|
+
rb_scan_options(ropt, "fill_value,lfill,ufill", &vfill, &vl, &vu);
|
|
251
|
+
vlfval = NIL_P(vl) ? vfill : vl;
|
|
252
|
+
vufval = NIL_P(vu) ? vfill : vu;
|
|
251
253
|
}
|
|
252
254
|
|
|
253
|
-
|
|
255
|
+
GetCArray(self, ca);
|
|
254
256
|
self_is_face = ca_is_face(ca);
|
|
255
257
|
|
|
256
258
|
rb_check_carray_object(ridx);
|
|
@@ -266,7 +268,6 @@ rb_ca_project (int argc, VALUE *argv, VALUE self)
|
|
|
266
268
|
|
|
267
269
|
if ( ! NIL_P(vlfval) && vlfval != CA_UNDEF ) {
|
|
268
270
|
rb_ca_obj2ptr(self, vlfval, lfval);
|
|
269
|
-
rb_ca_obj2ptr(self, vlfval, ufval);
|
|
270
271
|
}
|
|
271
272
|
|
|
272
273
|
if ( ! NIL_P(vufval) && vufval != CA_UNDEF ) {
|
|
@@ -281,13 +282,13 @@ rb_ca_project (int argc, VALUE *argv, VALUE self)
|
|
|
281
282
|
vstorage = self;
|
|
282
283
|
if ( self_is_face ) {
|
|
283
284
|
vstorage = rb_ca_strip_face_value(self);
|
|
284
|
-
|
|
285
|
+
GetCArray(vstorage, ca);
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
/* A fill of UNDEF is no fill: the cell is masked, as it is with none. */
|
|
288
289
|
{
|
|
289
290
|
VALUE vlower = vlfval;
|
|
290
|
-
VALUE vupper =
|
|
291
|
+
VALUE vupper = vufval;
|
|
291
292
|
obj = ca_project(ca, ci,
|
|
292
293
|
( NIL_P(vlower) || vlower == CA_UNDEF ) ? NULL : lfval,
|
|
293
294
|
( NIL_P(vupper) || vupper == CA_UNDEF ) ? NULL : ufval);
|
|
@@ -387,7 +388,7 @@ extern VALUE rb_ca_rank_index_ki_kind_dense (VALUE self, VALUE vaxis, int stable
|
|
|
387
388
|
* search_kw / search_nearest_kw and their _addr siblings) on the
|
|
388
389
|
* no-axis path. */
|
|
389
390
|
static VALUE
|
|
390
|
-
ca_reshape_search_result (VALUE query, VALUE rraw)
|
|
391
|
+
ca_reshape_search_result (volatile VALUE query, VALUE rraw)
|
|
391
392
|
{
|
|
392
393
|
CArray *cq;
|
|
393
394
|
GetCArray(query, cq);
|
|
@@ -405,6 +406,27 @@ ca_reshape_search_result (VALUE query, VALUE rraw)
|
|
|
405
406
|
return rb_ca_reshape((int) cq->ndim, shape_argv, rraw);
|
|
406
407
|
}
|
|
407
408
|
|
|
409
|
+
/* A Complex with an imaginary part has no place in the order of a real
|
|
410
|
+
array, so bsearch and search_nearest refuse it (search, which asks for
|
|
411
|
+
equal cells, finds none). */
|
|
412
|
+
static void
|
|
413
|
+
ca_refuse_unordered_query (volatile VALUE self, VALUE query)
|
|
414
|
+
{
|
|
415
|
+
CArray *ca;
|
|
416
|
+
if ( ! RB_TYPE_P(query, T_COMPLEX) || ! rb_obj_is_carray(self) ) {
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
GetCArray(self, ca);
|
|
420
|
+
if ( ca_is_face(ca) || ! ( ca_is_integer_type(ca) || ca_is_float_type(ca) ) ||
|
|
421
|
+
RTEST(rb_equal(rb_complex_imag(query), INT2FIX(0))) ) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
rb_raise(rb_eTypeError, "%s: %" PRIsVALUE " has no place in the order of %s %s array",
|
|
425
|
+
ca_calling_method_name(), rb_inspect(query),
|
|
426
|
+
( ca_type_name[ca->data_type][0] == 'i' ) ? "an" : "a",
|
|
427
|
+
ca_type_name[ca->data_type]);
|
|
428
|
+
}
|
|
429
|
+
|
|
408
430
|
static VALUE
|
|
409
431
|
rb_ca_bsearch_kw (int argc, VALUE *argv, VALUE self)
|
|
410
432
|
{
|
|
@@ -412,6 +434,7 @@ rb_ca_bsearch_kw (int argc, VALUE *argv, VALUE self)
|
|
|
412
434
|
VALUE raxis = Qnil;
|
|
413
435
|
rb_scan_options(ropt, "axis", &raxis);
|
|
414
436
|
rb_check_arity(argc, 1, 1);
|
|
437
|
+
ca_refuse_unordered_query(self, argv[0]);
|
|
415
438
|
|
|
416
439
|
if ( NIL_P(raxis) ) {
|
|
417
440
|
VALUE flat = rb_ca_flatten(self);
|
|
@@ -429,6 +452,7 @@ rb_ca_bsearch_addr_kw (int argc, VALUE *argv, VALUE self)
|
|
|
429
452
|
VALUE raxis = Qnil;
|
|
430
453
|
rb_scan_options(ropt, "axis", &raxis);
|
|
431
454
|
rb_check_arity(argc, 1, 1);
|
|
455
|
+
ca_refuse_unordered_query(self, argv[0]);
|
|
432
456
|
|
|
433
457
|
if ( NIL_P(raxis) ) {
|
|
434
458
|
/* 1-D self: view-flat addr == axis-local index, so the no-axis
|
|
@@ -441,30 +465,54 @@ rb_ca_bsearch_addr_kw (int argc, VALUE *argv, VALUE self)
|
|
|
441
465
|
return rb_ca_bsearch_addr_ki(self, argv[0], raxis);
|
|
442
466
|
}
|
|
443
467
|
|
|
468
|
+
/* The query of search as the array reads it. true and false are 1 and 0
|
|
469
|
+
to a numeric array. A value the array can not hold (nil, a String)
|
|
470
|
+
finds nothing, as an Integer outside the array's type does. The query is asked of the
|
|
471
|
+
cells that matched (none), in the type that holds the answer. A Face that
|
|
472
|
+
can not be searched is refused as for any query. */
|
|
473
|
+
static void
|
|
474
|
+
ca_search_query_read (volatile VALUE *pself, volatile VALUE *pquery)
|
|
475
|
+
{
|
|
476
|
+
CArray *ca;
|
|
477
|
+
GetCArray(*pself, ca);
|
|
478
|
+
*pquery = ca_truth_as_number(ca, *pquery);
|
|
479
|
+
if ( ! ca_query_matches_nothing(*pself, ca, *pquery) ) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if ( ca_is_face(ca) ) {
|
|
483
|
+
ca_face_require_orderable(*pself, "search", "search");
|
|
484
|
+
}
|
|
485
|
+
*pself = rb_funcall(*pself, rb_intern("eq"), 1, *pquery);
|
|
486
|
+
*pquery = Qtrue;
|
|
487
|
+
}
|
|
488
|
+
|
|
444
489
|
static VALUE
|
|
445
490
|
rb_ca_search_kw (int argc, VALUE *argv, VALUE self)
|
|
446
491
|
{
|
|
447
492
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
448
|
-
VALUE raxis = Qnil;
|
|
449
|
-
rb_scan_options(ropt, "axis", &raxis);
|
|
450
|
-
rb_check_arity(argc, 1,
|
|
493
|
+
VALUE raxis = Qnil, rtol = Qnil;
|
|
494
|
+
rb_scan_options(ropt, "axis,tol", &raxis, &rtol);
|
|
495
|
+
rb_check_arity(argc, 1, 1);
|
|
496
|
+
VALUE rquery = argv[0];
|
|
497
|
+
int has_tol = ! NIL_P(rtol);
|
|
498
|
+
ca_search_query_read(&self, &rquery);
|
|
451
499
|
|
|
452
500
|
if ( NIL_P(raxis) ) {
|
|
453
501
|
VALUE flat = rb_ca_flatten(self);
|
|
454
|
-
VALUE q = rb_obj_is_carray(
|
|
502
|
+
VALUE q = rb_obj_is_carray(rquery) ? rb_ca_flatten(rquery) : rquery;
|
|
455
503
|
VALUE r;
|
|
456
|
-
VALUE ki_argv[3] = { q, INT2FIX(0),
|
|
457
|
-
if (
|
|
504
|
+
VALUE ki_argv[3] = { q, INT2FIX(0), rtol };
|
|
505
|
+
if ( has_tol ) {
|
|
458
506
|
r = rb_ca_search_ki(3, ki_argv, flat);
|
|
459
507
|
}
|
|
460
508
|
else {
|
|
461
509
|
r = rb_ca_search_ki(2, ki_argv, flat);
|
|
462
510
|
}
|
|
463
|
-
return rb_obj_is_carray(
|
|
511
|
+
return rb_obj_is_carray(rquery) ? ca_reshape_search_result(rquery, r) : r;
|
|
464
512
|
}
|
|
465
|
-
/* search_ki(val, axis,
|
|
466
|
-
VALUE ki_argv[3] = {
|
|
467
|
-
if (
|
|
513
|
+
/* search_ki(val, axis, tol) -- argc=2 (val, axis) or 3 (val, axis, tol) */
|
|
514
|
+
VALUE ki_argv[3] = { rquery, raxis, rtol };
|
|
515
|
+
if ( has_tol ) {
|
|
468
516
|
return rb_ca_search_ki(3, ki_argv, self);
|
|
469
517
|
}
|
|
470
518
|
return rb_ca_search_ki(2, ki_argv, self);
|
|
@@ -474,26 +522,29 @@ static VALUE
|
|
|
474
522
|
rb_ca_search_addr_kw (int argc, VALUE *argv, VALUE self)
|
|
475
523
|
{
|
|
476
524
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
477
|
-
VALUE raxis = Qnil;
|
|
478
|
-
rb_scan_options(ropt, "axis", &raxis);
|
|
479
|
-
rb_check_arity(argc, 1,
|
|
525
|
+
VALUE raxis = Qnil, rtol = Qnil;
|
|
526
|
+
rb_scan_options(ropt, "axis,tol", &raxis, &rtol);
|
|
527
|
+
rb_check_arity(argc, 1, 1);
|
|
528
|
+
VALUE rquery = argv[0];
|
|
529
|
+
int has_tol = ! NIL_P(rtol);
|
|
530
|
+
ca_search_query_read(&self, &rquery);
|
|
480
531
|
|
|
481
532
|
if ( NIL_P(raxis) ) {
|
|
482
533
|
/* 1-D self: addr == index reuses _ki (not _addr_ki). */
|
|
483
534
|
VALUE flat = rb_ca_flatten(self);
|
|
484
|
-
VALUE q = rb_obj_is_carray(
|
|
535
|
+
VALUE q = rb_obj_is_carray(rquery) ? rb_ca_flatten(rquery) : rquery;
|
|
485
536
|
VALUE r;
|
|
486
|
-
VALUE ki_argv[3] = { q, INT2FIX(0),
|
|
487
|
-
if (
|
|
537
|
+
VALUE ki_argv[3] = { q, INT2FIX(0), rtol };
|
|
538
|
+
if ( has_tol ) {
|
|
488
539
|
r = rb_ca_search_ki(3, ki_argv, flat);
|
|
489
540
|
}
|
|
490
541
|
else {
|
|
491
542
|
r = rb_ca_search_ki(2, ki_argv, flat);
|
|
492
543
|
}
|
|
493
|
-
return rb_obj_is_carray(
|
|
544
|
+
return rb_obj_is_carray(rquery) ? ca_reshape_search_result(rquery, r) : r;
|
|
494
545
|
}
|
|
495
|
-
VALUE ki_argv[3] = {
|
|
496
|
-
if (
|
|
546
|
+
VALUE ki_argv[3] = { rquery, raxis, rtol };
|
|
547
|
+
if ( has_tol ) {
|
|
497
548
|
return rb_ca_search_addr_ki(3, ki_argv, self);
|
|
498
549
|
}
|
|
499
550
|
return rb_ca_search_addr_ki(2, ki_argv, self);
|
|
@@ -506,6 +557,7 @@ rb_ca_search_nearest_kw (int argc, VALUE *argv, VALUE self)
|
|
|
506
557
|
VALUE raxis = Qnil;
|
|
507
558
|
rb_scan_options(ropt, "axis", &raxis);
|
|
508
559
|
rb_check_arity(argc, 1, 1);
|
|
560
|
+
ca_refuse_unordered_query(self, argv[0]);
|
|
509
561
|
|
|
510
562
|
if ( NIL_P(raxis) ) {
|
|
511
563
|
VALUE flat = rb_ca_flatten(self);
|
|
@@ -523,6 +575,7 @@ rb_ca_search_nearest_addr_kw (int argc, VALUE *argv, VALUE self)
|
|
|
523
575
|
VALUE raxis = Qnil;
|
|
524
576
|
rb_scan_options(ropt, "axis", &raxis);
|
|
525
577
|
rb_check_arity(argc, 1, 1);
|
|
578
|
+
ca_refuse_unordered_query(self, argv[0]);
|
|
526
579
|
|
|
527
580
|
if ( NIL_P(raxis) ) {
|
|
528
581
|
/* 1-D self: addr == index reuses _ki (not _addr_ki) -- same as bsearch_addr. */
|
|
@@ -549,13 +602,13 @@ rb_ca_search_nearest_addr_kw (int argc, VALUE *argv, VALUE self)
|
|
|
549
602
|
|
|
550
603
|
/* The key orders self's cells one for one, so it has self's shape. */
|
|
551
604
|
static void
|
|
552
|
-
ca_by_key_check_shape (VALUE self, VALUE rkey, const char *name)
|
|
605
|
+
ca_by_key_check_shape (volatile VALUE self, volatile VALUE rkey, const char *name)
|
|
553
606
|
{
|
|
554
607
|
CArray *ca, *ck;
|
|
555
608
|
int8_t i;
|
|
556
609
|
rb_check_carray_object(rkey);
|
|
557
|
-
|
|
558
|
-
|
|
610
|
+
GetCArray(self, ca);
|
|
611
|
+
GetCArray(rkey, ck);
|
|
559
612
|
if ( ca->ndim == ck->ndim ) {
|
|
560
613
|
for (i = 0; i < ca->ndim; i++) {
|
|
561
614
|
if ( ca->dim[i] != ck->dim[i] ) break;
|
|
@@ -564,8 +617,7 @@ ca_by_key_check_shape (VALUE self, VALUE rkey, const char *name)
|
|
|
564
617
|
}
|
|
565
618
|
rb_raise(rb_eArgError, "%s: the key's shape %"PRIsVALUE" differs from "
|
|
566
619
|
"the array's %"PRIsVALUE, name,
|
|
567
|
-
|
|
568
|
-
rb_funcall(self, rb_intern("shape"), 0));
|
|
620
|
+
rb_ca_dim(rkey), rb_ca_dim(self));
|
|
569
621
|
}
|
|
570
622
|
|
|
571
623
|
/* self at the addresses an extremum by key found. A fiber with no cell to
|
|
@@ -582,21 +634,45 @@ ca_by_key_fetch (VALUE self, VALUE addrs)
|
|
|
582
634
|
return rb_ca_fetch(self, addrs);
|
|
583
635
|
}
|
|
584
636
|
|
|
585
|
-
/* sort_by_key(key, axis:
|
|
637
|
+
/* sort_by_key(key, axis: nil, masked_position: :last) -- gather self at
|
|
638
|
+
key.sort_addr(axis:, masked_position:). Without an axis the whole array
|
|
639
|
+
is ordered and the answer is flat, as sort answers. */
|
|
586
640
|
static VALUE
|
|
587
641
|
rb_ca_sort_by_key (int argc, VALUE *argv, VALUE self)
|
|
588
642
|
{
|
|
589
|
-
VALUE rkey, rkw = Qnil, raxis = Qnil;
|
|
643
|
+
VALUE rkey, rkw = Qnil, raxis = Qnil, rmasked_position = Qnil;
|
|
644
|
+
int masked_last;
|
|
590
645
|
rb_scan_args(argc, argv, "1:", &rkey, &rkw);
|
|
591
|
-
rb_scan_options(rkw, "axis", &raxis);
|
|
646
|
+
rb_scan_options(rkw, "axis,masked_position", &raxis, &rmasked_position);
|
|
647
|
+
/* where the cells whose key is masked go: :last (default) or :first */
|
|
648
|
+
masked_last = NIL_P(rmasked_position) ? 1
|
|
649
|
+
: ca_symbol_choice(rmasked_position, "masked_position", "first", "last", NULL);
|
|
650
|
+
ca_by_key_check_shape(self, rkey, "sort_by_key");
|
|
592
651
|
if ( NIL_P(raxis) ) {
|
|
593
|
-
|
|
652
|
+
VALUE flat_key = rb_ca_flatten(rkey);
|
|
653
|
+
VALUE flat = rb_ca_flatten(self);
|
|
654
|
+
VALUE addrs = rb_ca_sort_addr_c(flat_key, INT2FIX(0), 0, masked_last);
|
|
655
|
+
return rb_ca_fetch(flat, addrs);
|
|
594
656
|
}
|
|
595
|
-
|
|
596
|
-
VALUE addrs = rb_ca_sort_addr_c(rkey, raxis, 0, 1); /* masked_last=1 (:last), unchanged default */
|
|
657
|
+
VALUE addrs = rb_ca_sort_addr_c(rkey, raxis, 0, masked_last);
|
|
597
658
|
return rb_ca_fetch(self, addrs);
|
|
598
659
|
}
|
|
599
660
|
|
|
661
|
+
/* The extreme kernels have no fixlen lane: a fixlen key is read through the
|
|
662
|
+
rank of its cells, which keeps ties and masked cells. */
|
|
663
|
+
static VALUE
|
|
664
|
+
ca_by_key_comparable (volatile VALUE key)
|
|
665
|
+
{
|
|
666
|
+
CArray *ca;
|
|
667
|
+
GetCArray(key, ca);
|
|
668
|
+
if ( ca->data_type == CA_FIXLEN ) {
|
|
669
|
+
VALUE opts = rb_hash_new();
|
|
670
|
+
rb_hash_aset(opts, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("dense")));
|
|
671
|
+
return rb_funcallv_kw(key, rb_intern("rank_index"), 1, &opts, RB_PASS_KEYWORDS);
|
|
672
|
+
}
|
|
673
|
+
return key;
|
|
674
|
+
}
|
|
675
|
+
|
|
600
676
|
/* max_by_key(key, axis: nil) -- self[key.max_addr(axis:)] (or UNDEF if empty). */
|
|
601
677
|
static VALUE
|
|
602
678
|
rb_ca_max_by_key (int argc, VALUE *argv, VALUE self)
|
|
@@ -609,6 +685,7 @@ rb_ca_max_by_key (int argc, VALUE *argv, VALUE self)
|
|
|
609
685
|
return CA_UNDEF;
|
|
610
686
|
}
|
|
611
687
|
rkey = ca_order_key(rkey, "max_by_key");
|
|
688
|
+
rkey = ca_by_key_comparable(rkey);
|
|
612
689
|
|
|
613
690
|
VALUE addrs;
|
|
614
691
|
|
|
@@ -636,6 +713,7 @@ rb_ca_min_by_key (int argc, VALUE *argv, VALUE self)
|
|
|
636
713
|
return CA_UNDEF;
|
|
637
714
|
}
|
|
638
715
|
rkey = ca_order_key(rkey, "min_by_key");
|
|
716
|
+
rkey = ca_by_key_comparable(rkey);
|
|
639
717
|
|
|
640
718
|
VALUE addrs;
|
|
641
719
|
|
|
@@ -697,11 +775,10 @@ rb_ca_put_along_axis (int argc, VALUE *argv, VALUE self)
|
|
|
697
775
|
broadcast, UNDEF or a Face value means what it means unmasked), and
|
|
698
776
|
only the cells at unmasked indices are written. */
|
|
699
777
|
if ( RTEST(rb_ca_has_mask(addrs)) ) {
|
|
700
|
-
VALUE sel =
|
|
778
|
+
VALUE sel = rb_ca_is_not_masked(addrs);
|
|
701
779
|
VALUE vals = rb_funcall(self, rb_intern("project"), 1, addrs);
|
|
702
|
-
|
|
703
|
-
rb_ca_store(self,
|
|
704
|
-
rb_funcall(vals, rb_intern("[]"), 1, sel));
|
|
780
|
+
rb_ca_store2(vals, 0, NULL, argv[1]);
|
|
781
|
+
rb_ca_store(self, rb_ca_fetch(addrs, sel), rb_ca_fetch(vals, sel));
|
|
705
782
|
return self;
|
|
706
783
|
}
|
|
707
784
|
rb_ca_store(self, addrs, argv[1]);
|
|
@@ -711,12 +788,12 @@ rb_ca_put_along_axis (int argc, VALUE *argv, VALUE self)
|
|
|
711
788
|
/* ---- range -- (min..max) via fused minmax ----------------------------- */
|
|
712
789
|
|
|
713
790
|
static VALUE
|
|
714
|
-
rb_ca_range_method (VALUE self)
|
|
791
|
+
rb_ca_range_method (volatile VALUE self)
|
|
715
792
|
{
|
|
716
793
|
VALUE mm_argv[1] = { Qnil };
|
|
717
794
|
CArray *ca;
|
|
718
795
|
VALUE pair;
|
|
719
|
-
|
|
796
|
+
GetCArray(self, ca);
|
|
720
797
|
/* A Face answers its own minmax (in its order, with its elements). */
|
|
721
798
|
pair = ca_is_face(ca) ? rb_funcall(self, rb_intern("minmax"), 0)
|
|
722
799
|
: rb_ca_minmax_ki(0, mm_argv, self);
|
|
@@ -791,6 +868,7 @@ ca_topk_cmp (const ca_topk_fiber_t *f, ca_size_t i, ca_size_t j)
|
|
|
791
868
|
#undef CA_TOPK_CMP
|
|
792
869
|
|
|
793
870
|
/* Merge sort of positions by (order, position). */
|
|
871
|
+
/* recursion: a merge sort, log2 of the length deep */
|
|
794
872
|
static void
|
|
795
873
|
ca_topk_sort (const ca_topk_fiber_t *f, ca_size_t *p, ca_size_t *tmp, ca_size_t n)
|
|
796
874
|
{
|
|
@@ -1100,7 +1178,7 @@ ca_topk_buf_fiber (const ca_topk_fiber_t *f, ca_size_t len, ca_size_t cap,
|
|
|
1100
1178
|
filled with the axis last and moved into place at the end (cap cells
|
|
1101
1179
|
per fiber). */
|
|
1102
1180
|
static VALUE
|
|
1103
|
-
ca_topk_buffered_positions (VALUE key, long cap, long axis, int desc)
|
|
1181
|
+
ca_topk_buffered_positions (volatile VALUE key, long cap, long axis, int desc)
|
|
1104
1182
|
{
|
|
1105
1183
|
volatile VALUE holder = 0, out;
|
|
1106
1184
|
VALUE perm[CA_RANK_MAX];
|
|
@@ -1147,17 +1225,17 @@ ca_topk_buffered_positions (VALUE key, long cap, long axis, int desc)
|
|
|
1147
1225
|
/* Per-axis top-k positions (cap clamped, axis normalized).
|
|
1148
1226
|
* Called by rb_ca_topk_index below. */
|
|
1149
1227
|
static VALUE
|
|
1150
|
-
rb_ca_topk_positions (VALUE self, long cap, long axis_norm, int desc)
|
|
1228
|
+
rb_ca_topk_positions (volatile VALUE self, long cap, long axis_norm, int desc)
|
|
1151
1229
|
{
|
|
1152
1230
|
CArray *ca;
|
|
1153
|
-
|
|
1231
|
+
GetCArray(self, ca);
|
|
1154
1232
|
long dim_axis = (long) ca->dim[axis_norm];
|
|
1155
1233
|
VALUE raxis_norm = LONG2NUM(axis_norm);
|
|
1156
1234
|
|
|
1157
1235
|
/* The buffered walk reads any key but an object (its cells compare in
|
|
1158
1236
|
Ruby) or a complex one (no order), and keeps cap cells per fiber. */
|
|
1159
1237
|
if ( ca->data_type != CA_OBJECT && ! ca_is_complex_type(ca) ) {
|
|
1160
|
-
VALUE key = ca_order_key(self, desc ? "nlargest" : "nsmallest");
|
|
1238
|
+
volatile VALUE key = ca_order_key(self, desc ? "nlargest" : "nsmallest");
|
|
1161
1239
|
CArray *ck;
|
|
1162
1240
|
GetCArray(key, ck);
|
|
1163
1241
|
if ( ck->data_type != CA_OBJECT && ! ca_is_complex_type(ck) &&
|
|
@@ -1175,7 +1253,7 @@ rb_ca_topk_positions (VALUE self, long cap, long axis_norm, int desc)
|
|
|
1175
1253
|
VALUE kw = rb_hash_new();
|
|
1176
1254
|
rb_hash_aset(kw, ID2SYM(rb_intern("axis")), raxis_norm);
|
|
1177
1255
|
rb_hash_aset(kw, ID2SYM(rb_intern("descending")), desc ? Qtrue : Qfalse);
|
|
1178
|
-
VALUE rank = rb_funcallv_kw(self, rb_intern("
|
|
1256
|
+
VALUE rank = rb_funcallv_kw(self, rb_intern("rank_index"), 1, &kw, RB_PASS_KEYWORDS);
|
|
1179
1257
|
VALUE full = rb_ca_sort_index_ki_quick(rank, raxis_norm);
|
|
1180
1258
|
if ( cap >= dim_axis ) {
|
|
1181
1259
|
return rb_ca_copy(full);
|
|
@@ -1225,10 +1303,10 @@ rb_ca_topk_positions (VALUE self, long cap, long axis_norm, int desc)
|
|
|
1225
1303
|
* Called by rb_ca_nlargest_index / rb_ca_nsmallest_index (index
|
|
1226
1304
|
* variants) and indirectly by rb_ca_topk_values below. */
|
|
1227
1305
|
static VALUE
|
|
1228
|
-
rb_ca_topk_index (VALUE self, VALUE rn, VALUE raxis, int desc, const char *name)
|
|
1306
|
+
rb_ca_topk_index (volatile VALUE self, VALUE rn, VALUE raxis, int desc, const char *name)
|
|
1229
1307
|
{
|
|
1230
1308
|
CArray *ca;
|
|
1231
|
-
|
|
1309
|
+
GetCArray(self, ca);
|
|
1232
1310
|
long a = rb_ca_normalize_axis_value(self, raxis, name);
|
|
1233
1311
|
long n_val = ca_integer_arg(rn, "n", name);
|
|
1234
1312
|
long dim_a = (long) ca->dim[a];
|
|
@@ -1311,12 +1389,12 @@ rb_ca_nsmallest (int argc, VALUE *argv, VALUE self)
|
|
|
1311
1389
|
return rb_ca_topk_values(self, argv[0], raxis, 0, "nsmallest");
|
|
1312
1390
|
}
|
|
1313
1391
|
|
|
1314
|
-
/* ----
|
|
1392
|
+
/* ---- rank_index(axis:, descending:, method:) ---------------------------
|
|
1315
1393
|
*
|
|
1316
1394
|
* method: :ordinal (default) assigns every cell a distinct rank (ties
|
|
1317
1395
|
* broken by stable original position, scipy.stats.rankdata 'ordinal'
|
|
1318
1396
|
* style). method: :dense assigns tied values the same rank (no gaps),
|
|
1319
|
-
* the standard "dense rank" -- lets
|
|
1397
|
+
* the standard "dense rank" -- lets rank_index(descending:) compose as a
|
|
1320
1398
|
* sort_addr priority key without silently dropping a lower-priority
|
|
1321
1399
|
* key on ties: ordinal ranks are already a total order (no two cells
|
|
1322
1400
|
* ever compare equal), so a later sort_addr key never gets consulted;
|
|
@@ -1328,7 +1406,7 @@ rb_ca_nsmallest (int argc, VALUE *argv, VALUE self)
|
|
|
1328
1406
|
* order in both directions. */
|
|
1329
1407
|
|
|
1330
1408
|
static VALUE
|
|
1331
|
-
|
|
1409
|
+
rb_ca_rank_index (int argc, VALUE *argv, volatile VALUE self)
|
|
1332
1410
|
{
|
|
1333
1411
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1334
1412
|
VALUE raxis = Qnil, rdesc = Qfalse, rmethod = Qnil, rkind = Qnil;
|
|
@@ -1340,34 +1418,35 @@ rb_ca_order (int argc, VALUE *argv, VALUE self)
|
|
|
1340
1418
|
int do_stable = NIL_P(rkind) ? 0
|
|
1341
1419
|
: ca_symbol_choice(rkind, "kind", "quick", "stable", NULL);
|
|
1342
1420
|
|
|
1343
|
-
|
|
1421
|
+
int desc = ca_bool_arg(rdesc, "descending");
|
|
1422
|
+
if ( desc && ! dense ) {
|
|
1344
1423
|
VALUE kw = rb_hash_new();
|
|
1345
1424
|
rb_hash_aset(kw, ID2SYM(rb_intern("axis")), raxis);
|
|
1346
1425
|
rb_hash_aset(kw, ID2SYM(rb_intern("descending")), Qtrue);
|
|
1347
1426
|
rb_hash_aset(kw, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("dense")));
|
|
1348
1427
|
rb_hash_aset(kw, ID2SYM(rb_intern("kind")), do_stable ? ID2SYM(rb_intern("stable")) : ID2SYM(rb_intern("quick")));
|
|
1349
|
-
VALUE ranked = rb_funcallv_kw(self, rb_intern("
|
|
1428
|
+
VALUE ranked = rb_funcallv_kw(self, rb_intern("rank_index"), 1, &kw, RB_PASS_KEYWORDS);
|
|
1350
1429
|
rb_hash_delete(kw, ID2SYM(rb_intern("descending")));
|
|
1351
1430
|
rb_hash_delete(kw, ID2SYM(rb_intern("method")));
|
|
1352
|
-
return rb_funcallv_kw(ranked, rb_intern("
|
|
1431
|
+
return rb_funcallv_kw(ranked, rb_intern("rank_index"), 1, &kw, RB_PASS_KEYWORDS);
|
|
1353
1432
|
}
|
|
1354
1433
|
|
|
1355
1434
|
/* The kernel's dense == 2 is the descending dense rank. */
|
|
1356
|
-
int kmode = ( dense &&
|
|
1435
|
+
int kmode = ( dense && desc ) ? 2 : dense;
|
|
1357
1436
|
if ( NIL_P(raxis) ) {
|
|
1358
1437
|
VALUE flat = rb_ca_flatten(self);
|
|
1359
1438
|
/* Direct C-level dispatch via c_callable: true extern (mkkernel). */
|
|
1360
1439
|
VALUE ranked = rb_ca_rank_index_ki_kind_dense(flat, INT2FIX(0), do_stable, kmode);
|
|
1361
1440
|
/* reshape(*shape) */
|
|
1362
1441
|
CArray *ca;
|
|
1363
|
-
|
|
1442
|
+
GetCArray(self, ca);
|
|
1364
1443
|
VALUE shape_argv[CA_RANK_MAX];
|
|
1365
1444
|
for ( long k = 0; k < (long) ca->ndim; k++ ) {
|
|
1366
1445
|
shape_argv[k] = LONG2NUM((long) ca->dim[k]);
|
|
1367
1446
|
}
|
|
1368
1447
|
return rb_ca_reshape((int) ca->ndim, shape_argv, ranked);
|
|
1369
1448
|
}
|
|
1370
|
-
long axis_norm = rb_ca_normalize_axis_value(self, raxis, "
|
|
1449
|
+
long axis_norm = rb_ca_normalize_axis_value(self, raxis, "rank_index");
|
|
1371
1450
|
/* Output data_type: CA_SIZE (int64 on 64-bit builds), as the rest of the
|
|
1372
1451
|
*_index family. */
|
|
1373
1452
|
return rb_ca_rank_index_ki_kind_dense(self, LONG2NUM(axis_norm), do_stable, kmode);
|
|
@@ -1379,10 +1458,10 @@ rb_ca_order (int argc, VALUE *argv, VALUE self)
|
|
|
1379
1458
|
* rb_ca_to_float64), then optionally flatten when axis is nil.
|
|
1380
1459
|
* Called by rb_ca_linear_section_m and rb_ca_linear_fetch_m. */
|
|
1381
1460
|
static VALUE
|
|
1382
|
-
ca_linear_prep (VALUE self, VALUE raxis, const char *name, long *axis_out)
|
|
1461
|
+
ca_linear_prep (volatile VALUE self, VALUE raxis, const char *name, long *axis_out)
|
|
1383
1462
|
{
|
|
1384
1463
|
CArray *ca;
|
|
1385
|
-
|
|
1464
|
+
GetCArray(self, ca);
|
|
1386
1465
|
/* Face gate: linear_section / linear_fetch treat the axis as a continuous
|
|
1387
1466
|
numeric coordinate (fractional index by interpolating the stored values).
|
|
1388
1467
|
An ORDERABLE Face (storage order == surface order) is descended to its
|
|
@@ -1394,12 +1473,12 @@ ca_linear_prep (VALUE self, VALUE raxis, const char *name, long *axis_out)
|
|
|
1394
1473
|
if ( ca_is_face(ca) ) {
|
|
1395
1474
|
ca_face_require_orderable(self, name, "order");
|
|
1396
1475
|
self = rb_ca_strip_face_value(self);
|
|
1397
|
-
|
|
1476
|
+
GetCArray(self, ca);
|
|
1398
1477
|
}
|
|
1399
|
-
VALUE sc = (ca->data_type == CA_FLOAT64) ? self : rb_ca_to_float64(self);
|
|
1478
|
+
volatile VALUE sc = (ca->data_type == CA_FLOAT64) ? self : rb_ca_to_float64(self);
|
|
1400
1479
|
if ( NIL_P(raxis) ) {
|
|
1401
1480
|
CArray *sca;
|
|
1402
|
-
|
|
1481
|
+
GetCArray(sc, sca);
|
|
1403
1482
|
if ( sca->ndim > 1 ) {
|
|
1404
1483
|
sc = rb_ca_flatten(sc);
|
|
1405
1484
|
}
|
|
@@ -1411,7 +1490,7 @@ ca_linear_prep (VALUE self, VALUE raxis, const char *name, long *axis_out)
|
|
|
1411
1490
|
}
|
|
1412
1491
|
|
|
1413
1492
|
static VALUE
|
|
1414
|
-
rb_ca_linear_section_m (int argc, VALUE *argv, VALUE self)
|
|
1493
|
+
rb_ca_linear_section_m (int argc, VALUE *argv, volatile VALUE self)
|
|
1415
1494
|
{
|
|
1416
1495
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1417
1496
|
VALUE raxis = Qnil, rmethod = ID2SYM(id_sym_binary);
|
|
@@ -1423,7 +1502,7 @@ rb_ca_linear_section_m (int argc, VALUE *argv, VALUE self)
|
|
|
1423
1502
|
brought into one space (ca_face_reconcile_pair). */
|
|
1424
1503
|
if ( rb_obj_is_carray(self) ) {
|
|
1425
1504
|
CArray *sca;
|
|
1426
|
-
|
|
1505
|
+
GetCArray(self, sca);
|
|
1427
1506
|
if ( ca_is_face(sca) ) {
|
|
1428
1507
|
volatile VALUE ref = self, query = val;
|
|
1429
1508
|
ca_face_reconcile_pair(&ref, &query, "linear_section");
|
|
@@ -1434,7 +1513,7 @@ rb_ca_linear_section_m (int argc, VALUE *argv, VALUE self)
|
|
|
1434
1513
|
|
|
1435
1514
|
{
|
|
1436
1515
|
CArray *ca;
|
|
1437
|
-
|
|
1516
|
+
GetCArray(self, ca);
|
|
1438
1517
|
if ( ca_is_complex_type(ca) ) {
|
|
1439
1518
|
rb_raise(rb_eCADataTypeError,
|
|
1440
1519
|
"linear_section: a %s array has no order (complex numbers are "
|
|
@@ -1459,7 +1538,7 @@ rb_ca_linear_section_m (int argc, VALUE *argv, VALUE self)
|
|
|
1459
1538
|
}
|
|
1460
1539
|
|
|
1461
1540
|
static VALUE
|
|
1462
|
-
rb_ca_linear_fetch_m (int argc, VALUE *argv, VALUE self)
|
|
1541
|
+
rb_ca_linear_fetch_m (int argc, VALUE *argv, volatile VALUE self)
|
|
1463
1542
|
{
|
|
1464
1543
|
VALUE ropt = rb_pop_options(&argc, &argv);
|
|
1465
1544
|
VALUE raxis = Qnil;
|
|
@@ -1471,7 +1550,7 @@ rb_ca_linear_fetch_m (int argc, VALUE *argv, VALUE self)
|
|
|
1471
1550
|
weights are real, so each part is a real interpolation. */
|
|
1472
1551
|
{
|
|
1473
1552
|
CArray *ca;
|
|
1474
|
-
|
|
1553
|
+
GetCArray(self, ca);
|
|
1475
1554
|
if ( ca_is_complex_type(ca) ) {
|
|
1476
1555
|
VALUE args[2], re, im;
|
|
1477
1556
|
int n = 1;
|
|
@@ -1537,7 +1616,7 @@ Init_carray_order (void)
|
|
|
1537
1616
|
rb_define_method(rb_cCArray, "nsmallest", rb_ca_nsmallest, -1);
|
|
1538
1617
|
rb_define_method(rb_cCArray, "nlargest_index", rb_ca_nlargest_index, -1);
|
|
1539
1618
|
rb_define_method(rb_cCArray, "nsmallest_index", rb_ca_nsmallest_index, -1);
|
|
1540
|
-
rb_define_method(rb_cCArray, "
|
|
1619
|
+
rb_define_method(rb_cCArray, "rank_index", rb_ca_rank_index, -1);
|
|
1541
1620
|
rb_define_method(rb_cCArray, "linear_section", rb_ca_linear_section_m, -1);
|
|
1542
1621
|
rb_define_method(rb_cCArray, "linear_fetch", rb_ca_linear_fetch_m, -1);
|
|
1543
1622
|
|