carray 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +56 -0
- data/GPL +340 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LEGAL +50 -0
- data/NOTE +73 -0
- data/Rakefile +20 -0
- data/TODO +5 -0
- data/ca_iter_block.c +242 -0
- data/ca_iter_dimension.c +287 -0
- data/ca_iter_window.c +202 -0
- data/ca_obj_array.c +1189 -0
- data/ca_obj_bitarray.c +523 -0
- data/ca_obj_bitfield.c +636 -0
- data/ca_obj_block.c +885 -0
- data/ca_obj_fake.c +405 -0
- data/ca_obj_farray.c +482 -0
- data/ca_obj_field.c +625 -0
- data/ca_obj_grid.c +738 -0
- data/ca_obj_mapping.c +614 -0
- data/ca_obj_object.c +777 -0
- data/ca_obj_reduce.c +299 -0
- data/ca_obj_refer.c +627 -0
- data/ca_obj_repeat.c +640 -0
- data/ca_obj_select.c +558 -0
- data/ca_obj_shift.c +952 -0
- data/ca_obj_transpose.c +582 -0
- data/ca_obj_unbound_repeat.c +557 -0
- data/ca_obj_window.c +1023 -0
- data/carray.h +1381 -0
- data/carray_access.c +1798 -0
- data/carray_attribute.c +903 -0
- data/carray_call_cfunc.c +1107 -0
- data/carray_cast.c +1155 -0
- data/carray_cast_func.rb +498 -0
- data/carray_class.c +132 -0
- data/carray_conversion.c +518 -0
- data/carray_copy.c +453 -0
- data/carray_core.c +1307 -0
- data/carray_element.c +572 -0
- data/carray_generate.c +681 -0
- data/carray_iterator.c +630 -0
- data/carray_loop.c +462 -0
- data/carray_mask.c +1174 -0
- data/carray_math.rb +834 -0
- data/carray_numeric.c +257 -0
- data/carray_operator.c +582 -0
- data/carray_order.c +1040 -0
- data/carray_random.c +529 -0
- data/carray_sort_addr.c +261 -0
- data/carray_stat.c +2102 -0
- data/carray_stat_proc.rb +1990 -0
- data/carray_test.c +602 -0
- data/carray_undef.c +69 -0
- data/carray_utils.c +740 -0
- data/ext/calculus/carray_calculus.c +792 -0
- data/ext/calculus/carray_interp.c +355 -0
- data/ext/calculus/extconf.rb +12 -0
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
- data/ext/calculus/lib/math/calculus.rb +119 -0
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
- data/ext/dataframe/API.txt +11 -0
- data/ext/dataframe/extconf.rb +3 -0
- data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
- data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
- data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
- data/ext/fortio/extconf.rb +3 -0
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
- data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
- data/ext/fortio/lib/fortio.rb +3 -0
- data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
- data/ext/fortio/lib/fortio/fortran_format.y +215 -0
- data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
- data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
- data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
- data/ext/fortio/ruby_fortio.c +182 -0
- data/ext/fortio/test/test_H.rb +5 -0
- data/ext/fortio/test/test_T.rb +7 -0
- data/ext/fortio/test/test_fortran_format.rb +86 -0
- data/ext/fortio/test/test_namelist.rb +25 -0
- data/ext/fortio/test/test_sequential.rb +13 -0
- data/ext/fortio/test/test_sequential2.rb +13 -0
- data/ext/fortio/work/test.rb +10 -0
- data/ext/fortio/work/test_e.rb +19 -0
- data/ext/fortio/work/test_ep.rb +10 -0
- data/ext/fortio/work/test_parse.rb +12 -0
- data/ext/imagemap/carray_imagemap.c +495 -0
- data/ext/imagemap/doc/call_graph.dot +28 -0
- data/ext/imagemap/draw.c +567 -0
- data/ext/imagemap/extconf.rb +13 -0
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
- data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
- data/ext/imagemap/lib/image_map.rb +4 -0
- data/ext/imagemap/test/swath_index.rb +83 -0
- data/ext/imagemap/test/swath_warp.rb +99 -0
- data/ext/imagemap/test/test.rb +23 -0
- data/ext/imagemap/test/test_image.rb +42 -0
- data/ext/imagemap/test/test_line.rb +14 -0
- data/ext/imagemap/test/test_rotate.rb +17 -0
- data/ext/imagemap/test/test_triangle.rb +20 -0
- data/ext/imagemap/test/test_warp.rb +26 -0
- data/ext/mathfunc/carray_mathfunc.c +321 -0
- data/ext/mathfunc/extconf.rb +18 -0
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
- data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
- data/ext/mathfunc/test/test_hypot.rb +5 -0
- data/ext/mathfunc/test/test_j0.rb +22 -0
- data/ext/mathfunc/test/test_jn.rb +8 -0
- data/ext/mathfunc/test/test_sph.rb +9 -0
- data/ext/narray/README +22 -0
- data/ext/narray/ca_wrap_narray.c +491 -0
- data/ext/narray/carray_narray.c +21 -0
- data/ext/narray/extconf.rb +57 -0
- data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
- data/ext/narray/lib/math/narray.rb +17 -0
- data/ext/narray/lib/math/narray_miss.rb +45 -0
- data/extconf.rb +3 -25
- data/lib/carray.rb +28 -0
- data/lib/carray/autoload/autoload_base.rb +23 -0
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_io_excel.rb +5 -0
- data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
- data/lib/carray/autoload/autoload_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_io_table.rb +1 -0
- data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
- data/lib/carray/autoload/autoload_math_interp.rb +4 -0
- data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
- data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
- data/lib/carray/autoload/autoload_object_link.rb +1 -0
- data/lib/carray/autoload/autoload_object_pack.rb +2 -0
- data/lib/carray/base/autoload.rb +94 -0
- data/lib/carray/base/basic.rb +1051 -0
- data/lib/carray/base/inspect.rb +252 -0
- data/lib/carray/base/iterator.rb +367 -0
- data/lib/carray/base/math.rb +403 -0
- data/lib/carray/base/obsolete.rb +93 -0
- data/lib/carray/base/serialize.rb +260 -0
- data/lib/carray/base/struct.rb +634 -0
- data/lib/carray/graphics/gnuplot.rb +2116 -0
- data/lib/carray/info.rb +112 -0
- data/lib/carray/io/csv.rb +560 -0
- data/lib/carray/io/excel.rb +26 -0
- data/lib/carray/io/imagemagick.rb +231 -0
- data/lib/carray/io/pg.rb +101 -0
- data/lib/carray/io/sqlite3.rb +202 -0
- data/lib/carray/io/table.rb +77 -0
- data/lib/carray/math/histogram.rb +179 -0
- data/lib/carray/math/interp.rb +57 -0
- data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
- data/lib/carray/math/recurrence.rb +95 -0
- data/lib/carray/mkmf.rb +145 -0
- data/lib/carray/object/ca_obj_iterator.rb +52 -0
- data/lib/carray/object/ca_obj_link.rb +52 -0
- data/lib/carray/object/ca_obj_pack.rb +101 -0
- data/mkmath.rb +731 -0
- data/mt19937ar.c +182 -0
- data/mt19937ar.h +86 -0
- data/rdoc_main.rb +27 -0
- data/rdoc_math.rb +5 -0
- data/rdoc_stat.rb +31 -0
- data/ruby_carray.c +242 -0
- data/ruby_ccomplex.c +497 -0
- data/ruby_float_func.c +83 -0
- data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
- data/spec/CArray/bug/store_spec.rb +27 -0
- data/spec/CArray/index/repeat_spec.rb +10 -0
- data/spec/CArray/method/eq_spec.rb +80 -0
- data/spec/CArray/method/is_nan_spec.rb +12 -0
- data/spec/CArray/method/ne_spec.rb +18 -0
- data/spec/CArray/method/round_spec.rb +11 -0
- data/spec/CArray/object/_attribute_spec.rb +32 -0
- data/spec/CArray/object/s_new_spec.rb +31 -0
- data/spec/CArray/serialize/Serialization_spec.rb +89 -0
- data/spec/spec_all.rb +11 -0
- data/test/test_ALL.rb +50 -0
- data/test/test_CABitfield.rb +59 -0
- data/test/test_CABlock.rb +208 -0
- data/test/test_CAField.rb +40 -0
- data/test/test_CAGrid.rb +76 -0
- data/test/test_CAMapping.rb +106 -0
- data/test/test_CAMmap.rb +11 -0
- data/test/test_CARefer.rb +94 -0
- data/test/test_CARepeat.rb +66 -0
- data/test/test_CASelect.rb +23 -0
- data/test/test_CAShift.rb +17 -0
- data/test/test_CATranspose.rb +61 -0
- data/test/test_CAVirtual.rb +214 -0
- data/test/test_CAWindow.rb +55 -0
- data/test/test_CAWrap.rb +9 -0
- data/test/test_CArray.rb +228 -0
- data/test/test_CComplex.rb +83 -0
- data/test/test_CScalar.rb +91 -0
- data/test/test_attribute.rb +281 -0
- data/test/test_block_iterator.rb +17 -0
- data/test/test_boolean.rb +99 -0
- data/test/test_cast.rb +33 -0
- data/test/test_class.rb +85 -0
- data/test/test_complex.rb +43 -0
- data/test/test_composite.rb +125 -0
- data/test/test_convert.rb +79 -0
- data/test/test_copy.rb +141 -0
- data/test/test_creation.rb +85 -0
- data/test/test_element.rb +146 -0
- data/test/test_extream.rb +55 -0
- data/test/test_generate.rb +75 -0
- data/test/test_index.rb +71 -0
- data/test/test_mask.rb +578 -0
- data/test/test_math.rb +98 -0
- data/test/test_narray.rb +64 -0
- data/test/test_order.rb +147 -0
- data/test/test_random.rb +15 -0
- data/test/test_ref_store.rb +211 -0
- data/test/test_stat.rb +414 -0
- data/test/test_struct.rb +72 -0
- data/test/test_virtual.rb +49 -0
- data/utils/ca_ase.rb +21 -0
- data/utils/ca_methods.rb +15 -0
- data/utils/cast_checker.rb +30 -0
- data/utils/create_rdoc.sh +9 -0
- data/utils/diff_method.rb +52 -0
- data/utils/extract_rdoc.rb +27 -0
- data/utils/make_tgz.sh +3 -0
- data/utils/remove_resource_fork.sh +5 -0
- data/version.h +3 -3
- metadata +266 -1
data/carray_mask.c
ADDED
@@ -0,0 +1,1174 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
carray_mask.c
|
4
|
+
|
5
|
+
This file is part of Ruby/CArray extension library.
|
6
|
+
You can redistribute it and/or modify it under the terms of
|
7
|
+
the Ruby Licence.
|
8
|
+
|
9
|
+
Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
|
11
|
+
---------------------------------------------------------------------------- */
|
12
|
+
|
13
|
+
#include <stdarg.h>
|
14
|
+
#include "ruby.h"
|
15
|
+
#include "carray.h"
|
16
|
+
|
17
|
+
boolean8_t *
|
18
|
+
ca_mask_ptr (void *ap)
|
19
|
+
{
|
20
|
+
CArray *ca = (CArray*) ap;
|
21
|
+
ca_update_mask(ca);
|
22
|
+
return ( ca->mask ) ? (boolean8_t *) ca->mask->ptr : NULL;
|
23
|
+
}
|
24
|
+
|
25
|
+
int
|
26
|
+
ca_has_mask (void *ap)
|
27
|
+
{
|
28
|
+
CArray *ca = (CArray *) ap;
|
29
|
+
|
30
|
+
if ( ca->mask ) { /* mask array already created */
|
31
|
+
return 1;
|
32
|
+
}
|
33
|
+
else if ( ca_is_value_array(ca) ) {
|
34
|
+
return 0; /* array itself is returned by CArray#value */
|
35
|
+
}
|
36
|
+
else if ( ca_is_entity(ca) ) { /* entity array */
|
37
|
+
return ( ca->mask != NULL ) ? 1 : 0;
|
38
|
+
}
|
39
|
+
else if ( ca_is_caobject(ca) ) { /* CAObject */
|
40
|
+
CAObject *co = (CAObject *) ca;
|
41
|
+
if ( rb_obj_respond_to(co->self, rb_intern("mask_created?"), Qtrue) ) {
|
42
|
+
return rb_funcall(co->self, rb_intern("mask_created?"), 0);
|
43
|
+
}
|
44
|
+
return ( ca->mask != NULL ) ? 1 : 0;
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
CAVirtual *cr = (CAVirtual *) ca; /* virtual array, check parent array */
|
48
|
+
if ( ca_has_mask(cr->parent) ) {
|
49
|
+
ca_create_mask(ca);
|
50
|
+
return 1;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
int
|
59
|
+
ca_is_any_masked (void *ap)
|
60
|
+
{
|
61
|
+
CArray *ca = (CArray *) ap;
|
62
|
+
boolean8_t *m;
|
63
|
+
int32_t i;
|
64
|
+
int flag = 0;
|
65
|
+
|
66
|
+
ca_update_mask(ca);
|
67
|
+
if ( ca->mask ) {
|
68
|
+
ca_attach(ca->mask);
|
69
|
+
m = (boolean8_t *) ca->mask->ptr;
|
70
|
+
for (i=0; i<ca->elements; i++) {
|
71
|
+
if ( *m++ ) {
|
72
|
+
flag = 1;
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
ca_detach(ca->mask);
|
77
|
+
}
|
78
|
+
|
79
|
+
return flag;
|
80
|
+
}
|
81
|
+
|
82
|
+
int
|
83
|
+
ca_is_all_masked (void *ap)
|
84
|
+
{
|
85
|
+
CArray *ca = (CArray *) ap;
|
86
|
+
boolean8_t *m;
|
87
|
+
int32_t i;
|
88
|
+
int flag;
|
89
|
+
|
90
|
+
ca_update_mask(ca);
|
91
|
+
if ( ca->mask ) {
|
92
|
+
flag = 1;
|
93
|
+
ca_attach(ca->mask);
|
94
|
+
m = (boolean8_t *) ca->mask->ptr;
|
95
|
+
for (i=0; i<ca->elements; i++) {
|
96
|
+
if ( ! *m++ ) {
|
97
|
+
flag = 0;
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
ca_detach(ca->mask);
|
102
|
+
return flag;
|
103
|
+
} else {
|
104
|
+
return 0;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
void
|
109
|
+
ca_update_mask (void *ap)
|
110
|
+
{
|
111
|
+
CArray *ca = (CArray *) ap;
|
112
|
+
if ( ( ! ca->mask ) && ca_has_mask(ca) ) {
|
113
|
+
ca_create_mask(ca);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
void
|
118
|
+
ca_create_mask (void *ap)
|
119
|
+
{
|
120
|
+
CArray *ca = (CArray *) ap;
|
121
|
+
|
122
|
+
if ( ca_is_value_array(ca) ) {
|
123
|
+
rb_raise(rb_eRuntimeError,
|
124
|
+
"can not create mask array for the value array");
|
125
|
+
}
|
126
|
+
|
127
|
+
if ( ca_is_mask_array(ca) ) {
|
128
|
+
rb_raise(rb_eRuntimeError,
|
129
|
+
"can not create mask array for the mask array");
|
130
|
+
}
|
131
|
+
|
132
|
+
if ( ! ca->mask ) {
|
133
|
+
ca_func[ca->obj_type].create_mask(ca);
|
134
|
+
ca_set_flag(ca->mask, CA_FLAG_MASK_ARRAY);
|
135
|
+
if ( ca_is_virtual(ca) ) {
|
136
|
+
if ( CAVIRTUAL(ca)->attach ) {
|
137
|
+
ca_attach(ca->mask);
|
138
|
+
if ( ca_is_virtual(ca->mask) ) {
|
139
|
+
CAVIRTUAL(ca->mask)->attach = CAVIRTUAL(ca)->attach;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
void
|
147
|
+
ca_clear_mask (void *ap)
|
148
|
+
{
|
149
|
+
CArray *ca = (CArray *) ap;
|
150
|
+
|
151
|
+
ca_update_mask(ca);
|
152
|
+
if ( ca->mask ) {
|
153
|
+
boolean8_t zero = 0;
|
154
|
+
ca_fill(ca->mask, &zero);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
void
|
159
|
+
ca_setup_mask (void *ap, CArray *mask)
|
160
|
+
{
|
161
|
+
CArray *ca = (CArray *) ap;
|
162
|
+
|
163
|
+
ca_update_mask(ca);
|
164
|
+
|
165
|
+
if ( mask ) {
|
166
|
+
if ( ! ca->mask ) {
|
167
|
+
ca_create_mask(ca);
|
168
|
+
}
|
169
|
+
ca_attach(mask);
|
170
|
+
ca_sync_data(ca->mask, mask->ptr);
|
171
|
+
ca_detach(mask);
|
172
|
+
}
|
173
|
+
else if ( ca->mask ) {
|
174
|
+
boolean8_t zero = 0;
|
175
|
+
ca_fill(ca->mask, &zero);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
/*
|
180
|
+
ca_copy_mask_overlay_n (void *ap, int32_t elements, int n, CArray **slist)
|
181
|
+
|
182
|
+
+ slist[i] can be NULL (simply skipped)
|
183
|
+
|
184
|
+
*/
|
185
|
+
|
186
|
+
void
|
187
|
+
ca_copy_mask_overlay_n (void *ap, int32_t elements, int n, CArray **slist)
|
188
|
+
{
|
189
|
+
CArray *ca = (CArray *) ap;
|
190
|
+
CArray *cs;
|
191
|
+
boolean8_t *ma, *ms;
|
192
|
+
int i, some_has_mask = 0;
|
193
|
+
int32_t j;
|
194
|
+
|
195
|
+
for (i=0; i<n; i++) {
|
196
|
+
if ( slist[i] && ca_has_mask(slist[i]) ) {
|
197
|
+
some_has_mask = 1;
|
198
|
+
break;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
if ( some_has_mask ) {
|
203
|
+
|
204
|
+
ca_update_mask(ca);
|
205
|
+
if ( ! ca->mask ) {
|
206
|
+
ca_create_mask(ca);
|
207
|
+
}
|
208
|
+
|
209
|
+
if ( elements > ca->elements ) {
|
210
|
+
elements = ca->elements;
|
211
|
+
}
|
212
|
+
|
213
|
+
ca_attach(ca->mask);
|
214
|
+
for (i=0; i<n; i++) {
|
215
|
+
cs = slist[i];
|
216
|
+
if ( ! cs ) {
|
217
|
+
continue;
|
218
|
+
}
|
219
|
+
ca_update_mask(cs);
|
220
|
+
if ( ! cs->mask ) {
|
221
|
+
continue;
|
222
|
+
}
|
223
|
+
ca_attach(cs->mask);
|
224
|
+
ma = (boolean8_t *) ca->mask->ptr;
|
225
|
+
ms = (boolean8_t *) cs->mask->ptr;
|
226
|
+
if ( ca_is_scalar(cs) ) {
|
227
|
+
if ( *ms ) {
|
228
|
+
for (j=0; j<elements; j++) {
|
229
|
+
*ma = 1;
|
230
|
+
ma++;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
else {
|
235
|
+
for (j=0; j<elements; j++) {
|
236
|
+
if ( *ms ) {
|
237
|
+
*ma = 1;
|
238
|
+
}
|
239
|
+
ma++; ms++;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
ca_detach(cs->mask);
|
243
|
+
}
|
244
|
+
ca_sync(ca->mask);
|
245
|
+
ca_detach(ca->mask);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
void
|
250
|
+
ca_copy_mask_overlay (void *ap, int32_t elements, int n, ...)
|
251
|
+
{
|
252
|
+
CArray *ca = (CArray *) ap;
|
253
|
+
CArray **slist;
|
254
|
+
va_list args;
|
255
|
+
int i;
|
256
|
+
|
257
|
+
slist = malloc_with_check(sizeof(CArray *)*n);
|
258
|
+
va_start(args, n);
|
259
|
+
for (i=0; i<n; i++) {
|
260
|
+
slist[i] = va_arg(args, CArray *);
|
261
|
+
}
|
262
|
+
va_end(args);
|
263
|
+
|
264
|
+
ca_copy_mask_overlay_n(ca, elements, n, slist);
|
265
|
+
|
266
|
+
free(slist);
|
267
|
+
}
|
268
|
+
|
269
|
+
void
|
270
|
+
ca_copy_mask_overwrite_n (void *ap, int32_t elements, int n, CArray **slist)
|
271
|
+
{
|
272
|
+
CArray *ca = (CArray *) ap;
|
273
|
+
|
274
|
+
ca_update_mask(ca);
|
275
|
+
if ( ca->mask ) {
|
276
|
+
boolean8_t zero = 0;
|
277
|
+
ca_fill(ca->mask, &zero);
|
278
|
+
}
|
279
|
+
|
280
|
+
ca_copy_mask_overlay_n(ca, elements, n, slist);
|
281
|
+
}
|
282
|
+
|
283
|
+
void
|
284
|
+
ca_copy_mask_overwrite (void *ap, int32_t elements, int n, ...)
|
285
|
+
{
|
286
|
+
CArray *ca = (CArray *) ap;
|
287
|
+
CArray **slist;
|
288
|
+
va_list args;
|
289
|
+
int i;
|
290
|
+
|
291
|
+
slist = malloc_with_check(sizeof(CArray*)*n);
|
292
|
+
va_start(args, n);
|
293
|
+
for (i=0; i<n; i++) {
|
294
|
+
slist[i] = va_arg(args, CArray*);
|
295
|
+
}
|
296
|
+
va_end(args);
|
297
|
+
|
298
|
+
ca_update_mask(ca);
|
299
|
+
if ( ca->mask ) {
|
300
|
+
boolean8_t zero = 0;
|
301
|
+
ca_fill(ca->mask, &zero);
|
302
|
+
}
|
303
|
+
|
304
|
+
ca_copy_mask_overlay_n(ca, elements, n, slist);
|
305
|
+
|
306
|
+
free(slist);
|
307
|
+
}
|
308
|
+
|
309
|
+
void
|
310
|
+
ca_copy_mask (void *ap, void *ao)
|
311
|
+
{
|
312
|
+
CArray *ca = (CArray *) ap;
|
313
|
+
CArray *co = (CArray *) ao;
|
314
|
+
ca_check_same_elements(ca, co);
|
315
|
+
ca_copy_mask_overlay(ca, ca->elements, 1, co);
|
316
|
+
}
|
317
|
+
|
318
|
+
int32_t
|
319
|
+
ca_count_masked (void *ap)
|
320
|
+
{
|
321
|
+
CArray *ca = (CArray *) ap;
|
322
|
+
boolean8_t *m;
|
323
|
+
int32_t i, count = 0;
|
324
|
+
|
325
|
+
ca_update_mask(ca);
|
326
|
+
|
327
|
+
if ( ca->mask ) {
|
328
|
+
ca_attach(ca->mask);
|
329
|
+
m = (boolean8_t *) ca->mask->ptr;
|
330
|
+
for (i=0; i<ca->elements; i++) {
|
331
|
+
if ( *m++ ) {
|
332
|
+
count++;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
ca_detach(ca->mask);
|
336
|
+
}
|
337
|
+
|
338
|
+
return count;
|
339
|
+
}
|
340
|
+
|
341
|
+
int32_t
|
342
|
+
ca_count_not_masked (void *ap)
|
343
|
+
{
|
344
|
+
CArray *ca = (CArray *) ap;
|
345
|
+
return ca->elements - ca_count_masked(ca);
|
346
|
+
}
|
347
|
+
|
348
|
+
#define proc_fill_bang(type) \
|
349
|
+
{ \
|
350
|
+
int32_t i; \
|
351
|
+
type *p = (type *)ca->ptr; \
|
352
|
+
type v = *(type *)fill_value; \
|
353
|
+
boolean8_t *m = (boolean8_t *) ca->mask->ptr; \
|
354
|
+
for (i=0; i<ca->elements; i++) { \
|
355
|
+
if ( *m ) { \
|
356
|
+
*p = v; \
|
357
|
+
*m = 0; \
|
358
|
+
} \
|
359
|
+
m++; p++; \
|
360
|
+
} \
|
361
|
+
}
|
362
|
+
|
363
|
+
#define proc_fill_bang_fixlen() \
|
364
|
+
{ \
|
365
|
+
int32_t i; \
|
366
|
+
char *p = ca->ptr; \
|
367
|
+
boolean8_t *m = (boolean8_t *) ca->mask->ptr; \
|
368
|
+
for (i=0; i<ca->elements; i++) { \
|
369
|
+
if ( *m ) { \
|
370
|
+
memcpy(p, fill_value, ca->bytes); \
|
371
|
+
*m = 0; \
|
372
|
+
} \
|
373
|
+
m++; p+=ca->bytes; \
|
374
|
+
} \
|
375
|
+
}
|
376
|
+
|
377
|
+
void
|
378
|
+
ca_unmask (void *ap, char *fill_value)
|
379
|
+
{
|
380
|
+
CArray *ca = (CArray *) ap;
|
381
|
+
|
382
|
+
ca_update_mask(ca);
|
383
|
+
if ( ca->mask ) {
|
384
|
+
if ( ! fill_value ) {
|
385
|
+
boolean8_t zero = 0;
|
386
|
+
ca_fill(ca->mask, &zero);
|
387
|
+
}
|
388
|
+
else {
|
389
|
+
ca_attach(ca);
|
390
|
+
|
391
|
+
switch ( ca->data_type ) {
|
392
|
+
case CA_FIXLEN: proc_fill_bang_fixlen(); break;
|
393
|
+
case CA_BOOLEAN:
|
394
|
+
case CA_INT8:
|
395
|
+
case CA_UINT8: proc_fill_bang(int8_t); break;
|
396
|
+
case CA_INT16:
|
397
|
+
case CA_UINT16: proc_fill_bang(int16_t); break;
|
398
|
+
case CA_INT32:
|
399
|
+
case CA_UINT32:
|
400
|
+
case CA_FLOAT32: proc_fill_bang(int32_t); break;
|
401
|
+
case CA_INT64:
|
402
|
+
case CA_UINT64:
|
403
|
+
case CA_FLOAT64: proc_fill_bang(float64_t); break;
|
404
|
+
case CA_FLOAT128: proc_fill_bang(float128_t); break;
|
405
|
+
#ifdef HAVE_COMPLEX_H
|
406
|
+
case CA_CMPLX64: proc_fill_bang(cmplx64_t); break;
|
407
|
+
case CA_CMPLX128: proc_fill_bang(cmplx128_t); break;
|
408
|
+
case CA_CMPLX256: proc_fill_bang(cmplx256_t); break;
|
409
|
+
#endif
|
410
|
+
case CA_OBJECT: proc_fill_bang(VALUE); break;
|
411
|
+
default: rb_bug("array has an unknown data type");
|
412
|
+
}
|
413
|
+
|
414
|
+
ca_sync(ca);
|
415
|
+
ca_detach(ca);
|
416
|
+
}
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
CArray *
|
421
|
+
ca_unmask_copy (void *ap, char *fill_value)
|
422
|
+
{
|
423
|
+
CArray *ca = (CArray *) ap;
|
424
|
+
CArray *co;
|
425
|
+
char *p, *q;
|
426
|
+
boolean8_t *m;
|
427
|
+
int32_t i;
|
428
|
+
|
429
|
+
co = ca_template(ca);
|
430
|
+
ca_copy_data(ca, co->ptr);
|
431
|
+
|
432
|
+
if ( fill_value && ca_has_mask(ca) ) {
|
433
|
+
ca_attach(ca);
|
434
|
+
p = ca->ptr;
|
435
|
+
q = co->ptr;
|
436
|
+
m = (boolean8_t *) ca->mask->ptr;
|
437
|
+
for (i=0; i<ca->elements; i++) {
|
438
|
+
if ( *m ) {
|
439
|
+
memcpy(q, fill_value, ca->bytes);
|
440
|
+
}
|
441
|
+
m++; p+=ca->bytes; q+=co->bytes;
|
442
|
+
}
|
443
|
+
ca_detach(ca);
|
444
|
+
}
|
445
|
+
|
446
|
+
return co;
|
447
|
+
}
|
448
|
+
|
449
|
+
void
|
450
|
+
ca_invert_mask (void *ap)
|
451
|
+
{
|
452
|
+
CArray *ca = (CArray *) ap;
|
453
|
+
boolean8_t *m;
|
454
|
+
int32_t i;
|
455
|
+
|
456
|
+
ca_update_mask(ca);
|
457
|
+
|
458
|
+
if ( ! ca->mask ) {
|
459
|
+
ca_create_mask(ca);
|
460
|
+
}
|
461
|
+
|
462
|
+
ca_attach(ca->mask);
|
463
|
+
m = (boolean8_t *) ca->mask->ptr;
|
464
|
+
for (i=0; i<ca->elements; i++) {
|
465
|
+
*m ^= 1;
|
466
|
+
m++;
|
467
|
+
}
|
468
|
+
ca_detach(ca->mask);
|
469
|
+
|
470
|
+
return;
|
471
|
+
}
|
472
|
+
|
473
|
+
boolean8_t *
|
474
|
+
ca_allocate_mask_iterator_n (int n, CArray **slist)
|
475
|
+
{
|
476
|
+
boolean8_t *m, *mp, *ms;
|
477
|
+
CArray *cs;
|
478
|
+
int32_t j, elements = -1;
|
479
|
+
int i, some_has_mask = 0;
|
480
|
+
|
481
|
+
for (i=0; i<n; i++) {
|
482
|
+
if ( slist[i] ) {
|
483
|
+
if ( ca_has_mask(slist[i]) ) {
|
484
|
+
some_has_mask = 1;
|
485
|
+
}
|
486
|
+
|
487
|
+
if ( elements >= 0 ) {
|
488
|
+
if ( elements != slist[i]->elements ) {
|
489
|
+
if ( elements == 1 ) {
|
490
|
+
elements = slist[i]->elements;
|
491
|
+
}
|
492
|
+
else if ( ! ca_is_scalar(slist[i]) ) {
|
493
|
+
rb_raise(rb_eRuntimeError,
|
494
|
+
"# of elements is different among the given arrays");
|
495
|
+
}
|
496
|
+
}
|
497
|
+
}
|
498
|
+
else {
|
499
|
+
elements = slist[i]->elements;
|
500
|
+
}
|
501
|
+
}
|
502
|
+
}
|
503
|
+
|
504
|
+
m = malloc(sizeof(boolean8_t)*elements);
|
505
|
+
memset(m, 0, elements);
|
506
|
+
|
507
|
+
if ( ! some_has_mask ) {
|
508
|
+
return m;
|
509
|
+
}
|
510
|
+
|
511
|
+
for (i=0; i<n; i++) {
|
512
|
+
cs = slist[i];
|
513
|
+
if ( ! cs ) {
|
514
|
+
continue;
|
515
|
+
}
|
516
|
+
ca_update_mask(cs);
|
517
|
+
if ( ! cs->mask ) {
|
518
|
+
continue;
|
519
|
+
}
|
520
|
+
ca_attach(cs->mask);
|
521
|
+
ms = (boolean8_t *) cs->mask->ptr;
|
522
|
+
mp = m;
|
523
|
+
if ( ca_is_scalar(cs) ) {
|
524
|
+
if ( *ms ) {
|
525
|
+
for (j=0; j<elements; j++) {
|
526
|
+
*mp = 1;
|
527
|
+
mp++;
|
528
|
+
}
|
529
|
+
}
|
530
|
+
}
|
531
|
+
else {
|
532
|
+
for (j=0; j<elements; j++) {
|
533
|
+
*mp = ( *mp || *ms );
|
534
|
+
mp++; ms++;
|
535
|
+
}
|
536
|
+
}
|
537
|
+
ca_detach(cs->mask);
|
538
|
+
}
|
539
|
+
return m;
|
540
|
+
}
|
541
|
+
|
542
|
+
boolean8_t *
|
543
|
+
ca_allocate_mask_iterator (int n, ...)
|
544
|
+
{
|
545
|
+
boolean8_t *m;
|
546
|
+
CArray **slist;
|
547
|
+
va_list args;
|
548
|
+
int i;
|
549
|
+
|
550
|
+
slist = malloc_with_check(sizeof(CArray *)*n);
|
551
|
+
va_start(args, n);
|
552
|
+
for (i=0; i<n; i++) {
|
553
|
+
slist[i] = va_arg(args, CArray *);
|
554
|
+
}
|
555
|
+
va_end(args);
|
556
|
+
|
557
|
+
m = ca_allocate_mask_iterator_n(n, slist);
|
558
|
+
|
559
|
+
free(slist);
|
560
|
+
|
561
|
+
return m;
|
562
|
+
}
|
563
|
+
|
564
|
+
/* ------------------------------------------------------------------- */
|
565
|
+
|
566
|
+
/* rdoc:
|
567
|
+
class CArray
|
568
|
+
# Returns true if self has the mask array.
|
569
|
+
def has_mask?()
|
570
|
+
end
|
571
|
+
end
|
572
|
+
*/
|
573
|
+
|
574
|
+
VALUE
|
575
|
+
rb_ca_has_mask (VALUE self)
|
576
|
+
{
|
577
|
+
CArray *ca;
|
578
|
+
Data_Get_Struct(self, CArray, ca);
|
579
|
+
return ( ca_has_mask(ca) ) ? Qtrue : Qfalse;
|
580
|
+
}
|
581
|
+
|
582
|
+
/* rdoc:
|
583
|
+
class CArray
|
584
|
+
# Returns true if self has at least one masked element.
|
585
|
+
def any_masked?
|
586
|
+
end
|
587
|
+
end
|
588
|
+
*/
|
589
|
+
|
590
|
+
VALUE
|
591
|
+
rb_ca_is_any_masked (VALUE self)
|
592
|
+
{
|
593
|
+
CArray *ca;
|
594
|
+
Data_Get_Struct(self, CArray, ca);
|
595
|
+
return ( ca_is_any_masked(ca) ) ? Qtrue : Qfalse;
|
596
|
+
}
|
597
|
+
|
598
|
+
/* rdoc:
|
599
|
+
class CArray
|
600
|
+
# Returns true if all elements of self are masked.
|
601
|
+
def all_masked?
|
602
|
+
end
|
603
|
+
end
|
604
|
+
*/
|
605
|
+
|
606
|
+
VALUE
|
607
|
+
rb_ca_is_all_masked (VALUE self)
|
608
|
+
{
|
609
|
+
CArray *ca;
|
610
|
+
Data_Get_Struct(self, CArray, ca);
|
611
|
+
return ( ca_is_all_masked(ca) ) ? Qtrue : Qfalse;
|
612
|
+
}
|
613
|
+
|
614
|
+
/* rdoc:
|
615
|
+
class CArray
|
616
|
+
private
|
617
|
+
def create_mask
|
618
|
+
end
|
619
|
+
end
|
620
|
+
*/
|
621
|
+
|
622
|
+
static VALUE
|
623
|
+
rb_ca_create_mask (VALUE self)
|
624
|
+
{
|
625
|
+
CArray *ca;
|
626
|
+
rb_ca_modify(self);
|
627
|
+
Data_Get_Struct(self, CArray, ca);
|
628
|
+
ca_create_mask(ca);
|
629
|
+
return Qnil;
|
630
|
+
}
|
631
|
+
|
632
|
+
/* rdoc:
|
633
|
+
class CArray
|
634
|
+
private
|
635
|
+
def update_mask
|
636
|
+
end
|
637
|
+
end
|
638
|
+
*/
|
639
|
+
|
640
|
+
/*
|
641
|
+
static VALUE
|
642
|
+
rb_ca_update_mask (VALUE self)
|
643
|
+
{
|
644
|
+
CArray *ca;
|
645
|
+
Data_Get_Struct(self, CArray, ca);
|
646
|
+
ca_update_mask(ca);
|
647
|
+
return Qnil;
|
648
|
+
}
|
649
|
+
*/
|
650
|
+
|
651
|
+
/* rdoc:
|
652
|
+
class CArray
|
653
|
+
# Returns new array which refers the data of <code>self</code>.
|
654
|
+
# The data of masked elements of <code>self</code> can be accessed
|
655
|
+
# via the returned array. The value array can't be set mask.
|
656
|
+
def value ()
|
657
|
+
end
|
658
|
+
end
|
659
|
+
*/
|
660
|
+
|
661
|
+
VALUE
|
662
|
+
rb_ca_value_array (VALUE self)
|
663
|
+
{
|
664
|
+
VALUE obj;
|
665
|
+
CArray *ca, *co;
|
666
|
+
|
667
|
+
Data_Get_Struct(self, CArray, ca);
|
668
|
+
|
669
|
+
obj = rb_ca_refer_new(self, ca->data_type, ca->rank, ca->dim, ca->bytes, 0);
|
670
|
+
Data_Get_Struct(obj, CArray, co);
|
671
|
+
|
672
|
+
ca_set_flag(co, CA_FLAG_VALUE_ARRAY);
|
673
|
+
|
674
|
+
return obj;
|
675
|
+
}
|
676
|
+
|
677
|
+
/* rdoc:
|
678
|
+
class CArray
|
679
|
+
# Returns new array which refers the mask state of <code>self</code>.
|
680
|
+
# The mask array can't be set mask.
|
681
|
+
def mask ()
|
682
|
+
end
|
683
|
+
end
|
684
|
+
*/
|
685
|
+
|
686
|
+
VALUE
|
687
|
+
rb_ca_mask_array (VALUE self)
|
688
|
+
{
|
689
|
+
VALUE obj;
|
690
|
+
CArray *ca;
|
691
|
+
Data_Get_Struct(self, CArray, ca);
|
692
|
+
|
693
|
+
ca_update_mask(ca);
|
694
|
+
if ( ca->mask ) {
|
695
|
+
obj = Data_Wrap_Struct(ca_class[ca->mask->obj_type],
|
696
|
+
ca_mark, ca_free_nop, ca->mask);
|
697
|
+
rb_ivar_set(obj, rb_intern("masked_array"), self);
|
698
|
+
if ( OBJ_FROZEN(self) ) {
|
699
|
+
rb_ca_freeze(obj);
|
700
|
+
}
|
701
|
+
return obj;
|
702
|
+
}
|
703
|
+
else {
|
704
|
+
return INT2NUM(0);
|
705
|
+
}
|
706
|
+
}
|
707
|
+
|
708
|
+
/* rdoc:
|
709
|
+
class CArray
|
710
|
+
# Asigns <code>new_mask</code> to the mask array of <code>self</code>.
|
711
|
+
# If <code>self</code> doesn't have a mask array, it will be created
|
712
|
+
# before asignment.
|
713
|
+
def mask= (new_mask)
|
714
|
+
end
|
715
|
+
end
|
716
|
+
*/
|
717
|
+
|
718
|
+
VALUE
|
719
|
+
rb_ca_set_mask (VALUE self, VALUE rval)
|
720
|
+
{
|
721
|
+
volatile VALUE rmask = rval;
|
722
|
+
CArray *ca, *cv;
|
723
|
+
|
724
|
+
rb_ca_modify(self);
|
725
|
+
|
726
|
+
Data_Get_Struct(self, CArray, ca);
|
727
|
+
|
728
|
+
if ( ca_is_value_array(ca) ) {
|
729
|
+
rb_raise(rb_eRuntimeError,
|
730
|
+
"can not create mask for the value array");
|
731
|
+
}
|
732
|
+
|
733
|
+
if ( ca_is_mask_array(ca) ) {
|
734
|
+
rb_raise(rb_eRuntimeError,
|
735
|
+
"can not create mask for the mask array");
|
736
|
+
}
|
737
|
+
|
738
|
+
ca_update_mask(ca);
|
739
|
+
if ( ! ca->mask ) {
|
740
|
+
ca_create_mask(ca);
|
741
|
+
}
|
742
|
+
|
743
|
+
if ( rb_obj_is_carray(rmask) ) {
|
744
|
+
Data_Get_Struct(rmask, CArray, cv);
|
745
|
+
if ( ! ca_is_boolean_type(cv) ) {
|
746
|
+
cv = ca_wrap_readonly(rval, CA_BOOLEAN);
|
747
|
+
}
|
748
|
+
ca_setup_mask(ca, cv);
|
749
|
+
ca_copy_mask_overlay(ca, ca->elements, 1, cv);
|
750
|
+
return rval;
|
751
|
+
}
|
752
|
+
else {
|
753
|
+
return rb_ca_store_all(rb_ca_mask_array(self), rmask);
|
754
|
+
}
|
755
|
+
}
|
756
|
+
|
757
|
+
/* rdoc:
|
758
|
+
class CArray
|
759
|
+
# Returns new boolean type array of same shape with <code>self</code>.
|
760
|
+
# The returned array has 1 for the masked elements and
|
761
|
+
# 0 for not-masked elements.
|
762
|
+
def is_masked ()
|
763
|
+
end
|
764
|
+
end
|
765
|
+
*/
|
766
|
+
|
767
|
+
VALUE
|
768
|
+
rb_ca_is_masked (VALUE self)
|
769
|
+
{
|
770
|
+
volatile VALUE mask;
|
771
|
+
CArray *ca, *cm, *co;
|
772
|
+
boolean8_t zero = 0;
|
773
|
+
boolean8_t *m, *p;
|
774
|
+
int32_t i;
|
775
|
+
|
776
|
+
Data_Get_Struct(self, CArray, ca);
|
777
|
+
|
778
|
+
co = carray_new(CA_BOOLEAN, ca->rank, ca->dim, ca->bytes, NULL);
|
779
|
+
|
780
|
+
ca_update_mask(ca);
|
781
|
+
if ( ! ca->mask ) {
|
782
|
+
ca_fill(co, &zero);
|
783
|
+
}
|
784
|
+
else {
|
785
|
+
mask = rb_ca_mask_array(self);
|
786
|
+
Data_Get_Struct(mask, CArray, cm);
|
787
|
+
ca_attach(cm);
|
788
|
+
m = (boolean8_t *) cm->ptr;
|
789
|
+
p = (boolean8_t *) co->ptr;
|
790
|
+
for (i=0; i<ca->elements; i++) {
|
791
|
+
*p = ( *m ) ? 1 : 0;
|
792
|
+
m++; p++;
|
793
|
+
}
|
794
|
+
ca_detach(cm);
|
795
|
+
}
|
796
|
+
|
797
|
+
return ca_wrap_struct(co);
|
798
|
+
}
|
799
|
+
|
800
|
+
/* rdoc:
|
801
|
+
class CArray
|
802
|
+
# Returns new boolean type array of same shape with <code>self</code>.
|
803
|
+
# The returned array has 0 for the masked elements and
|
804
|
+
# 1 for not-masked elements.
|
805
|
+
def is_not_masked ()
|
806
|
+
end
|
807
|
+
end
|
808
|
+
*/
|
809
|
+
|
810
|
+
VALUE
|
811
|
+
rb_ca_is_not_masked (VALUE self)
|
812
|
+
{
|
813
|
+
volatile VALUE mask;
|
814
|
+
CArray *ca, *cm, *co;
|
815
|
+
boolean8_t one = 1;
|
816
|
+
boolean8_t *m, *p;
|
817
|
+
int32_t i;
|
818
|
+
|
819
|
+
Data_Get_Struct(self, CArray, ca);
|
820
|
+
|
821
|
+
co = carray_new(CA_BOOLEAN, ca->rank, ca->dim, ca->bytes, NULL);
|
822
|
+
|
823
|
+
ca_update_mask(ca);
|
824
|
+
if ( ! ca->mask ) {
|
825
|
+
ca_fill(co, &one);
|
826
|
+
}
|
827
|
+
else {
|
828
|
+
mask = rb_ca_mask_array(self);
|
829
|
+
Data_Get_Struct(mask, CArray, cm);
|
830
|
+
ca_attach(cm);
|
831
|
+
m = (boolean8_t *) cm->ptr;
|
832
|
+
p = (boolean8_t *) co->ptr;
|
833
|
+
for (i=0; i<ca->elements; i++) {
|
834
|
+
*p = ( *m ) ? 0 : 1;
|
835
|
+
m++; p++;
|
836
|
+
}
|
837
|
+
ca_detach(cm);
|
838
|
+
}
|
839
|
+
|
840
|
+
return ca_wrap_struct(co);
|
841
|
+
}
|
842
|
+
|
843
|
+
/* rdoc:
|
844
|
+
class CArray
|
845
|
+
# Returns the number of masked elements.
|
846
|
+
def count_masked ()
|
847
|
+
end
|
848
|
+
end
|
849
|
+
*/
|
850
|
+
|
851
|
+
VALUE
|
852
|
+
rb_ca_count_masked (VALUE self)
|
853
|
+
{
|
854
|
+
CArray *ca;
|
855
|
+
Data_Get_Struct(self, CArray, ca);
|
856
|
+
return INT2NUM(ca_count_masked(ca));
|
857
|
+
}
|
858
|
+
|
859
|
+
/* rdoc:
|
860
|
+
class CArray
|
861
|
+
# Returns the number of not-masked elements.
|
862
|
+
def count_not_masked ()
|
863
|
+
end
|
864
|
+
end
|
865
|
+
*/
|
866
|
+
|
867
|
+
VALUE
|
868
|
+
rb_ca_count_not_masked (VALUE self)
|
869
|
+
{
|
870
|
+
CArray *ca;
|
871
|
+
Data_Get_Struct(self, CArray, ca);
|
872
|
+
return INT2NUM(ca_count_not_masked(ca));
|
873
|
+
}
|
874
|
+
|
875
|
+
static VALUE
|
876
|
+
rb_ca_unmask_method (int argc, VALUE *argv, VALUE self)
|
877
|
+
{
|
878
|
+
volatile VALUE rfval = CA_NIL, rcs;
|
879
|
+
CArray *ca;
|
880
|
+
CScalar *cv;
|
881
|
+
char *fval = NULL;
|
882
|
+
|
883
|
+
rb_ca_modify(self);
|
884
|
+
|
885
|
+
if ( argc >= 1 ) {
|
886
|
+
rfval = argv[0];
|
887
|
+
}
|
888
|
+
|
889
|
+
Data_Get_Struct(self, CArray, ca);
|
890
|
+
|
891
|
+
if ( rfval != CA_NIL ) {
|
892
|
+
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
|
893
|
+
Data_Get_Struct(rcs, CScalar, cv);
|
894
|
+
fval = cv->ptr;
|
895
|
+
}
|
896
|
+
|
897
|
+
ca_unmask(ca, fval);
|
898
|
+
|
899
|
+
return self;
|
900
|
+
}
|
901
|
+
|
902
|
+
/* api: rb_ca_unmask */
|
903
|
+
|
904
|
+
VALUE
|
905
|
+
rb_ca_unmask (VALUE self)
|
906
|
+
{
|
907
|
+
return rb_ca_unmask_method(0, NULL, self);
|
908
|
+
}
|
909
|
+
|
910
|
+
/* api: rb_ca_mask_fill */
|
911
|
+
|
912
|
+
VALUE
|
913
|
+
rb_ca_mask_fill (VALUE self, VALUE fval)
|
914
|
+
{
|
915
|
+
return rb_ca_unmask_method(1, &fval, self);
|
916
|
+
}
|
917
|
+
|
918
|
+
/* rdoc:
|
919
|
+
class CArray
|
920
|
+
# Returns new unmasked array.
|
921
|
+
# If the optional argument <code>fill_value</code> is given,
|
922
|
+
# the masked elements are filled by <code>fill_value</code>.
|
923
|
+
# The returned array doesn't have the mask array.
|
924
|
+
def unmask_copy (fill_value=nil)
|
925
|
+
end
|
926
|
+
end
|
927
|
+
*/
|
928
|
+
|
929
|
+
static VALUE
|
930
|
+
rb_ca_unmask_copy_method (int argc, VALUE *argv, VALUE self)
|
931
|
+
{
|
932
|
+
volatile VALUE obj, rfval = CA_NIL, rcs;
|
933
|
+
CArray *ca, *co;
|
934
|
+
CScalar *cv;
|
935
|
+
char *fval = NULL;
|
936
|
+
|
937
|
+
if ( argc >= 1 ) {
|
938
|
+
rfval = argv[0];
|
939
|
+
}
|
940
|
+
|
941
|
+
Data_Get_Struct(self, CArray, ca);
|
942
|
+
|
943
|
+
if ( rfval != CA_NIL ) {
|
944
|
+
rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
|
945
|
+
Data_Get_Struct(rcs, CScalar, cv);
|
946
|
+
fval = cv->ptr;
|
947
|
+
}
|
948
|
+
|
949
|
+
co = ca_unmask_copy(ca, fval);
|
950
|
+
obj = ca_wrap_struct(co);
|
951
|
+
rb_ca_data_type_inherit(obj, self);
|
952
|
+
return obj;
|
953
|
+
}
|
954
|
+
|
955
|
+
/* api: rb_ca_unmask_copy */
|
956
|
+
|
957
|
+
VALUE
|
958
|
+
rb_ca_unmask_copy (VALUE self)
|
959
|
+
{
|
960
|
+
return rb_ca_unmask_copy_method(0, NULL, self);
|
961
|
+
}
|
962
|
+
|
963
|
+
/* api: rb_ca_mask_fill_copy */
|
964
|
+
|
965
|
+
VALUE
|
966
|
+
rb_ca_mask_fill_copy (VALUE self, VALUE fval)
|
967
|
+
{
|
968
|
+
return rb_ca_unmask_copy_method(1, &fval, self);
|
969
|
+
}
|
970
|
+
|
971
|
+
/* CArray#invert_mask */
|
972
|
+
|
973
|
+
VALUE
|
974
|
+
rb_ca_invert_mask (VALUE self)
|
975
|
+
{
|
976
|
+
CArray *ca;
|
977
|
+
Data_Get_Struct(self, CArray, ca);
|
978
|
+
ca_invert_mask(ca);
|
979
|
+
return self;
|
980
|
+
}
|
981
|
+
|
982
|
+
/* rdoc:
|
983
|
+
class CArray
|
984
|
+
# Sets the mask array of <code>self</code> by the logical sum of
|
985
|
+
# the mask states of <code>self</code> and arrays given in arguments.
|
986
|
+
def inherit_mask (*argv)
|
987
|
+
end
|
988
|
+
end
|
989
|
+
*/
|
990
|
+
|
991
|
+
static VALUE
|
992
|
+
rb_ca_inherit_mask_method (int argc, VALUE *argv, VALUE self)
|
993
|
+
{
|
994
|
+
CArray **slist;
|
995
|
+
CArray *ca, *cs;
|
996
|
+
int i;
|
997
|
+
|
998
|
+
rb_ca_modify(self);
|
999
|
+
|
1000
|
+
Data_Get_Struct(self, CArray, ca);
|
1001
|
+
|
1002
|
+
slist = malloc_with_check(sizeof(CArray *)*argc);
|
1003
|
+
for (i=0; i<argc; i++) {
|
1004
|
+
if ( rb_obj_is_carray(argv[i]) ) {
|
1005
|
+
Data_Get_Struct(argv[i], CArray, cs);
|
1006
|
+
slist[i] = cs;
|
1007
|
+
}
|
1008
|
+
else {
|
1009
|
+
slist[i] = NULL;
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
ca_copy_mask_overlay_n(ca, ca->elements, argc, slist);
|
1013
|
+
|
1014
|
+
free(slist);
|
1015
|
+
|
1016
|
+
return self;
|
1017
|
+
}
|
1018
|
+
|
1019
|
+
/* api: rb_ca_inherit_mask_n */
|
1020
|
+
|
1021
|
+
VALUE
|
1022
|
+
rb_ca_inherit_mask_n (VALUE self, int n, VALUE *rothers)
|
1023
|
+
{
|
1024
|
+
return rb_ca_inherit_mask_method(n, rothers, self);
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
/* api: rb_ca_inherit_mask */
|
1028
|
+
|
1029
|
+
VALUE
|
1030
|
+
rb_ca_inherit_mask (VALUE self, int n, ...)
|
1031
|
+
{
|
1032
|
+
VALUE other;
|
1033
|
+
CArray **slist;
|
1034
|
+
CArray *ca, *cs;
|
1035
|
+
int i;
|
1036
|
+
va_list rothers;
|
1037
|
+
|
1038
|
+
rb_ca_modify(self);
|
1039
|
+
|
1040
|
+
Data_Get_Struct(self, CArray, ca);
|
1041
|
+
|
1042
|
+
va_start(rothers, n);
|
1043
|
+
slist = malloc_with_check(sizeof(CArray *)*n);
|
1044
|
+
for (i=0; i<n; i++) {
|
1045
|
+
other = va_arg(rothers, VALUE);
|
1046
|
+
if ( rb_obj_is_carray(other) ) {
|
1047
|
+
Data_Get_Struct(other, CArray, cs);
|
1048
|
+
slist[i] = cs;
|
1049
|
+
}
|
1050
|
+
else {
|
1051
|
+
slist[i] = NULL;
|
1052
|
+
}
|
1053
|
+
}
|
1054
|
+
va_end(rothers);
|
1055
|
+
|
1056
|
+
ca_copy_mask_overlay_n(ca, ca->elements, n, slist);
|
1057
|
+
|
1058
|
+
free(slist);
|
1059
|
+
|
1060
|
+
return self;
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
/* rdoc:
|
1064
|
+
class CArray
|
1065
|
+
# Sets the mask array of <code>self</code> by the logical sum of
|
1066
|
+
# the mask states of arrays given in arguments.
|
1067
|
+
def inherit_mask_replace (*argv)
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
*/
|
1071
|
+
|
1072
|
+
static VALUE
|
1073
|
+
rb_ca_inherit_mask_replace_method (int argc, VALUE *argv, VALUE self)
|
1074
|
+
{
|
1075
|
+
CArray **slist;
|
1076
|
+
CArray *ca, *cs;
|
1077
|
+
int i;
|
1078
|
+
|
1079
|
+
rb_ca_modify(self);
|
1080
|
+
|
1081
|
+
Data_Get_Struct(self, CArray, ca);
|
1082
|
+
|
1083
|
+
slist = malloc_with_check(sizeof(CArray *)*argc);
|
1084
|
+
for (i=0; i<argc; i++) {
|
1085
|
+
if ( rb_obj_is_carray(argv[i]) ) {
|
1086
|
+
Data_Get_Struct(argv[i], CArray, cs);
|
1087
|
+
slist[i] = cs;
|
1088
|
+
}
|
1089
|
+
else {
|
1090
|
+
slist[i] = NULL;
|
1091
|
+
}
|
1092
|
+
}
|
1093
|
+
ca_copy_mask_overwrite_n(ca, ca->elements, argc, slist);
|
1094
|
+
|
1095
|
+
free(slist);
|
1096
|
+
|
1097
|
+
return self;
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
/* api: rb_ca_inherit_mask_replace_n */
|
1101
|
+
|
1102
|
+
VALUE
|
1103
|
+
rb_ca_inherit_mask_replace_n (VALUE self, int n, VALUE *rothers)
|
1104
|
+
{
|
1105
|
+
return rb_ca_inherit_mask_replace_method(n, rothers, self);
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
/* api: rb_ca_inherit_mask_replace */
|
1109
|
+
|
1110
|
+
VALUE
|
1111
|
+
rb_ca_inherit_mask_replace (VALUE self, int n, ...)
|
1112
|
+
{
|
1113
|
+
VALUE other;
|
1114
|
+
CArray **slist;
|
1115
|
+
CArray *ca, *cs;
|
1116
|
+
int i;
|
1117
|
+
va_list rothers;
|
1118
|
+
|
1119
|
+
rb_ca_modify(self);
|
1120
|
+
|
1121
|
+
Data_Get_Struct(self, CArray, ca);
|
1122
|
+
|
1123
|
+
va_start(rothers, n);
|
1124
|
+
slist = malloc_with_check(sizeof(CArray *)*n);
|
1125
|
+
for (i=0; i<n; i++) {
|
1126
|
+
other = va_arg(rothers, VALUE);
|
1127
|
+
if ( rb_obj_is_carray(other) ) {
|
1128
|
+
Data_Get_Struct(other, CArray, cs);
|
1129
|
+
slist[i] = cs;
|
1130
|
+
}
|
1131
|
+
else {
|
1132
|
+
slist[i] = NULL;
|
1133
|
+
}
|
1134
|
+
}
|
1135
|
+
va_end(rothers);
|
1136
|
+
|
1137
|
+
ca_copy_mask_overwrite_n(ca, ca->elements, n, slist);
|
1138
|
+
|
1139
|
+
free(slist);
|
1140
|
+
|
1141
|
+
return self;
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
void
|
1145
|
+
Init_carray_mask ()
|
1146
|
+
{
|
1147
|
+
rb_define_private_method(rb_cCArray, "__create_mask__", rb_ca_create_mask, 0);
|
1148
|
+
/*
|
1149
|
+
rb_define_private_method(rb_cCArray, "__update_mask__", rb_ca_update_mask, 0);
|
1150
|
+
*/
|
1151
|
+
|
1152
|
+
rb_define_method(rb_cCArray, "has_mask?", rb_ca_has_mask, 0);
|
1153
|
+
rb_define_method(rb_cCArray, "any_masked?", rb_ca_is_any_masked, 0);
|
1154
|
+
rb_define_method(rb_cCArray, "all_masked?", rb_ca_is_all_masked, 0);
|
1155
|
+
|
1156
|
+
rb_define_method(rb_cCArray, "value", rb_ca_value_array, 0);
|
1157
|
+
rb_define_method(rb_cCArray, "mask", rb_ca_mask_array, 0);
|
1158
|
+
rb_define_method(rb_cCArray, "mask=", rb_ca_set_mask, 1);
|
1159
|
+
rb_define_method(rb_cCArray, "is_masked", rb_ca_is_masked, 0);
|
1160
|
+
rb_define_method(rb_cCArray, "is_not_masked", rb_ca_is_not_masked, 0);
|
1161
|
+
rb_define_method(rb_cCArray, "unmask", rb_ca_unmask_method, -1);
|
1162
|
+
rb_define_method(rb_cCArray, "unmask_copy", rb_ca_unmask_copy_method, -1);
|
1163
|
+
rb_define_method(rb_cCArray, "invert_mask", rb_ca_invert_mask, 0);
|
1164
|
+
|
1165
|
+
rb_define_method(rb_cCArray, "inherit_mask", rb_ca_inherit_mask_method, -1);
|
1166
|
+
rb_define_method(rb_cCArray, "inherit_mask_replace",
|
1167
|
+
rb_ca_inherit_mask_replace_method, -1);
|
1168
|
+
|
1169
|
+
/* These methods go to lib/carray/base.rb. */
|
1170
|
+
/* rb_define_method(rb_cCArray, "count_masked", rb_ca_count_masked, 0); */
|
1171
|
+
/* rb_define_method(rb_cCArray, "count_not_masked", rb_ca_count_not_masked, 0); */
|
1172
|
+
|
1173
|
+
}
|
1174
|
+
|