carray 1.5.2 → 1.5.3
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/.yardopts +32 -0
- data/NEWS.md +26 -3
- data/Rakefile +1 -1
- data/TODO.md +5 -4
- data/carray.gemspec +7 -5
- data/ext/ca_obj_bitarray.c +4 -7
- data/ext/ca_obj_bitfield.c +3 -5
- data/ext/ca_obj_block.c +1 -6
- data/ext/ca_obj_unbound_repeat.c +21 -52
- data/ext/carray_attribute.c +16 -1
- data/ext/carray_core.c +22 -16
- data/ext/carray_math.rb +20 -2
- data/ext/carray_numeric.c +32 -51
- data/ext/carray_test.c +9 -0
- data/ext/carray_undef.c +0 -8
- data/ext/version.h +4 -4
- data/lib/carray.rb +1 -3
- data/lib/carray/autoload.rb +0 -2
- data/lib/carray/basic.rb +1 -3
- data/lib/carray/broadcast.rb +58 -21
- data/lib/carray/compose.rb +34 -10
- data/lib/carray/construct.rb +1 -3
- data/lib/carray/info.rb +1 -3
- data/lib/carray/inspect.rb +3 -5
- data/lib/carray/io/imagemagick.rb +1 -3
- data/lib/carray/iterator.rb +2 -3
- data/lib/carray/mask.rb +18 -7
- data/lib/carray/math.rb +4 -6
- data/lib/carray/math/histogram.rb +1 -3
- data/lib/carray/math/recurrence.rb +1 -3
- data/lib/carray/mkmf.rb +1 -3
- data/lib/carray/object/ca_obj_iterator.rb +1 -3
- data/lib/carray/object/ca_obj_link.rb +1 -3
- data/lib/carray/object/ca_obj_pack.rb +1 -3
- data/lib/carray/obsolete.rb +1 -3
- data/lib/carray/ordering.rb +1 -3
- data/lib/carray/serialize.rb +22 -13
- data/lib/carray/string.rb +1 -3
- data/lib/carray/struct.rb +3 -5
- data/lib/carray/testing.rb +5 -10
- data/lib/carray/time.rb +1 -3
- data/lib/carray/transform.rb +1 -3
- data/spec/Classes/CAUnboudRepeat_spec.rb +24 -0
- data/spec/Features/feature_boolean_spec.rb +15 -14
- data/spec/Features/feature_broadcast.rb +16 -0
- data/spec/Features/feature_mask_spec.rb +6 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e4fbee624a609253882db54f549e00916542bf9f98e3b3c42ed4e5d59d66e5
|
4
|
+
data.tar.gz: 482567a72214af98ccd8153b382ac04ea479b0b429831a6a604fb4af5f8d81a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2de7c7b26e38aa9b66e050616c69fdb2587d71da4f37e9fa0d1b3022427656260fda644d5eee913c64d8104823f1a34c70a813e15baa04c7fa64b855be202506
|
7
|
+
data.tar.gz: de95a6f88c5408677170014c2e6d1661e9c020bb130d6a22c506483588cd3a1373a44aba427acd0883a1161cfa27ad001dd686747682bef790dde516e2358a33
|
data/.yardopts
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
--markup markdown
|
2
|
+
--markup-provider kramdown
|
3
|
+
--no-private
|
4
|
+
--exclude lib/carray/obsolete.rb
|
5
|
+
--exclude lib/carray/autoload.rb
|
6
|
+
--exclude 'lib/carray/autoload/'
|
7
|
+
--readme README.md
|
8
|
+
--files NEWS.md,TODO.md
|
9
|
+
lib/carray.rb
|
10
|
+
ext/ruby_carray.c
|
11
|
+
ext/ca_obj_array.c
|
12
|
+
ext/ca_obj_bitarray.c
|
13
|
+
ext/ca_obj_bitfield.c
|
14
|
+
ext/ca_obj_block.c
|
15
|
+
ext/carray_attribute.c
|
16
|
+
ext/carray_call_cfunc.c
|
17
|
+
ext/carray_cast.c
|
18
|
+
ext/carray_class.c
|
19
|
+
ext/carray_conversion.c
|
20
|
+
ext/carray_copy.c
|
21
|
+
ext/carray_core.c
|
22
|
+
ext/carray_data_type.c
|
23
|
+
ext/carray_element.c
|
24
|
+
ext/carray_generate.c
|
25
|
+
ext/carray_loop.c
|
26
|
+
ext/carray_mask.c
|
27
|
+
ext/carray_operator.c
|
28
|
+
ext/carray_order.c
|
29
|
+
ext/carray_sort_addr.c
|
30
|
+
ext/carray_test.c
|
31
|
+
ext/carray_utils.c
|
32
|
+
|
data/NEWS.md
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
ChangeLog of Ruby/CArray
|
2
2
|
========================
|
3
3
|
|
4
|
+
1.5.2 -> 1.5.3
|
5
|
+
--------------
|
6
|
+
|
7
|
+
* [New] Add new method 'CArray#exp2'
|
8
|
+
* [New] Add new method 'CArray#log2'
|
9
|
+
* [New] Add new method 'CArray#logb'
|
10
|
+
* [New] Add new method 'CArray#remainder'
|
11
|
+
* [New] Add new method 'CArray.guard_undef'
|
12
|
+
* [New] Add new method 'CArray#data_class='
|
13
|
+
* [New] Add new method 'CArray.data_class?'
|
14
|
+
* [Mod] Modify 'CArray#pmax' to use 'fmax' for float type
|
15
|
+
* [Mod] Modify 'CArray#pmin' to use 'fmin' for float type
|
16
|
+
* [Mod] Remove method 'Object#undef?'
|
17
|
+
* [Mod] Remove method '::nan', '::inf'
|
18
|
+
* [Mod] Remove method 'TrueClass#*', 'FalseClass#*' (unknown origin)
|
19
|
+
* [Fix] Fix invalid access for CAUnboundRepeat using index
|
20
|
+
* [Fix] Fix treatment of extra :* in operation between CAUnboundRepeat objects
|
21
|
+
* [Fix] Fix to accept Symbol for the name of data_class member
|
22
|
+
* [Fix] Fix 'CArray#uniq' to accept the array with the dimension more than 2.
|
23
|
+
* [Fix] Fix for CArray serialization to include data_class
|
24
|
+
* [Fix] Fix data_class inheritance in some methods in which new CArray is created.
|
25
|
+
* [Fix] Fix 'CArray#broadcast_to' to accept the case of dimension extension.
|
26
|
+
|
4
27
|
1.5.1 -> 1.5.2
|
5
28
|
--------------
|
6
29
|
|
@@ -13,8 +36,8 @@ ChangeLog of Ruby/CArray
|
|
13
36
|
* [New] Add new API function `rb_ca_wrap_new`
|
14
37
|
* [Mod] Modify 'CArray#linspace' to return float64 array for integer arguments
|
15
38
|
* [Mod] Modify CAUnboundRepeat to have `ndim` same as the bounded array (before `ndim` same as parent array)
|
16
|
-
* [Mod]
|
17
|
-
* [Mod]
|
39
|
+
* [Mod] Remove the obsolete mothod 'CArray#dump'.
|
40
|
+
* [Mod] Remove the obsolete mothod 'CArray#load'.
|
18
41
|
* [Mod] Modify CArray.wrap_readonly to wrap string as array.
|
19
42
|
* [Fix] Add support for Integer (same as for Fixnum, Bignum)
|
20
43
|
|
@@ -23,12 +46,12 @@ ChangeLog of Ruby/CArray
|
|
23
46
|
|
24
47
|
* [New] Add data type classes like 'Float64' ... to provide the methods like 'CArray::Float64.linspace'
|
25
48
|
* [Mod] Modify 'CArray.float64' ... without aruguments to return the corresponding data type class
|
49
|
+
* [Mod] Set obsolete flag to 'CAIterator#sort_with'
|
26
50
|
* [Fix] Move C extension files into 'ext/'
|
27
51
|
* [Fix] Rename member 'rank' to 'ndim' in struct CArray in C extension
|
28
52
|
* [Fix] Remove 'CArray#shuffle' (gone to 'carray-random' gem)
|
29
53
|
* [Fix] Remove dependencies on 'rb_secure()' and 'rb_safe_level()'
|
30
54
|
* [Fix] Modify 'CArray#span' to handle fractional step for integer array
|
31
|
-
* [Obsolete] Set obsolete flag to 'CAIterator#sort_with'
|
32
55
|
|
33
56
|
1.4.0 -> 1.5.0
|
34
57
|
--------------
|
data/Rakefile
CHANGED
data/TODO.md
CHANGED
@@ -3,13 +3,14 @@ ToDo List
|
|
3
3
|
|
4
4
|
ToDo
|
5
5
|
-------
|
6
|
-
|
6
|
+
* Implement CArray.broadcast in C
|
7
|
+
* Implement Integer#{|,&,^,<<,>>} with Refinement (remove monkey patch)
|
8
|
+
* Remove RSTRUCT hack in carray_access.c for handling of Range object.
|
9
|
+
* Solve abs probrems
|
7
10
|
* Create spec
|
8
11
|
- str_format (cyclic format)
|
9
12
|
- CA_SIZE
|
10
|
-
|
11
|
-
* Implement CArray.broadcast in C
|
12
|
-
* Solve abs probrems
|
13
|
+
- serialization of carray which has data_class
|
13
14
|
|
14
15
|
Done
|
15
16
|
-------
|
data/carray.gemspec
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
Gem::Specification::new do |s|
|
2
2
|
|
3
|
-
version = "1.5.
|
3
|
+
version = "1.5.3"
|
4
4
|
|
5
|
-
files = Dir.glob("**/*")
|
5
|
+
files = Dir.glob("**/*") + [".yardopts"] -
|
6
|
+
[
|
6
7
|
Dir.glob("carray-*.gem"),
|
7
8
|
Dir.glob("ext/**/{Makefile,mkmf.log}"),
|
8
9
|
Dir.glob("**/*.{o,so,bundle}"),
|
9
10
|
Dir.glob("**/*~"),
|
10
11
|
Dir.glob("doc/**/*"),
|
12
|
+
Dir.glob("test/**/*"),
|
11
13
|
].flatten
|
12
14
|
|
13
15
|
s.platform = Gem::Platform::RUBY
|
14
16
|
s.name = "carray"
|
15
17
|
s.summary = "Multi-dimesional array class for Ruby"
|
16
18
|
s.description = <<-HERE
|
17
|
-
Ruby/CArray is an extension library for the multi-dimensional array class.
|
19
|
+
Ruby/CArray is an extension library for the multi-dimensional numerical array class.
|
18
20
|
CArray can store integers and floating point numbers to perform calculations
|
19
21
|
efficiently. Therefore, Ruby/CArray is suitable for numerical computation and data
|
20
22
|
analysis. Ruby/CArray has different features from other multidimensional array
|
21
|
-
libraries (narray, numo-narray, nmatrix), such as element-
|
23
|
+
libraries (narray, numo-narray, nmatrix), such as element-wise masks,
|
22
24
|
creation of reference arrays that can reflect changes to the referent,
|
23
25
|
the ability to access memory pointers of other objects, user-defined arrays,
|
24
26
|
and so on.
|
@@ -26,7 +28,7 @@ Gem::Specification::new do |s|
|
|
26
28
|
s.version = version
|
27
29
|
s.author = "Hiroki Motoyoshi"
|
28
30
|
s.email = ""
|
29
|
-
s.
|
31
|
+
s.license = 'MIT'
|
30
32
|
s.homepage = 'https://github.com/himotoyoshi/carray'
|
31
33
|
s.files = files
|
32
34
|
s.extensions = [ "ext/extconf.rb" ]
|
data/ext/ca_obj_bitarray.c
CHANGED
@@ -462,12 +462,9 @@ rb_ca_bitarray_new (VALUE cary)
|
|
462
462
|
return obj;
|
463
463
|
}
|
464
464
|
|
465
|
-
/*
|
466
|
-
|
467
|
-
|
468
|
-
end
|
469
|
-
alias bitarray bits
|
470
|
-
end
|
465
|
+
/* @overload bitarray
|
466
|
+
|
467
|
+
[TBD]
|
471
468
|
*/
|
472
469
|
|
473
470
|
VALUE
|
@@ -511,8 +508,8 @@ Init_ca_obj_bitarray ()
|
|
511
508
|
CA_OBJ_BITARRAY = ca_install_obj_type(rb_cCABitarray, ca_bitarray_func);
|
512
509
|
rb_define_const(rb_cObject, "CA_OBJ_BITARRAY", INT2NUM(CA_OBJ_BITARRAY));
|
513
510
|
|
514
|
-
rb_define_method(rb_cCArray, "bits", rb_ca_bitarray, 0);
|
515
511
|
rb_define_method(rb_cCArray, "bitarray", rb_ca_bitarray, 0);
|
512
|
+
rb_define_alias(rb_cCArray, "bits", "bitarray");
|
516
513
|
|
517
514
|
rb_define_alloc_func(rb_cCABitarray, rb_ca_bitarray_s_allocate);
|
518
515
|
rb_define_method(rb_cCABitarray, "initialize_copy",
|
data/ext/ca_obj_bitfield.c
CHANGED
@@ -557,11 +557,9 @@ rb_ca_bitfield_new (VALUE cary, ca_size_t offset, ca_size_t bitlen)
|
|
557
557
|
return obj;
|
558
558
|
}
|
559
559
|
|
560
|
-
/*
|
561
|
-
|
562
|
-
|
563
|
-
end
|
564
|
-
end
|
560
|
+
/* @overload bitfield (range, type)
|
561
|
+
|
562
|
+
[TBD]
|
565
563
|
*/
|
566
564
|
|
567
565
|
VALUE
|
data/ext/ca_obj_block.c
CHANGED
@@ -12,11 +12,6 @@
|
|
12
12
|
|
13
13
|
VALUE rb_cCABlock;
|
14
14
|
|
15
|
-
/* yard:
|
16
|
-
class CABlock < CAVirtual # :nodoc:
|
17
|
-
end
|
18
|
-
*/
|
19
|
-
|
20
15
|
static int
|
21
16
|
ca_block_setup (CABlock *ca, CArray *parent, int8_t ndim, ca_size_t *dim,
|
22
17
|
ca_size_t *start, ca_size_t *step, ca_size_t *count, ca_size_t offset)
|
@@ -733,7 +728,7 @@ rb_cb_initialize_copy (VALUE self, VALUE other)
|
|
733
728
|
return ary; \
|
734
729
|
}
|
735
730
|
|
736
|
-
/*
|
731
|
+
/* @overload size0:
|
737
732
|
class CABlock
|
738
733
|
def size0
|
739
734
|
end
|
data/ext/ca_obj_unbound_repeat.c
CHANGED
@@ -50,15 +50,9 @@ ca_ubrep_setup (CAUnboundRepeat *ca, CArray *parent,
|
|
50
50
|
ca->rep_ndim = rep_ndim;
|
51
51
|
ca->rep_dim = ALLOC_N(ca_size_t, rep_ndim);
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if ( ca->rep_dim[i] ) {
|
57
|
-
ca->dim[i] = ca->rep_dim[i];
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
ca->dim[i] = 1;
|
61
|
-
}
|
53
|
+
for (i=0; i<rep_ndim; i++) {
|
54
|
+
ca->rep_dim[i] = rep_dim[i];
|
55
|
+
ca->dim[i] = ( rep_dim[i] ) ? rep_dim[i] : 1;
|
62
56
|
}
|
63
57
|
|
64
58
|
if ( ca_has_mask(parent) ) {
|
@@ -104,13 +98,6 @@ ca_ubrep_func_ptr_at_addr (void *ap, ca_size_t addr)
|
|
104
98
|
return ca_ptr_at_addr(ca->parent, addr);
|
105
99
|
}
|
106
100
|
|
107
|
-
static char *
|
108
|
-
ca_ubrep_func_ptr_at_index (void *ap, ca_size_t *idx)
|
109
|
-
{
|
110
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
111
|
-
return ca_ptr_at_index(ca->parent, idx);
|
112
|
-
}
|
113
|
-
|
114
101
|
static void
|
115
102
|
ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
116
103
|
{
|
@@ -118,13 +105,6 @@ ca_ubrep_func_fetch_addr (void *ap, ca_size_t addr, void *ptr)
|
|
118
105
|
ca_fetch_addr(ca->parent, addr, ptr);
|
119
106
|
}
|
120
107
|
|
121
|
-
static void
|
122
|
-
ca_ubrep_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
123
|
-
{
|
124
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
125
|
-
ca_fetch_index(ca->parent, idx, ptr);
|
126
|
-
}
|
127
|
-
|
128
108
|
static void
|
129
109
|
ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
130
110
|
{
|
@@ -132,13 +112,6 @@ ca_ubrep_func_store_addr (void *ap, ca_size_t addr, void *ptr)
|
|
132
112
|
ca_store_addr(ca->parent, addr, ptr);
|
133
113
|
}
|
134
114
|
|
135
|
-
static void
|
136
|
-
ca_ubrep_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
137
|
-
{
|
138
|
-
CAUnboundRepeat *ca = (CAUnboundRepeat *) ap;
|
139
|
-
ca_store_index(ca->parent, idx, ptr);
|
140
|
-
}
|
141
|
-
|
142
115
|
static void
|
143
116
|
ca_ubrep_func_allocate (void *ap)
|
144
117
|
{
|
@@ -227,11 +200,11 @@ ca_operation_function_t ca_ubrep_func = {
|
|
227
200
|
free_ca_ubrep,
|
228
201
|
ca_ubrep_func_clone,
|
229
202
|
ca_ubrep_func_ptr_at_addr,
|
230
|
-
|
203
|
+
NULL,
|
231
204
|
ca_ubrep_func_fetch_addr,
|
232
|
-
|
205
|
+
NULL,
|
233
206
|
ca_ubrep_func_store_addr,
|
234
|
-
|
207
|
+
NULL,
|
235
208
|
ca_ubrep_func_allocate,
|
236
209
|
ca_ubrep_func_attach,
|
237
210
|
ca_ubrep_func_sync,
|
@@ -304,11 +277,10 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
304
277
|
rep_ndim = argc;
|
305
278
|
|
306
279
|
count = 0;
|
307
|
-
ndim
|
308
|
-
|
280
|
+
ndim = 0;
|
309
281
|
elements = 1;
|
310
282
|
for (i=0; i<rep_ndim; i++) {
|
311
|
-
if (
|
283
|
+
if ( TYPE(argv[i]) == T_SYMBOL ) {
|
312
284
|
if ( argv[i] == ID2SYM(rb_intern("*")) ) {
|
313
285
|
rep_dim[i] = 0;
|
314
286
|
}
|
@@ -321,8 +293,8 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
321
293
|
rb_raise(rb_eArgError, "invalid argument");
|
322
294
|
}
|
323
295
|
rep_dim[i] = ca->dim[count];
|
324
|
-
dim[ndim]
|
325
|
-
elements
|
296
|
+
dim[ndim] = ca->dim[count];
|
297
|
+
elements *= ca->dim[count];
|
326
298
|
count++; ndim++;
|
327
299
|
}
|
328
300
|
}
|
@@ -334,9 +306,8 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
334
306
|
if ( ndim != ca->ndim ) {
|
335
307
|
rb_raise(rb_eArgError, "invalid number of nil's (%i for %i)", ndim, ca->ndim);
|
336
308
|
}
|
337
|
-
|
338
|
-
|
339
|
-
}
|
309
|
+
|
310
|
+
return rb_ca_ubrep_new(self, rep_ndim, rep_dim);
|
340
311
|
}
|
341
312
|
|
342
313
|
static VALUE
|
@@ -388,6 +359,7 @@ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
|
388
359
|
ca_size_t upr_spec[CA_RANK_MAX];
|
389
360
|
ca_size_t srp_spec[CA_RANK_MAX];
|
390
361
|
int uprep = 0, srp_ndim;
|
362
|
+
int ndim_real;
|
391
363
|
int i;
|
392
364
|
|
393
365
|
Data_Get_Struct(self, CAUnboundRepeat, ca);
|
@@ -398,6 +370,7 @@ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
|
398
370
|
}
|
399
371
|
|
400
372
|
srp_ndim = 0;
|
373
|
+
ndim_real = 0;
|
401
374
|
for (i=0; i<new_ndim; i++) {
|
402
375
|
if ( ca->rep_dim[i] == 0 ) {
|
403
376
|
if ( new_dim[i] == 0 ) {
|
@@ -410,14 +383,16 @@ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
|
410
383
|
upr_spec[i] = new_dim[i];
|
411
384
|
}
|
412
385
|
else {
|
386
|
+
ndim_real++;
|
413
387
|
rep_spec[i] = 0;
|
414
388
|
srp_spec[srp_ndim++] = 0;
|
415
389
|
upr_spec[i] = ca->rep_dim[i];
|
416
390
|
}
|
417
391
|
}
|
392
|
+
|
418
393
|
if ( uprep ) {
|
419
394
|
volatile VALUE rep;
|
420
|
-
if ( srp_ndim >=
|
395
|
+
if ( srp_ndim >= ndim_real ) {
|
421
396
|
rep = rb_ca_repeat_new(rb_ca_parent(self), srp_ndim, srp_spec);
|
422
397
|
}
|
423
398
|
else {
|
@@ -430,11 +405,8 @@ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
|
430
405
|
}
|
431
406
|
}
|
432
407
|
|
433
|
-
/*
|
434
|
-
|
435
|
-
def bind_with(other)
|
436
|
-
end
|
437
|
-
end
|
408
|
+
/* @overload bind_with (other)
|
409
|
+
|
438
410
|
*/
|
439
411
|
|
440
412
|
VALUE
|
@@ -460,11 +432,8 @@ ca_ubrep_bind_with (VALUE self, VALUE other)
|
|
460
432
|
}
|
461
433
|
}
|
462
434
|
|
463
|
-
/*
|
464
|
-
|
465
|
-
def bind(*index)
|
466
|
-
end
|
467
|
-
end
|
435
|
+
/* @overload bind (*index)
|
436
|
+
|
468
437
|
*/
|
469
438
|
|
470
439
|
static VALUE
|
data/ext/carray_attribute.c
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
(Attribute)
|
18
18
|
Returns the object type (e.g. CA_OBJ_ARRAY, CA_OBJ_BLOCK, ...).
|
19
19
|
Since the object type can be known from the class of the object,
|
20
|
-
this attribute
|
20
|
+
this attribute methods is rarely used.
|
21
21
|
*/
|
22
22
|
|
23
23
|
VALUE
|
@@ -711,6 +711,20 @@ rb_ca_data_type_import (VALUE self, VALUE data_type)
|
|
711
711
|
return Qnil;
|
712
712
|
}
|
713
713
|
|
714
|
+
static VALUE
|
715
|
+
rb_ca_set_data_class (VALUE self, VALUE klass)
|
716
|
+
{
|
717
|
+
if ( RTEST(rb_ca_is_fixlen_type(self)) &&
|
718
|
+
rb_obj_is_data_class(klass) ) {
|
719
|
+
rb_ivar_set(self, rb_intern("member"), rb_hash_new());
|
720
|
+
return rb_ivar_set(self, id_data_class, klass);
|
721
|
+
}
|
722
|
+
else {
|
723
|
+
rb_raise(rb_eTypeError, "invalid data_class or self is not fixlen array.");
|
724
|
+
}
|
725
|
+
return Qnil;
|
726
|
+
}
|
727
|
+
|
714
728
|
/* ------------------------------------------------------------------- */
|
715
729
|
|
716
730
|
CArray *
|
@@ -824,6 +838,7 @@ Init_carray_attribute ()
|
|
824
838
|
rb_define_method(rb_cCArray, "parent", rb_ca_parent, 0);
|
825
839
|
|
826
840
|
rb_define_method(rb_cCArray, "data_class", rb_ca_data_class, 0);
|
841
|
+
rb_define_method(rb_cCArray, "data_class=", rb_ca_set_data_class, 1);
|
827
842
|
|
828
843
|
rb_define_method(rb_cCArray, "scalar?", rb_ca_is_scalar, 0);
|
829
844
|
|
data/ext/carray_core.c
CHANGED
@@ -1186,7 +1186,7 @@ rb_ca_data_class_encode (VALUE self, VALUE obj)
|
|
1186
1186
|
VALUE
|
1187
1187
|
rb_ca_members (VALUE self)
|
1188
1188
|
{
|
1189
|
-
VALUE data_class = rb_ca_data_class(self);
|
1189
|
+
volatile VALUE data_class = rb_ca_data_class(self);
|
1190
1190
|
if ( NIL_P(data_class) ) {
|
1191
1191
|
rb_raise(rb_eRuntimeError, "carray doesn't have data class");
|
1192
1192
|
}
|
@@ -1198,9 +1198,9 @@ rb_ca_members (VALUE self)
|
|
1198
1198
|
VALUE
|
1199
1199
|
rb_ca_field_as_member (VALUE self, VALUE sym)
|
1200
1200
|
{
|
1201
|
-
VALUE data_class = rb_ca_data_class(self);
|
1202
|
-
VALUE member;
|
1203
|
-
VALUE obj;
|
1201
|
+
volatile VALUE data_class = rb_ca_data_class(self);
|
1202
|
+
volatile VALUE member;
|
1203
|
+
volatile VALUE obj;
|
1204
1204
|
|
1205
1205
|
if ( NIL_P(data_class) ) {
|
1206
1206
|
rb_raise(rb_eRuntimeError, "carray doesn't have data class");
|
@@ -1214,23 +1214,29 @@ rb_ca_field_as_member (VALUE self, VALUE sym)
|
|
1214
1214
|
"for data_class array");
|
1215
1215
|
}
|
1216
1216
|
|
1217
|
-
if (
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1217
|
+
if ( rb_obj_is_kind_of(sym, rb_cInteger) ) {
|
1218
|
+
volatile VALUE member_names = rb_const_get(data_class, rb_intern("MEMBERS"));
|
1219
|
+
sym = rb_ary_entry(member_names, NUM2SIZE(sym));
|
1220
|
+
obj = rb_hash_aref(member, sym);
|
1221
|
+
}
|
1222
|
+
else {
|
1223
|
+
obj = rb_hash_aref(member, sym);
|
1224
|
+
if ( NIL_P(obj) ) {
|
1225
|
+
sym = rb_funcall(sym, rb_intern("to_s"), 0);
|
1226
|
+
obj = rb_hash_aref(member, sym);
|
1227
|
+
}
|
1223
1228
|
}
|
1224
1229
|
|
1225
|
-
obj = rb_hash_aref(member, sym);
|
1226
|
-
|
1227
1230
|
if ( rb_obj_is_carray(obj) ) {
|
1228
1231
|
return obj;
|
1229
1232
|
}
|
1230
1233
|
else {
|
1231
|
-
VALUE MEMBER_TABLE = rb_const_get(data_class, rb_intern("MEMBER_TABLE"));
|
1232
|
-
VALUE info = rb_hash_aref(MEMBER_TABLE, sym);
|
1234
|
+
volatile VALUE MEMBER_TABLE = rb_const_get(data_class, rb_intern("MEMBER_TABLE"));
|
1235
|
+
volatile VALUE info = rb_hash_aref(MEMBER_TABLE, sym);
|
1233
1236
|
if ( NIL_P(info) ) {
|
1237
|
+
if ( TYPE(sym) != T_STRING ) {
|
1238
|
+
sym = rb_funcall(sym, rb_intern("to_s"), 0);
|
1239
|
+
}
|
1234
1240
|
rb_raise(rb_eRuntimeError,
|
1235
1241
|
"can't find data_member named <%s>", StringValuePtr(sym));
|
1236
1242
|
}
|
@@ -1249,7 +1255,7 @@ rb_ca_field_as_member (VALUE self, VALUE sym)
|
|
1249
1255
|
VALUE
|
1250
1256
|
rb_ca_fields (VALUE self)
|
1251
1257
|
{
|
1252
|
-
VALUE data_class = rb_ca_data_class(self);
|
1258
|
+
volatile VALUE data_class = rb_ca_data_class(self);
|
1253
1259
|
volatile VALUE member_names, list;
|
1254
1260
|
int i;
|
1255
1261
|
if ( NIL_P(data_class) ) {
|
@@ -1272,7 +1278,7 @@ Returns an array of data class members (fields) with names specified
|
|
1272
1278
|
VALUE
|
1273
1279
|
rb_ca_fields_at (int argc, VALUE *argv, VALUE self)
|
1274
1280
|
{
|
1275
|
-
VALUE data_class = rb_ca_data_class(self);
|
1281
|
+
volatile VALUE data_class = rb_ca_data_class(self);
|
1276
1282
|
volatile VALUE member_names, list;
|
1277
1283
|
int i;
|
1278
1284
|
if ( NIL_P(data_class) ) {
|