carray 3.0.2 → 3.0.4
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 +568 -0
- data/README.md +6 -6
- data/carray.gemspec +1 -1
- data/ext/ca_axis_descriptor.h +27 -24
- data/ext/ca_axis_dispatch.c +220 -0
- data/ext/ca_axis_group.c +201 -123
- data/ext/ca_binop_dispatch.c +46 -52
- data/ext/ca_binop_dispatch.h +1 -1
- data/ext/ca_categorical_iterator.c +249 -183
- data/ext/ca_compare.c +7 -12
- data/ext/ca_for_buffer.h +21 -68
- data/ext/ca_group_iter.c +38 -23
- data/ext/ca_kernel_iterator.c +1765 -2076
- data/ext/ca_kernel_iterator.h +584 -566
- data/ext/ca_monop_dispatch.c +86 -63
- data/ext/ca_monop_dispatch.h +5 -0
- data/ext/ca_obj_array.c +223 -56
- data/ext/ca_obj_bincmp.c +172 -138
- data/ext/ca_obj_binop.c +116 -230
- data/ext/ca_obj_bitarray.c +40 -26
- data/ext/ca_obj_bitfield.c +100 -68
- data/ext/ca_obj_block.c +19 -9
- data/ext/ca_obj_byte_swap.c +45 -46
- data/ext/ca_obj_const_string.c +269 -44
- data/ext/ca_obj_face.c +612 -89
- data/ext/ca_obj_face.h +111 -47
- data/ext/ca_obj_fake.c +36 -79
- data/ext/ca_obj_farray.c +7 -3
- data/ext/ca_obj_field.c +33 -8
- data/ext/ca_obj_fixlen_string.c +23 -24
- data/ext/ca_obj_grid.c +541 -210
- data/ext/ca_obj_meld.c +331 -111
- data/ext/ca_obj_moncmp.c +80 -65
- data/ext/ca_obj_monop.c +177 -149
- data/ext/ca_obj_object.c +664 -248
- data/ext/ca_obj_record.c +63 -23
- data/ext/ca_obj_reduce.c +18 -16
- data/ext/ca_obj_refer.c +140 -58
- data/ext/ca_obj_remap.c +85 -24
- data/ext/ca_obj_repeat.c +24 -9
- data/ext/ca_obj_roll.c +121 -16
- data/ext/ca_obj_select.c +61 -58
- data/ext/ca_obj_select_axis.c +73 -107
- data/ext/ca_obj_shift.c +32 -102
- data/ext/ca_obj_stack.c +372 -122
- data/ext/ca_obj_stride.c +348 -140
- data/ext/ca_obj_string.c +88 -22
- data/ext/ca_obj_tile.c +38 -21
- data/ext/ca_obj_time.c +45 -31
- data/ext/ca_obj_timedelta.c +43 -29
- data/ext/ca_obj_transpose.c +17 -6
- data/ext/ca_obj_triop.c +125 -141
- data/ext/ca_obj_window.c +330 -44
- data/ext/ca_op_ipower.c +24 -11
- data/ext/ca_op_powi.h +57 -30
- data/ext/ca_pow5_table.h +656 -0
- data/ext/ca_sort_kernels.h +70 -0
- data/ext/ca_sweep_engine.c +104 -81
- data/ext/ca_sweep_engine.h +7 -20
- data/ext/ca_triop_dispatch.c +4 -1
- data/ext/ca_triop_dispatch.h +5 -2
- data/ext/caframe_csv_reader.c +542 -0
- data/ext/carray.h +241 -92
- data/ext/carray_access.c +608 -276
- data/ext/carray_address_basis.c +494 -97
- data/ext/carray_attribute.c +129 -4
- data/ext/carray_bincount.c +39 -7
- data/ext/carray_broadcast.c +56 -19
- data/ext/carray_build_flags.h +1 -1
- data/ext/carray_call_cfunc.c +108 -28
- data/ext/carray_cast.c +1576 -223
- data/ext/carray_cast_func.rb +77 -24
- data/ext/carray_class.c +4 -3
- data/ext/carray_conversion.c +208 -75
- data/ext/carray_copy.c +82 -24
- data/ext/carray_core.c +646 -162
- data/ext/carray_count.c +171 -88
- data/ext/carray_element.c +94 -60
- data/ext/carray_factorize.c +670 -324
- data/ext/carray_generate.c +260 -83
- data/ext/carray_histogram.c +209 -106
- data/ext/carray_hold.c +14 -16
- data/ext/carray_index_classifier.c +422 -243
- data/ext/carray_internal.h +692 -3
- data/ext/carray_kernels_bincmp.c +7 -0
- data/ext/carray_kernels_binop.c +487 -120
- data/ext/carray_kernels_init.c +653 -50
- data/ext/carray_kernels_moncmp.c +15 -8
- data/ext/carray_kernels_monop.c +99 -43
- data/ext/carray_kernels_reduce_aggregate.c +3925 -6112
- data/ext/carray_kernels_reduce_boolean.c +112 -36
- data/ext/carray_kernels_reduce_cumulative.c +2127 -6903
- data/ext/carray_kernels_reduce_extreme.c +3032 -2892
- data/ext/carray_kernels_reduce_variance.c +439 -500
- data/ext/carray_kernels_scan.c +1097 -488
- data/ext/carray_kernels_search.c +3787 -2176
- data/ext/carray_kernels_sort.c +1200 -920
- data/ext/carray_kernels_triop.c +479 -7
- data/ext/carray_key_windows.c +216 -0
- data/ext/carray_lazy.c +967 -153
- data/ext/carray_loop.c +81 -65
- data/ext/carray_mask.c +910 -324
- data/ext/carray_math_kernel.h +1 -0
- data/ext/carray_median_percentile.c +299 -100
- data/ext/carray_memory_view.c +872 -758
- data/ext/carray_operator.c +1171 -364
- data/ext/carray_order.c +505 -133
- data/ext/carray_partition.c +112 -65
- data/ext/carray_random.c +327 -239
- data/ext/carray_round.c +273 -0
- data/ext/carray_scatter.c +346 -78
- data/ext/carray_segment.c +257 -0
- data/ext/carray_slab.c +249 -86
- data/ext/carray_sort.c +224 -227
- data/ext/carray_sort_kernel.c +8 -1
- data/ext/carray_struct.c +118 -39
- data/ext/carray_test.c +193 -69
- data/ext/carray_time_text.c +1182 -0
- data/ext/carray_undef.c +4 -0
- data/ext/carray_utils.c +579 -113
- data/ext/extconf.rb +27 -2
- data/ext/mk_call_cfunc.rb +19 -4
- data/ext/mk_pow5_table.rb +35 -0
- data/ext/mkkernel.rb +1202 -1014
- data/ext/ruby_carray.c +17 -5
- data/ext/version.h +4 -4
- data/ext/version.rb +4 -2
- data/lib/carray/attribute.rb +160 -17
- data/lib/carray/autoload_carray.rb +23 -27
- data/lib/carray/autoload_method_extension.rb +20 -5
- data/lib/carray/axis_group.rb +360 -63
- data/lib/carray/basics.rb +162 -28
- data/lib/carray/bincount_nd.rb +18 -2
- data/lib/carray/block_iterator.rb +231 -58
- data/lib/carray/boolean_reduce.rb +34 -42
- data/lib/carray/categorical.rb +242 -52
- data/lib/carray/categorical_iterator.rb +437 -827
- data/lib/carray/complex.rb +41 -34
- data/lib/carray/conditional.rb +150 -14
- data/lib/carray/const_string.rb +59 -4
- data/lib/carray/construct.rb +15 -11
- data/lib/carray/data_type_extension.rb +1 -0
- data/lib/carray/distance_limit.rb +77 -0
- data/lib/carray/fixlen_string.rb +7 -1
- data/lib/carray/frame/column_verbs.rb +70 -0
- data/lib/carray/frame/concat.rb +157 -6
- data/lib/carray/frame/convert.rb +82 -7
- data/lib/carray/frame/csv_parser.rb +688 -87
- data/lib/carray/frame/describe.rb +80 -0
- data/lib/carray/frame/frame.rb +369 -45
- data/lib/carray/frame/group.rb +631 -90
- data/lib/carray/frame/io.rb +506 -79
- data/lib/carray/frame/join.rb +411 -62
- data/lib/carray/frame/records.rb +116 -19
- data/lib/carray/frame/reshape.rb +455 -0
- data/lib/carray/frame/sort.rb +30 -18
- data/lib/carray/frame/verbs.rb +868 -61
- data/lib/carray/frame/windows.rb +117 -0
- data/lib/carray/frame.rb +4 -0
- data/lib/carray/fuse_source.rb +118 -2
- data/lib/carray/fusion.rb +257 -42
- data/lib/carray/histogram.rb +6 -1
- data/lib/carray/inspect.rb +54 -13
- data/lib/carray/iterator.rb +99 -9
- data/lib/carray/key_windows.rb +620 -0
- data/lib/carray/lazy.rb +216 -193
- data/lib/carray/mask_gap_fill.rb +112 -92
- data/lib/carray/math.rb +32 -19
- data/lib/carray/meld_reduce.rb +52 -21
- data/lib/carray/methods/align_addr.rb +8 -4
- data/lib/carray/methods/bin.rb +26 -18
- data/lib/carray/methods/bincount.rb +18 -2
- data/lib/carray/methods/bit_string.rb +15 -4
- data/lib/carray/methods/choose.rb +16 -3
- data/lib/carray/methods/composition.rb +18 -10
- data/lib/carray/methods/factorize.rb +2 -2
- data/lib/carray/methods/gather_nd.rb +25 -5
- data/lib/carray/methods/insert_block.rb +9 -14
- data/lib/carray/methods/is_between.rb +59 -0
- data/lib/carray/methods/is_in.rb +140 -10
- data/lib/carray/methods/join.rb +2 -7
- data/lib/carray/methods/lag.rb +49 -0
- data/lib/carray/methods/locate_addr.rb +182 -45
- data/lib/carray/methods/mode.rb +18 -1
- data/lib/carray/methods/nunique.rb +11 -6
- data/lib/carray/methods/repeat.rb +1 -20
- data/lib/carray/methods/resize.rb +21 -23
- data/lib/carray/methods/snap.rb +34 -12
- data/lib/carray/methods/unique.rb +11 -2
- data/lib/carray/methods/value_counts.rb +4 -11
- data/lib/carray/record_order.rb +208 -0
- data/lib/carray/rng.rb +3 -0
- data/lib/carray/runtime.rb +65 -17
- data/lib/carray/segment_iterator.rb +1221 -0
- data/lib/carray/serialize.rb +214 -30
- data/lib/carray/slab_iterator.rb +101 -27
- data/lib/carray/stack.rb +10 -4
- data/lib/carray/string.rb +105 -5
- data/lib/carray/string_operation_extension.rb +12 -4
- data/lib/carray/struct.rb +137 -58
- data/lib/carray/struct_builder.rb +124 -17
- data/lib/carray/time.rb +1222 -186
- data/lib/carray/window_iterator.rb +242 -81
- data/lib/carray.rb +9 -2
- data/yard-stubs/ca_obj_array.rb +4 -4
- data/yard-stubs/ca_obj_bitarray.rb +7 -0
- data/yard-stubs/ca_obj_bitfield.rb +23 -12
- data/yard-stubs/ca_obj_fake.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +5 -1
- data/yard-stubs/ca_obj_grid.rb +21 -10
- data/yard-stubs/ca_obj_refer.rb +5 -4
- data/yard-stubs/ca_obj_roll.rb +2 -3
- data/yard-stubs/ca_obj_shift.rb +5 -1
- data/yard-stubs/ca_obj_stride.rb +10 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +9 -5
- data/yard-stubs/carray_access.rb +11 -5
- data/yard-stubs/carray_attribute.rb +0 -5
- data/yard-stubs/carray_broadcast.rb +1 -1
- data/yard-stubs/carray_cast.rb +88 -43
- data/yard-stubs/carray_conversion.rb +15 -2
- data/yard-stubs/carray_copy.rb +12 -5
- data/yard-stubs/carray_core.rb +3 -3
- data/yard-stubs/carray_count.rb +9 -0
- data/yard-stubs/carray_element.rb +10 -4
- data/yard-stubs/carray_generate.rb +21 -1
- data/yard-stubs/carray_lazy.rb +5 -1
- data/yard-stubs/carray_loop.rb +4 -1
- data/yard-stubs/carray_mask.rb +60 -12
- data/yard-stubs/carray_math.rb +52 -14
- data/yard-stubs/carray_median_percentile.rb +15 -8
- data/yard-stubs/carray_memory_view.rb +40 -23
- data/yard-stubs/carray_order.rb +61 -29
- data/yard-stubs/carray_random.rb +13 -4
- data/yard-stubs/carray_scatter.rb +21 -9
- data/yard-stubs/carray_segment.rb +72 -0
- data/yard-stubs/carray_slab.rb +10 -2
- data/yard-stubs/carray_sort.rb +49 -8
- data/yard-stubs/carray_test.rb +15 -3
- data/yard-stubs/carray_utils.rb +0 -26
- metadata +19 -5
- data/ext/ca_for_each_element.h +0 -239
- data/ext/carray_kernels_map.c +0 -3467
- data/lib/carray/arrow_tensor.rb +0 -401
- data/lib/carray/table.rb +0 -108
data/ext/carray.h
CHANGED
|
@@ -347,14 +347,12 @@ typedef struct {
|
|
|
347
347
|
void (*detach) (void *ap);
|
|
348
348
|
void (*fill_data) (void *ap, void *data);
|
|
349
349
|
void (*create_mask) (void *ap);
|
|
350
|
-
/* xfer protocol.
|
|
351
|
-
positional initializers leave it NULL automatically. dir = CA_XFER_GET /
|
|
352
|
-
CA_XFER_PUT. */
|
|
350
|
+
/* xfer protocol. dir = CA_XFER_GET / CA_XFER_PUT. */
|
|
353
351
|
void (*xfer_index) (void *ap, ca_size_t *idx, void *data, int dir);
|
|
354
352
|
void (*xfer_addrs) (void *ap, ca_size_t n, ca_size_t *addrs,
|
|
355
353
|
void *data, int dir);
|
|
356
|
-
/* fold_stride: one compose-fold hop
|
|
357
|
-
|
|
354
|
+
/* fold_stride: one compose-fold hop for the views that fold only
|
|
355
|
+
sometimes (CAWindow, CAGrid, CASelectAxis, CAStack, CAMeld).
|
|
358
356
|
Compose *f into next_parent's byte space and return 1, or decline
|
|
359
357
|
(leave *f / *next_parent untouched) and return 0 -> this view is the
|
|
360
358
|
fold boundary. CAStride family leaves this NULL (handled open-inline
|
|
@@ -637,6 +635,13 @@ typedef struct {
|
|
|
637
635
|
(count[k] == parent->dim[k] && start[k]
|
|
638
636
|
== 0 for k >= 1). Embedded region
|
|
639
637
|
must be contig in parent storage. */
|
|
638
|
+
/* A window over a parent that has no mask: the all-false mask its own
|
|
639
|
+
mask reads instead, so that masking the out-of-bounds cells gives the
|
|
640
|
+
parent no mask. Owned by this window; NULL otherwise. */
|
|
641
|
+
CArray *mask_standin;
|
|
642
|
+
/* On the mask of a window: the window whose mask it is, which holds the
|
|
643
|
+
stand-in and the parent whose mask replaces it. NULL otherwise. */
|
|
644
|
+
CArray *mask_owner;
|
|
640
645
|
} CAWindow; /* 56 + 16*(ndim) + 1*(bytes) + 1*ndim + 24*ndim (bytes) */
|
|
641
646
|
|
|
642
647
|
/* CAShift is a pure typedef of CAWindow. CAShift construction maps (shift[], roll[], fill,
|
|
@@ -681,17 +686,17 @@ typedef struct {
|
|
|
681
686
|
dim[k] = parent->dim[k] * reps[k]. */
|
|
682
687
|
} CATile; /* 56 + 8*(ndim) (bytes) */
|
|
683
688
|
|
|
684
|
-
typedef CATile CARoll; /*
|
|
685
|
-
|
|
686
|
-
is just CATile (= typedef body identical). */
|
|
689
|
+
typedef CATile CARoll; /* same layout as CATile, its own obj_type
|
|
690
|
+
CA_OBJ_ROLL (ext/ca_obj_roll.c) */
|
|
687
691
|
|
|
688
|
-
/* CAStack:
|
|
689
|
-
|
|
692
|
+
/* CAStack: stack view of K uniform-shape parents. The K axis sits at
|
|
693
|
+
k_axis in the view's shape (0 by default: shape = (K, *parent_shape));
|
|
694
|
+
the other axes are the parents' own.
|
|
690
695
|
- parents stored as Ruby Array @parents on the wrapper object (= GC
|
|
691
696
|
anchor); C-side tail `parents[]` is alias pointer array.
|
|
692
697
|
- CAView.parent points to parents[0] (= legacy compat for paths that
|
|
693
698
|
deref ca->parent without CAStack awareness).
|
|
694
|
-
- dim[
|
|
699
|
+
- dim[k_axis] = n_parents; the other dims are parents[0]->dim in order. */
|
|
695
700
|
typedef struct {
|
|
696
701
|
int16_t obj_type;
|
|
697
702
|
int8_t data_type;
|
|
@@ -699,7 +704,7 @@ typedef struct {
|
|
|
699
704
|
int32_t flags;
|
|
700
705
|
ca_size_t bytes;
|
|
701
706
|
ca_size_t elements; /* = n_parents * parents[0]->elements */
|
|
702
|
-
ca_size_t *dim; /* ALLOC_N(ndim)
|
|
707
|
+
ca_size_t *dim; /* ALLOC_N(ndim): parent->dim with n_parents at k_axis */
|
|
703
708
|
char *ptr;
|
|
704
709
|
CArray *mask;
|
|
705
710
|
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
@@ -716,6 +721,12 @@ typedef struct {
|
|
|
716
721
|
0 = outer-axis stack (legacy default).
|
|
717
722
|
parent_ndim = K innermost (= old merge at=-1).
|
|
718
723
|
Set by ca_stack_setup_with_axis / preserved on clone. */
|
|
724
|
+
CArray **mask_standins; /* NULL, or ALLOC_N(CArray*, n_parents) once the mask is
|
|
725
|
+
built: the all-false masks standing in for parents that
|
|
726
|
+
have none (owned, freed with the view) */
|
|
727
|
+
CArray *mask_owner; /* on the mask of a CAStack: that CAStack, whose stand-ins
|
|
728
|
+
this mask reads until they give way to the parents'
|
|
729
|
+
own masks (ca_multi_parent_mask_refresh); else NULL */
|
|
719
730
|
} CAStack;
|
|
720
731
|
|
|
721
732
|
/* CAMeld (ragged concatenate view along an existing axis). Unlike CAStack
|
|
@@ -725,8 +736,7 @@ typedef struct {
|
|
|
725
736
|
shape[meld_axis] = sum_k parents[k]->dim[meld_axis]
|
|
726
737
|
All other axes must match across parents (uniform check at constructor).
|
|
727
738
|
|
|
728
|
-
|
|
729
|
-
Other paths raise NotImplementedError. */
|
|
739
|
+
meld_axis may be any axis. */
|
|
730
740
|
typedef struct {
|
|
731
741
|
int16_t obj_type;
|
|
732
742
|
int8_t data_type;
|
|
@@ -749,6 +759,8 @@ typedef struct {
|
|
|
749
759
|
ca_size_t *seg_offset; /* ALLOC_N(ca_size_t, K+1); prefix sum along meld_axis.
|
|
750
760
|
seg_offset[0]=0, seg_offset[k+1]=seg_offset[k]+parents[k]->dim[meld_axis],
|
|
751
761
|
seg_offset[K]=dim[meld_axis]. */
|
|
762
|
+
CArray **mask_standins; /* as CAStack's: stand-in masks this view owns, or NULL */
|
|
763
|
+
CArray *mask_owner; /* as CAStack's */
|
|
752
764
|
} CAMeld;
|
|
753
765
|
|
|
754
766
|
/* Multi-parent view layout convention (CA_FLAG_MULTI_PARENTS). A view that
|
|
@@ -786,9 +798,14 @@ typedef struct {
|
|
|
786
798
|
VALUE self;
|
|
787
799
|
} CAObject; /* 48 + 4*(ndim) (bytes) */
|
|
788
800
|
|
|
789
|
-
/*
|
|
790
|
-
CAObjectMask is an internal class
|
|
791
|
-
|
|
801
|
+
/*
|
|
802
|
+
CAObjectMask is an internal class used only as the mask array of a
|
|
803
|
+
CAObject. Its bits live in the CAObject's mask hooks (mask_copy_data,
|
|
804
|
+
mask_fetch_addr, ...) when it has them, and in `cache` -- the mask
|
|
805
|
+
buffer of the CAObject's internal data array -- always. Like the mask
|
|
806
|
+
of any view it is cold at rest: ptr is NULL, and every read and write
|
|
807
|
+
goes through its slots to the hooks. An attach publishes the cache in
|
|
808
|
+
ptr, and `holds` counts the attaches not yet detached.
|
|
792
809
|
*/
|
|
793
810
|
|
|
794
811
|
typedef struct {
|
|
@@ -807,6 +824,8 @@ typedef struct {
|
|
|
807
824
|
ext/ca_array_pool.c. */
|
|
808
825
|
/* -------------*/
|
|
809
826
|
VALUE array;
|
|
827
|
+
char *cache;
|
|
828
|
+
long holds;
|
|
810
829
|
} CAObjectMask;
|
|
811
830
|
|
|
812
831
|
/* CARepeat (Phase R migration): structurally identical to CAStride.
|
|
@@ -854,16 +873,19 @@ extern const char * ca_type_name[CA_NTYPE];
|
|
|
854
873
|
extern const int ca_cast_table[CA_NTYPE][CA_NTYPE];
|
|
855
874
|
extern const int ca_cast_table2[CA_NTYPE][CA_NTYPE];
|
|
856
875
|
|
|
857
|
-
/* data_type promotion reducer
|
|
858
|
-
CArray.result_type and by the lazy view layer.
|
|
876
|
+
/* data_type promotion reducer over ca_cast_table. Used by
|
|
877
|
+
CArray.result_type and by the lazy view layer. Raises ArgumentError for
|
|
878
|
+
a code outside the data types, and CArray::DataTypeError for a pair with
|
|
879
|
+
no common type. See ext/carray_cast.c
|
|
859
880
|
for the definition; this is the single source of the promotion rule. */
|
|
860
881
|
int8_t ca_promote_type (int8_t a, int8_t b);
|
|
861
882
|
|
|
862
883
|
/* Infer a data_type code from a Ruby *value* (literal Numeric, true/false,
|
|
863
884
|
Complex, etc.) — distinct from rb_ca_guess_type which interprets the
|
|
864
885
|
object as a data_type *representation* (e.g. T_FIXNUM as a data_type code).
|
|
865
|
-
Used by
|
|
866
|
-
CArray
|
|
886
|
+
Used by rb_ca_cast_self_or_other.
|
|
887
|
+
A CArray, like any object it does not recognise, answers CA_OBJECT;
|
|
888
|
+
callers holding a CArray use ca->data_type. */
|
|
867
889
|
int8_t ca_value_to_data_type (VALUE obj);
|
|
868
890
|
|
|
869
891
|
/* Infer a data_type code from a MemoryView producer by parsing its format,
|
|
@@ -915,8 +937,6 @@ extern const rb_data_type_t cabyteswap_data_type;
|
|
|
915
937
|
/* cafield_data_type was retired in 3.0 (Phase F: CAField is now a
|
|
916
938
|
CAStride subclass; use castride_data_type). */
|
|
917
939
|
extern const rb_data_type_t cagrid_data_type;
|
|
918
|
-
/* camapping_data_type was retired in 3.0 (R.3: CAMapping removed; a[mapper]
|
|
919
|
-
now builds a CAGrid/CAStride normalize chain). */
|
|
920
940
|
extern const rb_data_type_t caobject_data_type;
|
|
921
941
|
extern const rb_data_type_t careduce_data_type;
|
|
922
942
|
extern const rb_data_type_t carefer_data_type;
|
|
@@ -927,7 +947,6 @@ extern const rb_data_type_t cawindow_data_type;
|
|
|
927
947
|
extern const rb_data_type_t carray_mask_data_type;
|
|
928
948
|
extern const rb_data_type_t cablock_mask_data_type;
|
|
929
949
|
extern const rb_data_type_t cagrid_mask_data_type;
|
|
930
|
-
extern const rb_data_type_t camapping_mask_data_type;
|
|
931
950
|
extern const rb_data_type_t careduce_mask_data_type;
|
|
932
951
|
extern const rb_data_type_t carefer_mask_data_type;
|
|
933
952
|
extern const rb_data_type_t caselect_mask_data_type;
|
|
@@ -984,67 +1003,78 @@ extern VALUE rb_cCArrayObject;
|
|
|
984
1003
|
|
|
985
1004
|
#define CA_CHECK_DATA_TYPE(data_type) \
|
|
986
1005
|
do { \
|
|
987
|
-
|
|
988
|
-
|
|
1006
|
+
int ca_dt_ = (data_type); \
|
|
1007
|
+
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE ) { \
|
|
1008
|
+
rb_raise(rb_eArgError, "invalid data_type id %i", ca_dt_); \
|
|
989
1009
|
} \
|
|
990
|
-
if ( ! ca_valid[
|
|
991
|
-
rb_raise(
|
|
1010
|
+
if ( ! ca_valid[ca_dt_] ) { \
|
|
1011
|
+
rb_raise(rb_eCADataTypeError, "data_type %s is disabled", ca_type_name[ca_dt_]); \
|
|
992
1012
|
} \
|
|
993
1013
|
} while (0)
|
|
994
1014
|
|
|
995
1015
|
#define CA_CHECK_DATA_TYPE_NUMERIC(data_type) \
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1016
|
+
do { \
|
|
1017
|
+
int ca_dt_ = (data_type); \
|
|
1018
|
+
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE || !ca_valid[ca_dt_] || \
|
|
1019
|
+
ca_dt_ == CA_FIXLEN || ca_dt_ == CA_OBJECT ) { \
|
|
1020
|
+
rb_raise(rb_eCADataTypeError, "invalid numeric data type"); \
|
|
1021
|
+
} \
|
|
1022
|
+
} while (0)
|
|
999
1023
|
|
|
1000
1024
|
#define CA_CHECK_RANK(ndim) \
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1025
|
+
do { \
|
|
1026
|
+
if ( (ndim) <= 0 || (ndim) > CA_RANK_MAX ) { \
|
|
1027
|
+
rb_raise(rb_eArgError, "invalid ndim"); \
|
|
1028
|
+
} \
|
|
1029
|
+
} while (0)
|
|
1004
1030
|
|
|
1005
1031
|
#define CA_CHECK_DIM(ndim, dim) \
|
|
1006
|
-
{ \
|
|
1032
|
+
do { \
|
|
1007
1033
|
int8_t i_; \
|
|
1008
|
-
for (i_=0; i_<ndim; i_++) { \
|
|
1009
|
-
if ( dim[i_] < 0 ) { \
|
|
1010
|
-
rb_raise(
|
|
1034
|
+
for (i_=0; i_<(ndim); i_++) { \
|
|
1035
|
+
if ( (dim)[i_] < 0 ) { \
|
|
1036
|
+
rb_raise(rb_eArgError, "negative size dimension at %i-dim", i_); \
|
|
1011
1037
|
} \
|
|
1012
1038
|
} \
|
|
1013
|
-
}
|
|
1039
|
+
} while (0)
|
|
1014
1040
|
|
|
1041
|
+
/* A fixlen cell is at least one byte wide. A zero-width cell has one
|
|
1042
|
+
possible value, and a strided view of it cannot say which cell is which:
|
|
1043
|
+
its byte strides are all zero. */
|
|
1015
1044
|
#define CA_CHECK_BYTES(data_type, bytes) \
|
|
1016
|
-
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
1045
|
+
do { \
|
|
1046
|
+
if ( (data_type) == CA_FIXLEN ) { \
|
|
1047
|
+
if ( (bytes) <= 0 ) { \
|
|
1048
|
+
rb_raise(rb_eArgError, \
|
|
1049
|
+
"invalid bytes (a fixlen needs bytes: of 1 or more)"); \
|
|
1050
|
+
} \
|
|
1019
1051
|
} \
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1052
|
+
else { \
|
|
1053
|
+
(bytes) = ca_sizeof[(data_type)]; \
|
|
1054
|
+
if ( (bytes) <= 0 ) { \
|
|
1055
|
+
rb_raise(rb_eArgError, "invalid bytes"); \
|
|
1056
|
+
} \
|
|
1025
1057
|
} \
|
|
1026
|
-
}
|
|
1058
|
+
} while (0)
|
|
1059
|
+
|
|
1060
|
+
/* An index into `n` places, counted from the end when negative, outside of
|
|
1061
|
+
which IndexError is raised naming the method the user called, `what` the
|
|
1062
|
+
index is ("index", "address") and the value given. */
|
|
1063
|
+
NORETURN(void ca_index_out_of_range (ca_size_t idx, ca_size_t n, const char *what));
|
|
1027
1064
|
|
|
1065
|
+
/* Normalise `index` in place against `dim` (a negative one counts from the
|
|
1066
|
+
end) and raise through ca_index_out_of_range when it falls outside. */
|
|
1028
1067
|
#define CA_CHECK_INDEX(index, dim) \
|
|
1029
1068
|
do { \
|
|
1030
|
-
|
|
1031
|
-
|
|
1069
|
+
ca_size_t ca_check_index_given_ = (index); \
|
|
1070
|
+
if ( (index) < 0 ) { \
|
|
1071
|
+
(index) += (dim); \
|
|
1032
1072
|
} \
|
|
1033
|
-
if ( index < 0 || index >= (dim) ) { \
|
|
1034
|
-
|
|
1073
|
+
if ( (index) < 0 || (index) >= (dim) ) { \
|
|
1074
|
+
ca_index_out_of_range(ca_check_index_given_, (dim), "index"); \
|
|
1035
1075
|
} \
|
|
1036
1076
|
} while (0)
|
|
1037
1077
|
|
|
1038
|
-
#define CA_CHECK_BOUND(ca, idx) \
|
|
1039
|
-
{ \
|
|
1040
|
-
int8_t i; \
|
|
1041
|
-
for (i=0; i<ca->ndim; i++) { \
|
|
1042
|
-
if ( idx[i] < 0 || idx[i] >= ca->dim[i] ) { \
|
|
1043
|
-
rb_raise(rb_eRuntimeError, "index out of range at %i-dim ( %i <=> 0..%i )", i, idx[i], ca->dim[i]-1); \
|
|
1044
|
-
} \
|
|
1045
|
-
} \
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
1078
|
/* -------------------------------------------------------------------- */
|
|
1049
1079
|
|
|
1050
1080
|
/* complex <-> Ruby Complex conversion
|
|
@@ -1070,6 +1100,10 @@ extern VALUE rb_cCArrayObject;
|
|
|
1070
1100
|
# endif
|
|
1071
1101
|
#endif
|
|
1072
1102
|
|
|
1103
|
+
/* A string as a complex cell: a real number read as Float() reads it
|
|
1104
|
+
(nan / inf included), else as Complex() does; anything else raises. */
|
|
1105
|
+
double complex ca_str_to_cmplx (VALUE str);
|
|
1106
|
+
|
|
1073
1107
|
static inline double complex
|
|
1074
1108
|
rb_carray_num2cmplx (VALUE num)
|
|
1075
1109
|
{
|
|
@@ -1079,8 +1113,18 @@ rb_carray_num2cmplx (VALUE num)
|
|
|
1079
1113
|
if ( RB_FLOAT_TYPE_P(num) || RB_INTEGER_TYPE_P(num) ) {
|
|
1080
1114
|
return (double complex) NUM2DBL(num);
|
|
1081
1115
|
}
|
|
1116
|
+
if ( RB_TYPE_P(num, T_STRING) ) {
|
|
1117
|
+
return ca_str_to_cmplx(num);
|
|
1118
|
+
}
|
|
1119
|
+
if ( NIL_P(num) ) {
|
|
1120
|
+
rb_raise(rb_eTypeError, "can't convert nil into Complex");
|
|
1121
|
+
}
|
|
1082
1122
|
if ( rb_respond_to(num, rb_intern("to_c")) ) {
|
|
1083
1123
|
VALUE c = rb_funcall(num, rb_intern("to_c"), 0);
|
|
1124
|
+
if ( ! RB_TYPE_P(c, T_COMPLEX) ) {
|
|
1125
|
+
rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" to Complex (%"PRIsVALUE"#to_c gives %"PRIsVALUE")",
|
|
1126
|
+
rb_obj_class(num), rb_obj_class(num), rb_obj_class(c));
|
|
1127
|
+
}
|
|
1084
1128
|
return CMPLX(NUM2DBL(rb_complex_real(c)), NUM2DBL(rb_complex_imag(c)));
|
|
1085
1129
|
}
|
|
1086
1130
|
if ( rb_respond_to(num, rb_intern("to_f")) ) {
|
|
@@ -1125,6 +1169,7 @@ double OBJ2DBL (VALUE v);
|
|
|
1125
1169
|
object->int/float cast loop so an unparseable cell becomes UNDEF instead
|
|
1126
1170
|
of a silent 0.0 (float) or a raise (int). See ext/carray_cast.c. */
|
|
1127
1171
|
int ca_obj2dbl_ok (VALUE v, double *out);
|
|
1172
|
+
int ca_obj2cmplx_ok (VALUE v, double complex *out);
|
|
1128
1173
|
int rb_obj2long_ok (VALUE v, long *out);
|
|
1129
1174
|
int rb_obj2ulong_ok (VALUE v, unsigned long *out);
|
|
1130
1175
|
int rb_obj2ll_ok (VALUE v, long long *out);
|
|
@@ -1156,8 +1201,7 @@ enum {
|
|
|
1156
1201
|
CA_IDX_SCALAR,
|
|
1157
1202
|
CA_IDX_ALL,
|
|
1158
1203
|
CA_IDX_BLOCK,
|
|
1159
|
-
CA_IDX_SYMBOL
|
|
1160
|
-
CA_IDX_REPEAT
|
|
1204
|
+
CA_IDX_SYMBOL
|
|
1161
1205
|
}; /* CA_INDEX_TYPE */
|
|
1162
1206
|
|
|
1163
1207
|
typedef union {
|
|
@@ -1226,14 +1270,14 @@ VALUE rb_carray_new_safe (int8_t data_type,
|
|
|
1226
1270
|
already hold a freshly decoded buffer and want to avoid a copy. The
|
|
1227
1271
|
buffer must be ruby_xmalloc()'d and at least elements*bytes long; it
|
|
1228
1272
|
is freed with xfree() when the array is collected. data_type must not
|
|
1229
|
-
be CA_OBJECT.
|
|
1273
|
+
be CA_OBJECT. When the call raises (a bad argument), the buffer stays
|
|
1274
|
+
the caller's. */
|
|
1230
1275
|
CArray *carray_new_adopt (int8_t data_type,
|
|
1231
1276
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, char *ptr);
|
|
1232
1277
|
VALUE rb_carray_new_adopt (int8_t data_type,
|
|
1233
1278
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, char *ptr);
|
|
1234
1279
|
|
|
1235
|
-
/*
|
|
1236
|
-
a reduction-output CArray for kernel_iterator authors. Computes
|
|
1280
|
+
/* Allocate a reduction-output CArray for kernel_iterator authors. Computes
|
|
1237
1281
|
output shape = self.dim with slab axes removed (ascending order),
|
|
1238
1282
|
collapses to shape [1] when fully reduced. See
|
|
1239
1283
|
ext/carray_core.c for docstring + semantics. */
|
|
@@ -1244,10 +1288,10 @@ VALUE rb_ca_new_reduced (VALUE self, int8_t *slab_axes,
|
|
|
1244
1288
|
VALUE rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
1245
1289
|
int32_t data_type, ca_size_t bytes, int keep_axis);
|
|
1246
1290
|
|
|
1247
|
-
/*
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1291
|
+
/* Parse variadic axis argv into a validated int8_t array. Accepts Integer
|
|
1292
|
+
args or a single Array arg (no argument = every axis), counts negative
|
|
1293
|
+
axes from the end, and raises ArgumentError for an axis out of range or
|
|
1294
|
+
given twice.
|
|
1251
1295
|
Returns the validated naxes. */
|
|
1252
1296
|
int8_t rb_ca_parse_reduce_axes (int argc, VALUE *argv,
|
|
1253
1297
|
CArray *ca, int8_t *out_axes);
|
|
@@ -1293,6 +1337,14 @@ VALUE rb_ca_farray (VALUE self);
|
|
|
1293
1337
|
|
|
1294
1338
|
/* --- ca_obj_stride.c --- */
|
|
1295
1339
|
|
|
1340
|
+
/* The strides and base_offset are taken as given: they are not checked
|
|
1341
|
+
against the parent's extent, so a view that reaches outside it reads
|
|
1342
|
+
and writes outside it.
|
|
1343
|
+
|
|
1344
|
+
ca_stride_setup with ca == NULL runs its checks and returns 0 without
|
|
1345
|
+
writing. ca_stride_new calls it that way before it allocates, so a
|
|
1346
|
+
rejected argument leaves no struct behind; a subclass constructor can
|
|
1347
|
+
do the same through its own setup function. */
|
|
1296
1348
|
int ca_stride_setup (CAStride *ca, int8_t obj_type, CArray *parent,
|
|
1297
1349
|
int8_t data_type, ca_size_t bytes,
|
|
1298
1350
|
int8_t ndim, ca_size_t *dim,
|
|
@@ -1362,8 +1414,16 @@ void ca_broadcast_pair (volatile VALUE *self, volatile VALUE *other);
|
|
|
1362
1414
|
ca_install_obj_type(klass, &td, mask_klass, &mask_td,
|
|
1363
1415
|
&my_func, sizeof(my_func));
|
|
1364
1416
|
|
|
1417
|
+
The table must reach at least through xfer_all: xfer_index, xfer_addrs
|
|
1418
|
+
and xfer_all have no default. fold_stride may be NULL (the view is a
|
|
1419
|
+
fold boundary); xfer_stride, the pool slots, fill_addrs and fill_stride
|
|
1420
|
+
fall back to a default when NULL. A shorter table raises RuntimeError.
|
|
1365
1421
|
A func_size larger than this build's struct means the caller was compiled
|
|
1366
|
-
against a newer carray; that is reported rather than truncated.
|
|
1422
|
+
against a newer carray; that is reported rather than truncated.
|
|
1423
|
+
|
|
1424
|
+
The obj_type parameters of ca_array_alloc, ca_array_pool_alloc,
|
|
1425
|
+
ca_stride_setup and ca_stride_new are int8_t, so an obj_type is numbered
|
|
1426
|
+
below 128: an install that would number one at 128 or above raises. */
|
|
1367
1427
|
|
|
1368
1428
|
int
|
|
1369
1429
|
ca_install_obj_type (VALUE klass,
|
|
@@ -1430,19 +1490,24 @@ int ca_is_mask_array (void *ap);
|
|
|
1430
1490
|
#define GetCArray(obj, ca) \
|
|
1431
1491
|
TypedData_Get_Struct((obj), CArray, &carray_data_type, (ca))
|
|
1432
1492
|
|
|
1433
|
-
/* True
|
|
1434
|
-
|
|
1435
|
-
strides are row-major contiguous
|
|
1436
|
-
|
|
1437
|
-
by
|
|
1438
|
-
|
|
1493
|
+
/* True when ca_attach(ca) gives ca->ptr the cells in place, without
|
|
1494
|
+
materialising: entity arrays, CAWrap, CScalar, and CAStride-family
|
|
1495
|
+
views whose composed strides are row-major contiguous over an attached
|
|
1496
|
+
root (alias-attach path). It is not the same as "attach is O(1)": a
|
|
1497
|
+
Face attaches in O(1) by borrowing its parent and answers false, and a
|
|
1498
|
+
CASource entity that publishes its ptr only while attached answers
|
|
1499
|
+
true. Used by the kernel iterator's alias decision, the sweep engine,
|
|
1500
|
+
and the views and mask paths that skip a sync when nothing was copied. */
|
|
1439
1501
|
int ca_attach_is_alias (void *ap);
|
|
1440
1502
|
|
|
1441
1503
|
/* OR operand masks into
|
|
1442
1504
|
ca_out->mask without ca_attach on operand masks (= gathers via
|
|
1443
|
-
ca_xfer_all into arena scratch then byte OR-folds). ca_out
|
|
1444
|
-
|
|
1445
|
-
|
|
1505
|
+
ca_xfer_all into arena scratch then byte OR-folds). ca_out's mask is
|
|
1506
|
+
written through its ptr, so ca_out is an entity or an attached view.
|
|
1507
|
+
Each operand other than a scalar has ca_out's number of elements
|
|
1508
|
+
(ArgumentError otherwise); n is at most 8. For bang variant where
|
|
1509
|
+
ca_out IS one of the operands, the existing mask is preserved as
|
|
1510
|
+
initial accumulator. */
|
|
1446
1511
|
void ca_mask_overlay_safe (CArray *ca_out, int n, ...);
|
|
1447
1512
|
|
|
1448
1513
|
#define ca_is_caobject(ca) ( (ca)->obj_type == CA_OBJ_OBJECT )
|
|
@@ -1459,6 +1524,7 @@ int ca_is_object_type (void *ap);
|
|
|
1459
1524
|
|
|
1460
1525
|
void ca_check_type (void *ap, int8_t data_type);
|
|
1461
1526
|
#define ca_check_data_type(ap, data_type) ca_check_type(ap, data_type)
|
|
1527
|
+
void ca_check_uninitialized (void *ap); /* initialize / initialize_copy entry */
|
|
1462
1528
|
void ca_check_ndim (void *ap, int ndim);
|
|
1463
1529
|
void ca_check_shape (void *ap, int ndim, ca_size_t *dim);
|
|
1464
1530
|
void ca_check_same_data_type (void *ap1, void *ap2);
|
|
@@ -1474,7 +1540,7 @@ int ca_is_valid_index (void *ap, ca_size_t *idx);
|
|
|
1474
1540
|
|
|
1475
1541
|
/* API : allocate, attach, update, sync, detach */
|
|
1476
1542
|
|
|
1477
|
-
/* Attach lifecycle contract (R1-
|
|
1543
|
+
/* Attach lifecycle contract (R1-R6). Ownership-based, and NOT transitive.
|
|
1478
1544
|
This block is the canonical statement of the contract; the other documents
|
|
1479
1545
|
copy it. guides/devel/04_attach_lifecycle.md discusses it at length.
|
|
1480
1546
|
|
|
@@ -1491,15 +1557,34 @@ int ca_is_valid_index (void *ap, ca_size_t *idx);
|
|
|
1491
1557
|
internally (views carry an attach refcount; entities do
|
|
1492
1558
|
not).
|
|
1493
1559
|
R5 (traffic) Attach hands you a buffer, not a live array. Use x->ptr;
|
|
1494
|
-
a view derived from x
|
|
1495
|
-
root
|
|
1560
|
+
a view derived from x may read past the buffer to the
|
|
1561
|
+
root (a CAStride-family view over a CAStride-family x
|
|
1562
|
+
does) or read the buffer (others), so writes to the
|
|
1563
|
+
buffer are not seen through derived views until x is
|
|
1564
|
+
synced.
|
|
1565
|
+
R6 (raising) ca_allocate and ca_attach that raise have taken
|
|
1566
|
+
nothing; ca_allocate_n and ca_attach_n take all of
|
|
1567
|
+
their arrays or none. Close a window with
|
|
1568
|
+
ca_sync_detach, which detaches even when the sync
|
|
1569
|
+
raises -- ca_sync then ca_detach leaves the window open
|
|
1570
|
+
on a raise. ca_sync_detach syncs, so it raises on a
|
|
1571
|
+
read-only array; a window that only read closes with
|
|
1572
|
+
ca_detach. Anything between that can raise (Ruby
|
|
1573
|
+
called from inside the window) needs an ensure of its
|
|
1574
|
+
own.
|
|
1496
1575
|
*/
|
|
1497
1576
|
|
|
1577
|
+
/* ca_allocate opens a window for writing every cell: what the cells held
|
|
1578
|
+
before is not kept, also when the array is already attached (object cells
|
|
1579
|
+
are reset to 0 and the mask is cleared). */
|
|
1498
1580
|
void ca_allocate (void *ap);
|
|
1499
1581
|
void ca_attach (void *ca);
|
|
1582
|
+
/* Re-gather an attached view's buffer from its parent (one level: a parent
|
|
1583
|
+
that holds its own buffer is read as it is). */
|
|
1500
1584
|
void ca_update (void *ca);
|
|
1501
1585
|
void ca_sync (void *ca);
|
|
1502
1586
|
void ca_detach (void *ca);
|
|
1587
|
+
void ca_sync_detach (void *ca);
|
|
1503
1588
|
|
|
1504
1589
|
void ca_allocate_n (int n, ...);
|
|
1505
1590
|
void ca_attach_n (int n, ...);
|
|
@@ -1507,17 +1592,70 @@ void ca_update_n (int n, ...);
|
|
|
1507
1592
|
void ca_sync_n (int n, ...);
|
|
1508
1593
|
void ca_detach_n (int n, ...);
|
|
1509
1594
|
|
|
1595
|
+
/* API : lending the addresses of cells
|
|
1596
|
+
|
|
1597
|
+
A kernel that reads cells by address itself -- a stencil reading
|
|
1598
|
+
a[i-1][j] and a[i+1][j] from its own loop -- needs, for each array, a
|
|
1599
|
+
pointer to cell (0, ..., 0) and the byte distance between neighbours
|
|
1600
|
+
along each axis. ca_with_address_bases lends that for the duration of
|
|
1601
|
+
`body`, whatever the arrays are, and puts back what the kernel wrote:
|
|
1602
|
+
|
|
1603
|
+
- an entity, or a view the engine can fold down to one (a slice, a
|
|
1604
|
+
transpose, a reshape), is addressed in place;
|
|
1605
|
+
- any other view (a selection, a conversion, a lazy expression) has
|
|
1606
|
+
the cells the kernel touches copied into a buffer, which is lent
|
|
1607
|
+
instead and, for a writable array, sent back afterwards: only the
|
|
1608
|
+
cells the kernel changed, through the view.
|
|
1609
|
+
|
|
1610
|
+
`box_start[i]` / `box_count[i]` (ndim values each) say which cells
|
|
1611
|
+
array i's kernel touches -- its loop range, widened by how far the
|
|
1612
|
+
kernel reaches (one cell each way for a[i-1] .. a[i+1]). They decide
|
|
1613
|
+
what the second case copies; the first case lends the whole array
|
|
1614
|
+
either way. Pass NULL for `box_start` and `box_count` (or for an
|
|
1615
|
+
entry of them) to lend the whole array. A box outside the array is
|
|
1616
|
+
refused. Address only the box, whichever way the array was lent.
|
|
1617
|
+
|
|
1618
|
+
`writable[i]` says whether the kernel writes array i (NULL: none is
|
|
1619
|
+
written); a read-only array is refused for writing. An object array
|
|
1620
|
+
is refused (its cells are Ruby values, not numbers), and so is a view
|
|
1621
|
+
with a mask that reinterprets the element size (its mask cells do not
|
|
1622
|
+
map one to one onto the parent's).
|
|
1623
|
+
|
|
1624
|
+
A masked array also lends its mask: one boolean8_t per cell (nonzero =
|
|
1625
|
+
masked), addressed with mask_strides the same way. A write to the
|
|
1626
|
+
mask is put back like a write to a cell. `mask` is NULL for an array
|
|
1627
|
+
with no mask.
|
|
1628
|
+
|
|
1629
|
+
`body` may raise: the arrays are still written back and closed.
|
|
1630
|
+
Returns what `body` returns. The CArray pointers must stay alive for
|
|
1631
|
+
the call (keep the VALUEs they came from). */
|
|
1632
|
+
typedef struct {
|
|
1633
|
+
char *ptr; /* cell (0, ..., 0) */
|
|
1634
|
+
ca_size_t strides[CA_RANK_MAX]; /* byte step along each axis */
|
|
1635
|
+
boolean8_t *mask; /* NULL when no mask */
|
|
1636
|
+
ca_size_t mask_strides[CA_RANK_MAX]; /* byte step in the mask */
|
|
1637
|
+
int writable;
|
|
1638
|
+
} ca_address_basis_t;
|
|
1639
|
+
|
|
1640
|
+
VALUE ca_with_address_bases (int32_t n, CArray **arrays, const int *writable,
|
|
1641
|
+
const ca_size_t *const *box_start,
|
|
1642
|
+
const ca_size_t *const *box_count,
|
|
1643
|
+
VALUE (*body)(ca_address_basis_t *bases,
|
|
1644
|
+
VALUE arg),
|
|
1645
|
+
VALUE arg);
|
|
1646
|
+
|
|
1510
1647
|
/* API : copying */
|
|
1511
1648
|
|
|
1512
1649
|
void *ca_clone (void *ap); /* use rb_obj_clone() */
|
|
1650
|
+
/* A CA_OBJECT copy holds VALUEs the GC does not see until the struct is
|
|
1651
|
+
wrapped, and wrapping allocates: for an object array use rb_ca_copy, which
|
|
1652
|
+
keeps them alive and returns the wrapped copy. */
|
|
1513
1653
|
CArray *ca_copy (void *ap); /* use rb_ca_copy() */
|
|
1514
1654
|
CArray *ca_template (void *ap); /* use rb_ca_template() */
|
|
1515
1655
|
CArray *ca_template_safe (void *ap); /* use rb_ca_template() */
|
|
1516
1656
|
CArray *ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes);
|
|
1517
1657
|
/* use rb_ca_template() */
|
|
1518
1658
|
|
|
1519
|
-
/* ca_paste / ca_clip / ca_cut (sub-region copy in/out) removed in 3.0; see
|
|
1520
|
-
lib/extras/crop_paste.rb for the Ruby thin wrapper replacements. */
|
|
1521
1659
|
void ca_fill (void *ap, void *ptr);
|
|
1522
1660
|
|
|
1523
1661
|
/* API : fetch, store */
|
|
@@ -1538,9 +1676,10 @@ void ca_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *data, int
|
|
|
1538
1676
|
opportunistic engine dispatch. */
|
|
1539
1677
|
int ca_xfer_addrs_is_sequential_run (ca_size_t n, ca_size_t *addrs,
|
|
1540
1678
|
ca_size_t *base_out);
|
|
1541
|
-
/*
|
|
1679
|
+
/* Resolve cand through identity CAStride compose-fold to find an
|
|
1542
1680
|
attached root. Returns cand if cand->ptr is set, cand is not CAStride
|
|
1543
|
-
family, or no identity compose-fold path exists
|
|
1681
|
+
family, or no identity compose-fold path exists (the cells differ from
|
|
1682
|
+
the root's in data type, width or position); otherwise returns the
|
|
1544
1683
|
resolved root (which has ptr). Used by view xfer_addrs slots to lift
|
|
1545
1684
|
parent->ptr gate through view CAStride layers (= chain pattern). */
|
|
1546
1685
|
CArray *ca_resolve_attached_root_via_identity (CArray *cand);
|
|
@@ -1616,6 +1755,8 @@ void ca_fill_stride_whole (void *ap, void *ptr);
|
|
|
1616
1755
|
extern VALUE CA_UNDEF;
|
|
1617
1756
|
extern VALUE CA_UNSPECIFIED;
|
|
1618
1757
|
|
|
1758
|
+
/* The mask's buffer, which a view's mask has only while attached: NULL
|
|
1759
|
+
otherwise. */
|
|
1619
1760
|
boolean8_t *ca_mask_ptr (void *ap);
|
|
1620
1761
|
int ca_has_mask (void *ap);
|
|
1621
1762
|
int ca_is_any_masked (void *ap);
|
|
@@ -1632,7 +1773,7 @@ void ca_copy_mask_overwrite (void *ap, ca_size_t elements, int n, ...);
|
|
|
1632
1773
|
ca_size_t ca_count_masked (void *ap);
|
|
1633
1774
|
ca_size_t ca_count_not_masked (void *ap);
|
|
1634
1775
|
void ca_unmask (void *ap, char *fill_value);
|
|
1635
|
-
CArray *
|
|
1776
|
+
CArray *ca_unmask_copy (void *ap, char *fill_value);
|
|
1636
1777
|
|
|
1637
1778
|
/* API : cast, conversion */
|
|
1638
1779
|
|
|
@@ -1646,7 +1787,7 @@ void ca_ptr2val (void *ap1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
|
1646
1787
|
void ca_val2ptr (int8_t data_type1, void *ptr1, void *ap2, void *ptr2);
|
|
1647
1788
|
void ca_val2val (int8_t data_type1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
1648
1789
|
VALUE ca_ptr2obj (void *ap, void *ptr); /* use rb_ca_ptr2obj() */
|
|
1649
|
-
void ca_obj2ptr (void *ap, VALUE obj, void *ptr); /* use
|
|
1790
|
+
void ca_obj2ptr (void *ap, VALUE obj, void *ptr); /* use rb_ca_obj2ptr() */
|
|
1650
1791
|
|
|
1651
1792
|
#define ca_wrap_writable(obj, data_type) \
|
|
1652
1793
|
(obj = rb_ca_wrap_writable(obj, INT2NUM(data_type)), (CArray*) DATA_PTR(obj))
|
|
@@ -1672,6 +1813,7 @@ void ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
|
1672
1813
|
ca_size_t *offset, ca_size_t *count, ca_size_t *step);
|
|
1673
1814
|
|
|
1674
1815
|
int ca_equal (void *ap, void *bp);
|
|
1816
|
+
int ca_eql_storage (void *ap, void *bp);
|
|
1675
1817
|
void ca_zerodiv(void) __attribute__((noreturn));
|
|
1676
1818
|
/* ca_rand removed in 3.0; use rb_random_real/rb_random_ulong_limited instead */
|
|
1677
1819
|
ca_size_t ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k);
|
|
@@ -1695,6 +1837,8 @@ void rb_check_carray_object (VALUE arg);
|
|
|
1695
1837
|
|
|
1696
1838
|
/* specific Data_Wrap_Struct for carray */
|
|
1697
1839
|
VALUE ca_wrap_struct (void *ap);
|
|
1840
|
+
/* As ca_wrap_struct, under the class klass. klass is not checked: it must
|
|
1841
|
+
be a CArray class whose instances share ap's TypedData. */
|
|
1698
1842
|
VALUE ca_wrap_struct_as (void *ap, VALUE klass);
|
|
1699
1843
|
|
|
1700
1844
|
/* query data_type */
|
|
@@ -1703,7 +1847,8 @@ void rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
|
1703
1847
|
int8_t *data_type, ca_size_t *bytes);
|
|
1704
1848
|
int rb_ca_is_type (VALUE arg, int type);
|
|
1705
1849
|
|
|
1706
|
-
/* scan index
|
|
1850
|
+
/* scan index. info->range_check is read, not written: set it (1 to check
|
|
1851
|
+
each index against ca_dim) before the call. */
|
|
1707
1852
|
void rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t elements,
|
|
1708
1853
|
long argc, VALUE *argv, CAIndexInfo *info);
|
|
1709
1854
|
|
|
@@ -1810,9 +1955,13 @@ VALUE rb_ca_fill_copy (VALUE self, VALUE val);
|
|
|
1810
1955
|
/* address calculation */
|
|
1811
1956
|
VALUE rb_ca_addr2index (VALUE self, VALUE raddr);
|
|
1812
1957
|
|
|
1813
|
-
/*
|
|
1958
|
+
/* A cell's bytes (self's data type, self->bytes wide) as the value ca[i]
|
|
1959
|
+
gives for that cell: true or false for a boolean, the element for a
|
|
1960
|
+
Face, a record for a struct. The mask is not consulted. */
|
|
1814
1961
|
VALUE rb_ca_ptr2obj (VALUE self, void *ptr);
|
|
1815
1962
|
#define rb_ca_fetch_ptr(self, ptr) rb_ca_ptr2obj(self, ptr)
|
|
1963
|
+
|
|
1964
|
+
/* elemental access like ca[i,j,k] or ca[addr] */
|
|
1816
1965
|
VALUE rb_ca_fetch_index (VALUE self, ca_size_t *idx);
|
|
1817
1966
|
VALUE rb_ca_fetch_addr (VALUE self, ca_size_t addr);
|
|
1818
1967
|
VALUE rb_ca_fetch (VALUE self, VALUE index);
|