carray 3.0.3 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +469 -0
- data/README.md +3 -2
- data/carray.gemspec +1 -1
- data/ext/ca_array_pool.c +25 -1
- data/ext/ca_axis_descriptor.h +27 -24
- data/ext/ca_axis_dispatch.c +14 -26
- data/ext/ca_axis_group.c +27 -27
- data/ext/ca_binop_dispatch.c +1 -29
- data/ext/ca_binop_dispatch.h +0 -1
- data/ext/ca_categorical_iterator.c +231 -153
- data/ext/ca_compare.c +9 -20
- data/ext/ca_composite_dispatch.c +9 -9
- data/ext/ca_group_iter.c +16 -17
- data/ext/ca_kernel_iterator.c +1240 -2000
- data/ext/ca_kernel_iterator.h +502 -519
- data/ext/ca_monop_dispatch.c +82 -59
- data/ext/ca_monop_dispatch.h +1 -0
- data/ext/ca_obj_array.c +152 -45
- data/ext/ca_obj_bincmp.c +25 -21
- data/ext/ca_obj_binop.c +16 -26
- data/ext/ca_obj_bitarray.c +8 -3
- data/ext/ca_obj_bitfield.c +63 -49
- data/ext/ca_obj_block.c +18 -9
- data/ext/ca_obj_byte_swap.c +7 -7
- data/ext/ca_obj_const_string.c +188 -22
- data/ext/ca_obj_face.c +280 -58
- data/ext/ca_obj_face.h +19 -0
- data/ext/ca_obj_fake.c +15 -29
- data/ext/ca_obj_farray.c +6 -3
- data/ext/ca_obj_field.c +30 -8
- data/ext/ca_obj_fixlen_string.c +2 -3
- data/ext/ca_obj_grid.c +455 -134
- data/ext/ca_obj_meld.c +172 -34
- data/ext/ca_obj_moncmp.c +23 -8
- data/ext/ca_obj_monop.c +113 -67
- data/ext/ca_obj_object.c +210 -52
- data/ext/ca_obj_record.c +15 -7
- data/ext/ca_obj_reduce.c +17 -8
- data/ext/ca_obj_refer.c +42 -35
- data/ext/ca_obj_remap.c +30 -9
- data/ext/ca_obj_repeat.c +9 -10
- data/ext/ca_obj_roll.c +31 -10
- data/ext/ca_obj_select.c +48 -14
- data/ext/ca_obj_select_axis.c +15 -47
- data/ext/ca_obj_shift.c +41 -7
- data/ext/ca_obj_stack.c +180 -34
- data/ext/ca_obj_stride.c +190 -134
- data/ext/ca_obj_string.c +80 -4
- data/ext/ca_obj_tile.c +32 -11
- data/ext/ca_obj_time.c +22 -6
- data/ext/ca_obj_timedelta.c +22 -6
- data/ext/ca_obj_transpose.c +13 -7
- data/ext/ca_obj_triop.c +26 -32
- data/ext/ca_obj_window.c +267 -74
- data/ext/ca_op_ipower.c +4 -4
- data/ext/ca_sort_kernels.h +6 -3
- data/ext/ca_sweep_engine.c +2 -2
- data/ext/caframe_csv_reader.c +80 -1
- data/ext/carray.h +214 -75
- data/ext/carray_access.c +200 -99
- data/ext/carray_address_basis.c +343 -87
- data/ext/carray_attribute.c +113 -6
- data/ext/carray_bincount.c +10 -8
- data/ext/carray_broadcast.c +13 -8
- data/ext/carray_build_flags.h +3 -0
- data/ext/carray_call_cfunc.c +108 -0
- data/ext/carray_cast.c +375 -96
- data/ext/carray_cast_func.rb +90 -20
- data/ext/carray_class.c +4 -3
- data/ext/carray_config.h +28 -0
- data/ext/carray_conversion.c +18 -9
- data/ext/carray_copy.c +51 -14
- data/ext/carray_core.c +150 -55
- data/ext/carray_count.c +56 -20
- data/ext/carray_element.c +81 -33
- data/ext/carray_factorize.c +138 -84
- data/ext/carray_generate.c +199 -52
- data/ext/carray_histogram.c +63 -18
- data/ext/carray_hold.c +12 -15
- data/ext/carray_index_classifier.c +388 -176
- data/ext/carray_internal.h +348 -29
- data/ext/carray_kernels_bincmp.c +4453 -0
- data/ext/carray_kernels_binop.c +11368 -0
- data/ext/carray_kernels_init.c +1734 -0
- data/ext/carray_kernels_moncmp.c +2104 -0
- data/ext/carray_kernels_monop.c +18369 -0
- data/ext/carray_kernels_reduce_aggregate.c +23818 -0
- data/ext/carray_kernels_reduce_boolean.c +406 -0
- data/ext/carray_kernels_reduce_cumulative.c +10086 -0
- data/ext/carray_kernels_reduce_extreme.c +17634 -0
- data/ext/carray_kernels_reduce_variance.c +3849 -0
- data/ext/carray_kernels_scan.c +4302 -0
- data/ext/carray_kernels_search.c +33829 -0
- data/ext/carray_kernels_sort.c +10897 -0
- data/ext/carray_kernels_triop.c +1864 -0
- data/ext/carray_key_windows.c +220 -0
- data/ext/carray_lazy.c +170 -111
- data/ext/carray_mask.c +337 -94
- data/ext/carray_median_percentile.c +82 -28
- data/ext/carray_memory_view.c +669 -561
- data/ext/carray_operator.c +129 -52
- data/ext/carray_order.c +604 -77
- data/ext/carray_partition.c +28 -27
- data/ext/carray_random.c +85 -31
- data/ext/carray_round.c +273 -0
- data/ext/carray_scatter.c +87 -45
- data/ext/carray_segment.c +3 -3
- data/ext/carray_slab.c +123 -37
- data/ext/carray_sort.c +259 -51
- data/ext/carray_sort_kernel.c +5 -7
- data/ext/carray_struct.c +54 -61
- data/ext/carray_test.c +26 -5
- data/ext/carray_time_text.c +4 -2
- data/ext/carray_undef.c +4 -0
- data/ext/carray_utils.c +309 -66
- data/ext/mk_call_cfunc.rb +19 -2
- data/ext/mkkernel.rb +403 -350
- data/ext/ruby_carray.c +10 -4
- data/ext/version.h +4 -4
- data/lib/carray/attribute.rb +139 -22
- data/lib/carray/autoload_carray.rb +8 -31
- data/lib/carray/autoload_method_extension.rb +14 -5
- data/lib/carray/axis_group.rb +255 -106
- data/lib/carray/basics.rb +105 -17
- data/lib/carray/bincount_nd.rb +12 -2
- data/lib/carray/block_iterator.rb +126 -23
- data/lib/carray/boolean_reduce.rb +17 -17
- data/lib/carray/categorical.rb +195 -59
- data/lib/carray/categorical_iterator.rb +132 -29
- data/lib/carray/complex.rb +5 -5
- data/lib/carray/conditional.rb +67 -18
- data/lib/carray/const_string.rb +24 -5
- data/lib/carray/construct.rb +15 -11
- data/lib/carray/data_type_extension.rb +9 -1
- data/lib/carray/distance_limit.rb +77 -0
- data/lib/carray/fixlen_string.rb +48 -3
- data/lib/carray/frame/column_verbs.rb +71 -0
- data/lib/carray/frame/concat.rb +17 -3
- data/lib/carray/frame/convert.rb +69 -0
- data/lib/carray/frame/csv_parser.rb +111 -17
- data/lib/carray/frame/describe.rb +3 -2
- data/lib/carray/frame/frame.rb +252 -28
- data/lib/carray/frame/group.rb +603 -101
- data/lib/carray/frame/io.rb +117 -28
- data/lib/carray/frame/join.rb +312 -51
- data/lib/carray/frame/records.rb +83 -7
- data/lib/carray/frame/reshape.rb +42 -35
- data/lib/carray/frame/sort.rb +7 -19
- data/lib/carray/frame/verbs.rb +188 -48
- data/lib/carray/frame/windows.rb +117 -0
- data/lib/carray/frame.rb +2 -0
- data/lib/carray/fuse_source.rb +42 -6
- data/lib/carray/fusion.rb +40 -16
- data/lib/carray/histogram.rb +6 -1
- data/lib/carray/inspect.rb +31 -8
- data/lib/carray/iterator.rb +85 -7
- data/lib/carray/key_windows.rb +620 -0
- data/lib/carray/lazy.rb +217 -183
- data/lib/carray/mask_gap_fill.rb +63 -57
- data/lib/carray/meld_reduce.rb +12 -14
- data/lib/carray/methods/bin.rb +26 -18
- data/lib/carray/methods/bincount.rb +16 -0
- data/lib/carray/methods/bit_string.rb +1 -1
- data/lib/carray/methods/choose.rb +16 -3
- data/lib/carray/methods/composition.rb +3 -1
- data/lib/carray/methods/gather_nd.rb +14 -5
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +59 -0
- data/lib/carray/methods/is_in.rb +61 -37
- data/lib/carray/methods/join.rb +1 -6
- data/lib/carray/methods/lag.rb +49 -0
- data/lib/carray/methods/locate_addr.rb +47 -51
- data/lib/carray/methods/mode.rb +1 -1
- data/lib/carray/methods/nunique.rb +11 -6
- data/lib/carray/methods/resize.rb +3 -3
- data/lib/carray/methods/value_counts.rb +4 -11
- data/lib/carray/record_order.rb +3 -3
- data/lib/carray/rng.rb +3 -0
- data/lib/carray/runtime.rb +53 -8
- data/lib/carray/segment_iterator.rb +323 -88
- data/lib/carray/serialize.rb +45 -14
- data/lib/carray/slab_iterator.rb +50 -0
- data/lib/carray/stack.rb +15 -12
- data/lib/carray/string.rb +113 -5
- data/lib/carray/string_operation_extension.rb +21 -6
- data/lib/carray/struct.rb +9 -21
- data/lib/carray/struct_builder.rb +24 -11
- data/lib/carray/time.rb +819 -158
- data/lib/carray/window_iterator.rb +122 -16
- data/lib/carray.rb +7 -0
- data/yard-stubs/ca_obj_bitfield.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +4 -0
- data/yard-stubs/ca_obj_grid.rb +21 -10
- data/yard-stubs/ca_obj_refer.rb +2 -1
- data/yard-stubs/ca_obj_roll.rb +2 -2
- data/yard-stubs/ca_obj_shift.rb +5 -1
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_transpose.rb +5 -4
- data/yard-stubs/ca_obj_window.rb +8 -3
- data/yard-stubs/carray_access.rb +6 -1
- data/yard-stubs/carray_attribute.rb +3 -6
- data/yard-stubs/carray_cast.rb +12 -0
- data/yard-stubs/carray_conversion.rb +7 -2
- data/yard-stubs/carray_copy.rb +4 -2
- data/yard-stubs/carray_count.rb +4 -4
- data/yard-stubs/carray_element.rb +17 -10
- data/yard-stubs/carray_generate.rb +21 -1
- data/yard-stubs/carray_mask.rb +32 -3
- data/yard-stubs/carray_math.rb +41 -5
- data/yard-stubs/carray_median_percentile.rb +5 -2
- data/yard-stubs/carray_memory_view.rb +40 -23
- data/yard-stubs/carray_order.rb +129 -22
- data/yard-stubs/carray_random.rb +13 -4
- data/yard-stubs/carray_scatter.rb +17 -10
- data/yard-stubs/carray_slab.rb +9 -2
- data/yard-stubs/carray_sort.rb +6 -5
- data/yard-stubs/carray_test.rb +5 -3
- metadata +25 -3
- data/lib/carray/arrow_tensor.rb +0 -401
- data/lib/carray/table.rb +0 -108
data/ext/caframe_csv_reader.c
CHANGED
|
@@ -39,6 +39,85 @@ ca_csv_at (const char *s, long n, long p, const char *t, long tlen)
|
|
|
39
39
|
return p + tlen <= n && memcmp(s + p, t, tlen) == 0;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/* The coderange of UTF-8 text, as rb_enc_str_coderange answers it: 7BIT,
|
|
43
|
+
VALID, or BROKEN for an invalid sequence (a stray continuation byte, an
|
|
44
|
+
overlong form, a surrogate, past U+10FFFF, or a sequence cut short).
|
|
45
|
+
Runs of ASCII are passed over 8 bytes at a time, which Ruby's scan does
|
|
46
|
+
not do once it has met a multibyte character. */
|
|
47
|
+
static int
|
|
48
|
+
ca_csv_utf8_coderange (const unsigned char *s, long n)
|
|
49
|
+
{
|
|
50
|
+
long i = 0;
|
|
51
|
+
int ascii = 1;
|
|
52
|
+
while ( i < n ) {
|
|
53
|
+
unsigned c, c1;
|
|
54
|
+
while ( i + 8 <= n ) {
|
|
55
|
+
uint64_t w;
|
|
56
|
+
memcpy(&w, s + i, 8);
|
|
57
|
+
if ( w & 0x8080808080808080ULL ) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
i += 8;
|
|
61
|
+
}
|
|
62
|
+
if ( i >= n ) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
c = s[i];
|
|
66
|
+
if ( c < 0x80 ) {
|
|
67
|
+
i += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
ascii = 0;
|
|
71
|
+
if ( c < 0xC2 || c > 0xF4 ) {
|
|
72
|
+
return ENC_CODERANGE_BROKEN;
|
|
73
|
+
}
|
|
74
|
+
if ( c < 0xE0 ) {
|
|
75
|
+
if ( i + 1 >= n || ( s[i + 1] & 0xC0 ) != 0x80 ) {
|
|
76
|
+
return ENC_CODERANGE_BROKEN;
|
|
77
|
+
}
|
|
78
|
+
i += 2;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if ( i + 1 >= n ) {
|
|
82
|
+
return ENC_CODERANGE_BROKEN;
|
|
83
|
+
}
|
|
84
|
+
c1 = s[i + 1];
|
|
85
|
+
if ( ( c1 & 0xC0 ) != 0x80
|
|
86
|
+
|| ( c == 0xE0 && c1 < 0xA0 ) || ( c == 0xED && c1 > 0x9F )
|
|
87
|
+
|| ( c == 0xF0 && c1 < 0x90 ) || ( c == 0xF4 && c1 > 0x8F ) ) {
|
|
88
|
+
return ENC_CODERANGE_BROKEN;
|
|
89
|
+
}
|
|
90
|
+
if ( c < 0xF0 ) {
|
|
91
|
+
if ( i + 2 >= n || ( s[i + 2] & 0xC0 ) != 0x80 ) {
|
|
92
|
+
return ENC_CODERANGE_BROKEN;
|
|
93
|
+
}
|
|
94
|
+
i += 3;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if ( i + 3 >= n || ( s[i + 2] & 0xC0 ) != 0x80 || ( s[i + 3] & 0xC0 ) != 0x80 ) {
|
|
98
|
+
return ENC_CODERANGE_BROKEN;
|
|
99
|
+
}
|
|
100
|
+
i += 4;
|
|
101
|
+
}
|
|
102
|
+
return ascii ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* The coderange of the text, computed here for UTF-8 and cached on the
|
|
106
|
+
String as Ruby would cache it, so the Ruby reader's later String#count on
|
|
107
|
+
the same chunk does not scan it again. */
|
|
108
|
+
static int
|
|
109
|
+
ca_csv_text_coderange (VALUE text, rb_encoding *enc)
|
|
110
|
+
{
|
|
111
|
+
int cr = ENC_CODERANGE(text);
|
|
112
|
+
if ( cr != ENC_CODERANGE_UNKNOWN || enc != rb_utf8_encoding() ) {
|
|
113
|
+
return rb_enc_str_coderange(text);
|
|
114
|
+
}
|
|
115
|
+
cr = ca_csv_utf8_coderange((const unsigned char *) RSTRING_PTR(text),
|
|
116
|
+
RSTRING_LEN(text));
|
|
117
|
+
ENC_CODERANGE_SET(text, cr);
|
|
118
|
+
return cr;
|
|
119
|
+
}
|
|
120
|
+
|
|
42
121
|
/* The end of the line content that starts at p: the position of its "\n",
|
|
43
122
|
or n; *next is where the following line starts. A "\r" before the "\n",
|
|
44
123
|
or at the end of the text, is not content. */
|
|
@@ -311,7 +390,7 @@ ca_csv_check_reader_args (VALUE text, VALUE vsep, VALUE vquote, VALUE vncol,
|
|
|
311
390
|
*ncol = NUM2LONG(vncol);
|
|
312
391
|
enc = rb_enc_get(text);
|
|
313
392
|
if ( ( enc != rb_utf8_encoding() && enc != rb_usascii_encoding() )
|
|
314
|
-
||
|
|
393
|
+
|| ca_csv_text_coderange(text, enc) == ENC_CODERANGE_BROKEN || *ncol < 0 ) {
|
|
315
394
|
return 0;
|
|
316
395
|
}
|
|
317
396
|
return RSTRING_LEN(vsep) >= 1 && RSTRING_LEN(vquote) >= 1;
|
data/ext/carray.h
CHANGED
|
@@ -173,6 +173,39 @@ typedef int8_t boolean8_t;
|
|
|
173
173
|
#define CA_ALIGN_CMPLX128 offsetof(struct { char c; cmplx128_t x; }, x)
|
|
174
174
|
#define CA_ALIGN_OBJECT offsetof(struct { char c; VALUE x; }, x)
|
|
175
175
|
|
|
176
|
+
/* Cell types that may sit at any byte. A view's cells need not be aligned
|
|
177
|
+
to their size: a struct member at offset 1, a refer with a byte offset,
|
|
178
|
+
a wrapped external buffer. Reading a cell through a plain `double *`
|
|
179
|
+
there is undefined (x86 vector code may assume the alignment), so a
|
|
180
|
+
kernel reads and writes cells through these. Same size and value as the
|
|
181
|
+
plain type; only the alignment the compiler may assume is 1. */
|
|
182
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
183
|
+
# define CA_UNALIGNED __attribute__((aligned(1)))
|
|
184
|
+
#else
|
|
185
|
+
# define CA_UNALIGNED
|
|
186
|
+
#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
|
+
|
|
176
209
|
/* -------------------------------------------------------------------- */
|
|
177
210
|
|
|
178
211
|
#define CA_OBJ_TYPE_MAX 256
|
|
@@ -347,14 +380,12 @@ typedef struct {
|
|
|
347
380
|
void (*detach) (void *ap);
|
|
348
381
|
void (*fill_data) (void *ap, void *data);
|
|
349
382
|
void (*create_mask) (void *ap);
|
|
350
|
-
/* xfer protocol.
|
|
351
|
-
positional initializers leave it NULL automatically. dir = CA_XFER_GET /
|
|
352
|
-
CA_XFER_PUT. */
|
|
383
|
+
/* xfer protocol. dir = CA_XFER_GET / CA_XFER_PUT. */
|
|
353
384
|
void (*xfer_index) (void *ap, ca_size_t *idx, void *data, int dir);
|
|
354
385
|
void (*xfer_addrs) (void *ap, ca_size_t n, ca_size_t *addrs,
|
|
355
386
|
void *data, int dir);
|
|
356
|
-
/* fold_stride: one compose-fold hop
|
|
357
|
-
|
|
387
|
+
/* fold_stride: one compose-fold hop for the views that fold only
|
|
388
|
+
sometimes (CAWindow, CAGrid, CASelectAxis, CAStack, CAMeld).
|
|
358
389
|
Compose *f into next_parent's byte space and return 1, or decline
|
|
359
390
|
(leave *f / *next_parent untouched) and return 0 -> this view is the
|
|
360
391
|
fold boundary. CAStride family leaves this NULL (handled open-inline
|
|
@@ -637,6 +668,13 @@ typedef struct {
|
|
|
637
668
|
(count[k] == parent->dim[k] && start[k]
|
|
638
669
|
== 0 for k >= 1). Embedded region
|
|
639
670
|
must be contig in parent storage. */
|
|
671
|
+
/* A window over a parent that has no mask: the all-false mask its own
|
|
672
|
+
mask reads instead, so that masking the out-of-bounds cells gives the
|
|
673
|
+
parent no mask. Owned by this window; NULL otherwise. */
|
|
674
|
+
CArray *mask_standin;
|
|
675
|
+
/* On the mask of a window: the window whose mask it is, which holds the
|
|
676
|
+
stand-in and the parent whose mask replaces it. NULL otherwise. */
|
|
677
|
+
CArray *mask_owner;
|
|
640
678
|
} CAWindow; /* 56 + 16*(ndim) + 1*(bytes) + 1*ndim + 24*ndim (bytes) */
|
|
641
679
|
|
|
642
680
|
/* CAShift is a pure typedef of CAWindow. CAShift construction maps (shift[], roll[], fill,
|
|
@@ -681,17 +719,17 @@ typedef struct {
|
|
|
681
719
|
dim[k] = parent->dim[k] * reps[k]. */
|
|
682
720
|
} CATile; /* 56 + 8*(ndim) (bytes) */
|
|
683
721
|
|
|
684
|
-
typedef CATile CARoll; /*
|
|
685
|
-
|
|
686
|
-
is just CATile (= typedef body identical). */
|
|
722
|
+
typedef CATile CARoll; /* same layout as CATile, its own obj_type
|
|
723
|
+
CA_OBJ_ROLL (ext/ca_obj_roll.c) */
|
|
687
724
|
|
|
688
|
-
/* CAStack:
|
|
689
|
-
|
|
725
|
+
/* CAStack: stack view of K uniform-shape parents. The K axis sits at
|
|
726
|
+
k_axis in the view's shape (0 by default: shape = (K, *parent_shape));
|
|
727
|
+
the other axes are the parents' own.
|
|
690
728
|
- parents stored as Ruby Array @parents on the wrapper object (= GC
|
|
691
729
|
anchor); C-side tail `parents[]` is alias pointer array.
|
|
692
730
|
- CAView.parent points to parents[0] (= legacy compat for paths that
|
|
693
731
|
deref ca->parent without CAStack awareness).
|
|
694
|
-
- dim[
|
|
732
|
+
- dim[k_axis] = n_parents; the other dims are parents[0]->dim in order. */
|
|
695
733
|
typedef struct {
|
|
696
734
|
int16_t obj_type;
|
|
697
735
|
int8_t data_type;
|
|
@@ -699,7 +737,7 @@ typedef struct {
|
|
|
699
737
|
int32_t flags;
|
|
700
738
|
ca_size_t bytes;
|
|
701
739
|
ca_size_t elements; /* = n_parents * parents[0]->elements */
|
|
702
|
-
ca_size_t *dim; /* ALLOC_N(ndim)
|
|
740
|
+
ca_size_t *dim; /* ALLOC_N(ndim): parent->dim with n_parents at k_axis */
|
|
703
741
|
char *ptr;
|
|
704
742
|
CArray *mask;
|
|
705
743
|
char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path).
|
|
@@ -731,8 +769,7 @@ typedef struct {
|
|
|
731
769
|
shape[meld_axis] = sum_k parents[k]->dim[meld_axis]
|
|
732
770
|
All other axes must match across parents (uniform check at constructor).
|
|
733
771
|
|
|
734
|
-
|
|
735
|
-
Other paths raise NotImplementedError. */
|
|
772
|
+
meld_axis may be any axis. */
|
|
736
773
|
typedef struct {
|
|
737
774
|
int16_t obj_type;
|
|
738
775
|
int8_t data_type;
|
|
@@ -869,8 +906,10 @@ extern const char * ca_type_name[CA_NTYPE];
|
|
|
869
906
|
extern const int ca_cast_table[CA_NTYPE][CA_NTYPE];
|
|
870
907
|
extern const int ca_cast_table2[CA_NTYPE][CA_NTYPE];
|
|
871
908
|
|
|
872
|
-
/* data_type promotion reducer
|
|
873
|
-
CArray.result_type and by the lazy view layer.
|
|
909
|
+
/* data_type promotion reducer over ca_cast_table. Used by
|
|
910
|
+
CArray.result_type and by the lazy view layer. Raises ArgumentError for
|
|
911
|
+
a code outside the data types, and CArray::DataTypeError for a pair with
|
|
912
|
+
no common type. See ext/carray_cast.c
|
|
874
913
|
for the definition; this is the single source of the promotion rule. */
|
|
875
914
|
int8_t ca_promote_type (int8_t a, int8_t b);
|
|
876
915
|
|
|
@@ -878,7 +917,8 @@ int8_t ca_promote_type (int8_t a, int8_t b);
|
|
|
878
917
|
Complex, etc.) — distinct from rb_ca_guess_type which interprets the
|
|
879
918
|
object as a data_type *representation* (e.g. T_FIXNUM as a data_type code).
|
|
880
919
|
Used by rb_ca_cast_self_or_other.
|
|
881
|
-
CArray
|
|
920
|
+
A CArray, like any object it does not recognise, answers CA_OBJECT;
|
|
921
|
+
callers holding a CArray use ca->data_type. */
|
|
882
922
|
int8_t ca_value_to_data_type (VALUE obj);
|
|
883
923
|
|
|
884
924
|
/* Infer a data_type code from a MemoryView producer by parsing its format,
|
|
@@ -930,8 +970,6 @@ extern const rb_data_type_t cabyteswap_data_type;
|
|
|
930
970
|
/* cafield_data_type was retired in 3.0 (Phase F: CAField is now a
|
|
931
971
|
CAStride subclass; use castride_data_type). */
|
|
932
972
|
extern const rb_data_type_t cagrid_data_type;
|
|
933
|
-
/* camapping_data_type was retired in 3.0 (R.3: CAMapping removed; a[mapper]
|
|
934
|
-
now builds a CAGrid/CAStride normalize chain). */
|
|
935
973
|
extern const rb_data_type_t caobject_data_type;
|
|
936
974
|
extern const rb_data_type_t careduce_data_type;
|
|
937
975
|
extern const rb_data_type_t carefer_data_type;
|
|
@@ -942,7 +980,6 @@ extern const rb_data_type_t cawindow_data_type;
|
|
|
942
980
|
extern const rb_data_type_t carray_mask_data_type;
|
|
943
981
|
extern const rb_data_type_t cablock_mask_data_type;
|
|
944
982
|
extern const rb_data_type_t cagrid_mask_data_type;
|
|
945
|
-
extern const rb_data_type_t camapping_mask_data_type;
|
|
946
983
|
extern const rb_data_type_t careduce_mask_data_type;
|
|
947
984
|
extern const rb_data_type_t carefer_mask_data_type;
|
|
948
985
|
extern const rb_data_type_t caselect_mask_data_type;
|
|
@@ -999,50 +1036,59 @@ extern VALUE rb_cCArrayObject;
|
|
|
999
1036
|
|
|
1000
1037
|
#define CA_CHECK_DATA_TYPE(data_type) \
|
|
1001
1038
|
do { \
|
|
1002
|
-
|
|
1003
|
-
|
|
1039
|
+
int ca_dt_ = (data_type); \
|
|
1040
|
+
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE ) { \
|
|
1041
|
+
rb_raise(rb_eArgError, "invalid data_type id %i", ca_dt_); \
|
|
1004
1042
|
} \
|
|
1005
|
-
if ( ! ca_valid[
|
|
1006
|
-
rb_raise(rb_eCADataTypeError, "data_type %s is disabled", ca_type_name[
|
|
1043
|
+
if ( ! ca_valid[ca_dt_] ) { \
|
|
1044
|
+
rb_raise(rb_eCADataTypeError, "data_type %s is disabled", ca_type_name[ca_dt_]); \
|
|
1007
1045
|
} \
|
|
1008
1046
|
} while (0)
|
|
1009
1047
|
|
|
1010
1048
|
#define CA_CHECK_DATA_TYPE_NUMERIC(data_type) \
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1049
|
+
do { \
|
|
1050
|
+
int ca_dt_ = (data_type); \
|
|
1051
|
+
if ( ca_dt_ <= CA_NONE || ca_dt_ >= CA_NTYPE || !ca_valid[ca_dt_] || \
|
|
1052
|
+
ca_dt_ == CA_FIXLEN || ca_dt_ == CA_OBJECT ) { \
|
|
1053
|
+
rb_raise(rb_eCADataTypeError, "invalid numeric data type"); \
|
|
1054
|
+
} \
|
|
1055
|
+
} while (0)
|
|
1014
1056
|
|
|
1015
1057
|
#define CA_CHECK_RANK(ndim) \
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1058
|
+
do { \
|
|
1059
|
+
if ( (ndim) <= 0 || (ndim) > CA_RANK_MAX ) { \
|
|
1060
|
+
rb_raise(rb_eArgError, "invalid ndim"); \
|
|
1061
|
+
} \
|
|
1062
|
+
} while (0)
|
|
1019
1063
|
|
|
1020
1064
|
#define CA_CHECK_DIM(ndim, dim) \
|
|
1021
|
-
{ \
|
|
1065
|
+
do { \
|
|
1022
1066
|
int8_t i_; \
|
|
1023
|
-
for (i_=0; i_<ndim; i_++) { \
|
|
1024
|
-
if ( dim[i_] < 0 ) { \
|
|
1067
|
+
for (i_=0; i_<(ndim); i_++) { \
|
|
1068
|
+
if ( (dim)[i_] < 0 ) { \
|
|
1025
1069
|
rb_raise(rb_eArgError, "negative size dimension at %i-dim", i_); \
|
|
1026
1070
|
} \
|
|
1027
1071
|
} \
|
|
1028
|
-
}
|
|
1072
|
+
} while (0)
|
|
1029
1073
|
|
|
1030
1074
|
/* A fixlen cell is at least one byte wide. A zero-width cell has one
|
|
1031
1075
|
possible value, and a strided view of it cannot say which cell is which:
|
|
1032
1076
|
its byte strides are all zero. */
|
|
1033
1077
|
#define CA_CHECK_BYTES(data_type, bytes) \
|
|
1034
|
-
|
|
1035
|
-
if (
|
|
1036
|
-
|
|
1037
|
-
|
|
1078
|
+
do { \
|
|
1079
|
+
if ( (data_type) == CA_FIXLEN ) { \
|
|
1080
|
+
if ( (bytes) <= 0 ) { \
|
|
1081
|
+
rb_raise(rb_eArgError, \
|
|
1082
|
+
"invalid bytes (a fixlen needs bytes: of 1 or more)"); \
|
|
1083
|
+
} \
|
|
1038
1084
|
} \
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1085
|
+
else { \
|
|
1086
|
+
(bytes) = ca_sizeof[(data_type)]; \
|
|
1087
|
+
if ( (bytes) <= 0 ) { \
|
|
1088
|
+
rb_raise(rb_eArgError, "invalid bytes"); \
|
|
1089
|
+
} \
|
|
1044
1090
|
} \
|
|
1045
|
-
}
|
|
1091
|
+
} while (0)
|
|
1046
1092
|
|
|
1047
1093
|
/* An index into `n` places, counted from the end when negative, outside of
|
|
1048
1094
|
which IndexError is raised naming the method the user called, `what` the
|
|
@@ -1108,6 +1154,10 @@ rb_carray_num2cmplx (VALUE num)
|
|
|
1108
1154
|
}
|
|
1109
1155
|
if ( rb_respond_to(num, rb_intern("to_c")) ) {
|
|
1110
1156
|
VALUE c = rb_funcall(num, rb_intern("to_c"), 0);
|
|
1157
|
+
if ( ! RB_TYPE_P(c, T_COMPLEX) ) {
|
|
1158
|
+
rb_raise(rb_eTypeError, "can't convert %"PRIsVALUE" to Complex (%"PRIsVALUE"#to_c gives %"PRIsVALUE")",
|
|
1159
|
+
rb_obj_class(num), rb_obj_class(num), rb_obj_class(c));
|
|
1160
|
+
}
|
|
1111
1161
|
return CMPLX(NUM2DBL(rb_complex_real(c)), NUM2DBL(rb_complex_imag(c)));
|
|
1112
1162
|
}
|
|
1113
1163
|
if ( rb_respond_to(num, rb_intern("to_f")) ) {
|
|
@@ -1184,8 +1234,7 @@ enum {
|
|
|
1184
1234
|
CA_IDX_SCALAR,
|
|
1185
1235
|
CA_IDX_ALL,
|
|
1186
1236
|
CA_IDX_BLOCK,
|
|
1187
|
-
CA_IDX_SYMBOL
|
|
1188
|
-
CA_IDX_REPEAT
|
|
1237
|
+
CA_IDX_SYMBOL
|
|
1189
1238
|
}; /* CA_INDEX_TYPE */
|
|
1190
1239
|
|
|
1191
1240
|
typedef union {
|
|
@@ -1254,14 +1303,14 @@ VALUE rb_carray_new_safe (int8_t data_type,
|
|
|
1254
1303
|
already hold a freshly decoded buffer and want to avoid a copy. The
|
|
1255
1304
|
buffer must be ruby_xmalloc()'d and at least elements*bytes long; it
|
|
1256
1305
|
is freed with xfree() when the array is collected. data_type must not
|
|
1257
|
-
be CA_OBJECT.
|
|
1306
|
+
be CA_OBJECT. When the call raises (a bad argument), the buffer stays
|
|
1307
|
+
the caller's. */
|
|
1258
1308
|
CArray *carray_new_adopt (int8_t data_type,
|
|
1259
1309
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, char *ptr);
|
|
1260
1310
|
VALUE rb_carray_new_adopt (int8_t data_type,
|
|
1261
1311
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, char *ptr);
|
|
1262
1312
|
|
|
1263
|
-
/*
|
|
1264
|
-
a reduction-output CArray for kernel_iterator authors. Computes
|
|
1313
|
+
/* Allocate a reduction-output CArray for kernel_iterator authors. Computes
|
|
1265
1314
|
output shape = self.dim with slab axes removed (ascending order),
|
|
1266
1315
|
collapses to shape [1] when fully reduced. See
|
|
1267
1316
|
ext/carray_core.c for docstring + semantics. */
|
|
@@ -1272,10 +1321,10 @@ VALUE rb_ca_new_reduced (VALUE self, int8_t *slab_axes,
|
|
|
1272
1321
|
VALUE rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
1273
1322
|
int32_t data_type, ca_size_t bytes, int keep_axis);
|
|
1274
1323
|
|
|
1275
|
-
/*
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1324
|
+
/* Parse variadic axis argv into a validated int8_t array. Accepts Integer
|
|
1325
|
+
args or a single Array arg (no argument = every axis), counts negative
|
|
1326
|
+
axes from the end, and raises ArgumentError for an axis out of range or
|
|
1327
|
+
given twice.
|
|
1279
1328
|
Returns the validated naxes. */
|
|
1280
1329
|
int8_t rb_ca_parse_reduce_axes (int argc, VALUE *argv,
|
|
1281
1330
|
CArray *ca, int8_t *out_axes);
|
|
@@ -1321,7 +1370,11 @@ VALUE rb_ca_farray (VALUE self);
|
|
|
1321
1370
|
|
|
1322
1371
|
/* --- ca_obj_stride.c --- */
|
|
1323
1372
|
|
|
1324
|
-
/*
|
|
1373
|
+
/* The strides and base_offset are taken as given: they are not checked
|
|
1374
|
+
against the parent's extent, so a view that reaches outside it reads
|
|
1375
|
+
and writes outside it.
|
|
1376
|
+
|
|
1377
|
+
ca_stride_setup with ca == NULL runs its checks and returns 0 without
|
|
1325
1378
|
writing. ca_stride_new calls it that way before it allocates, so a
|
|
1326
1379
|
rejected argument leaves no struct behind; a subclass constructor can
|
|
1327
1380
|
do the same through its own setup function. */
|
|
@@ -1394,8 +1447,16 @@ void ca_broadcast_pair (volatile VALUE *self, volatile VALUE *other);
|
|
|
1394
1447
|
ca_install_obj_type(klass, &td, mask_klass, &mask_td,
|
|
1395
1448
|
&my_func, sizeof(my_func));
|
|
1396
1449
|
|
|
1450
|
+
The table must reach at least through xfer_all: xfer_index, xfer_addrs
|
|
1451
|
+
and xfer_all have no default. fold_stride may be NULL (the view is a
|
|
1452
|
+
fold boundary); xfer_stride, the pool slots, fill_addrs and fill_stride
|
|
1453
|
+
fall back to a default when NULL. A shorter table raises RuntimeError.
|
|
1397
1454
|
A func_size larger than this build's struct means the caller was compiled
|
|
1398
|
-
against a newer carray; that is reported rather than truncated.
|
|
1455
|
+
against a newer carray; that is reported rather than truncated.
|
|
1456
|
+
|
|
1457
|
+
The obj_type parameters of ca_array_alloc, ca_array_pool_alloc,
|
|
1458
|
+
ca_stride_setup and ca_stride_new are int8_t, so an obj_type is numbered
|
|
1459
|
+
below 128: an install that would number one at 128 or above raises. */
|
|
1399
1460
|
|
|
1400
1461
|
int
|
|
1401
1462
|
ca_install_obj_type (VALUE klass,
|
|
@@ -1462,19 +1523,24 @@ int ca_is_mask_array (void *ap);
|
|
|
1462
1523
|
#define GetCArray(obj, ca) \
|
|
1463
1524
|
TypedData_Get_Struct((obj), CArray, &carray_data_type, (ca))
|
|
1464
1525
|
|
|
1465
|
-
/* True
|
|
1466
|
-
|
|
1467
|
-
strides are row-major contiguous
|
|
1468
|
-
|
|
1469
|
-
by
|
|
1470
|
-
|
|
1526
|
+
/* True when ca_attach(ca) gives ca->ptr the cells in place, without
|
|
1527
|
+
materialising: entity arrays, CAWrap, CScalar, and CAStride-family
|
|
1528
|
+
views whose composed strides are row-major contiguous over an attached
|
|
1529
|
+
root (alias-attach path). It is not the same as "attach is O(1)": a
|
|
1530
|
+
Face attaches in O(1) by borrowing its parent and answers false, and a
|
|
1531
|
+
CASource entity that publishes its ptr only while attached answers
|
|
1532
|
+
true. Used by the kernel iterator's alias decision, the sweep engine,
|
|
1533
|
+
and the views and mask paths that skip a sync when nothing was copied. */
|
|
1471
1534
|
int ca_attach_is_alias (void *ap);
|
|
1472
1535
|
|
|
1473
1536
|
/* OR operand masks into
|
|
1474
1537
|
ca_out->mask without ca_attach on operand masks (= gathers via
|
|
1475
|
-
ca_xfer_all into arena scratch then byte OR-folds). ca_out
|
|
1476
|
-
|
|
1477
|
-
|
|
1538
|
+
ca_xfer_all into arena scratch then byte OR-folds). ca_out's mask is
|
|
1539
|
+
written through its ptr, so ca_out is an entity or an attached view.
|
|
1540
|
+
Each operand other than a scalar has ca_out's number of elements
|
|
1541
|
+
(ArgumentError otherwise); n is at most 8. For bang variant where
|
|
1542
|
+
ca_out IS one of the operands, the existing mask is preserved as
|
|
1543
|
+
initial accumulator. */
|
|
1478
1544
|
void ca_mask_overlay_safe (CArray *ca_out, int n, ...);
|
|
1479
1545
|
|
|
1480
1546
|
#define ca_is_caobject(ca) ( (ca)->obj_type == CA_OBJ_OBJECT )
|
|
@@ -1524,20 +1590,30 @@ int ca_is_valid_index (void *ap, ca_size_t *idx);
|
|
|
1524
1590
|
internally (views carry an attach refcount; entities do
|
|
1525
1591
|
not).
|
|
1526
1592
|
R5 (traffic) Attach hands you a buffer, not a live array. Use x->ptr;
|
|
1527
|
-
a view derived from x
|
|
1528
|
-
root
|
|
1593
|
+
a view derived from x may read past the buffer to the
|
|
1594
|
+
root (a CAStride-family view over a CAStride-family x
|
|
1595
|
+
does) or read the buffer (others), so writes to the
|
|
1596
|
+
buffer are not seen through derived views until x is
|
|
1597
|
+
synced.
|
|
1529
1598
|
R6 (raising) ca_allocate and ca_attach that raise have taken
|
|
1530
1599
|
nothing; ca_allocate_n and ca_attach_n take all of
|
|
1531
1600
|
their arrays or none. Close a window with
|
|
1532
1601
|
ca_sync_detach, which detaches even when the sync
|
|
1533
1602
|
raises -- ca_sync then ca_detach leaves the window open
|
|
1534
|
-
on a raise.
|
|
1603
|
+
on a raise. ca_sync_detach syncs, so it raises on a
|
|
1604
|
+
read-only array; a window that only read closes with
|
|
1605
|
+
ca_detach. Anything between that can raise (Ruby
|
|
1535
1606
|
called from inside the window) needs an ensure of its
|
|
1536
1607
|
own.
|
|
1537
1608
|
*/
|
|
1538
1609
|
|
|
1610
|
+
/* ca_allocate opens a window for writing every cell: what the cells held
|
|
1611
|
+
before is not kept, also when the array is already attached (object cells
|
|
1612
|
+
are reset to 0 and the mask is cleared). */
|
|
1539
1613
|
void ca_allocate (void *ap);
|
|
1540
1614
|
void ca_attach (void *ca);
|
|
1615
|
+
/* Re-gather an attached view's buffer from its parent (one level: a parent
|
|
1616
|
+
that holds its own buffer is read as it is). */
|
|
1541
1617
|
void ca_update (void *ca);
|
|
1542
1618
|
void ca_sync (void *ca);
|
|
1543
1619
|
void ca_detach (void *ca);
|
|
@@ -1549,17 +1625,70 @@ void ca_update_n (int n, ...);
|
|
|
1549
1625
|
void ca_sync_n (int n, ...);
|
|
1550
1626
|
void ca_detach_n (int n, ...);
|
|
1551
1627
|
|
|
1628
|
+
/* API : lending the addresses of cells
|
|
1629
|
+
|
|
1630
|
+
A kernel that reads cells by address itself -- a stencil reading
|
|
1631
|
+
a[i-1][j] and a[i+1][j] from its own loop -- needs, for each array, a
|
|
1632
|
+
pointer to cell (0, ..., 0) and the byte distance between neighbours
|
|
1633
|
+
along each axis. ca_with_address_bases lends that for the duration of
|
|
1634
|
+
`body`, whatever the arrays are, and puts back what the kernel wrote:
|
|
1635
|
+
|
|
1636
|
+
- an entity, or a view the engine can fold down to one (a slice, a
|
|
1637
|
+
transpose, a reshape), is addressed in place;
|
|
1638
|
+
- any other view (a selection, a conversion, a lazy expression) has
|
|
1639
|
+
the cells the kernel touches copied into a buffer, which is lent
|
|
1640
|
+
instead and, for a writable array, sent back afterwards: only the
|
|
1641
|
+
cells the kernel changed, through the view.
|
|
1642
|
+
|
|
1643
|
+
`box_start[i]` / `box_count[i]` (ndim values each) say which cells
|
|
1644
|
+
array i's kernel touches -- its loop range, widened by how far the
|
|
1645
|
+
kernel reaches (one cell each way for a[i-1] .. a[i+1]). They decide
|
|
1646
|
+
what the second case copies; the first case lends the whole array
|
|
1647
|
+
either way. Pass NULL for `box_start` and `box_count` (or for an
|
|
1648
|
+
entry of them) to lend the whole array. A box outside the array is
|
|
1649
|
+
refused. Address only the box, whichever way the array was lent.
|
|
1650
|
+
|
|
1651
|
+
`writable[i]` says whether the kernel writes array i (NULL: none is
|
|
1652
|
+
written); a read-only array is refused for writing. An object array
|
|
1653
|
+
is refused (its cells are Ruby values, not numbers), and so is a view
|
|
1654
|
+
with a mask that reinterprets the element size (its mask cells do not
|
|
1655
|
+
map one to one onto the parent's).
|
|
1656
|
+
|
|
1657
|
+
A masked array also lends its mask: one boolean8_t per cell (nonzero =
|
|
1658
|
+
masked), addressed with mask_strides the same way. A write to the
|
|
1659
|
+
mask is put back like a write to a cell. `mask` is NULL for an array
|
|
1660
|
+
with no mask.
|
|
1661
|
+
|
|
1662
|
+
`body` may raise: the arrays are still written back and closed.
|
|
1663
|
+
Returns what `body` returns. The CArray pointers must stay alive for
|
|
1664
|
+
the call (keep the VALUEs they came from). */
|
|
1665
|
+
typedef struct {
|
|
1666
|
+
char *ptr; /* cell (0, ..., 0) */
|
|
1667
|
+
ca_size_t strides[CA_RANK_MAX]; /* byte step along each axis */
|
|
1668
|
+
boolean8_t *mask; /* NULL when no mask */
|
|
1669
|
+
ca_size_t mask_strides[CA_RANK_MAX]; /* byte step in the mask */
|
|
1670
|
+
int writable;
|
|
1671
|
+
} ca_address_basis_t;
|
|
1672
|
+
|
|
1673
|
+
VALUE ca_with_address_bases (int32_t n, CArray **arrays, const int *writable,
|
|
1674
|
+
const ca_size_t *const *box_start,
|
|
1675
|
+
const ca_size_t *const *box_count,
|
|
1676
|
+
VALUE (*body)(ca_address_basis_t *bases,
|
|
1677
|
+
VALUE arg),
|
|
1678
|
+
VALUE arg);
|
|
1679
|
+
|
|
1552
1680
|
/* API : copying */
|
|
1553
1681
|
|
|
1554
1682
|
void *ca_clone (void *ap); /* use rb_obj_clone() */
|
|
1683
|
+
/* A CA_OBJECT copy holds VALUEs the GC does not see until the struct is
|
|
1684
|
+
wrapped, and wrapping allocates: for an object array use rb_ca_copy, which
|
|
1685
|
+
keeps them alive and returns the wrapped copy. */
|
|
1555
1686
|
CArray *ca_copy (void *ap); /* use rb_ca_copy() */
|
|
1556
1687
|
CArray *ca_template (void *ap); /* use rb_ca_template() */
|
|
1557
1688
|
CArray *ca_template_safe (void *ap); /* use rb_ca_template() */
|
|
1558
1689
|
CArray *ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes);
|
|
1559
1690
|
/* use rb_ca_template() */
|
|
1560
1691
|
|
|
1561
|
-
/* ca_paste / ca_clip / ca_cut (sub-region copy in/out) removed in 3.0; see
|
|
1562
|
-
lib/extras/crop_paste.rb for the Ruby thin wrapper replacements. */
|
|
1563
1692
|
void ca_fill (void *ap, void *ptr);
|
|
1564
1693
|
|
|
1565
1694
|
/* API : fetch, store */
|
|
@@ -1580,9 +1709,10 @@ void ca_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *data, int
|
|
|
1580
1709
|
opportunistic engine dispatch. */
|
|
1581
1710
|
int ca_xfer_addrs_is_sequential_run (ca_size_t n, ca_size_t *addrs,
|
|
1582
1711
|
ca_size_t *base_out);
|
|
1583
|
-
/*
|
|
1712
|
+
/* Resolve cand through identity CAStride compose-fold to find an
|
|
1584
1713
|
attached root. Returns cand if cand->ptr is set, cand is not CAStride
|
|
1585
|
-
family, or no identity compose-fold path exists
|
|
1714
|
+
family, or no identity compose-fold path exists (the cells differ from
|
|
1715
|
+
the root's in data type, width or position); otherwise returns the
|
|
1586
1716
|
resolved root (which has ptr). Used by view xfer_addrs slots to lift
|
|
1587
1717
|
parent->ptr gate through view CAStride layers (= chain pattern). */
|
|
1588
1718
|
CArray *ca_resolve_attached_root_via_identity (CArray *cand);
|
|
@@ -1658,6 +1788,8 @@ void ca_fill_stride_whole (void *ap, void *ptr);
|
|
|
1658
1788
|
extern VALUE CA_UNDEF;
|
|
1659
1789
|
extern VALUE CA_UNSPECIFIED;
|
|
1660
1790
|
|
|
1791
|
+
/* The mask's buffer, which a view's mask has only while attached: NULL
|
|
1792
|
+
otherwise. */
|
|
1661
1793
|
boolean8_t *ca_mask_ptr (void *ap);
|
|
1662
1794
|
int ca_has_mask (void *ap);
|
|
1663
1795
|
int ca_is_any_masked (void *ap);
|
|
@@ -1674,7 +1806,7 @@ void ca_copy_mask_overwrite (void *ap, ca_size_t elements, int n, ...);
|
|
|
1674
1806
|
ca_size_t ca_count_masked (void *ap);
|
|
1675
1807
|
ca_size_t ca_count_not_masked (void *ap);
|
|
1676
1808
|
void ca_unmask (void *ap, char *fill_value);
|
|
1677
|
-
CArray *
|
|
1809
|
+
CArray *ca_unmask_copy (void *ap, char *fill_value);
|
|
1678
1810
|
|
|
1679
1811
|
/* API : cast, conversion */
|
|
1680
1812
|
|
|
@@ -1688,7 +1820,7 @@ void ca_ptr2val (void *ap1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
|
1688
1820
|
void ca_val2ptr (int8_t data_type1, void *ptr1, void *ap2, void *ptr2);
|
|
1689
1821
|
void ca_val2val (int8_t data_type1, void *ptr1, int8_t data_type2, void *ptr2);
|
|
1690
1822
|
VALUE ca_ptr2obj (void *ap, void *ptr); /* use rb_ca_ptr2obj() */
|
|
1691
|
-
void ca_obj2ptr (void *ap, VALUE obj, void *ptr); /* use
|
|
1823
|
+
void ca_obj2ptr (void *ap, VALUE obj, void *ptr); /* use rb_ca_obj2ptr() */
|
|
1692
1824
|
|
|
1693
1825
|
#define ca_wrap_writable(obj, data_type) \
|
|
1694
1826
|
(obj = rb_ca_wrap_writable(obj, INT2NUM(data_type)), (CArray*) DATA_PTR(obj))
|
|
@@ -1738,6 +1870,8 @@ void rb_check_carray_object (VALUE arg);
|
|
|
1738
1870
|
|
|
1739
1871
|
/* specific Data_Wrap_Struct for carray */
|
|
1740
1872
|
VALUE ca_wrap_struct (void *ap);
|
|
1873
|
+
/* As ca_wrap_struct, under the class klass. klass is not checked: it must
|
|
1874
|
+
be a CArray class whose instances share ap's TypedData. */
|
|
1741
1875
|
VALUE ca_wrap_struct_as (void *ap, VALUE klass);
|
|
1742
1876
|
|
|
1743
1877
|
/* query data_type */
|
|
@@ -1746,7 +1880,8 @@ void rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
|
1746
1880
|
int8_t *data_type, ca_size_t *bytes);
|
|
1747
1881
|
int rb_ca_is_type (VALUE arg, int type);
|
|
1748
1882
|
|
|
1749
|
-
/* scan index
|
|
1883
|
+
/* scan index. info->range_check is read, not written: set it (1 to check
|
|
1884
|
+
each index against ca_dim) before the call. */
|
|
1750
1885
|
void rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t elements,
|
|
1751
1886
|
long argc, VALUE *argv, CAIndexInfo *info);
|
|
1752
1887
|
|
|
@@ -1853,9 +1988,13 @@ VALUE rb_ca_fill_copy (VALUE self, VALUE val);
|
|
|
1853
1988
|
/* address calculation */
|
|
1854
1989
|
VALUE rb_ca_addr2index (VALUE self, VALUE raddr);
|
|
1855
1990
|
|
|
1856
|
-
/*
|
|
1991
|
+
/* A cell's bytes (self's data type, self->bytes wide) as the value ca[i]
|
|
1992
|
+
gives for that cell: true or false for a boolean, the element for a
|
|
1993
|
+
Face, a record for a struct. The mask is not consulted. */
|
|
1857
1994
|
VALUE rb_ca_ptr2obj (VALUE self, void *ptr);
|
|
1858
1995
|
#define rb_ca_fetch_ptr(self, ptr) rb_ca_ptr2obj(self, ptr)
|
|
1996
|
+
|
|
1997
|
+
/* elemental access like ca[i,j,k] or ca[addr] */
|
|
1859
1998
|
VALUE rb_ca_fetch_index (VALUE self, ca_size_t *idx);
|
|
1860
1999
|
VALUE rb_ca_fetch_addr (VALUE self, ca_size_t addr);
|
|
1861
2000
|
VALUE rb_ca_fetch (VALUE self, VALUE index);
|