carray 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSES +22 -0
- data/README.md +18 -14
- data/Rakefile +1 -1
- data/carray.gemspec +5 -13
- data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
- data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
- data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
- data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
- data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
- data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
- data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
- data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
- data/{carray.h → ext/carray.h} +73 -51
- data/{carray_access.c → ext/carray_access.c} +83 -83
- data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
- data/{carray_cast.c → ext/carray_cast.c} +6 -6
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
- data/{carray_class.c → ext/carray_class.c} +0 -0
- data/{carray_conversion.c → ext/carray_conversion.c} +8 -10
- data/{carray_copy.c → ext/carray_copy.c} +19 -19
- data/{carray_core.c → ext/carray_core.c} +2 -2
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +9 -9
- data/{carray_generate.c → ext/carray_generate.c} +0 -0
- data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
- data/{carray_loop.c → ext/carray_loop.c} +24 -24
- data/{carray_mask.c → ext/carray_mask.c} +17 -6
- data/{carray_math.rb → ext/carray_math.rb} +3 -3
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
- data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
- data/{carray_operator.c → ext/carray_operator.c} +9 -9
- data/{carray_order.c → ext/carray_order.c} +2 -153
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
- data/{carray_stat.c → ext/carray_stat.c} +5 -5
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
- data/{carray_test.c → ext/carray_test.c} +22 -21
- data/{carray_undef.c → ext/carray_undef.c} +0 -0
- data/{carray_utils.c → ext/carray_utils.c} +0 -0
- data/{extconf.rb → ext/extconf.rb} +0 -5
- data/{mkmath.rb → ext/mkmath.rb} +0 -0
- data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
- data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
- data/{version.h → ext/version.h} +5 -5
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +48 -37
- data/lib/carray/{base/autoload.rb → autoload.rb} +1 -1
- data/lib/carray/autoload/autoload_base.rb +1 -1
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +4 -3
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/basic.rb +193 -0
- data/lib/carray/compose.rb +291 -0
- data/lib/carray/construct.rb +445 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
- data/lib/carray/io/imagemagick.rb +1 -1
- data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
- data/lib/carray/mask.rb +91 -0
- data/lib/carray/{base/math.rb → math.rb} +16 -46
- data/lib/carray/math/histogram.rb +7 -7
- data/lib/carray/mkmf.rb +8 -0
- data/lib/carray/object/ca_obj_pack.rb +8 -8
- data/lib/carray/obsolete.rb +272 -0
- data/lib/carray/ordering.rb +157 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
- data/lib/carray/{base/string.rb → string.rb} +12 -64
- data/lib/carray/{base/struct.rb → struct.rb} +16 -16
- data/lib/carray/{io/table.rb → table.rb} +1 -10
- data/lib/carray/testing.rb +56 -0
- data/lib/carray/time.rb +78 -0
- data/lib/carray/transform.rb +100 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/test/test_ALL.rb +0 -2
- data/test/test_order.rb +7 -7
- data/test/test_ref_store.rb +13 -13
- data/test/test_stat.rb +7 -15
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +88 -151
- data/COPYING +0 -56
- data/GPL +0 -340
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/devel/im2col.rb +0 -17
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1146
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/test/test_narray.rb +0 -64
- data/test/test_random.rb +0 -15
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
@@ -22,7 +22,7 @@ VALUE rb_cCASelect;
|
|
22
22
|
typedef struct {
|
23
23
|
int16_t obj_type;
|
24
24
|
int8_t data_type;
|
25
|
-
int8_t
|
25
|
+
int8_t ndim;
|
26
26
|
int32_t flags;
|
27
27
|
ca_size_t bytes;
|
28
28
|
ca_size_t elements;
|
@@ -58,7 +58,7 @@ ca_select_setup (CASelect *ca, CArray *parent, CArray *select, int share)
|
|
58
58
|
ca->obj_type = CA_OBJ_SELECT;
|
59
59
|
ca->data_type = data_type;
|
60
60
|
ca->flags = 0;
|
61
|
-
ca->
|
61
|
+
ca->ndim = 1;
|
62
62
|
ca->bytes = bytes;
|
63
63
|
|
64
64
|
if ( share && ca_is_entity(select) ) {
|
@@ -22,7 +22,7 @@ static VALUE rb_cCAShift;
|
|
22
22
|
typedef struct {
|
23
23
|
int16_t obj_type;
|
24
24
|
int8_t data_type;
|
25
|
-
int8_t
|
25
|
+
int8_t ndim;
|
26
26
|
int32_t flags;
|
27
27
|
ca_size_t bytes;
|
28
28
|
ca_size_t elements;
|
@@ -47,35 +47,35 @@ int
|
|
47
47
|
ca_shift_setup (CAShift *ca, CArray *parent,
|
48
48
|
ca_size_t *shift, char *fill, int8_t *roll)
|
49
49
|
{
|
50
|
-
int8_t data_type,
|
50
|
+
int8_t data_type, ndim;
|
51
51
|
ca_size_t elements, bytes;
|
52
52
|
|
53
53
|
data_type = parent->data_type;
|
54
54
|
bytes = parent->bytes;
|
55
|
-
|
55
|
+
ndim = parent->ndim;
|
56
56
|
elements = parent->elements;
|
57
57
|
|
58
58
|
|
59
59
|
ca->obj_type = CA_OBJ_SHIFT;
|
60
60
|
ca->data_type = data_type;
|
61
61
|
ca->flags = 0;
|
62
|
-
ca->
|
62
|
+
ca->ndim = ndim;
|
63
63
|
ca->bytes = bytes;
|
64
64
|
ca->elements = elements;
|
65
65
|
ca->ptr = NULL;
|
66
66
|
ca->mask = NULL;
|
67
|
-
ca->dim = ALLOC_N(ca_size_t,
|
67
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
68
68
|
|
69
69
|
ca->parent = parent;
|
70
70
|
ca->attach = 0;
|
71
71
|
ca->nosync = 0;
|
72
|
-
ca->shift = ALLOC_N(ca_size_t,
|
72
|
+
ca->shift = ALLOC_N(ca_size_t, ndim);
|
73
73
|
ca->fill = ALLOC_N(char, ca->bytes);
|
74
|
-
ca->roll = ALLOC_N(int8_t,
|
74
|
+
ca->roll = ALLOC_N(int8_t, ndim);
|
75
75
|
|
76
|
-
memcpy(ca->dim, parent->dim,
|
77
|
-
memcpy(ca->shift, shift,
|
78
|
-
memcpy(ca->roll, roll,
|
76
|
+
memcpy(ca->dim, parent->dim, ndim * sizeof(ca_size_t));
|
77
|
+
memcpy(ca->shift, shift, ndim * sizeof(ca_size_t));
|
78
|
+
memcpy(ca->roll, roll, ndim * sizeof(int8_t));
|
79
79
|
|
80
80
|
if ( fill ) {
|
81
81
|
ca->fill_mask = 0;
|
@@ -194,7 +194,7 @@ ca_shift_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
194
194
|
int8_t i;
|
195
195
|
ca_size_t k, n;
|
196
196
|
n = 0;
|
197
|
-
for (i=0; i<ca->
|
197
|
+
for (i=0; i<ca->ndim; i++) {
|
198
198
|
k = idx[i];
|
199
199
|
if ( roll[i] ) {
|
200
200
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -230,7 +230,7 @@ ca_shift_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
230
230
|
int8_t i;
|
231
231
|
ca_size_t k, n;
|
232
232
|
n = 0;
|
233
|
-
for (i=0; i<ca->
|
233
|
+
for (i=0; i<ca->ndim; i++) {
|
234
234
|
k = idx[i];
|
235
235
|
if ( roll[i] ) {
|
236
236
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -257,7 +257,7 @@ ca_shift_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
257
257
|
int8_t i;
|
258
258
|
ca_size_t k, n;
|
259
259
|
n = 0;
|
260
|
-
for (i=0; i<ca->
|
260
|
+
for (i=0; i<ca->ndim; i++) {
|
261
261
|
k = idx[i];
|
262
262
|
if ( roll[i] ) {
|
263
263
|
k = ca_shift_rolled_index(ca, i, k);
|
@@ -402,7 +402,7 @@ ca_shift_attach_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx
|
|
402
402
|
int8_t roll = ca->roll[level];
|
403
403
|
ca_size_t i;
|
404
404
|
|
405
|
-
if ( level == ca->
|
405
|
+
if ( level == ca->ndim - 1 ) {
|
406
406
|
if ( fill ) {
|
407
407
|
for (i=0; i<ca->dim[level]; i++) {
|
408
408
|
idx[level] = i;
|
@@ -561,7 +561,7 @@ ca_shift_sync_loop (CAShift *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
561
561
|
int8_t roll = ca->roll[level];
|
562
562
|
ca_size_t i;
|
563
563
|
|
564
|
-
if ( level == ca->
|
564
|
+
if ( level == ca->ndim - 1 ) {
|
565
565
|
if ( ! shift ) {
|
566
566
|
idx[level] = 0;
|
567
567
|
idx0[level] = 0;
|
@@ -705,7 +705,7 @@ ca_shift_fill_loop (CAShift *ca, char *ptr,
|
|
705
705
|
int8_t roll = ca->roll[level];
|
706
706
|
ca_size_t i;
|
707
707
|
|
708
|
-
if ( level == ca->
|
708
|
+
if ( level == ca->ndim - 1 ) {
|
709
709
|
if ( ( ! shift ) || roll ) {
|
710
710
|
for (i=0; i<dim; i++) {
|
711
711
|
idx0[level] = i;
|
@@ -851,11 +851,11 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
851
851
|
ropt = rb_pop_options(&argc, &argv);
|
852
852
|
rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
|
853
853
|
|
854
|
-
if ( argc != ca->
|
855
|
-
rb_raise(rb_eArgError, "# of arguments mismatch with
|
854
|
+
if ( argc != ca->ndim ) {
|
855
|
+
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
|
856
856
|
}
|
857
857
|
|
858
|
-
for (i=0; i<ca->
|
858
|
+
for (i=0; i<ca->ndim; i++) {
|
859
859
|
shift[i] = NUM2SIZE(argv[i]);
|
860
860
|
}
|
861
861
|
|
@@ -889,18 +889,18 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
889
889
|
}
|
890
890
|
|
891
891
|
if ( NIL_P(rroll) ) {
|
892
|
-
for (i=0; i<ca->
|
892
|
+
for (i=0; i<ca->ndim; i++) {
|
893
893
|
roll[i] = 0;
|
894
894
|
}
|
895
895
|
}
|
896
896
|
else {
|
897
897
|
Check_Type(rroll, T_ARRAY);
|
898
898
|
|
899
|
-
if ( RARRAY_LEN(rroll) != ca->
|
900
|
-
rb_raise(rb_eArgError, "# of arguments mismatch with
|
899
|
+
if ( RARRAY_LEN(rroll) != ca->ndim ) {
|
900
|
+
rb_raise(rb_eArgError, "# of arguments mismatch with ndim");
|
901
901
|
}
|
902
902
|
|
903
|
-
for (i=0; i<ca->
|
903
|
+
for (i=0; i<ca->ndim; i++) {
|
904
904
|
roll[i] = NUM2INT(rb_ary_entry(rroll, i));
|
905
905
|
}
|
906
906
|
}
|
@@ -15,7 +15,7 @@
|
|
15
15
|
typedef struct {
|
16
16
|
int16_t obj_type;
|
17
17
|
int8_t data_type;
|
18
|
-
int8_t
|
18
|
+
int8_t ndim;
|
19
19
|
int32_t flags;
|
20
20
|
ca_size_t bytes;
|
21
21
|
ca_size_t elements;
|
@@ -44,7 +44,7 @@ static VALUE rb_cCATrans;
|
|
44
44
|
int
|
45
45
|
ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
46
46
|
{
|
47
|
-
int8_t data_type,
|
47
|
+
int8_t data_type, ndim;
|
48
48
|
ca_size_t bytes, elements;
|
49
49
|
ca_size_t *dim0;
|
50
50
|
ca_size_t newdim[CA_RANK_MAX];
|
@@ -54,17 +54,17 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
|
54
54
|
|
55
55
|
data_type = parent->data_type;
|
56
56
|
bytes = parent->bytes;
|
57
|
-
|
57
|
+
ndim = parent->ndim;
|
58
58
|
elements = parent->elements;
|
59
59
|
dim0 = parent->dim;
|
60
60
|
|
61
|
-
for (i=0; i<
|
61
|
+
for (i=0; i<ndim; i++) {
|
62
62
|
map[i] = -1;
|
63
63
|
}
|
64
64
|
|
65
|
-
for (i=0; i<
|
65
|
+
for (i=0; i<ndim; i++) {
|
66
66
|
idim = imap[i];
|
67
|
-
if ( idim < 0 || idim >=
|
67
|
+
if ( idim < 0 || idim >= ndim ) {
|
68
68
|
rb_raise(rb_eRuntimeError,
|
69
69
|
"specified %i-th dimension number out of range", i);
|
70
70
|
}
|
@@ -78,28 +78,28 @@ ca_trans_setup (CATrans *ca, CArray *parent, ca_size_t *imap)
|
|
78
78
|
}
|
79
79
|
|
80
80
|
step = 1;
|
81
|
-
for (i=imap[
|
81
|
+
for (i=imap[ndim-1]+1; i<ndim; i++) {
|
82
82
|
step *= dim0[i];
|
83
83
|
}
|
84
84
|
|
85
85
|
ca->obj_type = CA_OBJ_TRANSPOSE;
|
86
86
|
ca->data_type = data_type;
|
87
87
|
ca->flags = 0;
|
88
|
-
ca->
|
88
|
+
ca->ndim = ndim;
|
89
89
|
ca->bytes = bytes;
|
90
90
|
ca->elements = elements;
|
91
91
|
ca->ptr = NULL;
|
92
92
|
ca->mask = NULL;
|
93
|
-
ca->dim = ALLOC_N(ca_size_t,
|
93
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
94
94
|
|
95
95
|
ca->parent = parent;
|
96
96
|
ca->attach = 0;
|
97
97
|
ca->nosync = 0;
|
98
|
-
ca->imap = ALLOC_N(ca_size_t,
|
98
|
+
ca->imap = ALLOC_N(ca_size_t, ndim);
|
99
99
|
ca->step = step;
|
100
100
|
|
101
|
-
memcpy(ca->dim, newdim,
|
102
|
-
memcpy(ca->imap, imap,
|
101
|
+
memcpy(ca->dim, newdim, ndim * sizeof(ca_size_t));
|
102
|
+
memcpy(ca->imap, imap, ndim * sizeof(ca_size_t));
|
103
103
|
|
104
104
|
if ( ca_has_mask(parent) ) {
|
105
105
|
ca_create_mask(ca);
|
@@ -167,7 +167,7 @@ ca_trans_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
167
167
|
ca_size_t *imap = ca->imap;
|
168
168
|
ca_size_t idx0[CA_RANK_MAX];
|
169
169
|
int8_t i;
|
170
|
-
for (i=0; i<ca->
|
170
|
+
for (i=0; i<ca->ndim; i++) {
|
171
171
|
idx0[imap[i]] = idx[i];
|
172
172
|
}
|
173
173
|
return ca_ptr_at_index(ca->parent, idx0);
|
@@ -181,7 +181,7 @@ ca_trans_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
181
181
|
ca_size_t *imap = ca->imap;
|
182
182
|
ca_size_t idx0[CA_RANK_MAX];
|
183
183
|
int8_t i;
|
184
|
-
for (i=0; i<ca->
|
184
|
+
for (i=0; i<ca->ndim; i++) {
|
185
185
|
idx0[imap[i]] = idx[i];
|
186
186
|
}
|
187
187
|
ca_fetch_index(ca->parent, idx0, ptr);
|
@@ -194,7 +194,7 @@ ca_trans_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
194
194
|
ca_size_t *imap = ca->imap;
|
195
195
|
ca_size_t idx0[CA_RANK_MAX];
|
196
196
|
int8_t i;
|
197
|
-
for (i=0; i<ca->
|
197
|
+
for (i=0; i<ca->ndim; i++) {
|
198
198
|
idx0[imap[i]] = idx[i];
|
199
199
|
}
|
200
200
|
ca_store_index(ca->parent, idx0, ptr);
|
@@ -311,7 +311,7 @@ ca_trans_attach_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0
|
|
311
311
|
ca_size_t *imap = ca->imap;
|
312
312
|
ca_size_t i;
|
313
313
|
|
314
|
-
if ( level == ca->
|
314
|
+
if ( level == ca->ndim - 1 ) {
|
315
315
|
idx[level] = 0;
|
316
316
|
idx0[imap[level]] = 0;
|
317
317
|
switch ( ca->bytes ) {
|
@@ -392,7 +392,7 @@ ca_trans_sync_loop (CATrans *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
392
392
|
ca_size_t *imap = ca->imap;
|
393
393
|
ca_size_t i;
|
394
394
|
|
395
|
-
if ( level == ca->
|
395
|
+
if ( level == ca->ndim - 1 ) {
|
396
396
|
idx[level] = 0;
|
397
397
|
idx0[imap[level]] = 0;
|
398
398
|
switch ( ca->bytes ) {
|
@@ -473,7 +473,7 @@ ca_trans_fill_loop (CATrans *ca, char *ptr,
|
|
473
473
|
ca_size_t *imap = ca->imap;
|
474
474
|
ca_size_t i;
|
475
475
|
|
476
|
-
if ( level == ca->
|
476
|
+
if ( level == ca->ndim - 1 ) {
|
477
477
|
for (i=0; i<ca->dim[level]; i++) {
|
478
478
|
idx0[imap[level]] = i;
|
479
479
|
memcpy(ca_ptr_at_index(ca->parent, idx0), ptr, ca->bytes);
|
@@ -529,17 +529,17 @@ rb_ca_trans (int argc, VALUE *argv, VALUE self)
|
|
529
529
|
Data_Get_Struct(self, CArray, ca);
|
530
530
|
|
531
531
|
if ( argc == 0 ) {
|
532
|
-
for (i=0; i<ca->
|
533
|
-
imap[i] = ca->
|
532
|
+
for (i=0; i<ca->ndim; i++) {
|
533
|
+
imap[i] = ca->ndim - i - 1;
|
534
534
|
}
|
535
535
|
}
|
536
|
-
else if ( argc == ca->
|
537
|
-
for (i=0; i<ca->
|
536
|
+
else if ( argc == ca->ndim ) {
|
537
|
+
for (i=0; i<ca->ndim; i++) {
|
538
538
|
imap[i] = NUM2SIZE(argv[i]);
|
539
539
|
}
|
540
540
|
}
|
541
541
|
else {
|
542
|
-
rb_raise(rb_eArgError, "# of arguments should be equal to
|
542
|
+
rb_raise(rb_eArgError, "# of arguments should be equal to ndim");
|
543
543
|
}
|
544
544
|
|
545
545
|
obj = rb_ca_trans_new(self, imap);
|
@@ -21,39 +21,39 @@ VALUE rb_cCAUnboundRepeat;
|
|
21
21
|
|
22
22
|
int
|
23
23
|
ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
|
24
|
-
int32_t
|
24
|
+
int32_t rep_ndim, ca_size_t *rep_dim)
|
25
25
|
{
|
26
|
-
int8_t data_type,
|
26
|
+
int8_t data_type, ndim;
|
27
27
|
ca_size_t bytes, elements;
|
28
28
|
|
29
29
|
/* check arguments */
|
30
30
|
|
31
|
-
CA_CHECK_RANK(
|
31
|
+
CA_CHECK_RANK(rep_ndim);
|
32
32
|
|
33
33
|
data_type = parent->data_type;
|
34
34
|
bytes = parent->bytes;
|
35
|
-
|
35
|
+
ndim = parent->ndim;
|
36
36
|
elements = parent->elements;
|
37
37
|
|
38
38
|
ca->obj_type = CA_OBJ_UNBOUND_REPEAT;
|
39
39
|
ca->data_type = data_type;
|
40
40
|
ca->flags = 0;
|
41
|
-
ca->
|
41
|
+
ca->ndim = ndim;
|
42
42
|
ca->bytes = bytes;
|
43
43
|
ca->elements = elements;
|
44
44
|
ca->ptr = NULL;
|
45
45
|
ca->mask = NULL;
|
46
|
-
ca->dim = ALLOC_N(ca_size_t,
|
46
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
47
47
|
|
48
48
|
ca->parent = parent;
|
49
49
|
ca->attach = 0;
|
50
50
|
ca->nosync = 0;
|
51
51
|
|
52
|
-
ca->
|
53
|
-
ca->rep_dim = ALLOC_N(ca_size_t,
|
52
|
+
ca->rep_ndim = rep_ndim;
|
53
|
+
ca->rep_dim = ALLOC_N(ca_size_t, rep_ndim);
|
54
54
|
|
55
|
-
memcpy(ca->dim, parent->dim,
|
56
|
-
memcpy(ca->rep_dim, rep_dim,
|
55
|
+
memcpy(ca->dim, parent->dim, ndim * sizeof(ca_size_t));
|
56
|
+
memcpy(ca->rep_dim, rep_dim, rep_ndim * sizeof(ca_size_t));
|
57
57
|
|
58
58
|
if ( ca_has_mask(parent) ) {
|
59
59
|
ca_create_mask(ca);
|
@@ -63,10 +63,10 @@ ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
|
|
63
63
|
}
|
64
64
|
|
65
65
|
CAUnboundRepeat *
|
66
|
-
ca_ubrep_new (CArray *parent, int32_t
|
66
|
+
ca_ubrep_new (CArray *parent, int32_t rep_ndim, ca_size_t *rep_dim)
|
67
67
|
{
|
68
68
|
CAUnboundRepeat *ca = ALLOC(CAUnboundRepeat);
|
69
|
-
ca_ubrep_setup(ca, parent,
|
69
|
+
ca_ubrep_setup(ca, parent, rep_ndim, rep_dim);
|
70
70
|
return ca;
|
71
71
|
}
|
72
72
|
|
@@ -88,7 +88,7 @@ static void *
|
|
88
88
|
ca_ubrep_func_clone (void *ap)
|
89
89
|
{
|
90
90
|
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
91
|
-
return ca_ubrep_new(ca->parent, ca->
|
91
|
+
return ca_ubrep_new(ca->parent, ca->rep_ndim, ca->rep_dim);
|
92
92
|
}
|
93
93
|
|
94
94
|
static char *
|
@@ -212,7 +212,7 @@ ca_ubrep_func_create_mask (void *ap)
|
|
212
212
|
ca_create_mask(ca->parent);
|
213
213
|
}
|
214
214
|
ca->mask =
|
215
|
-
(CArray *) ca_ubrep_new(ca->parent->mask, ca->
|
215
|
+
(CArray *) ca_ubrep_new(ca->parent->mask, ca->rep_ndim, ca->rep_dim);
|
216
216
|
}
|
217
217
|
|
218
218
|
ca_operation_function_t ca_ubrep_func = {
|
@@ -239,14 +239,14 @@ ca_operation_function_t ca_ubrep_func = {
|
|
239
239
|
/* ------------------------------------------------------------------- */
|
240
240
|
|
241
241
|
VALUE
|
242
|
-
rb_ca_ubrep_new (VALUE cary, int32_t
|
242
|
+
rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim)
|
243
243
|
{
|
244
244
|
volatile VALUE obj;
|
245
245
|
CArray *parent;
|
246
246
|
CAUnboundRepeat *ca;
|
247
247
|
rb_check_carray_object(cary);
|
248
248
|
Data_Get_Struct(cary, CArray, parent);
|
249
|
-
ca = ca_ubrep_new(parent,
|
249
|
+
ca = ca_ubrep_new(parent, rep_ndim, rep_dim);
|
250
250
|
obj = ca_wrap_struct(ca);
|
251
251
|
rb_ca_set_parent(obj, cary);
|
252
252
|
rb_ca_data_type_inherit(obj, cary);
|
@@ -257,8 +257,8 @@ VALUE
|
|
257
257
|
rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
258
258
|
{
|
259
259
|
CArray *ca;
|
260
|
-
ca_size_t
|
261
|
-
int32_t
|
260
|
+
ca_size_t ndim, dim[CA_RANK_MAX];
|
261
|
+
int32_t rep_ndim;
|
262
262
|
ca_size_t rep_dim[CA_RANK_MAX];
|
263
263
|
ca_size_t count, i;
|
264
264
|
|
@@ -271,7 +271,7 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
271
271
|
args = rb_ary_new();
|
272
272
|
if ( rb_obj_is_kind_of(self, rb_cCAUnboundRepeat) ) {
|
273
273
|
repeatable = 1;
|
274
|
-
for (i=0; i<cr->
|
274
|
+
for (i=0; i<cr->rep_ndim; i++) {
|
275
275
|
if ( cr->rep_dim[i] == 1 ) {
|
276
276
|
rb_ary_push(args, ID2SYM(rb_intern("*")));
|
277
277
|
repeatable = 1;
|
@@ -285,7 +285,7 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
285
285
|
}
|
286
286
|
}
|
287
287
|
else {
|
288
|
-
for (i=0; i<ca->
|
288
|
+
for (i=0; i<ca->ndim; i++) {
|
289
289
|
if ( ca->dim[i] == 1 ) {
|
290
290
|
rb_ary_push(args, ID2SYM(rb_intern("*")));
|
291
291
|
repeatable = 1;
|
@@ -319,12 +319,12 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
319
319
|
return ca_ubrep_bind_with(obj, argv[0]);
|
320
320
|
}
|
321
321
|
|
322
|
-
|
322
|
+
rep_ndim = argc;
|
323
323
|
|
324
324
|
count = 0;
|
325
|
-
|
325
|
+
ndim = 0;
|
326
326
|
|
327
|
-
for (i=0; i<
|
327
|
+
for (i=0; i<rep_ndim; i++) {
|
328
328
|
if ( rb_obj_is_kind_of(argv[i], rb_cSymbol) ) {
|
329
329
|
if ( argv[i] == ID2SYM(rb_intern("*")) ) {
|
330
330
|
rep_dim[i] = 0;
|
@@ -341,25 +341,25 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
341
341
|
rb_raise(rb_eArgError, "invalid argument");
|
342
342
|
}
|
343
343
|
rep_dim[i] = ca->dim[count];
|
344
|
-
dim[
|
345
|
-
count++;
|
344
|
+
dim[ndim] = ca->dim[count];
|
345
|
+
count++; ndim++;
|
346
346
|
}
|
347
347
|
}
|
348
348
|
|
349
|
-
if ( count != ca->
|
349
|
+
if ( count != ca->ndim ) {
|
350
350
|
rb_raise(rb_eRuntimeError, "too small # of nil");
|
351
351
|
}
|
352
352
|
|
353
|
-
if (
|
353
|
+
if ( ndim != ca->ndim ) {
|
354
354
|
volatile VALUE par, obj;
|
355
|
-
par = rb_ca_refer_new(self, ca->data_type,
|
356
|
-
obj = rb_ca_ubrep_new(par,
|
355
|
+
par = rb_ca_refer_new(self, ca->data_type, ndim, dim, ca->bytes, 0);
|
356
|
+
obj = rb_ca_ubrep_new(par, rep_ndim, rep_dim);
|
357
357
|
rb_ivar_set(obj, rb_intern("__real_parent__"), par);
|
358
358
|
rb_ca_set_parent(obj, self);
|
359
359
|
return obj;
|
360
360
|
}
|
361
361
|
else {
|
362
|
-
return rb_ca_ubrep_new(self,
|
362
|
+
return rb_ca_ubrep_new(self, rep_ndim, rep_dim);
|
363
363
|
}
|
364
364
|
}
|
365
365
|
|
@@ -378,21 +378,21 @@ rb_ca_ubrep_initialize_copy (VALUE self, VALUE other)
|
|
378
378
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
379
379
|
Data_Get_Struct(other, CAUnboundRepeat, cs);
|
380
380
|
|
381
|
-
ca_ubrep_setup(ca, cs->parent, cs->
|
381
|
+
ca_ubrep_setup(ca, cs->parent, cs->rep_ndim, cs->rep_dim);
|
382
382
|
|
383
383
|
return self;
|
384
384
|
}
|
385
385
|
|
386
386
|
/*
|
387
387
|
static CARepeat *
|
388
|
-
ca_ubrep_bind (CAUnboundRepeat *ca, int32_t
|
388
|
+
ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_ndim, ca_size_t *new_dim)
|
389
389
|
{
|
390
390
|
ca_size_t rep_spec[CA_RANK_MAX];
|
391
391
|
int i;
|
392
|
-
if ( ca->
|
393
|
-
rb_raise(rb_eArgError, "invalid
|
392
|
+
if ( ca->rep_ndim != new_ndim ) {
|
393
|
+
rb_raise(rb_eArgError, "invalid new_ndim");
|
394
394
|
}
|
395
|
-
for (i=0; i<
|
395
|
+
for (i=0; i<new_ndim; i++) {
|
396
396
|
if ( ca->rep_dim[i] == 0 ) {
|
397
397
|
rep_spec[i] = new_dim[i];
|
398
398
|
}
|
@@ -400,57 +400,57 @@ ca_ubrep_bind (CAUnboundRepeat *ca, int32_t new_rank, ca_size_t *new_dim)
|
|
400
400
|
rep_spec[i] = 0;
|
401
401
|
}
|
402
402
|
}
|
403
|
-
return ca_repeat_new((CArray*)ca,
|
403
|
+
return ca_repeat_new((CArray*)ca, new_ndim, rep_spec);
|
404
404
|
}
|
405
405
|
*/
|
406
406
|
|
407
407
|
VALUE
|
408
|
-
ca_ubrep_bind2 (VALUE self, int32_t
|
408
|
+
ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
409
409
|
{
|
410
410
|
CAUnboundRepeat *ca;
|
411
411
|
ca_size_t rep_spec[CA_RANK_MAX];
|
412
412
|
ca_size_t upr_spec[CA_RANK_MAX];
|
413
413
|
ca_size_t srp_spec[CA_RANK_MAX];
|
414
|
-
int uprep = 0,
|
414
|
+
int uprep = 0, srp_ndim;
|
415
415
|
int i;
|
416
416
|
|
417
417
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
418
418
|
|
419
|
-
if ( ca->
|
420
|
-
rb_raise(rb_eArgError, "invalid
|
421
|
-
ca->
|
419
|
+
if ( ca->rep_ndim != new_ndim ) {
|
420
|
+
rb_raise(rb_eArgError, "invalid new_ndim (%i <-> %i)",
|
421
|
+
ca->rep_ndim, new_ndim);
|
422
422
|
}
|
423
423
|
|
424
|
-
|
425
|
-
for (i=0; i<
|
424
|
+
srp_ndim = 0;
|
425
|
+
for (i=0; i<new_ndim; i++) {
|
426
426
|
if ( ca->rep_dim[i] == 0 ) {
|
427
427
|
if ( new_dim[i] == 0 ) {
|
428
428
|
uprep = 1;
|
429
429
|
}
|
430
430
|
else {
|
431
|
-
srp_spec[
|
431
|
+
srp_spec[srp_ndim++] = new_dim[i];
|
432
432
|
}
|
433
433
|
rep_spec[i] = new_dim[i];
|
434
434
|
upr_spec[i] = new_dim[i];
|
435
435
|
}
|
436
436
|
else {
|
437
437
|
rep_spec[i] = 0;
|
438
|
-
srp_spec[
|
438
|
+
srp_spec[srp_ndim++] = 0;
|
439
439
|
upr_spec[i] = ca->rep_dim[i];
|
440
440
|
}
|
441
441
|
}
|
442
442
|
if ( uprep ) {
|
443
443
|
volatile VALUE rep;
|
444
|
-
if (
|
445
|
-
rep = rb_ca_repeat_new(rb_ca_parent(self),
|
444
|
+
if ( srp_ndim >= ca->ndim ) {
|
445
|
+
rep = rb_ca_repeat_new(rb_ca_parent(self), srp_ndim, srp_spec);
|
446
446
|
}
|
447
447
|
else {
|
448
448
|
rep = rb_ca_parent(self);
|
449
449
|
}
|
450
|
-
return rb_ca_ubrep_new(rep,
|
450
|
+
return rb_ca_ubrep_new(rep, new_ndim, upr_spec);
|
451
451
|
}
|
452
452
|
else {
|
453
|
-
return rb_ca_repeat_new(self,
|
453
|
+
return rb_ca_repeat_new(self, new_ndim, rep_spec);
|
454
454
|
}
|
455
455
|
}
|
456
456
|
|
@@ -474,13 +474,13 @@ ca_ubrep_bind_with (VALUE self, VALUE other)
|
|
474
474
|
|
475
475
|
if ( co->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
476
476
|
Data_Get_Struct(other, CAUnboundRepeat, cup);
|
477
|
-
return ca_ubrep_bind2(self, cup->
|
477
|
+
return ca_ubrep_bind2(self, cup->rep_ndim, cup->rep_dim);
|
478
478
|
}
|
479
479
|
else if ( ca_is_scalar(co) ) {
|
480
480
|
return self;
|
481
481
|
}
|
482
482
|
else {
|
483
|
-
return ca_ubrep_bind2(self, co->
|
483
|
+
return ca_ubrep_bind2(self, co->ndim, co->dim);
|
484
484
|
}
|
485
485
|
}
|
486
486
|
|
@@ -500,8 +500,8 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
|
|
500
500
|
|
501
501
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
502
502
|
|
503
|
-
if ( ca->
|
504
|
-
rb_raise(rb_eArgError, "invalid
|
503
|
+
if ( ca->rep_ndim != argc ) {
|
504
|
+
rb_raise(rb_eArgError, "invalid new_ndim");
|
505
505
|
}
|
506
506
|
for (i=0; i<argc; i++) {
|
507
507
|
if ( ca->rep_dim[i] == 0 ) {
|
@@ -524,8 +524,8 @@ rb_ca_ubrep_spec (VALUE self)
|
|
524
524
|
|
525
525
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
526
526
|
|
527
|
-
spec = rb_ary_new2(ca->
|
528
|
-
for (i=0; i<ca->
|
527
|
+
spec = rb_ary_new2(ca->rep_ndim);
|
528
|
+
for (i=0; i<ca->rep_ndim; i++) {
|
529
529
|
if ( ca->rep_dim[i] ) {
|
530
530
|
rb_ary_store(spec, i, SIZE2NUM(ca->rep_dim[i]));
|
531
531
|
}
|