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_iterator.c
ADDED
@@ -0,0 +1,630 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
carray_iterator.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_cCAIterator;
|
16
|
+
|
17
|
+
int8_t
|
18
|
+
ca_iter_rank (VALUE self)
|
19
|
+
{
|
20
|
+
int8_t rank;
|
21
|
+
if ( TYPE(self) == T_DATA ) {
|
22
|
+
CAIterator *it;
|
23
|
+
Data_Get_Struct(self, CAIterator, it);
|
24
|
+
rank = it->rank;
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
VALUE rrank = rb_ivar_get(self, rb_intern("@rank"));
|
28
|
+
rank = (int8_t) NUM2LONG(rrank);
|
29
|
+
}
|
30
|
+
return rank;
|
31
|
+
}
|
32
|
+
|
33
|
+
void
|
34
|
+
ca_iter_dim (VALUE self, int32_t *dim)
|
35
|
+
{
|
36
|
+
int i;
|
37
|
+
if ( TYPE(self) == T_DATA ) {
|
38
|
+
CAIterator *it;
|
39
|
+
Data_Get_Struct(self, CAIterator, it);
|
40
|
+
for (i=0; i<it->rank; i++) {
|
41
|
+
dim[i] = it->dim[i];
|
42
|
+
}
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
VALUE rrank = rb_ivar_get(self, rb_intern("@rank"));
|
46
|
+
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
47
|
+
int rank;
|
48
|
+
rank = NUM2LONG(rrank);
|
49
|
+
for (i=0; i<rank; i++) {
|
50
|
+
dim[i] = NUM2LONG(rb_ary_entry(rdim, i));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
int32_t
|
56
|
+
ca_iter_elements (VALUE self)
|
57
|
+
{
|
58
|
+
int i, elements;
|
59
|
+
if ( TYPE(self) == T_DATA ) {
|
60
|
+
CAIterator *it;
|
61
|
+
Data_Get_Struct(self, CAIterator, it);
|
62
|
+
elements = 1;
|
63
|
+
for (i=0; i<it->rank; i++) {
|
64
|
+
elements *= it->dim[i];
|
65
|
+
}
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
VALUE rrank = rb_ivar_get(self, rb_intern("@rank"));
|
69
|
+
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
70
|
+
int rank = NUM2LONG(rrank);
|
71
|
+
elements = 1;
|
72
|
+
for (i=0; i<rank; i++) {
|
73
|
+
elements *= NUM2LONG(rb_ary_entry(rdim, i));
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return elements;
|
77
|
+
}
|
78
|
+
|
79
|
+
VALUE
|
80
|
+
ca_iter_reference (VALUE self)
|
81
|
+
{
|
82
|
+
return rb_ivar_get(self, rb_intern("@reference"));
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE
|
86
|
+
ca_iter_kernel_at_addr (VALUE self, int32_t addr, VALUE rref)
|
87
|
+
{
|
88
|
+
volatile VALUE rker;
|
89
|
+
if ( TYPE(self) == T_DATA ) {
|
90
|
+
CAIterator *it;
|
91
|
+
CArray *ref, *ker;
|
92
|
+
Data_Get_Struct(self, CAIterator, it);
|
93
|
+
Data_Get_Struct(rref, CArray, ref);
|
94
|
+
ker = it->kernel_at_addr(it, addr, ref);
|
95
|
+
rker = ca_wrap_struct(ker);
|
96
|
+
rb_ca_data_type_inherit(rker, rref);
|
97
|
+
rb_ca_set_parent(rker, rref);
|
98
|
+
}
|
99
|
+
else {
|
100
|
+
rker = rb_funcall(self, rb_intern("kernel_at_addr"), 2,
|
101
|
+
INT2NUM(addr), rref);
|
102
|
+
}
|
103
|
+
return rker;
|
104
|
+
}
|
105
|
+
|
106
|
+
VALUE
|
107
|
+
ca_iter_kernel_at_index (VALUE self, int32_t *idx, VALUE rref)
|
108
|
+
{
|
109
|
+
VALUE rker;
|
110
|
+
if ( TYPE(self) == T_DATA ) {
|
111
|
+
CAIterator *it;
|
112
|
+
CArray *ref, *ker;
|
113
|
+
Data_Get_Struct(self, CAIterator, it);
|
114
|
+
Data_Get_Struct(rref, CArray, ref);
|
115
|
+
ker = it->kernel_at_index(it, idx, ref);
|
116
|
+
rker = ca_wrap_struct(ker);
|
117
|
+
rb_ca_data_type_inherit(rker, rref);
|
118
|
+
rb_ca_set_parent(rker, rref);
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
VALUE vidx;
|
122
|
+
int8_t rank = ca_iter_rank(self);
|
123
|
+
int i;
|
124
|
+
vidx = rb_ary_new2(rank);
|
125
|
+
for (i=0; i<rank; i++) {
|
126
|
+
rb_ary_store(vidx, i, INT2NUM(idx[i]));
|
127
|
+
}
|
128
|
+
rker = rb_funcall(self, rb_intern("kernel_at_index"), 2,
|
129
|
+
vidx, rref);
|
130
|
+
}
|
131
|
+
return rker;
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE
|
135
|
+
ca_iter_kernel_move_to_addr (VALUE self, int32_t addr, VALUE rref)
|
136
|
+
{
|
137
|
+
if ( TYPE(self) == T_DATA ) {
|
138
|
+
CAIterator *it;
|
139
|
+
CArray *ker;
|
140
|
+
Data_Get_Struct(self, CAIterator, it);
|
141
|
+
Data_Get_Struct(rref, CArray, ker);
|
142
|
+
it->kernel_move_to_addr(it, addr, ker);
|
143
|
+
}
|
144
|
+
else {
|
145
|
+
rb_funcall(self, rb_intern("kernel_move_to_addr"), 2,
|
146
|
+
INT2NUM(addr), rref);
|
147
|
+
}
|
148
|
+
return rref;
|
149
|
+
}
|
150
|
+
|
151
|
+
VALUE
|
152
|
+
ca_iter_kernel_move_to_index (VALUE self, int32_t *idx, VALUE rref)
|
153
|
+
{
|
154
|
+
VALUE rker;
|
155
|
+
if ( TYPE(self) == T_DATA ) {
|
156
|
+
CAIterator *it;
|
157
|
+
CArray *ker;
|
158
|
+
Data_Get_Struct(self, CAIterator, it);
|
159
|
+
Data_Get_Struct(rref, CArray, ker);
|
160
|
+
it->kernel_move_to_index(it, idx, ker);
|
161
|
+
}
|
162
|
+
else {
|
163
|
+
VALUE vidx;
|
164
|
+
int8_t rank = ca_iter_rank(self);
|
165
|
+
int i;
|
166
|
+
vidx = rb_ary_new2(rank);
|
167
|
+
for (i=0; i<rank; i++) {
|
168
|
+
rb_ary_store(vidx, i, INT2NUM(idx[i]));
|
169
|
+
}
|
170
|
+
rker = rb_funcall(self, rb_intern("kernel_move_to_index"), 2,
|
171
|
+
vidx, rref);
|
172
|
+
}
|
173
|
+
return rref;
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
VALUE
|
178
|
+
ca_iter_prepare_output (VALUE self, VALUE rtype, VALUE rbytes)
|
179
|
+
{
|
180
|
+
volatile VALUE obj;
|
181
|
+
CArray *co;
|
182
|
+
int8_t data_type;
|
183
|
+
int32_t bytes;
|
184
|
+
int i;
|
185
|
+
|
186
|
+
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
187
|
+
|
188
|
+
if ( TYPE(self) == T_DATA ) {
|
189
|
+
CAIterator *it;
|
190
|
+
Data_Get_Struct(self, CAIterator, it);
|
191
|
+
co = carray_new_safe(data_type, it->rank, it->dim, bytes, NULL);
|
192
|
+
}
|
193
|
+
else {
|
194
|
+
VALUE rrank = rb_ivar_get(self, rb_intern("@rank"));
|
195
|
+
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
196
|
+
int8_t rank = NUM2LONG(rrank);
|
197
|
+
int32_t dim[CA_RANK_MAX];
|
198
|
+
for (i=0; i<rank; i++) {
|
199
|
+
dim[i] = NUM2LONG(rb_ary_entry(rdim, i));
|
200
|
+
}
|
201
|
+
co = carray_new_safe(data_type, rank, dim, bytes, NULL);
|
202
|
+
}
|
203
|
+
|
204
|
+
obj = ca_wrap_struct(co);
|
205
|
+
rb_ca_data_type_import(obj, rtype);
|
206
|
+
|
207
|
+
return obj;
|
208
|
+
}
|
209
|
+
|
210
|
+
/* -------------------------------------------------------------------- */
|
211
|
+
|
212
|
+
/* rdoc:
|
213
|
+
class CAIterator
|
214
|
+
def rank
|
215
|
+
end
|
216
|
+
end
|
217
|
+
*/
|
218
|
+
|
219
|
+
VALUE
|
220
|
+
rb_ca_iter_rank (VALUE self)
|
221
|
+
{
|
222
|
+
return LONG2NUM(ca_iter_rank(self));
|
223
|
+
}
|
224
|
+
|
225
|
+
/* rdoc:
|
226
|
+
class CAIterator
|
227
|
+
def dim
|
228
|
+
end
|
229
|
+
end
|
230
|
+
*/
|
231
|
+
|
232
|
+
VALUE
|
233
|
+
rb_ca_iter_dim (VALUE self)
|
234
|
+
{
|
235
|
+
VALUE rdim;
|
236
|
+
int32_t dim[CA_RANK_MAX];
|
237
|
+
int8_t rank = ca_iter_rank(self);
|
238
|
+
int i;
|
239
|
+
ca_iter_dim(self, dim);
|
240
|
+
rdim = rb_ary_new2(rank);
|
241
|
+
for (i=0; i<rank; i++) {
|
242
|
+
rb_ary_store(rdim, i, INT2NUM(dim[i]));
|
243
|
+
}
|
244
|
+
return rdim;
|
245
|
+
}
|
246
|
+
|
247
|
+
/* rdoc:
|
248
|
+
class CAIterator
|
249
|
+
def elements
|
250
|
+
end
|
251
|
+
end
|
252
|
+
*/
|
253
|
+
|
254
|
+
VALUE
|
255
|
+
rb_ca_iter_elements (VALUE self)
|
256
|
+
{
|
257
|
+
return LONG2NUM(ca_iter_elements(self));
|
258
|
+
}
|
259
|
+
|
260
|
+
/* rdoc:
|
261
|
+
class CAIterator
|
262
|
+
def reference
|
263
|
+
end
|
264
|
+
end
|
265
|
+
*/
|
266
|
+
|
267
|
+
VALUE
|
268
|
+
rb_ca_iter_reference (VALUE self)
|
269
|
+
{
|
270
|
+
return ca_iter_reference(self);
|
271
|
+
}
|
272
|
+
|
273
|
+
/* rdoc:
|
274
|
+
class CAIterator
|
275
|
+
def kernel_at_addr
|
276
|
+
end
|
277
|
+
end
|
278
|
+
*/
|
279
|
+
|
280
|
+
VALUE
|
281
|
+
rb_ca_iter_kernel_at_addr (int argc, VALUE *argv, VALUE self)
|
282
|
+
{
|
283
|
+
volatile VALUE raddr, rcarray;
|
284
|
+
rb_scan_args(argc, argv, "11", &raddr, &rcarray);
|
285
|
+
if ( NIL_P(rcarray) ) {
|
286
|
+
rcarray = rb_ca_iter_reference(self);
|
287
|
+
}
|
288
|
+
return ca_iter_kernel_at_addr(self, NUM2LONG(raddr), rcarray);
|
289
|
+
}
|
290
|
+
|
291
|
+
/* rdoc:
|
292
|
+
class CAIterator
|
293
|
+
def kernel_at_index
|
294
|
+
end
|
295
|
+
end
|
296
|
+
*/
|
297
|
+
|
298
|
+
VALUE
|
299
|
+
rb_ca_iter_kernel_at_index (int argc, VALUE *argv, VALUE self)
|
300
|
+
{
|
301
|
+
volatile VALUE rindex, rcarray;
|
302
|
+
int32_t idx[CA_RANK_MAX];
|
303
|
+
int8_t rank = ca_iter_rank(self);
|
304
|
+
int i;
|
305
|
+
|
306
|
+
rb_scan_args(argc, argv, "11", &rindex, &rcarray);
|
307
|
+
|
308
|
+
if ( NIL_P(rcarray) ) {
|
309
|
+
rcarray = rb_ca_iter_reference(self);
|
310
|
+
}
|
311
|
+
|
312
|
+
for (i=0; i<rank; i++) {
|
313
|
+
idx[i] = NUM2LONG(rb_ary_entry(rindex, i));
|
314
|
+
}
|
315
|
+
|
316
|
+
return ca_iter_kernel_at_index(self, idx, rcarray);
|
317
|
+
}
|
318
|
+
|
319
|
+
/* rdoc:
|
320
|
+
class CAIterator
|
321
|
+
def kernel_move_to_addr
|
322
|
+
end
|
323
|
+
end
|
324
|
+
*/
|
325
|
+
|
326
|
+
VALUE
|
327
|
+
rb_ca_iter_kernel_move_to_addr (VALUE self, VALUE raddr, VALUE rker)
|
328
|
+
{
|
329
|
+
return ca_iter_kernel_move_to_addr(self, NUM2LONG(raddr), rker);
|
330
|
+
}
|
331
|
+
|
332
|
+
/* rdoc:
|
333
|
+
class CAIterator
|
334
|
+
def kernel_move_to_index
|
335
|
+
end
|
336
|
+
end
|
337
|
+
*/
|
338
|
+
|
339
|
+
VALUE
|
340
|
+
rb_ca_iter_kernel_move_to_index (VALUE self, VALUE rindex, VALUE rker)
|
341
|
+
{
|
342
|
+
int32_t idx[CA_RANK_MAX];
|
343
|
+
int8_t rank = ca_iter_rank(self);
|
344
|
+
int i;
|
345
|
+
|
346
|
+
for (i=0; i<rank; i++) {
|
347
|
+
idx[i] = NUM2LONG(rb_ary_entry(rindex, i));
|
348
|
+
}
|
349
|
+
|
350
|
+
return ca_iter_kernel_move_to_index(self, idx, rker);
|
351
|
+
}
|
352
|
+
|
353
|
+
/* rdoc:
|
354
|
+
class CAIterator
|
355
|
+
def prepare_output
|
356
|
+
end
|
357
|
+
end
|
358
|
+
*/
|
359
|
+
|
360
|
+
VALUE
|
361
|
+
rb_ca_iter_prepare_output (int argc, VALUE *argv, VALUE self)
|
362
|
+
{
|
363
|
+
VALUE rtype, ropt, rbytes = Qnil;
|
364
|
+
|
365
|
+
rb_scan_args(argc, argv, "11", &rtype, &ropt);
|
366
|
+
rb_scan_options(ropt, "bytes", &rbytes);
|
367
|
+
|
368
|
+
return ca_iter_prepare_output(self, rtype, rbytes);
|
369
|
+
}
|
370
|
+
|
371
|
+
/* -------------------------------------------------------------------- */
|
372
|
+
|
373
|
+
/* rdoc:
|
374
|
+
class CAIterator
|
375
|
+
def calculate
|
376
|
+
end
|
377
|
+
end
|
378
|
+
*/
|
379
|
+
|
380
|
+
VALUE
|
381
|
+
rb_ca_iter_calculate (int argc, VALUE *argv, VALUE self)
|
382
|
+
{
|
383
|
+
volatile VALUE rtype, rbytes, routput, rref, rker, rout;
|
384
|
+
CArray *co, *cr, *ck;
|
385
|
+
int32_t elements;
|
386
|
+
int8_t data_type;
|
387
|
+
int32_t bytes;
|
388
|
+
int i;
|
389
|
+
|
390
|
+
if ( argc < 1 ) {
|
391
|
+
rb_raise(rb_eArgError, "invalid # of arguments");
|
392
|
+
}
|
393
|
+
|
394
|
+
elements = ca_iter_elements(self);
|
395
|
+
|
396
|
+
rref = ca_iter_reference(self);
|
397
|
+
Data_Get_Struct(rref, CArray, cr);
|
398
|
+
|
399
|
+
if ( NIL_P(argv[0]) ) {
|
400
|
+
rtype = INT2NUM(cr->data_type);
|
401
|
+
rbytes = INT2NUM(cr->bytes);
|
402
|
+
}
|
403
|
+
else {
|
404
|
+
rb_ca_guess_type_and_bytes(argv[0], Qnil, &data_type, &bytes);
|
405
|
+
rtype = INT2NUM(data_type);
|
406
|
+
rbytes = INT2NUM(bytes);
|
407
|
+
}
|
408
|
+
argc--;
|
409
|
+
argv++;
|
410
|
+
|
411
|
+
routput = ca_iter_prepare_output(self, rtype, rbytes);
|
412
|
+
Data_Get_Struct(routput, CArray, co);
|
413
|
+
|
414
|
+
ca_attach(cr);
|
415
|
+
|
416
|
+
if ( rb_const_get(CLASS_OF(self), rb_intern("UNIFORM_KERNEL")) ) {
|
417
|
+
|
418
|
+
rker = ca_iter_kernel_at_addr(self, 0, rref);
|
419
|
+
|
420
|
+
Data_Get_Struct(rker, CArray, ck);
|
421
|
+
ca_attach(ck);
|
422
|
+
|
423
|
+
if ( rb_block_given_p() ) {
|
424
|
+
for (i=0; i<elements; i++) {
|
425
|
+
ca_iter_kernel_move_to_addr(self, i, rker);
|
426
|
+
ca_update(ck);
|
427
|
+
rout = rb_yield(rker);
|
428
|
+
rb_ca_store_addr(routput, i, rout);
|
429
|
+
}
|
430
|
+
}
|
431
|
+
else {
|
432
|
+
if ( argc < 1 ) {
|
433
|
+
rb_raise(rb_eArgError, "invalid # of arguments");
|
434
|
+
}
|
435
|
+
for (i=0; i<elements; i++) {
|
436
|
+
ca_iter_kernel_move_to_addr(self, i, rker);
|
437
|
+
ca_update(ck);
|
438
|
+
rout = rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]);
|
439
|
+
rb_ca_store_addr(routput, i, rout);
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
ca_detach(ck);
|
444
|
+
}
|
445
|
+
else {
|
446
|
+
|
447
|
+
if ( rb_block_given_p() ) {
|
448
|
+
for (i=0; i<elements; i++) {
|
449
|
+
rker = ca_iter_kernel_at_addr(self, i, rref);
|
450
|
+
rout = rb_yield(rker);
|
451
|
+
rb_ca_store_addr(routput, i, rout);
|
452
|
+
}
|
453
|
+
}
|
454
|
+
else {
|
455
|
+
if ( argc < 1 ) {
|
456
|
+
rb_raise(rb_eArgError, "invalid # of arguments");
|
457
|
+
}
|
458
|
+
for (i=0; i<elements; i++) {
|
459
|
+
rker = ca_iter_kernel_at_addr(self, i, rref);
|
460
|
+
rout = rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]);
|
461
|
+
rb_ca_store_addr(routput, i, rout);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
ca_detach(cr);
|
468
|
+
|
469
|
+
return routput;
|
470
|
+
}
|
471
|
+
|
472
|
+
/* rdoc:
|
473
|
+
class CAIterator
|
474
|
+
def filter
|
475
|
+
end
|
476
|
+
end
|
477
|
+
*/
|
478
|
+
|
479
|
+
VALUE
|
480
|
+
rb_ca_iter_filter (int argc, VALUE *argv, VALUE self)
|
481
|
+
{
|
482
|
+
volatile VALUE routput, rref, rker, rout;
|
483
|
+
CArray *co, *cr, *ck, *cq;
|
484
|
+
int32_t elements;
|
485
|
+
int8_t data_type;
|
486
|
+
int i;
|
487
|
+
|
488
|
+
if ( argc < 2 ) {
|
489
|
+
rb_raise(rb_eArgError, "invalid # of arguments");
|
490
|
+
}
|
491
|
+
|
492
|
+
elements = ca_iter_elements(self);
|
493
|
+
rref = ca_iter_reference(self);
|
494
|
+
|
495
|
+
Data_Get_Struct(rref, CArray, cr);
|
496
|
+
|
497
|
+
/* FIXME: check data_type validity */
|
498
|
+
|
499
|
+
data_type = NIL_P(argv[0]) ? cr->data_type : rb_ca_guess_type(argv[0]);
|
500
|
+
argc--;
|
501
|
+
argv++;
|
502
|
+
|
503
|
+
co = carray_new(data_type, cr->rank, cr->dim, 0, NULL);
|
504
|
+
routput = ca_wrap_struct(co);
|
505
|
+
|
506
|
+
if ( NIL_P(argv[0]) ) {
|
507
|
+
rb_ca_data_type_inherit(routput, rref);
|
508
|
+
}
|
509
|
+
|
510
|
+
ca_attach(cr);
|
511
|
+
|
512
|
+
if ( rb_const_get(CLASS_OF(self), rb_intern("UNIFORM_KERNEL")) ) {
|
513
|
+
|
514
|
+
rker = ca_iter_kernel_at_addr(self, 0, rref);
|
515
|
+
Data_Get_Struct(rker, CArray, ck);
|
516
|
+
ca_allocate(ck);
|
517
|
+
|
518
|
+
rout = ca_iter_kernel_at_addr(self, 0, routput);
|
519
|
+
Data_Get_Struct(rker, CArray, cq);
|
520
|
+
ca_allocate(cq);
|
521
|
+
|
522
|
+
for (i=0; i<elements; i++) {
|
523
|
+
ca_iter_kernel_move_to_addr(self, i, rker);
|
524
|
+
ca_iter_kernel_move_to_addr(self, i, rout);
|
525
|
+
ca_update(ck);
|
526
|
+
rb_funcall(rout, rb_intern("[]="), 1,
|
527
|
+
rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]));
|
528
|
+
ca_sync(cq);
|
529
|
+
}
|
530
|
+
|
531
|
+
ca_detach_n(2, ck, cq);
|
532
|
+
|
533
|
+
}
|
534
|
+
else {
|
535
|
+
|
536
|
+
for (i=0; i<elements; i++) {
|
537
|
+
rker = ca_iter_kernel_at_addr(self, i, rref);
|
538
|
+
rout = ca_iter_kernel_at_addr(self, i, routput);
|
539
|
+
rb_funcall(rout, rb_intern("[]="), 1,
|
540
|
+
rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]));
|
541
|
+
}
|
542
|
+
|
543
|
+
}
|
544
|
+
|
545
|
+
ca_detach(cr);
|
546
|
+
return routput;
|
547
|
+
}
|
548
|
+
|
549
|
+
/* rdoc:
|
550
|
+
class CAIterator
|
551
|
+
def evaluate
|
552
|
+
end
|
553
|
+
end
|
554
|
+
*/
|
555
|
+
|
556
|
+
VALUE
|
557
|
+
rb_ca_iter_evaluate (int argc, VALUE *argv, VALUE self)
|
558
|
+
{
|
559
|
+
volatile VALUE rref, rker;
|
560
|
+
CArray *cr, *ck;
|
561
|
+
int32_t elements;
|
562
|
+
int i;
|
563
|
+
|
564
|
+
elements = ca_iter_elements(self);
|
565
|
+
rref = ca_iter_reference(self);
|
566
|
+
|
567
|
+
Data_Get_Struct(rref, CArray, cr);
|
568
|
+
|
569
|
+
ca_attach(cr);
|
570
|
+
|
571
|
+
if ( rb_const_get(CLASS_OF(self), rb_intern("UNIFORM_KERNEL")) ) {
|
572
|
+
|
573
|
+
rker = ca_iter_kernel_at_addr(self, 0, rref);
|
574
|
+
|
575
|
+
Data_Get_Struct(rker, CArray, ck);
|
576
|
+
|
577
|
+
ca_attach(ck);
|
578
|
+
|
579
|
+
for (i=0; i<elements; i++) {
|
580
|
+
ca_iter_kernel_move_to_addr(self, i, rker);
|
581
|
+
ca_update(ck);
|
582
|
+
rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]);
|
583
|
+
}
|
584
|
+
|
585
|
+
ca_detach(ck);
|
586
|
+
}
|
587
|
+
else {
|
588
|
+
|
589
|
+
for (i=0; i<elements; i++) {
|
590
|
+
rker = ca_iter_kernel_at_addr(self, i, rref);
|
591
|
+
rb_funcall2(rker, SYM2ID(argv[0]), argc-1, &argv[1]);
|
592
|
+
}
|
593
|
+
|
594
|
+
}
|
595
|
+
|
596
|
+
ca_sync(cr);
|
597
|
+
ca_detach(cr);
|
598
|
+
|
599
|
+
return self;
|
600
|
+
}
|
601
|
+
|
602
|
+
|
603
|
+
void
|
604
|
+
Init_carray_iterator ()
|
605
|
+
{
|
606
|
+
rb_cCAIterator = rb_define_class("CAIterator", rb_cObject);
|
607
|
+
|
608
|
+
rb_define_method(rb_cCAIterator, "rank", rb_ca_iter_rank, 0);
|
609
|
+
rb_define_method(rb_cCAIterator, "dim", rb_ca_iter_dim, 0);
|
610
|
+
rb_define_method(rb_cCAIterator, "elements", rb_ca_iter_elements, 0);
|
611
|
+
rb_define_method(rb_cCAIterator, "reference", rb_ca_iter_reference, 0);
|
612
|
+
|
613
|
+
rb_define_method(rb_cCAIterator, "kernel_at_addr",
|
614
|
+
rb_ca_iter_kernel_at_addr, -1);
|
615
|
+
rb_define_method(rb_cCAIterator, "kernel_at_index",
|
616
|
+
rb_ca_iter_kernel_at_index, -1);
|
617
|
+
rb_define_method(rb_cCAIterator, "kernel_move_to_addr",
|
618
|
+
rb_ca_iter_kernel_move_to_addr, 2);
|
619
|
+
rb_define_method(rb_cCAIterator, "kernel_move_to_index",
|
620
|
+
rb_ca_iter_kernel_move_to_index, 2);
|
621
|
+
rb_define_method(rb_cCAIterator, "prepare_output",
|
622
|
+
rb_ca_iter_prepare_output, -1);
|
623
|
+
|
624
|
+
rb_define_method(rb_cCAIterator, "calculate", rb_ca_iter_calculate, -1);
|
625
|
+
rb_define_method(rb_cCAIterator, "filter", rb_ca_iter_filter, -1);
|
626
|
+
rb_define_method(rb_cCAIterator, "evaluate", rb_ca_iter_evaluate, -1);
|
627
|
+
|
628
|
+
}
|
629
|
+
|
630
|
+
|