carray 1.5.1 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +32 -0
- data/{LICENSES → LICENSE} +0 -0
- data/NEWS.md +83 -0
- data/README.md +34 -18
- data/Rakefile +1 -1
- data/TODO.md +17 -0
- data/carray.gemspec +10 -7
- data/ext/ca_iter_block.c +3 -5
- data/ext/ca_iter_dimension.c +4 -5
- data/ext/ca_iter_window.c +2 -4
- data/ext/ca_obj_array.c +394 -124
- data/ext/ca_obj_bitarray.c +6 -11
- data/ext/ca_obj_bitfield.c +5 -9
- data/ext/ca_obj_block.c +5 -12
- data/ext/ca_obj_fake.c +3 -5
- data/ext/ca_obj_farray.c +3 -5
- data/ext/ca_obj_field.c +15 -17
- data/ext/ca_obj_grid.c +5 -6
- data/ext/ca_obj_mapping.c +2 -4
- data/ext/ca_obj_object.c +3 -5
- data/ext/ca_obj_reduce.c +2 -4
- data/ext/ca_obj_refer.c +11 -15
- data/ext/ca_obj_repeat.c +2 -4
- data/ext/ca_obj_select.c +2 -4
- data/ext/ca_obj_shift.c +3 -5
- data/ext/ca_obj_transpose.c +3 -5
- data/ext/ca_obj_unbound_repeat.c +68 -122
- data/ext/ca_obj_window.c +7 -9
- data/ext/carray.h +17 -8
- data/ext/carray_access.c +183 -58
- data/ext/carray_attribute.c +151 -197
- data/ext/carray_call_cfunc.c +1 -3
- data/ext/carray_cast.c +345 -144
- data/ext/carray_cast_func.rb +1 -2
- data/ext/carray_class.c +28 -36
- data/ext/carray_conversion.c +56 -59
- data/ext/carray_copy.c +16 -32
- data/ext/carray_core.c +73 -60
- data/ext/carray_element.c +25 -44
- data/ext/carray_generate.c +74 -53
- data/ext/carray_iterator.c +13 -15
- data/ext/carray_loop.c +53 -82
- data/ext/carray_mask.c +99 -119
- data/ext/carray_math.rb +28 -12
- data/ext/carray_mathfunc.c +1 -3
- data/ext/carray_numeric.c +42 -45
- data/ext/carray_operator.c +45 -32
- data/ext/carray_order.c +231 -65
- data/ext/carray_sort_addr.c +14 -21
- data/ext/carray_stat.c +1 -3
- data/ext/carray_stat_proc.rb +2 -4
- data/ext/carray_test.c +41 -30
- data/ext/carray_undef.c +1 -11
- data/ext/carray_utils.c +138 -51
- data/ext/extconf.rb +14 -2
- data/ext/mkmath.rb +2 -2
- data/ext/ruby_carray.c +15 -7
- data/ext/ruby_ccomplex.c +2 -4
- data/ext/ruby_float_func.c +1 -3
- data/ext/version.h +5 -7
- data/lib/carray.rb +9 -9
- data/lib/carray/autoload.rb +0 -2
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +6 -6
- data/lib/carray/basic.rb +1 -3
- data/lib/carray/broadcast.rb +101 -0
- data/lib/carray/compose.rb +34 -10
- data/lib/carray/construct.rb +57 -18
- data/lib/carray/info.rb +1 -3
- data/lib/carray/inspect.rb +3 -5
- data/lib/carray/io/imagemagick.rb +1 -3
- data/lib/carray/iterator.rb +3 -3
- data/lib/carray/mask.rb +18 -7
- data/lib/carray/math.rb +4 -6
- data/lib/carray/math/histogram.rb +1 -3
- data/lib/carray/math/recurrence.rb +1 -3
- data/lib/carray/mkmf.rb +1 -3
- data/lib/carray/object/ca_obj_iterator.rb +1 -3
- data/lib/carray/object/ca_obj_link.rb +1 -3
- data/lib/carray/object/ca_obj_pack.rb +1 -3
- data/lib/carray/obsolete.rb +1 -17
- data/lib/carray/ordering.rb +29 -5
- data/lib/carray/serialize.rb +34 -25
- data/lib/carray/string.rb +1 -3
- data/lib/carray/struct.rb +3 -5
- data/lib/carray/testing.rb +5 -10
- data/lib/carray/time.rb +1 -3
- data/lib/carray/transform.rb +12 -3
- data/misc/NOTE +16 -38
- data/spec/Classes/CABitfield_spec.rb +58 -0
- data/spec/Classes/CABlockIterator_spec.rb +114 -0
- data/spec/Classes/CABlock_spec.rb +205 -0
- data/spec/Classes/CAField_spec.rb +39 -0
- data/spec/Classes/CAGrid_spec.rb +75 -0
- data/spec/Classes/CAMap_spec.rb +0 -0
- data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
- data/spec/Classes/CAObject_attribute_spec.rb +33 -0
- data/spec/Classes/CAObject_spec.rb +33 -0
- data/spec/Classes/CARefer_spec.rb +93 -0
- data/spec/Classes/CARepeat_spec.rb +65 -0
- data/spec/Classes/CASelect_spec.rb +22 -0
- data/spec/Classes/CAShift_spec.rb +16 -0
- data/spec/Classes/CAStruct_spec.rb +71 -0
- data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
- data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
- data/spec/Classes/CAWindow_spec.rb +54 -0
- data/spec/Classes/CAWrap_spec.rb +8 -0
- data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
- data/spec/Classes/CScalar_spec.rb +55 -0
- data/spec/Features/feature_130_spec.rb +19 -0
- data/spec/Features/feature_attributes_spec.rb +280 -0
- data/spec/Features/feature_boolean_spec.rb +98 -0
- data/spec/Features/feature_broadcast.rb +116 -0
- data/spec/Features/feature_cast_function.rb +19 -0
- data/spec/Features/feature_cast_spec.rb +33 -0
- data/spec/Features/feature_class_spec.rb +84 -0
- data/spec/Features/feature_complex_spec.rb +42 -0
- data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
- data/spec/Features/feature_convert_spec.rb +46 -0
- data/spec/Features/feature_copy_spec.rb +123 -0
- data/spec/Features/feature_creation_spec.rb +84 -0
- data/spec/Features/feature_element_spec.rb +144 -0
- data/spec/Features/feature_extream_spec.rb +54 -0
- data/spec/Features/feature_generate_spec.rb +74 -0
- data/spec/Features/feature_index_spec.rb +69 -0
- data/spec/Features/feature_mask_spec.rb +580 -0
- data/spec/Features/feature_math_spec.rb +97 -0
- data/spec/Features/feature_order_spec.rb +146 -0
- data/spec/Features/feature_ref_store_spec.rb +209 -0
- data/spec/Features/feature_serialization_spec.rb +125 -0
- data/spec/Features/feature_stat_spec.rb +397 -0
- data/spec/Features/feature_virtual_spec.rb +48 -0
- data/spec/Features/method_eq_spec.rb +81 -0
- data/spec/Features/method_is_nan_spec.rb +12 -0
- data/spec/Features/method_map_spec.rb +54 -0
- data/spec/Features/method_max_with.rb +20 -0
- data/spec/Features/method_min_with.rb +19 -0
- data/spec/Features/method_ne_spec.rb +18 -0
- data/spec/Features/method_project_spec.rb +188 -0
- data/spec/Features/method_ref_spec.rb +27 -0
- data/spec/Features/method_round_spec.rb +11 -0
- data/spec/Features/method_s_linspace_spec.rb +48 -0
- data/spec/Features/method_s_span_spec.rb +14 -0
- data/spec/Features/method_seq_spec.rb +47 -0
- data/spec/Features/method_sort_with.rb +43 -0
- data/spec/Features/method_sorted_with.rb +29 -0
- data/spec/Features/method_span_spec.rb +42 -0
- data/spec/Features/method_wrap_readonly_spec.rb +43 -0
- data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
- data/spec/spec_all.rb +0 -1
- data/utils/convert_test.rb +73 -0
- data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
- metadata +74 -58
- data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
- data/spec/CArray/bug/store_spec.rb +0 -27
- data/spec/CArray/index/repeat_spec.rb +0 -10
- data/spec/CArray/method/eq_spec.rb +0 -80
- data/spec/CArray/method/is_nan_spec.rb +0 -12
- data/spec/CArray/method/ne_spec.rb +0 -18
- data/spec/CArray/method/round_spec.rb +0 -11
- data/spec/CArray/object/_attribute_spec.rb +0 -32
- data/spec/CArray/object/s_new_spec.rb +0 -31
- data/spec/CArray/serialize/Serialization_spec.rb +0 -89
- data/test/test_130.rb +0 -23
- data/test/test_ALL.rb +0 -49
- data/test/test_CABitfield.rb +0 -59
- data/test/test_CABlock.rb +0 -208
- data/test/test_CAField.rb +0 -40
- data/test/test_CAGrid.rb +0 -76
- data/test/test_CAMmap.rb +0 -11
- data/test/test_CARefer.rb +0 -94
- data/test/test_CARepeat.rb +0 -66
- data/test/test_CASelect.rb +0 -23
- data/test/test_CAShift.rb +0 -17
- data/test/test_CAWindow.rb +0 -55
- data/test/test_CAWrap.rb +0 -9
- data/test/test_CComplex.rb +0 -83
- data/test/test_CScalar.rb +0 -91
- data/test/test_attribute.rb +0 -281
- data/test/test_block_iterator.rb +0 -17
- data/test/test_boolean.rb +0 -99
- data/test/test_cast.rb +0 -33
- data/test/test_class.rb +0 -85
- data/test/test_complex.rb +0 -43
- data/test/test_convert.rb +0 -79
- data/test/test_copy.rb +0 -141
- data/test/test_creation.rb +0 -85
- data/test/test_element.rb +0 -146
- data/test/test_extream.rb +0 -55
- data/test/test_generate.rb +0 -75
- data/test/test_index.rb +0 -71
- data/test/test_mask.rb +0 -578
- data/test/test_math.rb +0 -98
- data/test/test_order.rb +0 -147
- data/test/test_ref_store.rb +0 -211
- data/test/test_stat.rb +0 -406
- data/test/test_struct.rb +0 -72
- data/test/test_virtual.rb +0 -49
data/ext/carray_stat.c
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
carray_stat.c
|
4
4
|
|
5
5
|
This file is part of Ruby/CArray extension library.
|
6
|
-
You can redistribute it and/or modify it under the terms of
|
7
|
-
the Ruby Licence.
|
8
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
data/ext/carray_stat_proc.rb
CHANGED
@@ -286,12 +286,10 @@ header = <<HERE_END
|
|
286
286
|
carray_stat_proc.c
|
287
287
|
|
288
288
|
This file is part of Ruby/CArray extension library.
|
289
|
-
You can redistribute it and/or modify it under the terms of
|
290
|
-
the Ruby Licence.
|
291
289
|
|
292
|
-
This file is automatically generated from carray_stat_proc.rb
|
293
290
|
|
294
|
-
|
291
|
+
This file is automatically generated from carray_stat_proc.rb
|
292
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
295
293
|
|
296
294
|
---------------------------------------------------------------------------- */
|
297
295
|
|
data/ext/carray_test.c
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
carray_test.c
|
4
4
|
|
5
5
|
This file is part of Ruby/CArray extension library.
|
6
|
-
You can redistribute it and/or modify it under the terms of
|
7
|
-
the Ruby Licence.
|
8
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
This file includes the modified routine (ca_mem_hash) from
|
12
10
|
|
@@ -218,13 +216,18 @@ rb_obj_is_data_class (VALUE rtype)
|
|
218
216
|
return Qfalse;
|
219
217
|
}
|
220
218
|
|
219
|
+
static VALUE
|
220
|
+
rb_ca_s_is_data_class (VALUE self, VALUE rklass)
|
221
|
+
{
|
222
|
+
return rb_obj_is_data_class(rklass);
|
223
|
+
}
|
224
|
+
|
221
225
|
/* ------------------------------------------------------------- */
|
222
226
|
|
223
|
-
/*
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
end
|
227
|
+
/* @overload valid_index? (*idx)
|
228
|
+
|
229
|
+
(Inquiry)
|
230
|
+
Returns true if the given number list is valid as array index for the object
|
228
231
|
*/
|
229
232
|
|
230
233
|
static VALUE
|
@@ -242,9 +245,11 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
|
242
245
|
}
|
243
246
|
for (i=0; i<ca->ndim; i++) {
|
244
247
|
idx = NUM2SIZE(argv[i]);
|
248
|
+
/*
|
245
249
|
if ( idx < 0 ) {
|
246
250
|
idx += ca->dim[i];
|
247
251
|
}
|
252
|
+
*/
|
248
253
|
if ( idx < 0 || idx >= ca->dim[i] ) {
|
249
254
|
return Qfalse;
|
250
255
|
}
|
@@ -253,11 +258,10 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
|
253
258
|
return Qtrue;
|
254
259
|
}
|
255
260
|
|
256
|
-
/*
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
end
|
261
|
+
/* @overload valid_addr? (*addr)
|
262
|
+
|
263
|
+
(Inquiry)
|
264
|
+
Returns true if the given number is valid as array address for the object
|
261
265
|
*/
|
262
266
|
|
263
267
|
static VALUE
|
@@ -268,9 +272,11 @@ rb_ca_is_valid_addr (VALUE self, VALUE raddr)
|
|
268
272
|
|
269
273
|
Data_Get_Struct(self, CArray, ca);
|
270
274
|
addr = NUM2SIZE(raddr);
|
275
|
+
/*
|
271
276
|
if ( addr < 0 ) {
|
272
277
|
addr += ca->elements;
|
273
278
|
}
|
279
|
+
*/
|
274
280
|
if ( addr < 0 || addr >= ca->elements ) {
|
275
281
|
return Qfalse;
|
276
282
|
}
|
@@ -279,11 +285,10 @@ rb_ca_is_valid_addr (VALUE self, VALUE raddr)
|
|
279
285
|
}
|
280
286
|
}
|
281
287
|
|
282
|
-
/*
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
end
|
288
|
+
/* @overload has_same_shape?
|
289
|
+
|
290
|
+
(Inquiry)
|
291
|
+
Returns true if the object has the same shape with the given array.
|
287
292
|
*/
|
288
293
|
|
289
294
|
static VALUE
|
@@ -453,12 +458,10 @@ ca_equal (void *ap, void *bp)
|
|
453
458
|
return flag;
|
454
459
|
}
|
455
460
|
|
456
|
-
/*
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
alias eql? ==
|
461
|
-
end
|
461
|
+
/* @overload == (other)
|
462
|
+
|
463
|
+
(Inquiry)
|
464
|
+
Returns true if the object equals the given array.
|
462
465
|
*/
|
463
466
|
|
464
467
|
static VALUE
|
@@ -545,11 +548,10 @@ ca_hash (CArray *ca)
|
|
545
548
|
return hash;
|
546
549
|
}
|
547
550
|
|
548
|
-
/*
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
end
|
551
|
+
/* @overload hash
|
552
|
+
|
553
|
+
(Inquiry)
|
554
|
+
Returns the hash value of the object.
|
553
555
|
*/
|
554
556
|
|
555
557
|
VALUE
|
@@ -578,6 +580,12 @@ rb_ca_modify (VALUE self)
|
|
578
580
|
*/
|
579
581
|
}
|
580
582
|
|
583
|
+
/* @overload freeze
|
584
|
+
|
585
|
+
Freeze the object.
|
586
|
+
|
587
|
+
*/
|
588
|
+
|
581
589
|
VALUE
|
582
590
|
rb_ca_freeze (VALUE self)
|
583
591
|
{
|
@@ -598,6 +606,9 @@ Init_carray_test ()
|
|
598
606
|
rb_define_method(rb_cCArray, "freeze", rb_ca_freeze, 0);
|
599
607
|
|
600
608
|
rb_define_method(rb_cCArray, "==", rb_ca_equal, 1);
|
601
|
-
|
609
|
+
rb_define_alias(rb_cCArray, "eql?", "==");
|
602
610
|
rb_define_method(rb_cCArray, "hash", rb_ca_hash, 0);
|
611
|
+
|
612
|
+
rb_define_singleton_method(rb_cCArray, "data_class?", rb_ca_s_is_data_class, 1);
|
613
|
+
|
603
614
|
}
|
data/ext/carray_undef.c
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
carray_undef.c
|
4
4
|
|
5
5
|
This file is part of Ruby/CArray extension library.
|
6
|
-
You can redistribute it and/or modify it under the terms of
|
7
|
-
the Ruby Licence.
|
8
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
@@ -43,12 +41,6 @@ static VALUE rb_ud_equal (VALUE self, VALUE other)
|
|
43
41
|
return ( self == other ) ? Qtrue : Qfalse;
|
44
42
|
}
|
45
43
|
|
46
|
-
|
47
|
-
static VALUE rb_obj_is_undef (VALUE self)
|
48
|
-
{
|
49
|
-
return ( self == CA_UNDEF ) ? Qtrue : Qfalse;
|
50
|
-
}
|
51
|
-
|
52
44
|
void
|
53
45
|
Init_carray_undef ()
|
54
46
|
{
|
@@ -63,7 +55,5 @@ Init_carray_undef ()
|
|
63
55
|
CA_UNDEF = rb_funcall(rb_cUNDEF, rb_intern("new"), 0);
|
64
56
|
rb_undef_method(CLASS_OF(rb_cUNDEF), "new");
|
65
57
|
rb_const_set(rb_cObject, rb_intern("UNDEF"), CA_UNDEF);
|
66
|
-
|
67
|
-
rb_define_method(rb_cObject, "undef?", rb_obj_is_undef, 0);
|
68
58
|
}
|
69
59
|
|
data/ext/carray_utils.c
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
carray_utils.c
|
4
4
|
|
5
5
|
This file is part of Ruby/CArray extension library.
|
6
|
-
You can redistribute it and/or modify it under the terms of
|
7
|
-
the Ruby Licence.
|
8
6
|
|
9
|
-
Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
|
11
9
|
---------------------------------------------------------------------------- */
|
12
10
|
|
@@ -20,36 +18,10 @@
|
|
20
18
|
#include "st.h"
|
21
19
|
#endif
|
22
20
|
|
23
|
-
|
24
|
-
#define
|
25
|
-
|
26
|
-
|
27
|
-
RSTRUCT_ENUM_END
|
28
|
-
};
|
29
|
-
struct RStruct {
|
30
|
-
struct RBasic basic;
|
31
|
-
union {
|
32
|
-
struct {
|
33
|
-
long len;
|
34
|
-
const VALUE *ptr;
|
35
|
-
} heap;
|
36
|
-
const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
|
37
|
-
} as;
|
38
|
-
};
|
39
|
-
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
|
40
|
-
#endif
|
41
|
-
|
42
|
-
#if RUBY_VERSION_CODE >= 190
|
43
|
-
#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
|
44
|
-
#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
|
45
|
-
#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
|
46
|
-
#else
|
47
|
-
static ID id_beg, id_end, id_excl;
|
48
|
-
#define RANGE_BEG(r) (rb_ivar_get(r, id_beg))
|
49
|
-
#define RANGE_END(r) (rb_ivar_get(r, id_end))
|
50
|
-
#define RANGE_EXCL(r) (rb_ivar_get(r, id_excl))
|
51
|
-
#endif
|
52
|
-
|
21
|
+
static ID id_begin, id_end, id_excl_end;
|
22
|
+
#define RANGE_BEG(r) (rb_funcall(r, id_begin, 0))
|
23
|
+
#define RANGE_END(r) (rb_funcall(r, id_end, 0))
|
24
|
+
#define RANGE_EXCL(r) (rb_funcall(r, id_excl_end, 0))
|
53
25
|
|
54
26
|
/* ------------------------------------------------------------------- */
|
55
27
|
|
@@ -165,7 +137,7 @@ void
|
|
165
137
|
ca_parse_range (VALUE arg, ca_size_t size,
|
166
138
|
ca_size_t *poffset, ca_size_t *pcount, ca_size_t *pstep)
|
167
139
|
{
|
168
|
-
ca_size_t
|
140
|
+
ca_size_t start, last, count, step, bound, excl;
|
169
141
|
|
170
142
|
retry:
|
171
143
|
|
@@ -184,24 +156,59 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
184
156
|
}
|
185
157
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
186
158
|
/* i..j */
|
187
|
-
|
159
|
+
start = NUM2SIZE(RANGE_BEG(arg));
|
188
160
|
last = NUM2SIZE(RANGE_END(arg));
|
189
161
|
excl = RTEST(RANGE_EXCL(arg));
|
190
|
-
CA_CHECK_INDEX(
|
162
|
+
CA_CHECK_INDEX(start, size);
|
191
163
|
if ( last < 0 ) {
|
192
164
|
last += size;
|
193
165
|
}
|
194
166
|
if ( excl ) {
|
195
|
-
last += ( (last>=
|
167
|
+
last += ( (last>=start) ? -1 : 1 );
|
196
168
|
}
|
197
169
|
if ( last < 0 || last >= size ) {
|
198
170
|
rb_raise(rb_eIndexError,
|
199
171
|
"invalid index range");
|
200
172
|
}
|
201
|
-
*poffset =
|
202
|
-
*pcount = llabs(last -
|
173
|
+
*poffset = start;
|
174
|
+
*pcount = llabs(last - start) + 1;
|
203
175
|
*pstep = 1;
|
204
176
|
}
|
177
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
178
|
+
else if ( rb_obj_is_kind_of(arg, rb_cArithSeq) ) { /* ca[--,ArithSeq,--]*/
|
179
|
+
rb_arithmetic_sequence_components_t x;
|
180
|
+
rb_arithmetic_sequence_extract(arg, &x);
|
181
|
+
|
182
|
+
start = NUM2SIZE(x.begin);
|
183
|
+
last = NUM2SIZE(x.end);
|
184
|
+
excl = RTEST(x.exclude_end);
|
185
|
+
step = NUM2SIZE(x.step);
|
186
|
+
if ( step == 0 ) {
|
187
|
+
rb_raise(rb_eRuntimeError, "step should not be 0");
|
188
|
+
}
|
189
|
+
if ( last < 0 ) {
|
190
|
+
last += size;
|
191
|
+
}
|
192
|
+
if ( excl ) {
|
193
|
+
last += ( (last>=start) ? -1 : 1 );
|
194
|
+
}
|
195
|
+
if ( last < 0 || last >= size ) {
|
196
|
+
rb_raise(rb_eIndexError, "index out of range");
|
197
|
+
}
|
198
|
+
CA_CHECK_INDEX(start, size);
|
199
|
+
if ( (last - start) * step < 0 ) {
|
200
|
+
count = 1;
|
201
|
+
}
|
202
|
+
else {
|
203
|
+
count = llabs(last - start)/llabs(step) + 1;
|
204
|
+
}
|
205
|
+
bound = start + (count - 1)*step;
|
206
|
+
CA_CHECK_INDEX(bound, size);
|
207
|
+
*poffset = start;
|
208
|
+
*pcount = count;
|
209
|
+
*pstep = step;
|
210
|
+
}
|
211
|
+
#endif
|
205
212
|
else if ( TYPE(arg) == T_ARRAY ) {
|
206
213
|
if ( RARRAY_LEN(arg) == 1 ) { /* [nil] or [i..j] or [i] */
|
207
214
|
arg = rb_ary_entry(arg, 0);
|
@@ -254,6 +261,41 @@ ca_parse_range (VALUE arg, ca_size_t size,
|
|
254
261
|
*pcount = count;
|
255
262
|
*pstep = step;
|
256
263
|
}
|
264
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
265
|
+
else if ( rb_obj_is_kind_of(arg0, rb_cArithSeq) ) { /* ca[--,ArithSeq,--]*/
|
266
|
+
rb_arithmetic_sequence_components_t x;
|
267
|
+
rb_arithmetic_sequence_extract(arg0, &x);
|
268
|
+
|
269
|
+
start = NUM2SIZE(x.begin);
|
270
|
+
last = NUM2SIZE(x.end);
|
271
|
+
excl = RTEST(x.exclude_end);
|
272
|
+
step = NUM2SIZE(x.step);
|
273
|
+
if ( step == 0 ) {
|
274
|
+
rb_raise(rb_eRuntimeError, "step should not be 0");
|
275
|
+
}
|
276
|
+
if ( last < 0 ) {
|
277
|
+
last += size;
|
278
|
+
}
|
279
|
+
if ( excl ) {
|
280
|
+
last += ( (last>=start) ? -1 : 1 );
|
281
|
+
}
|
282
|
+
if ( last < 0 || last >= size ) {
|
283
|
+
rb_raise(rb_eIndexError, "index out of range");
|
284
|
+
}
|
285
|
+
CA_CHECK_INDEX(start, size);
|
286
|
+
if ( (last - start) * step < 0 ) {
|
287
|
+
count = 1;
|
288
|
+
}
|
289
|
+
else {
|
290
|
+
count = llabs(last - start)/llabs(step) + 1;
|
291
|
+
}
|
292
|
+
bound = start + (count - 1)*step;
|
293
|
+
CA_CHECK_INDEX(bound, size);
|
294
|
+
*poffset = start;
|
295
|
+
*pcount = count;
|
296
|
+
*pstep = step;
|
297
|
+
}
|
298
|
+
#endif
|
257
299
|
else { /* [i,n] */
|
258
300
|
start = NUM2SIZE(arg0);
|
259
301
|
count = NUM2SIZE(arg1);
|
@@ -292,7 +334,7 @@ void
|
|
292
334
|
ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
293
335
|
ca_size_t *poffset, ca_size_t *pcount, ca_size_t *pstep)
|
294
336
|
{
|
295
|
-
ca_size_t
|
337
|
+
ca_size_t start, last, count, step, bound, excl;
|
296
338
|
|
297
339
|
retry:
|
298
340
|
|
@@ -310,16 +352,35 @@ ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
310
352
|
}
|
311
353
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
312
354
|
/* i..j */
|
313
|
-
|
355
|
+
start = NUM2SIZE(RANGE_BEG(arg));
|
314
356
|
last = NUM2SIZE(RANGE_END(arg));
|
315
357
|
excl = RTEST(RANGE_EXCL(arg));
|
316
358
|
if ( excl ) {
|
317
|
-
last += ( (last>=
|
359
|
+
last += ( (last>=start) ? -1 : 1 );
|
318
360
|
}
|
319
|
-
*poffset =
|
320
|
-
*pcount = last -
|
361
|
+
*poffset = start;
|
362
|
+
*pcount = last - start + 1;
|
321
363
|
*pstep = 1;
|
322
364
|
}
|
365
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
366
|
+
else if ( rb_obj_is_kind_of(arg, rb_cArithSeq) ) { /* ca[--,ArithSeq,--]*/
|
367
|
+
rb_arithmetic_sequence_components_t x;
|
368
|
+
rb_arithmetic_sequence_extract(arg, &x);
|
369
|
+
|
370
|
+
start = NUM2SIZE(x.begin);
|
371
|
+
last = NUM2SIZE(x.end);
|
372
|
+
excl = RTEST(x.exclude_end);
|
373
|
+
step = NUM2SIZE(x.step);
|
374
|
+
if ( excl ) {
|
375
|
+
last += ( (last>=start) ? -1 : 1 );
|
376
|
+
}
|
377
|
+
count = (last - start)/llabs(step) + 1;
|
378
|
+
bound = start + (count - 1)*step;
|
379
|
+
*poffset = start;
|
380
|
+
*pcount = count;
|
381
|
+
*pstep = step;
|
382
|
+
}
|
383
|
+
#endif
|
323
384
|
else if ( TYPE(arg) == T_ARRAY ) {
|
324
385
|
if ( RARRAY_LEN(arg) == 1 ) { /* [nil] or [i..j] or [i] */
|
325
386
|
arg = rb_ary_entry(arg, 0);
|
@@ -351,6 +412,25 @@ ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
351
412
|
*pcount = count;
|
352
413
|
*pstep = step;
|
353
414
|
}
|
415
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
416
|
+
else if ( rb_obj_is_kind_of(arg0, rb_cArithSeq) ) { /* ca[--,ArithSeq,--]*/
|
417
|
+
rb_arithmetic_sequence_components_t x;
|
418
|
+
rb_arithmetic_sequence_extract(arg0, &x);
|
419
|
+
|
420
|
+
start = NUM2SIZE(x.begin);
|
421
|
+
last = NUM2SIZE(x.end);
|
422
|
+
excl = RTEST(x.exclude_end);
|
423
|
+
step = NUM2SIZE(x.step);
|
424
|
+
if ( excl ) {
|
425
|
+
last += ( (last>=start) ? -1 : 1 );
|
426
|
+
}
|
427
|
+
count = (last - start)/llabs(step) + 1;
|
428
|
+
bound = start + (count - 1)*step;
|
429
|
+
*poffset = start;
|
430
|
+
*pcount = count;
|
431
|
+
*pstep = step;
|
432
|
+
}
|
433
|
+
#endif
|
354
434
|
else { /* [i,n] */
|
355
435
|
start = NUM2SIZE(arg0);
|
356
436
|
count = NUM2SIZE(arg1);
|
@@ -422,6 +502,11 @@ ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k)
|
|
422
502
|
}
|
423
503
|
}
|
424
504
|
|
505
|
+
/* @private
|
506
|
+
@overload scan_float (str, fill_value=nil)
|
507
|
+
|
508
|
+
*/
|
509
|
+
|
425
510
|
static VALUE
|
426
511
|
rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
|
427
512
|
{
|
@@ -447,6 +532,11 @@ rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
|
|
447
532
|
}
|
448
533
|
}
|
449
534
|
|
535
|
+
/* @private
|
536
|
+
@overload scan_int (str, fill_value=nil)
|
537
|
+
|
538
|
+
*/
|
539
|
+
|
450
540
|
static VALUE
|
451
541
|
rb_ca_s_scan_int (int argc, VALUE *argv, VALUE self)
|
452
542
|
{
|
@@ -564,7 +654,7 @@ rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
|
564
654
|
}
|
565
655
|
}
|
566
656
|
|
567
|
-
/*
|
657
|
+
/* @private
|
568
658
|
def CArray.guess_type_and_bytes (type, bytes=0)
|
569
659
|
end
|
570
660
|
*/
|
@@ -742,12 +832,9 @@ rb_set_options (VALUE ropt, const char *spec_in, ...)
|
|
742
832
|
void
|
743
833
|
Init_carray_utils ()
|
744
834
|
{
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
id_end = rb_intern("end");
|
749
|
-
id_excl = rb_intern("excl");
|
750
|
-
#endif
|
835
|
+
id_begin = rb_intern("begin");
|
836
|
+
id_end = rb_intern("end");
|
837
|
+
id_excl_end = rb_intern("exclude_end?");
|
751
838
|
|
752
839
|
rb_define_singleton_method(rb_cCArray, "_scan_float",
|
753
840
|
rb_ca_s_scan_float, -1);
|