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/ca_obj_window.c
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
ca_obj_window.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
|
|
@@ -17,7 +15,7 @@
|
|
17
15
|
VALUE rb_cCAWindow;
|
18
16
|
int8_t CA_OBJ_WINDOW;
|
19
17
|
|
20
|
-
/*
|
18
|
+
/* yard:
|
21
19
|
class CAWindow < CAVirtual # :nodoc:
|
22
20
|
end
|
23
21
|
*/
|
@@ -703,7 +701,7 @@ rb_ca_window_new (VALUE cary,
|
|
703
701
|
return obj;
|
704
702
|
}
|
705
703
|
|
706
|
-
/*
|
704
|
+
/* yard:
|
707
705
|
class CArray
|
708
706
|
def window (*argv)
|
709
707
|
end
|
@@ -837,7 +835,7 @@ rb_ca_window_initialize_copy (VALUE self, VALUE other)
|
|
837
835
|
return self;
|
838
836
|
}
|
839
837
|
|
840
|
-
/*
|
838
|
+
/* yard:
|
841
839
|
class CAWindow
|
842
840
|
def index2addr0 (idx)
|
843
841
|
end
|
@@ -874,7 +872,7 @@ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
|
|
874
872
|
}
|
875
873
|
}
|
876
874
|
|
877
|
-
/*
|
875
|
+
/* yard:
|
878
876
|
class CAWindow
|
879
877
|
def addr2addr0 (addr)
|
880
878
|
end
|
@@ -928,7 +926,7 @@ rb_ca_window_move (int argc, VALUE *argv, VALUE self)
|
|
928
926
|
return self;
|
929
927
|
}
|
930
928
|
|
931
|
-
/*
|
929
|
+
/* yard:
|
932
930
|
class CAWindow
|
933
931
|
def fill_value
|
934
932
|
end
|
@@ -976,7 +974,7 @@ rb_ca_window_get_bounds (VALUE self)
|
|
976
974
|
return ary; \
|
977
975
|
}
|
978
976
|
|
979
|
-
/*
|
977
|
+
/* yard:
|
980
978
|
class CAWindow
|
981
979
|
def size0
|
982
980
|
end
|
data/ext/carray.h
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
carray.h
|
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
|
|
@@ -15,6 +13,10 @@
|
|
15
13
|
|
16
14
|
#include "ruby.h"
|
17
15
|
|
16
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
17
|
+
extern VALUE rb_cArithSeq;
|
18
|
+
#endif
|
19
|
+
|
18
20
|
/* -------------------------------------------------------------------- */
|
19
21
|
|
20
22
|
#include "carray_config.h"
|
@@ -760,6 +762,7 @@ typedef struct {
|
|
760
762
|
CArray *select;
|
761
763
|
VALUE block;
|
762
764
|
VALUE symbol;
|
765
|
+
int8_t range_check;
|
763
766
|
} CAIndexInfo;
|
764
767
|
|
765
768
|
/* -------------------------------------------------------------------- */
|
@@ -785,10 +788,10 @@ VALUE rb_ca_call_binop (VALUE self, VALUE other, ca_binop_func_t func[]);
|
|
785
788
|
VALUE rb_ca_call_binop_bang (VALUE self, VALUE other, ca_binop_func_t func[]);
|
786
789
|
VALUE rb_ca_call_moncmp (VALUE self, ca_moncmp_func_t func[]);
|
787
790
|
VALUE rb_ca_call_bincmp (VALUE self, VALUE other, ca_bincmp_func_t func[]);
|
788
|
-
void ca_monop_not_implement(ca_size_t n, char *ptr1, char *ptr2);
|
789
|
-
void ca_binop_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3);
|
790
|
-
void ca_moncmp_not_implement(ca_size_t n, char *ptr1, char *ptr2);
|
791
|
-
void ca_bincmp_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3);
|
791
|
+
void ca_monop_not_implement(ca_size_t n, char *ptr1, char *ptr2) __attribute__((noreturn));
|
792
|
+
void ca_binop_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3) __attribute__((noreturn));
|
793
|
+
void ca_moncmp_not_implement(ca_size_t n, char *ptr1, char *ptr2) __attribute__((noreturn));
|
794
|
+
void ca_bincmp_not_implement(ca_size_t n, char *ptr1, char *ptr2, char *ptr3) __attribute__((noreturn));
|
792
795
|
VALUE ca_math_call (VALUE mod, VALUE arg, ID id);
|
793
796
|
|
794
797
|
/* -------------------------------------------------------------------- */
|
@@ -819,6 +822,9 @@ VALUE rb_carray_new (int8_t data_type,
|
|
819
822
|
VALUE rb_carray_new_safe (int8_t data_type,
|
820
823
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask);
|
821
824
|
|
825
|
+
VALUE rb_ca_wrap_new (int8_t data_type,
|
826
|
+
int8_t ndim, ca_size_t *dim, ca_size_t bytes, CArray *mask, char *ptr);
|
827
|
+
|
822
828
|
CAWrap *ca_wrap_new (int8_t data_type,
|
823
829
|
int8_t ndim, ca_size_t *dim, ca_size_t bytes,
|
824
830
|
CArray *mask, char *ptr);
|
@@ -888,6 +894,9 @@ CARepeat *ca_repeat_new (CArray *carray, int8_t ndim, ca_size_t *count);
|
|
888
894
|
VALUE rb_ca_repeat_new (VALUE cary, int8_t ndim, ca_size_t *count);
|
889
895
|
VALUE rb_ca_repeat (int argc, VALUE *argv, VALUE self);
|
890
896
|
|
897
|
+
/* --- ca_obj_unbound_repeat.c --- */
|
898
|
+
|
899
|
+
VALUE rb_ca_ubrep_shave (VALUE self, VALUE other);
|
891
900
|
VALUE rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim);
|
892
901
|
VALUE ca_ubrep_bind_with (VALUE self, VALUE other);
|
893
902
|
|
@@ -1064,7 +1073,7 @@ void ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
|
1064
1073
|
ca_size_t *offset, ca_size_t *count, ca_size_t *step);
|
1065
1074
|
|
1066
1075
|
int ca_equal (void *ap, void *bp);
|
1067
|
-
void ca_zerodiv(void);
|
1076
|
+
void ca_zerodiv(void) __attribute__((noreturn));
|
1068
1077
|
int32_t ca_rand (double rmax);
|
1069
1078
|
ca_size_t ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k);
|
1070
1079
|
|
data/ext/carray_access.c
CHANGED
@@ -3,44 +3,17 @@
|
|
3
3
|
carray_access.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
|
|
13
11
|
#include "carray.h"
|
14
12
|
|
15
|
-
|
16
|
-
#define
|
17
|
-
|
18
|
-
|
19
|
-
RSTRUCT_ENUM_END
|
20
|
-
};
|
21
|
-
struct RStruct {
|
22
|
-
struct RBasic basic;
|
23
|
-
union {
|
24
|
-
struct {
|
25
|
-
long len;
|
26
|
-
const VALUE *ptr;
|
27
|
-
} heap;
|
28
|
-
const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
|
29
|
-
} as;
|
30
|
-
};
|
31
|
-
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
|
32
|
-
#endif
|
33
|
-
|
34
|
-
#if RUBY_VERSION_CODE >= 190
|
35
|
-
#define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0])
|
36
|
-
#define RANGE_END(r) (RSTRUCT(r)->as.ary[1])
|
37
|
-
#define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2])
|
38
|
-
#else
|
39
|
-
static ID id_beg, id_end, id_excl;
|
40
|
-
#define RANGE_BEG(r) (rb_ivar_get(r, id_beg))
|
41
|
-
#define RANGE_END(r) (rb_ivar_get(r, id_end))
|
42
|
-
#define RANGE_EXCL(r) (rb_ivar_get(r, id_excl))
|
43
|
-
#endif
|
13
|
+
static ID id_begin, id_end, id_excl_end;
|
14
|
+
#define RANGE_BEG(r) (rb_funcall(r, id_begin, 0))
|
15
|
+
#define RANGE_END(r) (rb_funcall(r, id_end, 0))
|
16
|
+
#define RANGE_EXCL(r) (rb_funcall(r, id_excl_end, 0))
|
44
17
|
|
45
18
|
static ID id_ca, id_to_ca;
|
46
19
|
static VALUE sym_star, sym_perc;
|
@@ -208,7 +181,7 @@ rb_ca_fetch_addr (VALUE self, ca_size_t addr)
|
|
208
181
|
return out;
|
209
182
|
}
|
210
183
|
|
211
|
-
/*
|
184
|
+
/* yard:
|
212
185
|
class CArray
|
213
186
|
def fill
|
214
187
|
end
|
@@ -293,7 +266,7 @@ ary_guess_shape (VALUE ary, int level, int *max_level, ca_size_t *dim)
|
|
293
266
|
}
|
294
267
|
}
|
295
268
|
|
296
|
-
/*
|
269
|
+
/* yard:
|
297
270
|
def CArray.guess_array_shape (arg)
|
298
271
|
end
|
299
272
|
*/
|
@@ -533,7 +506,9 @@ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
533
506
|
info->type = CA_REG_ADDRESS;
|
534
507
|
info->ndim = 1;
|
535
508
|
addr = NUM2SIZE(arg);
|
536
|
-
|
509
|
+
if ( info->range_check ) {
|
510
|
+
CA_CHECK_INDEX(addr, ca_elements);
|
511
|
+
}
|
537
512
|
info->index[0].scalar = addr;
|
538
513
|
return;
|
539
514
|
}
|
@@ -594,7 +569,9 @@ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
594
569
|
ca_size_t scalar;
|
595
570
|
index_type[i] = CA_IDX_SCALAR;
|
596
571
|
scalar = NUM2SIZE(arg);
|
597
|
-
|
572
|
+
if ( info->range_check ) {
|
573
|
+
CA_CHECK_INDEX_AT(scalar, ca_dim[i], i);
|
574
|
+
}
|
598
575
|
index[i].scalar = scalar;
|
599
576
|
}
|
600
577
|
else if ( NIL_P(arg) ) { /* ca[--,nil,--] */
|
@@ -612,17 +589,17 @@ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
612
589
|
info->ndim = ca_ndim;
|
613
590
|
}
|
614
591
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) { /* ca[--,i..j,--] */
|
615
|
-
ca_size_t
|
592
|
+
ca_size_t start, last, excl, count, step;
|
616
593
|
volatile VALUE iv_beg, iv_end, iv_excl;
|
617
594
|
iv_beg = RANGE_BEG(arg);
|
618
595
|
iv_end = RANGE_END(arg);
|
619
596
|
iv_excl = RANGE_EXCL(arg);
|
620
597
|
index_type[i] = CA_IDX_BLOCK; /* convert to block */
|
621
598
|
if ( NIL_P(iv_beg) ) {
|
622
|
-
|
599
|
+
start = 0;
|
623
600
|
}
|
624
601
|
else {
|
625
|
-
|
602
|
+
start = NUM2SIZE(iv_beg);
|
626
603
|
}
|
627
604
|
if ( NIL_P(iv_end) ) {
|
628
605
|
last = -1;
|
@@ -631,30 +608,95 @@ rb_ca_scan_index (int ca_ndim, ca_size_t *ca_dim, ca_size_t ca_elements,
|
|
631
608
|
last = NUM2SIZE(iv_end);
|
632
609
|
}
|
633
610
|
excl = RTEST(iv_excl);
|
634
|
-
|
611
|
+
|
612
|
+
if ( info->range_check ) {
|
613
|
+
CA_CHECK_INDEX_AT(start, ca_dim[i], i);
|
614
|
+
}
|
635
615
|
|
636
616
|
if ( last < 0 ) { /* don't use CA_CHECK_INDEX for excl */
|
637
617
|
last += ca_dim[i];
|
638
618
|
}
|
639
|
-
if ( excl && (
|
640
|
-
index[i].block.start =
|
619
|
+
if ( excl && ( start == last ) ) {
|
620
|
+
index[i].block.start = start;
|
621
|
+
index[i].block.count = 0;
|
622
|
+
index[i].block.step = 1;
|
623
|
+
}
|
624
|
+
else {
|
625
|
+
if ( excl ) {
|
626
|
+
last += ( (last>=start) ? -1 : 1 );
|
627
|
+
}
|
628
|
+
if ( info->range_check ) {
|
629
|
+
if ( last < 0 || last >= ca_dim[i] ) {
|
630
|
+
rb_raise(rb_eIndexError,
|
631
|
+
"index %lld is out of range (0..%lld) at %i-dim",
|
632
|
+
(ca_size_t) last, (ca_size_t) (ca_dim[i]-1), i);
|
633
|
+
}
|
634
|
+
}
|
635
|
+
index[i].block.start = start;
|
636
|
+
index[i].block.count = count = llabs(last - start) + 1;
|
637
|
+
index[i].block.step = step = ( last >= start ) ? 1 : -1;
|
638
|
+
}
|
639
|
+
}
|
640
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
641
|
+
else if ( rb_obj_is_kind_of(arg, rb_cArithSeq) ) { /* ca[--,ArithSeq,--]*/
|
642
|
+
ca_size_t start, last, excl, count, step, bound;
|
643
|
+
volatile VALUE iv_beg, iv_end, iv_excl;
|
644
|
+
rb_arithmetic_sequence_components_t x;
|
645
|
+
rb_arithmetic_sequence_extract(arg, &x);
|
646
|
+
iv_beg = x.begin;
|
647
|
+
iv_end = x.end;
|
648
|
+
iv_excl = x.exclude_end;
|
649
|
+
step = NUM2SIZE(x.step);
|
650
|
+
if ( NIL_P(iv_beg) ) {
|
651
|
+
start = 0;
|
652
|
+
}
|
653
|
+
else {
|
654
|
+
start = NUM2SIZE(iv_beg);
|
655
|
+
}
|
656
|
+
if ( NIL_P(iv_end) ) {
|
657
|
+
last = -1;
|
658
|
+
}
|
659
|
+
else {
|
660
|
+
last = NUM2SIZE(iv_end);
|
661
|
+
}
|
662
|
+
excl = RTEST(iv_excl);
|
663
|
+
if ( step == 0 ) {
|
664
|
+
rb_raise(rb_eRuntimeError,
|
665
|
+
"step in index equals to 0 in block reference");
|
666
|
+
}
|
667
|
+
index_type[i] = CA_IDX_BLOCK;
|
668
|
+
CA_CHECK_INDEX_AT(start, ca_dim[i], i);
|
669
|
+
if ( last < 0 ) {
|
670
|
+
last += ca_dim[i];
|
671
|
+
}
|
672
|
+
if ( excl && ( start == last ) ) {
|
673
|
+
index[i].block.start = start;
|
641
674
|
index[i].block.count = 0;
|
642
675
|
index[i].block.step = 1;
|
643
676
|
}
|
644
677
|
else {
|
645
678
|
if ( excl ) {
|
646
|
-
last += ( (last>=
|
679
|
+
last += ( (last>=start) ? -1 : 1 );
|
647
680
|
}
|
648
681
|
if ( last < 0 || last >= ca_dim[i] ) {
|
649
682
|
rb_raise(rb_eIndexError,
|
650
683
|
"index %lld is out of range (0..%lld) at %i-dim",
|
651
684
|
(ca_size_t) last, (ca_size_t) (ca_dim[i]-1), i);
|
652
685
|
}
|
653
|
-
|
654
|
-
|
655
|
-
|
686
|
+
if ( (last - start) * step < 0 ) {
|
687
|
+
count = 1;
|
688
|
+
}
|
689
|
+
else {
|
690
|
+
count = llabs(last - start)/llabs(step) + 1;
|
691
|
+
}
|
692
|
+
bound = start + (count - 1)*step;
|
693
|
+
CA_CHECK_INDEX_AT(bound, ca_dim[i], i);
|
694
|
+
index[i].block.start = start;
|
695
|
+
index[i].block.count = count;
|
696
|
+
index[i].block.step = step;
|
656
697
|
}
|
657
698
|
}
|
699
|
+
#endif
|
658
700
|
else if ( TYPE(arg) == T_ARRAY ) { /* ca[--,[array],--] */
|
659
701
|
if ( RARRAY_LEN(arg) == 1 ) {
|
660
702
|
VALUE arg0 = rb_ary_entry(arg, 0);
|
@@ -1254,7 +1296,7 @@ rb_ca_refer_new_flatten (VALUE self)
|
|
1254
1296
|
return rb_ca_refer_new(self, ca->data_type, 1, &dim0, ca->bytes, 0);
|
1255
1297
|
}
|
1256
1298
|
|
1257
|
-
/*
|
1299
|
+
/* yard:
|
1258
1300
|
class CArray
|
1259
1301
|
def [] (*spec)
|
1260
1302
|
end
|
@@ -1271,6 +1313,8 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
|
|
1271
1313
|
retry:
|
1272
1314
|
|
1273
1315
|
Data_Get_Struct(self, CArray, ca);
|
1316
|
+
|
1317
|
+
info.range_check = 1;
|
1274
1318
|
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
|
1275
1319
|
|
1276
1320
|
switch ( info.type ) {
|
@@ -1340,7 +1384,86 @@ rb_ca_fetch_method (int argc, VALUE *argv, VALUE self)
|
|
1340
1384
|
return obj;
|
1341
1385
|
}
|
1342
1386
|
|
1343
|
-
|
1387
|
+
static VALUE
|
1388
|
+
rb_cs_fetch_method (int argc, VALUE *argv, VALUE self)
|
1389
|
+
{
|
1390
|
+
volatile VALUE obj = Qnil;
|
1391
|
+
CArray *ca;
|
1392
|
+
CAIndexInfo info;
|
1393
|
+
|
1394
|
+
Data_Get_Struct(self, CArray, ca);
|
1395
|
+
|
1396
|
+
info.range_check = 0;
|
1397
|
+
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
|
1398
|
+
|
1399
|
+
switch ( info.type ) {
|
1400
|
+
case CA_REG_ADDRESS_COMPLEX:
|
1401
|
+
obj = rb_ca_fetch_addr(self, 0);
|
1402
|
+
break;
|
1403
|
+
case CA_REG_ADDRESS:
|
1404
|
+
obj = rb_ca_fetch_addr(self, 0);
|
1405
|
+
break;
|
1406
|
+
case CA_REG_FLATTEN:
|
1407
|
+
obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
|
1408
|
+
break;
|
1409
|
+
case CA_REG_POINT:
|
1410
|
+
obj = rb_ca_fetch_addr(self, 0);
|
1411
|
+
break;
|
1412
|
+
case CA_REG_ALL:
|
1413
|
+
obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
|
1414
|
+
break;
|
1415
|
+
case CA_REG_BLOCK:
|
1416
|
+
obj = self; /* rb_funcall(self, rb_intern("refer"), 0); */
|
1417
|
+
break;
|
1418
|
+
case CA_REG_SELECT:
|
1419
|
+
obj = rb_ca_select_new(self, argv[0]);
|
1420
|
+
break;
|
1421
|
+
case CA_REG_ITERATOR:
|
1422
|
+
obj = rb_dim_iter_new(self, &info);
|
1423
|
+
break;
|
1424
|
+
case CA_REG_REPEAT:
|
1425
|
+
obj = rb_ca_repeat(argc, argv, self);
|
1426
|
+
break;
|
1427
|
+
case CA_REG_UNBOUND_REPEAT:
|
1428
|
+
obj = rb_funcall2(self, rb_intern("unbound_repeat"), (int) argc, argv);
|
1429
|
+
break;
|
1430
|
+
case CA_REG_MAPPING:
|
1431
|
+
obj = rb_ca_mapping(argc, argv, self);
|
1432
|
+
break;
|
1433
|
+
case CA_REG_GRID:
|
1434
|
+
obj = rb_ca_grid(argc, argv, self);
|
1435
|
+
break;
|
1436
|
+
case CA_REG_METHOD_CALL: {
|
1437
|
+
volatile VALUE idx;
|
1438
|
+
idx = rb_funcall2(self, SYM2ID(info.symbol), argc-1, argv+1);
|
1439
|
+
obj = rb_ca_fetch(self, idx);
|
1440
|
+
break;
|
1441
|
+
}
|
1442
|
+
case CA_REG_MEMBER: {
|
1443
|
+
volatile VALUE data_class = rb_ca_data_class(self);
|
1444
|
+
if ( ! NIL_P(data_class) ) {
|
1445
|
+
obj = rb_ca_field_as_member(self, info.symbol);
|
1446
|
+
break;
|
1447
|
+
}
|
1448
|
+
else {
|
1449
|
+
rb_raise(rb_eIndexError,
|
1450
|
+
"can't refer member of carray doesn't have data_class");
|
1451
|
+
}
|
1452
|
+
break;
|
1453
|
+
}
|
1454
|
+
case CA_REG_ATTRIBUTE: {
|
1455
|
+
obj = rb_funcall(self, rb_intern("attribute"), 0);
|
1456
|
+
obj = rb_hash_aref(obj, info.symbol);
|
1457
|
+
break;
|
1458
|
+
}
|
1459
|
+
default:
|
1460
|
+
rb_raise(rb_eIndexError, "invalid index specified");
|
1461
|
+
}
|
1462
|
+
|
1463
|
+
return obj;
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
/* yard:
|
1344
1467
|
class CArray
|
1345
1468
|
def []= (*spec)
|
1346
1469
|
end
|
@@ -1363,6 +1486,7 @@ rb_ca_store_method (int argc, VALUE *argv, VALUE self)
|
|
1363
1486
|
|
1364
1487
|
Data_Get_Struct(self, CArray, ca);
|
1365
1488
|
|
1489
|
+
info.range_check = 1;
|
1366
1490
|
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
|
1367
1491
|
|
1368
1492
|
switch ( info.type ) {
|
@@ -1487,7 +1611,7 @@ rb_ca_store2 (VALUE self, int n, VALUE *rindex, VALUE rval)
|
|
1487
1611
|
return rb_ca_store_method((int)RARRAY_LEN(index), RARRAY_PTR(index), self);
|
1488
1612
|
}
|
1489
1613
|
|
1490
|
-
/*
|
1614
|
+
/* yard:
|
1491
1615
|
def CArray.scan_index(dim, idx)
|
1492
1616
|
end
|
1493
1617
|
*/
|
@@ -1515,6 +1639,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
|
|
1515
1639
|
CA_CHECK_RANK(ndim);
|
1516
1640
|
CA_CHECK_DIM(ndim, dim);
|
1517
1641
|
|
1642
|
+
info.range_check = 1;
|
1518
1643
|
rb_ca_scan_index(ndim, dim, elements,
|
1519
1644
|
RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
|
1520
1645
|
|
@@ -1596,7 +1721,7 @@ rb_ca_s_scan_index (VALUE self, VALUE rdim, VALUE ridx)
|
|
1596
1721
|
return rb_struct_new(S_CAInfo, rtype, rindex);
|
1597
1722
|
}
|
1598
1723
|
|
1599
|
-
/*
|
1724
|
+
/* yard:
|
1600
1725
|
class CArray
|
1601
1726
|
def normalize_index (idx)
|
1602
1727
|
end
|
@@ -1614,6 +1739,7 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
|
|
1614
1739
|
Data_Get_Struct(self, CArray, ca);
|
1615
1740
|
Check_Type(ridx, T_ARRAY);
|
1616
1741
|
|
1742
|
+
info.range_check = 1;
|
1617
1743
|
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements,
|
1618
1744
|
RARRAY_LEN(ridx), RARRAY_PTR(ridx), &info);
|
1619
1745
|
|
@@ -1668,7 +1794,7 @@ rb_ca_normalize_index (VALUE self, VALUE ridx)
|
|
1668
1794
|
|
1669
1795
|
/* ------------------------------------------------------------------- */
|
1670
1796
|
|
1671
|
-
/*
|
1797
|
+
/* yard:
|
1672
1798
|
class CArray
|
1673
1799
|
# converts addr to index
|
1674
1800
|
def addr2index (addr)
|
@@ -1703,7 +1829,7 @@ rb_ca_addr2index (VALUE self, VALUE raddr)
|
|
1703
1829
|
return out;
|
1704
1830
|
}
|
1705
1831
|
|
1706
|
-
/*
|
1832
|
+
/* yard:
|
1707
1833
|
class CArray
|
1708
1834
|
def index2addr (*index)
|
1709
1835
|
end
|
@@ -1823,12 +1949,9 @@ void
|
|
1823
1949
|
Init_carray_access ()
|
1824
1950
|
{
|
1825
1951
|
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
id_end = rb_intern("end");
|
1830
|
-
id_excl = rb_intern("excl");
|
1831
|
-
#endif
|
1952
|
+
id_begin = rb_intern("begin");
|
1953
|
+
id_end = rb_intern("end");
|
1954
|
+
id_excl_end = rb_intern("exclude_end?");
|
1832
1955
|
|
1833
1956
|
id_ca = rb_intern("ca");
|
1834
1957
|
id_to_ca = rb_intern("to_ca");
|
@@ -1838,6 +1961,8 @@ Init_carray_access ()
|
|
1838
1961
|
rb_define_method(rb_cCArray, "[]", rb_ca_fetch_method, -1);
|
1839
1962
|
rb_define_method(rb_cCArray, "[]=", rb_ca_store_method, -1);
|
1840
1963
|
|
1964
|
+
rb_define_method(rb_cCScalar, "[]", rb_cs_fetch_method, -1);
|
1965
|
+
|
1841
1966
|
rb_define_method(rb_cCArray, "fill", rb_ca_fill, 1);
|
1842
1967
|
rb_define_method(rb_cCArray, "fill_copy", rb_ca_fill_copy, 1);
|
1843
1968
|
|