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_loop.c
ADDED
@@ -0,0 +1,462 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
carray_loop.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
|
+
static VALUE
|
16
|
+
rb_ca_s_each_index_internal (int rank, VALUE *dim, uint8_t irank, VALUE ridx)
|
17
|
+
{
|
18
|
+
volatile VALUE ret = Qnil;
|
19
|
+
int32_t is_leaf = (irank == rank - 1);
|
20
|
+
int32_t i;
|
21
|
+
|
22
|
+
if ( NIL_P(dim[irank]) ) {
|
23
|
+
rb_ary_store(ridx, irank, Qnil);
|
24
|
+
if ( is_leaf ) {
|
25
|
+
ret = rb_yield_splat(rb_obj_clone(ridx));
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
ret = rb_ca_s_each_index_internal(rank, dim, irank+1, ridx);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
for (i=0; i<NUM2LONG(dim[irank]); i++) {
|
33
|
+
rb_ary_store(ridx, irank, INT2NUM(i));
|
34
|
+
if ( is_leaf ) {
|
35
|
+
ret = rb_yield_splat(rb_obj_clone(ridx));
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
ret = rb_ca_s_each_index_internal(rank, dim, irank+1, ridx);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
return ret;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* rdoc:
|
47
|
+
# Iterates with the multi-dimensional indeces for the given
|
48
|
+
# dimension numbers.
|
49
|
+
#
|
50
|
+
# CArray.each_index(3,2){|i,j| print "(#{i} #{j}) " }
|
51
|
+
#
|
52
|
+
# produces:
|
53
|
+
#
|
54
|
+
# (0 0) (0 1) (1 0) (1 1) (2 0) (2 1) (3 0) (3 1)
|
55
|
+
#
|
56
|
+
def CArray.each_index(*argv) # :yields: i0, i1, ...
|
57
|
+
end
|
58
|
+
*/
|
59
|
+
|
60
|
+
static VALUE
|
61
|
+
rb_ca_s_each_index (int rank, VALUE *dim, VALUE self)
|
62
|
+
{
|
63
|
+
volatile VALUE ridx = rb_ary_new2(rank);
|
64
|
+
#if RUBY_VERSION_CODE >= 190
|
65
|
+
RETURN_ENUMERATOR(self, rank, dim);
|
66
|
+
#endif
|
67
|
+
return rb_ca_s_each_index_internal(rank, dim, 0, ridx);
|
68
|
+
}
|
69
|
+
|
70
|
+
/* ------------------------------------------------------------------- */
|
71
|
+
|
72
|
+
/* rdoc:
|
73
|
+
class CArray
|
74
|
+
#
|
75
|
+
def each # :yields: v
|
76
|
+
end
|
77
|
+
end
|
78
|
+
*/
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
rb_ca_each (VALUE self)
|
82
|
+
{
|
83
|
+
volatile VALUE ret = Qnil;
|
84
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
85
|
+
int32_t i;
|
86
|
+
#if RUBY_VERSION_CODE >= 190
|
87
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
88
|
+
#endif
|
89
|
+
for (i=0; i<elements; i++) {
|
90
|
+
ret = rb_yield(rb_ca_fetch_addr(self, i));
|
91
|
+
}
|
92
|
+
return ret;
|
93
|
+
}
|
94
|
+
|
95
|
+
/* rdoc:
|
96
|
+
class CArray
|
97
|
+
#
|
98
|
+
def each_with_addr # :yields: v, addr
|
99
|
+
end
|
100
|
+
end
|
101
|
+
*/
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
rb_ca_each_with_addr (VALUE self)
|
105
|
+
{
|
106
|
+
volatile VALUE ret = Qnil;
|
107
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
108
|
+
int32_t i;
|
109
|
+
#if RUBY_VERSION_CODE >= 190
|
110
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
111
|
+
#endif
|
112
|
+
for (i=0; i<elements; i++) {
|
113
|
+
ret = rb_yield_values(2, rb_ca_fetch_addr(self, i), INT2NUM(i));
|
114
|
+
}
|
115
|
+
return ret;
|
116
|
+
}
|
117
|
+
|
118
|
+
/* rdoc:
|
119
|
+
class CArray
|
120
|
+
#
|
121
|
+
def each_addr() # :yields: addr
|
122
|
+
end
|
123
|
+
end
|
124
|
+
*/
|
125
|
+
|
126
|
+
static VALUE
|
127
|
+
rb_ca_each_addr (VALUE self)
|
128
|
+
{
|
129
|
+
volatile VALUE ret = Qnil;
|
130
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
131
|
+
int32_t i;
|
132
|
+
#if RUBY_VERSION_CODE >= 190
|
133
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
134
|
+
#endif
|
135
|
+
for (i=0; i<elements; i++) {
|
136
|
+
ret = rb_yield(LONG2NUM(i));
|
137
|
+
}
|
138
|
+
return ret;
|
139
|
+
}
|
140
|
+
|
141
|
+
static VALUE
|
142
|
+
rb_ca_each_index_internal (VALUE self, int8_t level, VALUE ridx)
|
143
|
+
{
|
144
|
+
volatile VALUE ret = Qnil;
|
145
|
+
CArray *ca;
|
146
|
+
int32_t i;
|
147
|
+
Data_Get_Struct(self, CArray, ca);
|
148
|
+
if ( level == ca->rank - 1 ) {
|
149
|
+
for (i=0; i<ca->dim[level]; i++) {
|
150
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
151
|
+
ret = rb_yield_splat(rb_obj_clone(ridx));
|
152
|
+
}
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
for (i=0; i<ca->dim[level]; i++) {
|
156
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
157
|
+
ret = rb_ca_each_index_internal(self, level+1, ridx);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return ret;
|
161
|
+
}
|
162
|
+
|
163
|
+
/* rdoc:
|
164
|
+
class CArray
|
165
|
+
# Iterates with the multi-dimensional indeces for the dimension of <i>ca</i>.
|
166
|
+
#
|
167
|
+
# CArray.int(3,2).each_index(){|i,j| print "(#{i} #{j}) " }
|
168
|
+
#
|
169
|
+
# <em>produces:</em>
|
170
|
+
#
|
171
|
+
# (0 0) (0 1) (1 0) (1 1) (2 0) (2 1) (3 0) (3 1)
|
172
|
+
#
|
173
|
+
def each_index # :yields: i0, i1, ...
|
174
|
+
end
|
175
|
+
end
|
176
|
+
*/
|
177
|
+
|
178
|
+
static VALUE
|
179
|
+
rb_ca_each_index (VALUE self)
|
180
|
+
{
|
181
|
+
volatile VALUE ridx;
|
182
|
+
int8_t rank = NUM2INT(rb_ca_rank(self));
|
183
|
+
ridx = rb_ary_new2(rank);
|
184
|
+
#if RUBY_VERSION_CODE >= 190
|
185
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
186
|
+
#endif
|
187
|
+
return rb_ca_each_index_internal(self, 0, ridx);
|
188
|
+
}
|
189
|
+
|
190
|
+
/* rdoc:
|
191
|
+
class CArray
|
192
|
+
#
|
193
|
+
def map! # :yields: v
|
194
|
+
end
|
195
|
+
end
|
196
|
+
*/
|
197
|
+
|
198
|
+
static VALUE
|
199
|
+
rb_ca_map_bang (VALUE self)
|
200
|
+
{
|
201
|
+
volatile VALUE obj;
|
202
|
+
CArray *ca;
|
203
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
204
|
+
int32_t i;
|
205
|
+
#if RUBY_VERSION_CODE >= 190
|
206
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
207
|
+
#endif
|
208
|
+
rb_ca_modify(self);
|
209
|
+
Data_Get_Struct(self, CArray, ca);
|
210
|
+
ca_attach(ca);
|
211
|
+
for (i=0; i<elements; i++) {
|
212
|
+
obj = rb_yield(rb_ca_fetch_addr(self, i));
|
213
|
+
rb_ca_store_addr(self, i, obj);
|
214
|
+
}
|
215
|
+
ca_sync(ca);
|
216
|
+
ca_detach(ca);
|
217
|
+
return self;
|
218
|
+
}
|
219
|
+
|
220
|
+
static VALUE
|
221
|
+
rb_ca_each_with_index_internal (VALUE self,
|
222
|
+
int8_t level, int32_t *idx, VALUE ridx)
|
223
|
+
{
|
224
|
+
volatile VALUE ret = Qnil;
|
225
|
+
CArray *ca;
|
226
|
+
int32_t i;
|
227
|
+
Data_Get_Struct(self, CArray, ca);
|
228
|
+
if ( level == ca->rank - 1 ) {
|
229
|
+
for (i=0; i<ca->dim[level]; i++) {
|
230
|
+
idx[level] = i;
|
231
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
232
|
+
ret = rb_yield_values(2, rb_ca_fetch_index(self, idx),
|
233
|
+
rb_obj_clone(ridx));
|
234
|
+
}
|
235
|
+
}
|
236
|
+
else {
|
237
|
+
for (i=0; i<ca->dim[level]; i++) {
|
238
|
+
idx[level] = i;
|
239
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
240
|
+
ret = rb_ca_each_with_index_internal(self, level+1, idx, ridx);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
return ret;
|
244
|
+
}
|
245
|
+
|
246
|
+
/* rdoc:
|
247
|
+
class CArray
|
248
|
+
#
|
249
|
+
def each_with_index # :yields: v, idx
|
250
|
+
end
|
251
|
+
end
|
252
|
+
*/
|
253
|
+
|
254
|
+
static VALUE
|
255
|
+
rb_ca_each_with_index (VALUE self)
|
256
|
+
{
|
257
|
+
volatile VALUE ridx, ret;
|
258
|
+
int32_t idx[CA_RANK_MAX];
|
259
|
+
int8_t rank = NUM2INT(rb_ca_rank(self));
|
260
|
+
#if RUBY_VERSION_CODE >= 190
|
261
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
262
|
+
#endif
|
263
|
+
rb_ca_modify(self);
|
264
|
+
ridx = rb_ary_new2(rank);
|
265
|
+
ret = rb_ca_each_with_index_internal(self, 0, idx, ridx);
|
266
|
+
return ret;
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
static void
|
271
|
+
rb_ca_map_with_index_bang_internal (VALUE self,
|
272
|
+
int8_t level, int32_t *idx, VALUE ridx)
|
273
|
+
{
|
274
|
+
CArray *ca;
|
275
|
+
int32_t i;
|
276
|
+
Data_Get_Struct(self, CArray, ca);
|
277
|
+
if ( level == ca->rank - 1 ) {
|
278
|
+
volatile VALUE obj;
|
279
|
+
for (i=0; i<ca->dim[level]; i++) {
|
280
|
+
idx[level] = i;
|
281
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
282
|
+
obj = rb_yield_values(2, rb_ca_fetch_index(self, idx),
|
283
|
+
rb_obj_clone(ridx));
|
284
|
+
rb_ca_store_index(self, idx, obj);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
else {
|
288
|
+
for (i=0; i<ca->dim[level]; i++) {
|
289
|
+
idx[level] = i;
|
290
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
291
|
+
rb_ca_map_with_index_bang_internal(self, level+1, idx, ridx);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
/* rdoc:
|
297
|
+
class CArray
|
298
|
+
#
|
299
|
+
def map_with_index! # :yields: v, idx
|
300
|
+
end
|
301
|
+
end
|
302
|
+
*/
|
303
|
+
|
304
|
+
static VALUE
|
305
|
+
rb_ca_map_with_index_bang (VALUE self)
|
306
|
+
{
|
307
|
+
volatile VALUE ridx;
|
308
|
+
CArray *ca;
|
309
|
+
int32_t idx[CA_RANK_MAX];
|
310
|
+
int8_t rank = NUM2INT(rb_ca_rank(self));
|
311
|
+
#if RUBY_VERSION_CODE >= 190
|
312
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
313
|
+
#endif
|
314
|
+
rb_ca_modify(self);
|
315
|
+
Data_Get_Struct(self, CArray, ca);
|
316
|
+
ca_attach(ca);
|
317
|
+
ridx = rb_ary_new2(rank);
|
318
|
+
rb_ca_map_with_index_bang_internal(self, 0, idx, ridx);
|
319
|
+
ca_sync(ca);
|
320
|
+
ca_detach(ca);
|
321
|
+
return self;
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
static void
|
326
|
+
rb_ca_map_index_bang_internal (VALUE self,
|
327
|
+
int8_t level, int32_t *idx, VALUE ridx)
|
328
|
+
{
|
329
|
+
CArray *ca;
|
330
|
+
int32_t i;
|
331
|
+
Data_Get_Struct(self, CArray, ca);
|
332
|
+
if ( level == ca->rank - 1 ) {
|
333
|
+
volatile VALUE obj;
|
334
|
+
for (i=0; i<ca->dim[level]; i++) {
|
335
|
+
idx[level] = i;
|
336
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
337
|
+
obj = rb_yield_splat(rb_obj_clone(ridx));
|
338
|
+
rb_ca_store_index(self, idx, obj);
|
339
|
+
}
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
for (i=0; i<ca->dim[level]; i++) {
|
343
|
+
idx[level] = i;
|
344
|
+
rb_ary_store(ridx, level, INT2NUM(i));
|
345
|
+
rb_ca_map_index_bang_internal(self, level+1, idx, ridx);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
/* rdoc:
|
351
|
+
class CArray
|
352
|
+
#
|
353
|
+
def map_index! # :yields: i0, i1, ...
|
354
|
+
end
|
355
|
+
end
|
356
|
+
*/
|
357
|
+
|
358
|
+
static VALUE
|
359
|
+
rb_ca_map_index_bang (VALUE self)
|
360
|
+
{
|
361
|
+
volatile VALUE ridx;
|
362
|
+
CArray *ca;
|
363
|
+
int32_t idx[CA_RANK_MAX];
|
364
|
+
int8_t rank = NUM2INT(rb_ca_rank(self));
|
365
|
+
#if RUBY_VERSION_CODE >= 190
|
366
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
367
|
+
#endif
|
368
|
+
rb_ca_modify(self);
|
369
|
+
Data_Get_Struct(self, CArray, ca);
|
370
|
+
ca_attach(ca);
|
371
|
+
ridx = rb_ary_new2(rank);
|
372
|
+
rb_ca_map_index_bang_internal(self, 0, idx, ridx);
|
373
|
+
ca_sync(ca);
|
374
|
+
ca_detach(ca);
|
375
|
+
return self;
|
376
|
+
}
|
377
|
+
|
378
|
+
/* rdoc:
|
379
|
+
class CArray
|
380
|
+
#
|
381
|
+
def map_with_addr! # :yields: v, addr
|
382
|
+
end
|
383
|
+
end
|
384
|
+
*/
|
385
|
+
|
386
|
+
static VALUE
|
387
|
+
rb_ca_map_with_addr_bang (VALUE self)
|
388
|
+
{
|
389
|
+
volatile VALUE obj;
|
390
|
+
CArray *ca;
|
391
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
392
|
+
int32_t i;
|
393
|
+
#if RUBY_VERSION_CODE >= 190
|
394
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
395
|
+
#endif
|
396
|
+
rb_ca_modify(self);
|
397
|
+
Data_Get_Struct(self, CArray, ca);
|
398
|
+
ca_attach(ca);
|
399
|
+
for (i=0; i<elements; i++) {
|
400
|
+
obj = rb_yield_values(2, rb_ca_fetch_addr(self, i), LONG2NUM(i));
|
401
|
+
rb_ca_store_addr(self, i, obj);
|
402
|
+
}
|
403
|
+
ca_sync(ca);
|
404
|
+
ca_detach(ca);
|
405
|
+
return self;
|
406
|
+
}
|
407
|
+
|
408
|
+
|
409
|
+
/* rdoc:
|
410
|
+
class CArray
|
411
|
+
#
|
412
|
+
def map_addr! # :yields: addr
|
413
|
+
end
|
414
|
+
end
|
415
|
+
*/
|
416
|
+
|
417
|
+
static VALUE
|
418
|
+
rb_ca_map_addr_bang (VALUE self)
|
419
|
+
{
|
420
|
+
volatile VALUE obj;
|
421
|
+
CArray *ca;
|
422
|
+
int32_t elements = NUM2LONG(rb_ca_elements(self));
|
423
|
+
int32_t i;
|
424
|
+
#if RUBY_VERSION_CODE >= 190
|
425
|
+
RETURN_ENUMERATOR(self, 0, 0);
|
426
|
+
#endif
|
427
|
+
rb_ca_modify(self);
|
428
|
+
Data_Get_Struct(self, CArray, ca);
|
429
|
+
ca_attach(ca);
|
430
|
+
for (i=0; i<elements; i++) {
|
431
|
+
obj = rb_yield(LONG2NUM(i));
|
432
|
+
rb_ca_store_addr(self, i, obj);
|
433
|
+
}
|
434
|
+
ca_sync(ca);
|
435
|
+
ca_detach(ca);
|
436
|
+
return self;
|
437
|
+
}
|
438
|
+
|
439
|
+
|
440
|
+
void
|
441
|
+
Init_carray_loop ()
|
442
|
+
{
|
443
|
+
rb_define_singleton_method(rb_cCArray, "each_index", rb_ca_s_each_index, -1);
|
444
|
+
|
445
|
+
rb_define_method(rb_cCArray, "each", rb_ca_each, 0);
|
446
|
+
rb_define_method(rb_cCArray, "each_addr", rb_ca_each_addr, 0);
|
447
|
+
rb_define_method(rb_cCArray, "each_index", rb_ca_each_index, 0);
|
448
|
+
rb_define_method(rb_cCArray, "each_with_addr", rb_ca_each_with_addr, 0);
|
449
|
+
rb_define_method(rb_cCArray, "each_with_index", rb_ca_each_with_index, 0);
|
450
|
+
|
451
|
+
rb_define_method(rb_cCArray, "map!", rb_ca_map_bang, 0);
|
452
|
+
rb_define_method(rb_cCArray, "map_addr!", rb_ca_map_addr_bang, 0);
|
453
|
+
rb_define_method(rb_cCArray, "map_index!", rb_ca_map_index_bang, 0);
|
454
|
+
rb_define_method(rb_cCArray, "map_with_addr!", rb_ca_map_with_addr_bang, 0);
|
455
|
+
rb_define_method(rb_cCArray, "map_with_index!", rb_ca_map_with_index_bang, 0);
|
456
|
+
|
457
|
+
rb_define_method(rb_cCArray, "collect!", rb_ca_map_bang, 0);
|
458
|
+
rb_define_method(rb_cCArray, "collect_addr!", rb_ca_map_addr_bang, 0);
|
459
|
+
rb_define_method(rb_cCArray, "collect_index!", rb_ca_map_index_bang, 0);
|
460
|
+
rb_define_method(rb_cCArray, "collect_with_addr!", rb_ca_map_with_addr_bang, 0);
|
461
|
+
rb_define_method(rb_cCArray, "collect_with_index!", rb_ca_map_with_index_bang, 0);
|
462
|
+
}
|