carray 1.5.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS.md +10 -0
- data/TODO.md +1 -0
- data/carray.gemspec +1 -1
- data/ext/ca_iter_block.c +20 -5
- data/ext/ca_iter_dimension.c +21 -10
- data/ext/ca_iter_window.c +17 -5
- data/ext/ca_obj_array.c +73 -10
- data/ext/ca_obj_bitarray.c +21 -6
- data/ext/ca_obj_bitfield.c +21 -11
- data/ext/ca_obj_block.c +34 -10
- data/ext/ca_obj_fake.c +21 -6
- data/ext/ca_obj_farray.c +34 -5
- data/ext/ca_obj_field.c +23 -7
- data/ext/ca_obj_grid.c +36 -7
- data/ext/ca_obj_mapping.c +36 -7
- data/ext/ca_obj_object.c +35 -9
- data/ext/ca_obj_reduce.c +34 -5
- data/ext/ca_obj_refer.c +31 -10
- data/ext/ca_obj_repeat.c +35 -12
- data/ext/ca_obj_select.c +35 -9
- data/ext/ca_obj_shift.c +41 -12
- data/ext/ca_obj_transpose.c +36 -7
- data/ext/ca_obj_unbound_repeat.c +39 -14
- data/ext/ca_obj_window.c +46 -15
- data/ext/carray.h +97 -31
- data/ext/carray_access.c +25 -42
- data/ext/carray_attribute.c +35 -35
- data/ext/carray_call_cfunc.c +28 -28
- data/ext/carray_cast.c +25 -26
- data/ext/carray_cast_func.rb +1 -2
- data/ext/carray_conversion.c +7 -10
- data/ext/carray_copy.c +5 -5
- data/ext/carray_core.c +44 -7
- data/ext/carray_element.c +9 -9
- data/ext/carray_generate.c +7 -7
- data/ext/carray_iterator.c +33 -23
- data/ext/carray_loop.c +9 -9
- data/ext/carray_mask.c +38 -36
- data/ext/carray_math.rb +6 -6
- data/ext/carray_numeric.c +1 -1
- data/ext/carray_operator.c +31 -21
- data/ext/carray_order.c +216 -12
- data/ext/carray_sort_addr.c +2 -2
- data/ext/carray_stat.c +22 -22
- data/ext/carray_stat_proc.rb +13 -13
- data/ext/carray_test.c +8 -8
- data/ext/ruby_carray.c +7 -0
- data/ext/ruby_ccomplex.c +25 -11
- data/ext/version.h +6 -6
- data/lib/carray/inspect.rb +0 -3
- data/lib/carray/io/imagemagick.rb +8 -9
- data/lib/carray/mkmf.rb +1 -0
- data/lib/carray/time.rb +1 -1
- data/spec/Classes/ex1.rb +46 -0
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 753475db4ed70adab65aa99cea8b1d735580e9c0b223b5e09333fe330cc4bff6
|
4
|
+
data.tar.gz: 45358fcc7b4e34cc3149eb2efbd2147fbbddce6ace834bd1c55a1b5773715d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eee1c8bd046106b36fdd0f6f8efbfa6e6dd620934f117fc31ef8145355028092cbb576dd7e22e8432ccd1b2b0a8c89bb7737cf69da4c03c7502c765e7a8bc39
|
7
|
+
data.tar.gz: 7f1a2c12010b430777f08639983b22bfd7378c18703fb5cf042e164f5ec62d42963878469c90fb005d86d842362e48357c2fd7f5b5952e52b584892244b8b7c8
|
data/NEWS.md
CHANGED
data/TODO.md
CHANGED
data/carray.gemspec
CHANGED
data/ext/ca_iter_block.c
CHANGED
@@ -10,11 +10,26 @@
|
|
10
10
|
|
11
11
|
#include "carray.h"
|
12
12
|
|
13
|
+
extern const rb_data_type_t cablockiterator_data_type;
|
14
|
+
|
15
|
+
const rb_data_type_t cablockiterator_data_type = {
|
16
|
+
.parent = &caiterator_data_type,
|
17
|
+
.wrap_struct_name = "CABlockIterator",
|
18
|
+
.function = {
|
19
|
+
.dmark = NULL,
|
20
|
+
.dfree = free,
|
21
|
+
.dsize = NULL,
|
22
|
+
.dcompact = NULL
|
23
|
+
},
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
25
|
+
};
|
26
|
+
|
13
27
|
/* yard:
|
14
28
|
class CABlockIterator < CAIterator # :nodoc:
|
15
29
|
end
|
16
30
|
*/
|
17
31
|
|
32
|
+
|
18
33
|
VALUE rb_cCABlockIterator;
|
19
34
|
|
20
35
|
/*
|
@@ -152,9 +167,9 @@ ca_bi_setup (VALUE self, VALUE rref, VALUE rker)
|
|
152
167
|
|
153
168
|
rker = rb_obj_clone(rker);
|
154
169
|
|
155
|
-
|
156
|
-
|
157
|
-
|
170
|
+
TypedData_Get_Struct(self, CABlockIterator, &cablockiterator_data_type, it);
|
171
|
+
TypedData_Get_Struct(rref, CArray, &carray_data_type, ref);
|
172
|
+
TypedData_Get_Struct(rker, CABlock, &cablock_data_type, ker);
|
158
173
|
|
159
174
|
if ( ref->ndim != ker->ndim ) {
|
160
175
|
rb_raise(rb_eRuntimeError, "ndim mismatch between reference and kernel");
|
@@ -189,7 +204,7 @@ static VALUE
|
|
189
204
|
rb_bi_s_allocate (VALUE klass)
|
190
205
|
{
|
191
206
|
CABlockIterator *it;
|
192
|
-
return
|
207
|
+
return TypedData_Make_Struct(klass, CABlockIterator, &cablockiterator_data_type, it);
|
193
208
|
}
|
194
209
|
|
195
210
|
static VALUE
|
@@ -217,7 +232,7 @@ rb_ca_block_iterator (int argc, VALUE *argv, VALUE self)
|
|
217
232
|
rker = rb_ca_fetch2(self, argc, argv);
|
218
233
|
|
219
234
|
rb_check_carray_object(rker);
|
220
|
-
|
235
|
+
TypedData_Get_Struct(rker, CArray, &carray_data_type, ker);
|
221
236
|
|
222
237
|
if ( ker->obj_type != CA_OBJ_BLOCK ) {
|
223
238
|
rb_raise(rb_eRuntimeError, "kernel must be CABlock object");
|
data/ext/ca_iter_dimension.c
CHANGED
@@ -32,6 +32,18 @@ typedef struct {
|
|
32
32
|
int8_t symindex[CA_RANK_MAX];
|
33
33
|
} CADimIterator;
|
34
34
|
|
35
|
+
const rb_data_type_t cadimiterator_data_type = {
|
36
|
+
.parent = &caiterator_data_type,
|
37
|
+
.wrap_struct_name = "CADimIterator",
|
38
|
+
.function = {
|
39
|
+
.dmark = NULL,
|
40
|
+
.dfree = free,
|
41
|
+
.dsize = NULL,
|
42
|
+
.dcompact = NULL
|
43
|
+
},
|
44
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
45
|
+
};
|
46
|
+
|
35
47
|
/* -------------------------------------------------------------------- */
|
36
48
|
|
37
49
|
static CArray *
|
@@ -128,9 +140,9 @@ ca_di_setup (VALUE self, VALUE rref, CAIndexInfo *info)
|
|
128
140
|
CADimIterator *it;
|
129
141
|
CAIndexInfo blk_spec;
|
130
142
|
int8_t ndim;
|
131
|
-
int i, j
|
143
|
+
int i, j;
|
132
144
|
|
133
|
-
|
145
|
+
TypedData_Get_Struct(self, CADimIterator, &cadimiterator_data_type, it);
|
134
146
|
|
135
147
|
if ( info->type != CA_REG_ITERATOR ) {
|
136
148
|
rb_raise(rb_eRuntimeError, "given spec is not for dim iteratror");
|
@@ -153,7 +165,6 @@ ca_di_setup (VALUE self, VALUE rref, CAIndexInfo *info)
|
|
153
165
|
ndim = 0;
|
154
166
|
|
155
167
|
j = 0;
|
156
|
-
k = 0;
|
157
168
|
|
158
169
|
for (i=0; i<info->ndim; i++) {
|
159
170
|
if ( info->index_type[i] == CA_IDX_SCALAR ) {
|
@@ -183,8 +194,8 @@ ca_di_setup (VALUE self, VALUE rref, CAIndexInfo *info)
|
|
183
194
|
rker = rb_apply(rref, rb_intern("[]"), rindex);
|
184
195
|
|
185
196
|
it->ndim = ndim;
|
186
|
-
|
187
|
-
|
197
|
+
TypedData_Get_Struct(rref, CArray, &carray_data_type, it->reference);
|
198
|
+
TypedData_Get_Struct(rker, CArray, &carray_data_type, it->kernel);
|
188
199
|
it->kernel_at_addr = ca_di_kernel_at_addr;
|
189
200
|
it->kernel_at_index = ca_di_kernel_at_index;
|
190
201
|
it->kernel_move_to_addr = ca_di_kernel_move_to_addr;
|
@@ -203,7 +214,7 @@ static VALUE
|
|
203
214
|
rb_di_s_allocate (VALUE klass)
|
204
215
|
{
|
205
216
|
CADimIterator *it;
|
206
|
-
return
|
217
|
+
return TypedData_Make_Struct(klass, CADimIterator, &cadimiterator_data_type, it);
|
207
218
|
}
|
208
219
|
|
209
220
|
static VALUE
|
@@ -212,15 +223,15 @@ rb_di_initialize_copy (VALUE self, VALUE other)
|
|
212
223
|
volatile VALUE rref, rker;
|
213
224
|
CADimIterator *is, *io;
|
214
225
|
|
215
|
-
|
216
|
-
|
226
|
+
TypedData_Get_Struct(self, CADimIterator, &cadimiterator_data_type, is);
|
227
|
+
TypedData_Get_Struct(other, CADimIterator, &cadimiterator_data_type, io);
|
217
228
|
|
218
229
|
rref = rb_ivar_get(self, rb_intern("@reference"));
|
219
230
|
rker = rb_obj_clone(rb_ivar_get(self, rb_intern("@kernel")));
|
220
231
|
|
221
232
|
*io = *is;
|
222
233
|
|
223
|
-
|
234
|
+
TypedData_Get_Struct(rker, CArray, &carray_data_type, io->kernel);
|
224
235
|
|
225
236
|
rb_ivar_set(self, rb_intern("@reference"), rref); /* required ivar */
|
226
237
|
rb_ivar_set(self, rb_intern("@kernel"), rker);
|
@@ -235,7 +246,7 @@ rb_ca_dim_iterator (int argc, VALUE *argv, VALUE self)
|
|
235
246
|
CAIndexInfo info;
|
236
247
|
CArray *ca;
|
237
248
|
|
238
|
-
|
249
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
239
250
|
|
240
251
|
info.range_check = 1;
|
241
252
|
rb_ca_scan_index(ca->ndim, ca->dim, ca->elements, argc, argv, &info);
|
data/ext/ca_iter_window.c
CHANGED
@@ -23,6 +23,18 @@ typedef struct {
|
|
23
23
|
ca_size_t offset[CA_RANK_MAX];
|
24
24
|
} CAWindowIterator;
|
25
25
|
|
26
|
+
const rb_data_type_t cawindowiterator_data_type = {
|
27
|
+
.parent = &caiterator_data_type,
|
28
|
+
.wrap_struct_name = "CAWindowIterator",
|
29
|
+
.function = {
|
30
|
+
.dmark = NULL,
|
31
|
+
.dfree = free,
|
32
|
+
.dsize = NULL,
|
33
|
+
.dcompact = NULL
|
34
|
+
},
|
35
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
36
|
+
};
|
37
|
+
|
26
38
|
VALUE rb_cCAWindowIterator;
|
27
39
|
|
28
40
|
/* yard:
|
@@ -130,9 +142,9 @@ ca_vi_setup (VALUE self, VALUE rref, VALUE rker)
|
|
130
142
|
|
131
143
|
rker = rb_obj_clone(rker);
|
132
144
|
|
133
|
-
|
134
|
-
|
135
|
-
|
145
|
+
TypedData_Get_Struct(self, CAWindowIterator, &cawindowiterator_data_type, it);
|
146
|
+
TypedData_Get_Struct(rref, CArray, &carray_data_type, ref);
|
147
|
+
TypedData_Get_Struct(rker, CArray, &carray_data_type, ker);
|
136
148
|
|
137
149
|
if ( ref->ndim != ker->ndim ) {
|
138
150
|
rb_raise(rb_eRuntimeError, "ndim mismatch between reference and kernel");
|
@@ -161,7 +173,7 @@ static VALUE
|
|
161
173
|
rb_vi_s_allocate (VALUE klass)
|
162
174
|
{
|
163
175
|
CAWindowIterator *it;
|
164
|
-
return
|
176
|
+
return TypedData_Make_Struct(klass, CAWindowIterator, &cawindowiterator_data_type, it);
|
165
177
|
}
|
166
178
|
|
167
179
|
static VALUE
|
@@ -170,7 +182,7 @@ rb_vi_initialize (VALUE self, VALUE rker)
|
|
170
182
|
CArray *ker;
|
171
183
|
|
172
184
|
rb_check_carray_object(rker);
|
173
|
-
|
185
|
+
TypedData_Get_Struct(rker, CArray, &carray_data_type, ker);
|
174
186
|
if ( ker->obj_type != CA_OBJ_WINDOW ) {
|
175
187
|
rb_raise(rb_eRuntimeError, "kernel must be CAWindow object");
|
176
188
|
}
|
data/ext/ca_obj_array.c
CHANGED
@@ -13,9 +13,72 @@
|
|
13
13
|
#include "rubysig.h"
|
14
14
|
#endif
|
15
15
|
|
16
|
+
/* -------------------------------------------------------------------- */
|
17
|
+
|
18
|
+
const rb_data_type_t carray_data_type = {
|
19
|
+
.parent = NULL,
|
20
|
+
.wrap_struct_name = "CArray",
|
21
|
+
.function = {
|
22
|
+
.dmark = ca_mark,
|
23
|
+
.dfree = ca_free,
|
24
|
+
.dsize = NULL,
|
25
|
+
.dcompact = NULL
|
26
|
+
},
|
27
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
28
|
+
};
|
29
|
+
|
30
|
+
const rb_data_type_t cawrap_data_type = {
|
31
|
+
.parent = &carray_data_type,
|
32
|
+
.wrap_struct_name = "CAWrap",
|
33
|
+
.function = {
|
34
|
+
.dmark = ca_mark,
|
35
|
+
.dfree = ca_free,
|
36
|
+
.dsize = NULL,
|
37
|
+
.dcompact = NULL
|
38
|
+
},
|
39
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
40
|
+
};
|
41
|
+
|
42
|
+
const rb_data_type_t cscalar_data_type = {
|
43
|
+
.parent = &carray_data_type,
|
44
|
+
.wrap_struct_name = "CScalar",
|
45
|
+
.function = {
|
46
|
+
.dmark = ca_mark,
|
47
|
+
.dfree = ca_free,
|
48
|
+
.dsize = NULL,
|
49
|
+
.dcompact = NULL
|
50
|
+
},
|
51
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
52
|
+
};
|
53
|
+
|
54
|
+
const rb_data_type_t cavirtual_data_type = {
|
55
|
+
.parent = &carray_data_type,
|
56
|
+
.wrap_struct_name = "CAVirtual",
|
57
|
+
.function = {
|
58
|
+
.dmark = ca_mark,
|
59
|
+
.dfree = ca_free,
|
60
|
+
.dsize = NULL,
|
61
|
+
.dcompact = NULL
|
62
|
+
},
|
63
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
64
|
+
};
|
65
|
+
|
66
|
+
const rb_data_type_t carray_mask_data_type = {
|
67
|
+
.parent = &carray_data_type,
|
68
|
+
.wrap_struct_name = "CArrayMask",
|
69
|
+
.function = {
|
70
|
+
.dmark = NULL,
|
71
|
+
.dfree = ca_free_nop,
|
72
|
+
.dsize = NULL,
|
73
|
+
.dcompact = NULL
|
74
|
+
},
|
75
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
76
|
+
};
|
77
|
+
|
16
78
|
/* ------------------------------------------------------------------- */
|
17
79
|
|
18
80
|
VALUE rb_cCArray, rb_cCAWrap, rb_cCScalar, rb_cCAVirtual;
|
81
|
+
VALUE rb_cCArrayMask;
|
19
82
|
|
20
83
|
/* yard:
|
21
84
|
class CArray
|
@@ -703,7 +766,7 @@ rb_ca_s_allocate (VALUE klass)
|
|
703
766
|
{
|
704
767
|
CArray *ca;
|
705
768
|
ca_check_mem_count();
|
706
|
-
return
|
769
|
+
return TypedData_Make_Struct(klass, CArray, &carray_data_type, ca);
|
707
770
|
}
|
708
771
|
|
709
772
|
/* @overload initialize(data_type, dim, bytes=0) { ... }
|
@@ -740,7 +803,7 @@ rb_ca_initialize (int argc, VALUE *argv, VALUE self)
|
|
740
803
|
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
|
741
804
|
}
|
742
805
|
|
743
|
-
|
806
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
744
807
|
carray_safe_setup(ca, data_type, ndim, dim, bytes, NULL);
|
745
808
|
|
746
809
|
if ( rb_block_given_p() ) {
|
@@ -953,8 +1016,8 @@ rb_ca_initialize_copy (VALUE self, VALUE other)
|
|
953
1016
|
|
954
1017
|
rb_call_super(1, &other);
|
955
1018
|
|
956
|
-
|
957
|
-
|
1019
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
1020
|
+
TypedData_Get_Struct(other, CArray, &carray_data_type, cs);
|
958
1021
|
|
959
1022
|
ca_update_mask(cs);
|
960
1023
|
carray_setup(ca, cs->data_type, cs->ndim, cs->dim, cs->bytes, cs->mask);
|
@@ -993,7 +1056,7 @@ rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
|
|
993
1056
|
|
994
1057
|
target = rb_yield_values(0);
|
995
1058
|
|
996
|
-
obj =
|
1059
|
+
obj = TypedData_Make_Struct(rb_cCAWrap, CAWrap, &cawrap_data_type, ca);
|
997
1060
|
ca_wrap_setup_null(ca, data_type, ndim, dim, bytes, NULL);
|
998
1061
|
|
999
1062
|
rb_funcall(target, rb_intern("wrap_as_carray"), 1, obj);
|
@@ -1023,7 +1086,7 @@ static VALUE
|
|
1023
1086
|
rb_cs_s_allocate (VALUE klass)
|
1024
1087
|
{
|
1025
1088
|
CScalar *ca;
|
1026
|
-
return
|
1089
|
+
return TypedData_Make_Struct(klass, CScalar, &cscalar_data_type, ca);
|
1027
1090
|
}
|
1028
1091
|
|
1029
1092
|
/*
|
@@ -1054,7 +1117,7 @@ rb_cs_initialize (int argc, VALUE *argv, VALUE self)
|
|
1054
1117
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
1055
1118
|
rb_ca_data_type_import(self, rtype);
|
1056
1119
|
|
1057
|
-
|
1120
|
+
TypedData_Get_Struct(self, CScalar, &cscalar_data_type, ca);
|
1058
1121
|
cscalar_setup(ca, data_type, bytes, NULL);
|
1059
1122
|
|
1060
1123
|
if ( rb_block_given_p() ) {
|
@@ -1266,8 +1329,8 @@ rb_cs_initialize_copy (VALUE self, VALUE other)
|
|
1266
1329
|
{
|
1267
1330
|
CScalar *ca, *cs;
|
1268
1331
|
|
1269
|
-
|
1270
|
-
|
1332
|
+
TypedData_Get_Struct(self, CScalar, &cscalar_data_type, ca);
|
1333
|
+
TypedData_Get_Struct(other, CScalar, &cscalar_data_type, cs);
|
1271
1334
|
|
1272
1335
|
cscalar_setup(ca, cs->data_type, cs->bytes, NULL);
|
1273
1336
|
memcpy(ca->ptr, cs->ptr, ca->bytes);
|
@@ -1288,7 +1351,7 @@ static VALUE
|
|
1288
1351
|
rb_cs_coerce (VALUE self, VALUE other)
|
1289
1352
|
{
|
1290
1353
|
CScalar *ca;
|
1291
|
-
|
1354
|
+
TypedData_Get_Struct(self, CScalar, &cscalar_data_type, ca);
|
1292
1355
|
return rb_assoc_new(rb_cscalar_new_with_value(ca->data_type, ca->bytes, other),
|
1293
1356
|
self);
|
1294
1357
|
}
|
data/ext/ca_obj_bitarray.c
CHANGED
@@ -28,6 +28,18 @@ typedef struct {
|
|
28
28
|
ca_size_t bitlen;
|
29
29
|
} CABitarray;
|
30
30
|
|
31
|
+
const rb_data_type_t cabitarray_data_type = {
|
32
|
+
.parent = &cavirtual_data_type,
|
33
|
+
.wrap_struct_name = "CABitarray",
|
34
|
+
.function = {
|
35
|
+
.dmark = ca_mark,
|
36
|
+
.dfree = ca_free,
|
37
|
+
.dsize = NULL,
|
38
|
+
.dcompact = NULL
|
39
|
+
},
|
40
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
41
|
+
};
|
42
|
+
|
31
43
|
static int8_t CA_OBJ_BITARRAY;
|
32
44
|
|
33
45
|
static VALUE rb_cCABitarray;
|
@@ -455,7 +467,7 @@ rb_ca_bitarray_new (VALUE cary)
|
|
455
467
|
CArray *parent;
|
456
468
|
CABitarray *ca;
|
457
469
|
rb_check_carray_object(cary);
|
458
|
-
|
470
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
459
471
|
ca = ca_bitarray_new(parent);
|
460
472
|
obj = ca_wrap_struct(ca);
|
461
473
|
rb_ca_set_parent(obj, cary);
|
@@ -473,7 +485,7 @@ rb_ca_bitarray (VALUE self)
|
|
473
485
|
volatile VALUE obj;
|
474
486
|
CArray *ca;
|
475
487
|
|
476
|
-
|
488
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
477
489
|
|
478
490
|
obj = rb_ca_bitarray_new(self);
|
479
491
|
|
@@ -484,7 +496,7 @@ static VALUE
|
|
484
496
|
rb_ca_bitarray_s_allocate (VALUE klass)
|
485
497
|
{
|
486
498
|
CABitarray *ca;
|
487
|
-
return
|
499
|
+
return TypedData_Make_Struct(klass, CABitarray, &cabitarray_data_type, ca);
|
488
500
|
}
|
489
501
|
|
490
502
|
static VALUE
|
@@ -492,8 +504,8 @@ rb_ca_bitarray_initialize_copy (VALUE self, VALUE other)
|
|
492
504
|
{
|
493
505
|
CABitarray *ca, *cs;
|
494
506
|
|
495
|
-
|
496
|
-
|
507
|
+
TypedData_Get_Struct(self, CABitarray, &cabitarray_data_type, ca);
|
508
|
+
TypedData_Get_Struct(other, CABitarray, &cabitarray_data_type, cs);
|
497
509
|
|
498
510
|
ca_bitarray_setup(ca, cs->parent);
|
499
511
|
|
@@ -505,7 +517,10 @@ Init_ca_obj_bitarray ()
|
|
505
517
|
{
|
506
518
|
rb_cCABitarray = rb_define_class("CABitarray", rb_cCAVirtual);
|
507
519
|
|
508
|
-
CA_OBJ_BITARRAY = ca_install_obj_type(rb_cCABitarray,
|
520
|
+
CA_OBJ_BITARRAY = ca_install_obj_type(rb_cCABitarray,
|
521
|
+
&cabitarray_data_type,
|
522
|
+
rb_cCArrayMask,
|
523
|
+
&carray_data_type, ca_bitarray_func);
|
509
524
|
rb_define_const(rb_cObject, "CA_OBJ_BITARRAY", INT2NUM(CA_OBJ_BITARRAY));
|
510
525
|
|
511
526
|
rb_define_method(rb_cCArray, "bitarray", rb_ca_bitarray, 0);
|
data/ext/ca_obj_bitfield.c
CHANGED
@@ -29,6 +29,18 @@ typedef struct {
|
|
29
29
|
uint64_t bit_mask;
|
30
30
|
} CABitfield;
|
31
31
|
|
32
|
+
const rb_data_type_t cabitfield_data_type = {
|
33
|
+
.parent = &cavirtual_data_type,
|
34
|
+
.wrap_struct_name = "CABitfield",
|
35
|
+
.function = {
|
36
|
+
.dmark = ca_mark,
|
37
|
+
.dfree = ca_free,
|
38
|
+
.dsize = NULL,
|
39
|
+
.dcompact = NULL
|
40
|
+
},
|
41
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
42
|
+
};
|
43
|
+
|
32
44
|
static int8_t CA_OBJ_BITFIELD;
|
33
45
|
|
34
46
|
static VALUE rb_cCABitfield;
|
@@ -550,7 +562,7 @@ rb_ca_bitfield_new (VALUE cary, ca_size_t offset, ca_size_t bitlen)
|
|
550
562
|
CArray *parent;
|
551
563
|
CABitfield *ca;
|
552
564
|
rb_check_carray_object(cary);
|
553
|
-
|
565
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
554
566
|
ca = ca_bitfield_new(parent, offset, bitlen);
|
555
567
|
obj = ca_wrap_struct(ca);
|
556
568
|
rb_ca_set_parent(obj, cary);
|
@@ -568,12 +580,11 @@ rb_ca_bitfield (int argc, VALUE *argv, VALUE self)
|
|
568
580
|
volatile VALUE rrange, rtype;
|
569
581
|
CArray *ca;
|
570
582
|
ca_size_t offset, bitlen, step;
|
571
|
-
int data_type = CA_NONE;
|
572
583
|
ca_size_t bitsize;
|
573
584
|
|
574
585
|
rb_scan_args(argc, argv, "11", (VALUE *) &rrange, (VALUE *) &rtype);
|
575
586
|
|
576
|
-
|
587
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
577
588
|
|
578
589
|
if ( TYPE(rrange) == T_FIXNUM ) {
|
579
590
|
offset = NUM2INT(rrange);
|
@@ -587,10 +598,6 @@ rb_ca_bitfield (int argc, VALUE *argv, VALUE self)
|
|
587
598
|
}
|
588
599
|
}
|
589
600
|
|
590
|
-
if ( ! NIL_P(rtype) ) {
|
591
|
-
data_type = rb_ca_guess_type(rtype);
|
592
|
-
}
|
593
|
-
|
594
601
|
return rb_ca_bitfield_new(self, offset, bitlen);
|
595
602
|
}
|
596
603
|
|
@@ -598,7 +605,7 @@ static VALUE
|
|
598
605
|
rb_ca_bitfield_s_allocate (VALUE klass)
|
599
606
|
{
|
600
607
|
CABitfield *ca;
|
601
|
-
return
|
608
|
+
return TypedData_Make_Struct(klass, CABitfield, &cabitfield_data_type, ca);
|
602
609
|
}
|
603
610
|
|
604
611
|
static VALUE
|
@@ -606,8 +613,8 @@ rb_ca_bitfield_initialize_copy (VALUE self, VALUE other)
|
|
606
613
|
{
|
607
614
|
CABitfield *ca, *cs;
|
608
615
|
|
609
|
-
|
610
|
-
|
616
|
+
TypedData_Get_Struct(self, CABitfield, &cabitfield_data_type, ca);
|
617
|
+
TypedData_Get_Struct(other, CABitfield, &cabitfield_data_type, cs);
|
611
618
|
|
612
619
|
ca_bitfield_setup(ca, cs->parent,
|
613
620
|
8 * cs->byte_offset + cs->bit_offset,
|
@@ -621,7 +628,10 @@ Init_ca_obj_bitfield ()
|
|
621
628
|
{
|
622
629
|
rb_cCABitfield = rb_define_class("CABitfield", rb_cCAVirtual);
|
623
630
|
|
624
|
-
CA_OBJ_BITFIELD = ca_install_obj_type(rb_cCABitfield,
|
631
|
+
CA_OBJ_BITFIELD = ca_install_obj_type(rb_cCABitfield,
|
632
|
+
&cabitfield_data_type,
|
633
|
+
rb_cCArrayMask,
|
634
|
+
&carray_data_type, ca_bitfield_func);
|
625
635
|
rb_define_const(rb_cObject, "CA_OBJ_BITFIELD", INT2NUM(CA_OBJ_BITFIELD));
|
626
636
|
|
627
637
|
rb_define_method(rb_cCArray, "bitfield", rb_ca_bitfield, -1);
|
data/ext/ca_obj_block.c
CHANGED
@@ -10,7 +10,32 @@
|
|
10
10
|
|
11
11
|
#include "carray.h"
|
12
12
|
|
13
|
+
const rb_data_type_t cablock_data_type = {
|
14
|
+
.parent = &cavirtual_data_type,
|
15
|
+
.wrap_struct_name = "CABlock",
|
16
|
+
.function = {
|
17
|
+
.dmark = ca_mark,
|
18
|
+
.dfree = ca_free,
|
19
|
+
.dsize = NULL,
|
20
|
+
.dcompact = NULL
|
21
|
+
},
|
22
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
23
|
+
};
|
24
|
+
|
25
|
+
const rb_data_type_t cablock_mask_data_type = {
|
26
|
+
.parent = &cablock_data_type,
|
27
|
+
.wrap_struct_name = "CABlockMask",
|
28
|
+
.function = {
|
29
|
+
.dmark = NULL,
|
30
|
+
.dfree = ca_free_nop,
|
31
|
+
.dsize = NULL,
|
32
|
+
.dcompact = NULL
|
33
|
+
},
|
34
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
35
|
+
};
|
36
|
+
|
13
37
|
VALUE rb_cCABlock;
|
38
|
+
VALUE rb_cCABlockMask;
|
14
39
|
|
15
40
|
static int
|
16
41
|
ca_block_setup (CABlock *ca, CArray *parent, int8_t ndim, ca_size_t *dim,
|
@@ -321,8 +346,7 @@ rb_ca_block_new (VALUE cary, int8_t ndim, ca_size_t *dim,
|
|
321
346
|
CABlock *ca;
|
322
347
|
|
323
348
|
rb_check_carray_object(cary);
|
324
|
-
|
325
|
-
|
349
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
326
350
|
ca = ca_block_new(parent, ndim, dim, start, step, count, offset);
|
327
351
|
obj = ca_wrap_struct(ca);
|
328
352
|
rb_ca_set_parent(obj, cary);
|
@@ -687,7 +711,7 @@ static VALUE
|
|
687
711
|
rb_cb_s_allocate (VALUE klass)
|
688
712
|
{
|
689
713
|
CABlock *ca;
|
690
|
-
return
|
714
|
+
return TypedData_Make_Struct(klass, CABlock, &cablock_data_type, ca);
|
691
715
|
}
|
692
716
|
|
693
717
|
static VALUE
|
@@ -697,8 +721,8 @@ rb_cb_initialize_copy (VALUE self, VALUE other)
|
|
697
721
|
ca_size_t shrink[CA_RANK_MAX];
|
698
722
|
int8_t i;
|
699
723
|
|
700
|
-
|
701
|
-
|
724
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, ca);
|
725
|
+
TypedData_Get_Struct(other, CABlock, &cablock_data_type, cs);
|
702
726
|
|
703
727
|
for (i=0; i<cs->ndim; i++) {
|
704
728
|
shrink[i] = 0;
|
@@ -720,7 +744,7 @@ rb_cb_initialize_copy (VALUE self, VALUE other)
|
|
720
744
|
volatile VALUE ary; \
|
721
745
|
CABlock *cb; \
|
722
746
|
int8_t i; \
|
723
|
-
|
747
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, cb); \
|
724
748
|
ary = rb_ary_new2(cb->ndim); \
|
725
749
|
for (i=0; i<cb->ndim; i++) { \
|
726
750
|
rb_ary_store(ary, i, LONG2NUM(cb->name[i])); \
|
@@ -752,7 +776,7 @@ static VALUE
|
|
752
776
|
rb_cb_offset (VALUE self)
|
753
777
|
{
|
754
778
|
CABlock *cb;
|
755
|
-
|
779
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, cb);
|
756
780
|
return SIZE2NUM(cb->offset);
|
757
781
|
}
|
758
782
|
|
@@ -771,7 +795,7 @@ rb_cb_idx2addr0 (int argc, VALUE *argv, VALUE self)
|
|
771
795
|
int8_t i;
|
772
796
|
ca_size_t idxi;
|
773
797
|
|
774
|
-
|
798
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, cb);
|
775
799
|
|
776
800
|
if ( argc != cb->ndim ) {
|
777
801
|
rb_raise(rb_eArgError,
|
@@ -803,7 +827,7 @@ rb_cb_addr2addr0 (VALUE self, VALUE raddr)
|
|
803
827
|
ca_size_t idx[CA_RANK_MAX];
|
804
828
|
int8_t i;
|
805
829
|
|
806
|
-
|
830
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, cb);
|
807
831
|
|
808
832
|
ca_addr2index((CArray*)cb, addr, idx);
|
809
833
|
|
@@ -831,7 +855,7 @@ rb_cb_move (int argc, VALUE *argv, VALUE self)
|
|
831
855
|
ca_size_t start;
|
832
856
|
int8_t i;
|
833
857
|
|
834
|
-
|
858
|
+
TypedData_Get_Struct(self, CABlock, &cablock_data_type, cb);
|
835
859
|
|
836
860
|
if ( argc != cb->ndim ) {
|
837
861
|
rb_raise(rb_eArgError, "invalid # of arguments");
|