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
data/ext/ca_obj_repeat.c
CHANGED
@@ -10,7 +10,32 @@
|
|
10
10
|
|
11
11
|
#include "carray.h"
|
12
12
|
|
13
|
+
const rb_data_type_t carepeat_data_type = {
|
14
|
+
.parent = &cavirtual_data_type,
|
15
|
+
.wrap_struct_name = "CARepeat",
|
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 carepeat_mask_data_type = {
|
26
|
+
.parent = &carepeat_data_type,
|
27
|
+
.wrap_struct_name = "CARepeatMask",
|
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_cCARepeat;
|
38
|
+
VALUE rb_cCARepeatMask;
|
14
39
|
|
15
40
|
/* yard:
|
16
41
|
class CARepeat < CAVirtual # :nodoc:
|
@@ -193,10 +218,9 @@ ca_repeat_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
|
|
193
218
|
CARepeat *ca = (CARepeat *) ap;
|
194
219
|
ca_size_t *count = ca->count;
|
195
220
|
ca_size_t idx0[CA_RANK_MAX];
|
196
|
-
int8_t
|
197
|
-
ca_size_t
|
221
|
+
int8_t i;
|
222
|
+
ca_size_t j;
|
198
223
|
j = 0;
|
199
|
-
n = 0;
|
200
224
|
for (i=0; i<ca->ndim; i++) {
|
201
225
|
if ( ! count[i] ) {
|
202
226
|
idx0[j++] = idx[i];
|
@@ -212,9 +236,8 @@ ca_repeat_func_store_index (void *ap, ca_size_t *idx, void *ptr)
|
|
212
236
|
ca_size_t *count = ca->count;
|
213
237
|
ca_size_t idx0[CA_RANK_MAX];
|
214
238
|
int8_t i;
|
215
|
-
ca_size_t
|
239
|
+
ca_size_t j;
|
216
240
|
j = 0;
|
217
|
-
n = 0;
|
218
241
|
for (i=0; i<ca->ndim; i++) {
|
219
242
|
if ( ! count[i] ) {
|
220
243
|
idx0[j++] = idx[i];
|
@@ -479,7 +502,7 @@ rb_ca_repeat_new (VALUE cary, int8_t ndim, ca_size_t *count)
|
|
479
502
|
CArray *parent;
|
480
503
|
CARepeat *ca;
|
481
504
|
rb_check_carray_object(cary);
|
482
|
-
|
505
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
483
506
|
ca = ca_repeat_new(parent, ndim, count);
|
484
507
|
obj = ca_wrap_struct(ca);
|
485
508
|
rb_ca_set_parent(obj, cary);
|
@@ -496,7 +519,7 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
496
519
|
ca_size_t repeat;
|
497
520
|
ca_size_t i;
|
498
521
|
|
499
|
-
|
522
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
500
523
|
|
501
524
|
if ( argc == 2 &&
|
502
525
|
(
|
@@ -508,10 +531,10 @@ rb_ca_repeat (int argc, VALUE *argv, VALUE self)
|
|
508
531
|
ca_size_t ndim, dim[CA_RANK_MAX];
|
509
532
|
int k;
|
510
533
|
if ( argv[0] == ID2SYM(rb_intern("%") ) ) {
|
511
|
-
|
534
|
+
TypedData_Get_Struct(argv[1], CArray, &carray_data_type, ct);
|
512
535
|
}
|
513
536
|
else {
|
514
|
-
|
537
|
+
TypedData_Get_Struct(argv[0], CArray, &carray_data_type, ct);
|
515
538
|
}
|
516
539
|
if ( ct->ndim < ca->ndim ) {
|
517
540
|
rb_raise(rb_eRuntimeError, "invalid ndim to template");
|
@@ -612,7 +635,7 @@ static VALUE
|
|
612
635
|
rb_ca_repeat_s_allocate (VALUE klass)
|
613
636
|
{
|
614
637
|
CARepeat *ca;
|
615
|
-
return
|
638
|
+
return TypedData_Make_Struct(klass, CARepeat, &carepeat_data_type, ca);
|
616
639
|
}
|
617
640
|
|
618
641
|
static VALUE
|
@@ -620,8 +643,8 @@ rb_ca_repeat_initialize_copy (VALUE self, VALUE other)
|
|
620
643
|
{
|
621
644
|
CARepeat *ca, *cs;
|
622
645
|
|
623
|
-
|
624
|
-
|
646
|
+
TypedData_Get_Struct(self, CARepeat, &carepeat_data_type, ca);
|
647
|
+
TypedData_Get_Struct(other, CARepeat, &carepeat_data_type, cs);
|
625
648
|
|
626
649
|
ca_repeat_setup(ca, cs->parent, cs->ndim, cs->count);
|
627
650
|
|
data/ext/ca_obj_select.c
CHANGED
@@ -10,8 +10,6 @@
|
|
10
10
|
|
11
11
|
#include "carray.h"
|
12
12
|
|
13
|
-
VALUE rb_cCASelect;
|
14
|
-
|
15
13
|
/* yard:
|
16
14
|
class CASelect < CAVirtual # :nodoc:
|
17
15
|
end
|
@@ -35,6 +33,34 @@ typedef struct {
|
|
35
33
|
ca_size_t _dim;
|
36
34
|
} CASelect;
|
37
35
|
|
36
|
+
const rb_data_type_t caselect_data_type = {
|
37
|
+
.parent = &cavirtual_data_type,
|
38
|
+
.wrap_struct_name = "CASelect",
|
39
|
+
.function = {
|
40
|
+
.dmark = ca_mark,
|
41
|
+
.dfree = ca_free,
|
42
|
+
.dsize = NULL,
|
43
|
+
.dcompact = NULL
|
44
|
+
},
|
45
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
46
|
+
};
|
47
|
+
|
48
|
+
const rb_data_type_t caselect_mask_data_type = {
|
49
|
+
.parent = &caselect_data_type,
|
50
|
+
.wrap_struct_name = "CASelectMask",
|
51
|
+
.function = {
|
52
|
+
.dmark = NULL,
|
53
|
+
.dfree = ca_free_nop,
|
54
|
+
.dsize = NULL,
|
55
|
+
.dcompact = NULL
|
56
|
+
},
|
57
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
58
|
+
};
|
59
|
+
|
60
|
+
VALUE rb_cCASelect;
|
61
|
+
VALUE rb_cCASelectMask;
|
62
|
+
|
63
|
+
|
38
64
|
/* ------------------------------------------------------------------- */
|
39
65
|
|
40
66
|
static int
|
@@ -365,8 +391,8 @@ rb_ca_select_new (VALUE cary, VALUE select)
|
|
365
391
|
CASelect *ca;
|
366
392
|
rb_check_carray_object(cary);
|
367
393
|
rb_check_carray_object(select);
|
368
|
-
|
369
|
-
|
394
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
395
|
+
TypedData_Get_Struct(select, CArray, &carray_data_type, cselect);
|
370
396
|
ca = (CASelect *) ca_select_new(parent, cselect);
|
371
397
|
if ( ! ca ) {
|
372
398
|
return Qnil;
|
@@ -385,8 +411,8 @@ rb_ca_select_new_share (VALUE cary, VALUE select)
|
|
385
411
|
CASelect *ca;
|
386
412
|
rb_check_carray_object(cary);
|
387
413
|
rb_check_carray_object(select);
|
388
|
-
|
389
|
-
|
414
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
415
|
+
TypedData_Get_Struct(select, CArray, &carray_data_type, cselect);
|
390
416
|
ca = (CASelect *) ca_select_new_share(parent, cselect);
|
391
417
|
if ( ! ca ) {
|
392
418
|
return Qnil;
|
@@ -527,7 +553,7 @@ static VALUE
|
|
527
553
|
rb_cm_s_allocate (VALUE klass)
|
528
554
|
{
|
529
555
|
CASelect *ca;
|
530
|
-
return
|
556
|
+
return TypedData_Make_Struct(klass, CASelect, &caselect_data_type, ca);
|
531
557
|
}
|
532
558
|
|
533
559
|
static VALUE
|
@@ -535,8 +561,8 @@ rb_cm_initialize_copy (VALUE self, VALUE other)
|
|
535
561
|
{
|
536
562
|
CASelect *ca, *cs;
|
537
563
|
|
538
|
-
|
539
|
-
|
564
|
+
TypedData_Get_Struct(self, CASelect, &caselect_data_type, ca);
|
565
|
+
TypedData_Get_Struct(other, CASelect, &caselect_data_type, cs);
|
540
566
|
|
541
567
|
/* share select info */
|
542
568
|
ca_select_setup(ca, cs->parent, cs->select, 1);
|
data/ext/ca_obj_shift.c
CHANGED
@@ -15,8 +15,6 @@
|
|
15
15
|
end
|
16
16
|
*/
|
17
17
|
|
18
|
-
static VALUE rb_cCAShift;
|
19
|
-
|
20
18
|
typedef struct {
|
21
19
|
int16_t obj_type;
|
22
20
|
int8_t data_type;
|
@@ -37,8 +35,35 @@ typedef struct {
|
|
37
35
|
int fill_mask;
|
38
36
|
} CAShift;
|
39
37
|
|
38
|
+
const rb_data_type_t cashift_data_type = {
|
39
|
+
.parent = &cavirtual_data_type,
|
40
|
+
.wrap_struct_name = "CAShift",
|
41
|
+
.function = {
|
42
|
+
.dmark = ca_mark,
|
43
|
+
.dfree = ca_free,
|
44
|
+
.dsize = NULL,
|
45
|
+
.dcompact = NULL
|
46
|
+
},
|
47
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
48
|
+
};
|
49
|
+
|
50
|
+
const rb_data_type_t cashift_mask_data_type = {
|
51
|
+
.parent = &cashift_data_type,
|
52
|
+
.wrap_struct_name = "CAShift",
|
53
|
+
.function = {
|
54
|
+
.dmark = ca_mark,
|
55
|
+
.dfree = ca_free,
|
56
|
+
.dsize = NULL,
|
57
|
+
.dcompact = NULL
|
58
|
+
},
|
59
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
60
|
+
};
|
61
|
+
|
40
62
|
static int8_t CA_OBJ_SHIFT;
|
41
63
|
|
64
|
+
VALUE rb_cCAShift;
|
65
|
+
VALUE rb_cCAShiftMask;
|
66
|
+
|
42
67
|
/* ------------------------------------------------------------------- */
|
43
68
|
|
44
69
|
int
|
@@ -797,7 +822,7 @@ rb_ca_shift_set_fill_value (VALUE self, VALUE rfval)
|
|
797
822
|
CAShift *ca;
|
798
823
|
CArray *cs;
|
799
824
|
|
800
|
-
|
825
|
+
TypedData_Get_Struct(self, CAShift, &cashift_data_type, ca);
|
801
826
|
|
802
827
|
if ( NIL_P(rfval) ) {
|
803
828
|
memset(ca->fill, 0, ca->bytes);
|
@@ -818,7 +843,7 @@ rb_ca_shift_new (VALUE cary, ca_size_t *shift, char *fill, int8_t *roll)
|
|
818
843
|
CArray *parent;
|
819
844
|
CAShift *ca;
|
820
845
|
rb_check_carray_object(cary);
|
821
|
-
|
846
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
822
847
|
ca = ca_shift_new(parent, shift, fill, roll);
|
823
848
|
obj = ca_wrap_struct(ca);
|
824
849
|
rb_ca_set_parent(obj, cary);
|
@@ -844,7 +869,7 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
844
869
|
char *fill = NULL;
|
845
870
|
int8_t i;
|
846
871
|
|
847
|
-
|
872
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
848
873
|
|
849
874
|
ropt = rb_pop_options(&argc, &argv);
|
850
875
|
rb_scan_options(ropt, "roll,fill_value", &rroll, &rfval);
|
@@ -868,7 +893,7 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
868
893
|
|
869
894
|
if ( rfval == CA_NIL ) {
|
870
895
|
rcs = rb_cscalar_new(ca->data_type, ca->bytes, NULL);
|
871
|
-
|
896
|
+
TypedData_Get_Struct(rcs, CScalar, &cscalar_data_type, cs);
|
872
897
|
fill = cs->ptr;
|
873
898
|
if ( ca_is_object_type(ca) ) {
|
874
899
|
*(VALUE *)fill = INT2NUM(0);
|
@@ -882,7 +907,7 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
882
907
|
}
|
883
908
|
else {
|
884
909
|
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
|
885
|
-
|
910
|
+
TypedData_Get_Struct(rcs, CScalar, &cscalar_data_type, cs);
|
886
911
|
fill = cs->ptr;
|
887
912
|
}
|
888
913
|
|
@@ -907,7 +932,7 @@ rb_ca_shift (int argc, VALUE *argv, VALUE self)
|
|
907
932
|
|
908
933
|
if ( rfval == CA_UNDEF ) {
|
909
934
|
CArray *co;
|
910
|
-
|
935
|
+
TypedData_Get_Struct(obj, CArray, &carray_data_type, co);
|
911
936
|
ca_create_mask(co);
|
912
937
|
}
|
913
938
|
|
@@ -920,7 +945,7 @@ static VALUE
|
|
920
945
|
rb_ca_shift_s_allocate (VALUE klass)
|
921
946
|
{
|
922
947
|
CAShift *ca;
|
923
|
-
return
|
948
|
+
return TypedData_Make_Struct(klass, CAShift, &cashift_data_type, ca);
|
924
949
|
}
|
925
950
|
|
926
951
|
static VALUE
|
@@ -928,8 +953,8 @@ rb_ca_shift_initialize_copy (VALUE self, VALUE other)
|
|
928
953
|
{
|
929
954
|
CAShift *ca, *cs;
|
930
955
|
|
931
|
-
|
932
|
-
|
956
|
+
TypedData_Get_Struct(self, CAShift, &cashift_data_type, ca);
|
957
|
+
TypedData_Get_Struct(other, CAShift, &cashift_data_type, cs);
|
933
958
|
|
934
959
|
ca_shift_setup(ca, cs->parent, cs->shift, cs->fill, cs->roll);
|
935
960
|
|
@@ -940,8 +965,12 @@ void
|
|
940
965
|
Init_ca_obj_shift ()
|
941
966
|
{
|
942
967
|
rb_cCAShift = rb_define_class("CAShift", rb_cCAVirtual);
|
968
|
+
rb_cCAShiftMask = rb_define_class("CAShiftMask", rb_cCAShift);
|
943
969
|
|
944
|
-
CA_OBJ_SHIFT = ca_install_obj_type(rb_cCAShift,
|
970
|
+
CA_OBJ_SHIFT = ca_install_obj_type(rb_cCAShift,
|
971
|
+
&cashift_data_type,
|
972
|
+
rb_cCAShiftMask,
|
973
|
+
&cashift_mask_data_type, ca_shift_func);
|
945
974
|
rb_define_const(rb_cObject, "CA_OBJ_SHIFT", INT2NUM(CA_OBJ_SHIFT));
|
946
975
|
|
947
976
|
rb_define_method(rb_cCArray, "shifted", rb_ca_shift, -1);
|
data/ext/ca_obj_transpose.c
CHANGED
@@ -30,7 +30,32 @@ typedef struct {
|
|
30
30
|
|
31
31
|
static int8_t CA_OBJ_TRANSPOSE;
|
32
32
|
|
33
|
-
|
33
|
+
const rb_data_type_t catrans_data_type = {
|
34
|
+
.parent = &cavirtual_data_type,
|
35
|
+
.wrap_struct_name = "CATrans",
|
36
|
+
.function = {
|
37
|
+
.dmark = ca_mark,
|
38
|
+
.dfree = ca_free,
|
39
|
+
.dsize = NULL,
|
40
|
+
.dcompact = NULL
|
41
|
+
},
|
42
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
43
|
+
};
|
44
|
+
|
45
|
+
const rb_data_type_t catrans_mask_data_type = {
|
46
|
+
.parent = &catrans_data_type,
|
47
|
+
.wrap_struct_name = "CATransMask",
|
48
|
+
.function = {
|
49
|
+
.dmark = NULL,
|
50
|
+
.dfree = ca_free_nop,
|
51
|
+
.dsize = NULL,
|
52
|
+
.dcompact = NULL
|
53
|
+
},
|
54
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
55
|
+
};
|
56
|
+
|
57
|
+
VALUE rb_cCATrans;
|
58
|
+
VALUE rb_cCATransMask;
|
34
59
|
|
35
60
|
/* yard:
|
36
61
|
class CATranspose < CAVirtual # :nodoc:
|
@@ -501,7 +526,7 @@ rb_ca_trans_new (VALUE cary, ca_size_t *imap)
|
|
501
526
|
CArray *parent;
|
502
527
|
CATrans *ca;
|
503
528
|
rb_check_carray_object(cary);
|
504
|
-
|
529
|
+
TypedData_Get_Struct(cary, CArray,&carray_data_type, parent);
|
505
530
|
ca = ca_trans_new(parent, imap);
|
506
531
|
obj = ca_wrap_struct(ca);
|
507
532
|
rb_ca_set_parent(obj, cary);
|
@@ -524,7 +549,7 @@ rb_ca_trans (int argc, VALUE *argv, VALUE self)
|
|
524
549
|
ca_size_t imap[CA_RANK_MAX];
|
525
550
|
int8_t i;
|
526
551
|
|
527
|
-
|
552
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
528
553
|
|
529
554
|
if ( argc == 0 ) {
|
530
555
|
for (i=0; i<ca->ndim; i++) {
|
@@ -549,7 +574,7 @@ static VALUE
|
|
549
574
|
rb_ca_trans_s_allocate (VALUE klass)
|
550
575
|
{
|
551
576
|
CATrans *ca;
|
552
|
-
return
|
577
|
+
return TypedData_Make_Struct(klass, CATrans, &catrans_data_type, ca);
|
553
578
|
}
|
554
579
|
|
555
580
|
static VALUE
|
@@ -557,8 +582,8 @@ rb_ca_trans_initialize_copy (VALUE self, VALUE other)
|
|
557
582
|
{
|
558
583
|
CATrans *ca, *cs;
|
559
584
|
|
560
|
-
|
561
|
-
|
585
|
+
TypedData_Get_Struct(self, CATrans, &catrans_data_type, ca);
|
586
|
+
TypedData_Get_Struct(other, CATrans, &catrans_data_type, cs);
|
562
587
|
|
563
588
|
ca_trans_setup(ca, cs->parent, cs->imap);
|
564
589
|
|
@@ -569,8 +594,12 @@ void
|
|
569
594
|
Init_ca_obj_transpose ()
|
570
595
|
{
|
571
596
|
rb_cCATrans = rb_define_class("CATranspose", rb_cCAVirtual);
|
597
|
+
rb_cCATransMask = rb_define_class("CATransposeMask", rb_cCATrans);
|
572
598
|
|
573
|
-
CA_OBJ_TRANSPOSE = ca_install_obj_type(rb_cCATrans,
|
599
|
+
CA_OBJ_TRANSPOSE = ca_install_obj_type(rb_cCATrans,
|
600
|
+
&catrans_data_type,
|
601
|
+
rb_cCATransMask,
|
602
|
+
&catrans_mask_data_type, ca_trans_func);
|
574
603
|
rb_define_const(rb_cObject, "CA_OBJ_TRANSPOSE", INT2NUM(CA_OBJ_TRANSPOSE));
|
575
604
|
|
576
605
|
rb_define_method(rb_cCArray, "transposed", rb_ca_trans, -1);
|
data/ext/ca_obj_unbound_repeat.c
CHANGED
@@ -10,7 +10,32 @@
|
|
10
10
|
|
11
11
|
#include "carray.h"
|
12
12
|
|
13
|
+
const rb_data_type_t caunboundrepeat_data_type = {
|
14
|
+
.parent = &cavirtual_data_type,
|
15
|
+
.wrap_struct_name = "CAUnboundRepeat",
|
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 caunboundrepeat_mask_data_type = {
|
26
|
+
.parent = &cavirtual_data_type,
|
27
|
+
.wrap_struct_name = "CAUnboundRepeatMask",
|
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_cCAUnboundRepeat;
|
38
|
+
VALUE rb_cCAUnboundRepeatMask;
|
14
39
|
|
15
40
|
/* yard:
|
16
41
|
class CAUnboundRepeat < CArray
|
@@ -228,8 +253,8 @@ rb_ca_ubrep_shave (VALUE self, VALUE other)
|
|
228
253
|
rb_check_carray_object(self);
|
229
254
|
rb_check_carray_object(other);
|
230
255
|
|
231
|
-
|
232
|
-
|
256
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
257
|
+
TypedData_Get_Struct(other, CArray, &carray_data_type, co);
|
233
258
|
|
234
259
|
if ( ca->elements != co->elements ) {
|
235
260
|
rb_raise(rb_eRuntimeError, "mismatch in # of elements");
|
@@ -254,7 +279,7 @@ rb_ca_ubrep_new (VALUE cary, int32_t rep_ndim, ca_size_t *rep_dim)
|
|
254
279
|
CArray *parent;
|
255
280
|
CAUnboundRepeat *ca;
|
256
281
|
rb_check_carray_object(cary);
|
257
|
-
|
282
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
258
283
|
ca = ca_ubrep_new(parent, rep_ndim, rep_dim);
|
259
284
|
obj = ca_wrap_struct(ca);
|
260
285
|
rb_ca_set_parent(obj, cary);
|
@@ -272,7 +297,7 @@ rb_ca_unbound_repeat (int argc, VALUE *argv, VALUE self)
|
|
272
297
|
ca_size_t rep_dim[CA_RANK_MAX];
|
273
298
|
ca_size_t elements, count, i;
|
274
299
|
|
275
|
-
|
300
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
276
301
|
|
277
302
|
rep_ndim = argc;
|
278
303
|
|
@@ -314,7 +339,7 @@ static VALUE
|
|
314
339
|
rb_ca_ubrep_s_allocate (VALUE klass)
|
315
340
|
{
|
316
341
|
CAUnboundRepeat *ca;
|
317
|
-
return
|
342
|
+
return TypedData_Make_Struct(klass, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
318
343
|
}
|
319
344
|
|
320
345
|
static VALUE
|
@@ -322,8 +347,8 @@ rb_ca_ubrep_initialize_copy (VALUE self, VALUE other)
|
|
322
347
|
{
|
323
348
|
CAUnboundRepeat *ca, *cs;
|
324
349
|
|
325
|
-
|
326
|
-
|
350
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
351
|
+
TypedData_Get_Struct(other, CAUnboundRepeat, &caunboundrepeat_data_type, cs);
|
327
352
|
|
328
353
|
ca_ubrep_setup(ca, cs->parent, cs->rep_ndim, cs->rep_dim);
|
329
354
|
|
@@ -362,7 +387,7 @@ ca_ubrep_bind2 (VALUE self, int32_t new_ndim, ca_size_t *new_dim)
|
|
362
387
|
int ndim_real;
|
363
388
|
int i;
|
364
389
|
|
365
|
-
|
390
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
366
391
|
|
367
392
|
if ( ca->rep_ndim != new_ndim ) {
|
368
393
|
rb_raise(rb_eArgError, "invalid new_ndim (%i <-> %i)",
|
@@ -417,11 +442,11 @@ ca_ubrep_bind_with (VALUE self, VALUE other)
|
|
417
442
|
|
418
443
|
rb_check_carray_object(other);
|
419
444
|
|
420
|
-
|
421
|
-
|
445
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
446
|
+
TypedData_Get_Struct(other, CArray, &carray_data_type, co);
|
422
447
|
|
423
448
|
if ( co->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
424
|
-
|
449
|
+
TypedData_Get_Struct(other, CAUnboundRepeat, &caunboundrepeat_data_type, cup);
|
425
450
|
return ca_ubrep_bind2(self, cup->rep_ndim, cup->rep_dim);
|
426
451
|
}
|
427
452
|
else if ( ca_is_scalar(co) ) {
|
@@ -443,7 +468,7 @@ rb_ca_ubrep_bind (int argc, VALUE *argv, VALUE self)
|
|
443
468
|
ca_size_t rep_spec[CA_RANK_MAX];
|
444
469
|
int i;
|
445
470
|
|
446
|
-
|
471
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
447
472
|
|
448
473
|
if ( ca->rep_ndim != argc ) {
|
449
474
|
rb_raise(rb_eArgError, "invalid new_ndim");
|
@@ -468,7 +493,7 @@ rb_ca_ubrep_spec (VALUE self)
|
|
468
493
|
CAUnboundRepeat *ca;
|
469
494
|
int i;
|
470
495
|
|
471
|
-
|
496
|
+
TypedData_Get_Struct(self, CAUnboundRepeat, &caunboundrepeat_data_type, ca);
|
472
497
|
|
473
498
|
spec = rb_ary_new2(ca->rep_ndim);
|
474
499
|
for (i=0; i<ca->rep_ndim; i++) {
|
@@ -486,7 +511,7 @@ rb_ca_ubrep_spec (VALUE self)
|
|
486
511
|
void
|
487
512
|
Init_ca_obj_unbound_repeat ()
|
488
513
|
{
|
489
|
-
/*
|
514
|
+
/* rb_cCAUnboundRepeat, CA_OBJ_UNBOUND_REPEAT are defined in rb_carray.c */
|
490
515
|
|
491
516
|
rb_define_const(rb_cObject, "CA_OBJ_UNBOUND_REPEAT", INT2NUM(CA_OBJ_UNBOUND_REPEAT));
|
492
517
|
|
data/ext/ca_obj_window.c
CHANGED
@@ -12,9 +12,36 @@
|
|
12
12
|
|
13
13
|
/* should not be static variable as used by CAIteratorWindow */
|
14
14
|
|
15
|
-
|
15
|
+
const rb_data_type_t cawindow_data_type = {
|
16
|
+
.parent = &cavirtual_data_type,
|
17
|
+
.wrap_struct_name = "CAWindow",
|
18
|
+
.function = {
|
19
|
+
.dmark = ca_mark,
|
20
|
+
.dfree = ca_free,
|
21
|
+
.dsize = NULL,
|
22
|
+
.dcompact = NULL
|
23
|
+
},
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
25
|
+
};
|
26
|
+
|
27
|
+
const rb_data_type_t cawindow_mask_data_type = {
|
28
|
+
.parent = &cawindow_data_type,
|
29
|
+
.wrap_struct_name = "CAWindowMask",
|
30
|
+
.function = {
|
31
|
+
.dmark = ca_mark,
|
32
|
+
.dfree = ca_free,
|
33
|
+
.dsize = NULL,
|
34
|
+
.dcompact = NULL
|
35
|
+
},
|
36
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
37
|
+
};
|
38
|
+
|
16
39
|
int8_t CA_OBJ_WINDOW;
|
17
40
|
|
41
|
+
VALUE rb_cCAWindow;
|
42
|
+
VALUE rb_cCAWindowMask;
|
43
|
+
|
44
|
+
|
18
45
|
/* yard:
|
19
46
|
class CAWindow < CAVirtual # :nodoc:
|
20
47
|
end
|
@@ -693,7 +720,7 @@ rb_ca_window_new (VALUE cary,
|
|
693
720
|
CArray *parent;
|
694
721
|
CAWindow *ca;
|
695
722
|
rb_check_carray_object(cary);
|
696
|
-
|
723
|
+
TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
|
697
724
|
ca = ca_window_new(parent, start, count, bounds, fill);
|
698
725
|
obj = ca_wrap_struct(ca);
|
699
726
|
rb_ca_set_parent(obj, cary);
|
@@ -721,7 +748,7 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
|
|
721
748
|
char *cbounds;
|
722
749
|
ca_size_t i;
|
723
750
|
|
724
|
-
|
751
|
+
TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
|
725
752
|
|
726
753
|
ropt = rb_pop_options(&argc, &argv);
|
727
754
|
rb_scan_options(ropt, "bounds,fill_value", &rbounds, &rfval);
|
@@ -760,7 +787,7 @@ rb_ca_window (int argc, VALUE *argv, VALUE self)
|
|
760
787
|
}
|
761
788
|
else {
|
762
789
|
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
|
763
|
-
|
790
|
+
TypedData_Get_Struct(rcs, CScalar, &cscalar_data_type, cs);
|
764
791
|
fill = cs->ptr;
|
765
792
|
}
|
766
793
|
|
@@ -819,7 +846,7 @@ static VALUE
|
|
819
846
|
rb_ca_window_s_allocate (VALUE klass)
|
820
847
|
{
|
821
848
|
CAWindow *ca;
|
822
|
-
return
|
849
|
+
return TypedData_Make_Struct(klass, CAWindow, &cawindow_data_type, ca);
|
823
850
|
}
|
824
851
|
|
825
852
|
static VALUE
|
@@ -827,8 +854,8 @@ rb_ca_window_initialize_copy (VALUE self, VALUE other)
|
|
827
854
|
{
|
828
855
|
CAWindow *ca, *cs;
|
829
856
|
|
830
|
-
|
831
|
-
|
857
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, ca);
|
858
|
+
TypedData_Get_Struct(other, CAWindow, &cawindow_data_type, cs);
|
832
859
|
|
833
860
|
ca_window_setup(ca, cs->parent, cs->start, cs->count, cs->bounds, cs->fill);
|
834
861
|
|
@@ -850,7 +877,7 @@ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
|
|
850
877
|
int8_t i;
|
851
878
|
ca_size_t idxi;
|
852
879
|
|
853
|
-
|
880
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
854
881
|
|
855
882
|
if ( argc != cw->ndim ) {
|
856
883
|
rb_raise(rb_eArgError,
|
@@ -887,7 +914,7 @@ rb_ca_window_addr2addr0 (VALUE self, VALUE raddr)
|
|
887
914
|
ca_size_t idx[CA_RANK_MAX];
|
888
915
|
int8_t i;
|
889
916
|
|
890
|
-
|
917
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
891
918
|
|
892
919
|
ca_addr2index((CArray*)cw, addr, idx);
|
893
920
|
|
@@ -908,7 +935,7 @@ rb_ca_window_move (int argc, VALUE *argv, VALUE self)
|
|
908
935
|
ca_size_t start;
|
909
936
|
int8_t i;
|
910
937
|
|
911
|
-
|
938
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
912
939
|
|
913
940
|
if ( argc != cw->ndim ) {
|
914
941
|
rb_raise(rb_eArgError, "invalid # of arguments");
|
@@ -939,7 +966,7 @@ static VALUE
|
|
939
966
|
rb_ca_window_set_fill_value (VALUE self, VALUE rfval)
|
940
967
|
{
|
941
968
|
CAWindow *cw;
|
942
|
-
|
969
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
943
970
|
rb_ca_obj2ptr(self, rfval, cw->fill);
|
944
971
|
return Qnil;
|
945
972
|
}
|
@@ -948,7 +975,7 @@ static VALUE
|
|
948
975
|
rb_ca_window_get_fill_value (VALUE self)
|
949
976
|
{
|
950
977
|
CAWindow *cw;
|
951
|
-
|
978
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
952
979
|
return rb_ca_ptr2obj(self, cw->fill);
|
953
980
|
}
|
954
981
|
|
@@ -956,7 +983,7 @@ static VALUE
|
|
956
983
|
rb_ca_window_get_bounds (VALUE self)
|
957
984
|
{
|
958
985
|
CAWindow *cw;
|
959
|
-
|
986
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw);
|
960
987
|
return SIZE2NUM(cw->bounds);
|
961
988
|
}
|
962
989
|
|
@@ -966,7 +993,7 @@ rb_ca_window_get_bounds (VALUE self)
|
|
966
993
|
volatile VALUE ary; \
|
967
994
|
CAWindow *cw; \
|
968
995
|
int8_t i; \
|
969
|
-
|
996
|
+
TypedData_Get_Struct(self, CAWindow, &cawindow_data_type, cw); \
|
970
997
|
ary = rb_ary_new2(cw->ndim); \
|
971
998
|
for (i=0; i<cw->ndim; i++) { \
|
972
999
|
rb_ary_store(ary, i, SIZE2NUM(cw->name[i])); \
|
@@ -998,8 +1025,12 @@ Init_ca_obj_window ()
|
|
998
1025
|
{
|
999
1026
|
|
1000
1027
|
rb_cCAWindow = rb_define_class("CAWindow", rb_cCAVirtual);
|
1028
|
+
rb_cCAWindowMask = rb_define_class("CAWindowMask", rb_cCAWindow);
|
1001
1029
|
|
1002
|
-
CA_OBJ_WINDOW = ca_install_obj_type(rb_cCAWindow,
|
1030
|
+
CA_OBJ_WINDOW = ca_install_obj_type(rb_cCAWindow,
|
1031
|
+
&cawindow_data_type,
|
1032
|
+
rb_cCAWindowMask,
|
1033
|
+
&cawindow_mask_data_type, ca_window_func);
|
1003
1034
|
rb_define_const(rb_cObject, "CA_OBJ_WINDOW", INT2NUM(CA_OBJ_WINDOW));
|
1004
1035
|
|
1005
1036
|
rb_define_method(rb_cCArray, "window", rb_ca_window, -1);
|