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_block.c
ADDED
@@ -0,0 +1,885 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_obj_block.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_cCABlock;
|
16
|
+
|
17
|
+
/* rdoc:
|
18
|
+
class CABlock < CAVirtual # :nodoc:
|
19
|
+
end
|
20
|
+
*/
|
21
|
+
|
22
|
+
static int
|
23
|
+
ca_block_setup (CABlock *ca, CArray *parent, int8_t rank, int32_t *dim,
|
24
|
+
int32_t *start, int32_t *step, int32_t *count, int32_t offset)
|
25
|
+
{
|
26
|
+
int8_t data_type;
|
27
|
+
int8_t maxdim_index;
|
28
|
+
int32_t maxdim_step, maxdim_step0;
|
29
|
+
int32_t elements, bytes;
|
30
|
+
int i;
|
31
|
+
|
32
|
+
data_type = parent->data_type;
|
33
|
+
bytes = parent->bytes;
|
34
|
+
|
35
|
+
elements = 1;
|
36
|
+
for (i=0; i<rank; i++) {
|
37
|
+
if ( count[i] < 0 ) {
|
38
|
+
rb_raise(rb_eIndexError,
|
39
|
+
"invalid size for %i-th dimension (negative)", i);
|
40
|
+
}
|
41
|
+
elements *= count[i];
|
42
|
+
}
|
43
|
+
|
44
|
+
maxdim_index = rank-1;
|
45
|
+
for (i=rank-2; i>=0; i--) {
|
46
|
+
if ( count[i] > count[maxdim_index] ) {
|
47
|
+
maxdim_index = i;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
maxdim_step = 1;
|
52
|
+
maxdim_step0 = step[maxdim_index];
|
53
|
+
for (i=maxdim_index+1; i<rank; i++) {
|
54
|
+
maxdim_step *= count[i];
|
55
|
+
maxdim_step0 *= dim[i];
|
56
|
+
}
|
57
|
+
|
58
|
+
ca->obj_type = CA_OBJ_BLOCK;
|
59
|
+
ca->data_type = data_type;
|
60
|
+
ca->flags = 0;
|
61
|
+
ca->rank = rank;
|
62
|
+
ca->bytes = bytes;
|
63
|
+
ca->elements = elements;
|
64
|
+
ca->ptr = NULL;
|
65
|
+
ca->mask = NULL;
|
66
|
+
ca->parent = parent;
|
67
|
+
ca->attach = 0;
|
68
|
+
ca->nosync = 0;
|
69
|
+
ca->offset = offset;
|
70
|
+
ca->start = ALLOC_N(int32_t, rank);
|
71
|
+
ca->step = ALLOC_N(int32_t, rank);
|
72
|
+
ca->count = ALLOC_N(int32_t, rank);
|
73
|
+
ca->size0 = ALLOC_N(int32_t, rank);
|
74
|
+
|
75
|
+
ca->maxdim_index = maxdim_index;
|
76
|
+
ca->maxdim_step = maxdim_step;
|
77
|
+
ca->maxdim_step0 = maxdim_step0;
|
78
|
+
|
79
|
+
/* printf("maxdim: %i %i %i\n", maxdim_index, maxdim_step, maxdim_step0); */
|
80
|
+
|
81
|
+
ca->dim = ca->count; /* ca->dim should not be free */
|
82
|
+
|
83
|
+
memcpy(ca->start, start, rank * sizeof(int32_t));
|
84
|
+
memcpy(ca->step, step, rank * sizeof(int32_t));
|
85
|
+
memcpy(ca->count, count, rank * sizeof(int32_t));
|
86
|
+
memcpy(ca->size0, dim, rank * sizeof(int32_t));
|
87
|
+
|
88
|
+
if ( ca_has_mask(parent) ) {
|
89
|
+
ca_create_mask(ca);
|
90
|
+
}
|
91
|
+
|
92
|
+
return 0;
|
93
|
+
}
|
94
|
+
|
95
|
+
CABlock *
|
96
|
+
ca_block_new (CArray *parent, int8_t rank, int32_t *dim,
|
97
|
+
int32_t *start, int32_t *step, int32_t *count, int32_t offset)
|
98
|
+
{
|
99
|
+
CABlock *ca = ALLOC(CABlock);
|
100
|
+
ca_block_setup(ca, parent, rank, dim, start, step, count, offset);
|
101
|
+
return ca;
|
102
|
+
}
|
103
|
+
|
104
|
+
static void
|
105
|
+
free_ca_block (void *ap)
|
106
|
+
{
|
107
|
+
CABlock *ca = (CABlock *) ap;
|
108
|
+
if ( ca != NULL ) {
|
109
|
+
xfree(ca->start);
|
110
|
+
xfree(ca->step);
|
111
|
+
xfree(ca->count);
|
112
|
+
xfree(ca->size0);
|
113
|
+
ca_free(ca->mask);
|
114
|
+
/* free(ca->dim); */
|
115
|
+
xfree(ca);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
static void ca_block_attach (CABlock *cb);
|
120
|
+
static void ca_block_sync (CABlock *cb);
|
121
|
+
|
122
|
+
/* ------------------------------------------------------------------- */
|
123
|
+
|
124
|
+
static void *
|
125
|
+
ca_block_func_clone (void *ap)
|
126
|
+
{
|
127
|
+
CABlock *ca = (CABlock *) ap;
|
128
|
+
return ca_block_new(ca->parent,
|
129
|
+
ca->rank, ca->size0,
|
130
|
+
ca->start, ca->step, ca->count, ca->offset);
|
131
|
+
}
|
132
|
+
|
133
|
+
static char *
|
134
|
+
ca_block_func_ptr_at_index (void *ap, int32_t *idx) ;
|
135
|
+
|
136
|
+
static char *
|
137
|
+
ca_block_func_ptr_at_addr (void *ap, int32_t addr)
|
138
|
+
{
|
139
|
+
CABlock *ca = (CABlock *) ap;
|
140
|
+
if ( ca->ptr ) {
|
141
|
+
return ca->ptr + ca->bytes * addr;
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
int32_t idx[CA_RANK_MAX];
|
145
|
+
ca_addr2index(ca, addr, idx);
|
146
|
+
return ca_block_func_ptr_at_index(ca, idx);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
static char *
|
151
|
+
ca_block_func_ptr_at_index (void *ap, int32_t *idx)
|
152
|
+
{
|
153
|
+
CABlock *ca = (CABlock *) ap;
|
154
|
+
|
155
|
+
if ( ca->ptr ) {
|
156
|
+
return ca_array_func_ptr_at_index(ca, idx);
|
157
|
+
}
|
158
|
+
else {
|
159
|
+
int32_t *start = ca->start;
|
160
|
+
int32_t *step = ca->step;
|
161
|
+
int32_t *size0 = ca->size0;
|
162
|
+
int32_t n, i;
|
163
|
+
n = start[0] + idx[0]*step[0];
|
164
|
+
for (i=1; i<ca->rank; i++) {
|
165
|
+
n *= size0[i];
|
166
|
+
n += start[i] + idx[i]*step[i];
|
167
|
+
}
|
168
|
+
n += ca->offset;
|
169
|
+
if ( ca->parent->ptr ) {
|
170
|
+
return ca->parent->ptr + ca->bytes * n;
|
171
|
+
}
|
172
|
+
else {
|
173
|
+
return ca_ptr_at_addr(ca->parent, n);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
static void
|
179
|
+
ca_block_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
180
|
+
{
|
181
|
+
CABlock *ca = (CABlock *) ap;
|
182
|
+
int32_t *start = ca->start;
|
183
|
+
int32_t *step = ca->step;
|
184
|
+
int32_t *size0 = ca->size0;
|
185
|
+
int32_t n, i;
|
186
|
+
n = start[0] + idx[0]*step[0];
|
187
|
+
for (i=1; i<ca->rank; i++) {
|
188
|
+
n *= size0[i];
|
189
|
+
n += start[i] + idx[i]*step[i];
|
190
|
+
}
|
191
|
+
n += ca->offset;
|
192
|
+
ca_fetch_addr(ca->parent, n, ptr);
|
193
|
+
}
|
194
|
+
|
195
|
+
static void
|
196
|
+
ca_block_func_store_index (void *ap, int32_t *idx, void *ptr)
|
197
|
+
{
|
198
|
+
CABlock *ca = (CABlock *) ap;
|
199
|
+
int32_t *start = ca->start;
|
200
|
+
int32_t *step = ca->step;
|
201
|
+
int32_t *size0 = ca->size0;
|
202
|
+
int32_t n, i;
|
203
|
+
n = start[0] + idx[0]*step[0];
|
204
|
+
for (i=1; i<ca->rank; i++) {
|
205
|
+
n *= size0[i];
|
206
|
+
n += start[i] + idx[i]*step[i];
|
207
|
+
}
|
208
|
+
n += ca->offset;
|
209
|
+
ca_store_addr(ca->parent, n, ptr);
|
210
|
+
}
|
211
|
+
|
212
|
+
static void
|
213
|
+
ca_block_func_allocate (void *ap)
|
214
|
+
{
|
215
|
+
CABlock *ca = (CABlock *) ap;
|
216
|
+
ca_attach(ca->parent);
|
217
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
218
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
219
|
+
}
|
220
|
+
|
221
|
+
static void
|
222
|
+
ca_block_func_attach (void *ap)
|
223
|
+
{
|
224
|
+
CABlock *ca = (CABlock *) ap;
|
225
|
+
ca_attach(ca->parent);
|
226
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
227
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
228
|
+
ca_block_attach(ca);
|
229
|
+
}
|
230
|
+
|
231
|
+
static void
|
232
|
+
ca_block_func_sync (void *ap)
|
233
|
+
{
|
234
|
+
CABlock *ca = (CABlock *) ap;
|
235
|
+
ca_block_sync(ca);
|
236
|
+
ca_sync(ca->parent);
|
237
|
+
}
|
238
|
+
|
239
|
+
static void
|
240
|
+
ca_block_func_detach (void *ap)
|
241
|
+
{
|
242
|
+
CABlock *ca = (CABlock *) ap;
|
243
|
+
free(ca->ptr);
|
244
|
+
ca->ptr = NULL;
|
245
|
+
ca_detach(ca->parent);
|
246
|
+
}
|
247
|
+
|
248
|
+
static void
|
249
|
+
ca_block_func_copy_data (void *ap, void *ptr)
|
250
|
+
{
|
251
|
+
CABlock *ca = (CABlock *) ap;
|
252
|
+
char *ptr0 = ca->ptr;
|
253
|
+
ca_attach(ca->parent);
|
254
|
+
ca->ptr = ptr;
|
255
|
+
ca_block_attach(ca);
|
256
|
+
ca->ptr = ptr0;
|
257
|
+
ca_detach(ca->parent);
|
258
|
+
}
|
259
|
+
|
260
|
+
static void
|
261
|
+
ca_block_func_sync_data (void *ap, void *ptr)
|
262
|
+
{
|
263
|
+
CABlock *ca = (CABlock *) ap;
|
264
|
+
char *ptr0 = ca->ptr;
|
265
|
+
ca_attach(ca->parent);
|
266
|
+
ca->ptr = ptr;
|
267
|
+
ca_block_sync(ca);
|
268
|
+
ca->ptr = ptr0;
|
269
|
+
ca_sync(ca->parent);
|
270
|
+
ca_detach(ca->parent);
|
271
|
+
}
|
272
|
+
|
273
|
+
static void ca_block_fill (CABlock *ca, char *val);
|
274
|
+
|
275
|
+
static void
|
276
|
+
ca_block_func_fill_data (void *ap, void *ptr)
|
277
|
+
{
|
278
|
+
CABlock *ca = (CABlock *) ap;
|
279
|
+
ca_attach(ca->parent);
|
280
|
+
ca_block_fill(ca, ptr);
|
281
|
+
ca_sync(ca->parent);
|
282
|
+
ca_detach(ca->parent);
|
283
|
+
}
|
284
|
+
|
285
|
+
static void
|
286
|
+
ca_block_func_create_mask (void *ap)
|
287
|
+
{
|
288
|
+
CABlock *ca = (CABlock *) ap;
|
289
|
+
ca_create_mask(ca->parent);
|
290
|
+
ca->mask =
|
291
|
+
(CArray *) ca_block_new(ca->parent->mask,
|
292
|
+
ca->rank, ca->size0,
|
293
|
+
ca->start, ca->step, ca->count, ca->offset);
|
294
|
+
}
|
295
|
+
|
296
|
+
ca_operation_function_t ca_block_func = {
|
297
|
+
CA_OBJ_BLOCK,
|
298
|
+
CA_VIRTUAL_ARRAY,
|
299
|
+
free_ca_block,
|
300
|
+
ca_block_func_clone,
|
301
|
+
ca_block_func_ptr_at_addr,
|
302
|
+
ca_block_func_ptr_at_index,
|
303
|
+
NULL,
|
304
|
+
ca_block_func_fetch_index,
|
305
|
+
NULL,
|
306
|
+
ca_block_func_store_index,
|
307
|
+
ca_block_func_allocate,
|
308
|
+
ca_block_func_attach,
|
309
|
+
ca_block_func_sync,
|
310
|
+
ca_block_func_detach,
|
311
|
+
ca_block_func_copy_data,
|
312
|
+
ca_block_func_sync_data,
|
313
|
+
ca_block_func_fill_data,
|
314
|
+
ca_block_func_create_mask,
|
315
|
+
};
|
316
|
+
|
317
|
+
/* ------------------------------------------------------------------- */
|
318
|
+
|
319
|
+
VALUE
|
320
|
+
rb_ca_block_new (VALUE cary, int8_t rank, int32_t *dim,
|
321
|
+
int32_t *start, int32_t *step, int32_t *count, int32_t offset)
|
322
|
+
{
|
323
|
+
volatile VALUE obj;
|
324
|
+
CArray *parent;
|
325
|
+
CABlock *ca;
|
326
|
+
|
327
|
+
rb_check_carray_object(cary);
|
328
|
+
Data_Get_Struct(cary, CArray, parent);
|
329
|
+
|
330
|
+
ca = ca_block_new(parent, rank, dim, start, step, count, offset);
|
331
|
+
obj = ca_wrap_struct(ca);
|
332
|
+
rb_ca_set_parent(obj, cary);
|
333
|
+
rb_ca_data_type_inherit(obj, cary);
|
334
|
+
return obj;
|
335
|
+
}
|
336
|
+
|
337
|
+
/* ---------------------------------------------------------------------- */
|
338
|
+
|
339
|
+
static void *mcopy_step (void *dest, const void *src,
|
340
|
+
size_t bytes, size_t n, size_t dstep, size_t sstep);
|
341
|
+
|
342
|
+
static void *mfill_step(void *dest,
|
343
|
+
size_t bytes, size_t n, size_t dstep, const void *src);
|
344
|
+
|
345
|
+
static void
|
346
|
+
ca_block_attach_loop2 (CABlock *ca, int8_t level, int32_t saddr, int32_t saddr0)
|
347
|
+
{
|
348
|
+
int32_t count = ca->count[level];
|
349
|
+
int32_t addr, addr0, i;
|
350
|
+
|
351
|
+
if ( level == ca->rank - 1 ) {
|
352
|
+
if ( ca->parent->ptr ) {
|
353
|
+
addr = saddr * ca->dim[level];
|
354
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
355
|
+
mcopy_step(ca_ptr_at_addr(ca, addr),
|
356
|
+
ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
357
|
+
ca->bytes, count, 1, ca->step[level]);
|
358
|
+
}
|
359
|
+
else {
|
360
|
+
for (i=0; i<count; i++) {
|
361
|
+
addr = saddr * ca->dim[level] + i;
|
362
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
363
|
+
+ i * ca->step[level];
|
364
|
+
memcpy(ca_ptr_at_addr(ca, addr),
|
365
|
+
ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
366
|
+
ca->bytes);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
}
|
370
|
+
else {
|
371
|
+
for (i=0; i<count; i++) {
|
372
|
+
addr = saddr * ca->dim[level] + i;
|
373
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
374
|
+
+ i * ca->step[level];
|
375
|
+
ca_block_attach_loop2(ca, level+1, addr, addr0);
|
376
|
+
}
|
377
|
+
}
|
378
|
+
}
|
379
|
+
|
380
|
+
static void
|
381
|
+
ca_block_attach_loop (CABlock *ca, int32_t level, int32_t saddr, int32_t saddr0)
|
382
|
+
{
|
383
|
+
int32_t count = ca->count[level];
|
384
|
+
int32_t addr, addr0, i;
|
385
|
+
|
386
|
+
if ( level == ca->rank - 1 ) {
|
387
|
+
if ( level == ca->maxdim_index ) {
|
388
|
+
addr = saddr * ca->dim[level];
|
389
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
390
|
+
mcopy_step(ca_ptr_at_addr(ca, addr),
|
391
|
+
ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
392
|
+
ca->bytes, count, 1, ca->step[level]);
|
393
|
+
}
|
394
|
+
else {
|
395
|
+
char *p = ca_ptr_at_addr(ca, saddr* ca->dim[level]);
|
396
|
+
char *q = ca_ptr_at_addr(ca->parent,
|
397
|
+
saddr0*ca->size0[level]+ca->start[level]+ca->offset);
|
398
|
+
int32_t pstep = ca->bytes;
|
399
|
+
int32_t qstep = ca->bytes*ca->step[level];
|
400
|
+
for (i=0; i<count; i++) {
|
401
|
+
mcopy_step(p,
|
402
|
+
q,
|
403
|
+
ca->bytes, ca->count[ca->maxdim_index],
|
404
|
+
ca->maxdim_step, ca->maxdim_step0);
|
405
|
+
p += pstep;
|
406
|
+
q += qstep;
|
407
|
+
}
|
408
|
+
}
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
if ( level == ca->maxdim_index ) {
|
412
|
+
addr = saddr * ca->dim[level];
|
413
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
414
|
+
ca_block_attach_loop(ca, level+1, addr, addr0);
|
415
|
+
}
|
416
|
+
else {
|
417
|
+
for (i=0; i<count; i++) {
|
418
|
+
addr = saddr * ca->dim[level] + i;
|
419
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
420
|
+
+ i * ca->step[level];
|
421
|
+
ca_block_attach_loop(ca, level+1, addr, addr0);
|
422
|
+
}
|
423
|
+
}
|
424
|
+
}
|
425
|
+
}
|
426
|
+
|
427
|
+
static void
|
428
|
+
ca_block_attach (CABlock *ca)
|
429
|
+
{
|
430
|
+
int32_t addr = 0, addr0 = 0;
|
431
|
+
if ( ca->rank <= 2 ) {
|
432
|
+
ca_block_attach_loop2(ca, 0, addr, addr0);
|
433
|
+
}
|
434
|
+
else {
|
435
|
+
ca_block_attach_loop(ca, 0, addr, addr0);
|
436
|
+
}
|
437
|
+
}
|
438
|
+
|
439
|
+
static void
|
440
|
+
ca_block_sync_loop2 (CABlock *ca, int32_t level, int32_t saddr, int32_t saddr0)
|
441
|
+
{
|
442
|
+
int32_t count = ca->count[level];
|
443
|
+
int32_t addr, addr0, i;
|
444
|
+
|
445
|
+
if ( level == ca->rank - 1 ) {
|
446
|
+
if ( ca->parent->ptr ) {
|
447
|
+
addr = saddr * ca->dim[level];
|
448
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
449
|
+
mcopy_step(ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
450
|
+
ca_ptr_at_addr(ca, addr),
|
451
|
+
ca->bytes, count, ca->step[level], 1);
|
452
|
+
}
|
453
|
+
else {
|
454
|
+
for (i=0; i<count; i++) {
|
455
|
+
addr = saddr * ca->dim[level] + i;
|
456
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
457
|
+
+ i * ca->step[level];
|
458
|
+
memcpy(ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
459
|
+
ca_ptr_at_addr(ca, addr),
|
460
|
+
ca->bytes);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}
|
464
|
+
else {
|
465
|
+
for (i=0; i<count; i++) {
|
466
|
+
addr = saddr * ca->dim[level] + i;
|
467
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level] + i * ca->step[level];
|
468
|
+
ca_block_sync_loop2(ca, level+1, addr, addr0);
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
static void
|
474
|
+
ca_block_sync_loop (CABlock *ca, int32_t level, int32_t saddr, int32_t saddr0)
|
475
|
+
{
|
476
|
+
int32_t count = ca->count[level];
|
477
|
+
int32_t addr, addr0, i;
|
478
|
+
|
479
|
+
if ( level == ca->rank - 1 ) {
|
480
|
+
if ( level == ca->maxdim_index ) {
|
481
|
+
addr = saddr * ca->dim[level];
|
482
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
483
|
+
mcopy_step(ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
484
|
+
ca_ptr_at_addr(ca, addr),
|
485
|
+
ca->bytes, count, ca->step[level], 1);
|
486
|
+
}
|
487
|
+
else {
|
488
|
+
for (i=0; i<count; i++) {
|
489
|
+
addr = saddr * ca->dim[level] + i;
|
490
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
491
|
+
+ i * ca->step[level];
|
492
|
+
mcopy_step(ca_ptr_at_addr(ca->parent, addr0 + ca->offset),
|
493
|
+
ca_ptr_at_addr(ca, addr),
|
494
|
+
ca->bytes, ca->count[ca->maxdim_index],
|
495
|
+
ca->maxdim_step0, ca->maxdim_step);
|
496
|
+
}
|
497
|
+
}
|
498
|
+
}
|
499
|
+
else {
|
500
|
+
if ( level == ca->maxdim_index ) {
|
501
|
+
addr = saddr * ca->dim[level];
|
502
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level];
|
503
|
+
ca_block_sync_loop(ca, level+1, addr, addr0);
|
504
|
+
}
|
505
|
+
else {
|
506
|
+
for (i=0; i<count; i++) {
|
507
|
+
addr = saddr * ca->dim[level] + i;
|
508
|
+
addr0 = saddr0 * ca->size0[level] + ca->start[level]
|
509
|
+
+ i * ca->step[level];
|
510
|
+
ca_block_sync_loop(ca, level+1, addr, addr0);
|
511
|
+
}
|
512
|
+
}
|
513
|
+
}
|
514
|
+
}
|
515
|
+
|
516
|
+
static void
|
517
|
+
ca_block_sync (CABlock *cb)
|
518
|
+
{
|
519
|
+
int32_t addr = 0, addr0 = 0;
|
520
|
+
if ( cb->rank <= 2 ) {
|
521
|
+
ca_block_sync_loop2(cb, 0, addr, addr0);
|
522
|
+
}
|
523
|
+
else {
|
524
|
+
ca_block_sync_loop(cb, 0, addr, addr0);
|
525
|
+
}
|
526
|
+
}
|
527
|
+
|
528
|
+
static void
|
529
|
+
ca_block_fill_loop2 (CABlock *ca, int32_t level, int32_t saddr, char *val)
|
530
|
+
{
|
531
|
+
int32_t count = ca->count[level];
|
532
|
+
int32_t addr, i;
|
533
|
+
if ( level == ca->rank - 1 ) {
|
534
|
+
addr = saddr * ca->dim[level];
|
535
|
+
mfill_step(ca_ptr_at_addr(ca, addr),
|
536
|
+
ca->bytes, count, ca->step[level], val);
|
537
|
+
}
|
538
|
+
else {
|
539
|
+
for (i=0; i<count; i++) {
|
540
|
+
addr = saddr * ca->dim[level] + i;
|
541
|
+
ca_block_fill_loop2(ca, level+1, addr, val);
|
542
|
+
}
|
543
|
+
}
|
544
|
+
}
|
545
|
+
|
546
|
+
static void
|
547
|
+
ca_block_fill_loop (CABlock *ca, int32_t level, int32_t saddr, char *val)
|
548
|
+
{
|
549
|
+
int32_t count = ca->count[level];
|
550
|
+
int32_t addr, i;
|
551
|
+
if ( level == ca->rank - 1 ) {
|
552
|
+
if ( level == ca->maxdim_index ) {
|
553
|
+
addr = saddr * ca->dim[level];
|
554
|
+
mfill_step(ca_ptr_at_addr(ca, addr),
|
555
|
+
ca->bytes, count, ca->step[level], val);
|
556
|
+
}
|
557
|
+
else {
|
558
|
+
for (i=0; i<count; i++) {
|
559
|
+
addr = saddr * ca->dim[level] + i;
|
560
|
+
mfill_step(ca_ptr_at_addr(ca, addr),
|
561
|
+
ca->bytes, ca->count[ca->maxdim_index],
|
562
|
+
ca->maxdim_step0, val);
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
}
|
567
|
+
else {
|
568
|
+
if ( level == ca->maxdim_index ) {
|
569
|
+
addr = saddr * ca->dim[level];
|
570
|
+
ca_block_fill_loop(ca, level+1, addr, val);
|
571
|
+
}
|
572
|
+
else {
|
573
|
+
for (i=0; i<count; i++) {
|
574
|
+
addr = saddr * ca->dim[level] + i;
|
575
|
+
ca_block_fill_loop(ca, level+1, addr, val);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
}
|
580
|
+
}
|
581
|
+
|
582
|
+
static void
|
583
|
+
ca_block_fill (CABlock *ca, char *val)
|
584
|
+
{
|
585
|
+
int32_t addr = 0;
|
586
|
+
if ( ca->rank <= 2 ) {
|
587
|
+
ca_block_fill_loop2(ca, 0, addr, val);
|
588
|
+
}
|
589
|
+
else {
|
590
|
+
ca_block_fill_loop(ca, 0, addr, val);
|
591
|
+
}
|
592
|
+
}
|
593
|
+
|
594
|
+
/* -------------------------------------------------------------------- */
|
595
|
+
|
596
|
+
static void *
|
597
|
+
mcopy_step (void *dest, const void *src,
|
598
|
+
size_t bytes, size_t n, size_t dstep, size_t sstep)
|
599
|
+
{
|
600
|
+
if ( dstep == 1 && sstep == 1 ) {
|
601
|
+
size_t bytelen = bytes * n;
|
602
|
+
size_t words = bytelen / sizeof(int);
|
603
|
+
size_t rests = bytelen % sizeof(int);
|
604
|
+
int *sp = (int*) src;
|
605
|
+
int *dp = (int*) dest;
|
606
|
+
char *scp;
|
607
|
+
char *dcp;
|
608
|
+
int32_t i;
|
609
|
+
for (i=words; i; i--) {
|
610
|
+
*dp++ = *sp++;
|
611
|
+
}
|
612
|
+
scp = (char*)sp; dcp = (char*)dp;
|
613
|
+
for (i=rests; i; i--) {
|
614
|
+
*dcp++ = *scp++;
|
615
|
+
}
|
616
|
+
}
|
617
|
+
else if ( dstep >= 1 || sstep >= 1 ) {
|
618
|
+
switch ( bytes ) {
|
619
|
+
case 1: {
|
620
|
+
int8_t *sp = (int8_t*) src, *dp = (int8_t*) dest;
|
621
|
+
while (n--) { *dp = *sp; dp+=dstep; sp+=sstep; }
|
622
|
+
break;
|
623
|
+
}
|
624
|
+
case 2: {
|
625
|
+
int16_t *sp = (int16_t*) src, *dp = (int16_t*) dest;
|
626
|
+
while (n--) { *dp = *sp; dp+=dstep; sp+=sstep; }
|
627
|
+
break;
|
628
|
+
}
|
629
|
+
case 4: {
|
630
|
+
int32_t *sp = (int32_t*) src, *dp = (int32_t*) dest;
|
631
|
+
while (n--) { *dp = *sp; dp+=dstep; sp+=sstep; }
|
632
|
+
break;
|
633
|
+
}
|
634
|
+
case 8: {
|
635
|
+
double *sp = (double*) src, *dp = (double*) dest;
|
636
|
+
while (n--) { *dp = *sp; dp+=dstep; sp+=sstep; }
|
637
|
+
break;
|
638
|
+
}
|
639
|
+
default: {
|
640
|
+
char *sp = (char*) src, *dp = (char*) dest;
|
641
|
+
while (n--) { memcpy(dp,sp,bytes); dp+=bytes*dstep; sp+=bytes*sstep; }
|
642
|
+
break;
|
643
|
+
}
|
644
|
+
}
|
645
|
+
}
|
646
|
+
|
647
|
+
return dest;
|
648
|
+
}
|
649
|
+
|
650
|
+
static void *
|
651
|
+
mfill_step(void *dest, size_t bytes, size_t n, size_t dstep, const void *src)
|
652
|
+
{
|
653
|
+
switch ( bytes ) {
|
654
|
+
case 1: {
|
655
|
+
int8_t *dp = (int8_t*) dest;
|
656
|
+
int8_t v = *(int8_t*) src;
|
657
|
+
while (n--) { *dp = v; dp+=dstep; }
|
658
|
+
break;
|
659
|
+
}
|
660
|
+
case 2: {
|
661
|
+
int16_t *dp = (int16_t*) dest;
|
662
|
+
int16_t v = *(int16_t*) src;
|
663
|
+
while (n--) { *dp = v; dp+=dstep; }
|
664
|
+
break;
|
665
|
+
}
|
666
|
+
case 4: {
|
667
|
+
int32_t *dp = (int32_t*) dest;
|
668
|
+
int32_t v = *(int32_t*) src;
|
669
|
+
while (n--) { *dp = v; dp+=dstep; }
|
670
|
+
break;
|
671
|
+
}
|
672
|
+
case 8: {
|
673
|
+
double *dp = (double*) dest;
|
674
|
+
double v = *(double*) src;
|
675
|
+
while (n--) { *dp = v; dp+=dstep; }
|
676
|
+
break;
|
677
|
+
}
|
678
|
+
default: {
|
679
|
+
char *sp = (char*) src, *dp = (char*) dest;
|
680
|
+
while (n--) { memcpy(dp,sp,bytes); dp+=bytes*dstep; }
|
681
|
+
break;
|
682
|
+
}
|
683
|
+
}
|
684
|
+
|
685
|
+
return dest;
|
686
|
+
}
|
687
|
+
|
688
|
+
/* ---------------------------------------------------------------------- */
|
689
|
+
|
690
|
+
static VALUE
|
691
|
+
rb_cb_s_allocate (VALUE klass)
|
692
|
+
{
|
693
|
+
CABlock *ca;
|
694
|
+
return Data_Make_Struct(klass, CABlock, ca_mark, ca_free, ca);
|
695
|
+
}
|
696
|
+
|
697
|
+
static VALUE
|
698
|
+
rb_cb_initialize_copy (VALUE self, VALUE other)
|
699
|
+
{
|
700
|
+
CABlock *ca, *cs;
|
701
|
+
int32_t shrink[CA_RANK_MAX];
|
702
|
+
int32_t i;
|
703
|
+
|
704
|
+
Data_Get_Struct(self, CABlock, ca);
|
705
|
+
Data_Get_Struct(other, CABlock, cs);
|
706
|
+
|
707
|
+
for (i=0; i<cs->rank; i++) {
|
708
|
+
shrink[i] = 0;
|
709
|
+
}
|
710
|
+
|
711
|
+
ca_block_setup(ca, cs->parent,
|
712
|
+
cs->rank, cs->size0, cs->start, cs->step, cs->count, cs->offset);
|
713
|
+
|
714
|
+
/* CHECK ME : other.parent instead of other ? */
|
715
|
+
rb_ca_set_parent(self, rb_ca_parent(other));
|
716
|
+
rb_ca_data_type_inherit(self, rb_ca_parent(other));
|
717
|
+
|
718
|
+
return self;
|
719
|
+
}
|
720
|
+
|
721
|
+
#define rb_cb_get_attr_ary(name) \
|
722
|
+
rb_cb_## name (VALUE self) \
|
723
|
+
{ \
|
724
|
+
volatile VALUE ary; \
|
725
|
+
CABlock *cb; \
|
726
|
+
int32_t i; \
|
727
|
+
Data_Get_Struct(self, CABlock, cb); \
|
728
|
+
ary = rb_ary_new2(cb->rank); \
|
729
|
+
for (i=0; i<cb->rank; i++) { \
|
730
|
+
rb_ary_store(ary, i, LONG2NUM(cb->name[i])); \
|
731
|
+
} \
|
732
|
+
return ary; \
|
733
|
+
}
|
734
|
+
|
735
|
+
/* rdoc:
|
736
|
+
class CABlock
|
737
|
+
def size0
|
738
|
+
end
|
739
|
+
def start
|
740
|
+
end
|
741
|
+
def step
|
742
|
+
end
|
743
|
+
def count
|
744
|
+
end
|
745
|
+
def offset
|
746
|
+
end
|
747
|
+
end
|
748
|
+
*/
|
749
|
+
|
750
|
+
static VALUE rb_cb_get_attr_ary(size0);
|
751
|
+
static VALUE rb_cb_get_attr_ary(start);
|
752
|
+
static VALUE rb_cb_get_attr_ary(step);
|
753
|
+
static VALUE rb_cb_get_attr_ary(count);
|
754
|
+
|
755
|
+
static VALUE
|
756
|
+
rb_cb_offset (VALUE self)
|
757
|
+
{
|
758
|
+
CABlock *cb;
|
759
|
+
Data_Get_Struct(self, CABlock, cb);
|
760
|
+
return INT2NUM(cb->offset);
|
761
|
+
}
|
762
|
+
|
763
|
+
/* rdoc:
|
764
|
+
class CABlock
|
765
|
+
def idx2addr0 (idx)
|
766
|
+
end
|
767
|
+
end
|
768
|
+
*/
|
769
|
+
|
770
|
+
static VALUE
|
771
|
+
rb_cb_idx2addr0 (int argc, VALUE *argv, VALUE self)
|
772
|
+
{
|
773
|
+
CABlock *cb;
|
774
|
+
int32_t addr;
|
775
|
+
int32_t i, idxi;
|
776
|
+
|
777
|
+
Data_Get_Struct(self, CABlock, cb);
|
778
|
+
|
779
|
+
if ( argc != cb->rank ) {
|
780
|
+
rb_raise(rb_eArgError,
|
781
|
+
"invalid # of arguments (should be <%i>)", cb->rank);
|
782
|
+
}
|
783
|
+
|
784
|
+
addr = 0;
|
785
|
+
for (i=0; i<cb->rank; i++) {
|
786
|
+
idxi = NUM2INT(argv[i]);
|
787
|
+
CA_CHECK_INDEX(idxi, cb->dim[i]);
|
788
|
+
addr = cb->size0[i] * addr + cb->start[i] + idxi * cb->step[i];
|
789
|
+
}
|
790
|
+
|
791
|
+
return INT2NUM(addr + cb->offset);
|
792
|
+
}
|
793
|
+
|
794
|
+
/* rdoc:
|
795
|
+
class CABlock
|
796
|
+
def addr2addr0 (addr)
|
797
|
+
end
|
798
|
+
end
|
799
|
+
*/
|
800
|
+
|
801
|
+
static VALUE
|
802
|
+
rb_cb_addr2addr0 (VALUE self, VALUE raddr)
|
803
|
+
{
|
804
|
+
CABlock *cb;
|
805
|
+
int32_t addr = NUM2INT(raddr);
|
806
|
+
int32_t idx[CA_RANK_MAX];
|
807
|
+
int32_t i;
|
808
|
+
|
809
|
+
Data_Get_Struct(self, CABlock, cb);
|
810
|
+
|
811
|
+
ca_addr2index((CArray*)cb, addr, idx);
|
812
|
+
|
813
|
+
addr = 0;
|
814
|
+
for (i=0; i<cb->rank; i++) {
|
815
|
+
addr *= cb->size0[i];
|
816
|
+
addr += cb->start[i] + idx[i] * cb->step[i];
|
817
|
+
}
|
818
|
+
|
819
|
+
return INT2NUM(addr + cb->offset);
|
820
|
+
}
|
821
|
+
|
822
|
+
|
823
|
+
/* rdoc:
|
824
|
+
class CABlock
|
825
|
+
def move (*index)
|
826
|
+
end
|
827
|
+
end
|
828
|
+
*/
|
829
|
+
|
830
|
+
static VALUE
|
831
|
+
rb_cb_move (int argc, VALUE *argv, VALUE self)
|
832
|
+
{
|
833
|
+
CABlock *cb;
|
834
|
+
int32_t start, i;
|
835
|
+
|
836
|
+
Data_Get_Struct(self, CABlock, cb);
|
837
|
+
|
838
|
+
if ( argc != cb->rank ) {
|
839
|
+
rb_raise(rb_eArgError, "invalid # of arguments");
|
840
|
+
}
|
841
|
+
|
842
|
+
ca_update_mask(cb);
|
843
|
+
|
844
|
+
for (i=0; i<cb->rank; i++) {
|
845
|
+
start = NUM2LONG(argv[i]);
|
846
|
+
if ( start < 0 ) {
|
847
|
+
start += cb->size0[i];
|
848
|
+
}
|
849
|
+
|
850
|
+
if ( start < 0 || start + (cb->dim[i]-1) * cb->step[i] >= cb->size0[i] ) {
|
851
|
+
rb_raise(rb_eArgError, "%i-th index out of range", i);
|
852
|
+
}
|
853
|
+
|
854
|
+
cb->start[i] = start;
|
855
|
+
|
856
|
+
if ( cb->mask ) {
|
857
|
+
((CABlock*)(cb->mask))->start[i] = start;
|
858
|
+
}
|
859
|
+
}
|
860
|
+
|
861
|
+
return self;
|
862
|
+
}
|
863
|
+
|
864
|
+
void
|
865
|
+
Init_ca_obj_block ()
|
866
|
+
{
|
867
|
+
/* rb_cCABlock, CA_OBJ_BLOCK are defined in rb_carray.c */
|
868
|
+
|
869
|
+
rb_define_const(rb_cObject, "CA_OBJ_BLOCK", INT2NUM(CA_OBJ_BLOCK));
|
870
|
+
|
871
|
+
rb_define_alloc_func(rb_cCABlock, rb_cb_s_allocate);
|
872
|
+
rb_define_method(rb_cCABlock, "initialize_copy", rb_cb_initialize_copy, 1);
|
873
|
+
|
874
|
+
rb_define_method(rb_cCABlock, "size0", rb_cb_size0, 0);
|
875
|
+
rb_define_method(rb_cCABlock, "start", rb_cb_start, 0);
|
876
|
+
rb_define_method(rb_cCABlock, "step", rb_cb_step, 0);
|
877
|
+
rb_define_method(rb_cCABlock, "count", rb_cb_count, 0);
|
878
|
+
rb_define_method(rb_cCABlock, "offset", rb_cb_offset, 0);
|
879
|
+
|
880
|
+
rb_define_method(rb_cCABlock, "move", rb_cb_move, -1);
|
881
|
+
|
882
|
+
rb_define_method(rb_cCABlock, "idx2addr0", rb_cb_idx2addr0, -1);
|
883
|
+
rb_define_method(rb_cCABlock, "index2addr0", rb_cb_idx2addr0, -1);
|
884
|
+
rb_define_method(rb_cCABlock, "addr2addr0", rb_cb_addr2addr0, 1);
|
885
|
+
}
|