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_transpose.c
ADDED
@@ -0,0 +1,582 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_obj_transpose.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
|
+
typedef struct {
|
16
|
+
int16_t obj_type;
|
17
|
+
int8_t data_type;
|
18
|
+
int8_t rank;
|
19
|
+
int32_t flags;
|
20
|
+
int32_t bytes;
|
21
|
+
int32_t elements;
|
22
|
+
int32_t *dim;
|
23
|
+
char *ptr;
|
24
|
+
CArray *mask;
|
25
|
+
CArray *parent;
|
26
|
+
uint32_t attach;
|
27
|
+
uint8_t nosync;
|
28
|
+
/* -------------*/
|
29
|
+
int32_t *imap;
|
30
|
+
int32_t step;
|
31
|
+
} CATrans;
|
32
|
+
|
33
|
+
static int8_t CA_OBJ_TRANSPOSE;
|
34
|
+
|
35
|
+
static VALUE rb_cCATrans;
|
36
|
+
|
37
|
+
/* rdoc:
|
38
|
+
class CATranspose < CAVirtual # :nodoc:
|
39
|
+
end
|
40
|
+
*/
|
41
|
+
|
42
|
+
/* ------------------------------------------------------------------- */
|
43
|
+
|
44
|
+
int
|
45
|
+
ca_trans_setup (CATrans *ca, CArray *parent, int32_t *imap)
|
46
|
+
{
|
47
|
+
int8_t data_type, rank;
|
48
|
+
int32_t bytes, elements;
|
49
|
+
int32_t *dim0;
|
50
|
+
int32_t newdim[CA_RANK_MAX];
|
51
|
+
int32_t map[CA_RANK_MAX];
|
52
|
+
int i, idim, step;
|
53
|
+
|
54
|
+
data_type = parent->data_type;
|
55
|
+
bytes = parent->bytes;
|
56
|
+
rank = parent->rank;
|
57
|
+
elements = parent->elements;
|
58
|
+
dim0 = parent->dim;
|
59
|
+
|
60
|
+
for (i=0; i<rank; i++) {
|
61
|
+
map[i] = -1;
|
62
|
+
}
|
63
|
+
|
64
|
+
for (i=0; i<rank; i++) {
|
65
|
+
idim = imap[i];
|
66
|
+
if ( idim < 0 || idim >= rank ) {
|
67
|
+
rb_raise(rb_eRuntimeError,
|
68
|
+
"specified %i-th dimension number out of range", i);
|
69
|
+
}
|
70
|
+
|
71
|
+
if ( map[idim] != -1 ) {
|
72
|
+
rb_raise(rb_eRuntimeError,
|
73
|
+
"specified %i-th dimension number is duplicated", i);
|
74
|
+
}
|
75
|
+
map[idim] = i;
|
76
|
+
newdim[i] = dim0[idim];
|
77
|
+
}
|
78
|
+
|
79
|
+
step = 1;
|
80
|
+
for (i=imap[rank-1]+1; i<rank; i++) {
|
81
|
+
step *= dim0[i];
|
82
|
+
}
|
83
|
+
|
84
|
+
ca->obj_type = CA_OBJ_TRANSPOSE;
|
85
|
+
ca->data_type = data_type;
|
86
|
+
ca->flags = 0;
|
87
|
+
ca->rank = rank;
|
88
|
+
ca->bytes = bytes;
|
89
|
+
ca->elements = elements;
|
90
|
+
ca->ptr = NULL;
|
91
|
+
ca->mask = NULL;
|
92
|
+
ca->dim = ALLOC_N(int32_t, rank);
|
93
|
+
|
94
|
+
ca->parent = parent;
|
95
|
+
ca->attach = 0;
|
96
|
+
ca->nosync = 0;
|
97
|
+
ca->imap = ALLOC_N(int32_t, rank);
|
98
|
+
ca->step = step;
|
99
|
+
|
100
|
+
memcpy(ca->dim, newdim, rank * sizeof(int32_t));
|
101
|
+
memcpy(ca->imap, imap, rank * sizeof(int32_t));
|
102
|
+
|
103
|
+
if ( ca_has_mask(parent) ) {
|
104
|
+
ca_create_mask(ca);
|
105
|
+
}
|
106
|
+
|
107
|
+
return 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
CATrans *
|
111
|
+
ca_trans_new (CArray *parent, int32_t *imap)
|
112
|
+
{
|
113
|
+
CATrans *ca = ALLOC(CATrans);
|
114
|
+
ca_trans_setup(ca, parent, imap);
|
115
|
+
return ca;
|
116
|
+
}
|
117
|
+
|
118
|
+
static void
|
119
|
+
free_ca_trans (void *ap)
|
120
|
+
{
|
121
|
+
CATrans *ca = (CATrans *) ap;
|
122
|
+
if ( ca != NULL ) {
|
123
|
+
xfree(ca->imap);
|
124
|
+
ca_free(ca->mask);
|
125
|
+
xfree(ca->dim);
|
126
|
+
xfree(ca);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
static void ca_trans_attach (CATrans *cb);
|
131
|
+
static void ca_trans_sync (CATrans *cb);
|
132
|
+
static void ca_trans_fill (CATrans *ca, char *ptr);
|
133
|
+
|
134
|
+
|
135
|
+
/* ------------------------------------------------------------------- */
|
136
|
+
|
137
|
+
static void *
|
138
|
+
ca_trans_func_clone (void *ap)
|
139
|
+
{
|
140
|
+
CATrans *ca = (CATrans *) ap;
|
141
|
+
return ca_trans_new(ca->parent, ca->imap);
|
142
|
+
}
|
143
|
+
|
144
|
+
static char *
|
145
|
+
ca_trans_func_ptr_at_addr (void *ap, int32_t addr)
|
146
|
+
{
|
147
|
+
CATrans *ca = (CATrans *) ap;
|
148
|
+
if ( ca->ptr ) {
|
149
|
+
return ca->ptr + ca->bytes * addr;
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
int32_t idx[CA_RANK_MAX];
|
153
|
+
ca_addr2index((CArray *)ca, addr, idx);
|
154
|
+
return ca_ptr_at_index(ca, idx);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
static char *
|
159
|
+
ca_trans_func_ptr_at_index (void *ap, int32_t *idx)
|
160
|
+
{
|
161
|
+
CATrans *ca = (CATrans *) ap;
|
162
|
+
if ( ca->ptr ) {
|
163
|
+
return ca_array_func_ptr_at_index(ca, idx);
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
int32_t *imap = ca->imap;
|
167
|
+
int32_t idx0[CA_RANK_MAX];
|
168
|
+
int32_t i;
|
169
|
+
for (i=0; i<ca->rank; i++) {
|
170
|
+
idx0[imap[i]] = idx[i];
|
171
|
+
}
|
172
|
+
return ca_ptr_at_index(ca->parent, idx0);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
static void
|
177
|
+
ca_trans_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
178
|
+
{
|
179
|
+
CATrans *ca = (CATrans *) ap;
|
180
|
+
int32_t *imap = ca->imap;
|
181
|
+
int32_t idx0[CA_RANK_MAX];
|
182
|
+
int32_t i;
|
183
|
+
for (i=0; i<ca->rank; i++) {
|
184
|
+
idx0[imap[i]] = idx[i];
|
185
|
+
}
|
186
|
+
ca_fetch_index(ca->parent, idx0, ptr);
|
187
|
+
}
|
188
|
+
|
189
|
+
static void
|
190
|
+
ca_trans_func_store_index (void *ap, int32_t *idx, void *ptr)
|
191
|
+
{
|
192
|
+
CATrans *ca = (CATrans *) ap;
|
193
|
+
int32_t *imap = ca->imap;
|
194
|
+
int32_t idx0[CA_RANK_MAX];
|
195
|
+
int32_t i;
|
196
|
+
for (i=0; i<ca->rank; i++) {
|
197
|
+
idx0[imap[i]] = idx[i];
|
198
|
+
}
|
199
|
+
ca_store_index(ca->parent, idx0, ptr);
|
200
|
+
}
|
201
|
+
|
202
|
+
static void
|
203
|
+
ca_trans_func_allocate (void *ap)
|
204
|
+
{
|
205
|
+
CATrans *ca = (CATrans *) ap;
|
206
|
+
ca_attach(ca->parent);
|
207
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
208
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
209
|
+
}
|
210
|
+
|
211
|
+
static void
|
212
|
+
ca_trans_func_attach (void *ap)
|
213
|
+
{
|
214
|
+
CATrans *ca = (CATrans *) ap;
|
215
|
+
ca_attach(ca->parent);
|
216
|
+
/* ca->ptr = ALLOC_N(char, ca_length(ca)); */
|
217
|
+
ca->ptr = malloc_with_check(ca_length(ca));
|
218
|
+
ca_trans_attach(ca);
|
219
|
+
}
|
220
|
+
|
221
|
+
static void
|
222
|
+
ca_trans_func_sync (void *ap)
|
223
|
+
{
|
224
|
+
CATrans *ca = (CATrans *) ap;
|
225
|
+
ca_trans_sync(ca);
|
226
|
+
ca_sync(ca->parent);
|
227
|
+
}
|
228
|
+
|
229
|
+
static void
|
230
|
+
ca_trans_func_detach (void *ap)
|
231
|
+
{
|
232
|
+
CATrans *ca = (CATrans *) ap;
|
233
|
+
free(ca->ptr);
|
234
|
+
ca->ptr = NULL;
|
235
|
+
ca_detach(ca->parent);
|
236
|
+
}
|
237
|
+
|
238
|
+
static void
|
239
|
+
ca_trans_func_copy_data (void *ap, void *ptr)
|
240
|
+
{
|
241
|
+
CATrans *ca = (CATrans *) ap;
|
242
|
+
char *ptr0 = ca->ptr;
|
243
|
+
ca_attach(ca->parent);
|
244
|
+
ca->ptr = ptr;
|
245
|
+
ca_trans_attach(ca);
|
246
|
+
ca->ptr = ptr0;
|
247
|
+
ca_detach(ca->parent);
|
248
|
+
}
|
249
|
+
|
250
|
+
static void
|
251
|
+
ca_trans_func_sync_data (void *ap, void *ptr)
|
252
|
+
{
|
253
|
+
CATrans *ca = (CATrans *) ap;
|
254
|
+
char *ptr0 = ca->ptr;
|
255
|
+
ca_attach(ca->parent);
|
256
|
+
ca->ptr = ptr;
|
257
|
+
ca_trans_sync(ca);
|
258
|
+
ca->ptr = ptr0;
|
259
|
+
ca_sync(ca->parent);
|
260
|
+
ca_detach(ca->parent);
|
261
|
+
}
|
262
|
+
|
263
|
+
static void
|
264
|
+
ca_trans_func_fill_data (void *ap, void *ptr)
|
265
|
+
{
|
266
|
+
CATrans *ca = (CATrans *) ap;
|
267
|
+
ca_attach(ca->parent);
|
268
|
+
ca_trans_fill(ca, ptr);
|
269
|
+
ca_sync(ca->parent);
|
270
|
+
ca_detach(ca->parent);
|
271
|
+
}
|
272
|
+
|
273
|
+
static void
|
274
|
+
ca_trans_func_create_mask (void *ap)
|
275
|
+
{
|
276
|
+
CATrans *ca = (CATrans *) ap;
|
277
|
+
ca_create_mask(ca->parent);
|
278
|
+
ca->mask =
|
279
|
+
(CArray *) ca_trans_new(ca->parent->mask, ca->imap);
|
280
|
+
}
|
281
|
+
|
282
|
+
ca_operation_function_t ca_trans_func = {
|
283
|
+
-1, /* CA_OBJ_TRANSPOSE */
|
284
|
+
CA_VIRTUAL_ARRAY,
|
285
|
+
free_ca_trans,
|
286
|
+
ca_trans_func_clone,
|
287
|
+
ca_trans_func_ptr_at_addr,
|
288
|
+
ca_trans_func_ptr_at_index,
|
289
|
+
NULL,
|
290
|
+
ca_trans_func_fetch_index,
|
291
|
+
NULL,
|
292
|
+
ca_trans_func_store_index,
|
293
|
+
ca_trans_func_allocate,
|
294
|
+
ca_trans_func_attach,
|
295
|
+
ca_trans_func_sync,
|
296
|
+
ca_trans_func_detach,
|
297
|
+
ca_trans_func_copy_data,
|
298
|
+
ca_trans_func_sync_data,
|
299
|
+
ca_trans_func_fill_data,
|
300
|
+
ca_trans_func_create_mask,
|
301
|
+
};
|
302
|
+
|
303
|
+
/* ------------------------------------------------------------------- */
|
304
|
+
|
305
|
+
static void
|
306
|
+
ca_trans_attach_loop (CATrans *ca, int8_t level, int32_t *idx, int32_t *idx0)
|
307
|
+
{
|
308
|
+
int32_t step = ca->step;
|
309
|
+
int32_t dim = ca->dim[level];
|
310
|
+
int32_t *imap = ca->imap;
|
311
|
+
int32_t i;
|
312
|
+
|
313
|
+
if ( level == ca->rank - 1 ) {
|
314
|
+
idx[level] = 0;
|
315
|
+
idx0[imap[level]] = 0;
|
316
|
+
switch ( ca->bytes ) {
|
317
|
+
case 1:
|
318
|
+
{
|
319
|
+
int8_t *p = ca_ptr_at_index(ca, idx);
|
320
|
+
int8_t *q = ca_ptr_at_index(ca->parent, idx0);
|
321
|
+
for (i=0; i<dim; i++) {
|
322
|
+
*p++ = *q;
|
323
|
+
q += step;
|
324
|
+
}
|
325
|
+
}
|
326
|
+
break;
|
327
|
+
case 2:
|
328
|
+
{
|
329
|
+
int16_t *p = ca_ptr_at_index(ca, idx);
|
330
|
+
int16_t *q = ca_ptr_at_index(ca->parent, idx0);
|
331
|
+
for (i=0; i<dim; i++) {
|
332
|
+
*p++ = *q;
|
333
|
+
q += step;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
break;
|
337
|
+
case 4:
|
338
|
+
{
|
339
|
+
int32_t *p = ca_ptr_at_index(ca, idx);
|
340
|
+
int32_t *q = ca_ptr_at_index(ca->parent, idx0);
|
341
|
+
for (i=0; i<dim; i++) {
|
342
|
+
*p++ = *q;
|
343
|
+
q += step;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
break;
|
347
|
+
case 8:
|
348
|
+
{
|
349
|
+
float64_t *p = ca_ptr_at_index(ca, idx);
|
350
|
+
float64_t *q = ca_ptr_at_index(ca->parent, idx0);
|
351
|
+
for (i=0; i<dim; i++) {
|
352
|
+
*p++ = *q;
|
353
|
+
q += step;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
break;
|
357
|
+
default:
|
358
|
+
{
|
359
|
+
char *p = ca_ptr_at_index(ca, idx);
|
360
|
+
char *q = ca_ptr_at_index(ca->parent, idx0);
|
361
|
+
for (i=0; i<dim; i++) {
|
362
|
+
memcpy(p, q, ca->bytes);
|
363
|
+
p += ca->bytes;
|
364
|
+
q += ca->bytes*step;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
}
|
368
|
+
}
|
369
|
+
else {
|
370
|
+
for (i=0; i<dim; i++) {
|
371
|
+
idx[level] = i;
|
372
|
+
idx0[imap[level]] = i;
|
373
|
+
ca_trans_attach_loop(ca, level+1, idx, idx0);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
static void
|
379
|
+
ca_trans_attach (CATrans *ca)
|
380
|
+
{
|
381
|
+
int32_t idx[CA_RANK_MAX];
|
382
|
+
int32_t idx0[CA_RANK_MAX];
|
383
|
+
ca_trans_attach_loop(ca, 0, idx, idx0);
|
384
|
+
}
|
385
|
+
|
386
|
+
static void
|
387
|
+
ca_trans_sync_loop (CATrans *ca, int8_t level, int32_t *idx, int32_t *idx0)
|
388
|
+
{
|
389
|
+
int32_t step = ca->step;
|
390
|
+
int32_t dim = ca->dim[level];
|
391
|
+
int32_t *imap = ca->imap;
|
392
|
+
int32_t i;
|
393
|
+
|
394
|
+
if ( level == ca->rank - 1 ) {
|
395
|
+
idx[level] = 0;
|
396
|
+
idx0[imap[level]] = 0;
|
397
|
+
switch ( ca->bytes ) {
|
398
|
+
case 1:
|
399
|
+
{
|
400
|
+
int8_t *p = ca_ptr_at_index(ca, idx);
|
401
|
+
int8_t *q = ca_ptr_at_index(ca->parent, idx0);
|
402
|
+
for (i=0; i<dim; i++) {
|
403
|
+
*q = *p++;
|
404
|
+
q += step;
|
405
|
+
}
|
406
|
+
}
|
407
|
+
break;
|
408
|
+
case 2:
|
409
|
+
{
|
410
|
+
int16_t *p = ca_ptr_at_index(ca, idx);
|
411
|
+
int16_t *q = ca_ptr_at_index(ca->parent, idx0);
|
412
|
+
for (i=0; i<dim; i++) {
|
413
|
+
*q = *p++;
|
414
|
+
q += step;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
break;
|
418
|
+
case 4:
|
419
|
+
{
|
420
|
+
int32_t *p = ca_ptr_at_index(ca, idx);
|
421
|
+
int32_t *q = ca_ptr_at_index(ca->parent, idx0);
|
422
|
+
for (i=0; i<dim; i++) {
|
423
|
+
*q = *p++;
|
424
|
+
q += step;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
break;
|
428
|
+
case 8:
|
429
|
+
{
|
430
|
+
float64_t *p = ca_ptr_at_index(ca, idx);
|
431
|
+
float64_t *q = ca_ptr_at_index(ca->parent, idx0);
|
432
|
+
for (i=0; i<dim; i++) {
|
433
|
+
*q = *p++;
|
434
|
+
q += step;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
break;
|
438
|
+
default:
|
439
|
+
{
|
440
|
+
char *p = ca_ptr_at_index(ca, idx);
|
441
|
+
char *q = ca_ptr_at_index(ca->parent, idx0);
|
442
|
+
for (i=0; i<dim; i++) {
|
443
|
+
memcpy(q, p, ca->bytes);
|
444
|
+
p += ca->bytes;
|
445
|
+
q += ca->bytes * step;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
}
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
for (i=0; i<dim; i++) {
|
452
|
+
idx[level] = i;
|
453
|
+
idx0[imap[level]] = i;
|
454
|
+
ca_trans_sync_loop(ca, level+1, idx, idx0);
|
455
|
+
}
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
static void
|
460
|
+
ca_trans_sync (CATrans *ca)
|
461
|
+
{
|
462
|
+
int32_t idx[CA_RANK_MAX];
|
463
|
+
int32_t idx0[CA_RANK_MAX];
|
464
|
+
ca_trans_sync_loop(ca, 0, idx, idx0);
|
465
|
+
}
|
466
|
+
|
467
|
+
/*
|
468
|
+
static void
|
469
|
+
ca_trans_fill_loop (CATrans *ca, char *ptr,
|
470
|
+
int8_t level, int32_t *idx0)
|
471
|
+
{
|
472
|
+
int32_t *imap = ca->imap;
|
473
|
+
int32_t i;
|
474
|
+
|
475
|
+
if ( level == ca->rank - 1 ) {
|
476
|
+
for (i=0; i<ca->dim[level]; i++) {
|
477
|
+
idx0[imap[level]] = i;
|
478
|
+
memcpy(ca_ptr_at_index(ca->parent, idx0), ptr, ca->bytes);
|
479
|
+
}
|
480
|
+
}
|
481
|
+
else {
|
482
|
+
for (i=0; i<ca->dim[level]; i++) {
|
483
|
+
idx0[imap[level]] = i;
|
484
|
+
ca_trans_fill_loop(ca, ptr, level+1, idx0);
|
485
|
+
}
|
486
|
+
}
|
487
|
+
}
|
488
|
+
*/
|
489
|
+
|
490
|
+
static void
|
491
|
+
ca_trans_fill (CATrans *ca, char *ptr)
|
492
|
+
{
|
493
|
+
ca_fill(ca->parent, ptr);
|
494
|
+
}
|
495
|
+
|
496
|
+
/* ------------------------------------------------------------------- */
|
497
|
+
|
498
|
+
VALUE
|
499
|
+
rb_ca_trans_new (VALUE cary, int32_t *imap)
|
500
|
+
{
|
501
|
+
volatile VALUE obj;
|
502
|
+
CArray *parent;
|
503
|
+
CATrans *ca;
|
504
|
+
rb_check_carray_object(cary);
|
505
|
+
Data_Get_Struct(cary, CArray, parent);
|
506
|
+
ca = ca_trans_new(parent, imap);
|
507
|
+
obj = ca_wrap_struct(ca);
|
508
|
+
rb_ca_set_parent(obj, cary);
|
509
|
+
rb_ca_data_type_inherit(obj, cary);
|
510
|
+
return obj;
|
511
|
+
}
|
512
|
+
|
513
|
+
/* rdoc:
|
514
|
+
class CArray
|
515
|
+
def transposed
|
516
|
+
end
|
517
|
+
end
|
518
|
+
*/
|
519
|
+
|
520
|
+
static VALUE
|
521
|
+
rb_ca_trans (int argc, VALUE *argv, VALUE self)
|
522
|
+
{
|
523
|
+
volatile VALUE obj;
|
524
|
+
CArray *ca;
|
525
|
+
int32_t imap[CA_RANK_MAX];
|
526
|
+
int32_t i;
|
527
|
+
|
528
|
+
Data_Get_Struct(self, CArray, ca);
|
529
|
+
|
530
|
+
if ( argc == 0 ) {
|
531
|
+
for (i=0; i<ca->rank; i++) {
|
532
|
+
imap[i] = ca->rank - i - 1;
|
533
|
+
}
|
534
|
+
}
|
535
|
+
else if ( argc == ca->rank ) {
|
536
|
+
for (i=0; i<ca->rank; i++) {
|
537
|
+
imap[i] = NUM2INT(argv[i]);
|
538
|
+
}
|
539
|
+
}
|
540
|
+
else {
|
541
|
+
rb_raise(rb_eArgError, "# of arguments should be equal to rank");
|
542
|
+
}
|
543
|
+
|
544
|
+
obj = rb_ca_trans_new(self, imap);
|
545
|
+
|
546
|
+
return obj;
|
547
|
+
}
|
548
|
+
|
549
|
+
static VALUE
|
550
|
+
rb_ca_trans_s_allocate (VALUE klass)
|
551
|
+
{
|
552
|
+
CATrans *ca;
|
553
|
+
return Data_Make_Struct(klass, CATrans, ca_mark, ca_free, ca);
|
554
|
+
}
|
555
|
+
|
556
|
+
static VALUE
|
557
|
+
rb_ca_trans_initialize_copy (VALUE self, VALUE other)
|
558
|
+
{
|
559
|
+
CATrans *ca, *cs;
|
560
|
+
|
561
|
+
Data_Get_Struct(self, CATrans, ca);
|
562
|
+
Data_Get_Struct(other, CATrans, cs);
|
563
|
+
|
564
|
+
ca_trans_setup(ca, cs->parent, cs->imap);
|
565
|
+
|
566
|
+
return self;
|
567
|
+
}
|
568
|
+
|
569
|
+
void
|
570
|
+
Init_ca_obj_transpose ()
|
571
|
+
{
|
572
|
+
rb_cCATrans = rb_define_class("CATranspose", rb_cCAVirtual);
|
573
|
+
|
574
|
+
CA_OBJ_TRANSPOSE = ca_install_obj_type(rb_cCATrans, ca_trans_func);
|
575
|
+
rb_define_const(rb_cObject, "CA_OBJ_TRANSPOSE", INT2NUM(CA_OBJ_TRANSPOSE));
|
576
|
+
|
577
|
+
rb_define_method(rb_cCArray, "transposed", rb_ca_trans, -1);
|
578
|
+
|
579
|
+
rb_define_alloc_func(rb_cCATrans, rb_ca_trans_s_allocate);
|
580
|
+
rb_define_method(rb_cCATrans, "initialize_copy",
|
581
|
+
rb_ca_trans_initialize_copy, 1);
|
582
|
+
}
|