carray 3.0.6 → 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 -1830
- data/README.md +62 -35
- 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 +12 -15
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +35 -0
- data/ext/ca_binop_dispatch.h +22 -46
- 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 -1504
- 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 +92 -165
- data/ext/ca_obj_bincmp.c +65 -48
- data/ext/ca_obj_binop.c +74 -49
- data/ext/ca_obj_bitarray.c +7 -21
- data/ext/ca_obj_bitfield.c +93 -26
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +34 -34
- data/ext/ca_obj_const_string.c +464 -304
- data/ext/ca_obj_face.c +167 -121
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +127 -34
- data/ext/ca_obj_farray.c +13 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +57 -34
- data/ext/ca_obj_grid.c +149 -113
- data/ext/ca_obj_meld.c +28 -26
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +88 -73
- data/ext/ca_obj_object.c +60 -46
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +10 -14
- data/ext/ca_obj_refer.c +146 -39
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +20 -28
- data/ext/ca_obj_select.c +17 -27
- data/ext/ca_obj_select_axis.c +35 -42
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +33 -29
- data/ext/ca_obj_stride.c +99 -62
- data/ext/ca_obj_string.c +8 -20
- data/ext/ca_obj_tile.c +14 -16
- 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 +48 -49
- data/ext/ca_obj_window.c +87 -99
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +97 -27
- data/ext/ca_op_powi.h +9 -28
- 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 +23 -26
- data/ext/ca_sweep_engine.c +92 -26
- data/ext/ca_sweep_engine.h +22 -15
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +12 -12
- data/ext/carray.h +300 -1009
- data/ext/carray_access.c +320 -207
- data/ext/carray_address_basis.c +128 -59
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +31 -27
- data/ext/carray_call_cfunc.c +174 -285
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +1191 -351
- data/ext/carray_cast_func.rb +68 -8
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +98 -39
- data/ext/carray_copy.c +52 -26
- data/ext/carray_core.c +286 -132
- data/ext/carray_count.c +53 -22
- data/ext/carray_element.c +49 -28
- data/ext/carray_factorize.c +64 -63
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +9 -11
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +127 -230
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1364 -156
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +37 -37
- data/ext/carray_loop.c +27 -23
- data/ext/carray_mask.c +235 -150
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +106 -100
- data/ext/carray_memory_view.c +83 -69
- data/ext/carray_operator.c +490 -128
- data/ext/carray_order.c +163 -84
- data/ext/carray_partition.c +14 -16
- data/ext/carray_random.c +48 -42
- data/ext/carray_round.c +33 -5
- data/ext/carray_scatter.c +57 -39
- data/ext/carray_segment.c +42 -46
- data/ext/carray_slab.c +77 -51
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +37 -31
- data/ext/carray_sort_kernel.c +36 -10
- data/ext/carray_struct.c +44 -34
- data/ext/carray_test.c +131 -81
- data/ext/carray_time_text.c +30 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +373 -139
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +25 -31
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +819 -488
- 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 +272 -185
- data/lib/carray/basics.rb +298 -56
- data/lib/carray/bincount_nd.rb +41 -18
- data/lib/carray/block_iterator.rb +167 -119
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +84 -59
- data/lib/carray/categorical_iterator.rb +90 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +98 -23
- data/lib/carray/const_string.rb +112 -46
- data/lib/carray/core_extensions.rb +20 -69
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +95 -12
- data/lib/carray/frame/column_verbs.rb +76 -9
- data/lib/carray/frame/concat.rb +51 -7
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +20 -5
- data/lib/carray/frame/frame.rb +73 -31
- data/lib/carray/frame/group.rb +247 -187
- data/lib/carray/frame/io.rb +36 -12
- data/lib/carray/frame/join.rb +56 -17
- data/lib/carray/frame/records.rb +7 -5
- data/lib/carray/frame/reshape.rb +27 -7
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +217 -134
- data/lib/carray/frame/windows.rb +254 -19
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +28 -23
- 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 +104 -23
- data/lib/carray/key_windows.rb +93 -61
- data/lib/carray/lazy.rb +208 -111
- 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 +8 -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 +73 -72
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +106 -103
- 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 +183 -143
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +157 -94
- 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 +23 -13
- 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 +50 -20
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +195 -17
- data/lib/carray/segment_iterator.rb +262 -137
- data/lib/carray/serialize.rb +635 -566
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +14 -15
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +97 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +247 -73
- data/lib/carray/time.rb +663 -365
- data/lib/carray/window_iterator.rb +232 -155
- 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 +6 -2
- 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 +10 -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 +28 -16
- data/yard-stubs/carray_access.rb +55 -6
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +121 -162
- 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 +10 -5
- 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 +162 -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 +72 -33
- 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 +12 -3
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_test.rb +18 -5
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +63 -25
- 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 -25387
- 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 -261
- data/lib/carray/data_type_limits.rb +0 -91
data/ext/ca_op_ipower.c
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/* ---------------------------------------------------------------------------
|
|
2
2
|
|
|
3
|
-
Float/Complex ** Integer
|
|
4
|
-
|
|
3
|
+
Float/Complex ** Integer: the exponent stays an int64 (no cast of the
|
|
4
|
+
array to a wider type), and each cell is computed exactly as `a ** b`
|
|
5
|
+
computes it when b is an array of that integer: the exponents -2 .. 4
|
|
6
|
+
by at most two multiplications or divisions, the rest by pow / powf /
|
|
7
|
+
cpow.
|
|
5
8
|
|
|
6
9
|
Contents:
|
|
7
10
|
(1) LAZY kernel table `ca_binop_ipower[CA_NTYPE]` — CABinOp dispatch
|
|
@@ -11,14 +14,59 @@
|
|
|
11
14
|
`rb_ca_pow{,_bang}` dispatch between ipower (Float/Complex **
|
|
12
15
|
Integer) and mkkernel-generated `rb_ca_power` (general pow).
|
|
13
16
|
|
|
14
|
-
Both paths share `
|
|
15
|
-
|
|
17
|
+
Both paths share `ca_ipow_<type>` below. The exponent is converted
|
|
18
|
+
the way an int64 cell is converted to the base's type (through double
|
|
19
|
+
for float32 / cmplx64), so the answer is the one the general power
|
|
20
|
+
kernel gives for the same exponent held in an array.
|
|
16
21
|
|
|
17
22
|
---------------------------------------------------------------------------- */
|
|
18
23
|
|
|
19
24
|
#include "carray.h"
|
|
20
25
|
#include "ca_binop_dispatch.h"
|
|
21
|
-
#include
|
|
26
|
+
#include <math.h>
|
|
27
|
+
#include <complex.h>
|
|
28
|
+
|
|
29
|
+
/* The exponents -2 .. 4 take at most two roundings, as in the power
|
|
30
|
+
kernel (MkKernel.pow_short). */
|
|
31
|
+
#define CA_IPOW_SHORT(x, p) do { \
|
|
32
|
+
switch ( p ) { \
|
|
33
|
+
case 2: return (x) * (x); \
|
|
34
|
+
case 3: return (x) * (x) * (x); \
|
|
35
|
+
case 4: return ((x) * (x)) * ((x) * (x)); \
|
|
36
|
+
case 1: return (x); \
|
|
37
|
+
case 0: return 1; \
|
|
38
|
+
case -1: return 1 / (x); \
|
|
39
|
+
case -2: return 1 / ((x) * (x)); \
|
|
40
|
+
} \
|
|
41
|
+
} while (0)
|
|
42
|
+
|
|
43
|
+
static inline float32_t
|
|
44
|
+
ca_ipow_float32_t (float32_t x, int64_t p)
|
|
45
|
+
{
|
|
46
|
+
CA_IPOW_SHORT(x, p);
|
|
47
|
+
return powf(x, (float) (double) p);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static inline float64_t
|
|
51
|
+
ca_ipow_float64_t (float64_t x, int64_t p)
|
|
52
|
+
{
|
|
53
|
+
CA_IPOW_SHORT(x, p);
|
|
54
|
+
return pow(x, (double) p);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static inline cmplx64_t
|
|
58
|
+
ca_ipow_cmplx64_t (cmplx64_t x, int64_t p)
|
|
59
|
+
{
|
|
60
|
+
CA_IPOW_SHORT(x, p);
|
|
61
|
+
return cpow(x, (float) (double) p);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static inline cmplx128_t
|
|
65
|
+
ca_ipow_cmplx128_t (cmplx128_t x, int64_t p)
|
|
66
|
+
{
|
|
67
|
+
CA_IPOW_SHORT(x, p);
|
|
68
|
+
return cpow(x, (double) p);
|
|
69
|
+
}
|
|
22
70
|
|
|
23
71
|
/* Defined in ext/carray_kernels.c (mkkernel-generated general pow /
|
|
24
72
|
cpow binop). Called by rb_ca_pow{,_bang} when the fast path does
|
|
@@ -71,7 +119,7 @@ ca_binop_ipower_##T (ca_size_t n, boolean8_t *m, \
|
|
|
71
119
|
p1 = q1 + k*i1; \
|
|
72
120
|
p2 = q2 + k*i2; \
|
|
73
121
|
p3 = q3 + k*i3; \
|
|
74
|
-
*p3 =
|
|
122
|
+
*p3 = ca_ipow_##T(*p1, *p2); \
|
|
75
123
|
} \
|
|
76
124
|
} \
|
|
77
125
|
} else { \
|
|
@@ -79,7 +127,7 @@ ca_binop_ipower_##T (ca_size_t n, boolean8_t *m, \
|
|
|
79
127
|
p1 = q1 + k*i1; \
|
|
80
128
|
p2 = q2 + k*i2; \
|
|
81
129
|
p3 = q3 + k*i3; \
|
|
82
|
-
*p3 =
|
|
130
|
+
*p3 = ca_ipow_##T(*p1, *p2); \
|
|
83
131
|
} \
|
|
84
132
|
} \
|
|
85
133
|
}
|
|
@@ -115,12 +163,12 @@ ca_ipower_float32_t (ca_size_t n, boolean8_t *m,
|
|
|
115
163
|
ca_u_float32_t *p1 = (ca_u_float32_t *) ptr1, *p2 = (ca_u_float32_t *) ptr2;
|
|
116
164
|
if ( m ) {
|
|
117
165
|
while (n--) {
|
|
118
|
-
if ( ! *m++ ) { *p2 =
|
|
166
|
+
if ( ! *m++ ) { *p2 = ca_ipow_float32_t(*p1, ipow); }
|
|
119
167
|
p1++; p2++;
|
|
120
168
|
}
|
|
121
169
|
}
|
|
122
170
|
else
|
|
123
|
-
while (n--) { (*p2) =
|
|
171
|
+
while (n--) { (*p2) = ca_ipow_float32_t(*p1, ipow); p1++; p2++; }
|
|
124
172
|
}
|
|
125
173
|
|
|
126
174
|
static void
|
|
@@ -130,12 +178,12 @@ ca_ipower_float64_t (ca_size_t n, boolean8_t *m,
|
|
|
130
178
|
ca_u_float64_t *p1 = (ca_u_float64_t *) ptr1, *p2 = (ca_u_float64_t *) ptr2;
|
|
131
179
|
if ( m ) {
|
|
132
180
|
while (n--) {
|
|
133
|
-
if ( ! *m++ ) { *p2 =
|
|
181
|
+
if ( ! *m++ ) { *p2 = ca_ipow_float64_t(*p1, ipow); }
|
|
134
182
|
p1++; p2++;
|
|
135
183
|
}
|
|
136
184
|
}
|
|
137
185
|
else
|
|
138
|
-
while (n--) { (*p2) =
|
|
186
|
+
while (n--) { (*p2) = ca_ipow_float64_t(*p1, ipow); p1++; p2++; }
|
|
139
187
|
}
|
|
140
188
|
|
|
141
189
|
static void
|
|
@@ -145,12 +193,12 @@ ca_ipower_cmplx64_t (ca_size_t n, boolean8_t *m,
|
|
|
145
193
|
ca_u_cmplx64_t *p1 = (ca_u_cmplx64_t *) ptr1, *p2 = (ca_u_cmplx64_t *) ptr2;
|
|
146
194
|
if ( m ) {
|
|
147
195
|
while (n--) {
|
|
148
|
-
if ( ! *m++ ) { *p2 =
|
|
196
|
+
if ( ! *m++ ) { *p2 = ca_ipow_cmplx64_t(*p1, ipow); }
|
|
149
197
|
p1++; p2++;
|
|
150
198
|
}
|
|
151
199
|
}
|
|
152
200
|
else
|
|
153
|
-
while (n--) { (*p2) =
|
|
201
|
+
while (n--) { (*p2) = ca_ipow_cmplx64_t(*p1, ipow); p1++; p2++; }
|
|
154
202
|
}
|
|
155
203
|
|
|
156
204
|
static void
|
|
@@ -160,16 +208,16 @@ ca_ipower_cmplx128_t (ca_size_t n, boolean8_t *m,
|
|
|
160
208
|
ca_u_cmplx128_t *p1 = (ca_u_cmplx128_t *) ptr1, *p2 = (ca_u_cmplx128_t *) ptr2;
|
|
161
209
|
if ( m ) {
|
|
162
210
|
while (n--) {
|
|
163
|
-
if ( ! *m++ ) { *p2 =
|
|
211
|
+
if ( ! *m++ ) { *p2 = ca_ipow_cmplx128_t(*p1, ipow); }
|
|
164
212
|
p1++; p2++;
|
|
165
213
|
}
|
|
166
214
|
}
|
|
167
215
|
else
|
|
168
|
-
while (n--) { (*p2) =
|
|
216
|
+
while (n--) { (*p2) = ca_ipow_cmplx128_t(*p1, ipow); p1++; p2++; }
|
|
169
217
|
}
|
|
170
218
|
|
|
171
|
-
/* The data types the ipower kernels cover; checked before
|
|
172
|
-
|
|
219
|
+
/* The data types the ipower kernels cover; checked before anything is
|
|
220
|
+
attached, so the switches inside cannot fall through to a raise. */
|
|
173
221
|
static int
|
|
174
222
|
ca_ipower_type_ok (CArray *ca)
|
|
175
223
|
{
|
|
@@ -191,7 +239,7 @@ ca_ipower_type_ok (CArray *ca)
|
|
|
191
239
|
* mask attach). Called by rb_ca_pow when the fast-path predicate
|
|
192
240
|
* matches. */
|
|
193
241
|
static VALUE
|
|
194
|
-
rb_ca_ipower (VALUE self, VALUE other)
|
|
242
|
+
rb_ca_ipower (volatile VALUE self, VALUE other)
|
|
195
243
|
{
|
|
196
244
|
volatile VALUE obj;
|
|
197
245
|
CArray *ca, *co;
|
|
@@ -200,7 +248,7 @@ rb_ca_ipower (VALUE self, VALUE other)
|
|
|
200
248
|
|
|
201
249
|
ipow = NUM2LL(other);
|
|
202
250
|
|
|
203
|
-
|
|
251
|
+
GetCArray(self, ca);
|
|
204
252
|
|
|
205
253
|
if ( ! ca_ipower_type_ok(ca) ) {
|
|
206
254
|
rb_raise(rb_eCADataTypeError, "invalid data type for ipower");
|
|
@@ -213,7 +261,7 @@ rb_ca_ipower (VALUE self, VALUE other)
|
|
|
213
261
|
m = ( co->mask ) ? (boolean8_t *)co->mask->ptr : NULL;
|
|
214
262
|
|
|
215
263
|
if ( ca_attach_is_alias(ca) ) {
|
|
216
|
-
ca_attach(ca); /*
|
|
264
|
+
ca_attach(ca); /* attach: nothing raises before the detach */
|
|
217
265
|
switch ( ca->data_type ) {
|
|
218
266
|
case CA_FLOAT32:
|
|
219
267
|
ca_ipower_float32_t(ca->elements, m, ca->ptr, ipow, co->ptr); break;
|
|
@@ -249,21 +297,23 @@ rb_ca_ipower (VALUE self, VALUE other)
|
|
|
249
297
|
}
|
|
250
298
|
|
|
251
299
|
static VALUE
|
|
252
|
-
rb_ca_ipower_bang (VALUE self, VALUE other)
|
|
300
|
+
rb_ca_ipower_bang (volatile VALUE self, VALUE other)
|
|
253
301
|
{
|
|
254
302
|
CArray *ca;
|
|
255
303
|
int64_t ipow;
|
|
256
304
|
boolean8_t *m;
|
|
257
305
|
|
|
306
|
+
rb_ca_modify(self);
|
|
307
|
+
|
|
258
308
|
ipow = NUM2LL(other);
|
|
259
309
|
|
|
260
|
-
|
|
310
|
+
GetCArray(self, ca);
|
|
261
311
|
|
|
262
312
|
if ( ! ca_ipower_type_ok(ca) ) {
|
|
263
313
|
rb_raise(rb_eRuntimeError, "invalid data type for ipower");
|
|
264
314
|
}
|
|
265
315
|
|
|
266
|
-
ca_attach(ca); /*
|
|
316
|
+
ca_attach(ca); /* attach: nothing raises before ca_sync_detach */
|
|
267
317
|
|
|
268
318
|
m = ( ca->mask ) ? (boolean8_t *)ca->mask->ptr : NULL;
|
|
269
319
|
|
|
@@ -283,16 +333,33 @@ rb_ca_ipower_bang (VALUE self, VALUE other)
|
|
|
283
333
|
return self;
|
|
284
334
|
}
|
|
285
335
|
|
|
336
|
+
/* An Integer exponent beyond int64 is taken as a Float: the power is then
|
|
337
|
+
* 0, 1, an infinity or NaN, as for the same exponent written as a Float.
|
|
338
|
+
* Within int64 it stays an Integer for the ipower kernels. */
|
|
339
|
+
static VALUE
|
|
340
|
+
ca_pow_wide_exponent (VALUE other)
|
|
341
|
+
{
|
|
342
|
+
if ( RB_TYPE_P(other, T_BIGNUM) &&
|
|
343
|
+
( RTEST(rb_funcall(other, rb_intern(">"), 1, LL2NUM(INT64_MAX))) ||
|
|
344
|
+
RTEST(rb_funcall(other, rb_intern("<"), 1, LL2NUM(INT64_MIN))) ) ) {
|
|
345
|
+
return DBL2NUM(rb_big2dbl(other));
|
|
346
|
+
}
|
|
347
|
+
return other;
|
|
348
|
+
}
|
|
349
|
+
|
|
286
350
|
/* CArray#pow(other) (alias `**`) — Float/Complex ** Integer takes the
|
|
287
351
|
* ipower fast path in this file; everything else falls through to the
|
|
288
352
|
* mkkernel-generated general pow/cpow (rb_ca_power in
|
|
289
353
|
* ext/carray_kernels.c). */
|
|
290
|
-
static VALUE rb_ca_pow (VALUE self, VALUE other)
|
|
354
|
+
static VALUE rb_ca_pow (volatile VALUE self, VALUE other)
|
|
291
355
|
{
|
|
292
356
|
volatile VALUE obj;
|
|
293
357
|
CArray *ca;
|
|
294
358
|
|
|
295
|
-
|
|
359
|
+
GetCArray(self, ca);
|
|
360
|
+
if ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) {
|
|
361
|
+
other = ca_pow_wide_exponent(other);
|
|
362
|
+
}
|
|
296
363
|
if ( ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) &&
|
|
297
364
|
rb_obj_is_kind_of(other, rb_cInteger) ) {
|
|
298
365
|
return rb_ca_ipower(self, other);
|
|
@@ -306,10 +373,13 @@ static VALUE rb_ca_pow (VALUE self, VALUE other)
|
|
|
306
373
|
/* CArray#pow!(other) — in-place variant of #pow. Dispatch mirrors
|
|
307
374
|
* rb_ca_pow (fast path for Float/Complex ** Integer, otherwise
|
|
308
375
|
* general rb_ca_power_bang). */
|
|
309
|
-
static VALUE rb_ca_pow_bang (VALUE self, VALUE other)
|
|
376
|
+
static VALUE rb_ca_pow_bang (volatile VALUE self, VALUE other)
|
|
310
377
|
{
|
|
311
378
|
CArray *ca;
|
|
312
|
-
|
|
379
|
+
GetCArray(self, ca);
|
|
380
|
+
if ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) {
|
|
381
|
+
other = ca_pow_wide_exponent(other);
|
|
382
|
+
}
|
|
313
383
|
if ( ( ca_is_float_type(ca) || ca_is_complex_type(ca) ) &&
|
|
314
384
|
rb_obj_is_kind_of(other, rb_cInteger) ) {
|
|
315
385
|
return rb_ca_ipower_bang(self, other);
|
data/ext/ca_op_powi.h
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
/* ---------------------------------------------------------------------------
|
|
2
2
|
|
|
3
|
-
ca_op_powi.h --
|
|
3
|
+
ca_op_powi.h -- `op_powi_<type>`, an integer to an integer power
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`op_powi_<type>` to compute integer exponentiation by binary
|
|
9
|
-
exponentiation (O(log p) vs pow's general path).
|
|
10
|
-
- ext/carray_math.c (hand-written, P.5b.5)
|
|
11
|
-
the `ipower` family (rb_ca_ipower, rb_ca_ipower_bang) uses
|
|
12
|
-
`op_powi_<type>` for the Float**Integer / Complex**Integer
|
|
13
|
-
fast path when invoked via CArray#pow with an Integer rhs.
|
|
5
|
+
This header is internal to carray and carries no contract. It is not
|
|
6
|
+
installed; it ships in the gem's ext/ directory only because carray is
|
|
7
|
+
built from it there.
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
The `power` binop kernel's integer variants (generated from
|
|
10
|
+
ext/mkkernel.rb) call `op_powi_<type>`, binary exponentiation in the
|
|
11
|
+
integer type. A float or complex base goes through pow / cpow
|
|
12
|
+
instead (ext/ca_op_ipower.c for an Integer exponent).
|
|
17
13
|
|
|
18
14
|
--------------------------------------------------------------------------- */
|
|
19
15
|
|
|
@@ -27,7 +23,7 @@
|
|
|
27
23
|
an evaluator that compiles a kernel body calling op_powi_<type>
|
|
28
24
|
(CArray.__kernel_helpers__, written into the build by mkkernel.rb). It
|
|
29
25
|
may use only <stdint.h>, float32_t / float64_t and ca_zerodiv: what such
|
|
30
|
-
an evaluator's C declares.
|
|
26
|
+
an evaluator's C declares. */
|
|
31
27
|
|
|
32
28
|
/* BEGIN kernel helpers */
|
|
33
29
|
|
|
@@ -85,17 +81,6 @@ op_powi_## type (type x, int64_t p) \
|
|
|
85
81
|
return op_powi_mag_## type(x, (uint64_t) p); \
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
#define op_powi_fc(type) \
|
|
89
|
-
op_powi_magnitude(type) \
|
|
90
|
-
static inline type \
|
|
91
|
-
op_powi_## type (type x, int64_t p) \
|
|
92
|
-
{ \
|
|
93
|
-
if ( p < 0 ) { \
|
|
94
|
-
return 1 / op_powi_mag_## type(x, (uint64_t) 0 - (uint64_t) p); \
|
|
95
|
-
} \
|
|
96
|
-
return op_powi_mag_## type(x, (uint64_t) p); \
|
|
97
|
-
}
|
|
98
|
-
|
|
99
84
|
op_powi(int8_t)
|
|
100
85
|
op_powi_u(uint8_t)
|
|
101
86
|
op_powi(int16_t)
|
|
@@ -104,12 +89,8 @@ op_powi(int32_t)
|
|
|
104
89
|
op_powi_u(uint32_t)
|
|
105
90
|
op_powi(int64_t)
|
|
106
91
|
op_powi_u(uint64_t)
|
|
107
|
-
op_powi_fc(float32_t)
|
|
108
|
-
op_powi_fc(float64_t)
|
|
109
92
|
|
|
110
93
|
/* END kernel helpers */
|
|
111
94
|
|
|
112
|
-
op_powi_fc(cmplx64_t)
|
|
113
|
-
op_powi_fc(cmplx128_t)
|
|
114
95
|
|
|
115
96
|
#endif /* CA_OP_POWI_H */
|
data/ext/ca_pow5_table.h
CHANGED
data/ext/ca_rng_normal.h
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
ca_rng_normal.h -- uniform to standard normal, as text
|
|
4
4
|
|
|
5
|
+
As a header this file is internal to carray and carries no contract; it
|
|
6
|
+
is not installed. Its text is handed out through
|
|
7
|
+
CArray::Rng::COMMON_SOURCE.
|
|
8
|
+
|
|
5
9
|
Read the two ways ca_rng_xoshiro256pp.h is read: compiled into this
|
|
6
10
|
extension, and handed out through CArray::Rng::COMMON_SOURCE for
|
|
7
11
|
another gem to paste. The same rules apply -- no include guard,
|
data/ext/ca_rng_xoshiro256pp.h
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
ca_rng_xoshiro256pp.h -- the xoshiro256++ generator, as text
|
|
4
4
|
|
|
5
|
+
As a header this file is internal to carray and carries no contract; it
|
|
6
|
+
is not installed. Its text is handed out through CArray::Rng::SOURCE.
|
|
7
|
+
|
|
5
8
|
This file is not a header in the usual sense. It carries no include
|
|
6
9
|
guard and includes nothing, because it is read two ways:
|
|
7
10
|
|
data/ext/ca_sort_kernels.h
CHANGED
|
@@ -2,38 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
ca_sort_kernels.h
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This header is internal to carray and carries no contract. It is not
|
|
6
|
+
installed, and carray.h does not include it: the sources that use it
|
|
7
|
+
(carray_sort_kernel.c, carray_sort.c, carray_partition.c,
|
|
8
|
+
ca_categorical_iterator.c and the generated carray_kernels_*.c)
|
|
9
|
+
include it themselves.
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
(i8 / u8 / i16 / u16 / i32 / u32 / i64 / u64 / f32 / f64)
|
|
9
|
-
P.3 : NaN pre-partition for f32 / f64
|
|
10
|
-
P.4 : pair (value + index) variants for argsort kernels —
|
|
11
|
-
sort_index / sort_addr / partition_index family
|
|
12
|
-
P.9 : value-level quickselect for partition_copy
|
|
11
|
+
Portable sort kernels:
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
typedefs from carray.h — when this header is included from carray.h
|
|
21
|
-
mid-file, those typedefs are already in scope by the time we reach
|
|
22
|
-
the include site.
|
|
13
|
+
- quicksort and mergesort over the 10 numeric data types
|
|
14
|
+
(i8 / u8 / i16 / u16 / i32 / u32 / i64 / u64 / f32 / f64)
|
|
15
|
+
- NaN pre-partition for f32 / f64
|
|
16
|
+
- pair (value + index) variants for the sort_index / sort_addr /
|
|
17
|
+
partition_index family
|
|
18
|
+
- value-level quickselect for partition_copy
|
|
23
19
|
|
|
24
20
|
--------------------------------------------------------------------------- */
|
|
25
21
|
|
|
26
22
|
#ifndef CA_SORT_KERNELS_H
|
|
27
23
|
#define CA_SORT_KERNELS_H 1
|
|
28
24
|
|
|
29
|
-
/* Needs int8_t .. uint64_t / float32_t / double / ca_size_t
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Guard-protected, so the re-entry is a no-op when carray.h is already in
|
|
33
|
-
flight. */
|
|
25
|
+
/* Needs int8_t .. uint64_t / float32_t / double / ca_size_t, so this
|
|
26
|
+
header includes carray.h itself. carray.h has an include guard, so the
|
|
27
|
+
include is a no-op when a source has already included it. */
|
|
34
28
|
#include "carray.h"
|
|
35
29
|
|
|
36
|
-
/*
|
|
30
|
+
/* Quicksort over 10 numeric data types. */
|
|
37
31
|
void ca_sort_quick_i8 (int8_t *a, ca_size_t n);
|
|
38
32
|
void ca_sort_quick_u8 (uint8_t *a, ca_size_t n);
|
|
39
33
|
void ca_sort_quick_i16 (int16_t *a, ca_size_t n);
|
|
@@ -45,7 +39,7 @@ void ca_sort_quick_u64 (uint64_t *a, ca_size_t n);
|
|
|
45
39
|
void ca_sort_quick_f32 (float32_t *a, ca_size_t n);
|
|
46
40
|
void ca_sort_quick_f64 (double *a, ca_size_t n);
|
|
47
41
|
|
|
48
|
-
/*
|
|
42
|
+
/* Mergesort over 10 numeric data types (`aux` is caller-supplied
|
|
49
43
|
scratch buffer of the same length / data type as `a`). */
|
|
50
44
|
void ca_sort_merge_i8 (int8_t *a, int8_t *aux, ca_size_t n);
|
|
51
45
|
void ca_sort_merge_u8 (uint8_t *a, uint8_t *aux, ca_size_t n);
|
|
@@ -58,9 +52,12 @@ void ca_sort_merge_u64 (uint64_t *a, uint64_t *aux, ca_size_t n);
|
|
|
58
52
|
void ca_sort_merge_f32 (float32_t *a, float32_t *aux, ca_size_t n);
|
|
59
53
|
void ca_sort_merge_f64 (double *a, double *aux, ca_size_t n);
|
|
60
54
|
|
|
61
|
-
/*
|
|
55
|
+
/* NaN pre-partition for float data types (Hoare 1-pass, returns finite count). */
|
|
62
56
|
ca_size_t ca_partition_nan_f32 (float32_t *a, ca_size_t n);
|
|
63
57
|
ca_size_t ca_partition_nan_f64 (double *a, ca_size_t n);
|
|
58
|
+
/* The same, keeping the order within both regions; scratch holds n values. */
|
|
59
|
+
ca_size_t ca_partition_nan_stable_f32 (float32_t *a, ca_size_t n, float32_t *scratch);
|
|
60
|
+
ca_size_t ca_partition_nan_stable_f64 (double *a, ca_size_t n, double *scratch);
|
|
64
61
|
|
|
65
62
|
/* Pair variant of NaN pre-partition for float argsort kernels. scratch
|
|
66
63
|
holds n pairs; its contents on return are unspecified. */
|
|
@@ -71,7 +68,7 @@ ca_size_t ca_partition_nan_pair_f32 (struct ca_pair_f32 *a, ca_size_t n,
|
|
|
71
68
|
ca_size_t ca_partition_nan_pair_f64 (struct ca_pair_f64 *a, ca_size_t n,
|
|
72
69
|
struct ca_pair_f64 *scratch);
|
|
73
70
|
|
|
74
|
-
/*
|
|
71
|
+
/* Value-level quickselect for partition_copy.
|
|
75
72
|
Reorders a[0..n) so that a[kth] is exact + left/right regions
|
|
76
73
|
satisfy <= / >= contracts. Order within each region unspecified. */
|
|
77
74
|
void ca_partition_quick_i8 (int8_t *a, ca_size_t n, ca_size_t kth);
|
|
@@ -85,7 +82,7 @@ void ca_partition_quick_u64 (uint64_t *a, ca_size_t n, ca_size_t kth);
|
|
|
85
82
|
void ca_partition_quick_f32 (float32_t *a, ca_size_t n, ca_size_t kth);
|
|
86
83
|
void ca_partition_quick_f64 (double *a, ca_size_t n, ca_size_t kth);
|
|
87
84
|
|
|
88
|
-
/*
|
|
85
|
+
/* Pair sort kernels (sort_index / sort_addr). The pair
|
|
89
86
|
struct is opaque to mkkernel-emitted callers via void*; each kernel
|
|
90
87
|
has its own well-defined layout: { TYPE v; ca_size_t i; } with natural
|
|
91
88
|
alignment padding. */
|