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
@@ -51,20 +51,20 @@ rb_ca_data_type (VALUE self)
|
|
51
51
|
/* rdoc
|
52
52
|
class CArray
|
53
53
|
# use CArray#ndims instead of this methods after carray-1.3.0
|
54
|
-
def
|
54
|
+
def ndim
|
55
55
|
end
|
56
|
-
# returns the
|
56
|
+
# returns the ndim (e.g. 1 for 1D array, 3 for 3D array, ...).
|
57
57
|
def ndims
|
58
58
|
end
|
59
59
|
end
|
60
60
|
*/
|
61
61
|
|
62
62
|
VALUE
|
63
|
-
|
63
|
+
rb_ca_ndim (VALUE self)
|
64
64
|
{
|
65
65
|
CArray *ca;
|
66
66
|
Data_Get_Struct(self, CArray, ca);
|
67
|
-
return INT2NUM(ca->
|
67
|
+
return INT2NUM(ca->ndim);
|
68
68
|
}
|
69
69
|
|
70
70
|
/* rdoc
|
@@ -147,8 +147,8 @@ rb_ca_dim (VALUE self)
|
|
147
147
|
CArray *ca;
|
148
148
|
int i;
|
149
149
|
Data_Get_Struct(self, CArray, ca);
|
150
|
-
dim = rb_ary_new2(ca->
|
151
|
-
for (i=0; i<ca->
|
150
|
+
dim = rb_ary_new2(ca->ndim);
|
151
|
+
for (i=0; i<ca->ndim; i++) {
|
152
152
|
rb_ary_store(dim, i, SIZE2NUM(ca->dim[i]));
|
153
153
|
}
|
154
154
|
return dim;
|
@@ -167,7 +167,7 @@ rb_ca_dim1 (VALUE self)
|
|
167
167
|
{
|
168
168
|
CArray *ca;
|
169
169
|
Data_Get_Struct(self, CArray, ca);
|
170
|
-
return ( ca->
|
170
|
+
return ( ca->ndim >= 2 ) ? SIZE2NUM(ca->dim[1]) : Qnil;
|
171
171
|
}
|
172
172
|
|
173
173
|
VALUE
|
@@ -175,7 +175,7 @@ rb_ca_dim2 (VALUE self)
|
|
175
175
|
{
|
176
176
|
CArray *ca;
|
177
177
|
Data_Get_Struct(self, CArray, ca);
|
178
|
-
return ( ca->
|
178
|
+
return ( ca->ndim >= 3 ) ? SIZE2NUM(ca->dim[2]) : Qnil;
|
179
179
|
}
|
180
180
|
|
181
181
|
VALUE
|
@@ -183,7 +183,7 @@ rb_ca_dim3 (VALUE self)
|
|
183
183
|
{
|
184
184
|
CArray *ca;
|
185
185
|
Data_Get_Struct(self, CArray, ca);
|
186
|
-
return ( ca->
|
186
|
+
return ( ca->ndim >= 4 ) ? SIZE2NUM(ca->dim[3]) : Qnil;
|
187
187
|
}
|
188
188
|
|
189
189
|
/* rdoc:
|
@@ -868,9 +868,9 @@ Init_carray_attribute ()
|
|
868
868
|
rb_define_method(rb_cCArray, "obj_type", rb_ca_obj_type, 0);
|
869
869
|
rb_define_method(rb_cCArray, "data_type", rb_ca_data_type, 0);
|
870
870
|
rb_define_method(rb_cCArray, "bytes", rb_ca_bytes, 0);
|
871
|
-
rb_define_method(rb_cCArray, "
|
872
|
-
rb_define_method(rb_cCArray, "
|
873
|
-
rb_define_method(rb_cCArray, "shape", rb_ca_dim, 0); /* after carray-1.
|
871
|
+
rb_define_method(rb_cCArray, "ndim", rb_ca_ndim, 0);
|
872
|
+
rb_define_method(rb_cCArray, "rank", rb_ca_ndim, 0); /* after carray-1.5.0 */
|
873
|
+
rb_define_method(rb_cCArray, "shape", rb_ca_dim, 0); /* after carray-1.5.0 */
|
874
874
|
rb_define_method(rb_cCArray, "dim", rb_ca_dim, 0);
|
875
875
|
rb_define_method(rb_cCArray, "dim0", rb_ca_dim0, 0);
|
876
876
|
rb_define_method(rb_cCArray, "dim1", rb_ca_dim1, 0);
|
File without changes
|
@@ -240,7 +240,7 @@ rb_ca_data_class_to_object (VALUE self)
|
|
240
240
|
obj = rb_cscalar_new(CA_OBJECT, 0, ca->mask);
|
241
241
|
}
|
242
242
|
else {
|
243
|
-
obj = rb_carray_new(CA_OBJECT, ca->
|
243
|
+
obj = rb_carray_new(CA_OBJECT, ca->ndim, ca->dim, 0, ca->mask);
|
244
244
|
}
|
245
245
|
|
246
246
|
for (i=0; i<ca->elements; i++) {
|
@@ -264,7 +264,7 @@ rb_ca_object_to_data_class (VALUE self, VALUE rtype, ca_size_t bytes)
|
|
264
264
|
obj = rb_cscalar_new(CA_FIXLEN, bytes, ca->mask);
|
265
265
|
}
|
266
266
|
else {
|
267
|
-
obj = rb_carray_new(CA_FIXLEN, ca->
|
267
|
+
obj = rb_carray_new(CA_FIXLEN, ca->ndim, ca->dim, bytes, ca->mask);
|
268
268
|
}
|
269
269
|
rb_ca_data_type_import(obj, rtype);
|
270
270
|
|
@@ -312,7 +312,7 @@ rb_ca_to_type_internal (int argc, VALUE *argv, VALUE self)
|
|
312
312
|
obj = rb_cscalar_new(data_type, bytes, ca->mask);
|
313
313
|
}
|
314
314
|
else {
|
315
|
-
obj = rb_carray_new(data_type, ca->
|
315
|
+
obj = rb_carray_new(data_type, ca->ndim, ca->dim, bytes, ca->mask);
|
316
316
|
}
|
317
317
|
|
318
318
|
rb_ca_data_type_import(obj, rtype);
|
@@ -1065,7 +1065,7 @@ rb_ca_cast_other (VALUE *self, volatile VALUE *other)
|
|
1065
1065
|
*/
|
1066
1066
|
|
1067
1067
|
VALUE
|
1068
|
-
|
1068
|
+
rb_ca_cast_with (VALUE self, VALUE other)
|
1069
1069
|
{
|
1070
1070
|
if ( rb_obj_is_carray(self) ) {
|
1071
1071
|
rb_ca_cast_self_or_other(&self, &other);
|
@@ -1145,7 +1145,7 @@ Init_carray_cast ()
|
|
1145
1145
|
"cast", rb_ca_s_cast, 1);
|
1146
1146
|
rb_define_singleton_method(rb_cCArray,
|
1147
1147
|
"cast_self_or_other", rb_ca_s_cast_self_or_other, 2);
|
1148
|
-
|
1149
|
-
|
1148
|
+
|
1149
|
+
rb_define_method(rb_cCArray, "cast_with", rb_ca_cast_with, 1);
|
1150
1150
|
}
|
1151
1151
|
|
File without changes
|
File without changes
|
@@ -27,7 +27,7 @@ rb_ca_to_a_loop (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
27
27
|
|
28
28
|
Data_Get_Struct(self, CArray, ca);
|
29
29
|
|
30
|
-
if ( level == ca->
|
30
|
+
if ( level == ca->ndim - 1 ) {
|
31
31
|
for (i=0; i<ca->dim[level]; i++) {
|
32
32
|
idx[level] = i;
|
33
33
|
rb_ary_store(ary, i, rb_ca_fetch_index(self, idx));
|
@@ -46,7 +46,7 @@ rb_ca_to_a_loop (VALUE self, int32_t level, ca_size_t *idx, VALUE ary)
|
|
46
46
|
/* rdoc:
|
47
47
|
class CArray
|
48
48
|
# Converts the array to Ruby's array. For higher dimension,
|
49
|
-
# the array is nested
|
49
|
+
# the array is nested ndim-1 times.
|
50
50
|
def to_a
|
51
51
|
end
|
52
52
|
end
|
@@ -149,7 +149,6 @@ rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
|
|
149
149
|
case T_FILE: {
|
150
150
|
volatile VALUE str;
|
151
151
|
rb_io_t *iop;
|
152
|
-
rb_secure(4);
|
153
152
|
GetOpenFile(io, iop);
|
154
153
|
rb_io_check_writable(iop);
|
155
154
|
ca_attach(ca);
|
@@ -162,7 +161,6 @@ rb_ca_dump_binary (int argc, VALUE *argv, VALUE self)
|
|
162
161
|
case T_FILE: {
|
163
162
|
OpenFile *iop;
|
164
163
|
size_t total;
|
165
|
-
rb_secure(4);
|
166
164
|
GetOpenFile(io, iop);
|
167
165
|
rb_io_check_writable(iop);
|
168
166
|
ca_attach(ca);
|
@@ -280,14 +278,14 @@ ca_to_cptr (void *ap)
|
|
280
278
|
rb_raise(rb_eRuntimeError, "[BUG] ca_to_cptr called for detached array");
|
281
279
|
}
|
282
280
|
|
283
|
-
if ( ca->
|
284
|
-
rb_raise(rb_eRuntimeError, "[BUG] ca_to_cptr called for
|
281
|
+
if ( ca->ndim == 1 ) {
|
282
|
+
rb_raise(rb_eRuntimeError, "[BUG] ca_to_cptr called for ndim-1 array");
|
285
283
|
}
|
286
284
|
|
287
285
|
offset[0] = 0;
|
288
286
|
count[0] = ca->dim[0];
|
289
287
|
ptr_num = count[0];
|
290
|
-
for (i=1; i<ca->
|
288
|
+
for (i=1; i<ca->ndim-1; i++) {
|
291
289
|
offset[i] = ptr_num;
|
292
290
|
count[i] = count[i-1] * ca->dim[i];
|
293
291
|
ptr_num += count[i];
|
@@ -295,15 +293,15 @@ ca_to_cptr (void *ap)
|
|
295
293
|
|
296
294
|
ptr = malloc(sizeof(void*)*ptr_num);
|
297
295
|
|
298
|
-
i = ca->
|
296
|
+
i = ca->ndim-2;
|
299
297
|
p = ptr + offset[i];
|
300
298
|
q = (char *)ca->ptr;
|
301
299
|
for (j=0; j<count[i]; j++) {
|
302
300
|
*p = (void*)q;
|
303
|
-
p++; q += ca->dim[ca->
|
301
|
+
p++; q += ca->dim[ca->ndim-1] * ca->bytes;
|
304
302
|
}
|
305
303
|
|
306
|
-
for (i=ca->
|
304
|
+
for (i=ca->ndim-3; i>=0; i--) {
|
307
305
|
p = ptr + offset[i];
|
308
306
|
r = ptr + offset[i+1];
|
309
307
|
for (j=0; j<count[i]; j++) {
|
@@ -25,7 +25,7 @@ ca_copy (void *ap)
|
|
25
25
|
co = (CArray *) cscalar_new(ca->data_type, ca->bytes, 0);
|
26
26
|
}
|
27
27
|
else { /* create array without mask */
|
28
|
-
co = carray_new(ca->data_type, ca->
|
28
|
+
co = carray_new(ca->data_type, ca->ndim, ca->dim, ca->bytes, 0);
|
29
29
|
}
|
30
30
|
|
31
31
|
if ( ca_is_attached(ca) ) {
|
@@ -72,7 +72,7 @@ ca_template (void *ap)
|
|
72
72
|
return (CArray*) cscalar_new(ca->data_type, ca->bytes, NULL);
|
73
73
|
}
|
74
74
|
else { /* create array without mask */
|
75
|
-
return carray_new(ca->data_type, ca->
|
75
|
+
return carray_new(ca->data_type, ca->ndim, ca->dim, ca->bytes, NULL);
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
@@ -84,7 +84,7 @@ ca_template_safe (void *ap)
|
|
84
84
|
return (CArray*) cscalar_new(ca->data_type, ca->bytes, NULL);
|
85
85
|
}
|
86
86
|
else { /* create array filled with 0, without mask */
|
87
|
-
return carray_new_safe(ca->data_type, ca->
|
87
|
+
return carray_new_safe(ca->data_type, ca->ndim, ca->dim, ca->bytes, NULL);
|
88
88
|
}
|
89
89
|
}
|
90
90
|
|
@@ -97,7 +97,7 @@ ca_template_safe2 (void *ap, int8_t data_type, ca_size_t bytes)
|
|
97
97
|
return (CArray*) cscalar_new(data_type, bytes, NULL);
|
98
98
|
}
|
99
99
|
else { /* create array filled with 0, without mask */
|
100
|
-
return carray_new_safe(data_type, ca->
|
100
|
+
return carray_new_safe(data_type, ca->ndim, ca->dim, bytes, NULL);
|
101
101
|
}
|
102
102
|
}
|
103
103
|
|
@@ -209,7 +209,7 @@ ca_paste_loop (CArray *ca, ca_size_t *offset, ca_size_t *offset0,
|
|
209
209
|
int32_t level, ca_size_t *idx, ca_size_t *idx0)
|
210
210
|
{
|
211
211
|
ca_size_t i;
|
212
|
-
if ( level == ca->
|
212
|
+
if ( level == ca->ndim - 1 ) {
|
213
213
|
idx[level] = offset[level];
|
214
214
|
idx0[level] = offset0[level];
|
215
215
|
memcpy(ca_ptr_at_index(ca, idx), ca_ptr_at_index(cs, idx0), size[level]*ca->bytes);
|
@@ -240,9 +240,9 @@ ca_paste (void *ap, ca_size_t *offset, void *sp)
|
|
240
240
|
int8_t i;
|
241
241
|
|
242
242
|
ca_check_same_data_type(ca, cs);
|
243
|
-
|
243
|
+
ca_check_same_ndim(ca, cs);
|
244
244
|
|
245
|
-
for (i=0; i<ca->
|
245
|
+
for (i=0; i<ca->ndim; i++) {
|
246
246
|
if ( offset[i] >= 0 ) {
|
247
247
|
if ( ca->dim[i] <= cs->dim[i] + offset[i] ) {
|
248
248
|
size[i] = ca->dim[i] - offset[i];
|
@@ -264,7 +264,7 @@ ca_paste (void *ap, ca_size_t *offset, void *sp)
|
|
264
264
|
}
|
265
265
|
}
|
266
266
|
|
267
|
-
for (i=0; i<ca->
|
267
|
+
for (i=0; i<ca->ndim; i++) {
|
268
268
|
CA_CHECK_INDEX(offset[i], ca->dim[i]);
|
269
269
|
}
|
270
270
|
|
@@ -287,7 +287,7 @@ ca_paste (void *ap, ca_size_t *offset, void *sp)
|
|
287
287
|
/* rdoc:
|
288
288
|
class CArray
|
289
289
|
# pastes `ary` to `self` at the index `idx`.
|
290
|
-
# `idx` should be Array object with the length same as `self.
|
290
|
+
# `idx` should be Array object with the length same as `self.ndim`.
|
291
291
|
# `ary` should have same shape with `self`.
|
292
292
|
def paste (idx, ary)
|
293
293
|
end
|
@@ -307,12 +307,12 @@ rb_ca_paste (VALUE self, VALUE roffset, VALUE rsrc)
|
|
307
307
|
|
308
308
|
Check_Type(roffset, T_ARRAY);
|
309
309
|
|
310
|
-
if ( RARRAY_LEN(roffset) != ca->
|
310
|
+
if ( RARRAY_LEN(roffset) != ca->ndim ) {
|
311
311
|
rb_raise(rb_eArgError,
|
312
|
-
"# of arguments should equal to the
|
312
|
+
"# of arguments should equal to the ndim");
|
313
313
|
}
|
314
314
|
|
315
|
-
for (i=0; i<ca->
|
315
|
+
for (i=0; i<ca->ndim; i++) {
|
316
316
|
offset[i] = NUM2SIZE(rb_ary_entry(roffset,i));
|
317
317
|
}
|
318
318
|
|
@@ -330,7 +330,7 @@ ca_clip_loop (CArray *ca, ca_size_t *offset, ca_size_t *offset0,
|
|
330
330
|
int32_t level, ca_size_t *idx, ca_size_t *idx0)
|
331
331
|
{
|
332
332
|
ca_size_t i;
|
333
|
-
if ( level == ca->
|
333
|
+
if ( level == ca->ndim - 1 ) {
|
334
334
|
idx[level] = offset[level];
|
335
335
|
idx0[level] = offset0[level];
|
336
336
|
memcpy(ca_ptr_at_index(cs, idx0), ca_ptr_at_index(ca, idx), size[level]*ca->bytes);
|
@@ -358,9 +358,9 @@ ca_clip (void *ap, ca_size_t *offset, void *sp)
|
|
358
358
|
int i;
|
359
359
|
|
360
360
|
ca_check_same_data_type(ca, cs);
|
361
|
-
|
361
|
+
ca_check_same_ndim(ca, cs);
|
362
362
|
|
363
|
-
for (i=0; i<ca->
|
363
|
+
for (i=0; i<ca->ndim; i++) {
|
364
364
|
if ( offset[i] >= 0 ) {
|
365
365
|
if ( ca->dim[i] <= cs->dim[i] + offset[i] ) {
|
366
366
|
size[i] = ca->dim[i] - offset[i];
|
@@ -382,7 +382,7 @@ ca_clip (void *ap, ca_size_t *offset, void *sp)
|
|
382
382
|
}
|
383
383
|
}
|
384
384
|
|
385
|
-
for (i=0; i<ca->
|
385
|
+
for (i=0; i<ca->ndim; i++) {
|
386
386
|
CA_CHECK_INDEX(offset[i], ca->dim[i]);
|
387
387
|
}
|
388
388
|
|
@@ -421,12 +421,12 @@ rb_ca_clip (VALUE self, VALUE roffset, VALUE rsrc)
|
|
421
421
|
|
422
422
|
Check_Type(roffset, T_ARRAY);
|
423
423
|
|
424
|
-
if ( RARRAY_LEN(roffset) != ca->
|
424
|
+
if ( RARRAY_LEN(roffset) != ca->ndim ) {
|
425
425
|
rb_raise(rb_eArgError,
|
426
|
-
"# of arguments should equal to the
|
426
|
+
"# of arguments should equal to the ndim");
|
427
427
|
}
|
428
428
|
|
429
|
-
for (i=0; i<ca->
|
429
|
+
for (i=0; i<ca->ndim; i++) {
|
430
430
|
offset[i] = NUM2SIZE(rb_ary_entry(roffset, i));
|
431
431
|
}
|
432
432
|
|
@@ -382,7 +382,7 @@ ca_addr2index (void *ap, ca_size_t addr, ca_size_t *idx)
|
|
382
382
|
CArray *ca = (CArray *) ap;
|
383
383
|
ca_size_t *dim = ca->dim;
|
384
384
|
int8_t i;
|
385
|
-
for (i=ca->
|
385
|
+
for (i=ca->ndim-1; i>=0; i--) {
|
386
386
|
idx[i] = addr % dim[i];
|
387
387
|
addr /= dim[i];
|
388
388
|
}
|
@@ -398,7 +398,7 @@ ca_index2addr (void *ap, ca_size_t *idx)
|
|
398
398
|
int8_t i;
|
399
399
|
ca_size_t n;
|
400
400
|
n = idx[0];
|
401
|
-
for (i=1; i<ca->
|
401
|
+
for (i=1; i<ca->ndim; i++) {
|
402
402
|
n = dim[i]*n+idx[i];
|
403
403
|
}
|
404
404
|
return n;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#include "carray.h"
|
2
|
+
|
3
|
+
VALUE rb_cCArrayBoolean;
|
4
|
+
VALUE rb_cCArrayUInt8;
|
5
|
+
VALUE rb_cCArrayUInt16;
|
6
|
+
VALUE rb_cCArrayUInt32;
|
7
|
+
VALUE rb_cCArrayUInt64;
|
8
|
+
VALUE rb_cCArrayInt8;
|
9
|
+
VALUE rb_cCArrayInt16;
|
10
|
+
VALUE rb_cCArrayInt32;
|
11
|
+
VALUE rb_cCArrayInt64;
|
12
|
+
VALUE rb_cCArrayFloat32;
|
13
|
+
VALUE rb_cCArrayFloat64;
|
14
|
+
VALUE rb_cCArrayFloat128;
|
15
|
+
VALUE rb_cCArrayCmplx64;
|
16
|
+
VALUE rb_cCArrayCmplx128;
|
17
|
+
VALUE rb_cCArrayCmplx256;
|
18
|
+
VALUE rb_cCArrayObject;
|
19
|
+
VALUE rb_cCArrayFixlen;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
ca_data_type_class (int8_t data_type)
|
23
|
+
{
|
24
|
+
switch ( data_type ) {
|
25
|
+
case CA_BOOLEAN: return rb_cCArrayBoolean; break;
|
26
|
+
case CA_INT8: return rb_cCArrayInt8; break;
|
27
|
+
case CA_UINT8: return rb_cCArrayUInt8; break;
|
28
|
+
case CA_INT16: return rb_cCArrayInt16; break;
|
29
|
+
case CA_UINT16: return rb_cCArrayUInt16; break;
|
30
|
+
case CA_INT32: return rb_cCArrayInt32; break;
|
31
|
+
case CA_UINT32: return rb_cCArrayUInt32; break;
|
32
|
+
case CA_INT64: return rb_cCArrayInt64; break;
|
33
|
+
case CA_UINT64: return rb_cCArrayUInt64; break;
|
34
|
+
case CA_FLOAT32: return rb_cCArrayFloat32; break;
|
35
|
+
case CA_FLOAT64: return rb_cCArrayFloat64; break;
|
36
|
+
case CA_FLOAT128: return rb_cCArrayFloat128; break;
|
37
|
+
case CA_CMPLX64: return rb_cCArrayCmplx64; break;
|
38
|
+
case CA_CMPLX128: return rb_cCArrayCmplx128; break;
|
39
|
+
case CA_CMPLX256: return rb_cCArrayCmplx256; break;
|
40
|
+
case CA_OBJECT: return rb_cCArrayObject; break;
|
41
|
+
default: rb_raise(rb_eRuntimeError, "invalid data type");
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
void
|
47
|
+
Init_carray_data_type ()
|
48
|
+
{
|
49
|
+
rb_cCArrayBoolean = rb_define_class_under(rb_cCArray, "Boolean", rb_cObject);
|
50
|
+
rb_cCArrayUInt8 = rb_define_class_under(rb_cCArray, "UInt8", rb_cObject);
|
51
|
+
rb_cCArrayUInt16 = rb_define_class_under(rb_cCArray, "UInt16", rb_cObject);
|
52
|
+
rb_cCArrayUInt32 = rb_define_class_under(rb_cCArray, "UInt32", rb_cObject);
|
53
|
+
rb_cCArrayUInt64 = rb_define_class_under(rb_cCArray, "UInt64", rb_cObject);
|
54
|
+
rb_cCArrayInt8 = rb_define_class_under(rb_cCArray, "Int8", rb_cObject);
|
55
|
+
rb_cCArrayInt16 = rb_define_class_under(rb_cCArray, "Int16", rb_cObject);
|
56
|
+
rb_cCArrayInt32 = rb_define_class_under(rb_cCArray, "Int32", rb_cObject);
|
57
|
+
rb_cCArrayInt64 = rb_define_class_under(rb_cCArray, "Int64", rb_cObject);
|
58
|
+
rb_cCArrayFloat32 = rb_define_class_under(rb_cCArray, "Float32", rb_cObject);
|
59
|
+
rb_cCArrayFloat64 = rb_define_class_under(rb_cCArray, "Float64", rb_cObject);
|
60
|
+
rb_cCArrayFloat128 = rb_define_class_under(rb_cCArray, "Float128", rb_cObject);
|
61
|
+
rb_cCArrayCmplx64 = rb_define_class_under(rb_cCArray, "Cmplx64", rb_cObject);
|
62
|
+
rb_cCArrayCmplx128 = rb_define_class_under(rb_cCArray, "Cmplx128", rb_cObject);
|
63
|
+
rb_cCArrayCmplx256 = rb_define_class_under(rb_cCArray, "Cmplx256", rb_cObject);
|
64
|
+
rb_cCArrayObject = rb_define_class_under(rb_cCArray, "Object", rb_cObject);
|
65
|
+
rb_cCArrayFixlen = rb_define_class_under(rb_cCArray, "Fixlen", rb_cObject);
|
66
|
+
}
|
@@ -48,7 +48,7 @@ rb_ca_elem_swap (VALUE self, VALUE ridx1, VALUE ridx2)
|
|
48
48
|
}
|
49
49
|
|
50
50
|
if ( TYPE(ridx1) == T_ARRAY ) {
|
51
|
-
for (i=0; i<ca->
|
51
|
+
for (i=0; i<ca->ndim; i++) {
|
52
52
|
k = NUM2SIZE(rb_ary_entry(ridx1, i));
|
53
53
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
54
54
|
idx1[i] = k;
|
@@ -71,7 +71,7 @@ rb_ca_elem_swap (VALUE self, VALUE ridx1, VALUE ridx2)
|
|
71
71
|
}
|
72
72
|
|
73
73
|
if ( TYPE(ridx2) == T_ARRAY ) {
|
74
|
-
for (i=0; i<ca->
|
74
|
+
for (i=0; i<ca->ndim; i++) {
|
75
75
|
k = NUM2SIZE(rb_ary_entry(ridx2, i));
|
76
76
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
77
77
|
idx2[i] = k;
|
@@ -159,7 +159,7 @@ rb_ca_elem_copy (VALUE self, VALUE ridx1, VALUE ridx2)
|
|
159
159
|
}
|
160
160
|
|
161
161
|
if ( TYPE(ridx1) == T_ARRAY ) {
|
162
|
-
for (i=0; i<ca->
|
162
|
+
for (i=0; i<ca->ndim; i++) {
|
163
163
|
k = NUM2SIZE(rb_ary_entry(ridx1, i));
|
164
164
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
165
165
|
idx1[i] = k;
|
@@ -180,7 +180,7 @@ rb_ca_elem_copy (VALUE self, VALUE ridx1, VALUE ridx2)
|
|
180
180
|
}
|
181
181
|
|
182
182
|
if ( TYPE(ridx2) == T_ARRAY ) {
|
183
|
-
for (i=0; i<ca->
|
183
|
+
for (i=0; i<ca->ndim; i++) {
|
184
184
|
k = NUM2SIZE(rb_ary_entry(ridx2, i));
|
185
185
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
186
186
|
idx2[i] = k;
|
@@ -228,7 +228,7 @@ rb_ca_elem_store (VALUE self, VALUE ridx, VALUE obj)
|
|
228
228
|
Data_Get_Struct(self, CArray, ca);
|
229
229
|
|
230
230
|
if ( TYPE(ridx) == T_ARRAY ) {
|
231
|
-
for (i=0; i<ca->
|
231
|
+
for (i=0; i<ca->ndim; i++) {
|
232
232
|
k = NUM2SIZE(rb_ary_entry(ridx, i));
|
233
233
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
234
234
|
idx[i] = k;
|
@@ -264,7 +264,7 @@ rb_ca_elem_fetch (VALUE self, VALUE ridx)
|
|
264
264
|
Data_Get_Struct(self, CArray, ca);
|
265
265
|
|
266
266
|
if ( TYPE(ridx) == T_ARRAY ) {
|
267
|
-
for (i=0; i<ca->
|
267
|
+
for (i=0; i<ca->ndim; i++) {
|
268
268
|
k = NUM2SIZE(rb_ary_entry(ridx, i));
|
269
269
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
270
270
|
idx[i] = k;
|
@@ -314,7 +314,7 @@ rb_ca_elem_incr (VALUE self, VALUE ridx1)
|
|
314
314
|
has_mask = ( ca->mask ) ? 1 : 0;
|
315
315
|
|
316
316
|
if ( TYPE(ridx1) == T_ARRAY ) {
|
317
|
-
for (i=0; i<ca->
|
317
|
+
for (i=0; i<ca->ndim; i++) {
|
318
318
|
k = NUM2SIZE(rb_ary_entry(ridx1, i));
|
319
319
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
320
320
|
idx1[i] = k;
|
@@ -401,7 +401,7 @@ rb_ca_elem_decr (VALUE self, VALUE ridx1)
|
|
401
401
|
has_mask = ( ca->mask ) ? 1 : 0;
|
402
402
|
|
403
403
|
if ( TYPE(ridx1) == T_ARRAY ) {
|
404
|
-
for (i=0; i<ca->
|
404
|
+
for (i=0; i<ca->ndim; i++) {
|
405
405
|
k = NUM2SIZE(rb_ary_entry(ridx1, i));
|
406
406
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
407
407
|
idx1[i] = k;
|
@@ -475,7 +475,7 @@ rb_ca_elem_test_masked (VALUE self, VALUE ridx1)
|
|
475
475
|
ca_update_mask(ca);
|
476
476
|
|
477
477
|
if ( TYPE(ridx1) == T_ARRAY ) {
|
478
|
-
for (i=0; i<ca->
|
478
|
+
for (i=0; i<ca->ndim; i++) {
|
479
479
|
k = NUM2SIZE(rb_ary_entry(ridx1, i));
|
480
480
|
CA_CHECK_INDEX(k, ca->dim[i]);
|
481
481
|
idx1[i] = k;
|