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/ca_obj_select.c
ADDED
@@ -0,0 +1,558 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_obj_select.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 "carray.h"
|
14
|
+
|
15
|
+
VALUE rb_cCASelect;
|
16
|
+
|
17
|
+
/* rdoc:
|
18
|
+
class CASelect < CAVirtual # :nodoc:
|
19
|
+
end
|
20
|
+
*/
|
21
|
+
|
22
|
+
typedef struct {
|
23
|
+
int16_t obj_type;
|
24
|
+
int8_t data_type;
|
25
|
+
int8_t rank;
|
26
|
+
int32_t flags;
|
27
|
+
int32_t bytes;
|
28
|
+
int32_t elements;
|
29
|
+
int32_t *dim; /* point to _dim */
|
30
|
+
char *ptr;
|
31
|
+
CArray *mask;
|
32
|
+
CArray *parent;
|
33
|
+
uint32_t attach;
|
34
|
+
uint8_t nosync;
|
35
|
+
/* ---------- */
|
36
|
+
CArray *select;
|
37
|
+
int32_t _dim;
|
38
|
+
} CASelect;
|
39
|
+
|
40
|
+
/* ------------------------------------------------------------------- */
|
41
|
+
|
42
|
+
static int
|
43
|
+
ca_select_setup (CASelect *ca, CArray *parent, CArray *select, int share)
|
44
|
+
{
|
45
|
+
int8_t data_type;
|
46
|
+
int32_t bytes;
|
47
|
+
int i;
|
48
|
+
|
49
|
+
if ( ! ca_is_boolean_type(select) ) {
|
50
|
+
rb_raise(rb_eRuntimeError,
|
51
|
+
"selection array for CASelect should be have "
|
52
|
+
"the data_type of CA_BOOLEAN");
|
53
|
+
}
|
54
|
+
|
55
|
+
data_type = parent->data_type;
|
56
|
+
bytes = parent->bytes;
|
57
|
+
|
58
|
+
ca->obj_type = CA_OBJ_SELECT;
|
59
|
+
ca->data_type = data_type;
|
60
|
+
ca->flags = 0;
|
61
|
+
ca->rank = 1;
|
62
|
+
ca->bytes = bytes;
|
63
|
+
|
64
|
+
if ( share && ca_is_entity(select) ) {
|
65
|
+
ca_set_flag(ca, CA_FLAG_SHARE_INDEX);
|
66
|
+
ca->select = select;
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
if ( ca_has_mask(select) ) {
|
70
|
+
boolean8_t *p, *q, *m;
|
71
|
+
ca->select = ca_template(select);
|
72
|
+
ca_attach(select);
|
73
|
+
q = (boolean8_t *) ca->select->ptr;
|
74
|
+
p = (boolean8_t *) select->ptr;
|
75
|
+
m = (boolean8_t *) select->mask->ptr;
|
76
|
+
for (i=0; i<select->elements; i++) {
|
77
|
+
*q = ( *m ) ? 0 : *p;
|
78
|
+
q++; p++; m++;
|
79
|
+
}
|
80
|
+
ca_detach(select);
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
ca->select = ca_copy(select);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
{
|
88
|
+
int count = 0;
|
89
|
+
boolean8_t *s = (boolean8_t *) ca->select->ptr;
|
90
|
+
for (i=0; i<ca->select->elements; i++) {
|
91
|
+
if ( *s ) {
|
92
|
+
count++;
|
93
|
+
}
|
94
|
+
s++;
|
95
|
+
}
|
96
|
+
ca->elements = count;
|
97
|
+
}
|
98
|
+
|
99
|
+
ca->ptr = NULL;
|
100
|
+
ca->mask = NULL;
|
101
|
+
ca->dim = &(ca->_dim);
|
102
|
+
ca->dim[0] = ca->elements;
|
103
|
+
|
104
|
+
ca->parent = parent;
|
105
|
+
ca->attach = 0;
|
106
|
+
ca->nosync = 0;
|
107
|
+
|
108
|
+
if ( ca_is_scalar(select) ) {
|
109
|
+
ca_set_flag(ca, CA_FLAG_SCALAR);
|
110
|
+
}
|
111
|
+
|
112
|
+
return 0;
|
113
|
+
}
|
114
|
+
|
115
|
+
CArray *
|
116
|
+
ca_select_new (CArray *parent, CArray *select)
|
117
|
+
{
|
118
|
+
CASelect *ca = ALLOC(CASelect);
|
119
|
+
ca_select_setup(ca, parent, select, 0);
|
120
|
+
return (CArray*) ca;
|
121
|
+
}
|
122
|
+
|
123
|
+
CArray *
|
124
|
+
ca_select_new_share (CArray *parent, CArray *select)
|
125
|
+
{
|
126
|
+
CASelect *ca = ALLOC(CASelect);
|
127
|
+
ca_select_setup(ca, parent, select, 1);
|
128
|
+
return (CArray*) ca;
|
129
|
+
}
|
130
|
+
|
131
|
+
static void
|
132
|
+
free_ca_select (void *ap)
|
133
|
+
{
|
134
|
+
CASelect *ca = (CASelect *) ap;
|
135
|
+
if ( ca != NULL ) {
|
136
|
+
ca_free(ca->mask);
|
137
|
+
if ( ! (ca->flags & CA_FLAG_SHARE_INDEX) ) {
|
138
|
+
ca_free(ca->select);
|
139
|
+
}
|
140
|
+
xfree(ca);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
void ca_select_to_ptr (CArray *ca, CArray *select, char *ptr);
|
145
|
+
void ca_select_from_ptr (CArray *ca, CArray *select, char *ptr);
|
146
|
+
void ca_select_fill (CArray *ca, CArray *select, char *valp);
|
147
|
+
void ca_select_to_carray (CArray *ca, CArray *select, CArray *cs);
|
148
|
+
void ca_select_from_carray (CArray *ca, CArray *select, CArray *cs);
|
149
|
+
|
150
|
+
/* ------------------------------------------------------------------- */
|
151
|
+
|
152
|
+
static void *
|
153
|
+
ca_select_func_clone (void *ap)
|
154
|
+
{
|
155
|
+
CASelect *ca = (CASelect *) ap;
|
156
|
+
return ca_select_new_share(ca->parent, ca->select);
|
157
|
+
}
|
158
|
+
|
159
|
+
static char *
|
160
|
+
ca_select_func_ptr_at_addr (void *ap, int32_t addr)
|
161
|
+
{
|
162
|
+
CASelect *ca = (CASelect *) ap;
|
163
|
+
|
164
|
+
if ( ca->ptr ) {
|
165
|
+
return ca->ptr + ca->bytes * addr;
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
int32_t n, i, a;
|
169
|
+
int32_t elements = ca->select->elements;
|
170
|
+
boolean8_t s;
|
171
|
+
|
172
|
+
n = 0;
|
173
|
+
a = 0;
|
174
|
+
|
175
|
+
for (i=0; i<elements; i++) {
|
176
|
+
ca_fetch_addr(ca->select, i, &s);
|
177
|
+
if ( s ) {
|
178
|
+
if ( addr == a++ ) {
|
179
|
+
n = i;
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
if ( ca_is_attached(ca->parent) ) {
|
186
|
+
return ca->parent->ptr + ca->bytes * n;
|
187
|
+
}
|
188
|
+
else {
|
189
|
+
return ca_ptr_at_addr(ca->parent, n);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
static char *
|
195
|
+
ca_select_func_ptr_at_index (void *ap, int32_t *idx)
|
196
|
+
{
|
197
|
+
CASelect *ca = (CASelect *) ap;
|
198
|
+
int32_t addr = idx[0];
|
199
|
+
|
200
|
+
if ( ca->ptr ) {
|
201
|
+
return ca->ptr + ca->bytes * addr;
|
202
|
+
}
|
203
|
+
else {
|
204
|
+
return ca_select_func_ptr_at_addr(ca, idx[0]);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
static void
|
209
|
+
ca_select_func_fetch_addr (void *ap, int32_t addr, void *ptr)
|
210
|
+
{
|
211
|
+
CASelect *ca = (CASelect *) ap;
|
212
|
+
int32_t n, i, a;
|
213
|
+
int32_t elements = ca->select->elements;
|
214
|
+
boolean8_t s;
|
215
|
+
n = 0;
|
216
|
+
a = 0;
|
217
|
+
for (i=0; i<elements; i++) {
|
218
|
+
ca_fetch_addr(ca->select, i, &s);
|
219
|
+
if ( s ) {
|
220
|
+
if ( addr == a++ ) {
|
221
|
+
n = i;
|
222
|
+
break;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
ca_fetch_addr(ca->parent, n, ptr);
|
227
|
+
}
|
228
|
+
|
229
|
+
static void
|
230
|
+
ca_select_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
231
|
+
{
|
232
|
+
ca_select_func_fetch_addr(ap, idx[0], ptr);
|
233
|
+
}
|
234
|
+
|
235
|
+
static void
|
236
|
+
ca_select_func_store_addr (void *ap, int32_t addr, void *ptr)
|
237
|
+
{
|
238
|
+
CASelect *ca = (CASelect *) ap;
|
239
|
+
int32_t n, i, a;
|
240
|
+
int32_t elements = ca->select->elements;
|
241
|
+
boolean8_t s;
|
242
|
+
n = 0;
|
243
|
+
a = 0;
|
244
|
+
for (i=0; i<elements; i++) {
|
245
|
+
ca_fetch_addr(ca->select, i, &s);
|
246
|
+
if ( s ) {
|
247
|
+
if ( addr == a++ ) {
|
248
|
+
n = i;
|
249
|
+
break;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
ca_store_addr(ca->parent, n, ptr);
|
254
|
+
}
|
255
|
+
|
256
|
+
static void
|
257
|
+
ca_select_func_store_index (void *ap, int32_t *idx, void *ptr)
|
258
|
+
{
|
259
|
+
ca_select_func_store_addr(ap, idx[0], ptr);
|
260
|
+
}
|
261
|
+
|
262
|
+
static void
|
263
|
+
ca_select_func_allocate (void *ap)
|
264
|
+
{
|
265
|
+
CASelect *ca = (CASelect *) ap;
|
266
|
+
ca_attach(ca->parent);
|
267
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
268
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
269
|
+
}
|
270
|
+
|
271
|
+
static void
|
272
|
+
ca_select_func_attach (void *ap)
|
273
|
+
{
|
274
|
+
CASelect *ca = (CASelect *) ap;
|
275
|
+
ca_attach(ca->parent);
|
276
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
277
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
278
|
+
ca_select_to_ptr(ca->parent, ca->select, ca->ptr);
|
279
|
+
}
|
280
|
+
|
281
|
+
static void
|
282
|
+
ca_select_func_sync (void *ap)
|
283
|
+
{
|
284
|
+
CASelect *ca = (CASelect *) ap;
|
285
|
+
ca_select_from_ptr(ca->parent, ca->select, ca->ptr);
|
286
|
+
ca_sync(ca->parent);
|
287
|
+
}
|
288
|
+
|
289
|
+
static void
|
290
|
+
ca_select_func_detach (void *ap)
|
291
|
+
{
|
292
|
+
CASelect *ca = (CASelect *) ap;
|
293
|
+
free(ca->ptr);
|
294
|
+
ca->ptr = NULL;
|
295
|
+
ca_detach(ca->parent);
|
296
|
+
}
|
297
|
+
|
298
|
+
static void
|
299
|
+
ca_select_func_copy_data (void *ap, void *ptr)
|
300
|
+
{
|
301
|
+
CASelect *ca = (CASelect *) ap;
|
302
|
+
ca_attach(ca->parent);
|
303
|
+
ca_select_to_ptr(ca->parent, ca->select, ptr);
|
304
|
+
ca_detach(ca->parent);
|
305
|
+
}
|
306
|
+
|
307
|
+
static void
|
308
|
+
ca_select_func_sync_data (void *ap, void *ptr)
|
309
|
+
{
|
310
|
+
CASelect *ca = (CASelect *) ap;
|
311
|
+
ca_attach(ca->parent);
|
312
|
+
ca_select_from_ptr(ca->parent, ca->select, ptr);
|
313
|
+
ca_sync(ca->parent);
|
314
|
+
ca_detach(ca->parent);
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
static void
|
319
|
+
ca_select_func_fill_data (void *ap, void *ptr)
|
320
|
+
{
|
321
|
+
CASelect *ca = (CASelect *) ap;
|
322
|
+
ca_attach(ca->parent);
|
323
|
+
ca_select_fill(ca->parent, ca->select, ptr);
|
324
|
+
ca_sync(ca->parent);
|
325
|
+
ca_detach(ca->parent);
|
326
|
+
}
|
327
|
+
|
328
|
+
static void
|
329
|
+
ca_select_func_create_mask (void *ap)
|
330
|
+
{
|
331
|
+
CASelect *ca = (CASelect *) ap;
|
332
|
+
ca_update_mask(ca->parent);
|
333
|
+
if ( ! ca->parent->mask ) {
|
334
|
+
ca_create_mask(ca->parent);
|
335
|
+
}
|
336
|
+
ca->mask = (CArray *) ca_select_new_share(ca->parent->mask, ca->select);
|
337
|
+
}
|
338
|
+
|
339
|
+
ca_operation_function_t ca_select_func = {
|
340
|
+
CA_OBJ_SELECT,
|
341
|
+
CA_VIRTUAL_ARRAY,
|
342
|
+
free_ca_select,
|
343
|
+
ca_select_func_clone,
|
344
|
+
ca_select_func_ptr_at_addr,
|
345
|
+
ca_select_func_ptr_at_index,
|
346
|
+
ca_select_func_fetch_addr,
|
347
|
+
ca_select_func_fetch_index,
|
348
|
+
ca_select_func_store_addr,
|
349
|
+
ca_select_func_store_index,
|
350
|
+
ca_select_func_allocate,
|
351
|
+
ca_select_func_attach,
|
352
|
+
ca_select_func_sync,
|
353
|
+
ca_select_func_detach,
|
354
|
+
ca_select_func_copy_data,
|
355
|
+
ca_select_func_sync_data,
|
356
|
+
ca_select_func_fill_data,
|
357
|
+
ca_select_func_create_mask,
|
358
|
+
};
|
359
|
+
|
360
|
+
/* ------------------------------------------------------------------- */
|
361
|
+
|
362
|
+
VALUE
|
363
|
+
rb_ca_select_new (VALUE cary, VALUE select)
|
364
|
+
{
|
365
|
+
volatile VALUE obj;
|
366
|
+
CArray *parent, *cselect;
|
367
|
+
CASelect *ca;
|
368
|
+
rb_check_carray_object(cary);
|
369
|
+
rb_check_carray_object(select);
|
370
|
+
Data_Get_Struct(cary, CArray, parent);
|
371
|
+
Data_Get_Struct(select, CArray, cselect);
|
372
|
+
ca = (CASelect *) ca_select_new(parent, cselect);
|
373
|
+
if ( ! ca ) {
|
374
|
+
return Qnil;
|
375
|
+
}
|
376
|
+
obj = ca_wrap_struct(ca);
|
377
|
+
rb_ca_set_parent(obj, cary);
|
378
|
+
rb_ca_data_type_inherit(obj, cary);
|
379
|
+
return obj;
|
380
|
+
}
|
381
|
+
|
382
|
+
VALUE
|
383
|
+
rb_ca_select_new_share (VALUE cary, VALUE select)
|
384
|
+
{
|
385
|
+
volatile VALUE obj;
|
386
|
+
CArray *parent, *cselect;
|
387
|
+
CASelect *ca;
|
388
|
+
rb_check_carray_object(cary);
|
389
|
+
rb_check_carray_object(select);
|
390
|
+
Data_Get_Struct(cary, CArray, parent);
|
391
|
+
Data_Get_Struct(select, CArray, cselect);
|
392
|
+
ca = (CASelect *) ca_select_new_share(parent, cselect);
|
393
|
+
if ( ! ca ) {
|
394
|
+
return Qnil;
|
395
|
+
}
|
396
|
+
obj = ca_wrap_struct(ca);
|
397
|
+
rb_ca_set_parent(obj, cary);
|
398
|
+
rb_ca_data_type_inherit(obj, cary);
|
399
|
+
rb_ivar_set(obj, rb_intern("referred_index"), select);
|
400
|
+
return obj;
|
401
|
+
}
|
402
|
+
|
403
|
+
/* -------------------------------------------------------------------- */
|
404
|
+
|
405
|
+
#define proc_select_to_ptr(type) \
|
406
|
+
{ \
|
407
|
+
type *p = (type *) ptr; \
|
408
|
+
type *q = (type *) ca->ptr; \
|
409
|
+
for (i=ca->elements; i; i--) { \
|
410
|
+
if ( *s ) { \
|
411
|
+
*p++ = *q; \
|
412
|
+
} \
|
413
|
+
q++; s++; \
|
414
|
+
} \
|
415
|
+
}
|
416
|
+
|
417
|
+
void
|
418
|
+
ca_select_to_ptr (CArray *ca, CArray *select, char *ptr)
|
419
|
+
{
|
420
|
+
boolean8_t *s = (boolean8_t*) select->ptr;
|
421
|
+
int32_t i;
|
422
|
+
|
423
|
+
switch ( ca->bytes ) {
|
424
|
+
case 1: proc_select_to_ptr(int8_t); break;
|
425
|
+
case 2: proc_select_to_ptr(int16_t); break;
|
426
|
+
case 4: proc_select_to_ptr(int32_t); break;
|
427
|
+
case 8: proc_select_to_ptr(float64_t); break;
|
428
|
+
default: {
|
429
|
+
char *p = ptr, *q = ca->ptr;
|
430
|
+
int32_t bytes = ca->bytes;
|
431
|
+
for (i=ca->elements; i; i--) {
|
432
|
+
if ( *s ) {
|
433
|
+
memcpy(q, p, bytes);
|
434
|
+
p+=bytes;
|
435
|
+
}
|
436
|
+
q+=bytes; s++;
|
437
|
+
}
|
438
|
+
break;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
}
|
443
|
+
|
444
|
+
/* ------------------------------------------------------------------- */
|
445
|
+
|
446
|
+
#define proc_select_from_ptr(type) \
|
447
|
+
{ \
|
448
|
+
type *p = (type *) ptr; \
|
449
|
+
type *q = (type *) ca->ptr; \
|
450
|
+
for (i=ca->elements; i; i--) { \
|
451
|
+
if ( *s ) { \
|
452
|
+
*q = *p++; \
|
453
|
+
} \
|
454
|
+
q++; s++; \
|
455
|
+
} \
|
456
|
+
}
|
457
|
+
|
458
|
+
void
|
459
|
+
ca_select_from_ptr (CArray *ca, CArray *select, char *ptr)
|
460
|
+
{
|
461
|
+
boolean8_t *s = (boolean8_t *) select->ptr;
|
462
|
+
int32_t i;
|
463
|
+
|
464
|
+
switch ( ca->bytes ) {
|
465
|
+
case 1: proc_select_from_ptr(int8_t); break;
|
466
|
+
case 2: proc_select_from_ptr(int16_t); break;
|
467
|
+
case 4: proc_select_from_ptr(int32_t); break;
|
468
|
+
case 8: proc_select_from_ptr(float64_t); break;
|
469
|
+
default: {
|
470
|
+
char *p = ptr;
|
471
|
+
char *q = ca->ptr;
|
472
|
+
int32_t bytes = ca->bytes;
|
473
|
+
for (i=ca->elements; i; i--) {
|
474
|
+
if ( *s ) {
|
475
|
+
memcpy(q, p, bytes);
|
476
|
+
p+=bytes;
|
477
|
+
}
|
478
|
+
q+=bytes; s++;
|
479
|
+
}
|
480
|
+
break;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
|
484
|
+
}
|
485
|
+
|
486
|
+
/* ------------------------------------------------------------------- */
|
487
|
+
|
488
|
+
#define proc_select_fill(type) \
|
489
|
+
{ \
|
490
|
+
type *q = (type *) ca->ptr; \
|
491
|
+
type v = *(type *) valp; \
|
492
|
+
for (i=ca->elements; i; i--) { \
|
493
|
+
if ( *s ) { \
|
494
|
+
*q = v; \
|
495
|
+
} \
|
496
|
+
q++; s++; \
|
497
|
+
} \
|
498
|
+
}
|
499
|
+
|
500
|
+
void
|
501
|
+
ca_select_fill (CArray *ca, CArray *select, char *valp)
|
502
|
+
{
|
503
|
+
boolean8_t *s = (boolean8_t *) select->ptr;
|
504
|
+
int32_t i;
|
505
|
+
|
506
|
+
switch ( ca->bytes ) {
|
507
|
+
case 1: proc_select_fill(int8_t); break;
|
508
|
+
case 2: proc_select_fill(int16_t); break;
|
509
|
+
case 4: proc_select_fill(int32_t); break;
|
510
|
+
case 8: proc_select_fill(float64_t); break;
|
511
|
+
default: {
|
512
|
+
char *q = ca->ptr;
|
513
|
+
int32_t bytes = ca->bytes;
|
514
|
+
for (i=ca->elements; i; i--) {
|
515
|
+
if ( *s ) {
|
516
|
+
memcpy(q, valp, bytes);
|
517
|
+
}
|
518
|
+
q+=bytes; s++;
|
519
|
+
}
|
520
|
+
break;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
}
|
525
|
+
|
526
|
+
/* ------------------------------------------------------------------- */
|
527
|
+
|
528
|
+
static VALUE
|
529
|
+
rb_cm_s_allocate (VALUE klass)
|
530
|
+
{
|
531
|
+
CASelect *ca;
|
532
|
+
return Data_Make_Struct(klass, CASelect, ca_mark, ca_free, ca);
|
533
|
+
}
|
534
|
+
|
535
|
+
static VALUE
|
536
|
+
rb_cm_initialize_copy (VALUE self, VALUE other)
|
537
|
+
{
|
538
|
+
CASelect *ca, *cs;
|
539
|
+
|
540
|
+
Data_Get_Struct(self, CASelect, ca);
|
541
|
+
Data_Get_Struct(other, CASelect, cs);
|
542
|
+
|
543
|
+
/* share select info */
|
544
|
+
ca_select_setup(ca, cs->parent, cs->select, 1);
|
545
|
+
|
546
|
+
return self;
|
547
|
+
}
|
548
|
+
|
549
|
+
void
|
550
|
+
Init_ca_obj_select ()
|
551
|
+
{
|
552
|
+
/* rb_cCASelect, CA_OBJ_SELECT are defined in rb_carray.c */
|
553
|
+
rb_define_const(rb_cObject, "CA_OBJ_SELECT", INT2NUM(CA_OBJ_SELECT));
|
554
|
+
|
555
|
+
rb_define_alloc_func(rb_cCASelect, rb_cm_s_allocate);
|
556
|
+
rb_define_method(rb_cCASelect, "initialize_copy", rb_cm_initialize_copy, 1);
|
557
|
+
}
|
558
|
+
|