carray 3.0.5 → 3.0.7
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/CHANGELOG.md +343 -0
- data/README.md +25 -4
- data/carray.gemspec +3 -2
- data/ext/ca_axis_dispatch.c +6 -0
- data/ext/ca_axis_group.c +7 -7
- data/ext/ca_binop_dispatch.c +8 -0
- data/ext/ca_binop_dispatch.h +1 -0
- data/ext/ca_categorical_iterator.c +14 -14
- data/ext/ca_kernel_iterator.c +116 -231
- data/ext/ca_kernel_iterator.h +416 -258
- data/ext/ca_obj_array.c +4 -4
- data/ext/ca_obj_bincmp.c +28 -4
- data/ext/ca_obj_binop.c +46 -12
- data/ext/ca_obj_bitarray.c +2 -4
- data/ext/ca_obj_bitfield.c +88 -4
- data/ext/ca_obj_byte_swap.c +4 -4
- data/ext/ca_obj_const_string.c +422 -257
- data/ext/ca_obj_face.c +73 -33
- data/ext/ca_obj_fake.c +114 -13
- data/ext/ca_obj_farray.c +7 -1
- data/ext/ca_obj_fixlen_string.c +51 -17
- data/ext/ca_obj_grid.c +179 -19
- data/ext/ca_obj_meld.c +74 -118
- data/ext/ca_obj_moncmp.c +9 -1
- data/ext/ca_obj_monop.c +100 -36
- data/ext/ca_obj_object.c +63 -29
- data/ext/ca_obj_reduce.c +17 -5
- data/ext/ca_obj_refer.c +162 -23
- data/ext/ca_obj_remap.c +69 -10
- data/ext/ca_obj_repeat.c +1 -1
- data/ext/ca_obj_roll.c +3 -4
- data/ext/ca_obj_select.c +12 -7
- data/ext/ca_obj_select_axis.c +9 -6
- data/ext/ca_obj_shift.c +1 -0
- data/ext/ca_obj_stack.c +315 -116
- data/ext/ca_obj_stride.c +177 -53
- data/ext/ca_obj_string.c +20 -4
- data/ext/ca_obj_tile.c +3 -4
- data/ext/ca_obj_triop.c +24 -13
- data/ext/ca_obj_window.c +23 -15
- data/ext/ca_op_ipower.c +71 -23
- data/ext/ca_op_powi.h +6 -29
- data/ext/ca_sort_kernels.h +3 -0
- data/ext/ca_sweep_engine.c +90 -23
- data/ext/ca_sweep_engine.h +5 -6
- data/ext/caframe_csv_reader.c +2 -2
- data/ext/carray.h +5 -2
- data/ext/carray_access.c +125 -103
- data/ext/carray_address_basis.c +209 -1
- data/ext/carray_attribute.c +8 -0
- data/ext/carray_broadcast.c +5 -6
- data/ext/carray_build_flags.h +1 -1
- data/ext/carray_call_cfunc.c +5 -8
- data/ext/carray_cast.c +319 -48
- data/ext/carray_cast_func.rb +37 -5
- data/ext/carray_conversion.c +65 -7
- data/ext/carray_copy.c +24 -0
- data/ext/carray_core.c +874 -72
- data/ext/carray_count.c +28 -9
- data/ext/carray_element.c +22 -12
- data/ext/carray_factorize.c +11 -11
- data/ext/carray_histogram.c +27 -5
- data/ext/carray_index_classifier.c +7 -5
- data/ext/carray_internal.h +241 -12
- data/ext/carray_kernels_bincmp.c +2007 -3
- data/ext/carray_kernels_binop.c +25502 -5336
- data/ext/carray_kernels_init.c +22 -22
- data/ext/carray_kernels_monop.c +10739 -3771
- data/ext/carray_kernels_reduce_aggregate.c +4429 -702
- data/ext/carray_kernels_reduce_boolean.c +1533 -15
- data/ext/carray_kernels_reduce_cumulative.c +1808 -248
- data/ext/carray_kernels_reduce_extreme.c +4508 -511
- data/ext/carray_kernels_reduce_variance.c +2284 -152
- data/ext/carray_kernels_scan.c +240 -240
- data/ext/carray_kernels_search.c +4211 -264
- data/ext/carray_kernels_sort.c +367 -450
- data/ext/carray_lazy.c +63 -1
- data/ext/carray_loop.c +10 -3
- data/ext/carray_mask.c +247 -149
- data/ext/carray_median_percentile.c +17 -12
- data/ext/carray_memory_view.c +54 -29
- data/ext/carray_operator.c +219 -55
- data/ext/carray_order.c +55 -11
- data/ext/carray_partition.c +1 -1
- data/ext/carray_random.c +5 -2
- data/ext/carray_round.c +24 -1
- data/ext/carray_scatter.c +4 -0
- data/ext/carray_segment.c +1 -1
- data/ext/carray_slab.c +110 -25
- data/ext/carray_sort.c +7 -4
- data/ext/carray_sort_kernel.c +24 -0
- data/ext/carray_struct.c +21 -6
- data/ext/carray_test.c +154 -53
- data/ext/carray_time_text.c +8 -2
- data/ext/carray_utils.c +124 -54
- data/ext/extconf.rb +11 -0
- data/ext/mk_call_cfunc.rb +6 -11
- data/ext/mkkernel.rb +383 -121
- data/ext/ruby_carray.c +4 -1
- data/ext/version.h +4 -4
- data/lib/carray/attribute.rb +25 -1
- data/lib/carray/autoload_carray.rb +3 -3
- data/lib/carray/autoload_method_extension.rb +5 -3
- data/lib/carray/axis_group.rb +22 -13
- data/lib/carray/basics.rb +27 -9
- data/lib/carray/bincount_nd.rb +8 -2
- data/lib/carray/block_iterator.rb +65 -24
- data/lib/carray/categorical.rb +27 -16
- data/lib/carray/categorical_iterator.rb +4 -3
- data/lib/carray/complex.rb +2 -2
- data/lib/carray/conditional.rb +55 -6
- data/lib/carray/const_string.rb +74 -0
- data/lib/carray/construct.rb +2 -2
- data/lib/carray/core_extensions.rb +19 -68
- data/lib/carray/data_type_extension.rb +1 -0
- data/lib/carray/fixlen_string.rb +83 -1
- data/lib/carray/frame/column_verbs.rb +102 -16
- data/lib/carray/frame/concat.rb +50 -6
- data/lib/carray/frame/convert.rb +19 -0
- data/lib/carray/frame/csv_parser.rb +45 -36
- data/lib/carray/frame/describe.rb +4 -2
- data/lib/carray/frame/frame.rb +436 -83
- data/lib/carray/frame/group.rb +731 -78
- data/lib/carray/frame/io.rb +216 -73
- data/lib/carray/frame/join.rb +166 -43
- data/lib/carray/frame/records.rb +9 -7
- data/lib/carray/frame/reshape.rb +109 -11
- data/lib/carray/frame/sort.rb +57 -9
- data/lib/carray/frame/verbs.rb +448 -60
- data/lib/carray/frame/windows.rb +71 -9
- data/lib/carray/fuse_source.rb +4 -2
- data/lib/carray/inspect.rb +7 -2
- data/lib/carray/iterator.rb +40 -0
- data/lib/carray/key_windows.rb +10 -4
- data/lib/carray/lazy.rb +28 -24
- data/lib/carray/mask_gap_fill.rb +37 -17
- data/lib/carray/meld_reduce.rb +1 -1
- data/lib/carray/methods/bin.rb +3 -0
- data/lib/carray/methods/choose.rb +3 -2
- data/lib/carray/methods/composition.rb +1 -1
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +4 -1
- data/lib/carray/methods/is_in.rb +23 -3
- data/lib/carray/methods/locate_addr.rb +63 -12
- data/lib/carray/methods/meshgrid.rb +3 -1
- data/lib/carray/methods/repeat.rb +11 -1
- data/lib/carray/record_order.rb +35 -6
- data/lib/carray/runtime.rb +57 -8
- data/lib/carray/segment_iterator.rb +42 -24
- data/lib/carray/serialize.rb +56 -17
- data/lib/carray/slab_iterator.rb +1 -1
- data/lib/carray/stack.rb +21 -9
- data/lib/carray/string.rb +6 -6
- data/lib/carray/string_operation_extension.rb +25 -4
- data/lib/carray/struct_builder.rb +4 -1
- data/lib/carray/time.rb +195 -46
- data/lib/carray/window_iterator.rb +64 -16
- data/yard-stubs/ca_obj_array.rb +26 -1
- data/yard-stubs/ca_obj_bitfield.rb +4 -1
- data/yard-stubs/ca_obj_refer.rb +3 -0
- data/yard-stubs/ca_obj_window.rb +2 -1
- data/yard-stubs/carray_access.rb +4 -2
- data/yard-stubs/carray_cast.rb +14 -5
- data/yard-stubs/carray_conversion.rb +8 -2
- data/yard-stubs/carray_count.rb +6 -3
- data/yard-stubs/carray_mask.rb +20 -1
- data/yard-stubs/carray_math.rb +36 -16
- data/yard-stubs/carray_memory_view.rb +7 -0
- data/yard-stubs/carray_order.rb +6 -0
- data/yard-stubs/carray_scatter.rb +2 -1
- data/yard-stubs/carray_test.rb +23 -7
- metadata +17 -3
|
@@ -138,10 +138,11 @@ mp_keep_axis_full_f64 (VALUE self, double v, int is_undef)
|
|
|
138
138
|
/* [shared] all-UNDEF reduced CA_FLOAT64 output for a zero-length reduction
|
|
139
139
|
axis. An order statistic of no elements has no value, so every reduced
|
|
140
140
|
cell is masked -- matching mean / min (which return UNDEF cells), not a
|
|
141
|
-
raise
|
|
142
|
-
|
|
141
|
+
raise, unless fill_value (nil for none) gives the cells a value, as it
|
|
142
|
+
does for a fiber with no present cell. keep_axis controls whether the
|
|
143
|
+
reduced axis is dropped or kept as a length-1 axis. */
|
|
143
144
|
static VALUE
|
|
144
|
-
mp_axis_all_masked (VALUE self, long axis, int keep_axis)
|
|
145
|
+
mp_axis_all_masked (VALUE self, long axis, VALUE fill_value, int keep_axis)
|
|
145
146
|
{
|
|
146
147
|
int8_t ax = (int8_t) axis;
|
|
147
148
|
CArray *ca;
|
|
@@ -150,6 +151,10 @@ mp_axis_all_masked (VALUE self, long axis, int keep_axis)
|
|
|
150
151
|
(ca->data_type == CA_OBJECT) ? CA_OBJECT
|
|
151
152
|
: CA_FLOAT64,
|
|
152
153
|
keep_axis);
|
|
154
|
+
if ( ! NIL_P(fill_value) ) {
|
|
155
|
+
rb_ca_store_all(out, fill_value);
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
153
158
|
CArray *co;
|
|
154
159
|
GetCArray(out, co);
|
|
155
160
|
ca_create_mask(co);
|
|
@@ -680,7 +685,7 @@ percentile_object_axis (VALUE self, VALUE pers, long axis, VALUE method)
|
|
|
680
685
|
is applied by the entry (rb_ca_percentile_m), so build reduced. */
|
|
681
686
|
VALUE res = rb_ary_new_capa(npers);
|
|
682
687
|
for ( long i = 0; i < npers; i++ )
|
|
683
|
-
rb_ary_push(res, mp_axis_all_masked(self, axis, 0));
|
|
688
|
+
rb_ary_push(res, mp_axis_all_masked(self, axis, Qnil, 0));
|
|
684
689
|
return res;
|
|
685
690
|
}
|
|
686
691
|
|
|
@@ -774,7 +779,7 @@ percentile_object_axis_masked (VALUE self, VALUE pers, long axis, VALUE method,
|
|
|
774
779
|
if ( M == 0 ) {
|
|
775
780
|
VALUE res = rb_ary_new_capa(npers);
|
|
776
781
|
for ( long i = 0; i < npers; i++ )
|
|
777
|
-
rb_ary_push(res, mp_axis_all_masked(self, axis, keep_axis));
|
|
782
|
+
rb_ary_push(res, mp_axis_all_masked(self, axis, fill_value, keep_axis));
|
|
778
783
|
return res;
|
|
779
784
|
}
|
|
780
785
|
|
|
@@ -904,13 +909,13 @@ rb_ca_median_m_body (int argc, VALUE *argv, VALUE self)
|
|
|
904
909
|
if ( !NIL_P(raxis) ) {
|
|
905
910
|
long axis = rb_ca_normalize_axis_value(self, raxis, "median");
|
|
906
911
|
long n = (long) ca->dim[axis];
|
|
907
|
-
if ( n == 0 ) return mp_axis_all_masked(self, axis, keep_axis);
|
|
912
|
+
if ( n == 0 ) return mp_axis_all_masked(self, axis, fill_value, keep_axis);
|
|
908
913
|
/* mask / min_count / fill_value require the per-fiber select (each fiber
|
|
909
914
|
has its own n_present); the plain partition path assumes a uniform n.
|
|
910
|
-
Switch
|
|
915
|
+
Switch ca_fast_path(CA_SC_MEDIAN_PARTITION): off, the per-fiber select. */
|
|
911
916
|
VALUE res;
|
|
912
917
|
if ( RTEST(rb_ca_has_mask(self)) || min_count > 0 || !NIL_P(fill_value)
|
|
913
|
-
|| !
|
|
918
|
+
|| ! ca_fast_path(CA_SC_MEDIAN_PARTITION) )
|
|
914
919
|
res = is_obj
|
|
915
920
|
? median_object_axis_masked(self, axis, min_count, fill_value, keep_axis)
|
|
916
921
|
: median_axis_masked(self, axis, min_count, fill_value, keep_axis);
|
|
@@ -1138,7 +1143,7 @@ pct_axis (VALUE self, VALUE pers_ary, long axis, VALUE method, int keep_axis)
|
|
|
1138
1143
|
/* zero-length axis: every requested p reduces to an all-UNDEF cell. */
|
|
1139
1144
|
VALUE res = rb_ary_new_capa(npers);
|
|
1140
1145
|
for ( long i = 0; i < npers; i++ )
|
|
1141
|
-
rb_ary_push(res, mp_axis_all_masked(self, axis, keep_axis));
|
|
1146
|
+
rb_ary_push(res, mp_axis_all_masked(self, axis, Qnil, keep_axis));
|
|
1142
1147
|
return res;
|
|
1143
1148
|
}
|
|
1144
1149
|
|
|
@@ -1167,7 +1172,7 @@ pct_axis_masked (VALUE self, VALUE pers_ary, long axis, VALUE method,
|
|
|
1167
1172
|
if ( M == 0 ) {
|
|
1168
1173
|
VALUE res = rb_ary_new_capa(npers);
|
|
1169
1174
|
for ( long i = 0; i < npers; i++ )
|
|
1170
|
-
rb_ary_push(res, mp_axis_all_masked(self, axis, keep_axis));
|
|
1175
|
+
rb_ary_push(res, mp_axis_all_masked(self, axis, fill_value, keep_axis));
|
|
1171
1176
|
return res;
|
|
1172
1177
|
}
|
|
1173
1178
|
|
|
@@ -1364,9 +1369,9 @@ rb_ca_percentile_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
1364
1369
|
/* mask / min_count / fill_value require the per-fiber select (each fiber
|
|
1365
1370
|
has its own n_present); the plain partition/sort path assumes a
|
|
1366
1371
|
uniform n. These paths bake keep_axis into the reduced output.
|
|
1367
|
-
Switch
|
|
1372
|
+
Switch ca_fast_path(CA_SC_PERCENTILE_PARTITION): off, the per-fiber select. */
|
|
1368
1373
|
int per_fiber = RTEST(rb_ca_has_mask(self)) || min_count > 0
|
|
1369
|
-
|| !NIL_P(fill_value) || !
|
|
1374
|
+
|| !NIL_P(fill_value) || ! ca_fast_path(CA_SC_PERCENTILE_PARTITION);
|
|
1370
1375
|
if ( !is_obj ) {
|
|
1371
1376
|
result = per_fiber
|
|
1372
1377
|
? pct_axis_masked(self, pers, axis, method, min_count, fill_value, keep_axis)
|
data/ext/carray_memory_view.c
CHANGED
|
@@ -202,7 +202,9 @@ ca_mv_record_member_spec (VALUE info, char *out, size_t outlen,
|
|
|
202
202
|
a member it has no item for (see above), or members that overlap or come
|
|
203
203
|
out of offset order (a union).
|
|
204
204
|
|
|
205
|
-
The result is frozen and cached on the data_class.
|
|
205
|
+
The result is frozen and cached on the data_class. Only the main Ractor
|
|
206
|
+
may set an instance variable on a class, so another Ractor builds the
|
|
207
|
+
format each time until the main one has cached it. It is an ordinary
|
|
206
208
|
String that compaction can move, so a view takes a copy of its bytes
|
|
207
209
|
rather than its pointer (ca_mv_get). */
|
|
208
210
|
static VALUE
|
|
@@ -245,11 +247,11 @@ ca_mv_struct_format_for_data_class (VALUE data_class)
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
rb_obj_freeze(buf);
|
|
248
|
-
rb_ivar_set(data_class, iv, buf);
|
|
250
|
+
if (ca_in_main_ractor()) rb_ivar_set(data_class, iv, buf);
|
|
249
251
|
return buf;
|
|
250
252
|
|
|
251
253
|
unsupported:
|
|
252
|
-
rb_ivar_set(data_class, iv, Qfalse);
|
|
254
|
+
if (ca_in_main_ractor()) rb_ivar_set(data_class, iv, Qfalse);
|
|
253
255
|
return Qnil;
|
|
254
256
|
}
|
|
255
257
|
|
|
@@ -447,6 +449,22 @@ ca_mv_probe_data_type (VALUE obj)
|
|
|
447
449
|
return data_type;
|
|
448
450
|
}
|
|
449
451
|
|
|
452
|
+
/* True when format is a struct of several members that exactly describes an
|
|
453
|
+
item of item_size bytes. A consumer takes such items as raw bytes: the
|
|
454
|
+
format names no members to rebuild a record from. */
|
|
455
|
+
static bool
|
|
456
|
+
ca_mv_format_is_struct (const char *format, ssize_t item_size)
|
|
457
|
+
{
|
|
458
|
+
rb_memory_view_item_component_t *members = NULL;
|
|
459
|
+
size_t n_members = 0;
|
|
460
|
+
const char *err = NULL;
|
|
461
|
+
ssize_t size;
|
|
462
|
+
if ( format == NULL ) return false;
|
|
463
|
+
size = rb_memory_view_parse_item_format(format, &members, &n_members, &err);
|
|
464
|
+
if ( members != NULL ) xfree(members);
|
|
465
|
+
return size == item_size && n_members >= 2;
|
|
466
|
+
}
|
|
467
|
+
|
|
450
468
|
/* Per-element byte width for consumer-side wrap/from CArray allocation.
|
|
451
469
|
For numeric types it is `ca_sizeof[data_type]`; for CA_FIXLEN it is the
|
|
452
470
|
MemoryView item_size, since fixlen has no compile-time element width. */
|
|
@@ -509,7 +527,7 @@ ca_mv_alloc_strides_contiguous (CArray *ca, ssize_t *shape, bool row_major)
|
|
|
509
527
|
|
|
510
528
|
typedef struct {
|
|
511
529
|
int depth; /* 0 = the view itself, 1 = parent, 2 = grand-, ... */
|
|
512
|
-
|
|
530
|
+
VALUE klass; /* class of the offending link (nil: unknown) */
|
|
513
531
|
const char *reason; /* short explanation */
|
|
514
532
|
int face; /* refused because it is a Face: a copy is
|
|
515
533
|
refused too, so no copy is suggested */
|
|
@@ -526,11 +544,10 @@ ca_mv_is_castride_family (CArray *ca)
|
|
|
526
544
|
return ca_func[ca->obj_type].attach == ca_stride_func.attach;
|
|
527
545
|
}
|
|
528
546
|
|
|
529
|
-
static
|
|
530
|
-
|
|
547
|
+
static VALUE
|
|
548
|
+
ca_mv_class_of (CArray *ca)
|
|
531
549
|
{
|
|
532
|
-
|
|
533
|
-
return NIL_P(klass) ? "(unknown)" : rb_class2name(klass);
|
|
550
|
+
return ca_class[ca->obj_type];
|
|
534
551
|
}
|
|
535
552
|
|
|
536
553
|
static const char *
|
|
@@ -595,7 +612,7 @@ ca_mv_compose_to_entity (CArray *ca, ca_mv_reject_t *rej,
|
|
|
595
612
|
if (ca_is_face(ca)) {
|
|
596
613
|
if (! ca_face_memory_view_exportable(ca)) {
|
|
597
614
|
rej->depth = 0;
|
|
598
|
-
rej->
|
|
615
|
+
rej->klass = ca_mv_class_of(ca);
|
|
599
616
|
rej->reason = "a Face whose storage bytes do not carry its values "
|
|
600
617
|
"without the Face; export its storage instead "
|
|
601
618
|
"(e.g. .ticks, .codes)";
|
|
@@ -607,7 +624,7 @@ ca_mv_compose_to_entity (CArray *ca, ca_mv_reject_t *rej,
|
|
|
607
624
|
if (ca_is_entity(ca)) {
|
|
608
625
|
if (! ca_mv_is_core_entity(ca)) {
|
|
609
626
|
rej->depth = 0;
|
|
610
|
-
rej->
|
|
627
|
+
rej->klass = ca_mv_class_of(ca);
|
|
611
628
|
rej->reason = "installed outside the core; its bytes are not "
|
|
612
629
|
"exported";
|
|
613
630
|
return false;
|
|
@@ -618,7 +635,7 @@ ca_mv_compose_to_entity (CArray *ca, ca_mv_reject_t *rej,
|
|
|
618
635
|
}
|
|
619
636
|
if (!ca_mv_is_castride_family(ca)) {
|
|
620
637
|
rej->depth = 0;
|
|
621
|
-
rej->
|
|
638
|
+
rej->klass = ca_mv_class_of(ca);
|
|
622
639
|
rej->reason = ca_mv_reject_reason_for(ca);
|
|
623
640
|
return false;
|
|
624
641
|
}
|
|
@@ -626,7 +643,7 @@ ca_mv_compose_to_entity (CArray *ca, ca_mv_reject_t *rej,
|
|
|
626
643
|
ca_stride_compose_to_root((CAStride *) ca, &root, out_strides, out_base);
|
|
627
644
|
if (!ca_is_entity(root)) {
|
|
628
645
|
rej->depth = -1;
|
|
629
|
-
rej->
|
|
646
|
+
rej->klass = ca_mv_class_of(root);
|
|
630
647
|
if (ca_mv_is_castride_family(root)) {
|
|
631
648
|
rej->reason = "CAStride chain stride pattern does not compose "
|
|
632
649
|
"linearly into entity (e.g. reshape across non-contig)";
|
|
@@ -637,7 +654,7 @@ ca_mv_compose_to_entity (CArray *ca, ca_mv_reject_t *rej,
|
|
|
637
654
|
}
|
|
638
655
|
if (! ca_mv_is_core_entity(root)) {
|
|
639
656
|
rej->depth = -1;
|
|
640
|
-
rej->
|
|
657
|
+
rej->klass = ca_mv_class_of(root);
|
|
641
658
|
rej->reason = "installed outside the core; its bytes are not exported";
|
|
642
659
|
return false;
|
|
643
660
|
}
|
|
@@ -702,7 +719,7 @@ ca_mv_fixlen_format (ca_size_t bytes)
|
|
|
702
719
|
{
|
|
703
720
|
st_data_t found;
|
|
704
721
|
char *fmt;
|
|
705
|
-
|
|
722
|
+
ca_native_lock_without_gvl(&ca_mv_fixlen_formats_lock);
|
|
706
723
|
if ( st_lookup(ca_mv_fixlen_formats, (st_data_t) bytes, &found) ) {
|
|
707
724
|
rb_nativethread_lock_unlock(&ca_mv_fixlen_formats_lock);
|
|
708
725
|
return (const char *) found;
|
|
@@ -710,7 +727,8 @@ ca_mv_fixlen_format (ca_size_t bytes)
|
|
|
710
727
|
rb_nativethread_lock_unlock(&ca_mv_fixlen_formats_lock);
|
|
711
728
|
fmt = ALLOC_N(char, 24);
|
|
712
729
|
snprintf(fmt, 24, "%llds", (long long) bytes);
|
|
713
|
-
|
|
730
|
+
/* lock: st_insert can run a GC, which does not take this lock */
|
|
731
|
+
ca_native_lock_without_gvl(&ca_mv_fixlen_formats_lock);
|
|
714
732
|
if ( st_lookup(ca_mv_fixlen_formats, (st_data_t) bytes, &found) ) {
|
|
715
733
|
xfree(fmt);
|
|
716
734
|
fmt = (char *) found;
|
|
@@ -900,7 +918,7 @@ ca_mv_release (VALUE obj, rb_memory_view_t *view)
|
|
|
900
918
|
}
|
|
901
919
|
|
|
902
920
|
/* ---------------- importer ----------------
|
|
903
|
-
Two-tier API
|
|
921
|
+
Two-tier API:
|
|
904
922
|
|
|
905
923
|
CArray.from_memory_view(obj) -> CArray (copy, independent buffer)
|
|
906
924
|
CArray.wrap_memory_view(obj) -> CAWrap (zero-copy, shared memory)
|
|
@@ -1169,6 +1187,9 @@ ca_mv_holder_take_data (ca_mv_imported_holder_t *h, VALUE src,
|
|
|
1169
1187
|
}
|
|
1170
1188
|
|
|
1171
1189
|
data_type = ca_mv_data_type_from_format(v->format, v->item_size);
|
|
1190
|
+
if ( data_type < 0 && ca_mv_format_is_struct(v->format, v->item_size) ) {
|
|
1191
|
+
data_type = CA_FIXLEN;
|
|
1192
|
+
}
|
|
1172
1193
|
if ( data_type < 0 ) {
|
|
1173
1194
|
rb_raise(rb_eArgError, "unsupported MemoryView format: %s (item_size=%ld)",
|
|
1174
1195
|
v->format, (long) v->item_size);
|
|
@@ -1342,10 +1363,10 @@ ca_mv_wrap_body (VALUE arg)
|
|
|
1342
1363
|
for a class would get something that is not it. */
|
|
1343
1364
|
if ( a->target_class != rb_cCAWrap && ! d->contiguous ) {
|
|
1344
1365
|
rb_raise(rb_eArgError,
|
|
1345
|
-
"%
|
|
1366
|
+
"%"PRIsVALUE" was requested, but this producer is strided, so the result "
|
|
1346
1367
|
"would be a CAStride; pass a row-major contiguous producer, or "
|
|
1347
1368
|
"use CArray.from_memory_view for a copy",
|
|
1348
|
-
|
|
1369
|
+
a->target_class);
|
|
1349
1370
|
}
|
|
1350
1371
|
|
|
1351
1372
|
if ( m != NULL ) {
|
|
@@ -1501,8 +1522,8 @@ rb_ca_s_wrap_memory_view (int argc, VALUE *argv, VALUE klass)
|
|
|
1501
1522
|
target_class = ( klass == rb_cCArray ) ? rb_cCAWrap : klass;
|
|
1502
1523
|
if ( ! RTEST(rb_class_inherited_p(target_class, rb_cCAWrap)) ) {
|
|
1503
1524
|
rb_raise(rb_eTypeError,
|
|
1504
|
-
"wrap_memory_view builds a CAWrap; %
|
|
1505
|
-
|
|
1525
|
+
"wrap_memory_view builds a CAWrap; %"PRIsVALUE" is not a subclass of it",
|
|
1526
|
+
target_class);
|
|
1506
1527
|
}
|
|
1507
1528
|
return ca_mv_wrap(obj, mask_obj, target_class, explicit_data_type, -1, 0);
|
|
1508
1529
|
}
|
|
@@ -1583,8 +1604,8 @@ rb_ca_s_from_memory_view (int argc, VALUE *argv, VALUE klass)
|
|
|
1583
1604
|
if ( klass != rb_cCArray &&
|
|
1584
1605
|
! RTEST(rb_class_inherited_p(klass, rb_cCAWrap)) ) {
|
|
1585
1606
|
rb_raise(rb_eTypeError,
|
|
1586
|
-
"from_memory_view builds a CArray; %
|
|
1587
|
-
|
|
1607
|
+
"from_memory_view builds a CArray; %"PRIsVALUE" cannot be returned from it",
|
|
1608
|
+
klass);
|
|
1588
1609
|
}
|
|
1589
1610
|
ca_mv_import_args_init(&a, obj, mask_obj);
|
|
1590
1611
|
a.explicit_data_type = explicit_data_type;
|
|
@@ -1621,9 +1642,13 @@ rb_ca_s_memory_view_reject_reason (VALUE klass, VALUE obj)
|
|
|
1621
1642
|
"producer cannot express yet (nested struct, "
|
|
1622
1643
|
"CArray template, :fixlen, or :object)");
|
|
1623
1644
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1645
|
+
if (ca->data_type == CA_OBJECT) {
|
|
1646
|
+
return rb_str_new_cstr("an object array holds Ruby objects, not bytes "
|
|
1647
|
+
"a consumer can read; convert it with to_type "
|
|
1648
|
+
"first");
|
|
1649
|
+
}
|
|
1650
|
+
return rb_sprintf("data_type %s has no MemoryView format",
|
|
1651
|
+
ca_type_name[ca->data_type]);
|
|
1627
1652
|
}
|
|
1628
1653
|
if (ca_has_mask(ca)) {
|
|
1629
1654
|
return rb_str_new_cstr("array has a mask; use arr.value (mask-ignoring CARefer) "
|
|
@@ -1636,12 +1661,12 @@ rb_ca_s_memory_view_reject_reason (VALUE klass, VALUE obj)
|
|
|
1636
1661
|
else if (rej.depth == 1) where = "parent";
|
|
1637
1662
|
else where = NULL; /* ancestor[N] */
|
|
1638
1663
|
if (where) {
|
|
1639
|
-
return rb_sprintf("%s is %
|
|
1640
|
-
where, rej.
|
|
1664
|
+
return rb_sprintf("%s is %"PRIsVALUE" (%s); zero-copy wrap not possible.%s",
|
|
1665
|
+
where, NIL_P(rej.klass) ? rb_str_new_cstr("(unknown)") : rej.klass, rej.reason,
|
|
1641
1666
|
rej.face ? "" : " Export arr.copy for a snapshot.");
|
|
1642
1667
|
} else {
|
|
1643
|
-
return rb_sprintf("ancestor[%d] is %
|
|
1644
|
-
rej.depth - 1, rej.
|
|
1668
|
+
return rb_sprintf("ancestor[%d] is %"PRIsVALUE" (%s); zero-copy wrap not possible.%s",
|
|
1669
|
+
rej.depth - 1, NIL_P(rej.klass) ? rb_str_new_cstr("(unknown)") : rej.klass, rej.reason,
|
|
1645
1670
|
rej.face ? "" : " Export arr.copy for a snapshot.");
|
|
1646
1671
|
}
|
|
1647
1672
|
}
|