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
data/ext/carray_utils.c
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
#include <stdarg.h>
|
|
14
14
|
#include <time.h>
|
|
15
|
+
#include <math.h>
|
|
15
16
|
#include "ruby.h"
|
|
16
17
|
#include "carray.h"
|
|
17
|
-
#include "carray_internal.h" /* ca_calling_method_name */
|
|
18
18
|
|
|
19
19
|
#include "ruby/st.h"
|
|
20
20
|
#include "ruby/thread_native.h"
|
|
@@ -22,11 +22,6 @@
|
|
|
22
22
|
#include "ruby/ractor.h"
|
|
23
23
|
#include "ruby/debug.h" /* rb_profile_frames: the method the user called */
|
|
24
24
|
|
|
25
|
-
static ID id_begin, id_end, id_excl_end;
|
|
26
|
-
#define RANGE_BEG(r) (rb_funcall(r, id_begin, 0))
|
|
27
|
-
#define RANGE_END(r) (rb_funcall(r, id_end, 0))
|
|
28
|
-
#define RANGE_EXCL(r) (rb_funcall(r, id_excl_end, 0))
|
|
29
|
-
|
|
30
25
|
/* ------------------------------------------------------------------- */
|
|
31
26
|
|
|
32
27
|
void
|
|
@@ -156,9 +151,14 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
156
151
|
}
|
|
157
152
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
|
158
153
|
/* i..j */
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
{
|
|
155
|
+
VALUE beg, end;
|
|
156
|
+
int exclusive;
|
|
157
|
+
rb_range_values(arg, &beg, &end, &exclusive);
|
|
158
|
+
start = ca_range_bound(beg);
|
|
159
|
+
last = ca_range_bound(end);
|
|
160
|
+
excl = exclusive;
|
|
161
|
+
}
|
|
162
162
|
CA_CHECK_INDEX(start, size);
|
|
163
163
|
if ( last < 0 ) {
|
|
164
164
|
last += size;
|
|
@@ -183,7 +183,8 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
183
183
|
excl = RTEST(x.exclude_end);
|
|
184
184
|
step = ca_range_bound(x.step);
|
|
185
185
|
if ( step == 0 ) {
|
|
186
|
-
rb_raise(rb_eArgError, "step should not be 0"
|
|
186
|
+
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
187
|
+
ca_calling_method_name());
|
|
187
188
|
}
|
|
188
189
|
CA_CHECK_INDEX(start, size);
|
|
189
190
|
if ( last < 0 ) {
|
|
@@ -221,7 +222,8 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
221
222
|
if ( NIL_P(arg0) ) { /* [nil,k] */
|
|
222
223
|
step = ca_range_bound(arg1);
|
|
223
224
|
if ( step == 0 ) {
|
|
224
|
-
rb_raise(rb_eArgError, "step should not be 0"
|
|
225
|
+
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
226
|
+
ca_calling_method_name());
|
|
225
227
|
}
|
|
226
228
|
start = 0;
|
|
227
229
|
count = (size-1)/llabs(step) + 1;
|
|
@@ -234,12 +236,18 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
234
236
|
*pstep = step;
|
|
235
237
|
}
|
|
236
238
|
else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* [i..j,k] */
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
{
|
|
240
|
+
VALUE beg, end;
|
|
241
|
+
int exclusive;
|
|
242
|
+
rb_range_values(arg0, &beg, &end, &exclusive);
|
|
243
|
+
start = ca_range_bound(beg);
|
|
244
|
+
last = ca_range_bound(end);
|
|
245
|
+
excl = exclusive;
|
|
246
|
+
}
|
|
240
247
|
step = ca_range_bound(arg1);
|
|
241
248
|
if ( step == 0 ) {
|
|
242
|
-
rb_raise(rb_eArgError, "step should not be 0"
|
|
249
|
+
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
250
|
+
ca_calling_method_name());
|
|
243
251
|
}
|
|
244
252
|
CA_CHECK_INDEX(start, size);
|
|
245
253
|
if ( last < 0 ) {
|
|
@@ -275,7 +283,8 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
275
283
|
excl = RTEST(x.exclude_end);
|
|
276
284
|
step = ca_range_bound(x.step);
|
|
277
285
|
if ( step == 0 ) {
|
|
278
|
-
rb_raise(rb_eArgError, "step should not be 0"
|
|
286
|
+
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
287
|
+
ca_calling_method_name());
|
|
279
288
|
}
|
|
280
289
|
CA_CHECK_INDEX(start, size);
|
|
281
290
|
if ( last < 0 ) {
|
|
@@ -320,7 +329,8 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
320
329
|
count = ca_range_bound(rb_ary_entry(arg, 1));
|
|
321
330
|
step = ca_range_bound(rb_ary_entry(arg, 2));
|
|
322
331
|
if ( step == 0 ) {
|
|
323
|
-
rb_raise(rb_eArgError, "step should not be 0"
|
|
332
|
+
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
333
|
+
ca_calling_method_name());
|
|
324
334
|
}
|
|
325
335
|
CA_CHECK_INDEX(start, size);
|
|
326
336
|
bound = start + (count - 1)*step;
|
|
@@ -332,11 +342,13 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
|
332
342
|
*pstep = step;
|
|
333
343
|
}
|
|
334
344
|
else {
|
|
335
|
-
rb_raise(rb_eArgError, "unknown range specification"
|
|
345
|
+
rb_raise(rb_eArgError, "%s: unknown range specification",
|
|
346
|
+
ca_calling_method_name());
|
|
336
347
|
}
|
|
337
348
|
}
|
|
338
349
|
else {
|
|
339
|
-
rb_raise(rb_eArgError, "unknown range specification"
|
|
350
|
+
rb_raise(rb_eArgError, "%s: unknown range specification",
|
|
351
|
+
ca_calling_method_name());
|
|
340
352
|
}
|
|
341
353
|
}
|
|
342
354
|
|
|
@@ -362,9 +374,14 @@ ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
|
362
374
|
}
|
|
363
375
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
|
364
376
|
/* i..j */
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
377
|
+
{
|
|
378
|
+
VALUE beg, end;
|
|
379
|
+
int exclusive;
|
|
380
|
+
rb_range_values(arg, &beg, &end, &exclusive);
|
|
381
|
+
start = ca_range_bound(beg);
|
|
382
|
+
last = ca_range_bound(end);
|
|
383
|
+
excl = exclusive;
|
|
384
|
+
}
|
|
368
385
|
if ( excl ) {
|
|
369
386
|
last -= 1;
|
|
370
387
|
}
|
|
@@ -415,9 +432,14 @@ ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
|
415
432
|
*pstep = step;
|
|
416
433
|
}
|
|
417
434
|
else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* [i..j,k] */
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
435
|
+
{
|
|
436
|
+
VALUE beg, end;
|
|
437
|
+
int exclusive;
|
|
438
|
+
rb_range_values(arg0, &beg, &end, &exclusive);
|
|
439
|
+
start = ca_range_bound(beg);
|
|
440
|
+
last = ca_range_bound(end);
|
|
441
|
+
excl = exclusive;
|
|
442
|
+
}
|
|
421
443
|
step = ca_range_bound(arg1);
|
|
422
444
|
if ( step == 0 ) {
|
|
423
445
|
rb_raise(rb_eArgError, "%s: step should not be 0",
|
|
@@ -470,11 +492,13 @@ ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
|
470
492
|
*pstep = step;
|
|
471
493
|
}
|
|
472
494
|
else {
|
|
473
|
-
rb_raise(rb_eArgError, "unknown range specification"
|
|
495
|
+
rb_raise(rb_eArgError, "%s: unknown range specification",
|
|
496
|
+
ca_calling_method_name());
|
|
474
497
|
}
|
|
475
498
|
}
|
|
476
499
|
else {
|
|
477
|
-
rb_raise(rb_eArgError, "unknown range specification"
|
|
500
|
+
rb_raise(rb_eArgError, "%s: unknown range specification",
|
|
501
|
+
ca_calling_method_name());
|
|
478
502
|
}
|
|
479
503
|
}
|
|
480
504
|
|
|
@@ -515,8 +539,8 @@ ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k)
|
|
|
515
539
|
k = k % (2*size0);
|
|
516
540
|
return ( k < size0 ) ? k : 2*size0-1-k;
|
|
517
541
|
default:
|
|
518
|
-
rb_raise(
|
|
519
|
-
"unknown
|
|
542
|
+
rb_raise(rb_eRuntimeError,
|
|
543
|
+
"[BUG] ca_bounds_normalize_index: unknown boundary (%i)", bounds);
|
|
520
544
|
}
|
|
521
545
|
}
|
|
522
546
|
|
|
@@ -547,17 +571,17 @@ ca_stable_id_name (ID id)
|
|
|
547
571
|
return name;
|
|
548
572
|
}
|
|
549
573
|
{
|
|
550
|
-
VALUE
|
|
574
|
+
volatile VALUE str = rb_id2str(id);
|
|
551
575
|
long len;
|
|
552
576
|
char *copy;
|
|
553
577
|
if ( NIL_P(str) ) {
|
|
554
578
|
return NULL;
|
|
555
579
|
}
|
|
556
580
|
len = RSTRING_LEN(str);
|
|
581
|
+
/* buffer: kept by the cache; freed here only when another thread stored it first */
|
|
557
582
|
copy = ALLOC_N(char, len + 1);
|
|
558
583
|
memcpy(copy, RSTRING_PTR(str), len);
|
|
559
584
|
copy[len] = '\0';
|
|
560
|
-
RB_GC_GUARD(str);
|
|
561
585
|
/* lock: st_insert can run a GC, which does not take this lock */
|
|
562
586
|
ca_native_lock_without_gvl(&ca_id_names_lock);
|
|
563
587
|
if ( st_lookup(ca_id_names, (st_data_t) id, &found) ) {
|
|
@@ -638,7 +662,7 @@ static long ca_library_root_len = 0;
|
|
|
638
662
|
/* CArray.library_root = dir (private): where the frames of the library's
|
|
639
663
|
own Ruby methods are. The first call wins. */
|
|
640
664
|
static VALUE
|
|
641
|
-
rb_ca_s_set_library_root (VALUE klass, VALUE dir)
|
|
665
|
+
rb_ca_s_set_library_root (VALUE klass, volatile VALUE dir)
|
|
642
666
|
{
|
|
643
667
|
if ( ca_library_root == NULL ) {
|
|
644
668
|
long len = RSTRING_LEN(StringValue(dir));
|
|
@@ -655,9 +679,9 @@ rb_ca_s_set_library_root (VALUE klass, VALUE dir)
|
|
|
655
679
|
library's: a method of a CA* or CScalar class, or a CA_* conversion
|
|
656
680
|
function. A method of a core class (Array#map, Integer#times) is not. */
|
|
657
681
|
static int
|
|
658
|
-
ca_frame_is_library_cfunc (VALUE frame, VALUE name)
|
|
682
|
+
ca_frame_is_library_cfunc (VALUE frame, volatile VALUE name)
|
|
659
683
|
{
|
|
660
|
-
VALUE path = rb_profile_frame_classpath(frame);
|
|
684
|
+
volatile VALUE path = rb_profile_frame_classpath(frame);
|
|
661
685
|
if ( ! NIL_P(path) ) {
|
|
662
686
|
const char *p = RSTRING_PTR(path);
|
|
663
687
|
long n = RSTRING_LEN(path);
|
|
@@ -690,8 +714,9 @@ ca_user_called_method_id (void)
|
|
|
690
714
|
}
|
|
691
715
|
n = rb_profile_frames(0, CA_NAMING_FRAMES, frames, lines);
|
|
692
716
|
for (i = 0; i < n; i++) {
|
|
693
|
-
VALUE file = rb_profile_frame_absolute_path(frames[i]);
|
|
694
|
-
VALUE name
|
|
717
|
+
volatile VALUE file = rb_profile_frame_absolute_path(frames[i]);
|
|
718
|
+
VALUE name;
|
|
719
|
+
volatile VALUE label;
|
|
695
720
|
if ( NIL_P(file) ) {
|
|
696
721
|
/* code evaluated with a file name (class_eval in the library) and the
|
|
697
722
|
core written in Ruby ("<internal:numeric>") have a path but no
|
|
@@ -727,7 +752,7 @@ ca_user_called_method_id (void)
|
|
|
727
752
|
innermost C method is named, as before the walk. */
|
|
728
753
|
label = rb_profile_frame_label(frames[i]);
|
|
729
754
|
if ( ! NIL_P(label) && strncmp(StringValueCStr(label), "block ", 6) == 0 ) {
|
|
730
|
-
VALUE base = rb_profile_frame_base_label(frames[i]);
|
|
755
|
+
volatile VALUE base = rb_profile_frame_base_label(frames[i]);
|
|
731
756
|
if ( ! NIL_P(base) && RSTRING_LEN(base) > 0 && RSTRING_PTR(base)[0] == '<' ) {
|
|
732
757
|
return 0;
|
|
733
758
|
}
|
|
@@ -741,6 +766,17 @@ ca_user_called_method_id (void)
|
|
|
741
766
|
return found;
|
|
742
767
|
}
|
|
743
768
|
|
|
769
|
+
double
|
|
770
|
+
ca_tolerance_arg (VALUE tol, const char *name)
|
|
771
|
+
{
|
|
772
|
+
double t = NUM2DBL(tol);
|
|
773
|
+
if ( ! ( t >= 0.0 ) ) {
|
|
774
|
+
rb_raise(rb_eArgError, "%s: tol must be zero or positive (got %"PRIsVALUE")",
|
|
775
|
+
name, rb_inspect(tol));
|
|
776
|
+
}
|
|
777
|
+
return t;
|
|
778
|
+
}
|
|
779
|
+
|
|
744
780
|
const char *
|
|
745
781
|
ca_calling_method_name (void)
|
|
746
782
|
{
|
|
@@ -787,11 +823,13 @@ ca_shape_elements (int8_t ndim, const ca_size_t *dim, ca_size_t bytes)
|
|
|
787
823
|
}
|
|
788
824
|
for ( i = 0; i < ndim; i++ ) {
|
|
789
825
|
if ( __builtin_mul_overflow(elements, dim[i], &elements) ) {
|
|
790
|
-
rb_raise(rb_eArgError, "too large byte length"
|
|
826
|
+
rb_raise(rb_eArgError, "%s: too large byte length",
|
|
827
|
+
ca_calling_method_name());
|
|
791
828
|
}
|
|
792
829
|
}
|
|
793
830
|
if ( __builtin_mul_overflow(elements, (bytes > 0 ? bytes : 1), &total) ) {
|
|
794
|
-
rb_raise(rb_eArgError, "too large byte length"
|
|
831
|
+
rb_raise(rb_eArgError, "%s: too large byte length",
|
|
832
|
+
ca_calling_method_name());
|
|
795
833
|
}
|
|
796
834
|
return elements;
|
|
797
835
|
}
|
|
@@ -802,7 +840,7 @@ ca_shape_elements (int8_t ndim, const ca_size_t *dim, ca_size_t bytes)
|
|
|
802
840
|
uint64 one holding 2**63 or more would turn negative and count from the
|
|
803
841
|
end of the axis, so it is refused as the out-of-range index it is. */
|
|
804
842
|
void
|
|
805
|
-
ca_check_index_array (VALUE v)
|
|
843
|
+
ca_check_index_array (volatile VALUE v)
|
|
806
844
|
{
|
|
807
845
|
CArray *ca;
|
|
808
846
|
if ( ! rb_obj_is_carray(v) ) return;
|
|
@@ -810,7 +848,8 @@ ca_check_index_array (VALUE v)
|
|
|
810
848
|
if ( ca_is_float_type(ca) || ca_is_complex_type(ca)
|
|
811
849
|
|| ca->data_type == CA_OBJECT || ca->data_type == CA_BOOLEAN ) {
|
|
812
850
|
rb_raise(rb_eIndexError,
|
|
813
|
-
"data_type %s is invalid for an index (should be integer)",
|
|
851
|
+
"%s: data_type %s is invalid for an index (should be integer)",
|
|
852
|
+
ca_calling_method_name(),
|
|
814
853
|
ca_type_name[ca->data_type]);
|
|
815
854
|
}
|
|
816
855
|
if ( ca->data_type != CA_UINT64 || ca->elements == 0 ) return;
|
|
@@ -818,11 +857,26 @@ ca_check_index_array (VALUE v)
|
|
|
818
857
|
VALUE max = rb_funcall(v, rb_intern("max"), 0);
|
|
819
858
|
if ( rb_obj_is_kind_of(max, rb_cInteger) &&
|
|
820
859
|
RTEST(rb_funcall(max, rb_intern(">"), 1, LL2NUM(CA_LENGTH_MAX))) ) {
|
|
821
|
-
rb_raise(rb_eIndexError, "index %"PRIsVALUE" is out of range",
|
|
860
|
+
rb_raise(rb_eIndexError, "%s: index %"PRIsVALUE" is out of range",
|
|
861
|
+
ca_calling_method_name(), max);
|
|
822
862
|
}
|
|
823
863
|
}
|
|
824
864
|
}
|
|
825
865
|
|
|
866
|
+
int
|
|
867
|
+
ca_bool_arg (VALUE v, const char *arg)
|
|
868
|
+
{
|
|
869
|
+
if ( v == Qtrue ) {
|
|
870
|
+
return 1;
|
|
871
|
+
}
|
|
872
|
+
if ( v == Qfalse || NIL_P(v) ) {
|
|
873
|
+
return 0;
|
|
874
|
+
}
|
|
875
|
+
rb_raise(rb_eArgError, "%s: %s: must be true or false (got %"PRIsVALUE")",
|
|
876
|
+
ca_calling_method_name(), arg, rb_inspect(v));
|
|
877
|
+
return 0;
|
|
878
|
+
}
|
|
879
|
+
|
|
826
880
|
long
|
|
827
881
|
ca_integer_arg (VALUE v, const char *arg, const char *name)
|
|
828
882
|
{
|
|
@@ -830,6 +884,17 @@ ca_integer_arg (VALUE v, const char *arg, const char *name)
|
|
|
830
884
|
rb_raise(rb_eTypeError, "%s: %s must be an Integer (got %"PRIsVALUE")",
|
|
831
885
|
name ? name : ca_calling_method_name(), arg, rb_obj_class(v));
|
|
832
886
|
}
|
|
887
|
+
if ( RB_TYPE_P(v, T_BIGNUM) ) {
|
|
888
|
+
long out;
|
|
889
|
+
int sign = rb_integer_pack(v, &out, 1, sizeof(out), 0,
|
|
890
|
+
INTEGER_PACK_NATIVE_BYTE_ORDER |
|
|
891
|
+
INTEGER_PACK_2COMP);
|
|
892
|
+
if ( sign == 2 || sign == -2 ) {
|
|
893
|
+
rb_raise(rb_eRangeError, "%s: %s %"PRIsVALUE" is out of range",
|
|
894
|
+
name ? name : ca_calling_method_name(), arg, v);
|
|
895
|
+
}
|
|
896
|
+
return out;
|
|
897
|
+
}
|
|
833
898
|
return NUM2LONG(v);
|
|
834
899
|
}
|
|
835
900
|
|
|
@@ -837,8 +902,8 @@ void
|
|
|
837
902
|
ca_index_out_of_range_at (ca_size_t idx, ca_size_t n, int axis)
|
|
838
903
|
{
|
|
839
904
|
rb_raise(rb_eIndexError,
|
|
840
|
-
"%s: index %
|
|
841
|
-
ca_calling_method_name(), (
|
|
905
|
+
"%s: index %"PRId64" is out of range for length %"PRId64" on axis %d",
|
|
906
|
+
ca_calling_method_name(), (int64_t) idx, (int64_t) n, axis);
|
|
842
907
|
}
|
|
843
908
|
|
|
844
909
|
void
|
|
@@ -856,8 +921,8 @@ ca_obj_compare_refused (VALUE a, VALUE b)
|
|
|
856
921
|
void
|
|
857
922
|
ca_index_out_of_range (ca_size_t idx, ca_size_t n, const char *what)
|
|
858
923
|
{
|
|
859
|
-
rb_raise(rb_eIndexError, "%s: %s %
|
|
860
|
-
ca_calling_method_name(), what, (
|
|
924
|
+
rb_raise(rb_eIndexError, "%s: %s %"PRId64" is out of range for length %"PRId64,
|
|
925
|
+
ca_calling_method_name(), what, (int64_t) idx, (int64_t) n);
|
|
861
926
|
}
|
|
862
927
|
|
|
863
928
|
/* The min_count: keyword of a reduction: nil (not given) is -1, any other
|
|
@@ -927,26 +992,62 @@ ca_fill_as (VALUE fill, int8_t data_type)
|
|
|
927
992
|
return rb_ca_fetch_addr(cell, 0);
|
|
928
993
|
}
|
|
929
994
|
|
|
930
|
-
/*
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
995
|
+
/* A fill_value for an integer answer: an Integer, or a Float with an
|
|
996
|
+
integer value (2.0), taken as that Integer. A value with a fraction, NaN
|
|
997
|
+
or an infinity is refused, as a store would otherwise cut it to an integer
|
|
998
|
+
without a word. Any other value is left to the store. */
|
|
999
|
+
static VALUE
|
|
1000
|
+
ca_integer_fill (VALUE fill, int8_t data_type, const char *name)
|
|
1001
|
+
{
|
|
1002
|
+
if ( RB_FLOAT_TYPE_P(fill) ) {
|
|
1003
|
+
double x = RFLOAT_VALUE(fill);
|
|
1004
|
+
if ( ! isfinite(x) || x != floor(x) ) {
|
|
1005
|
+
rb_raise(rb_eArgError,
|
|
1006
|
+
"%s: fill_value %"PRIsVALUE" is not an integer, and the answer is %s",
|
|
1007
|
+
name, rb_inspect(fill), ca_type_name[data_type]);
|
|
1008
|
+
}
|
|
1009
|
+
return rb_dbl2big(x);
|
|
1010
|
+
}
|
|
1011
|
+
if ( rb_obj_is_kind_of(fill, rb_cRational) ) {
|
|
1012
|
+
if ( rb_rational_den(fill) != INT2FIX(1) ) {
|
|
1013
|
+
rb_raise(rb_eArgError,
|
|
1014
|
+
"%s: fill_value %"PRIsVALUE" is not an integer, and the answer is %s",
|
|
1015
|
+
name, rb_inspect(fill), ca_type_name[data_type]);
|
|
1016
|
+
}
|
|
1017
|
+
return rb_rational_num(fill);
|
|
1018
|
+
}
|
|
1019
|
+
return fill;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/* recursion: one level per dimension of a reduction's answer */
|
|
1023
|
+
static VALUE
|
|
1024
|
+
ca_reduce_fill_in (volatile VALUE result, VALUE fill, int whole, int widen, const char *name)
|
|
938
1025
|
{
|
|
939
1026
|
if ( RB_TYPE_P(result, T_ARRAY) ) {
|
|
940
1027
|
long i, n = RARRAY_LEN(result);
|
|
941
1028
|
VALUE out = rb_ary_new_capa(n);
|
|
942
1029
|
for ( i = 0; i < n; i++ ) {
|
|
943
|
-
rb_ary_push(out,
|
|
1030
|
+
rb_ary_push(out, ca_reduce_fill_in(RARRAY_AREF(result, i), fill, whole, widen, name));
|
|
944
1031
|
}
|
|
945
1032
|
return out;
|
|
946
1033
|
}
|
|
947
1034
|
if ( rb_obj_is_kind_of(result, rb_cCArray) ) {
|
|
948
1035
|
CArray *cr;
|
|
949
1036
|
GetCArray(result, cr);
|
|
1037
|
+
if ( ca_is_integer_type(cr) && ! ca_is_face(cr) ) {
|
|
1038
|
+
fill = ca_integer_fill(fill, cr->data_type, name);
|
|
1039
|
+
/* A sum or a product answers in float64 where its total is out of the
|
|
1040
|
+
integer range; a fill out of that range is such a total, so the
|
|
1041
|
+
answer becomes float64 when a cell takes it. */
|
|
1042
|
+
if ( widen && ca_integer_range_side(fill, cr->data_type) != 0 ) {
|
|
1043
|
+
if ( ca_has_mask(cr) && ca_is_any_masked(cr) ) {
|
|
1044
|
+
result = rb_ca_mask_fill_copy(rb_ca_wrap_readonly(result,
|
|
1045
|
+
INT2NUM(CA_FLOAT64)),
|
|
1046
|
+
rb_Float(fill));
|
|
1047
|
+
}
|
|
1048
|
+
return whole ? rb_ca_fetch_addr(result, 0) : result;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
950
1051
|
if ( ca_has_mask(cr) ) {
|
|
951
1052
|
result = rb_ca_mask_fill_copy(result, fill);
|
|
952
1053
|
}
|
|
@@ -954,9 +1055,8 @@ ca_reduce_fill (VALUE result, VALUE fill, int whole)
|
|
|
954
1055
|
/* No cell needed the fill, but a fill the result cannot hold is
|
|
955
1056
|
refused all the same, not only when some cell happens to be
|
|
956
1057
|
undefined: it goes into a one-cell array of the result's kind. */
|
|
957
|
-
volatile VALUE one =
|
|
958
|
-
|
|
959
|
-
rb_range_new(INT2FIX(0), INT2FIX(0), 0));
|
|
1058
|
+
volatile VALUE one = rb_ca_fetch(rb_ca_flatten(result),
|
|
1059
|
+
rb_range_new(INT2FIX(0), INT2FIX(0), 0));
|
|
960
1060
|
rb_ca_store_addr(rb_ca_template(one), 0, fill);
|
|
961
1061
|
}
|
|
962
1062
|
return whole ? rb_ca_fetch_addr(result, 0) : result;
|
|
@@ -964,16 +1064,50 @@ ca_reduce_fill (VALUE result, VALUE fill, int whole)
|
|
|
964
1064
|
return ( result == CA_UNDEF ) ? fill : result;
|
|
965
1065
|
}
|
|
966
1066
|
|
|
967
|
-
/*
|
|
968
|
-
|
|
969
|
-
|
|
1067
|
+
/* The `fill_value:` of a reduction, applied to its result: the masked
|
|
1068
|
+
cells of a CArray result are filled as a store would fill them, each
|
|
1069
|
+
member of a two-array result (minmax) alike. `whole` says the result
|
|
1070
|
+
was computed with every axis kept for a full reduction; its one cell
|
|
1071
|
+
is then returned as the scalar the caller asked for. A caller passes
|
|
1072
|
+
no fill for `fill_value: UNDEF`, which leaves the cells undefined. An
|
|
1073
|
+
integer result refuses a fill with a fraction (ca_integer_fill). */
|
|
1074
|
+
VALUE
|
|
1075
|
+
ca_reduce_fill (VALUE result, VALUE fill, int whole)
|
|
1076
|
+
{
|
|
1077
|
+
return ca_reduce_fill_in(result, fill, whole, 0, ca_calling_method_name());
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/* ca_reduce_fill for a sum or a product: an integer answer takes a fill out
|
|
1081
|
+
of its range by becoming float64, where a cell takes the fill. */
|
|
1082
|
+
VALUE
|
|
1083
|
+
ca_reduce_fill_widening (VALUE result, VALUE fill, int whole, const char *name)
|
|
1084
|
+
{
|
|
1085
|
+
return ca_reduce_fill_in(result, fill, whole, 1, name);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/* CArray.__fill_undefined_result_cells__(result, fill_value, op = nil):
|
|
1089
|
+
ca_reduce_fill for a reduction written in Ruby. A fill_value of nil or
|
|
1090
|
+
UNDEF leaves the undefined cells as they are. `op` names the reduction
|
|
1091
|
+
in a refusal, and :sum or :prod lets an integer answer widen to float64
|
|
1092
|
+
for a fill out of its range (ca_reduce_fill_widening). */
|
|
970
1093
|
static VALUE
|
|
971
|
-
rb_ca_s_reduce_fill (
|
|
1094
|
+
rb_ca_s_reduce_fill (int argc, VALUE *argv, VALUE klass)
|
|
972
1095
|
{
|
|
1096
|
+
VALUE result, fill, op;
|
|
1097
|
+
char name[64];
|
|
1098
|
+
rb_scan_args(argc, argv, "21", &result, &fill, &op);
|
|
973
1099
|
if ( NIL_P(fill) || fill == CA_UNDEF ) {
|
|
974
1100
|
return result;
|
|
975
1101
|
}
|
|
976
|
-
|
|
1102
|
+
if ( NIL_P(op) ) {
|
|
1103
|
+
return ca_reduce_fill(result, fill, 0);
|
|
1104
|
+
}
|
|
1105
|
+
Check_Type(op, T_SYMBOL);
|
|
1106
|
+
/* name: copied out at once, as the fill runs Ruby before a refusal reads it */
|
|
1107
|
+
snprintf(name, sizeof(name), "%s", rb_id2name(SYM2ID(op)));
|
|
1108
|
+
return ca_reduce_fill_in(result, fill, 0,
|
|
1109
|
+
op == ID2SYM(rb_intern("sum")) || op == ID2SYM(rb_intern("prod")),
|
|
1110
|
+
name);
|
|
977
1111
|
}
|
|
978
1112
|
|
|
979
1113
|
/* ca_integer_arg for an `axis` argument. */
|
|
@@ -1014,7 +1148,7 @@ void
|
|
|
1014
1148
|
ca_check_rank_fits (long ndim, const char *name)
|
|
1015
1149
|
{
|
|
1016
1150
|
if ( ndim > CA_RANK_MAX ) {
|
|
1017
|
-
rb_raise(rb_eArgError, "%s: ndim %ld exceeds
|
|
1151
|
+
rb_raise(rb_eArgError, "%s: ndim %ld exceeds CArray::RANK_MAX %d",
|
|
1018
1152
|
name ? name : ca_calling_method_name(), ndim, CA_RANK_MAX);
|
|
1019
1153
|
}
|
|
1020
1154
|
}
|
|
@@ -1026,7 +1160,7 @@ ca_check_rank_fits (long ndim, const char *name)
|
|
|
1026
1160
|
too, since no ndim reaches it. `name` and the insertion-position use of
|
|
1027
1161
|
`ndim` are as for rb_ca_normalize_axis_for_ndim. */
|
|
1028
1162
|
int
|
|
1029
|
-
|
|
1163
|
+
rb_ca_normalize_axis_arg (VALUE raxis, int ndim, const char *name)
|
|
1030
1164
|
{
|
|
1031
1165
|
ca_check_rank_fits(ndim, name); /* no array has the axes to name */
|
|
1032
1166
|
if ( RB_INTEGER_TYPE_P(raxis) && ! RB_FIXNUM_P(raxis) ) {
|
|
@@ -1041,11 +1175,11 @@ ca_normalize_axis_arg (VALUE raxis, int ndim, const char *name)
|
|
|
1041
1175
|
for backward compatibility with the existing instance method
|
|
1042
1176
|
`CArray#normalize_axis`. */
|
|
1043
1177
|
int
|
|
1044
|
-
rb_ca_normalize_axis_value (VALUE self, VALUE raxis, const char *name)
|
|
1178
|
+
rb_ca_normalize_axis_value (volatile VALUE self, VALUE raxis, const char *name)
|
|
1045
1179
|
{
|
|
1046
1180
|
CArray *ca;
|
|
1047
1181
|
GetCArray(self, ca);
|
|
1048
|
-
return
|
|
1182
|
+
return rb_ca_normalize_axis_arg(raxis, (int) ca->ndim, name);
|
|
1049
1183
|
}
|
|
1050
1184
|
|
|
1051
1185
|
/* Ruby-facing `CArray#normalize_axis(axis, name=nil)` — returns the
|
|
@@ -1056,10 +1190,12 @@ rb_ca_normalize_axis_value (VALUE self, VALUE raxis, const char *name)
|
|
|
1056
1190
|
static VALUE
|
|
1057
1191
|
rb_ca_normalize_axis (int argc, VALUE *argv, VALUE self)
|
|
1058
1192
|
{
|
|
1059
|
-
VALUE raxis,
|
|
1193
|
+
VALUE raxis, rname_arg;
|
|
1194
|
+
volatile VALUE rname;
|
|
1060
1195
|
const char *name;
|
|
1061
1196
|
int k;
|
|
1062
|
-
rb_scan_args(argc, argv, "11", &raxis, &
|
|
1197
|
+
rb_scan_args(argc, argv, "11", &raxis, &rname_arg);
|
|
1198
|
+
rname = rname_arg;
|
|
1063
1199
|
name = NIL_P(rname) ? NULL : StringValueCStr(rname);
|
|
1064
1200
|
k = rb_ca_normalize_axis_value(self, raxis, name);
|
|
1065
1201
|
return INT2NUM(k);
|
|
@@ -1075,12 +1211,14 @@ rb_ca_normalize_axis (int argc, VALUE *argv, VALUE self)
|
|
|
1075
1211
|
static VALUE
|
|
1076
1212
|
rb_ca_s_normalize_axis (int argc, VALUE *argv, VALUE klass)
|
|
1077
1213
|
{
|
|
1078
|
-
VALUE raxis, rndim,
|
|
1214
|
+
VALUE raxis, rndim, rname_arg;
|
|
1215
|
+
volatile VALUE rname;
|
|
1079
1216
|
const char *name;
|
|
1080
1217
|
int k;
|
|
1081
|
-
rb_scan_args(argc, argv, "21", &raxis, &rndim, &
|
|
1218
|
+
rb_scan_args(argc, argv, "21", &raxis, &rndim, &rname_arg);
|
|
1219
|
+
rname = rname_arg;
|
|
1082
1220
|
name = NIL_P(rname) ? NULL : StringValueCStr(rname);
|
|
1083
|
-
k =
|
|
1221
|
+
k = rb_ca_normalize_axis_arg(raxis, NUM2INT(rndim), name);
|
|
1084
1222
|
return INT2NUM(k);
|
|
1085
1223
|
}
|
|
1086
1224
|
|
|
@@ -1091,15 +1229,17 @@ rb_ca_s_normalize_axis (int argc, VALUE *argv, VALUE klass)
|
|
|
1091
1229
|
* normalization), or an Array<Integer> (each element normalized).
|
|
1092
1230
|
* Raises on out-of-range or duplicate axes. */
|
|
1093
1231
|
static VALUE
|
|
1094
|
-
rb_ca_normalize_axes (int argc, VALUE *argv, VALUE self)
|
|
1232
|
+
rb_ca_normalize_axes (int argc, VALUE *argv, volatile VALUE self)
|
|
1095
1233
|
{
|
|
1096
|
-
VALUE raxes,
|
|
1234
|
+
VALUE raxes, rname_arg, out;
|
|
1235
|
+
volatile VALUE rname;
|
|
1097
1236
|
CArray *ca;
|
|
1098
1237
|
int8_t axes_buf[CA_RANK_MAX];
|
|
1099
1238
|
int8_t naxes, i;
|
|
1100
1239
|
const char *name;
|
|
1101
1240
|
|
|
1102
|
-
rb_scan_args(argc, argv, "11", &raxes, &
|
|
1241
|
+
rb_scan_args(argc, argv, "11", &raxes, &rname_arg);
|
|
1242
|
+
rname = rname_arg;
|
|
1103
1243
|
name = NIL_P(rname) ? NULL : StringValueCStr(rname); /* NULL: looked up on error */
|
|
1104
1244
|
GetCArray(self, ca);
|
|
1105
1245
|
|
|
@@ -1140,22 +1280,16 @@ static const struct {
|
|
|
1140
1280
|
{ "cmplx128", CA_CMPLX128 },
|
|
1141
1281
|
{ "cmplx256", CA_CMPLX256 }, /* reserved (retired in 3.0); ca_valid[15]=0 */
|
|
1142
1282
|
{ "object", CA_OBJECT },
|
|
1143
|
-
{ "byte", CA_UINT8 },
|
|
1144
|
-
{ "short", CA_INT16 },
|
|
1145
|
-
{ "int", CA_INT32 },
|
|
1146
|
-
{ "float", CA_FLOAT32 },
|
|
1147
|
-
{ "double", CA_FLOAT64 },
|
|
1148
|
-
{ "complex", CA_CMPLX64 },
|
|
1149
|
-
{ "dcomplex", CA_CMPLX128 },
|
|
1150
1283
|
{ NULL, CA_NONE },
|
|
1151
1284
|
};
|
|
1152
1285
|
|
|
1153
1286
|
|
|
1154
1287
|
|
|
1288
|
+
/* recursion: re-enters once, with a Symbol as a String */
|
|
1155
1289
|
int8_t
|
|
1156
|
-
rb_ca_guess_type (VALUE obj)
|
|
1290
|
+
rb_ca_guess_type (volatile VALUE obj)
|
|
1157
1291
|
{
|
|
1158
|
-
VALUE inspect;
|
|
1292
|
+
volatile VALUE inspect;
|
|
1159
1293
|
|
|
1160
1294
|
if ( TYPE(obj) == T_FIXNUM ) {
|
|
1161
1295
|
/* Check before narrowing to int8_t, so the message names the id given. */
|
|
@@ -1193,6 +1327,28 @@ rb_ca_guess_type (VALUE obj)
|
|
|
1193
1327
|
ca_calling_method_name(), StringValuePtr(inspect));
|
|
1194
1328
|
}
|
|
1195
1329
|
|
|
1330
|
+
/* A data_type given from Ruby is named (a Symbol, a String or a data
|
|
1331
|
+
class); the number behind it is the C enum, which C code passes and Ruby
|
|
1332
|
+
does not. Called by the methods that take a data_type from Ruby, not by
|
|
1333
|
+
rb_ca_guess_type, which C callers reach with a number. */
|
|
1334
|
+
void
|
|
1335
|
+
ca_refuse_type_number (VALUE rtype)
|
|
1336
|
+
{
|
|
1337
|
+
if ( ! RB_INTEGER_TYPE_P(rtype) ) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
if ( FIXNUM_P(rtype) && FIX2LONG(rtype) > CA_NONE &&
|
|
1341
|
+
FIX2LONG(rtype) < CA_NTYPE && ca_valid[FIX2LONG(rtype)] ) {
|
|
1342
|
+
rb_raise(rb_eArgError,
|
|
1343
|
+
"%s: data_type %"PRIsVALUE" is a type number; name the type (%"PRIsVALUE")",
|
|
1344
|
+
ca_calling_method_name(), rtype,
|
|
1345
|
+
rb_inspect(ID2SYM(ca_data_type_sym[FIX2LONG(rtype)])));
|
|
1346
|
+
}
|
|
1347
|
+
rb_raise(rb_eArgError,
|
|
1348
|
+
"%s: data_type %"PRIsVALUE" is a number; name the type (a Symbol such as :int32)",
|
|
1349
|
+
ca_calling_method_name(), rtype);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1196
1352
|
void
|
|
1197
1353
|
rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
1198
1354
|
int8_t *data_type, ca_size_t *bytes)
|
|
@@ -1213,8 +1369,19 @@ rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
|
1213
1369
|
}
|
|
1214
1370
|
}
|
|
1215
1371
|
else {
|
|
1216
|
-
|
|
1372
|
+
CA_CHECK_DATA_TYPE(*data_type);
|
|
1217
1373
|
*bytes = ca_sizeof[*data_type];
|
|
1374
|
+
/* A width is chosen only for :fixlen; another type has its own. 0
|
|
1375
|
+
(the internal callers' "none") and the type's own width are no
|
|
1376
|
+
choice and are taken. */
|
|
1377
|
+
if ( ! NIL_P(rbytes) ) {
|
|
1378
|
+
ca_size_t given = ca_integer_arg(rbytes, "bytes", NULL);
|
|
1379
|
+
if ( given != 0 && given != *bytes ) {
|
|
1380
|
+
rb_raise(rb_eArgError, "%s: bytes: is for :fixlen, not %"PRIsVALUE,
|
|
1381
|
+
ca_calling_method_name(),
|
|
1382
|
+
rb_inspect(ID2SYM(ca_data_type_sym[*data_type])));
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1218
1385
|
}
|
|
1219
1386
|
}
|
|
1220
1387
|
|
|
@@ -1229,9 +1396,9 @@ rb_ca_s_guess_type_and_bytes (int argc, VALUE *argv, VALUE klass)
|
|
|
1229
1396
|
VALUE rtype, rbytes;
|
|
1230
1397
|
int8_t data_type;
|
|
1231
1398
|
ca_size_t bytes;
|
|
1232
|
-
rb_scan_args(argc, argv, "11",
|
|
1399
|
+
rb_scan_args(argc, argv, "11", &rtype, &rbytes);
|
|
1233
1400
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
|
1234
|
-
return
|
|
1401
|
+
return rb_ary_new_from_args(2, INT2NUM(data_type), SIZE2NUM(bytes));
|
|
1235
1402
|
}
|
|
1236
1403
|
|
|
1237
1404
|
/* Takes the trailing keyword Hash off argv when the caller passed keywords.
|
|
@@ -1327,7 +1494,7 @@ rb_scan_options (VALUE ropt, const char *spec_in, ...)
|
|
|
1327
1494
|
has_option = 1;
|
|
1328
1495
|
}
|
|
1329
1496
|
else if ( ! NIL_P(ropt) ) {
|
|
1330
|
-
VALUE inspect = rb_inspect(ropt);
|
|
1497
|
+
volatile VALUE inspect = rb_inspect(ropt);
|
|
1331
1498
|
rb_raise(rb_eArgError,
|
|
1332
1499
|
"<%s> is invalid option specifier",
|
|
1333
1500
|
StringValuePtr(inspect));
|
|
@@ -1360,7 +1527,7 @@ rb_scan_options (VALUE ropt, const char *spec_in, ...)
|
|
|
1360
1527
|
int found = 0;
|
|
1361
1528
|
/* A value is read by Symbol above, so only a Symbol can name a key. */
|
|
1362
1529
|
if ( SYMBOL_P(key) ) {
|
|
1363
|
-
VALUE kname = rb_sym2str(key);
|
|
1530
|
+
volatile VALUE kname = rb_sym2str(key);
|
|
1364
1531
|
const char *kn = StringValueCStr(kname);
|
|
1365
1532
|
long kn_len = RSTRING_LEN(kname);
|
|
1366
1533
|
sp = spec_in;
|
|
@@ -1409,7 +1576,7 @@ rb_set_options (VALUE ropt, const char *spec_in, ...)
|
|
|
1409
1576
|
has_option = 1;
|
|
1410
1577
|
}
|
|
1411
1578
|
else if ( ! NIL_P(ropt) ) {
|
|
1412
|
-
VALUE inspect = rb_inspect(ropt);
|
|
1579
|
+
volatile VALUE inspect = rb_inspect(ropt);
|
|
1413
1580
|
rb_raise(rb_eArgError,
|
|
1414
1581
|
"<%s> is invalid option specifier",
|
|
1415
1582
|
StringValuePtr(inspect));
|
|
@@ -1500,9 +1667,6 @@ Init_carray_utils (void)
|
|
|
1500
1667
|
rb_nativethread_lock_initialize(&ca_id_names_lock);
|
|
1501
1668
|
rb_nativethread_lock_initialize(&ca_iseq_to_a_lock);
|
|
1502
1669
|
id_answering = rb_intern("__carray_answering_method__");
|
|
1503
|
-
id_begin = rb_intern("begin");
|
|
1504
|
-
id_end = rb_intern("end");
|
|
1505
|
-
id_excl_end = rb_intern("exclude_end?");
|
|
1506
1670
|
|
|
1507
1671
|
rb_define_private_method(rb_singleton_class(rb_cCArray),
|
|
1508
1672
|
"instruction_sequence_to_a",
|
|
@@ -1517,7 +1681,7 @@ Init_carray_utils (void)
|
|
|
1517
1681
|
rb_define_singleton_method(rb_cCArray, "__present_cells_needed_per_result_cell__",
|
|
1518
1682
|
rb_ca_s_min_count_need, 3);
|
|
1519
1683
|
rb_define_singleton_method(rb_cCArray, "__fill_undefined_result_cells__",
|
|
1520
|
-
rb_ca_s_reduce_fill,
|
|
1684
|
+
rb_ca_s_reduce_fill, -1);
|
|
1521
1685
|
rb_define_private_method(rb_singleton_class(rb_cCArray), "library_root=",
|
|
1522
1686
|
rb_ca_s_set_library_root, 1);
|
|
1523
1687
|
rb_define_singleton_method(rb_cCArray, "__name_errors_after_method__",
|