carray 3.0.5 → 3.0.7
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 +343 -0
- data/README.md +25 -4
- data/carray.gemspec +3 -2
- data/ext/ca_axis_dispatch.c +6 -0
- data/ext/ca_axis_group.c +7 -7
- data/ext/ca_binop_dispatch.c +8 -0
- data/ext/ca_binop_dispatch.h +1 -0
- data/ext/ca_categorical_iterator.c +14 -14
- data/ext/ca_kernel_iterator.c +116 -231
- data/ext/ca_kernel_iterator.h +416 -258
- data/ext/ca_obj_array.c +4 -4
- data/ext/ca_obj_bincmp.c +28 -4
- data/ext/ca_obj_binop.c +46 -12
- data/ext/ca_obj_bitarray.c +2 -4
- data/ext/ca_obj_bitfield.c +88 -4
- data/ext/ca_obj_byte_swap.c +4 -4
- data/ext/ca_obj_const_string.c +422 -257
- data/ext/ca_obj_face.c +73 -33
- data/ext/ca_obj_fake.c +114 -13
- data/ext/ca_obj_farray.c +7 -1
- data/ext/ca_obj_fixlen_string.c +51 -17
- data/ext/ca_obj_grid.c +179 -19
- data/ext/ca_obj_meld.c +74 -118
- data/ext/ca_obj_moncmp.c +9 -1
- data/ext/ca_obj_monop.c +100 -36
- data/ext/ca_obj_object.c +63 -29
- data/ext/ca_obj_reduce.c +17 -5
- data/ext/ca_obj_refer.c +162 -23
- data/ext/ca_obj_remap.c +69 -10
- data/ext/ca_obj_repeat.c +1 -1
- data/ext/ca_obj_roll.c +3 -4
- data/ext/ca_obj_select.c +12 -7
- data/ext/ca_obj_select_axis.c +9 -6
- data/ext/ca_obj_shift.c +1 -0
- data/ext/ca_obj_stack.c +315 -116
- data/ext/ca_obj_stride.c +177 -53
- data/ext/ca_obj_string.c +20 -4
- data/ext/ca_obj_tile.c +3 -4
- data/ext/ca_obj_triop.c +24 -13
- data/ext/ca_obj_window.c +23 -15
- data/ext/ca_op_ipower.c +71 -23
- data/ext/ca_op_powi.h +6 -29
- data/ext/ca_sort_kernels.h +3 -0
- data/ext/ca_sweep_engine.c +90 -23
- data/ext/ca_sweep_engine.h +5 -6
- data/ext/caframe_csv_reader.c +2 -2
- data/ext/carray.h +5 -2
- data/ext/carray_access.c +125 -103
- data/ext/carray_address_basis.c +209 -1
- data/ext/carray_attribute.c +8 -0
- data/ext/carray_broadcast.c +5 -6
- data/ext/carray_build_flags.h +1 -1
- data/ext/carray_call_cfunc.c +5 -8
- data/ext/carray_cast.c +319 -48
- data/ext/carray_cast_func.rb +37 -5
- data/ext/carray_conversion.c +65 -7
- data/ext/carray_copy.c +24 -0
- data/ext/carray_core.c +874 -72
- data/ext/carray_count.c +28 -9
- data/ext/carray_element.c +22 -12
- data/ext/carray_factorize.c +11 -11
- data/ext/carray_histogram.c +27 -5
- data/ext/carray_index_classifier.c +7 -5
- data/ext/carray_internal.h +241 -12
- data/ext/carray_kernels_bincmp.c +2007 -3
- data/ext/carray_kernels_binop.c +25502 -5336
- data/ext/carray_kernels_init.c +22 -22
- data/ext/carray_kernels_monop.c +10739 -3771
- data/ext/carray_kernels_reduce_aggregate.c +4429 -702
- data/ext/carray_kernels_reduce_boolean.c +1533 -15
- data/ext/carray_kernels_reduce_cumulative.c +1808 -248
- data/ext/carray_kernels_reduce_extreme.c +4508 -511
- data/ext/carray_kernels_reduce_variance.c +2284 -152
- data/ext/carray_kernels_scan.c +240 -240
- data/ext/carray_kernels_search.c +4211 -264
- data/ext/carray_kernels_sort.c +367 -450
- data/ext/carray_lazy.c +63 -1
- data/ext/carray_loop.c +10 -3
- data/ext/carray_mask.c +247 -149
- data/ext/carray_median_percentile.c +17 -12
- data/ext/carray_memory_view.c +54 -29
- data/ext/carray_operator.c +219 -55
- data/ext/carray_order.c +55 -11
- data/ext/carray_partition.c +1 -1
- data/ext/carray_random.c +5 -2
- data/ext/carray_round.c +24 -1
- data/ext/carray_scatter.c +4 -0
- data/ext/carray_segment.c +1 -1
- data/ext/carray_slab.c +110 -25
- data/ext/carray_sort.c +7 -4
- data/ext/carray_sort_kernel.c +24 -0
- data/ext/carray_struct.c +21 -6
- data/ext/carray_test.c +154 -53
- data/ext/carray_time_text.c +8 -2
- data/ext/carray_utils.c +124 -54
- data/ext/extconf.rb +11 -0
- data/ext/mk_call_cfunc.rb +6 -11
- data/ext/mkkernel.rb +383 -121
- data/ext/ruby_carray.c +4 -1
- data/ext/version.h +4 -4
- data/lib/carray/attribute.rb +25 -1
- data/lib/carray/autoload_carray.rb +3 -3
- data/lib/carray/autoload_method_extension.rb +5 -3
- data/lib/carray/axis_group.rb +22 -13
- data/lib/carray/basics.rb +27 -9
- data/lib/carray/bincount_nd.rb +8 -2
- data/lib/carray/block_iterator.rb +65 -24
- data/lib/carray/categorical.rb +27 -16
- data/lib/carray/categorical_iterator.rb +4 -3
- data/lib/carray/complex.rb +2 -2
- data/lib/carray/conditional.rb +55 -6
- data/lib/carray/const_string.rb +74 -0
- data/lib/carray/construct.rb +2 -2
- data/lib/carray/core_extensions.rb +19 -68
- data/lib/carray/data_type_extension.rb +1 -0
- data/lib/carray/fixlen_string.rb +83 -1
- data/lib/carray/frame/column_verbs.rb +102 -16
- data/lib/carray/frame/concat.rb +50 -6
- data/lib/carray/frame/convert.rb +19 -0
- data/lib/carray/frame/csv_parser.rb +45 -36
- data/lib/carray/frame/describe.rb +4 -2
- data/lib/carray/frame/frame.rb +436 -83
- data/lib/carray/frame/group.rb +731 -78
- data/lib/carray/frame/io.rb +216 -73
- data/lib/carray/frame/join.rb +166 -43
- data/lib/carray/frame/records.rb +9 -7
- data/lib/carray/frame/reshape.rb +109 -11
- data/lib/carray/frame/sort.rb +57 -9
- data/lib/carray/frame/verbs.rb +448 -60
- data/lib/carray/frame/windows.rb +71 -9
- data/lib/carray/fuse_source.rb +4 -2
- data/lib/carray/inspect.rb +7 -2
- data/lib/carray/iterator.rb +40 -0
- data/lib/carray/key_windows.rb +10 -4
- data/lib/carray/lazy.rb +28 -24
- data/lib/carray/mask_gap_fill.rb +37 -17
- data/lib/carray/meld_reduce.rb +1 -1
- data/lib/carray/methods/bin.rb +3 -0
- data/lib/carray/methods/choose.rb +3 -2
- data/lib/carray/methods/composition.rb +1 -1
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +4 -1
- data/lib/carray/methods/is_in.rb +23 -3
- data/lib/carray/methods/locate_addr.rb +63 -12
- data/lib/carray/methods/meshgrid.rb +3 -1
- data/lib/carray/methods/repeat.rb +11 -1
- data/lib/carray/record_order.rb +35 -6
- data/lib/carray/runtime.rb +57 -8
- data/lib/carray/segment_iterator.rb +42 -24
- data/lib/carray/serialize.rb +56 -17
- data/lib/carray/slab_iterator.rb +1 -1
- data/lib/carray/stack.rb +21 -9
- data/lib/carray/string.rb +6 -6
- data/lib/carray/string_operation_extension.rb +25 -4
- data/lib/carray/struct_builder.rb +4 -1
- data/lib/carray/time.rb +195 -46
- data/lib/carray/window_iterator.rb +64 -16
- data/yard-stubs/ca_obj_array.rb +26 -1
- data/yard-stubs/ca_obj_bitfield.rb +4 -1
- data/yard-stubs/ca_obj_refer.rb +3 -0
- data/yard-stubs/ca_obj_window.rb +2 -1
- data/yard-stubs/carray_access.rb +4 -2
- data/yard-stubs/carray_cast.rb +14 -5
- data/yard-stubs/carray_conversion.rb +8 -2
- data/yard-stubs/carray_count.rb +6 -3
- data/yard-stubs/carray_mask.rb +20 -1
- data/yard-stubs/carray_math.rb +36 -16
- data/yard-stubs/carray_memory_view.rb +7 -0
- data/yard-stubs/carray_order.rb +6 -0
- data/yard-stubs/carray_scatter.rb +2 -1
- data/yard-stubs/carray_test.rb +23 -7
- metadata +17 -3
data/ext/carray_test.c
CHANGED
|
@@ -201,6 +201,23 @@ rb_ca_is_type (VALUE arg, int type)
|
|
|
201
201
|
live in ca_obj_record.c; signatures stay in carray.h for cross-file
|
|
202
202
|
extern use. */
|
|
203
203
|
|
|
204
|
+
/* Whether v, an index along a length of n, names a position: a negative one
|
|
205
|
+
* counts from the end. An Integer too large for ca_size_t is out of any
|
|
206
|
+
* range; what is not an Integer is not an index. */
|
|
207
|
+
static int
|
|
208
|
+
ca_index_arg_in_range (VALUE v, ca_size_t n, const char *arg)
|
|
209
|
+
{
|
|
210
|
+
ca_size_t idx;
|
|
211
|
+
if ( RB_TYPE_P(v, T_BIGNUM) ) {
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
idx = ca_integer_arg(v, arg, NULL);
|
|
215
|
+
if ( idx < 0 ) {
|
|
216
|
+
idx += n;
|
|
217
|
+
}
|
|
218
|
+
return idx >= 0 && idx < n;
|
|
219
|
+
}
|
|
220
|
+
|
|
204
221
|
/* CArray#valid_index?(*idx) -- whether self[*idx] names a cell: a negative
|
|
205
222
|
* index counts from the end of its axis, as it does at every door. The
|
|
206
223
|
* number of indices must equal ndim (raises otherwise). */
|
|
@@ -208,7 +225,6 @@ static VALUE
|
|
|
208
225
|
rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
|
209
226
|
{
|
|
210
227
|
CArray *ca;
|
|
211
|
-
ca_size_t idx;
|
|
212
228
|
int i;
|
|
213
229
|
|
|
214
230
|
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
@@ -218,11 +234,7 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
|
|
218
234
|
"invalid # of arguments (%i for %i)", argc, ca->ndim);
|
|
219
235
|
}
|
|
220
236
|
for (i=0; i<ca->ndim; i++) {
|
|
221
|
-
|
|
222
|
-
if ( idx < 0 ) {
|
|
223
|
-
idx += ca->dim[i];
|
|
224
|
-
}
|
|
225
|
-
if ( idx < 0 || idx >= ca->dim[i] ) {
|
|
237
|
+
if ( ! ca_index_arg_in_range(argv[i], ca->dim[i], "an index") ) {
|
|
226
238
|
return Qfalse;
|
|
227
239
|
}
|
|
228
240
|
}
|
|
@@ -236,30 +248,26 @@ static VALUE
|
|
|
236
248
|
rb_ca_is_valid_addr (VALUE self, VALUE raddr)
|
|
237
249
|
{
|
|
238
250
|
CArray *ca;
|
|
239
|
-
ca_size_t addr;
|
|
240
251
|
|
|
241
252
|
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
242
|
-
|
|
243
|
-
if ( addr < 0 ) {
|
|
244
|
-
addr += ca->elements;
|
|
245
|
-
}
|
|
246
|
-
if ( addr < 0 || addr >= ca->elements ) {
|
|
247
|
-
return Qfalse;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
return Qtrue;
|
|
251
|
-
}
|
|
253
|
+
return ca_index_arg_in_range(raddr, ca->elements, "an address") ? Qtrue : Qfalse;
|
|
252
254
|
}
|
|
253
255
|
|
|
254
|
-
/* CArray#same_shape?(other) —
|
|
255
|
-
* Scalars compare true against any array (see ca_has_same_shape).
|
|
256
|
+
/* CArray#same_shape?(other) — whether self and other share ndim and dim[].
|
|
257
|
+
* Scalars compare true against any array (see ca_has_same_shape). Only the
|
|
258
|
+
* shape is compared, so no value is converted: other that is not a CArray
|
|
259
|
+
* takes the shape it has as an object array. */
|
|
256
260
|
static VALUE
|
|
257
261
|
rb_ca_has_same_shape (VALUE self, VALUE other)
|
|
258
262
|
{
|
|
259
263
|
CArray *ca, *cb;
|
|
260
264
|
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
if ( rb_obj_is_carray(other) ) {
|
|
266
|
+
TypedData_Get_Struct(other, CArray, &carray_data_type, cb);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
cb = ca_wrap_readonly(other, CA_OBJECT);
|
|
270
|
+
}
|
|
263
271
|
return ca_has_same_shape(ca, cb) ? Qtrue : Qfalse;
|
|
264
272
|
}
|
|
265
273
|
|
|
@@ -274,10 +282,42 @@ eql_## type (const char *a, const char *b, ca_size_t bytes) \
|
|
|
274
282
|
return ( *(const type*)a == *(const type*)b ); \
|
|
275
283
|
}
|
|
276
284
|
|
|
285
|
+
/* == compares contents: a NaN equals a NaN (whatever its payload), as the
|
|
286
|
+
same array read back or copied holds the same NaN; -0.0 equals 0.0 as
|
|
287
|
+
values do. eql? stays bitwise. An object cell equals itself first, as
|
|
288
|
+
in Array#== and Array#eql?, so a copy of an array holding any NaN object
|
|
289
|
+
equals it. A cell holding a CArray is asked all the same, so an array
|
|
290
|
+
that holds itself is refused as cyclic. */
|
|
291
|
+
static int
|
|
292
|
+
ca_object_cells_identical (VALUE x, VALUE y)
|
|
293
|
+
{
|
|
294
|
+
return x == y && ! rb_obj_is_carray(x);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static int
|
|
298
|
+
ca_object_cells_equal (VALUE x, VALUE y)
|
|
299
|
+
{
|
|
300
|
+
if ( ca_object_cells_identical(x, y) ) {
|
|
301
|
+
return 1;
|
|
302
|
+
}
|
|
303
|
+
if ( RB_FLOAT_TYPE_P(x) && RB_FLOAT_TYPE_P(y) &&
|
|
304
|
+
isnan(RFLOAT_VALUE(x)) && isnan(RFLOAT_VALUE(y)) ) {
|
|
305
|
+
return 1;
|
|
306
|
+
}
|
|
307
|
+
return RTEST(rb_funcall(x, id_equal, 1, y)) ? 1 : 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static int
|
|
311
|
+
ca_object_cells_eql (VALUE x, VALUE y)
|
|
312
|
+
{
|
|
313
|
+
return ca_object_cells_identical(x, y)
|
|
314
|
+
|| RTEST(rb_funcall(x, id_eql, 1, y));
|
|
315
|
+
}
|
|
316
|
+
|
|
277
317
|
static int
|
|
278
318
|
eql_VALUE (const char *a, const char *b, ca_size_t bytes)
|
|
279
319
|
{
|
|
280
|
-
return
|
|
320
|
+
return ca_object_cells_equal(*(const VALUE*)a, *(const VALUE*)b);
|
|
281
321
|
}
|
|
282
322
|
|
|
283
323
|
static int
|
|
@@ -295,10 +335,28 @@ eql_type(int32_t)
|
|
|
295
335
|
eql_type(uint32_t)
|
|
296
336
|
eql_type(int64_t)
|
|
297
337
|
eql_type(uint64_t)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
338
|
+
#define eql_float(type) \
|
|
339
|
+
static int \
|
|
340
|
+
eql_## type (const char *a, const char *b, ca_size_t bytes) \
|
|
341
|
+
{ \
|
|
342
|
+
type x = *(const type*)a, y = *(const type*)b; \
|
|
343
|
+
return ( x == y ) || ( isnan(x) && isnan(y) ); \
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
#define eql_cmplx(type, part) \
|
|
347
|
+
static int \
|
|
348
|
+
eql_## type (const char *a, const char *b, ca_size_t bytes) \
|
|
349
|
+
{ \
|
|
350
|
+
type x = *(const type*)a, y = *(const type*)b; \
|
|
351
|
+
part xr = creal(x), xi = cimag(x), yr = creal(y), yi = cimag(y); \
|
|
352
|
+
return ( ( xr == yr ) || ( isnan(xr) && isnan(yr) ) ) && \
|
|
353
|
+
( ( xi == yi ) || ( isnan(xi) && isnan(yi) ) ); \
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
eql_float(float32_t)
|
|
357
|
+
eql_float(float64_t)
|
|
358
|
+
eql_cmplx(cmplx64_t, float)
|
|
359
|
+
eql_cmplx(cmplx128_t, double)
|
|
302
360
|
|
|
303
361
|
/* Placeholder for CA_FLOAT128 / CA_CMPLX256 slots (ca_valid[12] =
|
|
304
362
|
ca_valid[15] = 0, so never invoked). */
|
|
@@ -371,8 +429,8 @@ ca_compare_body (VALUE arg)
|
|
|
371
429
|
comparison is bitwise (= NaN.eql?(NaN) yields true since their bit
|
|
372
430
|
patterns match), so memcmp gives the right semantics. For non-strict
|
|
373
431
|
(==) of numeric data_types, type-equality is byte-equality EXCEPT for
|
|
374
|
-
floats where -0.0 == +0.0 (different bit pattern, same value) and
|
|
375
|
-
NaN
|
|
432
|
+
floats where -0.0 == +0.0 (different bit pattern, same value) and any
|
|
433
|
+
NaN equals any NaN (payloads may differ) -- so we must keep the
|
|
376
434
|
per-element comparator there.
|
|
377
435
|
|
|
378
436
|
Integer / bool / fixlen data_types are byte-exact, so memcmp matches both
|
|
@@ -380,13 +438,13 @@ ca_compare_body (VALUE arg)
|
|
|
380
438
|
the comparator. */
|
|
381
439
|
if ( ! masked_a && ! masked_b ) {
|
|
382
440
|
if ( is_object ) {
|
|
383
|
-
ID id = strict ? id_eql : id_equal;
|
|
384
441
|
VALUE *va = (VALUE *) pa;
|
|
385
442
|
VALUE *vb = (VALUE *) pb;
|
|
386
443
|
for (i=0; i<ca->elements; i++) {
|
|
387
444
|
volatile VALUE x = va[i];
|
|
388
445
|
volatile VALUE y = vb[i];
|
|
389
|
-
|
|
446
|
+
int eq = strict ? ca_object_cells_eql(x, y) : ca_object_cells_equal(x, y);
|
|
447
|
+
if ( ! eq ) {
|
|
390
448
|
flag = 0;
|
|
391
449
|
break;
|
|
392
450
|
}
|
|
@@ -427,8 +485,7 @@ ca_compare_body (VALUE arg)
|
|
|
427
485
|
if ( is_object ) {
|
|
428
486
|
volatile VALUE x = *(VALUE *) pa;
|
|
429
487
|
volatile VALUE y = *(VALUE *) pb;
|
|
430
|
-
|
|
431
|
-
eq = RTEST(rb_funcall(x, id, 1, y));
|
|
488
|
+
eq = strict ? ca_object_cells_eql(x, y) : ca_object_cells_equal(x, y);
|
|
432
489
|
}
|
|
433
490
|
else if ( strict
|
|
434
491
|
|| ca->data_type <= CA_UINT64
|
|
@@ -451,6 +508,19 @@ ca_compare_body (VALUE arg)
|
|
|
451
508
|
return Qnil;
|
|
452
509
|
}
|
|
453
510
|
|
|
511
|
+
typedef struct {
|
|
512
|
+
CArray **list;
|
|
513
|
+
ca_compare_ctx_t *c;
|
|
514
|
+
} ca_compare_run_t;
|
|
515
|
+
|
|
516
|
+
static VALUE
|
|
517
|
+
ca_compare_run (VALUE arg)
|
|
518
|
+
{
|
|
519
|
+
ca_compare_run_t *r = (ca_compare_run_t *) arg;
|
|
520
|
+
ca_attach_window(2, r->list, "rr", ca_compare_body, (VALUE) r->c);
|
|
521
|
+
return Qnil;
|
|
522
|
+
}
|
|
523
|
+
|
|
454
524
|
/* ca_compare_common(a, b, strict) — shared body of ca_equal (==) and
|
|
455
525
|
* ca_eql_strict (eql?). Returns 1 if arrays match under the selected
|
|
456
526
|
* semantics, else 0.
|
|
@@ -461,8 +531,8 @@ ca_compare_body (VALUE arg)
|
|
|
461
531
|
* four masked/unmasked combinations.
|
|
462
532
|
*
|
|
463
533
|
* The only difference is the per-element comparator:
|
|
464
|
-
* == : ca_eql[data_type] (
|
|
465
|
-
* eql?: memcmp for numeric,
|
|
534
|
+
* == : ca_eql[data_type] (by value: NaN equals NaN, -0.0 equals 0.0)
|
|
535
|
+
* eql?: memcmp for numeric, ca_object_cells_eql for CA_OBJECT
|
|
466
536
|
*
|
|
467
537
|
* The unmasked-unmasked branch takes a bulk memcmp or per-cell
|
|
468
538
|
* shortcut to amortise per-element function pointer dispatch. */
|
|
@@ -503,8 +573,14 @@ ca_compare_common (void *ap, void *bp, int strict)
|
|
|
503
573
|
c.flag = 1;
|
|
504
574
|
list[0] = ca;
|
|
505
575
|
list[1] = cb;
|
|
506
|
-
/* The object lane calls #== / #eql? with both arrays attached
|
|
507
|
-
|
|
576
|
+
/* The object lane calls #== / #eql? with both arrays attached, and
|
|
577
|
+
recorded as compared over (ca_computing_run), so a cell holding one
|
|
578
|
+
of them is refused as cyclic rather than compared again without
|
|
579
|
+
end. */
|
|
580
|
+
ca_compare_run_t r;
|
|
581
|
+
r.list = list;
|
|
582
|
+
r.c = &c;
|
|
583
|
+
ca_computing_run(2, list, ca_compare_run, (VALUE) &r);
|
|
508
584
|
return c.flag;
|
|
509
585
|
}
|
|
510
586
|
}
|
|
@@ -522,9 +598,10 @@ ca_eql_storage (void *ap, void *bp)
|
|
|
522
598
|
}
|
|
523
599
|
|
|
524
600
|
/* CArray#==(other) — elementwise equality returning true / false.
|
|
525
|
-
* data_class, data_type, shape, and mask state must all match
|
|
526
|
-
*
|
|
527
|
-
*
|
|
601
|
+
* data_class, data_type, shape, and mask state must all match. It asks
|
|
602
|
+
* whether the contents are the same, so a NaN equals a NaN and -0.0
|
|
603
|
+
* equals 0.0; the IEEE comparison of each element is #eq. Non-CArray
|
|
604
|
+
* other returns false. */
|
|
528
605
|
static VALUE
|
|
529
606
|
rb_ca_equal (VALUE self, VALUE other)
|
|
530
607
|
{
|
|
@@ -607,6 +684,24 @@ rb_ca_eql (VALUE self, VALUE other)
|
|
|
607
684
|
|
|
608
685
|
#define CA_HASH_SAMPLE_BYTES 64
|
|
609
686
|
|
|
687
|
+
typedef struct {
|
|
688
|
+
st_index_t h;
|
|
689
|
+
ca_size_t n;
|
|
690
|
+
const VALUE *cells;
|
|
691
|
+
} ca_hash_cells_t;
|
|
692
|
+
|
|
693
|
+
static VALUE
|
|
694
|
+
ca_hash_cells (VALUE arg)
|
|
695
|
+
{
|
|
696
|
+
ca_hash_cells_t *hc = (ca_hash_cells_t *) arg;
|
|
697
|
+
ca_size_t i;
|
|
698
|
+
|
|
699
|
+
for (i = 0; i < hc->n; i++) {
|
|
700
|
+
hc->h = rb_hash_uint(hc->h, (st_index_t) NUM2LONG(rb_hash(hc->cells[i])));
|
|
701
|
+
}
|
|
702
|
+
return Qnil;
|
|
703
|
+
}
|
|
704
|
+
|
|
610
705
|
static st_index_t
|
|
611
706
|
ca_hash (CArray *ca)
|
|
612
707
|
{
|
|
@@ -616,19 +711,21 @@ ca_hash (CArray *ca)
|
|
|
616
711
|
ca_size_t data_len = ca_length(ca);
|
|
617
712
|
ca_size_t sample = (data_len < CA_HASH_SAMPLE_BYTES) ? data_len : CA_HASH_SAMPLE_BYTES;
|
|
618
713
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
h
|
|
622
|
-
h
|
|
623
|
-
h
|
|
714
|
+
/* Mixed in order: XOR would cancel equal fields, as a 1-D array's dim
|
|
715
|
+
and elements are. */
|
|
716
|
+
h = rb_hash_start(ca->data_type);
|
|
717
|
+
h = rb_hash_uint(h, (st_index_t) ca->ndim);
|
|
718
|
+
h = rb_hash_uint(h, (st_index_t) ca->bytes);
|
|
719
|
+
h = rb_hash_uint(h, (st_index_t) ca->elements);
|
|
720
|
+
h = rb_hash_uint(h, (st_index_t) scalar_flag);
|
|
624
721
|
if ( ca->ndim > 0 ) {
|
|
625
|
-
h
|
|
722
|
+
h = rb_hash_uint(h, rb_memhash(ca->dim, sizeof(ca_size_t) * ca->ndim));
|
|
626
723
|
}
|
|
627
724
|
|
|
628
725
|
/* ca_is_any_masked() attaches/detaches the mask internally and returns
|
|
629
726
|
only a boolean, so we never touch ca->mask->ptr here. */
|
|
630
727
|
masked_flag = ca_is_any_masked(ca) ? 1 : 0;
|
|
631
|
-
h
|
|
728
|
+
h = rb_hash_uint(h, (st_index_t) masked_flag);
|
|
632
729
|
|
|
633
730
|
if ( ! masked_flag && sample > 0 ) {
|
|
634
731
|
ca_size_t addrs[CA_HASH_SAMPLE_BYTES];
|
|
@@ -648,22 +745,23 @@ ca_hash (CArray *ca)
|
|
|
648
745
|
#hash, not the VALUE bits. The cells sit on the stack, where the
|
|
649
746
|
GC sees them while #hash runs. */
|
|
650
747
|
VALUE cells[CA_HASH_SAMPLE_BYTES / sizeof(VALUE)];
|
|
748
|
+
ca_hash_cells_t hc;
|
|
651
749
|
ca_xfer_addrs(ca, ncell, addrs, cells, CA_XFER_GET);
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
750
|
+
hc.h = h; hc.n = ncell; hc.cells = cells;
|
|
751
|
+
ca_cell_walk_run(ca_hash_cells, (VALUE) &hc);
|
|
752
|
+
h = hc.h;
|
|
655
753
|
RB_GC_GUARD(cells[0]);
|
|
656
754
|
}
|
|
657
755
|
else {
|
|
658
756
|
volatile VALUE holder;
|
|
659
757
|
char *buf = ALLOCV_N(char, holder, ncell * ca->bytes);
|
|
660
758
|
ca_xfer_addrs(ca, ncell, addrs, buf, CA_XFER_GET);
|
|
661
|
-
h
|
|
759
|
+
h = rb_hash_uint(h, rb_memhash(buf, ncell * ca->bytes));
|
|
662
760
|
ALLOCV_END(holder);
|
|
663
761
|
}
|
|
664
762
|
}
|
|
665
763
|
|
|
666
|
-
return h;
|
|
764
|
+
return rb_hash_end(h);
|
|
667
765
|
}
|
|
668
766
|
|
|
669
767
|
/* CArray#hash — Hash key value; wraps ca_hash into a Ruby Integer. */
|
|
@@ -795,7 +893,8 @@ without_read_only_ensure (VALUE arg)
|
|
|
795
893
|
* the bridge owns.
|
|
796
894
|
*
|
|
797
895
|
* Mechanics: clears CA_FLAG_READ_ONLY on self and on its mask for the
|
|
798
|
-
* duration of the block
|
|
896
|
+
* duration of the block, except on a mask that is a wrap: that mask borrows
|
|
897
|
+
* its bits from a producer (wrap_memory_view's mask:), which set the flag; rb_ensure restores both on normal return AND on
|
|
799
898
|
* raise, setting the flag on whatever mask self has by then. (A read-only
|
|
800
899
|
* array's mask carries the flag once CArray#mask has handed it out.) Frozen
|
|
801
900
|
* objects still raise FrozenError. Does not walk parent chains.
|
|
@@ -822,7 +921,9 @@ rb_ca_without_read_only_flag (VALUE self)
|
|
|
822
921
|
s.was_readonly = ca_test_flag(ca, CA_FLAG_READ_ONLY);
|
|
823
922
|
if (s.was_readonly) {
|
|
824
923
|
ca_unset_flag(ca, CA_FLAG_READ_ONLY);
|
|
825
|
-
|
|
924
|
+
/* A mask that is a wrap borrows its bits (the mask: of
|
|
925
|
+
wrap_memory_view); its flag is the lender's and stays. */
|
|
926
|
+
if (ca->mask && ca->mask->obj_type != CA_OBJ_ARRAY_WRAP) {
|
|
826
927
|
ca_unset_flag(ca->mask, CA_FLAG_READ_ONLY);
|
|
827
928
|
}
|
|
828
929
|
}
|
data/ext/carray_time_text.c
CHANGED
|
@@ -383,7 +383,7 @@ rb_ca_parse_time_text (int argc, VALUE *argv, VALUE self)
|
|
|
383
383
|
if ( ca->data_type != CA_OBJECT ) {
|
|
384
384
|
rb_raise(rb_eArgError, "time text reading needs an object array");
|
|
385
385
|
}
|
|
386
|
-
if ( ! ca_is_entity(ca) ) {
|
|
386
|
+
if ( ! ca_is_entity(ca) || ! ca->ptr ) {
|
|
387
387
|
src = rb_ca_copy(src);
|
|
388
388
|
TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
|
|
389
389
|
}
|
|
@@ -602,6 +602,12 @@ rb_ca_s_time_ticks_from_fields (VALUE klass,
|
|
|
602
602
|
other than Z, UTC and GMT, an offset written another way) is deferred to
|
|
603
603
|
Date._strptime for that cell.
|
|
604
604
|
|
|
605
|
+
Three inputs read differently from Date._strptime. A format with both
|
|
606
|
+
a two-digit year and a four-digit year takes the four-digit year, where
|
|
607
|
+
Date._strptime adds the century to it. %Z ends at the zone's name, so
|
|
608
|
+
digits directly after it go to the next directive. A NUL in the text
|
|
609
|
+
is text, so it is left over.
|
|
610
|
+
|
|
605
611
|
Strict reading, used to find the format a column is written in, holds
|
|
606
612
|
the text to the shape of the format: %Y is four digits and %y two, %N
|
|
607
613
|
one to nine digits, the other numbers one or two digits (two when a
|
|
@@ -1077,7 +1083,7 @@ rb_ca_strptime_fields (VALUE self, VALUE rformat, VALUE rstrict)
|
|
|
1077
1083
|
if ( ca->data_type != CA_OBJECT ) {
|
|
1078
1084
|
rb_raise(rb_eArgError, "strptime reading needs an object array");
|
|
1079
1085
|
}
|
|
1080
|
-
if ( ! ca_is_entity(ca) ) {
|
|
1086
|
+
if ( ! ca_is_entity(ca) || ! ca->ptr ) {
|
|
1081
1087
|
src = rb_ca_copy(src);
|
|
1082
1088
|
TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
|
|
1083
1089
|
}
|