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
@@ -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;
|
@@ -43,14 +43,14 @@ static VALUE rb_cCAFarray;
|
|
43
43
|
int
|
44
44
|
ca_farray_setup (CAFarray *ca, CArray *parent)
|
45
45
|
{
|
46
|
-
int8_t
|
46
|
+
int8_t ndim, data_type;
|
47
47
|
ca_size_t *dim, elements, bytes;
|
48
48
|
int i;
|
49
49
|
|
50
50
|
/* check arguments */
|
51
51
|
|
52
52
|
data_type = parent->data_type;
|
53
|
-
|
53
|
+
ndim = parent->ndim;
|
54
54
|
dim = parent->dim;
|
55
55
|
bytes = parent->bytes;
|
56
56
|
elements = parent->elements;
|
@@ -58,23 +58,23 @@ ca_farray_setup (CAFarray *ca, CArray *parent)
|
|
58
58
|
ca->obj_type = CA_OBJ_FARRAY;
|
59
59
|
ca->data_type = data_type;
|
60
60
|
ca->flags = 0;
|
61
|
-
ca->
|
61
|
+
ca->ndim = ndim;
|
62
62
|
ca->bytes = bytes;
|
63
63
|
ca->elements = elements;
|
64
64
|
ca->ptr = NULL;
|
65
65
|
ca->mask = NULL;
|
66
|
-
ca->dim = ALLOC_N(ca_size_t,
|
66
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
67
67
|
|
68
68
|
ca->parent = parent;
|
69
69
|
ca->attach = 0;
|
70
70
|
ca->nosync = 0;
|
71
71
|
|
72
|
-
for (i=0; i<
|
73
|
-
ca->dim[i] = dim[
|
72
|
+
for (i=0; i<ndim; i++) {
|
73
|
+
ca->dim[i] = dim[ndim-1-i];
|
74
74
|
}
|
75
75
|
|
76
76
|
ca->step = 1;
|
77
|
-
for (i=1; i<
|
77
|
+
for (i=1; i<ndim; i++) {
|
78
78
|
ca->step *= dim[i];
|
79
79
|
}
|
80
80
|
|
@@ -124,11 +124,11 @@ static void
|
|
124
124
|
ca_farray_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
125
125
|
{
|
126
126
|
CAFarray *ca = (CAFarray *) ap;
|
127
|
-
int8_t
|
127
|
+
int8_t ndim = ca->ndim;
|
128
128
|
ca_size_t idx0[CA_RANK_MAX];
|
129
129
|
int i;
|
130
|
-
for (i=0; i<
|
131
|
-
idx0[i] = idx[
|
130
|
+
for (i=0; i<ndim; i++) {
|
131
|
+
idx0[i] = idx[ndim-1-i];
|
132
132
|
}
|
133
133
|
ca_fetch_index(ca->parent, idx0, ptr);
|
134
134
|
}
|
@@ -137,11 +137,11 @@ static void
|
|
137
137
|
ca_farray_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
138
138
|
{
|
139
139
|
CAFarray *ca = (CAFarray *) ap;
|
140
|
-
int8_t
|
140
|
+
int8_t ndim = ca->ndim;
|
141
141
|
ca_size_t idx0[CA_RANK_MAX];
|
142
142
|
int i;
|
143
|
-
for (i=0; i<
|
144
|
-
idx0[i] = idx[
|
143
|
+
for (i=0; i<ndim; i++) {
|
144
|
+
idx0[i] = idx[ndim-1-i];
|
145
145
|
}
|
146
146
|
ca_store_index(ca->parent, idx0, ptr);
|
147
147
|
}
|
@@ -258,7 +258,7 @@ ca_fa_attach_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
258
258
|
ca_size_t step = ca->step;
|
259
259
|
ca_size_t dim = ca->dim[level];
|
260
260
|
ca_size_t i;
|
261
|
-
if ( level == ca->
|
261
|
+
if ( level == ca->ndim - 1 ) {
|
262
262
|
idx[level] = 0;
|
263
263
|
idx0[0] = 0;
|
264
264
|
switch ( ca->bytes ) {
|
@@ -315,7 +315,7 @@ ca_fa_attach_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
315
315
|
}
|
316
316
|
}
|
317
317
|
else {
|
318
|
-
int level0 = ca->
|
318
|
+
int level0 = ca->ndim - 1 - level;
|
319
319
|
for (i=0; i<dim; i++) {
|
320
320
|
idx[level] = i;
|
321
321
|
idx0[level0] = i;
|
@@ -339,7 +339,7 @@ ca_fa_sync_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
339
339
|
ca_size_t dim = ca->dim[level];
|
340
340
|
ca_size_t i;
|
341
341
|
|
342
|
-
if ( level == ca->
|
342
|
+
if ( level == ca->ndim - 1 ) {
|
343
343
|
idx[level] = 0;
|
344
344
|
idx0[0] = 0;
|
345
345
|
switch ( ca->bytes ) {
|
@@ -398,7 +398,7 @@ ca_fa_sync_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
398
398
|
else {
|
399
399
|
for (i=0; i<dim; i++) {
|
400
400
|
idx[level] = i;
|
401
|
-
idx0[ca->
|
401
|
+
idx0[ca->ndim - 1 - level] = i;
|
402
402
|
ca_fa_sync_loop(ca, level+1, idx, idx0);
|
403
403
|
}
|
404
404
|
}
|
@@ -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 @@ int
|
|
44
44
|
ca_field_setup (CAField *ca, CArray *parent,
|
45
45
|
ca_size_t offset, int8_t data_type, ca_size_t bytes)
|
46
46
|
{
|
47
|
-
int8_t
|
47
|
+
int8_t ndim;
|
48
48
|
ca_size_t elements;
|
49
49
|
|
50
50
|
/* check arguments */
|
@@ -64,25 +64,25 @@ ca_field_setup (CAField *ca, CArray *parent,
|
|
64
64
|
rb_raise(rb_eRuntimeError, "offset or bytes out of range");
|
65
65
|
}
|
66
66
|
|
67
|
-
|
67
|
+
ndim = parent->ndim;
|
68
68
|
elements = parent->elements;
|
69
69
|
|
70
70
|
ca->obj_type = CA_OBJ_FIELD;
|
71
71
|
ca->data_type = data_type;
|
72
72
|
ca->flags = 0;
|
73
|
-
ca->
|
73
|
+
ca->ndim = ndim;
|
74
74
|
ca->bytes = bytes;
|
75
75
|
ca->elements = elements;
|
76
76
|
ca->ptr = NULL;
|
77
77
|
ca->mask = NULL;
|
78
|
-
ca->dim = ALLOC_N(ca_size_t,
|
78
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
79
79
|
|
80
80
|
ca->parent = parent;
|
81
81
|
ca->attach = 0;
|
82
82
|
ca->nosync = 0;
|
83
83
|
ca->offset = offset;
|
84
84
|
|
85
|
-
memcpy(ca->dim, parent->dim,
|
85
|
+
memcpy(ca->dim, parent->dim, ndim * sizeof(ca_size_t));
|
86
86
|
|
87
87
|
if ( ca_has_mask(parent) ) {
|
88
88
|
ca_create_mask(ca);
|
@@ -149,9 +149,9 @@ ca_field_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
149
149
|
ca_size_t *dim = ca->dim;
|
150
150
|
int8_t i;
|
151
151
|
ca_size_t n;
|
152
|
-
n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[
|
153
|
-
for (i=1; i<ca->
|
154
|
-
n = dim[i]*n+idx[i]; /* ... + idx[
|
152
|
+
n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[ndim-1] */
|
153
|
+
for (i=1; i<ca->ndim; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[ndim-1] */
|
154
|
+
n = dim[i]*n+idx[i]; /* ... + idx[ndim-2]*dim[1] + idx[ndim-1] */
|
155
155
|
}
|
156
156
|
|
157
157
|
if ( ca->parent->ptr == NULL ) {
|
@@ -285,7 +285,7 @@ ca_field_func_create_mask (void *ap)
|
|
285
285
|
}
|
286
286
|
ca->mask =
|
287
287
|
(CArray *) ca_refer_new(ca->parent->mask,
|
288
|
-
CA_BOOLEAN, ca->
|
288
|
+
CA_BOOLEAN, ca->ndim, ca->dim, 0, 0);
|
289
289
|
}
|
290
290
|
|
291
291
|
ca_operation_function_t ca_field_func = {
|
@@ -583,21 +583,21 @@ rb_ca_field (int argc, VALUE *argv, VALUE self)
|
|
583
583
|
if ( rb_obj_is_carray(rtype) ) {
|
584
584
|
CArray *ct;
|
585
585
|
ca_size_t dim[CA_RANK_MAX];
|
586
|
-
int8_t
|
586
|
+
int8_t ndim;
|
587
587
|
int8_t i, j;
|
588
588
|
Data_Get_Struct(rtype, CArray, ct);
|
589
589
|
data_type = CA_FIXLEN;
|
590
590
|
bytes = ct->bytes * ct->elements;
|
591
591
|
obj = rb_ca_field_new(self, offset, data_type, bytes);
|
592
592
|
rb_ca_data_type_inherit(obj, rtype);
|
593
|
-
|
594
|
-
for (i=0; i<ca->
|
593
|
+
ndim = ca->ndim + ct->ndim;
|
594
|
+
for (i=0; i<ca->ndim; i++) {
|
595
595
|
dim[i] = ca->dim[i];
|
596
596
|
}
|
597
|
-
for (j=0; j<ct->
|
597
|
+
for (j=0; j<ct->ndim; j++, i++) {
|
598
598
|
dim[i] = ct->dim[j];
|
599
599
|
}
|
600
|
-
obj = rb_ca_refer_new(obj, ct->data_type,
|
600
|
+
obj = rb_ca_refer_new(obj, ct->data_type, ndim, dim, ct->bytes, 0);
|
601
601
|
}
|
602
602
|
else {
|
603
603
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
@@ -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;
|
@@ -43,20 +43,20 @@ int
|
|
43
43
|
ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
44
44
|
CArray **grid, int8_t *contig, int share)
|
45
45
|
{
|
46
|
-
int8_t
|
46
|
+
int8_t ndim, data_type;
|
47
47
|
ca_size_t *dim0;
|
48
48
|
ca_size_t elements, bytes;
|
49
49
|
double length;
|
50
50
|
int i, j, k;
|
51
51
|
|
52
52
|
data_type = parent->data_type;
|
53
|
-
|
53
|
+
ndim = parent->ndim;
|
54
54
|
bytes = parent->bytes;
|
55
55
|
dim0 = parent->dim;
|
56
56
|
|
57
57
|
elements = 1;
|
58
58
|
length = bytes;
|
59
|
-
for (i=0; i<
|
59
|
+
for (i=0; i<ndim; i++) {
|
60
60
|
if ( dim[i] < 0 ) {
|
61
61
|
rb_raise(rb_eRuntimeError, "negative size for %i-th dimension", i);
|
62
62
|
}
|
@@ -71,12 +71,12 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
71
71
|
ca->obj_type = CA_OBJ_GRID;
|
72
72
|
ca->data_type = data_type;
|
73
73
|
ca->flags = 0;
|
74
|
-
ca->
|
74
|
+
ca->ndim = ndim;
|
75
75
|
ca->bytes = bytes;
|
76
76
|
ca->elements = elements;
|
77
77
|
ca->ptr = NULL;
|
78
78
|
ca->mask = NULL;
|
79
|
-
ca->dim = ALLOC_N(ca_size_t,
|
79
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
80
80
|
|
81
81
|
ca->parent = parent;
|
82
82
|
ca->attach = 0;
|
@@ -88,14 +88,14 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
88
88
|
ca->contig = contig;
|
89
89
|
}
|
90
90
|
else {
|
91
|
-
ca->grid = ALLOC_N(CArray *,
|
92
|
-
ca->contig = ALLOC_N(int8_t,
|
91
|
+
ca->grid = ALLOC_N(CArray *, ndim);
|
92
|
+
ca->contig = ALLOC_N(int8_t, ndim);
|
93
93
|
}
|
94
94
|
|
95
|
-
memcpy(ca->dim, dim,
|
95
|
+
memcpy(ca->dim, dim, ndim * sizeof(ca_size_t));
|
96
96
|
|
97
97
|
if ( ! share ) {
|
98
|
-
for (i=0; i<
|
98
|
+
for (i=0; i<ndim; i++) {
|
99
99
|
if ( grid[i] ) {
|
100
100
|
if ( ca_is_any_masked(grid[i]) ) {
|
101
101
|
ca_size_t gsize = grid[i]->elements - ca_count_masked(grid[i]);
|
@@ -137,7 +137,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
|
137
137
|
}
|
138
138
|
}
|
139
139
|
|
140
|
-
if ( ca->
|
140
|
+
if ( ca->ndim == 1 && ca_is_scalar(grid[0]) ) {
|
141
141
|
ca_set_flag(ca, CA_FLAG_SCALAR);
|
142
142
|
}
|
143
143
|
|
@@ -169,7 +169,7 @@ free_ca_grid (void *ap)
|
|
169
169
|
ca_free(ca->mask);
|
170
170
|
if ( ! (ca->flags & CA_FLAG_SHARE_INDEX)) {
|
171
171
|
xfree(ca->contig);
|
172
|
-
for (i=0; i<ca->
|
172
|
+
for (i=0; i<ca->ndim; i++) {
|
173
173
|
ca_free(ca->grid[i]);
|
174
174
|
}
|
175
175
|
xfree(ca->grid);
|
@@ -217,7 +217,7 @@ ca_grid_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
217
217
|
ca_size_t n;
|
218
218
|
|
219
219
|
n = 0;
|
220
|
-
for (i=0; i<ca->
|
220
|
+
for (i=0; i<ca->ndim; i++) {
|
221
221
|
n = dim0[i]*n + *(ca_size_t*) ca_ptr_at_addr(grid[i], idx[i]);
|
222
222
|
}
|
223
223
|
|
@@ -240,7 +240,7 @@ ca_grid_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
240
240
|
CArray **grid = ca->grid;
|
241
241
|
ca_size_t idx0[CA_RANK_MAX];
|
242
242
|
int8_t i;
|
243
|
-
for (i=0; i<ca->
|
243
|
+
for (i=0; i<ca->ndim; i++) {
|
244
244
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
245
245
|
}
|
246
246
|
ca_fetch_index(ca->parent, idx0, ptr);
|
@@ -253,7 +253,7 @@ ca_grid_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
253
253
|
CArray **grid = ca->grid;
|
254
254
|
ca_size_t idx0[CA_RANK_MAX];
|
255
255
|
int8_t i;
|
256
|
-
for (i=0; i<ca->
|
256
|
+
for (i=0; i<ca->ndim; i++) {
|
257
257
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
258
258
|
}
|
259
259
|
ca_store_index(ca->parent, idx0, ptr);
|
@@ -386,7 +386,7 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
386
386
|
CArray **grid = ca->grid;
|
387
387
|
ca_size_t i, k;
|
388
388
|
|
389
|
-
if ( level == ca->
|
389
|
+
if ( level == ca->ndim - 1 ) {
|
390
390
|
idx[level] = 0;
|
391
391
|
idx0[level] = 0;
|
392
392
|
if ( ca->contig[level] ) {
|
@@ -460,7 +460,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
|
460
460
|
CArray **grid = ca->grid;
|
461
461
|
ca_size_t i, k;
|
462
462
|
|
463
|
-
if ( level == ca->
|
463
|
+
if ( level == ca->ndim - 1 ) {
|
464
464
|
idx[level] = 0;
|
465
465
|
idx0[level] = 0;
|
466
466
|
if ( ca->contig[level] ) {
|
@@ -532,7 +532,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
|
532
532
|
{
|
533
533
|
CArray **grid = ca->grid;
|
534
534
|
ca_size_t i, k;
|
535
|
-
if ( level == ca->
|
535
|
+
if ( level == ca->ndim - 1 ) {
|
536
536
|
idx0[level] = 0;
|
537
537
|
if ( ca->contig[level] ) {
|
538
538
|
char *p = ca_ptr_at_index(ca->parent, idx0);
|
@@ -624,21 +624,21 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
624
624
|
|
625
625
|
ridx = rb_ary_new4(argc, argv);
|
626
626
|
|
627
|
-
if ( RARRAY_LEN(ridx) > ca->
|
628
|
-
rb_raise(rb_eArgError, "# of arguments doesn't equal to the
|
627
|
+
if ( RARRAY_LEN(ridx) > ca->ndim ) {
|
628
|
+
rb_raise(rb_eArgError, "# of arguments doesn't equal to the ndim");
|
629
629
|
}
|
630
|
-
else if ( RARRAY_LEN(ridx) < ca->
|
630
|
+
else if ( RARRAY_LEN(ridx) < ca->ndim ) {
|
631
631
|
volatile VALUE ref;
|
632
632
|
CArray *cv;
|
633
633
|
ca_size_t rdim[CA_RANK_MAX];
|
634
|
-
ca_size_t
|
634
|
+
ca_size_t rndim = RARRAY_LEN(ridx);
|
635
635
|
ca_size_t j = 0, k;
|
636
|
-
for (i=0; i<
|
636
|
+
for (i=0; i<rndim; i++) {
|
637
637
|
rval = rb_ary_entry(ridx, i);
|
638
638
|
if ( rb_obj_is_carray(rval) ) {
|
639
639
|
Data_Get_Struct(rval, CArray, cv);
|
640
640
|
rdim[i] = 1;
|
641
|
-
for (k=0; k<cv->
|
641
|
+
for (k=0; k<cv->ndim; k++) {
|
642
642
|
rdim[i] *= ca->dim[j];
|
643
643
|
j += 1;
|
644
644
|
}
|
@@ -648,10 +648,10 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
648
648
|
j += 1;
|
649
649
|
}
|
650
650
|
}
|
651
|
-
if ( j != ca->
|
652
|
-
rb_raise(rb_eArgError, "invalid total
|
651
|
+
if ( j != ca->ndim ) {
|
652
|
+
rb_raise(rb_eArgError, "invalid total ndim of args");
|
653
653
|
}
|
654
|
-
ref = rb_ca_refer_new(self, ca->data_type,
|
654
|
+
ref = rb_ca_refer_new(self, ca->data_type, rndim, rdim, ca->bytes, 0);
|
655
655
|
return rb_ca_grid(argc, argv, ref);
|
656
656
|
}
|
657
657
|
|
@@ -21,7 +21,7 @@
|
|
21
21
|
typedef struct {
|
22
22
|
int16_t obj_type;
|
23
23
|
int8_t data_type;
|
24
|
-
int8_t
|
24
|
+
int8_t ndim;
|
25
25
|
int32_t flags;
|
26
26
|
ca_size_t bytes;
|
27
27
|
ca_size_t elements;
|
@@ -49,7 +49,7 @@ static VALUE rb_cCAMapping;
|
|
49
49
|
int
|
50
50
|
ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
|
51
51
|
{
|
52
|
-
int8_t
|
52
|
+
int8_t ndim, data_type;
|
53
53
|
ca_size_t elements, bytes;
|
54
54
|
ca_size_t *p;
|
55
55
|
ca_size_t i;
|
@@ -66,19 +66,19 @@ ca_mapping_setup (CAMapping *ca, CArray *parent, CArray *mapper, int share)
|
|
66
66
|
ca->bytes = bytes;
|
67
67
|
ca->ptr = NULL;
|
68
68
|
|
69
|
-
|
69
|
+
ndim = mapper->ndim;
|
70
70
|
elements = mapper->elements;
|
71
71
|
|
72
|
-
ca->
|
72
|
+
ca->ndim = ndim;
|
73
73
|
ca->elements = elements;
|
74
74
|
ca->mask = NULL;
|
75
|
-
ca->dim = ALLOC_N(ca_size_t,
|
75
|
+
ca->dim = ALLOC_N(ca_size_t, ndim);
|
76
76
|
|
77
77
|
ca->parent = parent;
|
78
78
|
ca->attach = 0;
|
79
79
|
ca->nosync = 0;
|
80
80
|
|
81
|
-
memcpy(ca->dim, mapper->dim,
|
81
|
+
memcpy(ca->dim, mapper->dim, ndim * sizeof(ca_size_t));
|
82
82
|
|
83
83
|
if ( share ) {
|
84
84
|
ca_set_flag(ca, CA_FLAG_SHARE_INDEX);
|
@@ -176,7 +176,7 @@ ca_mapping_func_ptr_at_index (void *ap, ca_size_t *idx)
|
|
176
176
|
int8_t i;
|
177
177
|
ca_size_t n;
|
178
178
|
n = idx[0];
|
179
|
-
for (i=1; i<ca->
|
179
|
+
for (i=1; i<ca->ndim; i++) {
|
180
180
|
n = dim[i]*n+idx[i];
|
181
181
|
}
|
182
182
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|
@@ -200,7 +200,7 @@ ca_mapping_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
200
200
|
int8_t i;
|
201
201
|
ca_size_t n;
|
202
202
|
n = idx[0];
|
203
|
-
for (i=1; i<ca->
|
203
|
+
for (i=1; i<ca->ndim; i++) {
|
204
204
|
n = dim[i]*n+idx[i];
|
205
205
|
}
|
206
206
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|
@@ -215,7 +215,7 @@ ca_mapping_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
215
215
|
int8_t i;
|
216
216
|
ca_size_t n;
|
217
217
|
n = idx[0];
|
218
|
-
for (i=1; i<ca->
|
218
|
+
for (i=1; i<ca->ndim; i++) {
|
219
219
|
n = dim[i]*n+idx[i];
|
220
220
|
}
|
221
221
|
n = *(ca_size_t*) ca_ptr_at_addr(ca->mapper, n);
|