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_internal.h
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
/* ---------------------------------------------------------------------------
|
|
2
2
|
|
|
3
|
-
carray_internal.h --
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
carray.h is what
|
|
7
|
-
everything it declares is a contract.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
carray_internal.h -- carray's own declarations, for carray's own
|
|
4
|
+
translation units only.
|
|
5
|
+
|
|
6
|
+
carray.h is what an extension gets from `#include "carray.h"`, so
|
|
7
|
+
everything it declares is a contract. The declarations carray's own
|
|
8
|
+
sources use besides those -- the structs, tags and classes of its views,
|
|
9
|
+
the bodies of its Ruby methods, the parts its operation slots are built
|
|
10
|
+
from -- are here instead.
|
|
11
|
+
|
|
12
|
+
carray.h includes this header at its end, after carray_math_kernel.h
|
|
13
|
+
and ca_kernel_iterator.h, when CARRAY_BUILD is defined, which it is for
|
|
14
|
+
every source of carray, so those sources get these declarations from
|
|
15
|
+
`#include "carray.h"`. This header relies on everything carray.h
|
|
16
|
+
declares, ca_iter_state included, and does not include carray.h
|
|
17
|
+
itself. An extension is built without CARRAY_BUILD and never reads it.
|
|
18
|
+
|
|
19
|
+
It includes carray's other internal headers for the kernel iterator:
|
|
20
|
+
ca_axis_descriptor.h (the per-axis descriptors; ca_kernel_iterator.h
|
|
21
|
+
has already included it for the engine's fields of ca_iter_state),
|
|
22
|
+
ca_iter_substrate.h and ca_kernel_iterator_internal.h. Its Face section
|
|
23
|
+
includes ca_obj_face.h for the hook types that section uses.
|
|
24
|
+
|
|
25
|
+
This header carries no contract: anything in it may change or go away
|
|
26
|
+
in any release, 3.x patch releases included. It is not installed (see
|
|
27
|
+
ext/extconf.rb $INSTALLFILES). It ships in the gem's ext/ directory only
|
|
28
|
+
because carray is built from it there; an extension that puts that
|
|
29
|
+
directory on its include path must still not include it.
|
|
16
30
|
|
|
17
31
|
Some internal clusters keep their own non-installed header rather than
|
|
18
32
|
folding in (ca_sort_kernels.h, ca_op_powi.h, ca_composite_dispatch.h);
|
|
19
|
-
what matters is only that they stay out of
|
|
20
|
-
install list.
|
|
33
|
+
what matters is only that they stay out of the installed headers.
|
|
21
34
|
|
|
22
35
|
---------------------------------------------------------------------------- */
|
|
23
36
|
|
|
@@ -25,10 +38,827 @@
|
|
|
25
38
|
#define CARRAY_INTERNAL_H
|
|
26
39
|
|
|
27
40
|
#include "ruby/thread_native.h" /* rb_nativethread_lock_t */
|
|
28
|
-
|
|
29
|
-
#include "carray.h"
|
|
30
41
|
#include <math.h> /* isnan, for CA_OBJ_ISNAN */
|
|
31
42
|
|
|
43
|
+
/* ---- Cell types, limits, flag bits and enums ------------------------- */
|
|
44
|
+
|
|
45
|
+
/* Enumerator::ArithmeticSequence, cached for carray's index parsing. An
|
|
46
|
+
extension looks the class up with rb_const_get. */
|
|
47
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
|
48
|
+
extern VALUE rb_cArithSeq;
|
|
49
|
+
#endif
|
|
50
|
+
|
|
51
|
+
/* The unaligned cell types carray's own kernels use, one for each cell
|
|
52
|
+
type. An extension declares its own with CA_UNALIGNED. */
|
|
53
|
+
typedef boolean8_t ca_u_boolean8_t;
|
|
54
|
+
typedef int8_t ca_u_int8_t;
|
|
55
|
+
typedef uint8_t ca_u_uint8_t;
|
|
56
|
+
typedef int16_t ca_u_int16_t CA_UNALIGNED;
|
|
57
|
+
typedef uint16_t ca_u_uint16_t CA_UNALIGNED;
|
|
58
|
+
typedef int32_t ca_u_int32_t CA_UNALIGNED;
|
|
59
|
+
typedef uint32_t ca_u_uint32_t CA_UNALIGNED;
|
|
60
|
+
typedef int64_t ca_u_int64_t CA_UNALIGNED;
|
|
61
|
+
typedef uint64_t ca_u_uint64_t CA_UNALIGNED;
|
|
62
|
+
typedef float32_t ca_u_float32_t CA_UNALIGNED;
|
|
63
|
+
typedef float64_t ca_u_float64_t CA_UNALIGNED;
|
|
64
|
+
typedef cmplx64_t ca_u_cmplx64_t CA_UNALIGNED;
|
|
65
|
+
typedef cmplx128_t ca_u_cmplx128_t CA_UNALIGNED;
|
|
66
|
+
typedef VALUE ca_u_VALUE CA_UNALIGNED;
|
|
67
|
+
|
|
68
|
+
typedef ca_u_float32_t ca_u_float;
|
|
69
|
+
typedef ca_u_float64_t ca_u_double;
|
|
70
|
+
|
|
71
|
+
/* CA_U(float64_t) is ca_u_float64_t (and CA_U(double) ca_u_double): for a
|
|
72
|
+
macro that takes the cell type. */
|
|
73
|
+
#define CA_U(type) ca_u_##type
|
|
74
|
+
|
|
75
|
+
/* The limit on a view's attach count, and an optimizer hint, both for
|
|
76
|
+
carray's own sources. */
|
|
77
|
+
#define CA_ATTACH_MAX 0x80000000
|
|
78
|
+
|
|
79
|
+
/* Assert an invariant to the optimizer (zero runtime cost). Used to teach
|
|
80
|
+
GCC's value-range propagation facts it cannot derive itself -- chiefly
|
|
81
|
+
`ndim <= CA_RANK_MAX`, which bounds loops and allocations over fixed
|
|
82
|
+
[CA_RANK_MAX] stack arrays. Without this, GCC (11.x) emits false-positive
|
|
83
|
+
-Wstringop-overflow / -Wmaybe-uninitialized / -Walloc-size-larger-than on
|
|
84
|
+
those loops because `int8_t ndim` ranges up to 127 as far as it can see.
|
|
85
|
+
The asserted conditions are hard invariants (CA_CHECK_RANK enforces them at
|
|
86
|
+
array creation); a violation is genuinely unreachable. */
|
|
87
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
88
|
+
# define CA_ASSUME(cond) do { if ( !(cond) ) __builtin_unreachable(); } while (0)
|
|
89
|
+
#else
|
|
90
|
+
# define CA_ASSUME(cond) ((void)0)
|
|
91
|
+
#endif
|
|
92
|
+
|
|
93
|
+
/* CALazyMarker. A marker layers "read this as the leaf of a lazy chain"
|
|
94
|
+
over storage that is identical to its parent's — the same premise as
|
|
95
|
+
CA_FLAG_IS_FACE — so the two are asked about together wherever a
|
|
96
|
+
storage-identical wrapper has to be seen through. Kept as its own bit
|
|
97
|
+
rather than folded into CA_FLAG_IS_FACE: ca_is_face is read in ~100
|
|
98
|
+
places that mean the Face mechanism specifically. The marker is carray's
|
|
99
|
+
own; an extension does not test this bit. */
|
|
100
|
+
#define CA_FLAG_IS_LAZY_MARKER 1024
|
|
101
|
+
|
|
102
|
+
/* The values of ca_endian, the host's byte order, for carray's own sources.
|
|
103
|
+
An extension that needs the byte order tests it itself. */
|
|
104
|
+
enum {
|
|
105
|
+
CA_LITTLE_ENDIAN = 0,
|
|
106
|
+
CA_BIG_ENDIAN = 1
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/* The boundary rules of CAWindow and the axis descriptors, for carray's own
|
|
110
|
+
views. */
|
|
111
|
+
enum {
|
|
112
|
+
CA_BOUNDS_RUBY = 1,
|
|
113
|
+
CA_BOUNDS_STRICT,
|
|
114
|
+
CA_BOUNDS_NEAREST,
|
|
115
|
+
CA_BOUNDS_PERIODIC,
|
|
116
|
+
CA_BOUNDS_REFLECT,
|
|
117
|
+
CA_BOUNDS_FILL,
|
|
118
|
+
CA_BOUNDS_MASK,
|
|
119
|
+
}; /* CA_BOUNDS_TYPE for CAWindow */
|
|
120
|
+
|
|
121
|
+
/* Per-axis descriptor framework: types, producer interface, and common
|
|
122
|
+
attach engine. ca_kernel_iterator.h has already included it, for the
|
|
123
|
+
engine's fields of ca_iter_state. */
|
|
124
|
+
#include "ca_axis_descriptor.h"
|
|
125
|
+
|
|
126
|
+
/* ---- The entity's operation slots and the structs of carray's views ---- */
|
|
127
|
+
|
|
128
|
+
/* The entity's operation slots. An extension starts its own table from a
|
|
129
|
+
copy of the entity's, ca_operation_table_copy(CA_OBJ_ARRAY, ...), and
|
|
130
|
+
replaces slots in it; it does not call these slots by name. */
|
|
131
|
+
void * ca_array_func_clone (void *ap);
|
|
132
|
+
void ca_array_func_allocate (void *ap);
|
|
133
|
+
void ca_array_func_attach (void *ap);
|
|
134
|
+
void ca_array_func_sync (void *ap);
|
|
135
|
+
void ca_array_func_detach (void *ap);
|
|
136
|
+
void ca_array_func_xfer_index (void *ap, ca_size_t *idx, void *data, int dir);
|
|
137
|
+
void ca_array_func_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs,
|
|
138
|
+
void *data, int dir);
|
|
139
|
+
void ca_array_func_xfer_all (void *ap, void *data, int dir);
|
|
140
|
+
void ca_array_func_fill_data (void *ap, void *val);
|
|
141
|
+
void ca_array_func_create_mask (void *ap);
|
|
142
|
+
|
|
143
|
+
/* The struct of CScalar; an extension makes one with rb_cscalar_new and
|
|
144
|
+
reads it as a CArray. */
|
|
145
|
+
typedef struct {
|
|
146
|
+
CA_ARRAY_HEADER
|
|
147
|
+
ca_size_t _dim;
|
|
148
|
+
} CScalar;
|
|
149
|
+
|
|
150
|
+
/* CABlock: CAStride prefix + native-spec tail.
|
|
151
|
+
The tail (offset, start, step, count, size0) describes the block in the
|
|
152
|
+
parent's terms and serves:
|
|
153
|
+
- the Ruby accessors #offset, #start, #step and #size0
|
|
154
|
+
- #idx2addr0 / #addr2addr0
|
|
155
|
+
Code that changes `start[]` must recompute base_offset
|
|
156
|
+
(ca_block_sync_base_offset) to keep the CAStride prefix consistent:
|
|
157
|
+
the transfer slots, taken from CAStride, read only the prefix. */
|
|
158
|
+
typedef struct {
|
|
159
|
+
CA_ARRAY_HEADER
|
|
160
|
+
CArray *parent;
|
|
161
|
+
uint32_t attach;
|
|
162
|
+
uint8_t nosync;
|
|
163
|
+
/* --- CAStride prefix continues --- */
|
|
164
|
+
ca_size_t *strides;
|
|
165
|
+
ca_size_t base_offset;
|
|
166
|
+
/* --- CABlock tail (native spec) --- */
|
|
167
|
+
ca_size_t offset;
|
|
168
|
+
ca_size_t *start;
|
|
169
|
+
ca_size_t *step;
|
|
170
|
+
ca_size_t *count;
|
|
171
|
+
ca_size_t *size0;
|
|
172
|
+
} CABlock;
|
|
173
|
+
|
|
174
|
+
/* The structs of the views carray itself defines. An extension does not
|
|
175
|
+
define a view of these kinds or read their tails, so only sources built
|
|
176
|
+
with carray see them. */
|
|
177
|
+
typedef struct {
|
|
178
|
+
CA_ARRAY_HEADER
|
|
179
|
+
CArray *parent;
|
|
180
|
+
uint32_t attach;
|
|
181
|
+
uint8_t nosync;
|
|
182
|
+
/* ---------- */
|
|
183
|
+
uint8_t *bounds; /* [ndim] per-axis policy. Per-axis so that
|
|
184
|
+
CAShift (per-axis roll[]) can be expressed as
|
|
185
|
+
a CAWindow specialisation. */
|
|
186
|
+
ca_size_t *start;
|
|
187
|
+
ca_size_t *count;
|
|
188
|
+
ca_size_t *size0;
|
|
189
|
+
char *fill;
|
|
190
|
+
/* Embed model: the window as one alias rectangle inside the parent plus
|
|
191
|
+
its fill complement. Computed by ca_window_recompute_embed when the
|
|
192
|
+
window is set up. Attach and sync use it to copy the rectangle and
|
|
193
|
+
fill the rest with no per-element bound check. */
|
|
194
|
+
ca_size_t *embed_parent_start; /* [ndim] parent-side alias rectangle start */
|
|
195
|
+
ca_size_t *embed_count; /* [ndim] alias rectangle size per axis */
|
|
196
|
+
ca_size_t *embed_output_offset; /* [ndim] output-side alias rectangle start */
|
|
197
|
+
uint8_t embed_is_empty; /* 1 = fully out of parent, alias is empty */
|
|
198
|
+
uint8_t embed_covers_all; /* 1 = interior-only, fill is unused */
|
|
199
|
+
uint8_t embed_eligible; /* 1 = all bounds in {FILL, MASK}, attach
|
|
200
|
+
takes the embed fast path. Other
|
|
201
|
+
policies (PERIODIC/REFLECT/...) fall
|
|
202
|
+
back to the ca_axis_dispatch_* engine. */
|
|
203
|
+
uint8_t embed_alias_eligible; /* 1 = direct ca_attach(window) can alias
|
|
204
|
+
to parent->ptr without copy.
|
|
205
|
+
Condition: embed_eligible
|
|
206
|
+
+ embed_covers_all + inner axes full
|
|
207
|
+
(count[k] == parent->dim[k] && start[k]
|
|
208
|
+
== 0 for k >= 1). Embedded region
|
|
209
|
+
must be contig in parent storage. */
|
|
210
|
+
/* A window over a parent that has no mask: the all-false mask its own
|
|
211
|
+
mask reads instead, so that masking the out-of-bounds cells gives the
|
|
212
|
+
parent no mask. Owned by this window; NULL otherwise. */
|
|
213
|
+
CArray *mask_standin;
|
|
214
|
+
/* On the mask of a window: the window whose mask it is, which holds the
|
|
215
|
+
stand-in and the parent whose mask replaces it. NULL otherwise. */
|
|
216
|
+
CArray *mask_owner;
|
|
217
|
+
} CAWindow; /* 56 + 16*(ndim) + 1*(bytes) + 1*ndim + 24*ndim (bytes) */
|
|
218
|
+
|
|
219
|
+
/* CAShift is a pure typedef of CAWindow. CAShift construction maps (shift[], roll[], fill,
|
|
220
|
+
fill_mask) onto CAWindow's (start = -shift, count = parent->dim,
|
|
221
|
+
bounds = roll ? PERIODIC : (fill_mask ? MASK : FILL), fill). The
|
|
222
|
+
two views share the operation table (ca_window_func); only obj_type
|
|
223
|
+
differs (CA_OBJ_SHIFT vs CA_OBJ_WINDOW) to preserve user-facing class
|
|
224
|
+
distinction. */
|
|
225
|
+
typedef CAWindow CAShift;
|
|
226
|
+
|
|
227
|
+
/* CATile: N-region expansion view (tiled repetition of the parent).
|
|
228
|
+
Output shape = parent.dim * reps per axis; total tiles = product(reps).
|
|
229
|
+
Each tile is a full-parent alias at output offset
|
|
230
|
+
(i_0 * parent.dim[0], i_1 * parent.dim[1], ...). Attach iterates
|
|
231
|
+
total_tiles regions, calling ca_composite_region_gather for each.
|
|
232
|
+
|
|
233
|
+
CARoll is a typedef of CATile, as CAShift is of CAWindow: the C struct
|
|
234
|
+
layout is shared, and CARoll reads `reps[]` as its per-axis shift. Its
|
|
235
|
+
operation table is a copy of CATile's with the slots that depend on
|
|
236
|
+
the shift overridden (ext/ca_obj_roll.c). */
|
|
237
|
+
typedef struct {
|
|
238
|
+
CA_ARRAY_HEADER
|
|
239
|
+
CArray *parent;
|
|
240
|
+
uint32_t attach;
|
|
241
|
+
uint8_t nosync;
|
|
242
|
+
/* ---------- */
|
|
243
|
+
ca_size_t *reps; /* [ndim] number of tiles per axis.
|
|
244
|
+
Total tiles = product(reps).
|
|
245
|
+
dim[k] = parent->dim[k] * reps[k]. */
|
|
246
|
+
} CATile; /* 56 + 8*(ndim) (bytes) */
|
|
247
|
+
|
|
248
|
+
typedef CATile CARoll; /* same layout as CATile, its own obj_type
|
|
249
|
+
CA_OBJ_ROLL (ext/ca_obj_roll.c) */
|
|
250
|
+
|
|
251
|
+
/* CAStack: stack view of K uniform-shape parents. The K axis sits at
|
|
252
|
+
k_axis in the view's shape (0 by default: shape = (K, *parent_shape));
|
|
253
|
+
the other axes are the parents' own.
|
|
254
|
+
- parents stored as Ruby Array @parents on the wrapper object (= GC
|
|
255
|
+
anchor); C-side tail `parents[]` is alias pointer array.
|
|
256
|
+
- CAView.parent points to parents[0] (= legacy compat for paths that
|
|
257
|
+
deref ca->parent without CAStack awareness).
|
|
258
|
+
- dim[k_axis] = n_parents; the other dims are parents[0]->dim in order. */
|
|
259
|
+
typedef struct {
|
|
260
|
+
CA_ARRAY_HEADER
|
|
261
|
+
CArray *parent; /* = parents[0] (legacy CAView field) */
|
|
262
|
+
uint32_t attach;
|
|
263
|
+
uint8_t nosync;
|
|
264
|
+
/* ---- CAStack tail ---- */
|
|
265
|
+
int32_t n_parents; /* K = axis-0 size */
|
|
266
|
+
CArray **parents; /* ALLOC_N(CArray*, n_parents); aliases, not owned */
|
|
267
|
+
int8_t k_axis; /* K axis insertion position in view shape, [0, parent_ndim].
|
|
268
|
+
0 = outer-axis stack (the default).
|
|
269
|
+
parent_ndim = K innermost.
|
|
270
|
+
Set by ca_stack_setup_with_axis / preserved on clone. */
|
|
271
|
+
CArray **mask_standins; /* NULL, or ALLOC_N(CArray*, n_parents) once the mask is
|
|
272
|
+
built: the all-false masks standing in for parents that
|
|
273
|
+
have none (owned, freed with the view) */
|
|
274
|
+
CArray *mask_owner; /* on the mask of a CAStack: that CAStack, whose stand-ins
|
|
275
|
+
this mask reads until they give way to the parents'
|
|
276
|
+
own masks (ca_multi_parent_mask_refresh); else NULL */
|
|
277
|
+
} CAStack;
|
|
278
|
+
|
|
279
|
+
/* CAMeld (ragged concatenate view along an existing axis). Unlike CAStack
|
|
280
|
+
which introduces a new K axis, CAMeld welds K parents along one of their
|
|
281
|
+
existing axes and may have uneven segment lengths there.
|
|
282
|
+
shape[a] = parents[0]->dim[a] for a != meld_axis
|
|
283
|
+
shape[meld_axis] = sum_k parents[k]->dim[meld_axis]
|
|
284
|
+
All other axes must match across parents (uniform check at constructor).
|
|
285
|
+
|
|
286
|
+
meld_axis may be any axis. */
|
|
287
|
+
typedef struct {
|
|
288
|
+
CA_ARRAY_HEADER
|
|
289
|
+
CArray *parent; /* = parents[0] (legacy CAView field) */
|
|
290
|
+
uint32_t attach;
|
|
291
|
+
uint8_t nosync;
|
|
292
|
+
/* ---- CAMeld tail (n_parents / parents kept adjacent to header for
|
|
293
|
+
CAMultiParent layout convention) ---- */
|
|
294
|
+
int32_t n_parents; /* K = number of segments */
|
|
295
|
+
CArray **parents; /* ALLOC_N(CArray*, K); aliases, not owned */
|
|
296
|
+
int8_t meld_axis; /* existing axis being welded, [0, parent_ndim) */
|
|
297
|
+
ca_size_t *seg_offset; /* ALLOC_N(ca_size_t, K+1); prefix sum along meld_axis.
|
|
298
|
+
seg_offset[0]=0, seg_offset[k+1]=seg_offset[k]+parents[k]->dim[meld_axis],
|
|
299
|
+
seg_offset[K]=dim[meld_axis]. */
|
|
300
|
+
CArray **mask_standins; /* as CAStack's: stand-in masks this view owns, or NULL */
|
|
301
|
+
CArray *mask_owner; /* as CAStack's */
|
|
302
|
+
} CAMeld;
|
|
303
|
+
|
|
304
|
+
/* Multi-parent view layout convention (CA_FLAG_MULTI_PARENTS). A view that
|
|
305
|
+
fans out to K parents must place `n_parents` + `parents[]` immediately after
|
|
306
|
+
the CAView header (exactly as CAStack does) so generic routines that would
|
|
307
|
+
otherwise walk a single ->parent can fold over all parents without knowing
|
|
308
|
+
the concrete view type. Cast `(CAMultiParent *) ca` only when the flag is
|
|
309
|
+
set. CAStack is the first conforming type (layout-checked in
|
|
310
|
+
Init_ca_obj_stack via offsetof). */
|
|
311
|
+
typedef struct {
|
|
312
|
+
CAView header; /* common view prefix (obj_type .. nosync) */
|
|
313
|
+
int32_t n_parents;
|
|
314
|
+
CArray **parents;
|
|
315
|
+
} CAMultiParent;
|
|
316
|
+
|
|
317
|
+
typedef struct {
|
|
318
|
+
CA_ARRAY_HEADER
|
|
319
|
+
CArray *parent;
|
|
320
|
+
uint32_t attach;
|
|
321
|
+
uint8_t nosync;
|
|
322
|
+
/* -------------*/
|
|
323
|
+
CArray *data;
|
|
324
|
+
VALUE self;
|
|
325
|
+
} CAObject;
|
|
326
|
+
|
|
327
|
+
/*
|
|
328
|
+
CAObjectMask is an internal class used only as the mask array of a
|
|
329
|
+
CAObject. Its bits live in the CAObject's mask hooks (mask_copy_data,
|
|
330
|
+
mask_fetch_addr, ...) when it has them, and in `cache` -- the mask
|
|
331
|
+
buffer of the CAObject's internal data array -- always. Like the mask
|
|
332
|
+
of any view it is cold at rest: ptr is NULL, and every read and write
|
|
333
|
+
goes through its slots to the hooks. An attach publishes the cache in
|
|
334
|
+
ptr, and `holds` counts the attaches not yet detached.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
typedef struct {
|
|
338
|
+
CA_ARRAY_HEADER
|
|
339
|
+
/* -------------*/
|
|
340
|
+
VALUE array;
|
|
341
|
+
char *cache;
|
|
342
|
+
long holds;
|
|
343
|
+
} CAObjectMask;
|
|
344
|
+
|
|
345
|
+
/* CARepeat: structurally identical to CAStride.
|
|
346
|
+
The "repeat" axes are encoded as strides[k] == 0. */
|
|
347
|
+
typedef CAStride CARepeat;
|
|
348
|
+
|
|
349
|
+
/*
|
|
350
|
+
CAReduce is an internal class
|
|
351
|
+
used only in ca_obj_refer.c.
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
typedef struct {
|
|
355
|
+
CA_ARRAY_HEADER
|
|
356
|
+
CArray *parent;
|
|
357
|
+
uint32_t attach;
|
|
358
|
+
uint8_t nosync;
|
|
359
|
+
/* ---- */
|
|
360
|
+
ca_size_t count;
|
|
361
|
+
ca_size_t offset;
|
|
362
|
+
} CAReduce;
|
|
363
|
+
|
|
364
|
+
/* ---- Tables, TypedData tags and classes ------------------------------ */
|
|
365
|
+
|
|
366
|
+
/* The host's byte order and the promotion tables behind ca_promote_type,
|
|
367
|
+
for carray's own sources. An extension asks ca_promote_type for the
|
|
368
|
+
common data type of two. */
|
|
369
|
+
extern const int ca_endian;
|
|
370
|
+
extern const int ca_cast_table[CA_NTYPE][CA_NTYPE];
|
|
371
|
+
extern const int ca_cast_table2[CA_NTYPE][CA_NTYPE];
|
|
372
|
+
|
|
373
|
+
/* Symbol cache for data_type code → Symbol lookup. Initialized in
|
|
374
|
+
Init_carray_class. Indexed by data_type code (0 = CA_FIXLEN ...
|
|
375
|
+
CA_NTYPE-1 = CA_OBJECT). An extension converts with
|
|
376
|
+
rb_ca_data_type_to_sym. */
|
|
377
|
+
extern ID ca_data_type_sym[CA_NTYPE];
|
|
378
|
+
|
|
379
|
+
/* ca_func[] is indexed with sizeof(ca_operation_function_t) as its
|
|
380
|
+
stride, which grows when a slot is added, so only sources built with
|
|
381
|
+
carray see it. An extension installs its table with
|
|
382
|
+
ca_install_obj_type and keeps its own copy. */
|
|
383
|
+
extern ca_operation_function_t ca_func[CA_OBJ_TYPE_MAX];
|
|
384
|
+
/* The count of installed obj_types; an extension keeps the number
|
|
385
|
+
ca_install_obj_type returns. */
|
|
386
|
+
extern int ca_obj_num;
|
|
387
|
+
|
|
388
|
+
/* The tags of the views carray itself defines. An extension takes any
|
|
389
|
+
array through carray_data_type (GetCArray) and derives its own tags
|
|
390
|
+
from the ones carray.h declares, so these are seen only by sources built with
|
|
391
|
+
carray. */
|
|
392
|
+
extern const rb_data_type_t cawrap_data_type;
|
|
393
|
+
extern const rb_data_type_t cscalar_data_type;
|
|
394
|
+
extern const rb_data_type_t cabitarray_data_type;
|
|
395
|
+
extern const rb_data_type_t cabitfield_data_type;
|
|
396
|
+
extern const rb_data_type_t cablock_data_type;
|
|
397
|
+
extern const rb_data_type_t cafake_data_type;
|
|
398
|
+
extern const rb_data_type_t cabyteswap_data_type;
|
|
399
|
+
extern const rb_data_type_t cagrid_data_type;
|
|
400
|
+
extern const rb_data_type_t caobject_data_type;
|
|
401
|
+
extern const rb_data_type_t careduce_data_type;
|
|
402
|
+
extern const rb_data_type_t carefer_data_type;
|
|
403
|
+
extern const rb_data_type_t caselect_data_type;
|
|
404
|
+
extern const rb_data_type_t cashift_data_type;
|
|
405
|
+
extern const rb_data_type_t cawindow_data_type;
|
|
406
|
+
|
|
407
|
+
extern const rb_data_type_t cablock_mask_data_type;
|
|
408
|
+
extern const rb_data_type_t cagrid_mask_data_type;
|
|
409
|
+
extern const rb_data_type_t careduce_mask_data_type;
|
|
410
|
+
extern const rb_data_type_t carefer_mask_data_type;
|
|
411
|
+
extern const rb_data_type_t caselect_mask_data_type;
|
|
412
|
+
extern const rb_data_type_t cashift_mask_data_type;
|
|
413
|
+
extern const rb_data_type_t cawindow_mask_data_type;
|
|
414
|
+
|
|
415
|
+
/* The classes of the views and iterators carray itself defines. An
|
|
416
|
+
extension tests an array with rb_obj_is_kind_of against the classes
|
|
417
|
+
carray.h declares and does not need these. */
|
|
418
|
+
extern VALUE rb_cCScalar;
|
|
419
|
+
extern VALUE rb_cCAWrap;
|
|
420
|
+
extern VALUE rb_cCARefer;
|
|
421
|
+
extern VALUE rb_cCABlock;
|
|
422
|
+
extern VALUE rb_cCAField;
|
|
423
|
+
extern VALUE rb_cCAByteSwap;
|
|
424
|
+
extern VALUE rb_cCAStrideMask;
|
|
425
|
+
extern VALUE rb_cCASelect;
|
|
426
|
+
extern VALUE rb_cCAObject;
|
|
427
|
+
extern VALUE rb_cCARepeat;
|
|
428
|
+
extern VALUE rb_cCAIterator;
|
|
429
|
+
|
|
430
|
+
extern VALUE rb_cCAReferMask;
|
|
431
|
+
extern VALUE rb_cCABlockMask;
|
|
432
|
+
extern VALUE rb_cCAFieldMask;
|
|
433
|
+
extern VALUE rb_cCASelectMask;
|
|
434
|
+
extern VALUE rb_cCAObjectMask;
|
|
435
|
+
extern VALUE rb_cCARepeatMask;
|
|
436
|
+
|
|
437
|
+
/* The CAMath module, for carray's own sources. An extension looks it up
|
|
438
|
+
with rb_const_get(rb_cObject, rb_intern("CAMath")). */
|
|
439
|
+
extern VALUE rb_mCAMath;
|
|
440
|
+
|
|
441
|
+
/* ---- The cast loop's parsers and index parsing ----------------------- */
|
|
442
|
+
|
|
443
|
+
/* Mask-aware object->numeric parsers: return 1 with *out set on success, or
|
|
444
|
+
0 (no value; caller masks the cell) on parse failure. Used by the
|
|
445
|
+
object->int/float cast loop so an unparseable cell becomes UNDEF instead
|
|
446
|
+
of a silent 0.0 (float) or a raise (int). An Integer wider than the C
|
|
447
|
+
type gives its low bytes (two's complement), as a narrowing C cast does;
|
|
448
|
+
these parsers do not raise. See ext/carray_cast.c. They are parts of
|
|
449
|
+
carray's cast loop; an extension converts an object array with
|
|
450
|
+
rb_ca_to_type. */
|
|
451
|
+
int ca_obj2dbl_ok (VALUE v, double *out);
|
|
452
|
+
int ca_obj2cmplx_ok (VALUE v, double complex *out);
|
|
453
|
+
int rb_obj2long_ok (VALUE v, long *out);
|
|
454
|
+
int rb_obj2ulong_ok (VALUE v, unsigned long *out);
|
|
455
|
+
int rb_obj2ll_ok (VALUE v, long long *out);
|
|
456
|
+
int rb_obj2ull_ok (VALUE v, unsigned long long *out);
|
|
457
|
+
|
|
458
|
+
/* index parsing (carray's own; not part of the extension surface) */
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
enum {
|
|
462
|
+
CA_REG_NONE,
|
|
463
|
+
CA_REG_ALL,
|
|
464
|
+
CA_REG_ADDRESS,
|
|
465
|
+
CA_REG_FLATTEN,
|
|
466
|
+
CA_REG_ADDRESS_COMPLEX,
|
|
467
|
+
CA_REG_POINT,
|
|
468
|
+
CA_REG_BLOCK,
|
|
469
|
+
CA_REG_SELECT,
|
|
470
|
+
CA_REG_ITERATOR,
|
|
471
|
+
CA_REG_REPEAT,
|
|
472
|
+
CA_REG_GRID,
|
|
473
|
+
CA_REG_ADDRESS_ARRAY,
|
|
474
|
+
CA_REG_METHOD_CALL,
|
|
475
|
+
CA_REG_MEMBER,
|
|
476
|
+
CA_REG_ATTRIBUTE,
|
|
477
|
+
}; /* CA_REGION_TYPE */
|
|
478
|
+
|
|
479
|
+
enum {
|
|
480
|
+
CA_IDX_SCALAR,
|
|
481
|
+
CA_IDX_ALL,
|
|
482
|
+
CA_IDX_BLOCK,
|
|
483
|
+
CA_IDX_SYMBOL
|
|
484
|
+
}; /* CA_INDEX_TYPE */
|
|
485
|
+
|
|
486
|
+
typedef union {
|
|
487
|
+
ca_size_t scalar;
|
|
488
|
+
struct {
|
|
489
|
+
ca_size_t start;
|
|
490
|
+
ca_size_t step;
|
|
491
|
+
ca_size_t count;
|
|
492
|
+
} block;
|
|
493
|
+
struct {
|
|
494
|
+
ID id;
|
|
495
|
+
VALUE spec;
|
|
496
|
+
} symbol;
|
|
497
|
+
} CAIndex;
|
|
498
|
+
|
|
499
|
+
typedef struct {
|
|
500
|
+
int16_t type;
|
|
501
|
+
int16_t ndim;
|
|
502
|
+
int32_t index_type[CA_RANK_MAX];
|
|
503
|
+
CAIndex index[CA_RANK_MAX];
|
|
504
|
+
CArray *select;
|
|
505
|
+
VALUE block;
|
|
506
|
+
VALUE symbol;
|
|
507
|
+
int8_t range_check;
|
|
508
|
+
} CAIndexInfo;
|
|
509
|
+
|
|
510
|
+
/* ---- Constructors, and the bodies of the view-making methods --------- */
|
|
511
|
+
|
|
512
|
+
/* The setup and the free_object slot of the entity and of CAWrap, for
|
|
513
|
+
carray's own sources. An extension makes an entity with carray_new or
|
|
514
|
+
rb_carray_new, and frees an array through ca_free. */
|
|
515
|
+
int carray_setup (CArray *ca,
|
|
516
|
+
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
517
|
+
ca_size_t bytes, CArray *mask);
|
|
518
|
+
|
|
519
|
+
int carray_safe_setup (CArray *ca,
|
|
520
|
+
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
521
|
+
ca_size_t bytes, CArray *mask);
|
|
522
|
+
|
|
523
|
+
void free_carray (void *ap);
|
|
524
|
+
void free_ca_wrap (void *ap);
|
|
525
|
+
|
|
526
|
+
/* rb_ca_new_reduced's shape computation, with the output byte width
|
|
527
|
+
passed explicitly so a runtime-width output data_type (CA_FIXLEN) can
|
|
528
|
+
be allocated. Only carray's own reductions make such an output; an
|
|
529
|
+
extension allocates its reduction output with rb_ca_new_reduced. */
|
|
530
|
+
VALUE rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
531
|
+
int32_t data_type, ca_size_t bytes, int keep_axis);
|
|
532
|
+
|
|
533
|
+
/* The other CScalar constructors, for carray's own sources. An extension
|
|
534
|
+
makes a CScalar with rb_cscalar_new. */
|
|
535
|
+
CScalar *cscalar_new (int8_t data_type, ca_size_t bytes, CArray *ma);
|
|
536
|
+
CScalar *cscalar_new2 (int8_t data_type, ca_size_t bytes, char *val);
|
|
537
|
+
VALUE rb_cscalar_new_with_value (int8_t data_type, ca_size_t bytes, VALUE rval);
|
|
538
|
+
|
|
539
|
+
/* A Ruby value as a CArray (CArray.cast): an Integer as int64, a Float as
|
|
540
|
+
float64, true / false as boolean, a Complex as cmplx128, an Array or a
|
|
541
|
+
Range through to_ca, anything else as an object cell. A CArray is
|
|
542
|
+
returned as it is. */
|
|
543
|
+
VALUE rb_ca_cast (VALUE self);
|
|
544
|
+
|
|
545
|
+
/* The Ruby-level builder of a CARefer, used by carray's indexing. An
|
|
546
|
+
extension makes a reinterpreting view with ca_refer_new, or a
|
|
547
|
+
strided view with ca_stride_new / rb_ca_stride_new. */
|
|
548
|
+
VALUE rb_ca_refer_new (VALUE self,
|
|
549
|
+
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
550
|
+
ca_size_t bytes, ca_size_t offset);
|
|
551
|
+
|
|
552
|
+
/* --- ca_obj_farray.c --- */
|
|
553
|
+
|
|
554
|
+
/* The body of CArray#farray; an extension calls the method with
|
|
555
|
+
rb_funcall. */
|
|
556
|
+
VALUE rb_ca_farray (VALUE self);
|
|
557
|
+
|
|
558
|
+
/* one stride-composition hop: express leaf (in parent's byte space) into
|
|
559
|
+
parent->parent's byte space. Non-static so carray's sometimes-fold views
|
|
560
|
+
(e.g. CAWindow::fold_stride) can compose through a synthetic stride
|
|
561
|
+
layer; an extension composes a whole chain with ca_stride_compose_to_root. */
|
|
562
|
+
int ca_stride_compose_through (CAStride *leaf, CAStride *parent,
|
|
563
|
+
ca_size_t *out_strides, ca_size_t *out_base);
|
|
564
|
+
|
|
565
|
+
/* The bodies of the view-making methods below (CArray#grid, #field,
|
|
566
|
+
#fake, #repeat and the indexing behind them). An extension makes these
|
|
567
|
+
views by calling the methods with rb_funcall. */
|
|
568
|
+
|
|
569
|
+
/* --- ca_obj_grid.c --- */
|
|
570
|
+
|
|
571
|
+
VALUE rb_ca_grid (int argc, VALUE *argv, VALUE self);
|
|
572
|
+
int rb_ca_select_axis_eligible_p (int argc, VALUE *argv, VALUE self);
|
|
573
|
+
VALUE rb_ca_select_axis (int argc, VALUE *argv, VALUE self);
|
|
574
|
+
|
|
575
|
+
/* --- ca_obj_mapping.c --- */
|
|
576
|
+
|
|
577
|
+
VALUE rb_ca_mapping (int argc, VALUE *argv, VALUE self);
|
|
578
|
+
|
|
579
|
+
/* --- ca_obj_field.c --- */
|
|
580
|
+
|
|
581
|
+
VALUE rb_ca_field (int argc, VALUE *argv, VALUE self);
|
|
582
|
+
|
|
583
|
+
/* --- ca_obj_byte_swap.c / ca_obj_bitfield.c --- */
|
|
584
|
+
|
|
585
|
+
VALUE rb_ca_endian (VALUE self, VALUE byte_order);
|
|
586
|
+
VALUE rb_ca_bitfield (int argc, VALUE *argv, VALUE self);
|
|
587
|
+
|
|
588
|
+
/* --- ca_obj_fake.c --- */
|
|
589
|
+
|
|
590
|
+
VALUE rb_ca_fake_type (VALUE self, VALUE rtype, VALUE rbytes);
|
|
591
|
+
|
|
592
|
+
/* --- ca_obj_repeat.c --- */
|
|
593
|
+
|
|
594
|
+
VALUE rb_ca_repeat (int argc, VALUE *argv, VALUE self);
|
|
595
|
+
|
|
596
|
+
/* --- carray_broadcast.c --- */
|
|
597
|
+
|
|
598
|
+
/* The shape matching of the binary operators and the lazy builders, for
|
|
599
|
+
carray's own sources. An extension combines two arrays by calling the
|
|
600
|
+
operator with rb_funcall. */
|
|
601
|
+
VALUE ca_broadcast_view (VALUE src, int8_t ndim, ca_size_t *target_dim);
|
|
602
|
+
void ca_broadcast_pair (volatile VALUE *self, volatile VALUE *other);
|
|
603
|
+
|
|
604
|
+
/* ---- Queries, checks, copying, transfer and fill --------------------- */
|
|
605
|
+
|
|
606
|
+
/* True for a CALazyMarker. */
|
|
607
|
+
#define ca_is_lazy_marker(ca) ( ca_test_flag((ca), CA_FLAG_IS_LAZY_MARKER) )
|
|
608
|
+
|
|
609
|
+
/* The checks at the entry of carray's own view constructors (initialize /
|
|
610
|
+
initialize_copy) and of its data_class arguments. */
|
|
611
|
+
void ca_check_uninitialized (void *ap); /* initialize / initialize_copy entry */
|
|
612
|
+
void ca_check_data_class (VALUE rtype);
|
|
613
|
+
|
|
614
|
+
/* The clone slot's dispatcher, for carray's own sources; an extension
|
|
615
|
+
clones an array with rb_obj_clone(). */
|
|
616
|
+
void *ca_clone (void *ap);
|
|
617
|
+
|
|
618
|
+
/* ca_fill_data with the read-only check done twice, for carray's own
|
|
619
|
+
sources. An extension calls ca_fill_data. */
|
|
620
|
+
void ca_fill (void *ap, void *ptr);
|
|
621
|
+
|
|
622
|
+
/* The shortcuts carray's own xfer_addrs slots take, for carray's own
|
|
623
|
+
sources. An extension's slot hands its addresses on with ca_xfer_addrs. */
|
|
624
|
+
/* Shared predicate: detect if addrs[] is a sequential run
|
|
625
|
+
(addrs[i] == addrs[0]+i for all i). Used by ca_xfer_addrs_dispatch and
|
|
626
|
+
by view xfer_addrs slots for whole-view / sub-region run detection ->
|
|
627
|
+
opportunistic engine dispatch. */
|
|
628
|
+
int ca_xfer_addrs_is_sequential_run (ca_size_t n, ca_size_t *addrs,
|
|
629
|
+
ca_size_t *base_out);
|
|
630
|
+
/* Resolve cand through identity CAStride compose-fold to find an
|
|
631
|
+
attached root. Returns cand if cand->ptr is set, cand is not CAStride
|
|
632
|
+
family, or no identity compose-fold path exists (the cells differ from
|
|
633
|
+
the root's in data type, width or position); otherwise returns the
|
|
634
|
+
resolved root (which has ptr). Used by view xfer_addrs slots to lift
|
|
635
|
+
parent->ptr gate through view CAStride layers (= chain pattern). */
|
|
636
|
+
CArray *ca_resolve_attached_root_via_identity (CArray *cand);
|
|
637
|
+
|
|
638
|
+
/* The parts carray's own fill_stride and fill_addrs slots are built from,
|
|
639
|
+
for carray's own sources. An extension that has no faster way to fill a
|
|
640
|
+
region leaves the slot NULL and gets the per-cell default. */
|
|
641
|
+
/* The per-cell walk, to stand in for regions this view cannot pass on. */
|
|
642
|
+
void ca_fill_stride_default (void *ap, ca_size_t base, int8_t ndim,
|
|
643
|
+
ca_size_t *counts, ca_size_t *steps, void *ptr);
|
|
644
|
+
void ca_fill_addrs_default (void *ap, ca_size_t n, ca_size_t *addrs, void *ptr);
|
|
645
|
+
|
|
646
|
+
/* For a view whose fill is a read-modify-write of its parent and so has no
|
|
647
|
+
region to pass down: walk the region and feed its addresses to the batched
|
|
648
|
+
address slot in windows, rather than descending the chain per cell. */
|
|
649
|
+
void ca_fill_stride_via_addrs (void *ap, ca_size_t base, int8_t ndim,
|
|
650
|
+
ca_size_t *counts, ca_size_t *steps,
|
|
651
|
+
void *ptr);
|
|
652
|
+
|
|
653
|
+
/* The test for the one region a view can always pass on: all of itself. */
|
|
654
|
+
int ca_fill_stride_is_whole (void *ap, ca_size_t base, int8_t ndim,
|
|
655
|
+
ca_size_t *counts, ca_size_t *steps);
|
|
656
|
+
|
|
657
|
+
/* Fill the whole of `ca` by handing its own extent to ca_fill_stride: the
|
|
658
|
+
region every caller means when it says "all of me". Views use it to route
|
|
659
|
+
a full-coverage fill_data into the region path. */
|
|
660
|
+
void ca_fill_stride_whole (void *ap, void *ptr);
|
|
661
|
+
|
|
662
|
+
/* ---- Casts, helpers, options and the bodies of Ruby methods ---------- */
|
|
663
|
+
|
|
664
|
+
/* The cast table and the cast between a cell and a Ruby object without
|
|
665
|
+
the Face's conversion, for carray's own sources. An extension casts
|
|
666
|
+
with ca_cast_block and converts a cell with rb_ca_ptr2obj and
|
|
667
|
+
rb_ca_obj2ptr. */
|
|
668
|
+
typedef void (*ca_cast_func_t)(ca_size_t, CArray *, void *, CArray *, void *, boolean8_t *);
|
|
669
|
+
extern ca_cast_func_t ca_cast_func_table[CA_NTYPE][CA_NTYPE];
|
|
670
|
+
VALUE ca_ptr2obj (void *ap, void *ptr);
|
|
671
|
+
void ca_obj2ptr (void *ap, VALUE obj, void *ptr);
|
|
672
|
+
|
|
673
|
+
/* Helpers of carray's own operators, views and comparisons, for carray's
|
|
674
|
+
own sources. An extension parses a Range with ca_parse_range and
|
|
675
|
+
compares arrays with rb_funcall (==, eql?). */
|
|
676
|
+
ca_size_t ca_get_loop_count (int n, ...);
|
|
677
|
+
ca_size_t ca_set_iterator (int n, ...);
|
|
678
|
+
void ca_swap_bytes (char *p, ca_size_t bytes, ca_size_t elements);
|
|
679
|
+
void ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
680
|
+
ca_size_t *offset, ca_size_t *count, ca_size_t *step);
|
|
681
|
+
int ca_equal (void *ap, void *bp);
|
|
682
|
+
int ca_eql_storage (void *ap, void *bp);
|
|
683
|
+
ca_size_t ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k);
|
|
684
|
+
|
|
685
|
+
/* rb_ca_parse_reduce_axes_kw with the method name for its error messages
|
|
686
|
+
given by the caller. An extension uses rb_ca_parse_reduce_axes_kw,
|
|
687
|
+
whose messages name the Ruby method that called it. */
|
|
688
|
+
int8_t rb_ca_parse_reduce_axes_kw_ctx (VALUE axis_val, CArray *ca,
|
|
689
|
+
int8_t *out_axes, const char *ctx);
|
|
690
|
+
|
|
691
|
+
/* carray's own parsing of a type and byte-width argument pair. An
|
|
692
|
+
extension reads the type with rb_ca_guess_type and compares data_type
|
|
693
|
+
codes. */
|
|
694
|
+
void rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
695
|
+
int8_t *data_type, ca_size_t *bytes);
|
|
696
|
+
int rb_ca_is_type (VALUE arg, int type);
|
|
697
|
+
|
|
698
|
+
/* scan index. info->range_check is read, not written: set it (1 to check
|
|
699
|
+
each index against ca_dim) before the call. */
|
|
700
|
+
void rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t elements,
|
|
701
|
+
long argc, VALUE *argv, CAIndexInfo *info);
|
|
702
|
+
|
|
703
|
+
/* The operand handling of carray's binary operators. An extension brings
|
|
704
|
+
two operands to one type with rb_ca_cast_self_or_other. */
|
|
705
|
+
int rb_ca_test_castable (VALUE other);
|
|
706
|
+
VALUE rb_ca_binop_pass_to_other (VALUE self, VALUE other, ID method);
|
|
707
|
+
void rb_ca_cast_other (volatile VALUE *self, volatile VALUE *other);
|
|
708
|
+
|
|
709
|
+
/* data class access (struct), for carray's own sources */
|
|
710
|
+
VALUE rb_obj_is_data_class (VALUE rtype);
|
|
711
|
+
|
|
712
|
+
/* The bodies of the Ruby methods that freeze an array, report its
|
|
713
|
+
attributes and its type, and read its data class. An extension reads
|
|
714
|
+
the attributes from the struct (ca->obj_type, ca->data_type, ca->ndim,
|
|
715
|
+
ca->bytes, ca->flags, ca->elements, ca->dim), tests the data type with
|
|
716
|
+
the ca_is_*_type functions and the kind of array with ca_is_entity,
|
|
717
|
+
ca_is_view, ca_is_attached, ca_is_empty, ca_is_readonly,
|
|
718
|
+
ca_is_mask_array, ca_is_value_array and ca_is_scalar, and calls the
|
|
719
|
+
other methods (freeze, set_read_only_flag, data_class, members,
|
|
720
|
+
fields, ...) with rb_funcall. */
|
|
721
|
+
VALUE rb_ca_freeze (VALUE self);
|
|
722
|
+
VALUE rb_ca_set_read_only_flag (VALUE self);
|
|
723
|
+
|
|
724
|
+
VALUE rb_ca_obj_type (VALUE self);
|
|
725
|
+
VALUE rb_ca_data_type (VALUE self);
|
|
726
|
+
VALUE rb_ca_ndim (VALUE self);
|
|
727
|
+
VALUE rb_ca_bytes (VALUE self);
|
|
728
|
+
VALUE rb_ca_flags (VALUE self);
|
|
729
|
+
VALUE rb_ca_elements (VALUE self);
|
|
730
|
+
VALUE rb_ca_dim (VALUE self);
|
|
731
|
+
VALUE rb_ca_data_type_name (VALUE self);
|
|
732
|
+
|
|
733
|
+
VALUE rb_ca_is_fixlen_type (VALUE self);
|
|
734
|
+
VALUE rb_ca_is_boolean_type (VALUE self);
|
|
735
|
+
VALUE rb_ca_is_integer_type (VALUE self);
|
|
736
|
+
VALUE rb_ca_is_float_type (VALUE self);
|
|
737
|
+
VALUE rb_ca_is_complex_type (VALUE self);
|
|
738
|
+
VALUE rb_ca_is_object_type (VALUE self);
|
|
739
|
+
|
|
740
|
+
VALUE rb_ca_is_entity (VALUE self);
|
|
741
|
+
VALUE rb_ca_is_virtual (VALUE self);
|
|
742
|
+
VALUE rb_ca_is_attached (VALUE self);
|
|
743
|
+
VALUE rb_ca_is_empty (VALUE self);
|
|
744
|
+
VALUE rb_ca_is_read_only (VALUE self);
|
|
745
|
+
VALUE rb_ca_is_mask_array (VALUE self);
|
|
746
|
+
VALUE rb_ca_is_value_array (VALUE self);
|
|
747
|
+
|
|
748
|
+
VALUE rb_ca_is_scalar (VALUE self);
|
|
749
|
+
|
|
750
|
+
VALUE rb_ca_has_data_class (VALUE self);
|
|
751
|
+
VALUE rb_ca_data_class (VALUE self);
|
|
752
|
+
/* CArray#data_class= raises ArgumentError and points to CARecord.new /
|
|
753
|
+
CARecord.wrap; its function (rb_ca_set_data_class) is defined in
|
|
754
|
+
carray_attribute.c and not declared here. */
|
|
755
|
+
VALUE rb_ca_data_class_decode (VALUE self, VALUE str);
|
|
756
|
+
VALUE rb_ca_data_class_encode (VALUE self, VALUE obj);
|
|
757
|
+
VALUE rb_ca_members (VALUE self);
|
|
758
|
+
VALUE rb_ca_face_field (VALUE self, VALUE sym);
|
|
759
|
+
VALUE rb_ca_fields_at (int argc, VALUE *argv, VALUE self);
|
|
760
|
+
VALUE rb_ca_fields (VALUE self);
|
|
761
|
+
|
|
762
|
+
/* The bodies of has_mask?, any_masked?, all_masked?, inherit_mask and
|
|
763
|
+
inherit_mask_replace. An extension tests the mask with ca_has_mask,
|
|
764
|
+
ca_is_any_masked and ca_is_all_masked, and gives an output the mask of
|
|
765
|
+
its operands with ca_copy_mask_overlay or ca_mask_overlay_safe. */
|
|
766
|
+
VALUE rb_ca_has_mask (VALUE self);
|
|
767
|
+
VALUE rb_ca_is_any_masked (VALUE self);
|
|
768
|
+
VALUE rb_ca_is_all_masked (VALUE self);
|
|
769
|
+
VALUE rb_ca_inherit_mask_replace_n (VALUE self, int argc, VALUE *argv);
|
|
770
|
+
VALUE rb_ca_inherit_mask_replace (VALUE self, int n, ...);
|
|
771
|
+
VALUE rb_ca_inherit_mask_n (VALUE self, int argc, VALUE *argv);
|
|
772
|
+
VALUE rb_ca_inherit_mask (VALUE self, int n, ...);
|
|
773
|
+
|
|
774
|
+
/* The bodies of the Ruby methods to_ca, addr2index, the elem_* family,
|
|
775
|
+
the conversions named by a data type (int8, float64, object, ...),
|
|
776
|
+
to_a, seq, seq!, where and swap_bytes, with the helpers behind them.
|
|
777
|
+
An extension calls these methods with rb_funcall, or uses the C
|
|
778
|
+
functions for the same work: ca_addr2index, ca_fetch_index /
|
|
779
|
+
ca_store_index or rb_ca_fetch_index / rb_ca_store_index for single
|
|
780
|
+
cells, rb_ca_ptr2obj and rb_ca_obj2ptr for a cell's bytes, ca_ptr2ptr
|
|
781
|
+
and ca_cast_block to convert cells, and rb_ca_to_type to convert an
|
|
782
|
+
array.
|
|
783
|
+
|
|
784
|
+
rb_ca_store_all is the body behind self[] = val that carray's own
|
|
785
|
+
sources call; an extension stores val in every cell with
|
|
786
|
+
rb_ca_store2(self, 0, NULL, val). */
|
|
787
|
+
VALUE rb_ca_store_all (VALUE self, VALUE val);
|
|
788
|
+
|
|
789
|
+
VALUE rb_ca_to_ca (int argc, VALUE *argv, VALUE self);
|
|
790
|
+
|
|
791
|
+
/* address calculation */
|
|
792
|
+
VALUE rb_ca_addr2index (VALUE self, VALUE raddr);
|
|
793
|
+
|
|
794
|
+
#define rb_ca_fetch_ptr(self, ptr) rb_ca_ptr2obj(self, ptr)
|
|
795
|
+
#define rb_ca_store_ptr(self, ptr, val) rb_ca_obj2ptr(self, val, ptr)
|
|
796
|
+
|
|
797
|
+
/* elemental operations */
|
|
798
|
+
VALUE rb_ca_elem_swap (VALUE self, VALUE vidx1, VALUE vidx2);
|
|
799
|
+
VALUE rb_ca_elem_copy (VALUE self, VALUE vidx1, VALUE vidx2);
|
|
800
|
+
VALUE rb_ca_elem_store (VALUE self, VALUE vidx, VALUE obj);
|
|
801
|
+
VALUE rb_ca_elem_fetch (VALUE self, VALUE vidx);
|
|
802
|
+
VALUE rb_ca_elem_incr (VALUE self, VALUE vidx1);
|
|
803
|
+
VALUE rb_ca_elem_decr (VALUE self, VALUE vidx1);
|
|
804
|
+
VALUE rb_ca_elem_test_masked (VALUE self, VALUE vidx1);
|
|
805
|
+
|
|
806
|
+
/* data type conversion */
|
|
807
|
+
VALUE rb_ca_ptr2ptr (VALUE ra1, void *ptr1, VALUE ra2, void *ptr2);
|
|
808
|
+
VALUE rb_ca_cast_block (ca_size_t n, VALUE ra1, void *ptr1,
|
|
809
|
+
VALUE ra2, void *ptr2);
|
|
810
|
+
|
|
811
|
+
VALUE rb_ca_to_boolean (VALUE self);
|
|
812
|
+
VALUE rb_ca_to_int8 (VALUE self);
|
|
813
|
+
VALUE rb_ca_to_uint8 (VALUE self);
|
|
814
|
+
VALUE rb_ca_to_int16 (VALUE self);
|
|
815
|
+
VALUE rb_ca_to_uint16 (VALUE self);
|
|
816
|
+
VALUE rb_ca_to_int32 (VALUE self);
|
|
817
|
+
VALUE rb_ca_to_uint32 (VALUE self);
|
|
818
|
+
VALUE rb_ca_to_int64 (VALUE self);
|
|
819
|
+
VALUE rb_ca_to_uint64 (VALUE self);
|
|
820
|
+
VALUE rb_ca_to_float32 (VALUE self);
|
|
821
|
+
VALUE rb_ca_to_float64 (VALUE self);
|
|
822
|
+
VALUE rb_ca_to_cmplx64 (VALUE self);
|
|
823
|
+
VALUE rb_ca_to_cmplx128 (VALUE self);
|
|
824
|
+
VALUE rb_ca_to_VALUE (VALUE self);
|
|
825
|
+
#define rb_ca_to_object(self) rb_ca_to_VALUE(self)
|
|
826
|
+
|
|
827
|
+
/* to ruby's array */
|
|
828
|
+
VALUE rb_ca_to_a (VALUE self);
|
|
829
|
+
|
|
830
|
+
/* generation */
|
|
831
|
+
VALUE rb_ca_seq_bang (VALUE self, VALUE offset, VALUE step);
|
|
832
|
+
VALUE rb_ca_seq_bang2 (VALUE self, int n, VALUE *args);
|
|
833
|
+
VALUE rb_ca_seq (VALUE self, VALUE offset, VALUE step);
|
|
834
|
+
VALUE rb_ca_seq2 (VALUE self, int n, VALUE *args);
|
|
835
|
+
VALUE rb_ca_where (VALUE self);
|
|
836
|
+
|
|
837
|
+
/* elemental byte swap */
|
|
838
|
+
VALUE rb_ca_swap_bytes_bang (VALUE self);
|
|
839
|
+
VALUE rb_ca_swap_bytes (VALUE self);
|
|
840
|
+
|
|
841
|
+
/* ---- The index walk and the debug hook ------------------------------- */
|
|
842
|
+
|
|
843
|
+
/* carray_loop.c — unified multi-dimensional index walk shared by
|
|
844
|
+
each_index / each_with_index / map_index! / map_with_index! and by
|
|
845
|
+
the construction-block sugar in rb_ca_initialize. */
|
|
846
|
+
#define CA_LOOP_WITH_VALUE 1
|
|
847
|
+
#define CA_LOOP_STORE 2
|
|
848
|
+
|
|
849
|
+
VALUE rb_ca_index_walk (VALUE self, CArray *ca, int8_t level,
|
|
850
|
+
ca_size_t *idx, VALUE ridx, int mode);
|
|
851
|
+
|
|
852
|
+
/* An empty function, for carray's own sources. */
|
|
853
|
+
void ca_debug ();
|
|
854
|
+
|
|
855
|
+
/* The kernel iterator's internal parts: the substrate the engine shares
|
|
856
|
+
with the descriptor framework and the CAStride family, and the
|
|
857
|
+
iterator's own declarations. The substrate's inline helpers use
|
|
858
|
+
ca_bounds_normalize_index, declared above. */
|
|
859
|
+
#include "ca_iter_substrate.h"
|
|
860
|
+
#include "ca_kernel_iterator_internal.h"
|
|
861
|
+
|
|
32
862
|
/* ---- properties a copy or a folded view must carry (ca_obj_refer.c) -------
|
|
33
863
|
|
|
34
864
|
Copies VALUE_ARRAY (dropping any mask), READ_ONLY and MASK_ARRAY from
|
|
@@ -183,6 +1013,11 @@ void rb_ca_set_lifted_from (VALUE lifted, VALUE face);
|
|
|
183
1013
|
(carray_cast.c): _to answers 1 / 0 (UNDEF), _store raises. */
|
|
184
1014
|
int ca_decimal_string_to (VALUE str, int8_t data_type, void *out);
|
|
185
1015
|
void ca_decimal_string_store (VALUE str, int8_t data_type, void *out);
|
|
1016
|
+
/* A boolean cell read from an object: a String by its words (1 / 0 /
|
|
1017
|
+
true / false), else true / false / 0 / 1; _to answers 0 for a cell that
|
|
1018
|
+
becomes UNDEF, _store raises (carray_cast.c). */
|
|
1019
|
+
int ca_boolean_value_to (VALUE v, void *out);
|
|
1020
|
+
void ca_boolean_value_store (VALUE v, void *out);
|
|
186
1021
|
|
|
187
1022
|
/* Give `ca` a mask holding `m` (one byte per cell) when any cell is set,
|
|
188
1023
|
and leave it without one otherwise. */
|
|
@@ -208,26 +1043,23 @@ ca_mask_from_bytes (CArray *ca, const boolean8_t *m)
|
|
|
208
1043
|
raises so that the others still receive what was written, and raises
|
|
209
1044
|
the first exception once all have been tried.
|
|
210
1045
|
|
|
211
|
-
ca_attach_window
|
|
212
|
-
'a' allocate + sync), runs body(arg), and closes every array however body
|
|
213
|
-
leaves. Any window inside which Ruby runs or something raises goes
|
|
214
|
-
through it; see the definition for what a raise does to 'w' and 'a'. */
|
|
1046
|
+
ca_attach_window is declared in carray.h. */
|
|
215
1047
|
|
|
216
1048
|
void ca_attach_all (CArray **list, int32_t n);
|
|
217
1049
|
void ca_sync_all (CArray **list, int32_t n);
|
|
218
1050
|
void ca_sync_carry_on (CArray *ca, volatile VALUE *error);
|
|
219
|
-
VALUE ca_attach_window (int32_t n, CArray **list, const char *modes,
|
|
220
|
-
VALUE (*body)(VALUE), VALUE arg);
|
|
221
1051
|
|
|
222
|
-
/*
|
|
1052
|
+
/* Arrays attached for a block can be left attached for good: Ruby does not
|
|
223
1053
|
run the ensure of a suspended Fiber that is collected (an Enumerator
|
|
224
1054
|
stopped with #next and dropped). ca_window_guard_arm makes a guard that
|
|
225
|
-
runs cleanup(arg) from a finalizer when that happens; the
|
|
226
|
-
it when it
|
|
227
|
-
|
|
1055
|
+
runs cleanup(arg) from a finalizer when that happens; the code that
|
|
1056
|
+
attached disarms it when it detaches normally (on Ruby 3.x only in the
|
|
1057
|
+
main Ractor, whose finalizer table is safe to change; the sentinel is
|
|
1058
|
+
then nil). arg is heap memory the guard frees, and mark marks the
|
|
1059
|
+
VALUEs it holds. ca_attach_window_yielding is
|
|
228
1060
|
ca_attach_window with such a guard; owners keeps the arrays alive. */
|
|
229
1061
|
VALUE ca_window_guard_arm (void (*cleanup)(void *), void (*mark)(void *),
|
|
230
|
-
void *arg, VALUE *sentinel);
|
|
1062
|
+
void *arg, volatile VALUE *sentinel);
|
|
231
1063
|
void ca_window_guard_disarm (VALUE guard, VALUE sentinel);
|
|
232
1064
|
VALUE ca_attach_window_yielding (VALUE owners, int32_t n, CArray **list,
|
|
233
1065
|
const char *modes, VALUE (*body)(VALUE),
|
|
@@ -285,7 +1117,7 @@ VALUE ca_window_create_bounds_mask (VALUE view);
|
|
|
285
1117
|
/* ca_stride_setup without asking the parent for its mask; see
|
|
286
1118
|
ca_view_inherit_mask. The in-tree subclasses use this. */
|
|
287
1119
|
|
|
288
|
-
int ca_stride_setup_view (CAStride *ca,
|
|
1120
|
+
int ca_stride_setup_view (CAStride *ca, int16_t obj_type, CArray *parent,
|
|
289
1121
|
int8_t data_type, ca_size_t bytes,
|
|
290
1122
|
int8_t ndim, ca_size_t *dim,
|
|
291
1123
|
ca_size_t *strides, ca_size_t base_offset);
|
|
@@ -416,7 +1248,8 @@ void ca_axis_view_sync_owned (void *ap);
|
|
|
416
1248
|
The constructors that DO belong to the ext-author surface stay in
|
|
417
1249
|
carray.h and are not repeated here: ca_wrap_new / rb_ca_wrap_new (adopt
|
|
418
1250
|
external memory), ca_stride_setup / ca_stride_new / rb_ca_stride_new
|
|
419
|
-
(author a strided view -- see
|
|
1251
|
+
(author a strided view -- see
|
|
1252
|
+
guides/devel/06_view_algebra_and_castride.md), and ca_refer_new /
|
|
420
1253
|
rb_ca_refer_new (reinterpret / re-mask, which a bridge gem does use). */
|
|
421
1254
|
|
|
422
1255
|
/* ca_obj_block.c */
|
|
@@ -467,10 +1300,34 @@ void ca_refuse_complex_into_real (CArray *ca, CArray *cv);
|
|
|
467
1300
|
void ca_cast_block_skip_masked (ca_size_t n, void *ap1, void *ptr1,
|
|
468
1301
|
void *ap2, void *ptr2, boolean8_t *m);
|
|
469
1302
|
|
|
470
|
-
/*
|
|
471
|
-
|
|
1303
|
+
/* The tolerance of is_close / is_equiv: a number, zero or positive. A
|
|
1304
|
+
negative or NaN tolerance is refused (ArgumentError) under the name
|
|
1305
|
+
`name` (carray_utils.c). */
|
|
1306
|
+
double ca_tolerance_arg (VALUE tol, const char *name);
|
|
1307
|
+
|
|
1308
|
+
/* Refuse a Ruby Array read as one value of a cell; kind is "an integer",
|
|
1309
|
+
"a float" or "a boolean" (carray_cast.c). */
|
|
1310
|
+
NORETURN(void ca_refuse_array_value (const char *kind));
|
|
1311
|
+
|
|
1312
|
+
/* Refuse nil read as one value of a cell (carray_cast.c). */
|
|
1313
|
+
NORETURN(void ca_refuse_nil_value (const char *kind));
|
|
1314
|
+
void ca_refuse_type_number (VALUE rtype);
|
|
1315
|
+
VALUE ca_record_view_of (VALUE obj, VALUE data_class, const char *method);
|
|
1316
|
+
void ca_refuse_data_class (VALUE rtype, const char *method);
|
|
1317
|
+
|
|
1318
|
+
/* Refuse v when it is a Ruby Array given where an array with a data type
|
|
1319
|
+
is expected; role names what it would have been (carray_cast.c). */
|
|
1320
|
+
void ca_refuse_ruby_array (VALUE v, const char *role);
|
|
472
1321
|
VALUE ca_answer_as_caller (VALUE (*body)(VALUE), VALUE arg);
|
|
473
1322
|
long ca_integer_arg (VALUE v, const char *arg, const char *name);
|
|
1323
|
+
/* A Ruby value for a number cell is a Numeric or UNDEF; a String or another
|
|
1324
|
+
object (a Time) is refused (TypeError). The second form checks the
|
|
1325
|
+
elements of a Ruby Array. */
|
|
1326
|
+
void ca_refuse_non_number_value (int8_t data_type, VALUE v);
|
|
1327
|
+
void ca_refuse_non_number_elements (int8_t data_type, VALUE ary);
|
|
1328
|
+
/* A true / false keyword: true, false or nil (nil reads as false), else
|
|
1329
|
+
ArgumentError "<method>: <arg>: must be true or false (got v)". */
|
|
1330
|
+
int ca_bool_arg (VALUE v, const char *arg);
|
|
474
1331
|
/* 1 with the position of an index key (an Integer, or a Float with no
|
|
475
1332
|
fraction while exact), 2 for an Integer past int64, 0 otherwise. */
|
|
476
1333
|
int ca_index_key_position (VALUE v, ca_size_t *out);
|
|
@@ -480,9 +1337,8 @@ ca_size_t ca_shape_elements (int8_t ndim, const ca_size_t *dim, ca_size_t byte
|
|
|
480
1337
|
void ca_check_index_array (VALUE v);
|
|
481
1338
|
VALUE ca_order_key (VALUE v, const char *name);
|
|
482
1339
|
void ca_check_integer_fits (VALUE v, int8_t data_type);
|
|
483
|
-
VALUE ca_obj2integer_fitting (VALUE v, int8_t data_type);
|
|
484
1340
|
/* A Ruby value stored into an integer cell of `dst`: refused when it does
|
|
485
|
-
not fit (
|
|
1341
|
+
not fit (rb_ca_obj2integer_fitting), except into the cells of a bit field
|
|
486
1342
|
view (ca_bitfield_beneath), which keep it modulo 2 ** bits
|
|
487
1343
|
(ca_integer_wrap_bits). */
|
|
488
1344
|
VALUE ca_obj2integer_store (CArray *dst, VALUE v, int8_t data_type);
|
|
@@ -493,22 +1349,53 @@ VALUE ca_bitfield_wrap_integer (CArray *ca, VALUE v);
|
|
|
493
1349
|
decimal integer, any other value through Integer() (1.5 is 1). */
|
|
494
1350
|
VALUE ca_integer_wrap_bits (VALUE v, int bits, int sign_extend);
|
|
495
1351
|
int ca_integer_range_side (VALUE v, int8_t data_type);
|
|
1352
|
+
VALUE ca_integer_wrap_to_type (VALUE v, int8_t data_type);
|
|
1353
|
+
enum {
|
|
1354
|
+
CA_SCALAR_FOR_RING,
|
|
1355
|
+
CA_SCALAR_FOR_MIN,
|
|
1356
|
+
CA_SCALAR_FOR_MAX,
|
|
1357
|
+
CA_SCALAR_FOR_ORDER,
|
|
1358
|
+
CA_SCALAR_FOR_COMPARE
|
|
1359
|
+
};
|
|
1360
|
+
void ca_scalar_operand_for_op (volatile VALUE *scalar, VALUE array,
|
|
1361
|
+
int how);
|
|
1362
|
+
void ca_scalar_operands_for_op (volatile VALUE *self,
|
|
1363
|
+
volatile VALUE *other, int how);
|
|
1364
|
+
|
|
1365
|
+
/* fma / fms operands beside the receiver taken as + and * take a scalar
|
|
1366
|
+
(carray_operator.c). */
|
|
1367
|
+
void ca_triop_ring_scalar_operands (volatile VALUE *self,
|
|
1368
|
+
volatile VALUE *other2,
|
|
1369
|
+
volatile VALUE *other3);
|
|
496
1370
|
int ca_obj_number_fits_integer (VALUE v, int8_t data_type);
|
|
497
1371
|
int ca_bincmp_integer_prepare (volatile VALUE *self, volatile VALUE *other,
|
|
498
1372
|
int op_id, int *signed_side);
|
|
499
1373
|
int ca_bincmp_answer_when_negative (int op_id, int signed_side);
|
|
1374
|
+
int ca_bincmp_tolerance_integer_prepare (VALUE self, VALUE other);
|
|
1375
|
+
VALUE ca_bincmp_tolerance_by_value (VALUE self, VALUE other,
|
|
1376
|
+
int is_equiv, double tol);
|
|
500
1377
|
long ca_axis_integer (VALUE raxis, const char *name);
|
|
501
1378
|
/* Refuse a write into a read-only array that is not frozen (carray_test.c);
|
|
502
1379
|
every guard calls this rather than raising its own. */
|
|
503
1380
|
NORETURN(void ca_refuse_read_only (void));
|
|
1381
|
+
/* A view reaches its parent's slots through the dispatchers (ca_attach,
|
|
1382
|
+
ca_xfer_all, ca_xfer_stride, ...), so a chain of views is walked by C
|
|
1383
|
+
recursion, one level of the dispatcher per view. Each dispatcher calls
|
|
1384
|
+
this on entry, before it takes anything, so a chain deeper than the
|
|
1385
|
+
machine stack raises SystemStackError instead of overflowing it. The
|
|
1386
|
+
VM's own detection turns an overflow into SystemStackError only on the
|
|
1387
|
+
main thread's stack; on a Fiber's stack it is a fatal error. */
|
|
1388
|
+
static inline void
|
|
1389
|
+
ca_check_stack_room (void)
|
|
1390
|
+
{
|
|
1391
|
+
if ( ruby_stack_check() ) {
|
|
1392
|
+
rb_raise(rb_eSysStackError, "stack level too deep (a chain of views)");
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
504
1395
|
/* Refuse an operator with no kernel for `data_type`, naming the method and
|
|
505
1396
|
the type (carray_operator.c); the eager operators and the lazy builders. */
|
|
506
1397
|
NORETURN(void ca_op_refuse_unimplemented (VALUE operand, int8_t data_type,
|
|
507
1398
|
VALUE eclass));
|
|
508
|
-
/* Refuse a rank above CA_RANK_MAX before any dim is written (carray_utils.c). */
|
|
509
|
-
void ca_check_rank_fits (long ndim, const char *name);
|
|
510
|
-
/* The checks of carray.h inside the library, each naming the method the
|
|
511
|
-
user called; the public ones stay as they are for extensions. */
|
|
512
1399
|
/* A wrap of a caller's buffer lent to a CAObject hook (CA_FLAG_LENT), and
|
|
513
1400
|
the mark that a view was taken of it while it was lent
|
|
514
1401
|
(CA_FLAG_LENT_VIEWED). rb_ca_set_parent sets the second; the hook's
|
|
@@ -538,65 +1425,10 @@ VALUE ca_cell_walk_run (VALUE (*body)(VALUE), VALUE arg);
|
|
|
538
1425
|
and the caller (an index view: CAGrid, CASelect, CAWindow, CAStack, ...),
|
|
539
1426
|
calling no Ruby. A transfer through such views down to entities cannot
|
|
540
1427
|
come back into an array, and is not recorded (ca_with_cyclic_check). */
|
|
541
|
-
void ca_register_cell_moving_view (
|
|
1428
|
+
void ca_register_cell_moving_view (int16_t obj_type);
|
|
542
1429
|
VALUE ca_iter_ensure_computing (CArray *ca, int32_t n, ca_iter_state *states,
|
|
543
1430
|
VALUE (*body)(VALUE), VALUE arg);
|
|
544
1431
|
|
|
545
|
-
#define CA_CHECK_DATA_TYPE_GIVEN(data_type) \
|
|
546
|
-
do { \
|
|
547
|
-
int ca_dt_ = (data_type); \
|
|
548
|
-
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE ) { \
|
|
549
|
-
rb_raise(rb_eArgError, "%s: invalid data_type id %i", \
|
|
550
|
-
ca_calling_method_name(), ca_dt_); \
|
|
551
|
-
} \
|
|
552
|
-
if ( ! ca_valid[ca_dt_] ) { \
|
|
553
|
-
rb_raise(rb_eCADataTypeError, "%s: data_type %s is disabled", \
|
|
554
|
-
ca_calling_method_name(), ca_type_name[ca_dt_]); \
|
|
555
|
-
} \
|
|
556
|
-
} while (0)
|
|
557
|
-
|
|
558
|
-
#define CA_CHECK_DIM_GIVEN(ndim, dim) \
|
|
559
|
-
do { \
|
|
560
|
-
int8_t i_; \
|
|
561
|
-
for (i_ = 0; i_ < (ndim); i_++) { \
|
|
562
|
-
if ( (dim)[i_] < 0 ) { \
|
|
563
|
-
rb_raise(rb_eArgError, "%s: negative size dimension at %i-dim", \
|
|
564
|
-
ca_calling_method_name(), i_); \
|
|
565
|
-
} \
|
|
566
|
-
} \
|
|
567
|
-
} while (0)
|
|
568
|
-
|
|
569
|
-
#define CA_CHECK_BYTES_GIVEN(data_type, bytes) \
|
|
570
|
-
do { \
|
|
571
|
-
if ( (data_type) == CA_FIXLEN ) { \
|
|
572
|
-
if ( (bytes) <= 0 ) { \
|
|
573
|
-
rb_raise(rb_eArgError, \
|
|
574
|
-
"%s: invalid bytes (a fixlen needs bytes: of 1 or more)", \
|
|
575
|
-
ca_calling_method_name()); \
|
|
576
|
-
} \
|
|
577
|
-
} \
|
|
578
|
-
else { \
|
|
579
|
-
(bytes) = ca_sizeof[(data_type)]; \
|
|
580
|
-
if ( (bytes) <= 0 ) { \
|
|
581
|
-
rb_raise(rb_eArgError, "%s: invalid bytes", ca_calling_method_name()); \
|
|
582
|
-
} \
|
|
583
|
-
} \
|
|
584
|
-
} while (0)
|
|
585
|
-
|
|
586
|
-
/* CA_CHECK_RANK inside the library: no axes at all is no shape, and above
|
|
587
|
-
CA_RANK_MAX goes to the part, which names the method. The public macro
|
|
588
|
-
stays as it is for extensions. */
|
|
589
|
-
#define CA_CHECK_RANK_GIVEN(ndim) \
|
|
590
|
-
do { \
|
|
591
|
-
long ca_nd_ = (long) (ndim); \
|
|
592
|
-
if ( ca_nd_ <= 0 ) { \
|
|
593
|
-
rb_raise(rb_eArgError, "invalid ndim"); \
|
|
594
|
-
} \
|
|
595
|
-
ca_check_rank_fits(ca_nd_, NULL); \
|
|
596
|
-
} while (0)
|
|
597
|
-
/* An `axis` argument as an axis in [0, ndim): the rule every entry taking
|
|
598
|
-
an axis from Ruby calls (carray_utils.c). */
|
|
599
|
-
int ca_normalize_axis_arg (VALUE raxis, int ndim, const char *name);
|
|
600
1432
|
VALUE ca_fill_as (VALUE fill, int8_t data_type);
|
|
601
1433
|
/* ---- Face MemoryView export (ca_obj_face.c) -------------------------------
|
|
602
1434
|
|
|
@@ -604,7 +1436,7 @@ VALUE ca_fill_as (VALUE fill, int8_t data_type);
|
|
|
604
1436
|
Face (CARecord, CAFixlenString); the MemoryView producer refuses every
|
|
605
1437
|
other Face. Unregistered Faces are refused. */
|
|
606
1438
|
|
|
607
|
-
void ca_face_register_memory_view (
|
|
1439
|
+
void ca_face_register_memory_view (int16_t obj_type, int exportable);
|
|
608
1440
|
int ca_face_memory_view_exportable (CArray *ca);
|
|
609
1441
|
|
|
610
1442
|
/* The reference and the operand of a comparison brought into one space (see
|
|
@@ -613,55 +1445,6 @@ int ca_face_memory_view_exportable (CArray *ca);
|
|
|
613
1445
|
void ca_face_reconcile_pair (volatile VALUE *pref, volatile VALUE *poperand,
|
|
614
1446
|
const char *name);
|
|
615
1447
|
|
|
616
|
-
/* ---- Empty regions ---------------------------------------------------------
|
|
617
|
-
|
|
618
|
-
A region with a zero count on some axis has no cells. The per-cell walks
|
|
619
|
-
visit their first cell before they test the counts, so every region
|
|
620
|
-
transfer returns on an empty region before it walks: a zero-cell caller
|
|
621
|
-
buffer has no room for that first cell. */
|
|
622
|
-
|
|
623
|
-
static inline int
|
|
624
|
-
ca_region_is_empty (int8_t ndim, const ca_size_t *counts)
|
|
625
|
-
{
|
|
626
|
-
int8_t k;
|
|
627
|
-
for ( k = 0; k < ndim; k++ ) {
|
|
628
|
-
if ( counts[k] <= 0 ) return 1;
|
|
629
|
-
}
|
|
630
|
-
return 0;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/* ---- An index into n places ----------------------------------------------
|
|
634
|
-
|
|
635
|
-
A negative index counts from the end; one outside 0...n after that raises
|
|
636
|
-
IndexError, naming the method the user called, `what` the index is (an
|
|
637
|
-
"index", an "address") and the value given. Every index door decides
|
|
638
|
-
this here. */
|
|
639
|
-
|
|
640
|
-
/* ca_index_out_of_range is declared in carray.h (CA_CHECK_INDEX uses it). */
|
|
641
|
-
|
|
642
|
-
static inline ca_size_t
|
|
643
|
-
ca_index_in_range (ca_size_t idx, ca_size_t n, const char *what)
|
|
644
|
-
{
|
|
645
|
-
ca_size_t i = ( idx < 0 ) ? idx + n : idx;
|
|
646
|
-
if ( i < 0 || i >= n ) {
|
|
647
|
-
ca_index_out_of_range(idx, n, what);
|
|
648
|
-
}
|
|
649
|
-
return i;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
/* The same for an index on axis `axis` of a multi-axis index. */
|
|
653
|
-
NORETURN(void ca_index_out_of_range_at (ca_size_t idx, ca_size_t n, int axis));
|
|
654
|
-
|
|
655
|
-
static inline ca_size_t
|
|
656
|
-
ca_index_in_range_at (ca_size_t idx, ca_size_t n, int axis)
|
|
657
|
-
{
|
|
658
|
-
ca_size_t i = ( idx < 0 ) ? idx + n : idx;
|
|
659
|
-
if ( i < 0 || i >= n ) {
|
|
660
|
-
ca_index_out_of_range_at(idx, n, axis);
|
|
661
|
-
}
|
|
662
|
-
return i;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
1448
|
/* ---- How many cells a result cell needs ---------------------------------
|
|
666
1449
|
|
|
667
1450
|
A reduction's result cell is UNDEF when fewer cells contribute to it than
|
|
@@ -678,21 +1461,30 @@ ca_too_few_present (ca_size_t present, ca_size_t min_count, ca_size_t least)
|
|
|
678
1461
|
}
|
|
679
1462
|
|
|
680
1463
|
long ca_min_count_arg (VALUE v, const char *name);
|
|
1464
|
+
|
|
1465
|
+
/* The sum, the product and the weighted sum (integer weights) of an
|
|
1466
|
+
integer array: the exact int64 / uint64 total, or the float64 one where
|
|
1467
|
+
that is out of range
|
|
1468
|
+
(carray_integer_total.c). The generated sum / prod dispatchers call it
|
|
1469
|
+
with their float64 fold (`general`) and their wrapping integer fold. */
|
|
1470
|
+
enum { CA_INTEGER_TOTAL_SUM, CA_INTEGER_TOTAL_PROD, CA_INTEGER_TOTAL_WSUM };
|
|
1471
|
+
VALUE ca_integer_total (int argc, VALUE *argv, VALUE self,
|
|
1472
|
+
VALUE (*general) (int, VALUE *, VALUE),
|
|
1473
|
+
VALUE (*wrapping) (int, VALUE *, VALUE),
|
|
1474
|
+
int kind);
|
|
1475
|
+
/* The running sum and product of an integer array (cumsum / cumprod), by
|
|
1476
|
+
the same rule: the int64 / uint64 running values, or the float64 scan
|
|
1477
|
+
where one of them is out of range. */
|
|
1478
|
+
VALUE ca_integer_scan (int argc, VALUE *argv, VALUE self,
|
|
1479
|
+
VALUE (*general) (int, VALUE *, VALUE),
|
|
1480
|
+
VALUE (*wrapping) (int, VALUE *, VALUE),
|
|
1481
|
+
int kind);
|
|
681
1482
|
VALUE ca_reduce_fill (VALUE result, VALUE fill, int whole);
|
|
1483
|
+
VALUE ca_reduce_fill_widening (VALUE result, VALUE fill, int whole,
|
|
1484
|
+
const char *name);
|
|
682
1485
|
int ca_symbol_choice (VALUE v, const char *arg, const char *c0,
|
|
683
1486
|
const char *c1, const char *name);
|
|
684
1487
|
|
|
685
|
-
/* Return the value of `call`, keeping the array `v` reachable until the call
|
|
686
|
-
has returned. A kernel reads its source through the CArray pointer only,
|
|
687
|
-
so a view made just to be passed in (a flattened or common-type view)
|
|
688
|
-
would otherwise be left to a garbage collection that runs while its
|
|
689
|
-
cells are read: `return kernel(v, ...)` lets the compiler drop `v`. */
|
|
690
|
-
#define CA_RETURN_KEEPING(v, call) do { \
|
|
691
|
-
VALUE ca_kept_result_ = (call); \
|
|
692
|
-
RB_GC_GUARD(v); \
|
|
693
|
-
return ca_kept_result_; \
|
|
694
|
-
} while (0)
|
|
695
|
-
|
|
696
1488
|
/* A NaN loses every contest of an extremum (min / max / minmax / the
|
|
697
1489
|
positions / the running cummin / cummax / pmin / pmax): it never displaces
|
|
698
1490
|
another value, the first number displaces it, and nothing but NaN answers
|
|
@@ -838,7 +1630,7 @@ void ca_multi_parent_value_trial_through (CArray *m, VALUE (*body)(VALUE)
|
|
|
838
1630
|
volatile VALUE keep_ = rb_ary_new(); \
|
|
839
1631
|
CArray *t = ca_multi_parent_value_trial((CArray *) (ap), keep_); \
|
|
840
1632
|
call; \
|
|
841
|
-
|
|
1633
|
+
(void) keep_; /* the call reads the stand-ins, which keep_ holds */ \
|
|
842
1634
|
} \
|
|
843
1635
|
} while (0)
|
|
844
1636
|
int ca_monop_writable_cast_target (CArray *ca, int8_t *target);
|
|
@@ -881,7 +1673,7 @@ int8_t ca_query_match_type (int8_t ref, VALUE query);
|
|
|
881
1673
|
VALUE ca_fixlen_widen_for_query (VALUE self, VALUE query);
|
|
882
1674
|
|
|
883
1675
|
static inline int
|
|
884
|
-
ca_query_match_applies (CArray *ref, VALUE query)
|
|
1676
|
+
ca_query_match_applies (CArray *ref, volatile VALUE query)
|
|
885
1677
|
{
|
|
886
1678
|
if ( ! ( ca_is_integer_type(ref) || ca_is_float_type(ref)
|
|
887
1679
|
|| ref->data_type == CA_BOOLEAN ) ) {
|
|
@@ -889,7 +1681,7 @@ ca_query_match_applies (CArray *ref, VALUE query)
|
|
|
889
1681
|
}
|
|
890
1682
|
if ( rb_obj_is_carray(query) ) {
|
|
891
1683
|
CArray *q;
|
|
892
|
-
|
|
1684
|
+
GetCArray(query, q);
|
|
893
1685
|
if ( ca_is_face(q) ) {
|
|
894
1686
|
return 0;
|
|
895
1687
|
}
|
|
@@ -918,16 +1710,32 @@ VALUE ca_truth_as_number (CArray *ca, VALUE v);
|
|
|
918
1710
|
/* eq / ne when no cell can match (carray_operator.c). */
|
|
919
1711
|
VALUE ca_bincmp_no_match (VALUE self, int ne);
|
|
920
1712
|
|
|
1713
|
+
/* A value a Face says none of its cells can be (its private method
|
|
1714
|
+
foreign_value?, asked when the Face defines it) (ca_cast.c). */
|
|
1715
|
+
int ca_face_value_foreign (VALUE self, VALUE v);
|
|
1716
|
+
|
|
921
1717
|
/* A value an array can not hold matches no cell as a value query: eq, ne,
|
|
922
1718
|
count and search answer as they do for an Integer outside the array's
|
|
923
1719
|
type. nil is such a value for every array but an object one, which
|
|
924
|
-
holds nil and is asked.
|
|
1720
|
+
holds nil and is asked. A Face answers for itself (ca_face_value_foreign):
|
|
1721
|
+
a time array, for one, is asked about a time and a time written as a
|
|
1722
|
+
String, and a Symbol or a Float is no time. */
|
|
925
1723
|
static inline int
|
|
926
|
-
ca_query_matches_nothing (CArray *ca, VALUE query)
|
|
1724
|
+
ca_query_matches_nothing (VALUE self, CArray *ca, VALUE query)
|
|
927
1725
|
{
|
|
928
1726
|
if ( NIL_P(query) ) {
|
|
929
1727
|
return ca->data_type != CA_OBJECT;
|
|
930
1728
|
}
|
|
1729
|
+
if ( ca_is_face(ca) ) {
|
|
1730
|
+
return ca_face_value_foreign(self, query);
|
|
1731
|
+
}
|
|
1732
|
+
/* a Complex with an imaginary part is no value of a real cell (one whose
|
|
1733
|
+
imaginary part is 0 is its real part, as eq reads it) */
|
|
1734
|
+
if ( RB_TYPE_P(query, T_COMPLEX) &&
|
|
1735
|
+
( ca_is_integer_type(ca) || ca_is_float_type(ca) ) &&
|
|
1736
|
+
! RTEST(rb_equal(rb_complex_imag(query), INT2FIX(0))) ) {
|
|
1737
|
+
return 1;
|
|
1738
|
+
}
|
|
931
1739
|
return ca_value_foreign_to(ca, query);
|
|
932
1740
|
}
|
|
933
1741
|
|
|
@@ -1080,4 +1888,310 @@ int ca_in_main_ractor (void);
|
|
|
1080
1888
|
free. The lock must not be held across a call that can raise. */
|
|
1081
1889
|
void ca_native_lock_without_gvl (rb_nativethread_lock_t *lock);
|
|
1082
1890
|
|
|
1891
|
+
/* ---- The kernel drivers (carray_operator.c) -------------------------- */
|
|
1892
|
+
|
|
1893
|
+
/* carray's own drivers, which run a table over arrays. An extension
|
|
1894
|
+
calls the Ruby method instead (rb_funcall), which reaches the table
|
|
1895
|
+
through them. */
|
|
1896
|
+
VALUE rb_ca_call_monop (VALUE self, ca_monop_func_t func[]);
|
|
1897
|
+
VALUE rb_ca_call_monop_bang (VALUE self, ca_monop_func_t func[]);
|
|
1898
|
+
/* Dtype-changing monop dispatch: out_data_types[in_data_type] gives the output
|
|
1899
|
+
data_type for each input data_type (= -1 if not implemented). Used by
|
|
1900
|
+
monops with output: { numeric: ..., complex: ... } Hash form (e.g. abs
|
|
1901
|
+
cmplx128 -> f64). Allocates output array of out_data_types[in_data_type]. */
|
|
1902
|
+
VALUE rb_ca_call_monop_typed (VALUE self, ca_monop_func_t func[], int8_t out_data_types[]);
|
|
1903
|
+
VALUE rb_ca_call_binop (VALUE self, VALUE other, ca_binop_func_t func[]);
|
|
1904
|
+
VALUE rb_ca_call_binop_bang (VALUE self, VALUE other, ca_binop_func_t func[]);
|
|
1905
|
+
|
|
1906
|
+
/* Kleene three-valued mask fixup for boolean AND (is_or=0) / OR (is_or=1),
|
|
1907
|
+
applied by the generated `&`/`|` wrappers after rb_ca_call_binop. No-op
|
|
1908
|
+
unless the output is boolean with a mask. */
|
|
1909
|
+
VALUE ca_kleene_bool_fixup (VALUE vout, VALUE vself, VALUE vother, int is_or);
|
|
1910
|
+
|
|
1911
|
+
/* Triop driver: applies a 3-input / 1-output kernel. Operand 1 = self,
|
|
1912
|
+
operands 2/3 are passed in. Common data_type promotion via
|
|
1913
|
+
rb_ca_cast_self_or_other applied pairwise. Scalar / array
|
|
1914
|
+
combinations (= 2^3 = 8 cases) are handled uniformly via
|
|
1915
|
+
ca_set_iterator(3, ...) which collapses scalar operands to stride 0. */
|
|
1916
|
+
VALUE rb_ca_call_triop (VALUE self, VALUE other2, VALUE other3,
|
|
1917
|
+
ca_triop_func_t func[]);
|
|
1918
|
+
VALUE rb_ca_call_triop_bang (VALUE self, VALUE other2, VALUE other3,
|
|
1919
|
+
ca_triop_func_t func[]);
|
|
1920
|
+
VALUE rb_ca_call_moncmp (VALUE self, ca_moncmp_func_t func[]);
|
|
1921
|
+
VALUE rb_ca_call_bincmp (VALUE self, VALUE other, ca_bincmp_func_t func[], double tol);
|
|
1922
|
+
|
|
1923
|
+
VALUE ca_math_call (VALUE mod, VALUE arg, ID id);
|
|
1924
|
+
|
|
1925
|
+
/* ---- The monop dispatch lookups (ca_monop_dispatch.c, ca_obj_monop.c) */
|
|
1926
|
+
|
|
1927
|
+
/* Look up the per-data_type kernel for a normal monop op_id. Returns NULL
|
|
1928
|
+
for cast op_ids (caller handles cast via ca_cast_block). */
|
|
1929
|
+
ca_monop_func_t ca_monop_kernel_lookup (uint16_t op_id, int8_t in_data_type);
|
|
1930
|
+
int ca_monop_op_id_of_table (ca_monop_func_t table[]);
|
|
1931
|
+
|
|
1932
|
+
/* A CAMonOp node for op_id over cary (CAMonOp.__build__ in Ruby): a cast
|
|
1933
|
+
node when op_id is CA_MONOP_CAST_BASE + a data type. */
|
|
1934
|
+
VALUE rb_ca_monop_build (VALUE cary, uint16_t op_id);
|
|
1935
|
+
|
|
1936
|
+
/* Returns true iff op_id encodes a cast operation. */
|
|
1937
|
+
int ca_monop_is_cast (uint16_t op_id);
|
|
1938
|
+
|
|
1939
|
+
/* Returns true iff op_id widens an integer parent to CA_FLOAT64 (the
|
|
1940
|
+
math functions: sqrt, sin, exp, ...). */
|
|
1941
|
+
int ca_monop_is_widening (uint16_t op_id);
|
|
1942
|
+
|
|
1943
|
+
/* Returns true iff op_id is a "writable view" op
|
|
1944
|
+
(= cast or byte_swap). These ops:
|
|
1945
|
+
- support writable view lifecycle (CA_FLAG_READ_ONLY not set)
|
|
1946
|
+
- have an inverse mapping for write-back (cast = reverse cast;
|
|
1947
|
+
byte_swap = involution = same op applied twice)
|
|
1948
|
+
- use CAFake-style attach/sync/detach lifecycle in CAMonOp
|
|
1949
|
+
(ca_attach(parent) in allocate/attach, op apply to fill ca.ptr,
|
|
1950
|
+
inverse op + memcpy to parent.ptr in sync, ca_detach(parent))
|
|
1951
|
+
Non-cast / non-byte_swap monop / monfunc remain read-only with
|
|
1952
|
+
chain materialise lifecycle. */
|
|
1953
|
+
int ca_monop_is_writable_view (uint16_t op_id);
|
|
1954
|
+
|
|
1955
|
+
/* Returns true iff `view` is a single-node CAMonOp with a cast op_id
|
|
1956
|
+
(= no further CAMonOp in the parent chain). The kernel iterator's
|
|
1957
|
+
per-fiber fused path takes such a view.
|
|
1958
|
+
|
|
1959
|
+
For chain CAMonOp (= depth ≥ 2, e.g. `a.lazy.sqrt.cast`), returns 0
|
|
1960
|
+
so the existing chain materialise path (= arena-pooled scratches)
|
|
1961
|
+
continues to handle the chain end-to-end.
|
|
1962
|
+
|
|
1963
|
+
`view` must be a non-NULL CArray*. Returns 0 for non-CAMonOp views.
|
|
1964
|
+
Defined in ca_obj_monop.c so it can access the CAMonOp struct internals
|
|
1965
|
+
(op_id tail field, parent pointer). */
|
|
1966
|
+
int ca_monop_view_is_single_cast (CArray *view);
|
|
1967
|
+
|
|
1968
|
+
/* Compute the output data_type for (op_id, parent_data_type). Mirrors existing
|
|
1969
|
+
eager mkmath rules. */
|
|
1970
|
+
int8_t ca_lazy_promote_monop (uint16_t op_id, int8_t parent_data_type);
|
|
1971
|
+
|
|
1972
|
+
/* Compute the data_type the kernel expects as input. When != parent_data_type,
|
|
1973
|
+
a CAMonOp(:cast_<data_type>) node must be inserted between this op and
|
|
1974
|
+
its parent (finding #1, cast-before). For cast op_ids, returns
|
|
1975
|
+
parent_data_type unchanged. */
|
|
1976
|
+
int8_t ca_monop_kernel_input_data_type (uint16_t op_id, int8_t parent_data_type);
|
|
1977
|
+
|
|
1978
|
+
/* ---- The binop dispatch lookups (ca_binop_dispatch.c) ---------------- */
|
|
1979
|
+
|
|
1980
|
+
/* Look up the same-type vv kernel for (op_id, common_dt). Returns NULL
|
|
1981
|
+
if not implemented. */
|
|
1982
|
+
ca_binop_func_t ca_binop_kernel_lookup_vv (uint16_t op_id, int8_t common_dt);
|
|
1983
|
+
|
|
1984
|
+
/* Compute output (= common) data_type via the existing eager promotion rule
|
|
1985
|
+
(ca_promote_type). */
|
|
1986
|
+
int8_t ca_lazy_promote_binop (uint16_t op_id, int8_t l_dt, int8_t r_dt);
|
|
1987
|
+
|
|
1988
|
+
/* What data_type does each operand need to be cast to before reaching the
|
|
1989
|
+
kernel? Returns common data_type for both (= cast-before route). When
|
|
1990
|
+
common != operand.data_type, caller inserts CAMonOp(:cast_<common>). */
|
|
1991
|
+
void ca_binop_kernel_input_data_types (uint16_t op_id, int8_t l_dt, int8_t r_dt,
|
|
1992
|
+
int8_t *out_l_in_dt, int8_t *out_r_in_dt);
|
|
1993
|
+
|
|
1994
|
+
/* The op id of a kernel table, and properties of an op id. */
|
|
1995
|
+
int ca_binop_op_id_of_table (ca_binop_func_t table[]);
|
|
1996
|
+
int ca_binop_picks_by_order (int op_id);
|
|
1997
|
+
int ca_binop_is_ring (int op_id);
|
|
1998
|
+
int ca_binop_scalar_operand_mode (int op_id);
|
|
1999
|
+
|
|
2000
|
+
/* ---- The triop dispatch lookups (ca_triop_dispatch.c) ---------------- */
|
|
2001
|
+
|
|
2002
|
+
/* Look up the triop kernel for (op_id, common_dt). Returns NULL if
|
|
2003
|
+
not implemented at the requested data_type. */
|
|
2004
|
+
ca_triop_func_t ca_triop_kernel_lookup_vvv (uint16_t op_id, int8_t common_dt);
|
|
2005
|
+
|
|
2006
|
+
/* 3-way promotion: common data_type of (dt1, dt2, dt3). For select it is
|
|
2007
|
+
that of the two branches (dt2, dt3); the condition is converted to it. */
|
|
2008
|
+
int8_t ca_lazy_promote_triop (uint16_t op_id, int8_t dt1, int8_t dt2, int8_t dt3);
|
|
2009
|
+
|
|
2010
|
+
/* Each operand's cast-target data_type (= common data_type for all three,
|
|
2011
|
+
the cast-before invariant). */
|
|
2012
|
+
void ca_triop_kernel_input_data_types (uint16_t op_id,
|
|
2013
|
+
int8_t dt1, int8_t dt2, int8_t dt3,
|
|
2014
|
+
int8_t *out_dt1, int8_t *out_dt2,
|
|
2015
|
+
int8_t *out_dt3);
|
|
2016
|
+
|
|
2017
|
+
/* ---- The bincmp dispatch lookups (ca_bincmp_dispatch.c) -------------- */
|
|
2018
|
+
|
|
2019
|
+
/* Look up the bincmp kernel for (op_id, common_dt). Returns NULL if
|
|
2020
|
+
not implemented at the requested data_type. All bincmp kernels write
|
|
2021
|
+
boolean8_t to ptr3. */
|
|
2022
|
+
ca_bincmp_func_t ca_bincmp_kernel_lookup (uint16_t op_id, int8_t common_dt);
|
|
2023
|
+
|
|
2024
|
+
/* Compute input common data_type via ca_promote_type. Output data_type is
|
|
2025
|
+
always CA_BOOLEAN (NOT returned here; CABinCmp.data_type is set
|
|
2026
|
+
directly). */
|
|
2027
|
+
int8_t ca_lazy_bincmp_promote (uint16_t op_id, int8_t l_dt, int8_t r_dt);
|
|
2028
|
+
|
|
2029
|
+
/* What data_type does each operand need to be cast to before reaching the
|
|
2030
|
+
kernel? Returns common data_type for both (= cast-before route, same as
|
|
2031
|
+
CABinOp). */
|
|
2032
|
+
void ca_bincmp_kernel_input_data_types (uint16_t op_id, int8_t l_dt, int8_t r_dt,
|
|
2033
|
+
int8_t *out_l_in_dt, int8_t *out_r_in_dt);
|
|
2034
|
+
|
|
2035
|
+
/* ---- The moncmp dispatch lookup (ca_moncmp_dispatch.c) --------------- */
|
|
2036
|
+
|
|
2037
|
+
/* Look up the moncmp kernel for (op_id, in_dt). Returns NULL if not
|
|
2038
|
+
implemented at the requested data_type. All moncmp kernels write
|
|
2039
|
+
boolean8_t to ptr2. No cast insertion needed (= kernel exists for
|
|
2040
|
+
all numeric data_types including integer, where it const-folds inside
|
|
2041
|
+
the kernel + preserves mask via skip semantics). */
|
|
2042
|
+
ca_moncmp_func_t ca_moncmp_kernel_lookup (uint16_t op_id, int8_t in_dt);
|
|
2043
|
+
|
|
2044
|
+
/* ---- carray's own Face parts (ca_obj_face.c) ------------------------- */
|
|
2045
|
+
|
|
2046
|
+
#include "ca_obj_face.h" /* the Face hook types the parts below use */
|
|
2047
|
+
|
|
2048
|
+
/* -- wrapper lift (Face or CALazyMarker) --
|
|
2049
|
+
|
|
2050
|
+
For carray's own view-making methods. An extension's view-making
|
|
2051
|
+
method lifts a Face with CA_FACE_LIFT_IF_FACE.
|
|
2052
|
+
|
|
2053
|
+
A Face and a CALazyMarker are both storage-identical wrappers: they add
|
|
2054
|
+
an interpretation over their parent's bytes without changing them. Both
|
|
2055
|
+
want the same invariant at a view-creating method -- the wrapper stays on
|
|
2056
|
+
top, and the view is built against what the wrapper wraps. For a Face
|
|
2057
|
+
that keeps `dt.shift(1)` a CATime; for a marker it keeps a fuse block's
|
|
2058
|
+
expression lazy instead of dropping out of the chain.
|
|
2059
|
+
|
|
2060
|
+
The flag test comes first and covers both bits in one mask, so an
|
|
2061
|
+
ordinary array leaves through a single AND. That matters: `[]` is the
|
|
2062
|
+
hottest method this is deployed on.
|
|
2063
|
+
|
|
2064
|
+
NOT interchangeable with CA_FACE_LIFT_IF_FACE. Face is lifted at ~24
|
|
2065
|
+
sites, including ones a marker must not follow it through -- `copy` owns
|
|
2066
|
+
its data, `sort` reorders values, `value` and `strip_mask` change what
|
|
2067
|
+
the mask means. Deploy this only where the result is a view whose shape
|
|
2068
|
+
was fixed at construction and which only moves positions. */
|
|
2069
|
+
#define CA_WRAPPER_LIFT(obj, self, ca) do { \
|
|
2070
|
+
if ( ca_test_flag((ca), CA_FLAG_IS_FACE | CA_FLAG_IS_LAZY_MARKER) \
|
|
2071
|
+
&& rb_obj_is_kind_of((obj), rb_cCArray) ) { \
|
|
2072
|
+
(obj) = ca_wrapper_lift((obj), (self), (ca)); \
|
|
2073
|
+
} \
|
|
2074
|
+
} while (0)
|
|
2075
|
+
|
|
2076
|
+
VALUE ca_wrapper_lift (VALUE view, VALUE wrapper, void *wrapper_ca);
|
|
2077
|
+
|
|
2078
|
+
/* -- carray's own Face parts --
|
|
2079
|
+
|
|
2080
|
+
These parts are for carray's own sources. An extension lifts a view
|
|
2081
|
+
with CA_FACE_LIFT_IF_FACE, converts through the hooks it registers, and
|
|
2082
|
+
gates its ordering and search kernels with the parts in ca_obj_face.h. */
|
|
2083
|
+
|
|
2084
|
+
/* Struct duplicate + parent + shape swap. The primitive under
|
|
2085
|
+
ca_face_lift; also called directly where a result is re-wrapped under
|
|
2086
|
+
a Face without going through a view (partition, generated reduce). */
|
|
2087
|
+
VALUE rb_ca_face_template (VALUE original_face, CArray *new_parent,
|
|
2088
|
+
ca_size_t *new_dim);
|
|
2089
|
+
|
|
2090
|
+
/* Lift a fresh array `result` (one a reduction, a scan or a partition built
|
|
2091
|
+
from the Face's storage) into the Face `face`: the same Face class over
|
|
2092
|
+
`result`, carrying the subclass tail, `result`'s mask and the state
|
|
2093
|
+
copy_state carries. `result` stays reachable through the new Face. */
|
|
2094
|
+
VALUE ca_face_relift_entity (VALUE face, VALUE result);
|
|
2095
|
+
|
|
2096
|
+
/* Face gate for the element-wise comparison operators (< <= > >=, eq, ne).
|
|
2097
|
+
When self is a Face over numeric storage, descends both operands to
|
|
2098
|
+
storage (ORDERABLE required) and reconciles a Face RHS via to_comparable;
|
|
2099
|
+
a fixlen-storage Face or a non-Face self is left untouched. Called from
|
|
2100
|
+
rb_ca_call_bincmp. See ca_obj_face.c for the full contract. */
|
|
2101
|
+
void ca_face_reconcile_comparison (volatile VALUE *pself,
|
|
2102
|
+
volatile VALUE *pother);
|
|
2103
|
+
|
|
2104
|
+
/* CAFace abstract base class init.
|
|
2105
|
+
Called from ruby_carray.c's Init after rb_cCAView is defined, before
|
|
2106
|
+
CATime / CATimedelta Init. */
|
|
2107
|
+
void Init_ca_face (void);
|
|
2108
|
+
|
|
2109
|
+
/* Composite Face data_class dispatch. Extern for direct C access from
|
|
2110
|
+
`rb_ca_data_class` (carray_attribute.c) into the CARecord tail.
|
|
2111
|
+
CA_OBJ_RECORD identifies the obj_type (assigned at runtime by
|
|
2112
|
+
ca_install_obj_type). A further composite Face follows the same
|
|
2113
|
+
pattern: an extern here and one case in the switch in
|
|
2114
|
+
carray_attribute.c. */
|
|
2115
|
+
extern int16_t CA_OBJ_RECORD;
|
|
2116
|
+
VALUE rb_ca_record_get_data_class (CArray *ca);
|
|
2117
|
+
|
|
2118
|
+
/* CA_OBJ_STRING identifies CAString, read by the store path
|
|
2119
|
+
(carray_access.c) to send an array source through the write hook. */
|
|
2120
|
+
extern int16_t CA_OBJ_STRING;
|
|
2121
|
+
|
|
2122
|
+
/* Single source of truth for the surface -> storage-domain conversion.
|
|
2123
|
+
Returns `obj` unchanged when `ca` is not a Face or when no hook is
|
|
2124
|
+
registered / defined (so a bare Integer / String passes through to the
|
|
2125
|
+
existing storage cast). Otherwise returns the storage-domain value the
|
|
2126
|
+
Face produced. Called from rb_ca_obj2ptr (single-cell / fill / masked /
|
|
2127
|
+
range stores) and from the Array-of-scalars bulk store branch. */
|
|
2128
|
+
VALUE ca_face_element_to_storage (VALUE self, CArray *ca, VALUE obj);
|
|
2129
|
+
|
|
2130
|
+
/* The tables the registration functions write, one entry per obj_type. */
|
|
2131
|
+
extern ca_face_element_to_storage_fn ca_face_element_to_storage_table[];
|
|
2132
|
+
extern ca_face_state_compatible_fn ca_face_state_compatible_table[];
|
|
2133
|
+
extern int8_t ca_face_state_portable_table[];
|
|
2134
|
+
|
|
2135
|
+
/* Dispatch order:
|
|
2136
|
+
1. C hook registered for a->obj_type → call hook, return its result
|
|
2137
|
+
2. Else if the Ruby class of `va` defines `face_state_compatible?`
|
|
2138
|
+
on a Face subclass (= overrides CArray's default) → invoke with
|
|
2139
|
+
`vb`, return RTEST of result
|
|
2140
|
+
3. Else → 1 (= default compatible, class identity only)
|
|
2141
|
+
Caller must pre-check a->obj_type == b->obj_type. `va` / `vb` are
|
|
2142
|
+
the Ruby VALUEs of the same instances (used only for the Ruby fallback
|
|
2143
|
+
path). */
|
|
2144
|
+
int ca_face_state_compatible (VALUE va, CArray *a, VALUE vb, CArray *b);
|
|
2145
|
+
|
|
2146
|
+
/* Dispatch:
|
|
2147
|
+
1. C table entry registered for obj_type → return that value
|
|
2148
|
+
2. Else if the Ruby class `klass` defines a singleton method
|
|
2149
|
+
`face_state_portable?` (= subclass owns it) → invoke and RTEST
|
|
2150
|
+
3. Else → 1 (= default portable)
|
|
2151
|
+
`klass` is the Ruby class of the Face instance (used for the Ruby
|
|
2152
|
+
fallback path). Pass Qnil when the class is unknown / unavailable
|
|
2153
|
+
(= falls through to default). */
|
|
2154
|
+
int ca_face_state_portable (int16_t obj_type, VALUE klass);
|
|
2155
|
+
|
|
2156
|
+
/* Check a list of arrays about to be combined into one (CAStack, CAMeld,
|
|
2157
|
+
promote_list). Returns the Face class every element shares, or Qnil
|
|
2158
|
+
when none of them is a Face; the combined array is then lifted into
|
|
2159
|
+
that class. Raises ArgumentError for a mix of Face and non-Face arrays
|
|
2160
|
+
or of two Face classes, for two or more of a Face whose state is not
|
|
2161
|
+
portable, and for elements whose state differs from the first one's.
|
|
2162
|
+
`who` names the caller at the head of the message. */
|
|
2163
|
+
VALUE ca_face_list_class (VALUE list, const char *who);
|
|
2164
|
+
|
|
2165
|
+
/* A Face array's storage-side parent, one level down; any other array
|
|
2166
|
+
as it is. */
|
|
2167
|
+
VALUE ca_face_strip_one (VALUE v);
|
|
2168
|
+
|
|
2169
|
+
/* CArray#parent: for a Face, a read-only view of its storage; for any other
|
|
2170
|
+
array, its parent as it is. */
|
|
2171
|
+
VALUE rb_ca_parent_method (VALUE self);
|
|
2172
|
+
|
|
2173
|
+
/* The conversion a refusal of a Face whose cells encode its values points
|
|
2174
|
+
at (#to_string for a string Face, to_type(:object) for any other). */
|
|
2175
|
+
const char *ca_face_conversion_hint (VALUE face);
|
|
2176
|
+
|
|
2177
|
+
/* The method that gives the storage under a Face (#ticks, #codes), or NULL
|
|
2178
|
+
when the Face has none of those. */
|
|
2179
|
+
const char *ca_face_storage_method (VALUE face);
|
|
2180
|
+
|
|
2181
|
+
/* Raise eclass naming a Face that does not define the numeric operation
|
|
2182
|
+
`name`; returns when self is not a Face. See ca_obj_face.c. */
|
|
2183
|
+
void ca_face_refuse_numeric (VALUE self, const char *name, VALUE eclass);
|
|
2184
|
+
|
|
2185
|
+
/* Bring a Face operand into the reference's storage space, or refuse. A
|
|
2186
|
+
Face passes only if it declares COMPARABLE_STORAGE, i.e. its storage
|
|
2187
|
+
cells are the values it shows; anything else (a byte range, a code, a
|
|
2188
|
+
tick) is refused rather than compared as bytes. Non-Face operands are
|
|
2189
|
+
returned untouched. `name` opens the message. */
|
|
2190
|
+
VALUE ca_face_operand_descend (VALUE operand, const char *name);
|
|
2191
|
+
|
|
2192
|
+
/* `==` (strict = 0) / `eql?` (strict = 1) when an operand is a Face other
|
|
2193
|
+
than a record array. See ca_obj_face.c. */
|
|
2194
|
+
int ca_face_equal (VALUE va, VALUE vb, int strict);
|
|
2195
|
+
|
|
2196
|
+
|
|
1083
2197
|
#endif /* CARRAY_INTERNAL_H */
|