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.h
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
|
2
|
+
|
|
3
|
+
carray.h -- the C interface of CArray, for extension authors
|
|
4
|
+
|
|
5
|
+
This header is what an extension gets from `#include "carray.h"`. What
|
|
6
|
+
it declares to an extension is the contract, fixed for the rest of 3.x
|
|
7
|
+
from 3.0.10; a name it calls carray's own is not part of it even where
|
|
8
|
+
it is shown. It includes carray_config.h, carray_call_cfunc.h,
|
|
9
|
+
carray_math_kernel.h (with the five ca_*_dispatch.h headers) and
|
|
10
|
+
ca_kernel_iterator.h. The other two installed headers, ca_obj_face.h
|
|
11
|
+
and ca_for_buffer.h, an extension includes itself.
|
|
12
|
+
|
|
13
|
+
carray's own declarations are in carray_internal.h, which this header
|
|
14
|
+
includes at its end, after the sub-headers, only when carray itself is
|
|
15
|
+
built (CARRAY_BUILD defined).
|
|
16
|
+
|
|
17
|
+
---------------------------------------------------------------------------- */
|
|
18
|
+
|
|
1
19
|
#ifndef CARRAY_H
|
|
2
20
|
#define CARRAY_H
|
|
3
21
|
|
|
4
22
|
#include "ruby.h"
|
|
5
23
|
|
|
6
|
-
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
|
7
|
-
extern VALUE rb_cArithSeq;
|
|
8
|
-
#endif
|
|
9
|
-
|
|
10
24
|
/* -------------------------------------------------------------------- */
|
|
11
25
|
|
|
12
26
|
#include "carray_config.h"
|
|
@@ -135,11 +149,10 @@ typedef int8_t boolean8_t;
|
|
|
135
149
|
typedef dummy_t float64_t;
|
|
136
150
|
#endif
|
|
137
151
|
|
|
138
|
-
/* float128_t
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
these types. */
|
|
152
|
+
/* There is no float128_t or cmplx256_t. The enum slots CA_FLOAT128 (=12)
|
|
153
|
+
and CA_CMPLX256 (=15) are reserved holes so that CA_NTYPE-sized tables
|
|
154
|
+
keep their layout; ca_valid[12] and ca_valid[15] are 0, so no CArray of
|
|
155
|
+
these types can be created. */
|
|
143
156
|
|
|
144
157
|
#ifdef HAVE_COMPLEX_H
|
|
145
158
|
# include <complex.h>
|
|
@@ -173,72 +186,42 @@ typedef int8_t boolean8_t;
|
|
|
173
186
|
#define CA_ALIGN_CMPLX128 offsetof(struct { char c; cmplx128_t x; }, x)
|
|
174
187
|
#define CA_ALIGN_OBJECT offsetof(struct { char c; VALUE x; }, x)
|
|
175
188
|
|
|
176
|
-
/*
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
/* Cells may sit at any byte. A view's cells need not be aligned to their
|
|
190
|
+
size: a struct member at offset 1, a refer with a byte offset, a wrapped
|
|
191
|
+
external buffer. Reading a cell through a plain `double *` there is
|
|
192
|
+
undefined (x86 vector code may assume the alignment), so a kernel reads
|
|
193
|
+
and writes cells through a type declared with CA_UNALIGNED, for example
|
|
194
|
+
`typedef double my_cell_t CA_UNALIGNED;`. Such a type has the size and
|
|
195
|
+
value of the plain type; only the alignment the compiler may assume is
|
|
196
|
+
1. The kernel-iterator macros declare theirs this way. */
|
|
182
197
|
#if defined(__GNUC__) || defined(__clang__)
|
|
183
198
|
# define CA_UNALIGNED __attribute__((aligned(1)))
|
|
184
199
|
#else
|
|
185
200
|
# define CA_UNALIGNED
|
|
186
201
|
#endif
|
|
187
|
-
typedef boolean8_t ca_u_boolean8_t;
|
|
188
|
-
typedef int8_t ca_u_int8_t;
|
|
189
|
-
typedef uint8_t ca_u_uint8_t;
|
|
190
|
-
typedef int16_t ca_u_int16_t CA_UNALIGNED;
|
|
191
|
-
typedef uint16_t ca_u_uint16_t CA_UNALIGNED;
|
|
192
|
-
typedef int32_t ca_u_int32_t CA_UNALIGNED;
|
|
193
|
-
typedef uint32_t ca_u_uint32_t CA_UNALIGNED;
|
|
194
|
-
typedef int64_t ca_u_int64_t CA_UNALIGNED;
|
|
195
|
-
typedef uint64_t ca_u_uint64_t CA_UNALIGNED;
|
|
196
|
-
typedef float32_t ca_u_float32_t CA_UNALIGNED;
|
|
197
|
-
typedef float64_t ca_u_float64_t CA_UNALIGNED;
|
|
198
|
-
typedef cmplx64_t ca_u_cmplx64_t CA_UNALIGNED;
|
|
199
|
-
typedef cmplx128_t ca_u_cmplx128_t CA_UNALIGNED;
|
|
200
|
-
typedef VALUE ca_u_VALUE CA_UNALIGNED;
|
|
201
|
-
|
|
202
|
-
typedef ca_u_float32_t ca_u_float;
|
|
203
|
-
typedef ca_u_float64_t ca_u_double;
|
|
204
|
-
|
|
205
|
-
/* CA_U(float64_t) is ca_u_float64_t (and CA_U(double) ca_u_double): for a
|
|
206
|
-
macro that takes the cell type. */
|
|
207
|
-
#define CA_U(type) ca_u_##type
|
|
208
202
|
|
|
209
203
|
/* -------------------------------------------------------------------- */
|
|
210
204
|
|
|
211
|
-
|
|
205
|
+
/* CA_OBJ_TYPE_MAX and CA_NTYPE size the public tables (ca_class[],
|
|
206
|
+
ca_sizeof[], the ca_<family>_<op>[CA_NTYPE] dispatch tables, ...), so
|
|
207
|
+
both are fixed within 3.x. A data type added within 3.x takes one of
|
|
208
|
+
the reserved holes in the CA_DATA_TYPE enum below. */
|
|
209
|
+
#define CA_OBJ_TYPE_MAX 1024
|
|
212
210
|
#define CA_DIM_MAX 16
|
|
213
211
|
#define CA_RANK_MAX CA_DIM_MAX
|
|
214
|
-
#define CA_ATTACH_MAX 0x80000000
|
|
215
|
-
|
|
216
|
-
/* Assert an invariant to the optimizer (zero runtime cost). Used to teach
|
|
217
|
-
GCC's value-range propagation facts it cannot derive itself -- chiefly
|
|
218
|
-
`ndim <= CA_RANK_MAX`, which bounds loops and allocations over fixed
|
|
219
|
-
[CA_RANK_MAX] stack arrays. Without this, GCC (11.x) emits false-positive
|
|
220
|
-
-Wstringop-overflow / -Wmaybe-uninitialized / -Walloc-size-larger-than on
|
|
221
|
-
those loops because `int8_t ndim` ranges up to 127 as far as it can see.
|
|
222
|
-
The asserted conditions are hard invariants (CA_CHECK_RANK enforces them at
|
|
223
|
-
array creation); a violation is genuinely unreachable. */
|
|
224
|
-
#if defined(__GNUC__) || defined(__clang__)
|
|
225
|
-
# define CA_ASSUME(cond) do { if ( !(cond) ) __builtin_unreachable(); } while (0)
|
|
226
|
-
#else
|
|
227
|
-
# define CA_ASSUME(cond) ((void)0)
|
|
228
|
-
#endif
|
|
229
212
|
|
|
230
213
|
#define CA_FLAG_SCALAR 1
|
|
231
214
|
#define CA_FLAG_MASK_ARRAY 2
|
|
232
215
|
#define CA_FLAG_VALUE_ARRAY 4
|
|
233
216
|
#define CA_FLAG_READ_ONLY 8
|
|
234
217
|
#define CA_FLAG_SHARE_INDEX 16
|
|
235
|
-
/*
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
the
|
|
218
|
+
/* Bit 32 marks a view with more than one parent (CAStack, CAMeld and the
|
|
219
|
+
lazy CABinOp / CABinCmp / CATriOp). Generic routines that walk a single
|
|
220
|
+
->parent test this flag and instead fold over the parents[] exposed by
|
|
221
|
+
the CAMultiParent layout convention. */
|
|
239
222
|
#define CA_FLAG_MULTI_PARENTS 32
|
|
240
|
-
/*
|
|
241
|
-
|
|
223
|
+
/* Bit 64 is unused: the cyclic-read check (ca_test_cyclic_check) writes no
|
|
224
|
+
flag to the array. */
|
|
242
225
|
#define CA_FLAG_IS_FACE 128
|
|
243
226
|
/* Face opt-in ordering/search flags.
|
|
244
227
|
A Face declares that its numeric storage may be descended to for kernel
|
|
@@ -258,23 +241,10 @@ typedef ca_u_float64_t ca_u_double;
|
|
|
258
241
|
search / count / value-hash entries. Whether COMPARABLE holds is likewise
|
|
259
242
|
not a question of being numeric but of carrying a unit -- CATimedelta is
|
|
260
243
|
int64 on both sides and still sets ORDERABLE only. */
|
|
261
|
-
/* CALazyMarker. A marker layers "read this as the leaf of a lazy chain"
|
|
262
|
-
over storage that is identical to its parent's — the same premise as
|
|
263
|
-
CA_FLAG_IS_FACE — so the two are asked about together wherever a
|
|
264
|
-
storage-identical wrapper has to be seen through. Kept as its own bit
|
|
265
|
-
rather than folded into CA_FLAG_IS_FACE: ca_is_face is read in ~100
|
|
266
|
-
places that mean the Face mechanism specifically. */
|
|
267
|
-
#define CA_FLAG_IS_LAZY_MARKER 1024
|
|
268
|
-
|
|
269
244
|
#define CA_FLAG_FACE_ORDERABLE_STORAGE 256
|
|
270
245
|
#define CA_FLAG_FACE_COMPARABLE_STORAGE 512
|
|
271
246
|
/* NOTE: `flags` is int32_t, so there is plenty of bit space left. */
|
|
272
247
|
|
|
273
|
-
enum {
|
|
274
|
-
CA_LITTLE_ENDIAN = 0,
|
|
275
|
-
CA_BIG_ENDIAN = 1
|
|
276
|
-
};
|
|
277
|
-
|
|
278
248
|
enum {
|
|
279
249
|
CA_REAL_ARRAY,
|
|
280
250
|
CA_VIEW_ARRAY
|
|
@@ -284,11 +254,11 @@ enum {
|
|
|
284
254
|
CA_OBJ_ARRAY,
|
|
285
255
|
CA_OBJ_ARRAY_WRAP,
|
|
286
256
|
CA_OBJ_SCALAR,
|
|
287
|
-
CA_OBJ_REFER,
|
|
288
|
-
CA_OBJ_BLOCK,
|
|
289
|
-
CA_OBJ_SELECT,
|
|
257
|
+
CA_OBJ_REFER, /* carray's own view; not for extensions */
|
|
258
|
+
CA_OBJ_BLOCK, /* carray's own view; not for extensions */
|
|
259
|
+
CA_OBJ_SELECT, /* carray's own view; not for extensions */
|
|
290
260
|
CA_OBJ_OBJECT,
|
|
291
|
-
CA_OBJ_REPEAT,
|
|
261
|
+
CA_OBJ_REPEAT, /* carray's own view; not for extensions */
|
|
292
262
|
};
|
|
293
263
|
|
|
294
264
|
enum {
|
|
@@ -311,25 +281,8 @@ enum {
|
|
|
311
281
|
CA_CMPLX256, /* 15 */
|
|
312
282
|
CA_OBJECT, /* 16 */
|
|
313
283
|
CA_NTYPE, /* 17 */
|
|
314
|
-
CA_BYTE = CA_UINT8,
|
|
315
|
-
CA_SHORT = CA_INT16,
|
|
316
|
-
CA_INT = CA_INT32,
|
|
317
|
-
CA_FLOAT = CA_FLOAT32,
|
|
318
|
-
CA_DOUBLE = CA_FLOAT64,
|
|
319
|
-
CA_COMPLEX = CA_CMPLX64,
|
|
320
|
-
CA_DCOMPLEX = CA_CMPLX128,
|
|
321
284
|
}; /* CA_DATA_TYPE */
|
|
322
285
|
|
|
323
|
-
enum {
|
|
324
|
-
CA_BOUNDS_RUBY = 1,
|
|
325
|
-
CA_BOUNDS_STRICT,
|
|
326
|
-
CA_BOUNDS_NEAREST,
|
|
327
|
-
CA_BOUNDS_PERIODIC,
|
|
328
|
-
CA_BOUNDS_REFLECT,
|
|
329
|
-
CA_BOUNDS_FILL,
|
|
330
|
-
CA_BOUNDS_MASK,
|
|
331
|
-
}; /* CA_BOUNDS_TYPE for CAWindow */
|
|
332
|
-
|
|
333
286
|
/* -------------------------------------------------------------------- */
|
|
334
287
|
|
|
335
288
|
#ifdef HAVE_TYPE_INT64_T
|
|
@@ -347,10 +300,6 @@ enum {
|
|
|
347
300
|
#endif
|
|
348
301
|
|
|
349
302
|
/* -------------------------------------------------------------------- */
|
|
350
|
-
/* Per-axis descriptor framework (D1+D2+D3): types, producer interface,
|
|
351
|
-
and common attach engine. Lives in its own header so the carray.h
|
|
352
|
-
preamble stays focused on basic types + struct definitions. */
|
|
353
|
-
#include "ca_axis_descriptor.h"
|
|
354
303
|
|
|
355
304
|
/* xfer protocol direction flags. The protocol is walked through in
|
|
356
305
|
guides/devel/04_attach_lifecycle.md. */
|
|
@@ -419,9 +368,9 @@ typedef struct {
|
|
|
419
368
|
void (*pool_init) (void *ap, int8_t ndim); /* required if struct_size != 0 */
|
|
420
369
|
/* fill_addrs / fill_stride: write one value into part of the view.
|
|
421
370
|
fill_data carries no
|
|
422
|
-
region and so can only say "fill everything I cover"; without a region
|
|
423
|
-
|
|
424
|
-
|
|
371
|
+
region and so can only say "fill everything I cover"; without a region,
|
|
372
|
+
filling part of a view means borrowing a pointer, which materialises a
|
|
373
|
+
non-foldable root and writes all of it back. `ptr` is a
|
|
425
374
|
single element's worth of bytes, as for fill_data, since the value does
|
|
426
375
|
not scale with the region.
|
|
427
376
|
|
|
@@ -438,20 +387,6 @@ typedef struct {
|
|
|
438
387
|
ca_size_t *counts, ca_size_t *steps, void *ptr);
|
|
439
388
|
} ca_operation_function_t;
|
|
440
389
|
|
|
441
|
-
/* default operation_function */
|
|
442
|
-
|
|
443
|
-
void * ca_array_func_clone (void *ap);
|
|
444
|
-
void ca_array_func_allocate (void *ap);
|
|
445
|
-
void ca_array_func_attach (void *ap);
|
|
446
|
-
void ca_array_func_sync (void *ap);
|
|
447
|
-
void ca_array_func_detach (void *ap);
|
|
448
|
-
void ca_array_func_xfer_index (void *ap, ca_size_t *idx, void *data, int dir);
|
|
449
|
-
void ca_array_func_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs,
|
|
450
|
-
void *data, int dir);
|
|
451
|
-
void ca_array_func_xfer_all (void *ap, void *data, int dir);
|
|
452
|
-
void ca_array_func_fill_data (void *ap, void *val);
|
|
453
|
-
void ca_array_func_create_mask (void *ap);
|
|
454
|
-
|
|
455
390
|
/* Pool framework primitives (guides/devel/03_memory_management.md).
|
|
456
391
|
- ca_array_alloc: xmalloc(struct_size) + ca_array_pool_alloc().
|
|
457
392
|
For the C construction path (= replaces
|
|
@@ -459,14 +394,17 @@ void ca_array_func_create_mask (void *ap);
|
|
|
459
394
|
- ca_array_pool_alloc: xmalloc(pool_bytes(ndim)) into ca->_pool, then
|
|
460
395
|
run pool_init. For the initialize_copy path
|
|
461
396
|
where TypedData_Make_Struct has already
|
|
462
|
-
allocated the struct. Both
|
|
463
|
-
|
|
397
|
+
allocated the struct. Both take pool_bytes and
|
|
398
|
+
pool_init (and ca_array_alloc struct_size) from
|
|
399
|
+
the operation table obj_type was installed
|
|
400
|
+
with, so the table given to ca_install_obj_type
|
|
401
|
+
must fill them.
|
|
464
402
|
- ca_array_free: xfree(ca->_pool) and xfree(ca). Per-class
|
|
465
403
|
free_object callbacks call this branch when
|
|
466
404
|
ca->_pool != NULL; otherwise they fall through
|
|
467
405
|
to the legacy ALLOC_N free path. */
|
|
468
|
-
void * ca_array_alloc (
|
|
469
|
-
void ca_array_pool_alloc (void *ap,
|
|
406
|
+
void * ca_array_alloc (int16_t obj_type, int8_t ndim);
|
|
407
|
+
void ca_array_pool_alloc (void *ap, int16_t obj_type, int8_t ndim);
|
|
470
408
|
void ca_array_free (void *ap);
|
|
471
409
|
|
|
472
410
|
/* -------------------------------------------------------------------- */
|
|
@@ -475,84 +413,57 @@ void ca_array_free (void *ap);
|
|
|
475
413
|
|
|
476
414
|
typedef struct _CArray CArray;
|
|
477
415
|
|
|
416
|
+
/* The fields every array struct starts with, in this order. A view or
|
|
417
|
+
an obj_type installed by an extension declares its struct as
|
|
418
|
+
typedef struct { CA_ARRAY_HEADER <its own fields> } MyView;
|
|
419
|
+
so that a pointer to it can be read as a CArray *.
|
|
420
|
+
|
|
421
|
+
_pool framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
422
|
+
Ext authors must not read, write, or xfree it directly; see
|
|
423
|
+
ext/ca_array_pool.c.
|
|
424
|
+
_reserved kept for carray to use within 3.x without moving the
|
|
425
|
+
fields after the header. carray does not read it in this
|
|
426
|
+
release; ext authors must not read or write it. */
|
|
427
|
+
#define CA_ARRAY_HEADER \
|
|
428
|
+
int16_t obj_type; \
|
|
429
|
+
int8_t data_type; \
|
|
430
|
+
int8_t ndim; \
|
|
431
|
+
int32_t flags; \
|
|
432
|
+
ca_size_t bytes; \
|
|
433
|
+
ca_size_t elements; \
|
|
434
|
+
ca_size_t *dim; \
|
|
435
|
+
char *ptr; \
|
|
436
|
+
CArray *mask; \
|
|
437
|
+
char *_pool; \
|
|
438
|
+
void *_reserved[2];
|
|
439
|
+
|
|
478
440
|
struct _CArray {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
int8_t ndim;
|
|
482
|
-
int32_t flags;
|
|
483
|
-
ca_size_t bytes;
|
|
484
|
-
ca_size_t elements;
|
|
485
|
-
ca_size_t *dim;
|
|
486
|
-
char *ptr;
|
|
487
|
-
CArray *mask;
|
|
488
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
489
|
-
Reserved for framework use; ext authors must not read,
|
|
490
|
-
write, or xfree this field directly. See
|
|
491
|
-
ext/ca_array_pool.c. */
|
|
492
|
-
}; /* 28 + 4*ndim (bytes) */
|
|
441
|
+
CA_ARRAY_HEADER
|
|
442
|
+
};
|
|
493
443
|
|
|
494
444
|
typedef CArray CAWrap;
|
|
495
445
|
|
|
496
446
|
typedef struct {
|
|
497
|
-
|
|
498
|
-
int8_t data_type;
|
|
499
|
-
int8_t ndim;
|
|
500
|
-
int32_t flags;
|
|
501
|
-
ca_size_t bytes;
|
|
502
|
-
ca_size_t elements;
|
|
503
|
-
ca_size_t *dim;
|
|
504
|
-
char *ptr;
|
|
505
|
-
CArray *mask;
|
|
506
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
507
|
-
Reserved for framework use; ext authors must not read,
|
|
508
|
-
write, or xfree this field directly. See
|
|
509
|
-
ext/ca_array_pool.c. */
|
|
510
|
-
ca_size_t _dim;
|
|
511
|
-
} CScalar; /* 32 (bytes) */
|
|
512
|
-
|
|
513
|
-
typedef struct {
|
|
514
|
-
int16_t obj_type;
|
|
515
|
-
int8_t data_type;
|
|
516
|
-
int8_t ndim;
|
|
517
|
-
int32_t flags;
|
|
518
|
-
ca_size_t bytes;
|
|
519
|
-
ca_size_t elements;
|
|
520
|
-
ca_size_t *dim;
|
|
521
|
-
char *ptr;
|
|
522
|
-
CArray *mask;
|
|
523
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
524
|
-
Reserved for framework use; ext authors must not read,
|
|
525
|
-
write, or xfree this field directly. See
|
|
526
|
-
ext/ca_array_pool.c. */
|
|
447
|
+
CA_ARRAY_HEADER
|
|
527
448
|
CArray *parent;
|
|
528
449
|
uint32_t attach;
|
|
529
450
|
uint8_t nosync;
|
|
530
|
-
} CAView;
|
|
531
|
-
|
|
532
|
-
/* CARefer
|
|
533
|
-
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
451
|
+
} CAView;
|
|
452
|
+
|
|
453
|
+
/* CARefer: CAStride prefix + a `mask0` tail.
|
|
454
|
+
- A refer reads the parent's bytes as a row-major contiguous array of
|
|
455
|
+
its own data type, shape and element size, starting `offset` parent
|
|
456
|
+
elements in; reshape and byte reinterpretation both reduce to
|
|
457
|
+
(strides, base_offset). Whether the element size equals, divides or
|
|
458
|
+
spans the parent's follows from comparing ca->bytes with
|
|
459
|
+
ca->parent->bytes.
|
|
460
|
+
- `mask0` owns the intermediate that the visible mask refers to when
|
|
461
|
+
the element sizes differ: a CARepeat that spreads each parent mask
|
|
462
|
+
cell over the cells it divides into, or a CAReduce that ORs the
|
|
463
|
+
parent mask cells one view cell spans. NULL when the sizes are equal
|
|
464
|
+
and when the parent has no mask. */
|
|
542
465
|
typedef struct {
|
|
543
|
-
|
|
544
|
-
int8_t data_type;
|
|
545
|
-
int8_t ndim;
|
|
546
|
-
int32_t flags;
|
|
547
|
-
ca_size_t bytes;
|
|
548
|
-
ca_size_t elements;
|
|
549
|
-
ca_size_t *dim;
|
|
550
|
-
char *ptr;
|
|
551
|
-
CArray *mask;
|
|
552
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
553
|
-
Reserved for framework use; ext authors must not read,
|
|
554
|
-
write, or xfree this field directly. See
|
|
555
|
-
ext/ca_array_pool.c. */
|
|
466
|
+
CA_ARRAY_HEADER
|
|
556
467
|
CArray *parent;
|
|
557
468
|
uint32_t attach;
|
|
558
469
|
uint8_t nosync;
|
|
@@ -563,58 +474,8 @@ typedef struct {
|
|
|
563
474
|
CArray *mask0;
|
|
564
475
|
} CARefer;
|
|
565
476
|
|
|
566
|
-
/* CABlock (Phase E): CAStride prefix + native-spec tail.
|
|
567
|
-
The tail (offset, start, step, count, size0) is preserved for:
|
|
568
|
-
- public Ruby accessors (#offset, #start, #step, #count, #size0)
|
|
569
|
-
- #idx2addr0 / #addr2addr0 implementations
|
|
570
|
-
- block / dimension iterators that mutate start[] in place
|
|
571
|
-
After every mutation of `start[]`, base_offset must be
|
|
572
|
-
recomputed to stay consistent with the CAStride prefix.
|
|
573
|
-
|
|
574
|
-
The old maxdim_* gather-loop optimization fields are gone:
|
|
575
|
-
CAStride's own gather/scatter (P1/P1.5/P2/P3) does the same job. */
|
|
576
|
-
typedef struct {
|
|
577
|
-
int16_t obj_type;
|
|
578
|
-
int8_t data_type;
|
|
579
|
-
int8_t ndim;
|
|
580
|
-
int32_t flags;
|
|
581
|
-
ca_size_t bytes;
|
|
582
|
-
ca_size_t elements;
|
|
583
|
-
ca_size_t *dim;
|
|
584
|
-
char *ptr;
|
|
585
|
-
CArray *mask;
|
|
586
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
587
|
-
Reserved for framework use; ext authors must not read,
|
|
588
|
-
write, or xfree this field directly. See
|
|
589
|
-
ext/ca_array_pool.c. */
|
|
590
|
-
CArray *parent;
|
|
591
|
-
uint32_t attach;
|
|
592
|
-
uint8_t nosync;
|
|
593
|
-
/* --- CAStride prefix continues --- */
|
|
594
|
-
ca_size_t *strides;
|
|
595
|
-
ca_size_t base_offset;
|
|
596
|
-
/* --- CABlock tail (native spec) --- */
|
|
597
|
-
ca_size_t offset;
|
|
598
|
-
ca_size_t *start;
|
|
599
|
-
ca_size_t *step;
|
|
600
|
-
ca_size_t *count;
|
|
601
|
-
ca_size_t *size0;
|
|
602
|
-
} CABlock;
|
|
603
|
-
|
|
604
477
|
typedef struct {
|
|
605
|
-
|
|
606
|
-
int8_t data_type;
|
|
607
|
-
int8_t ndim;
|
|
608
|
-
int32_t flags;
|
|
609
|
-
ca_size_t bytes;
|
|
610
|
-
ca_size_t elements;
|
|
611
|
-
ca_size_t *dim;
|
|
612
|
-
char *ptr;
|
|
613
|
-
CArray *mask;
|
|
614
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
615
|
-
Reserved for framework use; ext authors must not read,
|
|
616
|
-
write, or xfree this field directly. See
|
|
617
|
-
ext/ca_array_pool.c. */
|
|
478
|
+
CA_ARRAY_HEADER
|
|
618
479
|
CArray *parent;
|
|
619
480
|
uint32_t attach;
|
|
620
481
|
uint8_t nosync;
|
|
@@ -623,295 +484,17 @@ typedef struct {
|
|
|
623
484
|
ca_size_t base_offset; /* byte offset from parent->ptr to view[0,...] */
|
|
624
485
|
} CAStride; /* CA_OBJ_STRIDE: generic strided view */
|
|
625
486
|
|
|
626
|
-
typedef struct {
|
|
627
|
-
int16_t obj_type;
|
|
628
|
-
int8_t data_type;
|
|
629
|
-
int8_t ndim;
|
|
630
|
-
int32_t flags;
|
|
631
|
-
ca_size_t bytes;
|
|
632
|
-
ca_size_t elements;
|
|
633
|
-
ca_size_t *dim;
|
|
634
|
-
char *ptr;
|
|
635
|
-
CArray *mask;
|
|
636
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
637
|
-
Reserved for framework use; ext authors must not read,
|
|
638
|
-
write, or xfree this field directly. See
|
|
639
|
-
ext/ca_array_pool.c. */
|
|
640
|
-
CArray *parent;
|
|
641
|
-
uint32_t attach;
|
|
642
|
-
uint8_t nosync;
|
|
643
|
-
/* ---------- */
|
|
644
|
-
uint8_t *bounds; /* [ndim] per-axis policy (a scalar uint8_t
|
|
645
|
-
before). Allows
|
|
646
|
-
CAShift (per-axis roll[]) to be expressed as
|
|
647
|
-
a CAWindow specialisation. */
|
|
648
|
-
ca_size_t *start;
|
|
649
|
-
ca_size_t *count;
|
|
650
|
-
ca_size_t *size0;
|
|
651
|
-
char *fill;
|
|
652
|
-
/* COMPOSITE_FAMILY Phase 1 (E.2): embed descriptor model. Computed by
|
|
653
|
-
ca_compute_embed_descriptor at setup time, immutable for view lifetime.
|
|
654
|
-
Used by attach/sync (E.3-E.4) to skip per-element bound checks via
|
|
655
|
-
"1 alias + 1 fill" decomposition. */
|
|
656
|
-
ca_size_t *embed_parent_start; /* [ndim] parent-side alias rectangle start */
|
|
657
|
-
ca_size_t *embed_count; /* [ndim] alias rectangle size per axis */
|
|
658
|
-
ca_size_t *embed_output_offset; /* [ndim] output-side alias rectangle start */
|
|
659
|
-
uint8_t embed_is_empty; /* 1 = fully out of parent, alias is empty */
|
|
660
|
-
uint8_t embed_covers_all; /* 1 = interior-only, fill is unused */
|
|
661
|
-
uint8_t embed_eligible; /* 1 = all bounds in {FILL, MASK}, attach
|
|
662
|
-
takes the embed fast path (E.3). Other
|
|
663
|
-
policies (PERIODIC/REFLECT/...) fall
|
|
664
|
-
back to the ca_axis_dispatch_* engine. */
|
|
665
|
-
uint8_t embed_alias_eligible; /* 1 = direct ca_attach(window) can alias
|
|
666
|
-
to parent->ptr without copy (Phase 1.5
|
|
667
|
-
E.8 A-path). Condition: embed_eligible
|
|
668
|
-
+ embed_covers_all + inner axes full
|
|
669
|
-
(count[k] == parent->dim[k] && start[k]
|
|
670
|
-
== 0 for k >= 1). Embedded region
|
|
671
|
-
must be contig in parent storage. */
|
|
672
|
-
/* A window over a parent that has no mask: the all-false mask its own
|
|
673
|
-
mask reads instead, so that masking the out-of-bounds cells gives the
|
|
674
|
-
parent no mask. Owned by this window; NULL otherwise. */
|
|
675
|
-
CArray *mask_standin;
|
|
676
|
-
/* On the mask of a window: the window whose mask it is, which holds the
|
|
677
|
-
stand-in and the parent whose mask replaces it. NULL otherwise. */
|
|
678
|
-
CArray *mask_owner;
|
|
679
|
-
} CAWindow; /* 56 + 16*(ndim) + 1*(bytes) + 1*ndim + 24*ndim (bytes) */
|
|
680
|
-
|
|
681
|
-
/* CAShift is a pure typedef of CAWindow. CAShift construction maps (shift[], roll[], fill,
|
|
682
|
-
fill_mask) onto CAWindow's (start = -shift, count = parent->dim,
|
|
683
|
-
bounds = roll ? PERIODIC : (fill_mask ? MASK : FILL), fill). The
|
|
684
|
-
two views share the operation table (ca_window_func); only obj_type
|
|
685
|
-
differs (CA_OBJ_SHIFT vs CA_OBJ_WINDOW) to preserve user-facing class
|
|
686
|
-
distinction. */
|
|
687
|
-
typedef CAWindow CAShift;
|
|
688
|
-
|
|
689
|
-
/* COMPOSITE_FAMILY Phase 2 (T.3, 2026-05-26): CATile = N-region
|
|
690
|
-
expansion view (tiled repetition of the parent). Output shape =
|
|
691
|
-
parent.dim * reps per axis; total tiles = product(reps). Each tile
|
|
692
|
-
is a full-parent alias at output offset
|
|
693
|
-
(i_0 * parent.dim[0], i_1 * parent.dim[1], ...). Attach iterates
|
|
694
|
-
total_tiles regions, calling ca_composite_region_gather for each.
|
|
695
|
-
|
|
696
|
-
CARoll = typedef CATile (same pattern as the
|
|
697
|
-
CAShift = CAWindow precedent); constructor parameters differ but the
|
|
698
|
-
C struct layout is shared, and the attach/sync routine is identical
|
|
699
|
-
(= dispatch the region list in order). */
|
|
700
|
-
typedef struct {
|
|
701
|
-
int16_t obj_type;
|
|
702
|
-
int8_t data_type;
|
|
703
|
-
int8_t ndim;
|
|
704
|
-
int32_t flags;
|
|
705
|
-
ca_size_t bytes;
|
|
706
|
-
ca_size_t elements;
|
|
707
|
-
ca_size_t *dim;
|
|
708
|
-
char *ptr;
|
|
709
|
-
CArray *mask;
|
|
710
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
711
|
-
Reserved for framework use; ext authors must not read,
|
|
712
|
-
write, or xfree this field directly. See
|
|
713
|
-
ext/ca_array_pool.c. */
|
|
714
|
-
CArray *parent;
|
|
715
|
-
uint32_t attach;
|
|
716
|
-
uint8_t nosync;
|
|
717
|
-
/* ---------- */
|
|
718
|
-
ca_size_t *reps; /* [ndim] number of tiles per axis.
|
|
719
|
-
Total tiles = product(reps).
|
|
720
|
-
dim[k] = parent->dim[k] * reps[k]. */
|
|
721
|
-
} CATile; /* 56 + 8*(ndim) (bytes) */
|
|
722
|
-
|
|
723
|
-
typedef CATile CARoll; /* same layout as CATile, its own obj_type
|
|
724
|
-
CA_OBJ_ROLL (ext/ca_obj_roll.c) */
|
|
725
|
-
|
|
726
|
-
/* CAStack: stack view of K uniform-shape parents. The K axis sits at
|
|
727
|
-
k_axis in the view's shape (0 by default: shape = (K, *parent_shape));
|
|
728
|
-
the other axes are the parents' own.
|
|
729
|
-
- parents stored as Ruby Array @parents on the wrapper object (= GC
|
|
730
|
-
anchor); C-side tail `parents[]` is alias pointer array.
|
|
731
|
-
- CAView.parent points to parents[0] (= legacy compat for paths that
|
|
732
|
-
deref ca->parent without CAStack awareness).
|
|
733
|
-
- dim[k_axis] = n_parents; the other dims are parents[0]->dim in order. */
|
|
734
|
-
typedef struct {
|
|
735
|
-
int16_t obj_type;
|
|
736
|
-
int8_t data_type;
|
|
737
|
-
int8_t ndim; /* = parents[0]->ndim + 1 */
|
|
738
|
-
int32_t flags;
|
|
739
|
-
ca_size_t bytes;
|
|
740
|
-
ca_size_t elements; /* = n_parents * parents[0]->elements */
|
|
741
|
-
ca_size_t *dim; /* ALLOC_N(ndim): parent->dim with n_parents at k_axis */
|
|
742
|
-
char *ptr;
|
|
743
|
-
CArray *mask;
|
|
744
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
745
|
-
Reserved for framework use; ext authors must not read,
|
|
746
|
-
write, or xfree this field directly. See
|
|
747
|
-
ext/ca_array_pool.c. */
|
|
748
|
-
CArray *parent; /* = parents[0] (legacy CAView field) */
|
|
749
|
-
uint32_t attach;
|
|
750
|
-
uint8_t nosync;
|
|
751
|
-
/* ---- CAStack tail ---- */
|
|
752
|
-
int32_t n_parents; /* K = axis-0 size */
|
|
753
|
-
CArray **parents; /* ALLOC_N(CArray*, n_parents); aliases, not owned */
|
|
754
|
-
int8_t k_axis; /* K axis insertion position in view shape, [0, parent_ndim].
|
|
755
|
-
0 = outer-axis stack (legacy default).
|
|
756
|
-
parent_ndim = K innermost (= old merge at=-1).
|
|
757
|
-
Set by ca_stack_setup_with_axis / preserved on clone. */
|
|
758
|
-
CArray **mask_standins; /* NULL, or ALLOC_N(CArray*, n_parents) once the mask is
|
|
759
|
-
built: the all-false masks standing in for parents that
|
|
760
|
-
have none (owned, freed with the view) */
|
|
761
|
-
CArray *mask_owner; /* on the mask of a CAStack: that CAStack, whose stand-ins
|
|
762
|
-
this mask reads until they give way to the parents'
|
|
763
|
-
own masks (ca_multi_parent_mask_refresh); else NULL */
|
|
764
|
-
} CAStack;
|
|
765
|
-
|
|
766
|
-
/* CAMeld (ragged concatenate view along an existing axis). Unlike CAStack
|
|
767
|
-
which introduces a new K axis, CAMeld welds K parents along one of their
|
|
768
|
-
existing axes and may have uneven segment lengths there.
|
|
769
|
-
shape[a] = parents[0]->dim[a] for a != meld_axis
|
|
770
|
-
shape[meld_axis] = sum_k parents[k]->dim[meld_axis]
|
|
771
|
-
All other axes must match across parents (uniform check at constructor).
|
|
772
|
-
|
|
773
|
-
meld_axis may be any axis. */
|
|
774
|
-
typedef struct {
|
|
775
|
-
int16_t obj_type;
|
|
776
|
-
int8_t data_type;
|
|
777
|
-
int8_t ndim; /* = parents[0]->ndim (no new axis) */
|
|
778
|
-
int32_t flags;
|
|
779
|
-
ca_size_t bytes;
|
|
780
|
-
ca_size_t elements; /* = sum_k parents[k]->elements */
|
|
781
|
-
ca_size_t *dim; /* ALLOC_N(ndim); dim[meld_axis]=seg_offset[K], else parents[0]->dim */
|
|
782
|
-
char *ptr;
|
|
783
|
-
CArray *mask;
|
|
784
|
-
char *_pool; /* framework-managed pool buffer; do not touch */
|
|
785
|
-
CArray *parent; /* = parents[0] (legacy CAView field) */
|
|
786
|
-
uint32_t attach;
|
|
787
|
-
uint8_t nosync;
|
|
788
|
-
/* ---- CAMeld tail (n_parents / parents kept adjacent to header for
|
|
789
|
-
CAMultiParent layout convention) ---- */
|
|
790
|
-
int32_t n_parents; /* K = number of segments */
|
|
791
|
-
CArray **parents; /* ALLOC_N(CArray*, K); aliases, not owned */
|
|
792
|
-
int8_t meld_axis; /* existing axis being welded, [0, parent_ndim) */
|
|
793
|
-
ca_size_t *seg_offset; /* ALLOC_N(ca_size_t, K+1); prefix sum along meld_axis.
|
|
794
|
-
seg_offset[0]=0, seg_offset[k+1]=seg_offset[k]+parents[k]->dim[meld_axis],
|
|
795
|
-
seg_offset[K]=dim[meld_axis]. */
|
|
796
|
-
CArray **mask_standins; /* as CAStack's: stand-in masks this view owns, or NULL */
|
|
797
|
-
CArray *mask_owner; /* as CAStack's */
|
|
798
|
-
} CAMeld;
|
|
799
|
-
|
|
800
|
-
/* Multi-parent view layout convention (CA_FLAG_MULTI_PARENTS). A view that
|
|
801
|
-
fans out to K parents must place `n_parents` + `parents[]` immediately after
|
|
802
|
-
the CAView header (exactly as CAStack does) so generic routines that would
|
|
803
|
-
otherwise walk a single ->parent can fold over all parents without knowing
|
|
804
|
-
the concrete view type. Cast `(CAMultiParent *) ca` only when the flag is
|
|
805
|
-
set. CAStack is the first conforming type (layout-checked in
|
|
806
|
-
Init_ca_obj_stack via offsetof). */
|
|
807
|
-
typedef struct {
|
|
808
|
-
CAView header; /* common view prefix (obj_type .. nosync) */
|
|
809
|
-
int32_t n_parents;
|
|
810
|
-
CArray **parents;
|
|
811
|
-
} CAMultiParent;
|
|
812
|
-
|
|
813
|
-
typedef struct {
|
|
814
|
-
int16_t obj_type;
|
|
815
|
-
int8_t data_type;
|
|
816
|
-
int8_t ndim;
|
|
817
|
-
int32_t flags;
|
|
818
|
-
ca_size_t bytes;
|
|
819
|
-
ca_size_t elements;
|
|
820
|
-
ca_size_t *dim;
|
|
821
|
-
char *ptr;
|
|
822
|
-
CArray *mask;
|
|
823
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
824
|
-
Reserved for framework use; ext authors must not read,
|
|
825
|
-
write, or xfree this field directly. See
|
|
826
|
-
ext/ca_array_pool.c. */
|
|
827
|
-
CArray *parent;
|
|
828
|
-
uint32_t attach;
|
|
829
|
-
uint8_t nosync;
|
|
830
|
-
/* -------------*/
|
|
831
|
-
CArray *data;
|
|
832
|
-
VALUE self;
|
|
833
|
-
} CAObject; /* 48 + 4*(ndim) (bytes) */
|
|
834
|
-
|
|
835
|
-
/*
|
|
836
|
-
CAObjectMask is an internal class used only as the mask array of a
|
|
837
|
-
CAObject. Its bits live in the CAObject's mask hooks (mask_copy_data,
|
|
838
|
-
mask_fetch_addr, ...) when it has them, and in `cache` -- the mask
|
|
839
|
-
buffer of the CAObject's internal data array -- always. Like the mask
|
|
840
|
-
of any view it is cold at rest: ptr is NULL, and every read and write
|
|
841
|
-
goes through its slots to the hooks. An attach publishes the cache in
|
|
842
|
-
ptr, and `holds` counts the attaches not yet detached.
|
|
843
|
-
*/
|
|
844
|
-
|
|
845
|
-
typedef struct {
|
|
846
|
-
int16_t obj_type;
|
|
847
|
-
int8_t data_type;
|
|
848
|
-
int8_t ndim;
|
|
849
|
-
int32_t flags;
|
|
850
|
-
ca_size_t bytes;
|
|
851
|
-
ca_size_t elements;
|
|
852
|
-
ca_size_t *dim;
|
|
853
|
-
char *ptr;
|
|
854
|
-
CArray *mask;
|
|
855
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
856
|
-
Reserved for framework use; ext authors must not read,
|
|
857
|
-
write, or xfree this field directly. See
|
|
858
|
-
ext/ca_array_pool.c. */
|
|
859
|
-
/* -------------*/
|
|
860
|
-
VALUE array;
|
|
861
|
-
char *cache;
|
|
862
|
-
long holds;
|
|
863
|
-
} CAObjectMask;
|
|
864
|
-
|
|
865
|
-
/* CARepeat (Phase R migration): structurally identical to CAStride.
|
|
866
|
-
The "repeat" axes are encoded as strides[k] == 0. */
|
|
867
|
-
typedef CAStride CARepeat;
|
|
868
|
-
|
|
869
|
-
/*
|
|
870
|
-
CAReduce is an internal class
|
|
871
|
-
used only in ca_obj_refer.c.
|
|
872
|
-
*/
|
|
873
|
-
|
|
874
|
-
typedef struct {
|
|
875
|
-
int16_t obj_type;
|
|
876
|
-
int8_t data_type;
|
|
877
|
-
int8_t ndim;
|
|
878
|
-
int32_t flags;
|
|
879
|
-
ca_size_t bytes;
|
|
880
|
-
ca_size_t elements;
|
|
881
|
-
ca_size_t *dim;
|
|
882
|
-
char *ptr;
|
|
883
|
-
CArray *mask;
|
|
884
|
-
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
885
|
-
Reserved for framework use; ext authors must not read,
|
|
886
|
-
write, or xfree this field directly. See
|
|
887
|
-
ext/ca_array_pool.c. */
|
|
888
|
-
CArray *parent;
|
|
889
|
-
uint32_t attach;
|
|
890
|
-
uint8_t nosync;
|
|
891
|
-
/* ---- */
|
|
892
|
-
ca_size_t count;
|
|
893
|
-
ca_size_t offset;
|
|
894
|
-
} CAReduce;
|
|
895
|
-
|
|
896
487
|
/* -------------------------------------------------------------------- */
|
|
897
488
|
|
|
898
|
-
/* CAIterator is a form-only Ruby base (see ext/carray_iterator.c); the 2.0 C
|
|
899
|
-
struct (a kernel_at_addr dispatch slot) was retired in 3.0. */
|
|
900
|
-
|
|
901
|
-
/* -------------------------------------------------------------------- */
|
|
902
|
-
|
|
903
|
-
extern const int ca_endian;
|
|
904
489
|
extern const int32_t ca_valid[CA_NTYPE];
|
|
905
490
|
extern const int32_t ca_sizeof[CA_NTYPE];
|
|
906
491
|
extern const char * ca_type_name[CA_NTYPE];
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
no common type. See ext/carray_cast.c
|
|
914
|
-
for the definition; this is the single source of the promotion rule. */
|
|
492
|
+
|
|
493
|
+
/* data_type promotion reducer. Used by CArray.result_type and by the lazy
|
|
494
|
+
view layer. Raises ArgumentError for a code outside the data types, and
|
|
495
|
+
CArray::DataTypeError for a pair with no common type. See
|
|
496
|
+
ext/carray_cast.c for the definition; this is the single source of the
|
|
497
|
+
promotion rule. */
|
|
915
498
|
int8_t ca_promote_type (int8_t a, int8_t b);
|
|
916
499
|
|
|
917
500
|
/* Infer a data_type code from a Ruby *value* (literal Numeric, true/false,
|
|
@@ -928,19 +511,14 @@ int8_t ca_value_to_data_type (VALUE obj);
|
|
|
928
511
|
Defined in ext/carray_memory_view.c. */
|
|
929
512
|
int8_t ca_mv_probe_data_type (VALUE obj);
|
|
930
513
|
|
|
931
|
-
/* Symbol
|
|
932
|
-
|
|
933
|
-
CA_NTYPE-1 = CA_OBJECT). Use rb_ca_data_type_to_sym for the public
|
|
934
|
-
conversion entry point (it validates the code first). */
|
|
935
|
-
extern ID ca_data_type_sym[CA_NTYPE];
|
|
514
|
+
/* The Symbol of a data_type code (:int32 for CA_INT32, ...); the code
|
|
515
|
+
is validated first. */
|
|
936
516
|
VALUE rb_ca_data_type_to_sym (int8_t data_type);
|
|
937
517
|
|
|
938
518
|
extern VALUE ca_class[CA_OBJ_TYPE_MAX];
|
|
939
519
|
extern const rb_data_type_t *ca_typeddata[CA_OBJ_TYPE_MAX];
|
|
940
520
|
extern VALUE ca_mask_class[CA_OBJ_TYPE_MAX];
|
|
941
521
|
extern const rb_data_type_t *ca_mask_typeddata[CA_OBJ_TYPE_MAX];
|
|
942
|
-
extern ca_operation_function_t ca_func[CA_OBJ_TYPE_MAX];
|
|
943
|
-
extern int ca_obj_num;
|
|
944
522
|
|
|
945
523
|
#define CAVIEW(x) ((CAView *)(x))
|
|
946
524
|
|
|
@@ -955,94 +533,50 @@ extern int ca_obj_num;
|
|
|
955
533
|
/* -------------------------------------------------------------------- */
|
|
956
534
|
|
|
957
535
|
extern const rb_data_type_t carray_data_type;
|
|
958
|
-
extern const rb_data_type_t cawrap_data_type;
|
|
959
|
-
extern const rb_data_type_t cscalar_data_type;
|
|
960
536
|
extern const rb_data_type_t caview_data_type;
|
|
537
|
+
extern const rb_data_type_t castride_data_type;
|
|
961
538
|
extern const rb_data_type_t caface_data_type;
|
|
962
539
|
extern const rb_data_type_t casource_data_type;
|
|
963
540
|
|
|
964
|
-
extern const rb_data_type_t cabitarray_data_type;
|
|
965
|
-
extern const rb_data_type_t cabitfield_data_type;
|
|
966
|
-
extern const rb_data_type_t cablock_data_type;
|
|
967
|
-
extern const rb_data_type_t castride_data_type;
|
|
968
|
-
extern const rb_data_type_t castride_mask_data_type;
|
|
969
|
-
extern const rb_data_type_t cafake_data_type;
|
|
970
|
-
extern const rb_data_type_t cabyteswap_data_type;
|
|
971
|
-
/* cafield_data_type was retired in 3.0 (Phase F: CAField is now a
|
|
972
|
-
CAStride subclass; use castride_data_type). */
|
|
973
|
-
extern const rb_data_type_t cagrid_data_type;
|
|
974
|
-
extern const rb_data_type_t caobject_data_type;
|
|
975
|
-
extern const rb_data_type_t careduce_data_type;
|
|
976
|
-
extern const rb_data_type_t carefer_data_type;
|
|
977
|
-
extern const rb_data_type_t caselect_data_type;
|
|
978
|
-
extern const rb_data_type_t cashift_data_type;
|
|
979
|
-
extern const rb_data_type_t cawindow_data_type;
|
|
980
|
-
|
|
981
541
|
extern const rb_data_type_t carray_mask_data_type;
|
|
982
|
-
extern const rb_data_type_t
|
|
983
|
-
extern const rb_data_type_t cagrid_mask_data_type;
|
|
984
|
-
extern const rb_data_type_t careduce_mask_data_type;
|
|
985
|
-
extern const rb_data_type_t carefer_mask_data_type;
|
|
986
|
-
extern const rb_data_type_t caselect_mask_data_type;
|
|
987
|
-
extern const rb_data_type_t cashift_mask_data_type;
|
|
988
|
-
extern const rb_data_type_t cawindow_mask_data_type;
|
|
542
|
+
extern const rb_data_type_t castride_mask_data_type;
|
|
989
543
|
|
|
990
544
|
/* -------------------------------------------------------------------- */
|
|
991
545
|
|
|
992
546
|
extern VALUE rb_cCArray;
|
|
993
547
|
extern VALUE rb_cCAView;
|
|
548
|
+
extern VALUE rb_cCAStride;
|
|
994
549
|
extern VALUE rb_cCAFace;
|
|
995
550
|
extern VALUE rb_cCASource;
|
|
996
|
-
extern VALUE rb_cCScalar;
|
|
997
|
-
extern VALUE rb_cCAWrap;
|
|
998
|
-
extern VALUE rb_cCARefer;
|
|
999
|
-
extern VALUE rb_cCABlock;
|
|
1000
|
-
extern VALUE rb_cCAField;
|
|
1001
|
-
extern VALUE rb_cCAByteSwap;
|
|
1002
|
-
extern VALUE rb_cCAStride;
|
|
1003
|
-
extern VALUE rb_cCAStrideMask;
|
|
1004
|
-
extern VALUE rb_cCASelect;
|
|
1005
|
-
extern VALUE rb_cCAObject;
|
|
1006
|
-
extern VALUE rb_cCARepeat;
|
|
1007
|
-
extern VALUE rb_cCAIterator;
|
|
1008
551
|
|
|
1009
552
|
extern VALUE rb_cCArrayMask;
|
|
1010
|
-
extern VALUE rb_cCAReferMask;
|
|
1011
|
-
extern VALUE rb_cCABlockMask;
|
|
1012
|
-
extern VALUE rb_cCAFieldMask;
|
|
1013
|
-
extern VALUE rb_cCASelectMask;
|
|
1014
|
-
extern VALUE rb_cCAObjectMask;
|
|
1015
|
-
extern VALUE rb_cCARepeatMask;
|
|
1016
553
|
|
|
1017
554
|
extern VALUE rb_mCA;
|
|
1018
|
-
extern VALUE rb_mCAMath;
|
|
1019
555
|
extern VALUE rb_eCADataTypeError;
|
|
1020
556
|
|
|
1021
|
-
extern VALUE rb_cCArrayBoolean;
|
|
1022
|
-
extern VALUE rb_cCArrayUInt8;
|
|
1023
|
-
extern VALUE rb_cCArrayUInt16;
|
|
1024
|
-
extern VALUE rb_cCArrayUInt32;
|
|
1025
|
-
extern VALUE rb_cCArrayUInt64;
|
|
1026
|
-
extern VALUE rb_cCArrayInt8;
|
|
1027
|
-
extern VALUE rb_cCArrayInt16;
|
|
1028
|
-
extern VALUE rb_cCArrayInt32;
|
|
1029
|
-
extern VALUE rb_cCArrayInt64;
|
|
1030
|
-
extern VALUE rb_cCArrayFloat32;
|
|
1031
|
-
extern VALUE rb_cCArrayFloat64;
|
|
1032
|
-
extern VALUE rb_cCArrayCmplx64;
|
|
1033
|
-
extern VALUE rb_cCArrayCmplx128;
|
|
1034
|
-
extern VALUE rb_cCArrayObject;
|
|
1035
|
-
|
|
1036
557
|
/* -------------------------------------------------------------------- */
|
|
1037
558
|
|
|
559
|
+
/* The name of the method the user called, found from the frames: an error
|
|
560
|
+
message opens with "%s: " and this, so a part shared by many methods
|
|
561
|
+
names the one that was called (carray_utils.c). */
|
|
562
|
+
const char *ca_calling_method_name (void);
|
|
563
|
+
|
|
564
|
+
/* Refuse a rank above CA_RANK_MAX, naming the method (`name`, or the method
|
|
565
|
+
the user called when NULL), before any dim is written (carray_utils.c). */
|
|
566
|
+
void ca_check_rank_fits (long ndim, const char *name);
|
|
567
|
+
|
|
568
|
+
/* The checks below raise naming the method the user called. */
|
|
569
|
+
|
|
1038
570
|
#define CA_CHECK_DATA_TYPE(data_type) \
|
|
1039
571
|
do { \
|
|
1040
572
|
int ca_dt_ = (data_type); \
|
|
1041
573
|
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE ) { \
|
|
1042
|
-
rb_raise(rb_eArgError, "invalid data_type id %i",
|
|
574
|
+
rb_raise(rb_eArgError, "%s: invalid data_type id %i", \
|
|
575
|
+
ca_calling_method_name(), ca_dt_); \
|
|
1043
576
|
} \
|
|
1044
577
|
if ( ! ca_valid[ca_dt_] ) { \
|
|
1045
|
-
rb_raise(rb_eCADataTypeError, "data_type %s is disabled",
|
|
578
|
+
rb_raise(rb_eCADataTypeError, "%s: data_type %s is disabled", \
|
|
579
|
+
ca_calling_method_name(), ca_type_name[ca_dt_]); \
|
|
1046
580
|
} \
|
|
1047
581
|
} while (0)
|
|
1048
582
|
|
|
@@ -1051,23 +585,28 @@ extern VALUE rb_cCArrayObject;
|
|
|
1051
585
|
int ca_dt_ = (data_type); \
|
|
1052
586
|
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE || !ca_valid[ca_dt_] || \
|
|
1053
587
|
ca_dt_ == CA_FIXLEN || ca_dt_ == CA_OBJECT ) { \
|
|
1054
|
-
rb_raise(rb_eCADataTypeError, "invalid numeric data type"
|
|
588
|
+
rb_raise(rb_eCADataTypeError, "%s: invalid numeric data type", \
|
|
589
|
+
ca_calling_method_name()); \
|
|
1055
590
|
} \
|
|
1056
591
|
} while (0)
|
|
1057
592
|
|
|
593
|
+
/* No axes at all is no shape; above CA_RANK_MAX goes to ca_check_rank_fits. */
|
|
1058
594
|
#define CA_CHECK_RANK(ndim) \
|
|
1059
595
|
do { \
|
|
1060
|
-
|
|
1061
|
-
|
|
596
|
+
long ca_nd_ = (long) (ndim); \
|
|
597
|
+
if ( ca_nd_ <= 0 ) { \
|
|
598
|
+
rb_raise(rb_eArgError, "%s: invalid ndim", ca_calling_method_name()); \
|
|
1062
599
|
} \
|
|
600
|
+
ca_check_rank_fits(ca_nd_, NULL); \
|
|
1063
601
|
} while (0)
|
|
1064
602
|
|
|
1065
|
-
#define CA_CHECK_DIM(ndim, dim)
|
|
603
|
+
#define CA_CHECK_DIM(ndim, dim) \
|
|
1066
604
|
do { \
|
|
1067
605
|
int8_t i_; \
|
|
1068
|
-
for (i_=0; i_<(ndim); i_++) { \
|
|
606
|
+
for (i_ = 0; i_ < (ndim); i_++) { \
|
|
1069
607
|
if ( (dim)[i_] < 0 ) { \
|
|
1070
|
-
rb_raise(rb_eArgError, "negative size dimension at %i-dim",
|
|
608
|
+
rb_raise(rb_eArgError, "%s: negative size dimension at %i-dim", \
|
|
609
|
+
ca_calling_method_name(), i_); \
|
|
1071
610
|
} \
|
|
1072
611
|
} \
|
|
1073
612
|
} while (0)
|
|
@@ -1078,15 +617,16 @@ extern VALUE rb_cCArrayObject;
|
|
|
1078
617
|
#define CA_CHECK_BYTES(data_type, bytes) \
|
|
1079
618
|
do { \
|
|
1080
619
|
if ( (data_type) == CA_FIXLEN ) { \
|
|
1081
|
-
if ( (bytes) <= 0 ) {
|
|
1082
|
-
rb_raise(rb_eArgError,
|
|
1083
|
-
"invalid bytes (a fixlen needs bytes: of 1 or more)"
|
|
620
|
+
if ( (bytes) <= 0 ) { \
|
|
621
|
+
rb_raise(rb_eArgError, \
|
|
622
|
+
"%s: invalid bytes (a fixlen needs bytes: of 1 or more)", \
|
|
623
|
+
ca_calling_method_name()); \
|
|
1084
624
|
} \
|
|
1085
625
|
} \
|
|
1086
626
|
else { \
|
|
1087
627
|
(bytes) = ca_sizeof[(data_type)]; \
|
|
1088
|
-
if ( (bytes) <= 0 ) {
|
|
1089
|
-
rb_raise(rb_eArgError, "invalid bytes"); \
|
|
628
|
+
if ( (bytes) <= 0 ) { \
|
|
629
|
+
rb_raise(rb_eArgError, "%s: invalid bytes", ca_calling_method_name()); \
|
|
1090
630
|
} \
|
|
1091
631
|
} \
|
|
1092
632
|
} while (0)
|
|
@@ -1109,12 +649,56 @@ NORETURN(void ca_index_out_of_range (ca_size_t idx, ca_size_t n, const char *wha
|
|
|
1109
649
|
} \
|
|
1110
650
|
} while (0)
|
|
1111
651
|
|
|
652
|
+
/* ---- Empty regions ---------------------------------------------------------
|
|
653
|
+
|
|
654
|
+
A region with a zero count on some axis has no cells. The per-cell walks
|
|
655
|
+
visit their first cell before they test the counts, so every region
|
|
656
|
+
transfer returns on an empty region before it walks: a zero-cell caller
|
|
657
|
+
buffer has no room for that first cell. */
|
|
658
|
+
|
|
659
|
+
static inline int
|
|
660
|
+
ca_region_is_empty (int8_t ndim, const ca_size_t *counts)
|
|
661
|
+
{
|
|
662
|
+
int8_t k;
|
|
663
|
+
for ( k = 0; k < ndim; k++ ) {
|
|
664
|
+
if ( counts[k] <= 0 ) return 1;
|
|
665
|
+
}
|
|
666
|
+
return 0;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/* ---- An index into n places ----------------------------------------------
|
|
670
|
+
|
|
671
|
+
A negative index counts from the end; one outside 0...n after that raises
|
|
672
|
+
IndexError, naming the method the user called, `what` the index is (an
|
|
673
|
+
"index", an "address") and the value given. */
|
|
674
|
+
|
|
675
|
+
static inline ca_size_t
|
|
676
|
+
ca_index_in_range (ca_size_t idx, ca_size_t n, const char *what)
|
|
677
|
+
{
|
|
678
|
+
ca_size_t i = ( idx < 0 ) ? idx + n : idx;
|
|
679
|
+
if ( i < 0 || i >= n ) {
|
|
680
|
+
ca_index_out_of_range(idx, n, what);
|
|
681
|
+
}
|
|
682
|
+
return i;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/* The same for an index on axis `axis` of a multi-axis index. */
|
|
686
|
+
NORETURN(void ca_index_out_of_range_at (ca_size_t idx, ca_size_t n, int axis));
|
|
687
|
+
|
|
688
|
+
static inline ca_size_t
|
|
689
|
+
ca_index_in_range_at (ca_size_t idx, ca_size_t n, int axis)
|
|
690
|
+
{
|
|
691
|
+
ca_size_t i = ( idx < 0 ) ? idx + n : idx;
|
|
692
|
+
if ( i < 0 || i >= n ) {
|
|
693
|
+
ca_index_out_of_range_at(idx, n, axis);
|
|
694
|
+
}
|
|
695
|
+
return i;
|
|
696
|
+
}
|
|
697
|
+
|
|
1112
698
|
/* -------------------------------------------------------------------- */
|
|
1113
699
|
|
|
1114
|
-
/* complex <-> Ruby Complex conversion
|
|
1115
|
-
|
|
1116
|
-
CComplex class is gone in 3.0 -- the macros now produce and consume
|
|
1117
|
-
Ruby's built-in Complex.) */
|
|
700
|
+
/* complex <-> Ruby Complex conversion. NUM2CC / CC2NUM convert between a
|
|
701
|
+
C complex and Ruby's built-in Complex. */
|
|
1118
702
|
|
|
1119
703
|
#ifdef HAVE_COMPLEX_H
|
|
1120
704
|
|
|
@@ -1138,6 +722,10 @@ NORETURN(void ca_index_out_of_range (ca_size_t idx, ca_size_t n, const char *wha
|
|
|
1138
722
|
(nan / inf included), else as Complex() does; anything else raises. */
|
|
1139
723
|
double complex ca_str_to_cmplx (VALUE str);
|
|
1140
724
|
|
|
725
|
+
/* Any other value as a complex cell: to_c, else to_f; nil and a value
|
|
726
|
+
with neither raise. */
|
|
727
|
+
double complex ca_obj_to_cmplx (VALUE num);
|
|
728
|
+
|
|
1141
729
|
static inline double complex
|
|
1142
730
|
rb_carray_num2cmplx (VALUE num)
|
|
1143
731
|
{
|
|
@@ -1150,21 +738,7 @@ rb_carray_num2cmplx (VALUE num)
|
|
|
1150
738
|
if ( RB_TYPE_P(num, T_STRING) ) {
|
|
1151
739
|
return ca_str_to_cmplx(num);
|
|
1152
740
|
}
|
|
1153
|
-
|
|
1154
|
-
rb_raise(rb_eTypeError, "can't convert nil into Complex");
|
|
1155
|
-
}
|
|
1156
|
-
if ( rb_respond_to(num, rb_intern("to_c")) ) {
|
|
1157
|
-
VALUE c = rb_funcall(num, rb_intern("to_c"), 0);
|
|
1158
|
-
if ( ! RB_TYPE_P(c, T_COMPLEX) ) {
|
|
1159
|
-
rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" to Complex (%"PRIsVALUE"#to_c gives %"PRIsVALUE")",
|
|
1160
|
-
rb_obj_class(num), rb_obj_class(num), rb_obj_class(c));
|
|
1161
|
-
}
|
|
1162
|
-
return CMPLX(NUM2DBL(rb_complex_real(c)), NUM2DBL(rb_complex_imag(c)));
|
|
1163
|
-
}
|
|
1164
|
-
if ( rb_respond_to(num, rb_intern("to_f")) ) {
|
|
1165
|
-
return (double complex) NUM2DBL(rb_funcall(num, rb_intern("to_f"), 0));
|
|
1166
|
-
}
|
|
1167
|
-
rb_raise(rb_eTypeError, "can not convert to complex");
|
|
741
|
+
return ca_obj_to_cmplx(num);
|
|
1168
742
|
}
|
|
1169
743
|
|
|
1170
744
|
static inline VALUE
|
|
@@ -1198,100 +772,21 @@ unsigned long long rb_obj2ull (VALUE);
|
|
|
1198
772
|
|
|
1199
773
|
double OBJ2DBL (VALUE v);
|
|
1200
774
|
|
|
1201
|
-
/* Mask-aware object->numeric parsers: return 1 with *out set on success, or
|
|
1202
|
-
0 (no value; caller masks the cell) on parse failure. Used by the
|
|
1203
|
-
object->int/float cast loop so an unparseable cell becomes UNDEF instead
|
|
1204
|
-
of a silent 0.0 (float) or a raise (int). An Integer wider than the C
|
|
1205
|
-
type gives its low bytes (two's complement), as a narrowing C cast does;
|
|
1206
|
-
these parsers do not raise. See ext/carray_cast.c. */
|
|
1207
|
-
int ca_obj2dbl_ok (VALUE v, double *out);
|
|
1208
|
-
int ca_obj2cmplx_ok (VALUE v, double complex *out);
|
|
1209
|
-
int rb_obj2long_ok (VALUE v, long *out);
|
|
1210
|
-
int rb_obj2ulong_ok (VALUE v, unsigned long *out);
|
|
1211
|
-
int rb_obj2ll_ok (VALUE v, long long *out);
|
|
1212
|
-
int rb_obj2ull_ok (VALUE v, unsigned long long *out);
|
|
1213
|
-
|
|
1214
|
-
/* -------------------------------------------------------------------- */
|
|
1215
|
-
|
|
1216
|
-
/* index parsing */
|
|
1217
|
-
|
|
1218
|
-
enum {
|
|
1219
|
-
CA_REG_NONE,
|
|
1220
|
-
CA_REG_ALL,
|
|
1221
|
-
CA_REG_ADDRESS,
|
|
1222
|
-
CA_REG_FLATTEN,
|
|
1223
|
-
CA_REG_ADDRESS_COMPLEX,
|
|
1224
|
-
CA_REG_POINT,
|
|
1225
|
-
CA_REG_BLOCK,
|
|
1226
|
-
CA_REG_SELECT,
|
|
1227
|
-
CA_REG_ITERATOR,
|
|
1228
|
-
CA_REG_REPEAT,
|
|
1229
|
-
CA_REG_GRID,
|
|
1230
|
-
CA_REG_MAPPING,
|
|
1231
|
-
CA_REG_METHOD_CALL,
|
|
1232
|
-
CA_REG_MEMBER,
|
|
1233
|
-
CA_REG_ATTRIBUTE,
|
|
1234
|
-
}; /* CA_REGION_TYPE */
|
|
1235
|
-
|
|
1236
|
-
enum {
|
|
1237
|
-
CA_IDX_SCALAR,
|
|
1238
|
-
CA_IDX_ALL,
|
|
1239
|
-
CA_IDX_BLOCK,
|
|
1240
|
-
CA_IDX_SYMBOL
|
|
1241
|
-
}; /* CA_INDEX_TYPE */
|
|
1242
|
-
|
|
1243
|
-
typedef union {
|
|
1244
|
-
ca_size_t scalar;
|
|
1245
|
-
struct {
|
|
1246
|
-
ca_size_t start;
|
|
1247
|
-
ca_size_t step;
|
|
1248
|
-
ca_size_t count;
|
|
1249
|
-
} block;
|
|
1250
|
-
struct {
|
|
1251
|
-
ID id;
|
|
1252
|
-
VALUE spec;
|
|
1253
|
-
} symbol;
|
|
1254
|
-
} CAIndex;
|
|
1255
|
-
|
|
1256
|
-
typedef struct {
|
|
1257
|
-
int16_t type;
|
|
1258
|
-
int16_t ndim;
|
|
1259
|
-
int32_t index_type[CA_RANK_MAX];
|
|
1260
|
-
CAIndex index[CA_RANK_MAX];
|
|
1261
|
-
CArray *select;
|
|
1262
|
-
VALUE block;
|
|
1263
|
-
VALUE symbol;
|
|
1264
|
-
int8_t range_check;
|
|
1265
|
-
} CAIndexInfo;
|
|
1266
|
-
|
|
1267
775
|
/* -------------------------------------------------------------------- */
|
|
1268
776
|
|
|
1269
777
|
/* The element-wise kernel typedefs (ca_monop_func_t / ca_binop_func_t /
|
|
1270
|
-
ca_triop_func_t / ca_moncmp_func_t / ca_bincmp_func_t)
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
includes at the bottom (umbrella). Declarations only moved — definitions
|
|
1274
|
-
and ABI are unchanged. */
|
|
778
|
+
ca_triop_func_t / ca_moncmp_func_t / ca_bincmp_func_t) and the
|
|
779
|
+
per-data_type dispatch tables are declared in carray_math_kernel.h,
|
|
780
|
+
which this header includes at the bottom (umbrella). */
|
|
1275
781
|
|
|
1276
782
|
/* -------------------------------------------------------------------- */
|
|
1277
783
|
|
|
1278
784
|
/* --- ca_obj_array.c --- */
|
|
1279
785
|
|
|
1280
|
-
int carray_setup (CArray *ca,
|
|
1281
|
-
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
1282
|
-
ca_size_t bytes, CArray *mask);
|
|
1283
|
-
|
|
1284
|
-
int carray_safe_setup (CArray *ca,
|
|
1285
|
-
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
1286
|
-
ca_size_t bytes, CArray *mask);
|
|
1287
|
-
|
|
1288
786
|
int ca_wrap_setup_null (CArray *ca,
|
|
1289
|
-
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
787
|
+
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
1290
788
|
ca_size_t bytes, CArray *mask);
|
|
1291
789
|
|
|
1292
|
-
void free_carray (void *ap);
|
|
1293
|
-
void free_ca_wrap (void *ap);
|
|
1294
|
-
|
|
1295
790
|
CArray *carray_new (int8_t data_type,
|
|
1296
791
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *ma);
|
|
1297
792
|
CArray *carray_new_safe (int8_t data_type,
|
|
@@ -1319,10 +814,6 @@ VALUE rb_carray_new_adopt (int8_t data_type,
|
|
|
1319
814
|
ext/carray_core.c for docstring + semantics. */
|
|
1320
815
|
VALUE rb_ca_new_reduced (VALUE self, int8_t *slab_axes,
|
|
1321
816
|
int8_t naxes, int32_t data_type, int keep_axis);
|
|
1322
|
-
/* Same shape computation, but the output byte width is passed explicitly
|
|
1323
|
-
so a runtime-width output data_type (CA_FIXLEN) can be allocated. */
|
|
1324
|
-
VALUE rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
1325
|
-
int32_t data_type, ca_size_t bytes, int keep_axis);
|
|
1326
817
|
|
|
1327
818
|
/* Parse variadic axis argv into a validated int8_t array. Accepts Integer
|
|
1328
819
|
args or a single Array arg (no argument = every axis), counts negative
|
|
@@ -1351,26 +842,20 @@ CAWrap *ca_wrap_new_null (int8_t data_type,
|
|
|
1351
842
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes,
|
|
1352
843
|
CArray *mask);
|
|
1353
844
|
|
|
1354
|
-
CScalar
|
|
1355
|
-
|
|
845
|
+
/* An extension makes a CScalar with rb_cscalar_new and sets its value
|
|
846
|
+
with rb_ca_store_addr(obj, 0, val). */
|
|
1356
847
|
VALUE rb_cscalar_new (int8_t data_type, ca_size_t bytes, CArray *mask);
|
|
1357
|
-
VALUE rb_cscalar_new_with_value (int8_t data_type, ca_size_t bytes, VALUE rval);
|
|
1358
848
|
|
|
1359
849
|
/* --- ca_obj_refer.c --- */
|
|
1360
850
|
|
|
1361
851
|
CARefer *ca_refer_new (CArray *ca,
|
|
1362
852
|
int8_t data_type, int8_t ndim, ca_size_t *dim,
|
|
1363
853
|
ca_size_t bytes, ca_size_t offset);
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
ca_size_t bytes, ca_size_t offset);
|
|
854
|
+
/* The C forms of CArray#reshape and CArray#flatten; calling them is the
|
|
855
|
+
same as calling the method. */
|
|
1367
856
|
VALUE rb_ca_reshape (int argc, VALUE *argv, VALUE self);
|
|
1368
857
|
VALUE rb_ca_flatten (VALUE self);
|
|
1369
858
|
|
|
1370
|
-
/* --- ca_obj_farray.c --- */
|
|
1371
|
-
|
|
1372
|
-
VALUE rb_ca_farray (VALUE self);
|
|
1373
|
-
|
|
1374
859
|
/* --- ca_obj_stride.c --- */
|
|
1375
860
|
|
|
1376
861
|
/* The strides and base_offset are taken as given: they are not checked
|
|
@@ -1381,11 +866,11 @@ VALUE rb_ca_farray (VALUE self);
|
|
|
1381
866
|
writing. ca_stride_new calls it that way before it allocates, so a
|
|
1382
867
|
rejected argument leaves no struct behind; a subclass constructor can
|
|
1383
868
|
do the same through its own setup function. */
|
|
1384
|
-
int ca_stride_setup (CAStride *ca,
|
|
869
|
+
int ca_stride_setup (CAStride *ca, int16_t obj_type, CArray *parent,
|
|
1385
870
|
int8_t data_type, ca_size_t bytes,
|
|
1386
871
|
int8_t ndim, ca_size_t *dim,
|
|
1387
872
|
ca_size_t *strides, ca_size_t base_offset);
|
|
1388
|
-
CAStride *ca_stride_new (
|
|
873
|
+
CAStride *ca_stride_new (int16_t obj_type, CArray *parent,
|
|
1389
874
|
int8_t data_type, ca_size_t bytes,
|
|
1390
875
|
int8_t ndim, ca_size_t *dim,
|
|
1391
876
|
ca_size_t *strides, ca_size_t base_offset);
|
|
@@ -1393,51 +878,11 @@ VALUE rb_ca_stride_new (VALUE cary,
|
|
|
1393
878
|
int8_t data_type, ca_size_t bytes,
|
|
1394
879
|
int8_t ndim, ca_size_t *dim,
|
|
1395
880
|
ca_size_t *strides, ca_size_t base_offset);
|
|
1396
|
-
extern
|
|
881
|
+
extern int16_t CA_OBJ_STRIDE;
|
|
1397
882
|
void ca_stride_compose_to_root (CAStride *leaf,
|
|
1398
883
|
CArray **out_root,
|
|
1399
884
|
ca_size_t *out_strides,
|
|
1400
885
|
ca_size_t *out_base);
|
|
1401
|
-
/* one stride-composition hop: express leaf (in parent's byte space) into
|
|
1402
|
-
parent->parent's byte space. Non-static so sometimes-fold participants
|
|
1403
|
-
(e.g. CAWindow::fold_stride) can compose through a synthetic stride layer. */
|
|
1404
|
-
int ca_stride_compose_through (CAStride *leaf, CAStride *parent,
|
|
1405
|
-
ca_size_t *out_strides, ca_size_t *out_base);
|
|
1406
|
-
|
|
1407
|
-
/* --- ca_obj_grid.c --- */
|
|
1408
|
-
|
|
1409
|
-
/* rb_ca_grid_new signature
|
|
1410
|
-
changed to take a per-axis cag_axis_t proto array (private to
|
|
1411
|
-
ca_obj_grid.c). No external callers exist so the declaration is
|
|
1412
|
-
removed from the public header. */
|
|
1413
|
-
VALUE rb_ca_grid (int argc, VALUE *argv, VALUE self);
|
|
1414
|
-
int rb_ca_select_axis_eligible_p (int argc, VALUE *argv, VALUE self);
|
|
1415
|
-
VALUE rb_ca_select_axis (int argc, VALUE *argv, VALUE self);
|
|
1416
|
-
|
|
1417
|
-
/* --- ca_obj_mapping.c --- */
|
|
1418
|
-
|
|
1419
|
-
VALUE rb_ca_mapping (int argc, VALUE *argv, VALUE self);
|
|
1420
|
-
|
|
1421
|
-
/* --- ca_obj_field.c --- */
|
|
1422
|
-
|
|
1423
|
-
VALUE rb_ca_field (int argc, VALUE *argv, VALUE self);
|
|
1424
|
-
|
|
1425
|
-
/* --- ca_obj_fake.c --- */
|
|
1426
|
-
|
|
1427
|
-
VALUE rb_ca_fake_type (VALUE self, VALUE rtype, VALUE rbytes);
|
|
1428
|
-
|
|
1429
|
-
/* --- ca_obj_repeat.c --- */
|
|
1430
|
-
|
|
1431
|
-
VALUE rb_ca_repeat (int argc, VALUE *argv, VALUE self);
|
|
1432
|
-
|
|
1433
|
-
/* --- carray_broadcast.c --- */
|
|
1434
|
-
|
|
1435
|
-
VALUE ca_broadcast_view (VALUE src, int8_t ndim, ca_size_t *target_dim);
|
|
1436
|
-
void ca_broadcast_pair (volatile VALUE *self, volatile VALUE *other);
|
|
1437
|
-
|
|
1438
|
-
/* --- ca_iter_dimension retired: CADimensionIterator -> CASlabIterator --- */
|
|
1439
|
-
|
|
1440
|
-
/* -------------------------------------------------------------------- */
|
|
1441
886
|
|
|
1442
887
|
/* API : defining new array */
|
|
1443
888
|
|
|
@@ -1457,11 +902,10 @@ void ca_broadcast_pair (volatile VALUE *self, volatile VALUE *other);
|
|
|
1457
902
|
A func_size larger than this build's struct means the caller was compiled
|
|
1458
903
|
against a newer carray; that is reported rather than truncated.
|
|
1459
904
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
below 128: an install that would number one at 128 or above raises. */
|
|
905
|
+
An obj_type is numbered below CA_OBJ_TYPE_MAX; an install past that
|
|
906
|
+
raises. */
|
|
1463
907
|
|
|
1464
|
-
|
|
908
|
+
int16_t
|
|
1465
909
|
ca_install_obj_type (VALUE klass,
|
|
1466
910
|
const rb_data_type_t *typeddata,
|
|
1467
911
|
VALUE mask_klass,
|
|
@@ -1469,8 +913,20 @@ ca_install_obj_type (VALUE klass,
|
|
|
1469
913
|
const ca_operation_function_t *func,
|
|
1470
914
|
size_t func_size);
|
|
1471
915
|
|
|
916
|
+
/* Copies the operation table of an installed obj_type into dst, as the
|
|
917
|
+
starting point for a table of one's own:
|
|
918
|
+
|
|
919
|
+
ca_operation_function_t f;
|
|
920
|
+
ca_operation_table_copy(CA_OBJ_ARRAY, &f, sizeof(f));
|
|
921
|
+
f.attach = my_attach;
|
|
922
|
+
ca_install_obj_type(klass, ..., &f, sizeof(f));
|
|
923
|
+
|
|
924
|
+
size is sizeof(ca_operation_function_t) as the caller was compiled.
|
|
925
|
+
Slots the caller's struct has and this carray does not are zeroed.
|
|
926
|
+
Raises ArgumentError for an obj_type that is not installed. */
|
|
927
|
+
void ca_operation_table_copy (int16_t obj_type,
|
|
928
|
+
ca_operation_function_t *dst, size_t size);
|
|
1472
929
|
|
|
1473
|
-
VALUE ca_data_type_class (int8_t data_type);
|
|
1474
930
|
|
|
1475
931
|
void ca_mark (void *ap);
|
|
1476
932
|
void ca_free (void *ap);
|
|
@@ -1485,10 +941,7 @@ int ca_is_scalar (void *ap);
|
|
|
1485
941
|
/* ca_is_entity indexes ca_func[], so expanding it inline compiles in the
|
|
1486
942
|
current sizeof(ca_operation_function_t) as the array stride. Sources built
|
|
1487
943
|
with the rest of carray are recompiled whenever a slot is added and get the
|
|
1488
|
-
macro; anything built separately gets the function
|
|
1489
|
-
addition cannot silently re-index the table underneath it. (Reading
|
|
1490
|
-
ca_func[] directly carries the same coupling, and is left available to
|
|
1491
|
-
callers that ask for it deliberately.) */
|
|
944
|
+
macro; anything built separately gets the function. */
|
|
1492
945
|
#ifdef CARRAY_BUILD
|
|
1493
946
|
#define ca_is_entity(ca) ( ca_func[(ca)->obj_type].entity_type == CA_REAL_ARRAY )
|
|
1494
947
|
#else
|
|
@@ -1515,7 +968,6 @@ int ca_is_readonly (void *ap);
|
|
|
1515
968
|
int ca_is_value_array (void *ap);
|
|
1516
969
|
int ca_is_mask_array (void *ap);
|
|
1517
970
|
#define ca_is_face(ca) ( ca_test_flag((ca), CA_FLAG_IS_FACE) )
|
|
1518
|
-
#define ca_is_lazy_marker(ca) ( ca_test_flag((ca), CA_FLAG_IS_LAZY_MARKER) )
|
|
1519
971
|
|
|
1520
972
|
#define ca_is_attached(ca) ( (ca)->ptr != NULL )
|
|
1521
973
|
#define ca_is_empty(ca) ( (ca)->elements == 0 )
|
|
@@ -1560,7 +1012,6 @@ int ca_is_object_type (void *ap);
|
|
|
1560
1012
|
|
|
1561
1013
|
void ca_check_type (void *ap, int8_t data_type);
|
|
1562
1014
|
#define ca_check_data_type(ap, data_type) ca_check_type(ap, data_type)
|
|
1563
|
-
void ca_check_uninitialized (void *ap); /* initialize / initialize_copy entry */
|
|
1564
1015
|
void ca_check_ndim (void *ap, int ndim);
|
|
1565
1016
|
void ca_check_shape (void *ap, int ndim, ca_size_t *dim);
|
|
1566
1017
|
void ca_check_same_data_type (void *ap1, void *ap2);
|
|
@@ -1568,7 +1019,6 @@ void ca_check_same_ndim (void *ap1, void *ap2);
|
|
|
1568
1019
|
void ca_check_same_elements (void *ap1, void *ap2);
|
|
1569
1020
|
void ca_check_same_shape (void *ap1, void *ap2);
|
|
1570
1021
|
void ca_check_index (void *ap, ca_size_t *idx);
|
|
1571
|
-
void ca_check_data_class (VALUE rtype);
|
|
1572
1022
|
int ca_is_valid_index (void *ap, ca_size_t *idx);
|
|
1573
1023
|
|
|
1574
1024
|
#define ca_ndim(ca) ((ca)->ndim)
|
|
@@ -1576,41 +1026,13 @@ int ca_is_valid_index (void *ap, ca_size_t *idx);
|
|
|
1576
1026
|
|
|
1577
1027
|
/* API : allocate, attach, update, sync, detach */
|
|
1578
1028
|
|
|
1579
|
-
/*
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
implementation may do so as an internal optimisation;
|
|
1587
|
-
never rely on it.
|
|
1588
|
-
R3 (necessity) To touch ca->parent->ptr, call ca_attach(ca->parent)
|
|
1589
|
-
yourself.
|
|
1590
|
-
R4 (ordering) Attaching both parent and child: open parent -> child,
|
|
1591
|
-
close child -> parent, sync in attach order. Symmetric
|
|
1592
|
-
nesting stays correct when a view double-attaches
|
|
1593
|
-
internally (views carry an attach refcount; entities do
|
|
1594
|
-
not).
|
|
1595
|
-
R5 (traffic) Attach hands you a buffer, not a live array. Use x->ptr;
|
|
1596
|
-
a view derived from x may read past the buffer to the
|
|
1597
|
-
root (a CAStride-family view over a CAStride-family x
|
|
1598
|
-
does) or read the buffer (others), so writes to the
|
|
1599
|
-
buffer are not seen through derived views until x is
|
|
1600
|
-
synced.
|
|
1601
|
-
R6 (raising) ca_allocate and ca_attach that raise have taken
|
|
1602
|
-
nothing; ca_allocate_n and ca_attach_n take all of
|
|
1603
|
-
their arrays or none. Close a window with
|
|
1604
|
-
ca_sync_detach, which detaches even when the sync
|
|
1605
|
-
raises -- ca_sync then ca_detach leaves the window open
|
|
1606
|
-
on a raise. ca_sync_detach syncs, so it raises on a
|
|
1607
|
-
read-only array; a window that only read closes with
|
|
1608
|
-
ca_detach. Anything between that can raise (Ruby
|
|
1609
|
-
called from inside the window) needs an ensure of its
|
|
1610
|
-
own.
|
|
1611
|
-
*/
|
|
1612
|
-
|
|
1613
|
-
/* ca_allocate opens a window for writing every cell: what the cells held
|
|
1029
|
+
/* To read or write the cells of an array, use the kernel iterator
|
|
1030
|
+
(ca_kernel_iterator.h) or ca_xfer_all / ca_copy_data / ca_sync_data.
|
|
1031
|
+
Use ca_attach only where these cannot be used: attaching a view can copy
|
|
1032
|
+
its cells into a new buffer. The rules for code that attaches (R1-R6)
|
|
1033
|
+
are in guides/devel/04_attach_lifecycle.md. */
|
|
1034
|
+
|
|
1035
|
+
/* ca_allocate attaches an array for writing every cell: what the cells held
|
|
1614
1036
|
before is not kept, also when the array is already attached (object cells
|
|
1615
1037
|
are reset to 0 and the mask is cleared). */
|
|
1616
1038
|
void ca_allocate (void *ap);
|
|
@@ -1628,6 +1050,16 @@ void ca_update_n (int n, ...);
|
|
|
1628
1050
|
void ca_sync_n (int n, ...);
|
|
1629
1051
|
void ca_detach_n (int n, ...);
|
|
1630
1052
|
|
|
1053
|
+
/* For code that runs Ruby or can raise while arrays are attached. It
|
|
1054
|
+
attaches list[0..n-1], one mode per array ('r' attach, 'w' attach and
|
|
1055
|
+
sync, 'a' allocate and sync), runs body(arg), and detaches every array
|
|
1056
|
+
however body leaves. The arrays are attached all or none. On a raise a
|
|
1057
|
+
'w' array is synced with what was written, and an 'a' array is not
|
|
1058
|
+
synced (allocate does not read the cells, so the unwritten ones hold
|
|
1059
|
+
nothing). */
|
|
1060
|
+
VALUE ca_attach_window (int32_t n, CArray **list, const char *modes,
|
|
1061
|
+
VALUE (*body)(VALUE), VALUE arg);
|
|
1062
|
+
|
|
1631
1063
|
/* API : lending the addresses of cells
|
|
1632
1064
|
|
|
1633
1065
|
A kernel that reads cells by address itself -- a stencil reading
|
|
@@ -1682,17 +1114,16 @@ VALUE ca_with_address_bases (int32_t n, CArray **arrays, const int *writable,
|
|
|
1682
1114
|
|
|
1683
1115
|
/* API : copying */
|
|
1684
1116
|
|
|
1685
|
-
void *ca_clone (void *ap); /* use rb_obj_clone() */
|
|
1686
1117
|
/* A CA_OBJECT copy holds VALUEs the GC does not see until the struct is
|
|
1687
1118
|
wrapped, and wrapping allocates: for an object array use rb_ca_copy, which
|
|
1688
1119
|
keeps them alive and returns the wrapped copy. */
|
|
1689
1120
|
CArray *ca_copy (void *ap); /* use rb_ca_copy() */
|
|
1690
|
-
|
|
1691
|
-
|
|
1121
|
+
/* A new entity of the shape of ap, without a mask: the cells are left as
|
|
1122
|
+
allocated (ca_template) or zero-filled (_safe). Wrap it with
|
|
1123
|
+
ca_wrap_struct before anything can raise, or use rb_ca_template(). */
|
|
1124
|
+
CArray *ca_template (void *ap);
|
|
1125
|
+
CArray *ca_template_safe (void *ap);
|
|
1692
1126
|
CArray *ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes);
|
|
1693
|
-
/* use rb_ca_template() */
|
|
1694
|
-
|
|
1695
|
-
void ca_fill (void *ap, void *ptr);
|
|
1696
1127
|
|
|
1697
1128
|
/* API : fetch, store */
|
|
1698
1129
|
|
|
@@ -1706,19 +1137,6 @@ void ca_store_index (void *ap, ca_size_t *idx, void *ptr);
|
|
|
1706
1137
|
void ca_store_addr (void *ap, ca_size_t addr, void *ptr);
|
|
1707
1138
|
void ca_xfer_index (void *ap, ca_size_t *idx, void *data, int dir);
|
|
1708
1139
|
void ca_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *data, int dir);
|
|
1709
|
-
/* Shared predicate: detect if addrs[] is a sequential run
|
|
1710
|
-
(addrs[i] == addrs[0]+i for all i). Used by ca_xfer_addrs_dispatch and
|
|
1711
|
-
by view xfer_addrs slots for whole-view / sub-region run detection ->
|
|
1712
|
-
opportunistic engine dispatch. */
|
|
1713
|
-
int ca_xfer_addrs_is_sequential_run (ca_size_t n, ca_size_t *addrs,
|
|
1714
|
-
ca_size_t *base_out);
|
|
1715
|
-
/* Resolve cand through identity CAStride compose-fold to find an
|
|
1716
|
-
attached root. Returns cand if cand->ptr is set, cand is not CAStride
|
|
1717
|
-
family, or no identity compose-fold path exists (the cells differ from
|
|
1718
|
-
the root's in data type, width or position); otherwise returns the
|
|
1719
|
-
resolved root (which has ptr). Used by view xfer_addrs slots to lift
|
|
1720
|
-
parent->ptr gate through view CAStride layers (= chain pattern). */
|
|
1721
|
-
CArray *ca_resolve_attached_root_via_identity (CArray *cand);
|
|
1722
1140
|
|
|
1723
1141
|
/* Shared gate for the xfer_stride slots' structural fast paths.
|
|
1724
1142
|
|
|
@@ -1745,30 +1163,20 @@ void ca_xfer_all (void *ap, void *data, int dir);
|
|
|
1745
1163
|
|
|
1746
1164
|
void ca_copy_data (void *ap, char *ptr);
|
|
1747
1165
|
void ca_sync_data (void *ap, char *ptr);
|
|
1166
|
+
/* ca_fill_data writes one value (ptr, one element's worth of bytes) into
|
|
1167
|
+
every cell of the array. */
|
|
1748
1168
|
void ca_fill_data (void *ap, void *ptr);
|
|
1749
1169
|
|
|
1750
1170
|
/* Write one value into part of a view. ptr is one element's worth of bytes.
|
|
1751
1171
|
Both describe the region over the view's own linear addresses; see the
|
|
1752
1172
|
fill_stride slot comment for why addresses rather than an index box.
|
|
1753
|
-
A view without the matching slot gets a per-cell
|
|
1754
|
-
through xfer_index, so the region is still all that
|
|
1173
|
+
A view without the matching slot (the slot left NULL) gets a per-cell
|
|
1174
|
+
default that descends through xfer_index, so the region is still all that
|
|
1175
|
+
gets touched. */
|
|
1755
1176
|
void ca_fill_stride (void *ap, ca_size_t base, int8_t ndim,
|
|
1756
1177
|
ca_size_t *counts, ca_size_t *steps, void *ptr);
|
|
1757
1178
|
void ca_fill_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *ptr);
|
|
1758
1179
|
|
|
1759
|
-
/* For slot implementations: the per-cell walk, to stand in for regions this
|
|
1760
|
-
view cannot pass on, and the test for the one region it always can. */
|
|
1761
|
-
void ca_fill_stride_default (void *ap, ca_size_t base, int8_t ndim,
|
|
1762
|
-
ca_size_t *counts, ca_size_t *steps, void *ptr);
|
|
1763
|
-
void ca_fill_addrs_default (void *ap, ca_size_t n, ca_size_t *addrs, void *ptr);
|
|
1764
|
-
|
|
1765
|
-
/* For a view whose fill is a read-modify-write of its parent and so has no
|
|
1766
|
-
region to pass down: walk the region and feed its addresses to the batched
|
|
1767
|
-
address slot in windows, rather than descending the chain per cell. */
|
|
1768
|
-
void ca_fill_stride_via_addrs (void *ap, ca_size_t base, int8_t ndim,
|
|
1769
|
-
ca_size_t *counts, ca_size_t *steps,
|
|
1770
|
-
void *ptr);
|
|
1771
|
-
|
|
1772
1180
|
/* The entity fill, against a buffer the caller resolved for itself. A source
|
|
1773
1181
|
that hands out its pointer on demand rather than keeping one at rest gets
|
|
1774
1182
|
the same run-writing walk without having to write it again, and without
|
|
@@ -1778,13 +1186,6 @@ void ca_fill_stride_buffer (char *dst, ca_size_t bytes, ca_size_t base,
|
|
|
1778
1186
|
ca_size_t *steps, void *ptr);
|
|
1779
1187
|
void ca_fill_addrs_buffer (char *dst, ca_size_t bytes, ca_size_t n,
|
|
1780
1188
|
ca_size_t *addrs, void *ptr);
|
|
1781
|
-
int ca_fill_stride_is_whole (void *ap, ca_size_t base, int8_t ndim,
|
|
1782
|
-
ca_size_t *counts, ca_size_t *steps);
|
|
1783
|
-
|
|
1784
|
-
/* Fill the whole of `ca` by handing its own extent to ca_fill_stride: the
|
|
1785
|
-
region every caller means when it says "all of me". Views use it to route
|
|
1786
|
-
a full-coverage fill_data into the region path. */
|
|
1787
|
-
void ca_fill_stride_whole (void *ap, void *ptr);
|
|
1788
1189
|
|
|
1789
1190
|
/* API : mask handling */
|
|
1790
1191
|
|
|
@@ -1813,8 +1214,6 @@ CArray *ca_unmask_copy (void *ap, char *fill_value);
|
|
|
1813
1214
|
|
|
1814
1215
|
/* API : cast, conversion */
|
|
1815
1216
|
|
|
1816
|
-
typedef void (*ca_cast_func_t)(ca_size_t, CArray *, void *, CArray *, void *, boolean8_t *);
|
|
1817
|
-
extern ca_cast_func_t ca_cast_func_table[CA_NTYPE][CA_NTYPE];
|
|
1818
1217
|
void ca_cast_block(ca_size_t n, void *a1, void *ptr1, void *a2, void *ptr2);
|
|
1819
1218
|
void ca_cast_block_with_mask (ca_size_t n, void *ap1, void *ptr1,
|
|
1820
1219
|
void *ap2, void *ptr2, boolean8_t *m);
|
|
@@ -1822,13 +1221,13 @@ void ca_ptr2ptr (void *ca1, void *ptr1, void *ca2, void *ptr2);
|
|
|
1822
1221
|
void ca_ptr2val (void *ap1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
1823
1222
|
void ca_val2ptr (int8_t data_type1, void *ptr1, void *ap2, void *ptr2);
|
|
1824
1223
|
void ca_val2val (int8_t data_type1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
1825
|
-
VALUE ca_ptr2obj (void *ap, void *ptr); /* use rb_ca_ptr2obj() */
|
|
1826
|
-
void ca_obj2ptr (void *ap, VALUE obj, void *ptr); /* use rb_ca_obj2ptr() */
|
|
1827
1224
|
|
|
1828
1225
|
#define ca_wrap_writable(obj, data_type) \
|
|
1829
|
-
(obj = rb_ca_wrap_writable(obj, INT2NUM(data_type)),
|
|
1226
|
+
(obj = rb_ca_wrap_writable(obj, INT2NUM(data_type)), \
|
|
1227
|
+
(CArray *) rb_check_typeddata((obj), &carray_data_type))
|
|
1830
1228
|
#define ca_wrap_readonly(obj, data_type) \
|
|
1831
|
-
(obj = rb_ca_wrap_readonly(obj, INT2NUM(data_type)),
|
|
1229
|
+
(obj = rb_ca_wrap_readonly(obj, INT2NUM(data_type)), \
|
|
1230
|
+
(CArray *) rb_check_typeddata((obj), &carray_data_type))
|
|
1832
1231
|
|
|
1833
1232
|
VALUE rb_carray_wrap_ptr (int8_t data_type,
|
|
1834
1233
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes,
|
|
@@ -1839,24 +1238,23 @@ VALUE rb_carray_wrap_ptr (int8_t data_type,
|
|
|
1839
1238
|
boolean8_t *ca_allocate_mask_iterator (int n, ...);
|
|
1840
1239
|
boolean8_t *ca_allocate_mask_iterator_n (int n, CArray **slist);
|
|
1841
1240
|
|
|
1842
|
-
ca_size_t ca_get_loop_count (int n, ...);
|
|
1843
|
-
ca_size_t ca_set_iterator (int n, ...);
|
|
1844
|
-
|
|
1845
|
-
void ca_swap_bytes (char *p, ca_size_t bytes, ca_size_t elements);
|
|
1846
1241
|
void ca_parse_range (VALUE vrange, ca_size_t size,
|
|
1847
1242
|
ca_size_t *offset, ca_size_t *count, ca_size_t *step);
|
|
1848
|
-
void ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
1849
|
-
ca_size_t *offset, ca_size_t *count, ca_size_t *step);
|
|
1850
|
-
|
|
1851
|
-
int ca_equal (void *ap, void *bp);
|
|
1852
|
-
int ca_eql_storage (void *ap, void *bp);
|
|
1853
1243
|
void ca_zerodiv(void) __attribute__((noreturn));
|
|
1854
|
-
|
|
1855
|
-
ca_size_t ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k);
|
|
1244
|
+
|
|
1856
1245
|
int rb_ca_normalize_axis_value (VALUE self, VALUE raxis, const char *name);
|
|
1246
|
+
/* An `axis` argument as an axis in [0, ndim): an Integer, negative counting
|
|
1247
|
+
from the end. Any other Integer raises ArgumentError naming the value,
|
|
1248
|
+
and anything else raises TypeError. `name` names the method in the
|
|
1249
|
+
message (NULL: the method the user called). For an insertion position,
|
|
1250
|
+
pass ndim + 1. */
|
|
1251
|
+
int rb_ca_normalize_axis_arg (VALUE raxis, int ndim, const char *name);
|
|
1857
1252
|
int rb_ca_normalize_axis_for_ndim (long raw, int ndim, const char *name);
|
|
1858
|
-
|
|
1859
|
-
|
|
1253
|
+
|
|
1254
|
+
/* A Ruby value read for an integer cell of `data_type`: an Integer, refused
|
|
1255
|
+
with RangeError naming the method when it does not fit the type. Any
|
|
1256
|
+
other value goes through Integer() (1.5 is 1; nil and NaN raise). */
|
|
1257
|
+
VALUE rb_ca_obj2integer_fitting (VALUE v, int8_t data_type);
|
|
1860
1258
|
|
|
1861
1259
|
/* API : high level */
|
|
1862
1260
|
|
|
@@ -1879,88 +1277,33 @@ VALUE ca_wrap_struct_as (void *ap, VALUE klass);
|
|
|
1879
1277
|
|
|
1880
1278
|
/* query data_type */
|
|
1881
1279
|
int8_t rb_ca_guess_type (VALUE obj);
|
|
1882
|
-
void rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
1883
|
-
int8_t *data_type, ca_size_t *bytes);
|
|
1884
|
-
int rb_ca_is_type (VALUE arg, int type);
|
|
1885
|
-
|
|
1886
|
-
/* scan index. info->range_check is read, not written: set it (1 to check
|
|
1887
|
-
each index against ca_dim) before the call. */
|
|
1888
|
-
void rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t elements,
|
|
1889
|
-
long argc, VALUE *argv, CAIndexInfo *info);
|
|
1890
1280
|
|
|
1891
1281
|
|
|
1892
1282
|
/* cast */
|
|
1893
|
-
int rb_ca_test_castable (VALUE other);
|
|
1894
|
-
VALUE rb_ca_binop_pass_to_other (VALUE self, VALUE other, ID method);
|
|
1895
1283
|
void rb_ca_cast_self_or_other (volatile VALUE *self, volatile VALUE *other);
|
|
1896
|
-
void rb_ca_cast_other (VALUE *self, volatile VALUE *other);
|
|
1897
1284
|
|
|
1898
1285
|
VALUE rb_ca_wrap_writable (VALUE obj, VALUE vtype);
|
|
1899
1286
|
VALUE rb_ca_wrap_readonly (VALUE obj, VALUE vtype);
|
|
1900
1287
|
|
|
1901
1288
|
/* inheritance */
|
|
1902
|
-
/* rb_ca_data_type_inherit / rb_ca_data_type_import were removed in 3.0.
|
|
1903
|
-
data_class lives on
|
|
1904
|
-
Face (CARecord) tail; view ctors no longer carry data_class via
|
|
1905
|
-
@data_class ivar — Face dispatch (CA_FACE_LIFT_IF_FACE) handles it. */
|
|
1906
1289
|
VALUE rb_ca_set_parent (VALUE self, VALUE obj);
|
|
1907
1290
|
/* call once for a view carray */
|
|
1908
1291
|
|
|
1909
1292
|
/* freeze and decraration of modifing contents of carray */
|
|
1910
|
-
VALUE rb_ca_freeze (VALUE self);
|
|
1911
|
-
VALUE rb_ca_set_read_only_flag (VALUE self);
|
|
1912
1293
|
void rb_ca_modify (VALUE self); /* guard: rb_check_frozen(self) + ca_is_readonly */
|
|
1913
1294
|
|
|
1914
1295
|
/* attributes */
|
|
1915
|
-
VALUE rb_ca_obj_type (VALUE self);
|
|
1916
|
-
VALUE rb_ca_data_type (VALUE self);
|
|
1917
|
-
VALUE rb_ca_ndim (VALUE self);
|
|
1918
|
-
VALUE rb_ca_bytes (VALUE self);
|
|
1919
|
-
VALUE rb_ca_flags (VALUE self);
|
|
1920
|
-
VALUE rb_ca_elements (VALUE self);
|
|
1921
|
-
VALUE rb_ca_dim (VALUE self);
|
|
1922
|
-
VALUE rb_ca_dim0 (VALUE self);
|
|
1923
|
-
VALUE rb_ca_dim1 (VALUE self);
|
|
1924
|
-
VALUE rb_ca_dim2 (VALUE self);
|
|
1925
|
-
VALUE rb_ca_dim3 (VALUE self);
|
|
1926
|
-
VALUE rb_ca_data_type_name (VALUE self);
|
|
1927
1296
|
VALUE rb_ca_parent (VALUE self);
|
|
1928
1297
|
|
|
1929
|
-
VALUE rb_ca_is_fixlen_type (VALUE self);
|
|
1930
|
-
VALUE rb_ca_is_boolean_type (VALUE self);
|
|
1931
|
-
VALUE rb_ca_is_integer_type (VALUE self);
|
|
1932
|
-
VALUE rb_ca_is_float_type (VALUE self);
|
|
1933
|
-
VALUE rb_ca_is_complex_type (VALUE self);
|
|
1934
|
-
VALUE rb_ca_is_object_type (VALUE self);
|
|
1935
|
-
|
|
1936
|
-
VALUE rb_ca_is_entity (VALUE self);
|
|
1937
|
-
VALUE rb_ca_is_virtual (VALUE self);
|
|
1938
|
-
VALUE rb_ca_is_attached (VALUE self);
|
|
1939
|
-
VALUE rb_ca_is_empty (VALUE self);
|
|
1940
|
-
VALUE rb_ca_is_read_only (VALUE self);
|
|
1941
|
-
VALUE rb_ca_is_mask_array (VALUE self);
|
|
1942
|
-
VALUE rb_ca_is_value_array (VALUE self);
|
|
1943
|
-
|
|
1944
|
-
VALUE rb_ca_is_scalar (VALUE self);
|
|
1945
|
-
|
|
1946
|
-
/* data class access (struct) */
|
|
1947
|
-
VALUE rb_obj_is_data_class (VALUE rtype);
|
|
1948
|
-
VALUE rb_ca_has_data_class (VALUE self);
|
|
1949
|
-
VALUE rb_ca_data_class (VALUE self);
|
|
1950
|
-
/* rb_ca_set_data_class was removed in 3.0. The Ruby method
|
|
1951
|
-
CArray#data_class= raises ArgumentError with migration message. */
|
|
1952
|
-
VALUE rb_ca_data_class_decode (VALUE self, VALUE str);
|
|
1953
|
-
VALUE rb_ca_data_class_encode (VALUE self, VALUE obj);
|
|
1954
|
-
VALUE rb_ca_members (VALUE self);
|
|
1955
|
-
VALUE rb_ca_face_field (VALUE self, VALUE sym);
|
|
1956
|
-
VALUE rb_ca_fields_at (int argc, VALUE *argv, VALUE self);
|
|
1957
|
-
VALUE rb_ca_fields (VALUE self);
|
|
1958
|
-
|
|
1959
1298
|
/* mask */
|
|
1960
1299
|
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1300
|
+
/* rb_ca_is_masked, rb_ca_is_not_masked, rb_ca_value_array,
|
|
1301
|
+
rb_ca_mask_array and rb_ca_set_mask here, rb_ca_fill and
|
|
1302
|
+
rb_ca_fill_copy, and rb_ca_reshape and rb_ca_flatten are the C forms of
|
|
1303
|
+
the Ruby methods is_masked, is_not_masked, value, mask, mask=, fill,
|
|
1304
|
+
fill_copy, reshape and flatten: calling one is the same as calling the
|
|
1305
|
+
method. rb_ca_fetch, rb_ca_fetch2, rb_ca_store and rb_ca_store2 below
|
|
1306
|
+
are the C forms of [] and []=, with the exceptions given there. */
|
|
1964
1307
|
VALUE rb_ca_value_array (VALUE self);
|
|
1965
1308
|
VALUE rb_ca_mask_array (VALUE self);
|
|
1966
1309
|
VALUE rb_ca_set_mask (VALUE self, VALUE val);
|
|
@@ -1970,15 +1313,10 @@ VALUE rb_ca_unmask (VALUE self);
|
|
|
1970
1313
|
VALUE rb_ca_mask_fill (VALUE self, VALUE fval);
|
|
1971
1314
|
VALUE rb_ca_unmask_copy (VALUE self);
|
|
1972
1315
|
VALUE rb_ca_mask_fill_copy (VALUE self, VALUE fval);
|
|
1973
|
-
VALUE rb_ca_inherit_mask_replace_n (VALUE self, int argc, VALUE *argv);
|
|
1974
|
-
VALUE rb_ca_inherit_mask_replace (VALUE self, int n, ...);
|
|
1975
|
-
VALUE rb_ca_inherit_mask_n (VALUE self, int argc, VALUE *argv);
|
|
1976
|
-
VALUE rb_ca_inherit_mask (VALUE self, int n, ...);
|
|
1977
1316
|
|
|
1978
1317
|
/* copy */
|
|
1979
1318
|
|
|
1980
1319
|
VALUE rb_ca_copy (VALUE self);
|
|
1981
|
-
VALUE rb_ca_to_ca (int argc, VALUE *argv, VALUE self);
|
|
1982
1320
|
int ca_to_ca_writable_arg (int argc, VALUE *argv);
|
|
1983
1321
|
NORETURN(void ca_to_ca_refuse_writable (VALUE self));
|
|
1984
1322
|
VALUE rb_ca_template (VALUE self);
|
|
@@ -1988,105 +1326,47 @@ VALUE rb_ca_template_n (int n, ...);
|
|
|
1988
1326
|
VALUE rb_ca_fill (VALUE self, VALUE val);
|
|
1989
1327
|
VALUE rb_ca_fill_copy (VALUE self, VALUE val);
|
|
1990
1328
|
|
|
1991
|
-
/* address calculation */
|
|
1992
|
-
VALUE rb_ca_addr2index (VALUE self, VALUE raddr);
|
|
1993
|
-
|
|
1994
1329
|
/* A cell's bytes (self's data type, self->bytes wide) as the value ca[i]
|
|
1995
1330
|
gives for that cell: true or false for a boolean, the element for a
|
|
1996
1331
|
Face, a record for a struct. The mask is not consulted. */
|
|
1997
1332
|
VALUE rb_ca_ptr2obj (VALUE self, void *ptr);
|
|
1998
|
-
#define rb_ca_fetch_ptr(self, ptr) rb_ca_ptr2obj(self, ptr)
|
|
1999
1333
|
|
|
2000
1334
|
/* elemental access like ca[i,j,k] or ca[addr] */
|
|
2001
1335
|
VALUE rb_ca_fetch_index (VALUE self, ca_size_t *idx);
|
|
2002
1336
|
VALUE rb_ca_fetch_addr (VALUE self, ca_size_t addr);
|
|
1337
|
+
|
|
1338
|
+
/* rb_ca_fetch and rb_ca_fetch2 are CArray#[], and rb_ca_store and
|
|
1339
|
+
rb_ca_store2 are CArray#[]=, with val as the value. rb_ca_fetch and
|
|
1340
|
+
rb_ca_store take the indices as one Ruby Array, or a single index as
|
|
1341
|
+
itself. The messages of their errors name the Ruby method that called
|
|
1342
|
+
the extension.
|
|
1343
|
+
|
|
1344
|
+
A CScalar has [] and []= of its own, which take no index or the index
|
|
1345
|
+
0 and refuse any other. These functions index a CScalar as CArray#[]
|
|
1346
|
+
indexes a one-cell 1-D array instead: with no index rb_ca_fetch2 gives
|
|
1347
|
+
a one-cell view of it, not its value, and indices such as -1, nil, 0..0
|
|
1348
|
+
or a boolean array are taken. An extension reads a CScalar's value
|
|
1349
|
+
with rb_ca_fetch_addr(obj, 0) and stores it with rb_ca_store_addr(obj,
|
|
1350
|
+
0, val), or calls [] and []= with rb_funcall. An extension stores val
|
|
1351
|
+
in every cell of an array with rb_ca_store2(self, 0, NULL, val). */
|
|
2003
1352
|
VALUE rb_ca_fetch (VALUE self, VALUE index);
|
|
2004
1353
|
VALUE rb_ca_fetch2 (VALUE self, int n, VALUE *vindex);
|
|
2005
1354
|
|
|
2006
1355
|
VALUE rb_ca_obj2ptr (VALUE self, VALUE val, void *ptr);
|
|
2007
|
-
#define rb_ca_store_ptr(self, ptr, val) rb_ca_obj2ptr(self, val, ptr)
|
|
2008
1356
|
VALUE rb_ca_store_index (VALUE self, ca_size_t *idx, VALUE val);
|
|
2009
1357
|
VALUE rb_ca_store_addr (VALUE self, ca_size_t addr, VALUE val);
|
|
2010
1358
|
VALUE rb_ca_store (VALUE self, VALUE index, VALUE val);
|
|
2011
1359
|
VALUE rb_ca_store2 (VALUE self, int n, VALUE *vindex, VALUE val);
|
|
2012
|
-
VALUE rb_ca_store_all (VALUE self, VALUE val);
|
|
2013
|
-
|
|
2014
|
-
/* elemental operations */
|
|
2015
|
-
VALUE rb_ca_elem_swap (VALUE self, VALUE vidx1, VALUE vidx2);
|
|
2016
|
-
VALUE rb_ca_elem_copy (VALUE self, VALUE vidx1, VALUE vidx2);
|
|
2017
|
-
VALUE rb_ca_elem_store (VALUE self, VALUE vidx, VALUE obj);
|
|
2018
|
-
VALUE rb_ca_elem_fetch (VALUE self, VALUE vidx);
|
|
2019
|
-
VALUE rb_ca_elem_incr (VALUE self, VALUE vidx1);
|
|
2020
|
-
VALUE rb_ca_elem_decr (VALUE self, VALUE vidx1);
|
|
2021
|
-
VALUE rb_ca_elem_test_masked (VALUE self, VALUE vidx1);
|
|
2022
|
-
|
|
2023
|
-
/* data type conversion */
|
|
2024
|
-
VALUE rb_ca_ptr2ptr (VALUE ra1, void *ptr1, VALUE ra2, void *ptr2);
|
|
2025
|
-
VALUE rb_ca_cast_block (ca_size_t n, VALUE ra1, void *ptr1,
|
|
2026
|
-
VALUE ra2, void *ptr2);
|
|
2027
1360
|
|
|
2028
1361
|
VALUE rb_ca_to_type (VALUE self, VALUE rtype, VALUE rbytes);
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
VALUE rb_ca_to_uint8 (VALUE self);
|
|
2032
|
-
VALUE rb_ca_to_int16 (VALUE self);
|
|
2033
|
-
VALUE rb_ca_to_uint16 (VALUE self);
|
|
2034
|
-
VALUE rb_ca_to_int32 (VALUE self);
|
|
2035
|
-
VALUE rb_ca_to_uint32 (VALUE self);
|
|
2036
|
-
VALUE rb_ca_to_int64 (VALUE self);
|
|
2037
|
-
VALUE rb_ca_to_uint64 (VALUE self);
|
|
2038
|
-
VALUE rb_ca_to_float32 (VALUE self);
|
|
2039
|
-
VALUE rb_ca_to_float64 (VALUE self);
|
|
2040
|
-
VALUE rb_ca_to_cmplx64 (VALUE self);
|
|
2041
|
-
VALUE rb_ca_to_cmplx128 (VALUE self);
|
|
2042
|
-
VALUE rb_ca_to_VALUE (VALUE self);
|
|
2043
|
-
#define rb_ca_to_object(self) rb_ca_to_VALUE(self)
|
|
2044
|
-
|
|
2045
|
-
/* to ruby's array */
|
|
2046
|
-
VALUE rb_ca_to_a (VALUE self);
|
|
2047
|
-
|
|
2048
|
-
/* generation */
|
|
2049
|
-
VALUE rb_ca_seq_bang (VALUE self, VALUE offset, VALUE step);
|
|
2050
|
-
VALUE rb_ca_seq_bang2 (VALUE self, int n, VALUE *args);
|
|
2051
|
-
VALUE rb_ca_seq (VALUE self, VALUE offset, VALUE step);
|
|
2052
|
-
VALUE rb_ca_seq2 (VALUE self, int n, VALUE *args);
|
|
2053
|
-
VALUE rb_ca_where (VALUE self);
|
|
2054
|
-
|
|
2055
|
-
/* elemental byte swap */
|
|
2056
|
-
VALUE rb_ca_swap_bytes_bang (VALUE self);
|
|
2057
|
-
VALUE rb_ca_swap_bytes (VALUE self);
|
|
2058
|
-
|
|
2059
|
-
/* API : CAMath functions
|
|
1362
|
+
|
|
1363
|
+
/* API : the call_cfunc / cslab entry points
|
|
2060
1364
|
*
|
|
2061
1365
|
* Declarations live in carray_call_cfunc.h, co-generated with
|
|
2062
1366
|
* carray_call_cfunc.c by ext/mk_call_cfunc.rb to keep prototypes
|
|
2063
1367
|
* and definitions in lockstep. */
|
|
2064
1368
|
#include "carray_call_cfunc.h"
|
|
2065
1369
|
|
|
2066
|
-
/* -------------------------------------------------------------------- */
|
|
2067
|
-
|
|
2068
|
-
/* carray_loop.c — unified multi-dimensional index walk shared by
|
|
2069
|
-
each_index / each_with_index / map_index! / map_with_index! and by
|
|
2070
|
-
the construction-block sugar in rb_ca_initialize. */
|
|
2071
|
-
#define CA_LOOP_WITH_VALUE 1
|
|
2072
|
-
#define CA_LOOP_STORE 2
|
|
2073
|
-
|
|
2074
|
-
VALUE rb_ca_index_walk (VALUE self, CArray *ca, int8_t level,
|
|
2075
|
-
ca_size_t *idx, VALUE ridx, int mode);
|
|
2076
|
-
|
|
2077
|
-
/* -------------------------------------------------------------------- */
|
|
2078
|
-
|
|
2079
|
-
void ca_debug ();
|
|
2080
|
-
|
|
2081
|
-
/* -------------------------------------------------------------------- */
|
|
2082
|
-
|
|
2083
|
-
/* Portable textbook sort kernels.
|
|
2084
|
-
These are layer ③ true-internal (ca_sort_kernels.h self-describes as
|
|
2085
|
-
"ext-internal, signatures may change across 3.x"). They are NOT pulled
|
|
2086
|
-
into the carray.h umbrella and NOT installed: the internal consumers (carray_sort_kernel.c / carray_sort.c /
|
|
2087
|
-
carray_partition.c / carray_kernels.c) include ca_sort_kernels.h
|
|
2088
|
-
directly. */
|
|
2089
|
-
|
|
2090
1370
|
/* -------------------------------------------------------------------- */
|
|
2091
1371
|
/* Public umbrella */
|
|
2092
1372
|
/* -------------------------------------------------------------------- */
|
|
@@ -2096,9 +1376,18 @@ void ca_debug ();
|
|
|
2096
1376
|
`#include "carray.h"`. Placed at the bottom so these sub-headers see
|
|
2097
1377
|
every type / enum / struct defined above (ca_size_t, CA_NTYPE, CArray,
|
|
2098
1378
|
...). All sub-headers are include-guarded, so the carray.h re-entry
|
|
2099
|
-
from inside them is a no-op.
|
|
1379
|
+
from inside them is a no-op. The Face authoring surface (ca_obj_face.h)
|
|
1380
|
+
and rb_ca_call_with_buffer (ca_for_buffer.h) are not pulled in: an
|
|
1381
|
+
extension that uses them includes them itself. */
|
|
2100
1382
|
|
|
2101
|
-
#include "carray_math_kernel.h" /* kernel typedefs +
|
|
1383
|
+
#include "carray_math_kernel.h" /* kernel typedefs + dispatch tables */
|
|
2102
1384
|
#include "ca_kernel_iterator.h" /* CA_FOR_EACH_SLAB / CA_WITH_WHOLE_VIEW / CA_SLAB_*_T */
|
|
2103
1385
|
|
|
1386
|
+
/* carray's own declarations, which an extension, built without
|
|
1387
|
+
CARRAY_BUILD, never reads. They come last because they build on every
|
|
1388
|
+
public declaration above, ca_iter_state included. */
|
|
1389
|
+
#ifdef CARRAY_BUILD
|
|
1390
|
+
#include "carray_internal.h"
|
|
1391
|
+
#endif
|
|
1392
|
+
|
|
2104
1393
|
#endif
|