carray 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/ca_iter_block.c +32 -30
- data/ca_iter_dimension.c +24 -22
- data/ca_iter_window.c +25 -23
- data/ca_obj_array.c +58 -56
- data/ca_obj_bitarray.c +27 -27
- data/ca_obj_bitfield.c +46 -45
- data/ca_obj_block.c +77 -72
- data/ca_obj_fake.c +20 -20
- data/ca_obj_farray.c +22 -22
- data/ca_obj_field.c +31 -30
- data/ca_obj_grid.c +63 -62
- data/ca_obj_mapping.c +35 -32
- data/ca_obj_object.c +54 -54
- data/ca_obj_reduce.c +13 -13
- data/ca_obj_refer.c +42 -39
- data/ca_obj_repeat.c +50 -47
- data/ca_obj_select.c +24 -24
- data/ca_obj_shift.c +61 -58
- data/ca_obj_transpose.c +52 -51
- data/ca_obj_unbound_repeat.c +28 -27
- data/ca_obj_window.c +77 -72
- data/carray.gemspec +0 -2
- data/carray.h +190 -163
- data/carray_access.c +137 -136
- data/carray_attribute.c +24 -13
- data/carray_call_cfunc.c +21 -21
- data/carray_cast.c +106 -110
- data/carray_cast_func.rb +17 -17
- data/carray_class.c +3 -3
- data/carray_conversion.c +15 -15
- data/carray_copy.c +27 -27
- data/carray_core.c +22 -21
- data/carray_element.c +55 -47
- data/carray_generate.c +32 -32
- data/carray_iterator.c +36 -35
- data/carray_loop.c +37 -37
- data/carray_mask.c +21 -21
- data/carray_math.rb +18 -18
- data/carray_numeric.c +1 -1
- data/carray_operator.c +19 -18
- data/carray_order.c +30 -30
- data/carray_random.c +34 -32
- data/carray_sort_addr.c +12 -12
- data/carray_stat.c +127 -127
- data/carray_stat_proc.rb +152 -141
- data/carray_test.c +16 -16
- data/carray_utils.c +58 -56
- data/ext/calculus/carray_calculus.c +19 -20
- data/ext/calculus/carray_interp.c +12 -11
- data/ext/fortio/lib/fortio/fortran_sequential.rb +2 -2
- data/ext/fortio/ruby_fortio.c +1 -1
- data/ext/imagemap/carray_imagemap.c +14 -14
- data/ext/narray/ca_wrap_narray.c +30 -21
- data/extconf.rb +5 -0
- data/lib/carray/base/basic.rb +4 -3
- data/lib/carray/base/serialize.rb +3 -3
- data/lib/carray/graphics/gnuplot.rb +10 -7
- data/lib/carray/io/csv.rb +14 -9
- data/lib/carray/io/imagemagick.rb +7 -0
- data/lib/carray/io/sqlite3.rb +6 -4
- data/mkmath.rb +20 -20
- data/ruby_carray.c +2 -0
- data/ruby_ccomplex.c +3 -3
- data/test/test_130.rb +23 -0
- data/test/test_ALL.rb +2 -1
- data/test/test_order.rb +3 -3
- data/test/test_stat.rb +2 -2
- data/version.h +4 -4
- metadata +4 -37
- data/examples/ex001.rb +0 -10
- data/examples/test-int.rb +0 -13
- data/lib/carray/autoload/autoload_io_excel.rb +0 -5
- data/lib/carray/io/excel.rb +0 -26
data/ca_obj_fake.c
CHANGED
@@ -17,9 +17,9 @@ typedef struct {
|
|
17
17
|
int8_t data_type;
|
18
18
|
int8_t rank;
|
19
19
|
int32_t flags;
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
ca_size_t bytes;
|
21
|
+
ca_size_t elements;
|
22
|
+
ca_size_t *dim;
|
23
23
|
char *ptr;
|
24
24
|
CArray *mask;
|
25
25
|
CArray *parent;
|
@@ -39,10 +39,10 @@ static VALUE rb_cCAFake;
|
|
39
39
|
/* ------------------------------------------------------------------- */
|
40
40
|
|
41
41
|
int
|
42
|
-
ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type,
|
42
|
+
ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, ca_size_t bytes)
|
43
43
|
{
|
44
44
|
int8_t rank;
|
45
|
-
|
45
|
+
ca_size_t *dim, elements;
|
46
46
|
|
47
47
|
/* check arguments */
|
48
48
|
|
@@ -61,13 +61,13 @@ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, int32_t bytes)
|
|
61
61
|
ca->elements = elements;
|
62
62
|
ca->ptr = NULL;
|
63
63
|
ca->mask = NULL;
|
64
|
-
ca->dim = ALLOC_N(
|
64
|
+
ca->dim = ALLOC_N(ca_size_t, rank);
|
65
65
|
|
66
66
|
ca->parent = parent;
|
67
67
|
ca->attach = 0;
|
68
68
|
ca->nosync = 0;
|
69
69
|
|
70
|
-
memcpy(ca->dim, dim, rank * sizeof(
|
70
|
+
memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
|
71
71
|
|
72
72
|
if ( ca_has_mask(parent) ) {
|
73
73
|
ca_create_mask(ca);
|
@@ -81,7 +81,7 @@ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, int32_t bytes)
|
|
81
81
|
}
|
82
82
|
|
83
83
|
CAFake *
|
84
|
-
ca_fake_new (CArray *parent, int8_t data_type,
|
84
|
+
ca_fake_new (CArray *parent, int8_t data_type, ca_size_t bytes)
|
85
85
|
{
|
86
86
|
CAFake *ca = ALLOC(CAFake);
|
87
87
|
ca_fake_setup(ca, parent, data_type, bytes);
|
@@ -110,21 +110,21 @@ ca_fake_func_clone (void *ap)
|
|
110
110
|
}
|
111
111
|
|
112
112
|
static char *
|
113
|
-
ca_fake_func_ptr_at_addr (void *ap,
|
113
|
+
ca_fake_func_ptr_at_addr (void *ap, ca_size_t addr)
|
114
114
|
{
|
115
115
|
CAFake *ca = (CAFake *) ap;
|
116
116
|
return ca->ptr + ca->bytes * addr;
|
117
117
|
}
|
118
118
|
|
119
119
|
static char *
|
120
|
-
ca_fake_func_ptr_at_index (void *ap,
|
120
|
+
ca_fake_func_ptr_at_index (void *ap, ca_size_t *idx)
|
121
121
|
{
|
122
122
|
CAFake *ca = (CAFake *) ap;
|
123
123
|
return ca_func[CA_OBJ_ARRAY].ptr_at_index(ca, idx);
|
124
124
|
}
|
125
125
|
|
126
126
|
static void
|
127
|
-
ca_fake_func_fetch_index (void *ap,
|
127
|
+
ca_fake_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
128
128
|
{
|
129
129
|
CAFake *ca = (CAFake *) ap;
|
130
130
|
if ( ca->parent->bytes <= 32 ) {
|
@@ -141,7 +141,7 @@ ca_fake_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
|
141
141
|
}
|
142
142
|
|
143
143
|
static void
|
144
|
-
ca_fake_func_store_index (void *ap,
|
144
|
+
ca_fake_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
145
145
|
{
|
146
146
|
CAFake *ca = (CAFake *) ap;
|
147
147
|
if ( ca->parent->bytes <= 32 ) {
|
@@ -168,8 +168,8 @@ ca_fake_func_allocate (void *ap)
|
|
168
168
|
/* initialize elements with 0 for CA_OBJECT data_type */
|
169
169
|
if ( ca->data_type == CA_OBJECT ) {
|
170
170
|
VALUE *p = (VALUE *) ca->ptr;
|
171
|
-
VALUE zero =
|
172
|
-
|
171
|
+
VALUE zero = SIZE2NUM(0);
|
172
|
+
ca_size_t i;
|
173
173
|
for (i=0; i<ca->elements; i++) {
|
174
174
|
*p++ = zero;
|
175
175
|
}
|
@@ -189,8 +189,8 @@ ca_fake_func_attach (void *ap)
|
|
189
189
|
/* initialize elements with 0 for CA_OBJECT data_type */
|
190
190
|
if ( ca->data_type == CA_OBJECT ) {
|
191
191
|
VALUE *p = (VALUE *) ca->ptr;
|
192
|
-
VALUE zero =
|
193
|
-
|
192
|
+
VALUE zero = SIZE2NUM(0);
|
193
|
+
ca_size_t i;
|
194
194
|
for (i=0; i<ca->elements; i++) {
|
195
195
|
*p++ = zero;
|
196
196
|
}
|
@@ -315,7 +315,7 @@ ca_operation_function_t ca_fake_func = {
|
|
315
315
|
/* ------------------------------------------------------------------- */
|
316
316
|
|
317
317
|
VALUE
|
318
|
-
rb_ca_fake_new (VALUE cary, int8_t data_type,
|
318
|
+
rb_ca_fake_new (VALUE cary, int8_t data_type, ca_size_t bytes)
|
319
319
|
{
|
320
320
|
volatile VALUE obj;
|
321
321
|
CArray *parent;
|
@@ -341,11 +341,11 @@ rb_ca_fake (int argc, VALUE *argv, VALUE self)
|
|
341
341
|
volatile VALUE obj, rtype, ropt, rbytes = Qnil;
|
342
342
|
CArray *ca;
|
343
343
|
int8_t data_type;
|
344
|
-
|
344
|
+
ca_size_t bytes;
|
345
345
|
|
346
346
|
Data_Get_Struct(self, CArray, ca);
|
347
347
|
|
348
|
-
rb_scan_args(argc, argv, "11", &rtype, &ropt);
|
348
|
+
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
|
349
349
|
rb_scan_options(ropt, "bytes", &rbytes);
|
350
350
|
|
351
351
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
@@ -360,7 +360,7 @@ rb_ca_fake_type (VALUE self, VALUE rtype, VALUE rbytes)
|
|
360
360
|
{
|
361
361
|
volatile VALUE obj;
|
362
362
|
int8_t data_type;
|
363
|
-
|
363
|
+
ca_size_t bytes;
|
364
364
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
365
365
|
obj = rb_ca_fake_new(self, data_type, bytes);
|
366
366
|
rb_ca_data_type_import(obj, rtype);
|
data/ca_obj_farray.c
CHANGED
@@ -17,16 +17,16 @@ typedef struct {
|
|
17
17
|
int8_t data_type;
|
18
18
|
int8_t rank;
|
19
19
|
int32_t flags;
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
ca_size_t bytes;
|
21
|
+
ca_size_t elements;
|
22
|
+
ca_size_t *dim;
|
23
23
|
char *ptr;
|
24
24
|
CArray *mask;
|
25
25
|
CArray *parent;
|
26
26
|
uint32_t attach;
|
27
27
|
uint8_t nosync;
|
28
28
|
/* --------------- */
|
29
|
-
|
29
|
+
ca_size_t step;
|
30
30
|
} CAFarray;
|
31
31
|
|
32
32
|
static int8_t CA_OBJ_FARRAY;
|
@@ -44,7 +44,7 @@ int
|
|
44
44
|
ca_farray_setup (CAFarray *ca, CArray *parent)
|
45
45
|
{
|
46
46
|
int8_t rank, data_type;
|
47
|
-
|
47
|
+
ca_size_t *dim, elements, bytes;
|
48
48
|
int i;
|
49
49
|
|
50
50
|
/* check arguments */
|
@@ -63,7 +63,7 @@ ca_farray_setup (CAFarray *ca, CArray *parent)
|
|
63
63
|
ca->elements = elements;
|
64
64
|
ca->ptr = NULL;
|
65
65
|
ca->mask = NULL;
|
66
|
-
ca->dim = ALLOC_N(
|
66
|
+
ca->dim = ALLOC_N(ca_size_t, rank);
|
67
67
|
|
68
68
|
ca->parent = parent;
|
69
69
|
ca->attach = 0;
|
@@ -121,11 +121,11 @@ ca_farray_func_clone (void *ap)
|
|
121
121
|
#define ca_farray_func_ptr_at_index ca_array_func_ptr_at_index
|
122
122
|
|
123
123
|
static void
|
124
|
-
ca_farray_func_fetch_index (void *ap,
|
124
|
+
ca_farray_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
125
125
|
{
|
126
126
|
CAFarray *ca = (CAFarray *) ap;
|
127
127
|
int8_t rank = ca->rank;
|
128
|
-
|
128
|
+
ca_size_t idx0[CA_RANK_MAX];
|
129
129
|
int i;
|
130
130
|
for (i=0; i<rank; i++) {
|
131
131
|
idx0[i] = idx[rank-1-i];
|
@@ -134,11 +134,11 @@ ca_farray_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
|
134
134
|
}
|
135
135
|
|
136
136
|
static void
|
137
|
-
ca_farray_func_store_index (void *ap,
|
137
|
+
ca_farray_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
138
138
|
{
|
139
139
|
CAFarray *ca = (CAFarray *) ap;
|
140
140
|
int8_t rank = ca->rank;
|
141
|
-
|
141
|
+
ca_size_t idx0[CA_RANK_MAX];
|
142
142
|
int i;
|
143
143
|
for (i=0; i<rank; i++) {
|
144
144
|
idx0[i] = idx[rank-1-i];
|
@@ -253,11 +253,11 @@ ca_operation_function_t ca_farray_func = {
|
|
253
253
|
|
254
254
|
|
255
255
|
static void
|
256
|
-
ca_fa_attach_loop (CAFarray *ca, int8_t level,
|
256
|
+
ca_fa_attach_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
257
257
|
{
|
258
|
-
|
259
|
-
|
260
|
-
|
258
|
+
ca_size_t step = ca->step;
|
259
|
+
ca_size_t dim = ca->dim[level];
|
260
|
+
ca_size_t i;
|
261
261
|
if ( level == ca->rank - 1 ) {
|
262
262
|
idx[level] = 0;
|
263
263
|
idx0[0] = 0;
|
@@ -327,17 +327,17 @@ ca_fa_attach_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
|
|
327
327
|
static void
|
328
328
|
ca_fa_attach (CAFarray *ca)
|
329
329
|
{
|
330
|
-
|
331
|
-
|
330
|
+
ca_size_t idx[CA_RANK_MAX];
|
331
|
+
ca_size_t idx0[CA_RANK_MAX];
|
332
332
|
ca_fa_attach_loop(ca, 0, idx, idx0);
|
333
333
|
}
|
334
334
|
|
335
335
|
static void
|
336
|
-
ca_fa_sync_loop (CAFarray *ca, int8_t level,
|
336
|
+
ca_fa_sync_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
|
337
337
|
{
|
338
|
-
|
339
|
-
|
340
|
-
|
338
|
+
ca_size_t step = ca->step;
|
339
|
+
ca_size_t dim = ca->dim[level];
|
340
|
+
ca_size_t i;
|
341
341
|
|
342
342
|
if ( level == ca->rank - 1 ) {
|
343
343
|
idx[level] = 0;
|
@@ -407,8 +407,8 @@ ca_fa_sync_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
|
|
407
407
|
static void
|
408
408
|
ca_fa_sync (CAFarray *ca)
|
409
409
|
{
|
410
|
-
|
411
|
-
|
410
|
+
ca_size_t idx[CA_RANK_MAX];
|
411
|
+
ca_size_t idx0[CA_RANK_MAX];
|
412
412
|
ca_fa_sync_loop(ca, 0, idx, idx0);
|
413
413
|
}
|
414
414
|
|
data/ca_obj_field.c
CHANGED
@@ -17,16 +17,16 @@ typedef struct {
|
|
17
17
|
int8_t data_type;
|
18
18
|
int8_t rank;
|
19
19
|
int32_t flags;
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
ca_size_t bytes;
|
21
|
+
ca_size_t elements;
|
22
|
+
ca_size_t *dim;
|
23
23
|
char *ptr;
|
24
24
|
CArray *mask;
|
25
25
|
CArray *parent;
|
26
26
|
uint32_t attach;
|
27
27
|
uint8_t nosync;
|
28
28
|
/* -------------*/
|
29
|
-
|
29
|
+
ca_size_t offset;
|
30
30
|
} CAField;
|
31
31
|
|
32
32
|
static int8_t CA_OBJ_FIELD;
|
@@ -42,10 +42,10 @@ static VALUE rb_cCAField;
|
|
42
42
|
|
43
43
|
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
47
|
int8_t rank;
|
48
|
-
|
48
|
+
ca_size_t elements;
|
49
49
|
|
50
50
|
/* check arguments */
|
51
51
|
|
@@ -75,14 +75,14 @@ ca_field_setup (CAField *ca, CArray *parent,
|
|
75
75
|
ca->elements = elements;
|
76
76
|
ca->ptr = NULL;
|
77
77
|
ca->mask = NULL;
|
78
|
-
ca->dim = ALLOC_N(
|
78
|
+
ca->dim = ALLOC_N(ca_size_t, rank);
|
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, rank * sizeof(
|
85
|
+
memcpy(ca->dim, parent->dim, rank * sizeof(ca_size_t));
|
86
86
|
|
87
87
|
if ( ca_has_mask(parent) ) {
|
88
88
|
ca_create_mask(ca);
|
@@ -96,7 +96,7 @@ ca_field_setup (CAField *ca, CArray *parent,
|
|
96
96
|
}
|
97
97
|
|
98
98
|
CAField *
|
99
|
-
ca_field_new (CArray *parent,
|
99
|
+
ca_field_new (CArray *parent, ca_size_t offset, int8_t data_type, ca_size_t bytes)
|
100
100
|
{
|
101
101
|
CAField *ca = ALLOC(CAField);
|
102
102
|
ca_field_setup(ca, parent, offset, data_type, bytes);
|
@@ -128,11 +128,11 @@ ca_field_func_clone (void *ap)
|
|
128
128
|
}
|
129
129
|
|
130
130
|
static char *
|
131
|
-
ca_field_func_ptr_at_addr (void *ap,
|
131
|
+
ca_field_func_ptr_at_addr (void *ap, ca_size_t addr)
|
132
132
|
{
|
133
133
|
CAField *ca = (CAField *) ap;
|
134
134
|
if ( ! ca->ptr ) {
|
135
|
-
|
135
|
+
ca_size_t idx[CA_RANK_MAX];
|
136
136
|
ca_addr2index((CArray *)ca, addr, idx);
|
137
137
|
return ca_ptr_at_index(ca, idx);
|
138
138
|
}
|
@@ -142,12 +142,13 @@ ca_field_func_ptr_at_addr (void *ap, int32_t addr)
|
|
142
142
|
}
|
143
143
|
|
144
144
|
static char *
|
145
|
-
ca_field_func_ptr_at_index (void *ap,
|
145
|
+
ca_field_func_ptr_at_index (void *ap, ca_size_t *idx)
|
146
146
|
{
|
147
147
|
CAField *ca = (CAField *) ap;
|
148
148
|
if ( ! ca->ptr ) {
|
149
|
-
|
150
|
-
|
149
|
+
ca_size_t *dim = ca->dim;
|
150
|
+
int8_t i;
|
151
|
+
ca_size_t n;
|
151
152
|
n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[rank-1] */
|
152
153
|
for (i=1; i<ca->rank; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[rank-1] */
|
153
154
|
n = dim[i]*n+idx[i]; /* ... + idx[rank-2]*dim[1] + idx[rank-1] */
|
@@ -166,7 +167,7 @@ ca_field_func_ptr_at_index (void *ap, int32_t *idx)
|
|
166
167
|
}
|
167
168
|
|
168
169
|
static void
|
169
|
-
ca_field_func_fetch_index (void *ap,
|
170
|
+
ca_field_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
170
171
|
{
|
171
172
|
CAField *ca = (CAField *) ap;
|
172
173
|
if ( ca->parent->bytes <= 32 ) {
|
@@ -183,7 +184,7 @@ ca_field_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
|
183
184
|
}
|
184
185
|
|
185
186
|
static void
|
186
|
-
ca_field_func_store_index (void *ap,
|
187
|
+
ca_field_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
187
188
|
{
|
188
189
|
CAField *ca = (CAField *) ap;
|
189
190
|
if ( ca->parent->bytes <= 32 ) {
|
@@ -313,9 +314,9 @@ ca_operation_function_t ca_field_func = {
|
|
313
314
|
static void
|
314
315
|
ca_field_attach (CAField *ca)
|
315
316
|
{
|
316
|
-
|
317
|
-
|
318
|
-
|
317
|
+
ca_size_t pbytes = ca->parent->bytes;
|
318
|
+
ca_size_t bytes = ca->bytes;
|
319
|
+
ca_size_t n = ca->elements;
|
319
320
|
|
320
321
|
switch ( ca->data_type ) {
|
321
322
|
case CA_BOOLEAN:
|
@@ -380,9 +381,9 @@ ca_field_attach (CAField *ca)
|
|
380
381
|
static void
|
381
382
|
ca_field_sync (CAField *ca)
|
382
383
|
{
|
383
|
-
|
384
|
-
|
385
|
-
|
384
|
+
ca_size_t pbytes = ca->parent->bytes;
|
385
|
+
ca_size_t bytes = ca->bytes;
|
386
|
+
ca_size_t n = ca->elements;
|
386
387
|
|
387
388
|
switch ( ca->data_type ) {
|
388
389
|
case CA_BOOLEAN:
|
@@ -447,8 +448,8 @@ ca_field_sync (CAField *ca)
|
|
447
448
|
static void
|
448
449
|
ca_field_fill (CAField *ca, char *ptr)
|
449
450
|
{
|
450
|
-
|
451
|
-
|
451
|
+
ca_size_t pbytes = ca->parent->bytes;
|
452
|
+
ca_size_t n = ca->elements;
|
452
453
|
char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
|
453
454
|
|
454
455
|
switch ( ca->data_type ) {
|
@@ -509,7 +510,7 @@ ca_field_fill (CAField *ca, char *ptr)
|
|
509
510
|
/* ------------------------------------------------------------------- */
|
510
511
|
|
511
512
|
VALUE
|
512
|
-
rb_ca_field_new (VALUE cary,
|
513
|
+
rb_ca_field_new (VALUE cary, ca_size_t offset, int8_t data_type, ca_size_t bytes)
|
513
514
|
{
|
514
515
|
volatile VALUE obj;
|
515
516
|
CArray *parent;
|
@@ -562,7 +563,7 @@ rb_ca_field (int argc, VALUE *argv, VALUE self)
|
|
562
563
|
volatile VALUE obj, voffset, rtype, ropt, rbytes = Qnil;
|
563
564
|
CArray *ca;
|
564
565
|
int8_t data_type;
|
565
|
-
|
566
|
+
ca_size_t offset, bytes;
|
566
567
|
|
567
568
|
if ( argc == 1 ) {
|
568
569
|
return rb_ca_field_as_member(self, argv[0]);
|
@@ -574,16 +575,16 @@ rb_ca_field (int argc, VALUE *argv, VALUE self)
|
|
574
575
|
/* CArray#field(offset, data_class) */
|
575
576
|
/* CArray#field(offset, template) */
|
576
577
|
|
577
|
-
rb_scan_args(argc, argv, "21", &voffset, &rtype, &ropt);
|
578
|
+
rb_scan_args(argc, argv, "21", (VALUE *) &voffset, (VALUE *) &rtype, (VALUE *) &ropt);
|
578
579
|
rb_scan_options(ropt, "bytes", &rbytes);
|
579
580
|
|
580
|
-
offset =
|
581
|
+
offset = NUM2SIZE(voffset);
|
581
582
|
|
582
583
|
if ( rb_obj_is_carray(rtype) ) {
|
583
584
|
CArray *ct;
|
584
|
-
|
585
|
+
ca_size_t dim[CA_RANK_MAX];
|
585
586
|
int8_t rank;
|
586
|
-
|
587
|
+
int8_t i, j;
|
587
588
|
Data_Get_Struct(rtype, CArray, ct);
|
588
589
|
data_type = CA_FIXLEN;
|
589
590
|
bytes = ct->bytes * ct->elements;
|
data/ca_obj_grid.c
CHANGED
@@ -17,9 +17,9 @@ typedef struct {
|
|
17
17
|
int8_t data_type;
|
18
18
|
int8_t rank;
|
19
19
|
int32_t flags;
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
ca_size_t bytes;
|
21
|
+
ca_size_t elements;
|
22
|
+
ca_size_t *dim;
|
23
23
|
char *ptr;
|
24
24
|
CArray *mask;
|
25
25
|
CArray *parent;
|
@@ -40,12 +40,12 @@ static VALUE rb_cCAGrid;
|
|
40
40
|
static int8_t CA_OBJ_GRID;
|
41
41
|
|
42
42
|
int
|
43
|
-
ca_grid_setup (CAGrid *ca, CArray *parent,
|
43
|
+
ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
|
44
44
|
CArray **grid, int8_t *contig, int share)
|
45
45
|
{
|
46
46
|
int8_t rank, data_type;
|
47
|
-
|
48
|
-
|
47
|
+
ca_size_t *dim0;
|
48
|
+
ca_size_t elements, bytes;
|
49
49
|
double length;
|
50
50
|
int i, j, k;
|
51
51
|
|
@@ -76,7 +76,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
|
|
76
76
|
ca->elements = elements;
|
77
77
|
ca->ptr = NULL;
|
78
78
|
ca->mask = NULL;
|
79
|
-
ca->dim = ALLOC_N(
|
79
|
+
ca->dim = ALLOC_N(ca_size_t, rank);
|
80
80
|
|
81
81
|
ca->parent = parent;
|
82
82
|
ca->attach = 0;
|
@@ -92,23 +92,23 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
|
|
92
92
|
ca->contig = ALLOC_N(int8_t, rank);
|
93
93
|
}
|
94
94
|
|
95
|
-
memcpy(ca->dim, dim, rank * sizeof(
|
95
|
+
memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
|
96
96
|
|
97
97
|
if ( ! share ) {
|
98
98
|
for (i=0; i<rank; 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]);
|
102
102
|
boolean8_t *m;
|
103
|
-
|
104
|
-
ca->grid[i] = carray_new(
|
103
|
+
ca_size_t n;
|
104
|
+
ca->grid[i] = carray_new(CA_SIZE, 1, &gsize, 0, NULL);
|
105
105
|
m = (boolean8_t *)grid[i]->mask->ptr;
|
106
106
|
n = 0;
|
107
107
|
for (j=0; j<grid[i]->elements; j++) {
|
108
108
|
if ( ! *m ) {
|
109
|
-
k = ((
|
109
|
+
k = ((ca_size_t*)grid[i]->ptr)[j];
|
110
110
|
CA_CHECK_INDEX(k, dim0[i]);
|
111
|
-
((
|
111
|
+
((ca_size_t*)ca->grid[i]->ptr)[n] = k;
|
112
112
|
n++;
|
113
113
|
}
|
114
114
|
m++;
|
@@ -118,17 +118,17 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
|
|
118
118
|
else {
|
119
119
|
ca->grid[i] = ca_template(grid[i]);
|
120
120
|
for (j=0; j<grid[i]->elements; j++) {
|
121
|
-
k = ((
|
121
|
+
k = ((ca_size_t*)grid[i]->ptr)[j];
|
122
122
|
CA_CHECK_INDEX(k, dim0[i]);
|
123
|
-
((
|
123
|
+
((ca_size_t*)ca->grid[i]->ptr)[j] = k;
|
124
124
|
}
|
125
125
|
ca->contig[i] = 0;
|
126
126
|
}
|
127
127
|
}
|
128
128
|
else {
|
129
|
-
|
130
|
-
ca->grid[i] = carray_new(
|
131
|
-
p = (
|
129
|
+
ca_size_t *p;
|
130
|
+
ca->grid[i] = carray_new(CA_SIZE, 1, &dim[i], 0, NULL);
|
131
|
+
p = (ca_size_t *)ca->grid[i]->ptr;
|
132
132
|
for (j=0; j<dim[i]; j++) {
|
133
133
|
*p++ = j;
|
134
134
|
}
|
@@ -145,7 +145,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
|
|
145
145
|
}
|
146
146
|
|
147
147
|
CAGrid *
|
148
|
-
ca_grid_new (CArray *parent,
|
148
|
+
ca_grid_new (CArray *parent, ca_size_t *dim, CArray **grid)
|
149
149
|
{
|
150
150
|
CAGrid *ca = ALLOC(CAGrid);
|
151
151
|
ca_grid_setup(ca, parent, dim, grid, NULL, 0);
|
@@ -153,7 +153,7 @@ ca_grid_new (CArray *parent, int32_t *dim, CArray **grid)
|
|
153
153
|
}
|
154
154
|
|
155
155
|
CAGrid *
|
156
|
-
ca_grid_new_share (CArray *parent,
|
156
|
+
ca_grid_new_share (CArray *parent, ca_size_t *dim, CArray **grid, int8_t *contig)
|
157
157
|
{
|
158
158
|
CAGrid *ca = ALLOC(CAGrid);
|
159
159
|
ca_grid_setup(ca, parent, dim, grid, contig, 1);
|
@@ -164,7 +164,7 @@ static void
|
|
164
164
|
free_ca_grid (void *ap)
|
165
165
|
{
|
166
166
|
CAGrid *ca = (CAGrid *) ap;
|
167
|
-
|
167
|
+
ca_size_t i;
|
168
168
|
if ( ca != NULL ) {
|
169
169
|
ca_free(ca->mask);
|
170
170
|
if ( ! (ca->flags & CA_FLAG_SHARE_INDEX)) {
|
@@ -193,11 +193,11 @@ ca_grid_func_clone (void *ap)
|
|
193
193
|
}
|
194
194
|
|
195
195
|
static char *
|
196
|
-
ca_grid_func_ptr_at_addr (void *ap,
|
196
|
+
ca_grid_func_ptr_at_addr (void *ap, ca_size_t addr)
|
197
197
|
{
|
198
198
|
CAGrid *ca = (CAGrid *) ap;
|
199
199
|
if ( ! ca->ptr ) {
|
200
|
-
|
200
|
+
ca_size_t idx[CA_RANK_MAX];
|
201
201
|
ca_addr2index((CArray *)ca, addr, idx);
|
202
202
|
return ca_ptr_at_index(ca, idx);
|
203
203
|
}
|
@@ -207,17 +207,18 @@ ca_grid_func_ptr_at_addr (void *ap, int32_t addr)
|
|
207
207
|
}
|
208
208
|
|
209
209
|
static char *
|
210
|
-
ca_grid_func_ptr_at_index (void *ap,
|
210
|
+
ca_grid_func_ptr_at_index (void *ap, ca_size_t *idx)
|
211
211
|
{
|
212
212
|
CAGrid *ca = (CAGrid *) ap;
|
213
213
|
if ( ! ca->ptr ) {
|
214
214
|
CArray **grid = ca->grid;
|
215
|
-
|
216
|
-
|
215
|
+
ca_size_t *dim0 = ca->parent->dim;
|
216
|
+
int8_t i;
|
217
|
+
ca_size_t n;
|
217
218
|
|
218
219
|
n = 0;
|
219
220
|
for (i=0; i<ca->rank; i++) {
|
220
|
-
n = dim0[i]*n + *(
|
221
|
+
n = dim0[i]*n + *(ca_size_t*) ca_ptr_at_addr(grid[i], idx[i]);
|
221
222
|
}
|
222
223
|
|
223
224
|
if ( ca->parent->ptr == NULL ) {
|
@@ -233,12 +234,12 @@ ca_grid_func_ptr_at_index (void *ap, int32_t *idx)
|
|
233
234
|
}
|
234
235
|
|
235
236
|
static void
|
236
|
-
ca_grid_func_fetch_index (void *ap,
|
237
|
+
ca_grid_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
237
238
|
{
|
238
239
|
CAGrid *ca = (CAGrid *) ap;
|
239
240
|
CArray **grid = ca->grid;
|
240
|
-
|
241
|
-
|
241
|
+
ca_size_t idx0[CA_RANK_MAX];
|
242
|
+
int8_t i;
|
242
243
|
for (i=0; i<ca->rank; i++) {
|
243
244
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
244
245
|
}
|
@@ -246,12 +247,12 @@ ca_grid_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
|
246
247
|
}
|
247
248
|
|
248
249
|
static void
|
249
|
-
ca_grid_func_store_index (void *ap,
|
250
|
+
ca_grid_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
250
251
|
{
|
251
252
|
CAGrid *ca = (CAGrid *) ap;
|
252
253
|
CArray **grid = ca->grid;
|
253
|
-
|
254
|
-
|
254
|
+
ca_size_t idx0[CA_RANK_MAX];
|
255
|
+
int8_t i;
|
255
256
|
for (i=0; i<ca->rank; i++) {
|
256
257
|
ca_fetch_addr(grid[i], idx[i], &idx0[i]);
|
257
258
|
}
|
@@ -370,7 +371,7 @@ ca_operation_function_t ca_grid_func = {
|
|
370
371
|
|
371
372
|
#define proc_grid_attach(type) \
|
372
373
|
{ \
|
373
|
-
|
374
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
|
374
375
|
type *p = (type*) ca_ptr_at_index(ca, idx); \
|
375
376
|
type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
|
376
377
|
for (i=0; i<ca->dim[level]; i++, pi++, p++) { \
|
@@ -380,10 +381,10 @@ ca_operation_function_t ca_grid_func = {
|
|
380
381
|
}
|
381
382
|
|
382
383
|
static void
|
383
|
-
ca_grid_attach_loop (CAGrid *ca, int16_t level,
|
384
|
+
ca_grid_attach_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
384
385
|
{
|
385
386
|
CArray **grid = ca->grid;
|
386
|
-
|
387
|
+
ca_size_t i, k;
|
387
388
|
|
388
389
|
if ( level == ca->rank - 1 ) {
|
389
390
|
idx[level] = 0;
|
@@ -400,7 +401,7 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
400
401
|
case 8: proc_grid_attach(float64_t); break;
|
401
402
|
default:
|
402
403
|
{
|
403
|
-
|
404
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
|
404
405
|
char *p = ca_ptr_at_index(ca, idx);
|
405
406
|
char *q;
|
406
407
|
idx0[level] = 0;
|
@@ -422,8 +423,8 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
422
423
|
}
|
423
424
|
}
|
424
425
|
else {
|
425
|
-
|
426
|
-
pi = (
|
426
|
+
ca_size_t *pi;
|
427
|
+
pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
|
427
428
|
for (i=0; i<ca->dim[level]; i++, pi++) {
|
428
429
|
k = *pi;
|
429
430
|
idx[level] = i;
|
@@ -437,14 +438,14 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
437
438
|
static void
|
438
439
|
ca_grid_attach (CAGrid *ca)
|
439
440
|
{
|
440
|
-
|
441
|
-
|
441
|
+
ca_size_t idx[CA_RANK_MAX];
|
442
|
+
ca_size_t idx0[CA_RANK_MAX];
|
442
443
|
ca_grid_attach_loop(ca, (int16_t) 0, idx, idx0);
|
443
444
|
}
|
444
445
|
|
445
446
|
#define proc_grid_sync(type) \
|
446
447
|
{ \
|
447
|
-
|
448
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
|
448
449
|
type *p = (type*) ca_ptr_at_index(ca, idx); \
|
449
450
|
type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
|
450
451
|
for (i=0; i<ca->dim[level]; i++, pi++, p++) { \
|
@@ -454,10 +455,10 @@ ca_grid_attach (CAGrid *ca)
|
|
454
455
|
}
|
455
456
|
|
456
457
|
static void
|
457
|
-
ca_grid_sync_loop (CAGrid *ca, int16_t level,
|
458
|
+
ca_grid_sync_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
|
458
459
|
{
|
459
460
|
CArray **grid = ca->grid;
|
460
|
-
|
461
|
+
ca_size_t i, k;
|
461
462
|
|
462
463
|
if ( level == ca->rank - 1 ) {
|
463
464
|
idx[level] = 0;
|
@@ -474,7 +475,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
474
475
|
case 8: proc_grid_sync(float64_t); break;
|
475
476
|
default:
|
476
477
|
{
|
477
|
-
|
478
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
|
478
479
|
char *p = ca_ptr_at_index(ca, idx);
|
479
480
|
char *q;
|
480
481
|
idx0[level] = 0;
|
@@ -497,7 +498,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
497
498
|
}
|
498
499
|
else {
|
499
500
|
for (i=0; i<ca->dim[level]; i++) {
|
500
|
-
k = *(
|
501
|
+
k = *(ca_size_t*) ca_ptr_at_addr(grid[level], i);
|
501
502
|
idx[level] = i;
|
502
503
|
idx0[level] = k;
|
503
504
|
ca_grid_sync_loop(ca, level+1, idx, idx0);
|
@@ -509,14 +510,14 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
|
|
509
510
|
static void
|
510
511
|
ca_grid_sync (CAGrid *ca)
|
511
512
|
{
|
512
|
-
|
513
|
-
|
513
|
+
ca_size_t idx[CA_RANK_MAX];
|
514
|
+
ca_size_t idx0[CA_RANK_MAX];
|
514
515
|
ca_grid_sync_loop(ca, (int16_t) 0, idx, idx0);
|
515
516
|
}
|
516
517
|
|
517
518
|
#define proc_grid_fill(type) \
|
518
519
|
{ \
|
519
|
-
|
520
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
|
520
521
|
type fval = *(type*)ptr; \
|
521
522
|
type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
|
522
523
|
for (i=0; i<ca->dim[level]; i++, pi++) { \
|
@@ -527,10 +528,10 @@ ca_grid_sync (CAGrid *ca)
|
|
527
528
|
|
528
529
|
static void
|
529
530
|
ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
530
|
-
int16_t level,
|
531
|
+
int16_t level, ca_size_t *idx0)
|
531
532
|
{
|
532
533
|
CArray **grid = ca->grid;
|
533
|
-
|
534
|
+
ca_size_t i, k;
|
534
535
|
if ( level == ca->rank - 1 ) {
|
535
536
|
idx0[level] = 0;
|
536
537
|
if ( ca->contig[level] ) {
|
@@ -548,7 +549,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
|
548
549
|
case 8: proc_grid_fill(float64_t); break;
|
549
550
|
default:
|
550
551
|
{
|
551
|
-
|
552
|
+
ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
|
552
553
|
char *q;
|
553
554
|
idx0[level] = 0;
|
554
555
|
q = ca_ptr_at_index(ca->parent, idx0);
|
@@ -569,7 +570,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
|
569
570
|
}
|
570
571
|
else {
|
571
572
|
for (i=0; i<ca->dim[level]; i++) {
|
572
|
-
k = *(
|
573
|
+
k = *(ca_size_t*) ca_ptr_at_addr(grid[level], i);
|
573
574
|
idx0[level] = k;
|
574
575
|
ca_grid_fill_loop(ca, ptr, level+1, idx0);
|
575
576
|
}
|
@@ -580,14 +581,14 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
|
|
580
581
|
static void
|
581
582
|
ca_grid_fill (CAGrid *ca, char *ptr)
|
582
583
|
{
|
583
|
-
|
584
|
+
ca_size_t idx0[CA_RANK_MAX];
|
584
585
|
ca_grid_fill_loop(ca, ptr, (int16_t) 0, idx0);
|
585
586
|
}
|
586
587
|
|
587
588
|
/* ------------------------------------------------------------------- */
|
588
589
|
|
589
590
|
VALUE
|
590
|
-
rb_ca_grid_new (VALUE cary,
|
591
|
+
rb_ca_grid_new (VALUE cary, ca_size_t *dim, CArray **grid)
|
591
592
|
{
|
592
593
|
volatile VALUE obj;
|
593
594
|
CArray *parent;
|
@@ -615,9 +616,9 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
615
616
|
volatile VALUE list = rb_ary_new();
|
616
617
|
CArray *ca;
|
617
618
|
CArray *ci[CA_RANK_MAX];
|
618
|
-
|
619
|
+
ca_size_t dim[CA_RANK_MAX];
|
619
620
|
CArray *grid[CA_RANK_MAX];
|
620
|
-
|
621
|
+
ca_size_t i;
|
621
622
|
|
622
623
|
Data_Get_Struct(self, CArray, ca);
|
623
624
|
|
@@ -629,9 +630,9 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
629
630
|
else if ( RARRAY_LEN(ridx) < ca->rank ) {
|
630
631
|
volatile VALUE ref;
|
631
632
|
CArray *cv;
|
632
|
-
|
633
|
-
|
634
|
-
|
633
|
+
ca_size_t rdim[CA_RANK_MAX];
|
634
|
+
ca_size_t rrank = RARRAY_LEN(ridx);
|
635
|
+
ca_size_t j = 0, k;
|
635
636
|
for (i=0; i<rrank; i++) {
|
636
637
|
rval = rb_ary_entry(ridx, i);
|
637
638
|
if ( rb_obj_is_carray(rval) ) {
|
@@ -668,12 +669,12 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
|
|
668
669
|
}
|
669
670
|
}
|
670
671
|
else if ( rb_obj_is_kind_of(rval, rb_cRange) ) {
|
671
|
-
rval = rb_funcall(rb_mKernel, rb_intern("
|
672
|
+
rval = rb_funcall(rb_mKernel, rb_intern("CA_SIZE"), 1, rval);
|
672
673
|
}
|
673
674
|
else if ( TYPE(rval) == T_ARRAY ) {
|
674
675
|
rb_raise(rb_eRuntimeError, "not implemented for this index");
|
675
676
|
}
|
676
|
-
ci[i] = ca_wrap_readonly(rval,
|
677
|
+
ci[i] = ca_wrap_readonly(rval, CA_SIZE);
|
677
678
|
rb_ary_push(list, rval);
|
678
679
|
ca_attach(ci[i]);
|
679
680
|
|