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_object.c
ADDED
@@ -0,0 +1,777 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_obj_object.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
|
+
/*
|
14
|
+
CAObject's template methods
|
15
|
+
|
16
|
+
* Initializer
|
17
|
+
|
18
|
+
initialize(...)
|
19
|
+
|
20
|
+
call super(type, dim, bytes) in this method
|
21
|
+
|
22
|
+
* For readable array
|
23
|
+
|
24
|
+
fetch_addr(addr) ### at least one of these two methods
|
25
|
+
fetch_index(idx)
|
26
|
+
|
27
|
+
copy_data(data)
|
28
|
+
|
29
|
+
* For writable array
|
30
|
+
|
31
|
+
store_addr(addr, val) ### at lease one of these two methods
|
32
|
+
store_index(idx, val)
|
33
|
+
|
34
|
+
sync_data(data)
|
35
|
+
fill_data(value)
|
36
|
+
|
37
|
+
*/
|
38
|
+
|
39
|
+
#include "carray.h"
|
40
|
+
|
41
|
+
VALUE rb_cCAObject;
|
42
|
+
|
43
|
+
|
44
|
+
/* rdoc:
|
45
|
+
class CAObject < CAVirtual # :nodoc:
|
46
|
+
end
|
47
|
+
*/
|
48
|
+
|
49
|
+
|
50
|
+
/* ---------------------------------------------------------------------- */
|
51
|
+
|
52
|
+
static int8_t CA_OBJ_OBJECT_MASK;
|
53
|
+
static VALUE rb_cCAObjectMask;
|
54
|
+
|
55
|
+
/* rdoc:
|
56
|
+
class CAObjectMask < CAVirtual # :nodoc:
|
57
|
+
end
|
58
|
+
*/
|
59
|
+
|
60
|
+
|
61
|
+
static CAObjectMask *
|
62
|
+
ca_objmask_new (VALUE array, int8_t rank, int32_t *dim)
|
63
|
+
{
|
64
|
+
CAObjectMask *ca = ALLOC(CAObjectMask);
|
65
|
+
ca_wrap_setup_null((CArray *)ca, CA_BOOLEAN, rank, dim, 0, NULL);
|
66
|
+
ca->obj_type = CA_OBJ_OBJECT_MASK;
|
67
|
+
ca->array = array;
|
68
|
+
|
69
|
+
return ca;
|
70
|
+
}
|
71
|
+
|
72
|
+
static VALUE
|
73
|
+
ca_objmask_mask_data (void *ap)
|
74
|
+
{
|
75
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
76
|
+
return rb_funcall(rb_ivar_get(ca->array, rb_intern("__data__")),
|
77
|
+
rb_intern("mask"), 0);
|
78
|
+
}
|
79
|
+
|
80
|
+
static void *
|
81
|
+
ca_objmask_func_clone (void *ap)
|
82
|
+
{
|
83
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
84
|
+
return ca_objmask_new(ca->array, ca->rank, ca->dim);
|
85
|
+
}
|
86
|
+
|
87
|
+
void
|
88
|
+
ca_objmask_func_fetch_addr (void *ap, int32_t addr, void *ptr)
|
89
|
+
{
|
90
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
91
|
+
volatile VALUE ridx, raddr, rval;
|
92
|
+
int i;
|
93
|
+
|
94
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_addr"), Qtrue) ) {
|
95
|
+
raddr = LONG2NUM(addr);
|
96
|
+
rval = rb_funcall(ca->array, rb_intern("mask_fetch_addr"), 1, raddr);
|
97
|
+
*(uint8_t*) ptr = NUM2INT(rval) == 0 ? 0 : 1;
|
98
|
+
ca_array_func_store_addr(ca, addr, ptr);
|
99
|
+
}
|
100
|
+
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
|
101
|
+
int32_t idx[CA_RANK_MAX];
|
102
|
+
ca_addr2index(ca, addr, idx);
|
103
|
+
ridx = rb_ary_new2(ca->rank);
|
104
|
+
for (i=0; i<ca->rank; i++) {
|
105
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
106
|
+
}
|
107
|
+
rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
|
108
|
+
*(uint8_t*) ptr = NUM2INT(rval) == 0 ? 0 : 1;
|
109
|
+
ca_array_func_store_index(ca, idx, ptr);
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
ca_array_func_fetch_addr(ca, addr, ptr);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
void
|
117
|
+
ca_objmask_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
118
|
+
{
|
119
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
120
|
+
volatile VALUE ridx, raddr, rval;
|
121
|
+
int i;
|
122
|
+
|
123
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_index"), Qtrue) ) {
|
124
|
+
ridx = rb_ary_new2(ca->rank);
|
125
|
+
for (i=0; i<ca->rank; i++) {
|
126
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
127
|
+
}
|
128
|
+
rval = rb_funcall(ca->array, rb_intern("mask_fetch_index"), 1, ridx);
|
129
|
+
*(uint8_t*) ptr = NUM2INT(rval) == 0 ? 0 : 1;
|
130
|
+
ca_array_func_store_index(ca, idx, ptr);
|
131
|
+
}
|
132
|
+
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_fetch_addr"), Qtrue) ) {
|
133
|
+
int32_t addr = ca_index2addr(ca, idx);
|
134
|
+
raddr = LONG2NUM(addr);
|
135
|
+
rval = rb_funcall(ca->array, rb_intern("mask_fetch_addr"), 1, raddr);
|
136
|
+
*(uint8_t*) ptr = NUM2INT(rval) == 0 ? 0 : 1;
|
137
|
+
ca_array_func_store_addr(ca, addr, ptr);
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
ca_array_func_fetch_index(ca, idx, ptr);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
void
|
146
|
+
ca_objmask_func_store_addr (void *ap, int32_t addr, void *ptr)
|
147
|
+
{
|
148
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
149
|
+
volatile VALUE ridx, raddr, rval;
|
150
|
+
int i;
|
151
|
+
|
152
|
+
ca_array_func_store_addr(ca, addr, ptr);
|
153
|
+
rval = INT2FIX( *(uint8_t*)ptr );
|
154
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_addr"), Qtrue) ) {
|
155
|
+
raddr = LONG2NUM(addr);
|
156
|
+
rb_funcall(ca->array, rb_intern("mask_store_addr"), 2, raddr, rval);
|
157
|
+
}
|
158
|
+
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
|
159
|
+
int32_t idx[CA_RANK_MAX];
|
160
|
+
ca_addr2index(ca, addr, idx);
|
161
|
+
ridx = rb_ary_new2(ca->rank);
|
162
|
+
for (i=0; i<ca->rank; i++) {
|
163
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
164
|
+
}
|
165
|
+
rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
void
|
170
|
+
ca_objmask_func_store_index (void *ap, int32_t *idx, void *ptr)
|
171
|
+
{
|
172
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
173
|
+
volatile VALUE ridx, raddr, rval;
|
174
|
+
int i;
|
175
|
+
|
176
|
+
ca_array_func_store_index(ca, idx, ptr);
|
177
|
+
rval = INT2FIX( *(uint8_t*)ptr );
|
178
|
+
|
179
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_index"), Qtrue) ) {
|
180
|
+
ridx = rb_ary_new2(ca->rank);
|
181
|
+
for (i=0; i<ca->rank; i++) {
|
182
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
183
|
+
}
|
184
|
+
rb_funcall(ca->array, rb_intern("mask_store_index"), 2, ridx, rval);
|
185
|
+
}
|
186
|
+
else if ( rb_obj_respond_to(ca->array, rb_intern("mask_store_addr"), Qtrue) ) {
|
187
|
+
int32_t addr = ca_index2addr(ca, idx);
|
188
|
+
raddr = LONG2NUM(addr);
|
189
|
+
rb_funcall(ca->array, rb_intern("mask_store_addr"), 2, raddr, rval);
|
190
|
+
}
|
191
|
+
|
192
|
+
}
|
193
|
+
|
194
|
+
static void
|
195
|
+
ca_objmask_func_attach (void *ap)
|
196
|
+
{
|
197
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
198
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_copy_data"), Qtrue) ) {
|
199
|
+
rb_funcall(ca->array, rb_intern("mask_copy_data"),
|
200
|
+
1, ca_objmask_mask_data(ca));
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
void
|
205
|
+
ca_objmask_func_sync (void *ap)
|
206
|
+
{
|
207
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
208
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_sync_data"), Qtrue) ) {
|
209
|
+
rb_funcall(ca->array, rb_intern("mask_sync_data"),
|
210
|
+
1, ca_objmask_mask_data(ca));
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
static void
|
215
|
+
ca_objmask_func_copy_data (void *ap, void *ptr)
|
216
|
+
{
|
217
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
218
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_copy_data"), Qtrue) ) {
|
219
|
+
char *ptr0 = ca->ptr;
|
220
|
+
ca->ptr = ptr;
|
221
|
+
rb_funcall(ca->array, rb_intern("mask_copy_data"),
|
222
|
+
1, ca_objmask_mask_data(ca));
|
223
|
+
ca->ptr = ptr0;
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
ca_array_func_copy_data(ca, ptr);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
static void
|
231
|
+
ca_objmask_func_sync_data (void *ap, void *ptr)
|
232
|
+
{
|
233
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
234
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_copy_data"), Qtrue) ) {
|
235
|
+
char *ptr0 = ca->ptr;
|
236
|
+
ca->ptr = ptr;
|
237
|
+
rb_funcall(ca->array, rb_intern("mask_sync_data"),
|
238
|
+
1, ca_objmask_mask_data(ca));
|
239
|
+
ca->ptr = ptr0;
|
240
|
+
}
|
241
|
+
else {
|
242
|
+
ca_array_func_sync_data(ca, ptr);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
void
|
247
|
+
ca_objmask_func_fill_data (void *ap, void *val)
|
248
|
+
{
|
249
|
+
CAObjectMask *ca = (CAObjectMask *) ap;
|
250
|
+
ca_array_func_fill_data(ca, val);
|
251
|
+
if ( rb_obj_respond_to(ca->array, rb_intern("mask_fill_data"), Qtrue) ) {
|
252
|
+
rb_funcall(ca->array, rb_intern("mask_fill_data"),
|
253
|
+
1, INT2FIX(*(uint8_t*)val));
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
static ca_operation_function_t ca_objmask_func = {
|
258
|
+
-1, /* CA_OBJ_OBJECT_MASK */
|
259
|
+
CA_REAL_ARRAY,
|
260
|
+
free_ca_wrap,
|
261
|
+
ca_objmask_func_clone,
|
262
|
+
ca_array_func_ptr_at_addr,
|
263
|
+
ca_array_func_ptr_at_index,
|
264
|
+
ca_objmask_func_fetch_addr,
|
265
|
+
ca_objmask_func_fetch_index,
|
266
|
+
ca_objmask_func_store_addr,
|
267
|
+
ca_objmask_func_store_index,
|
268
|
+
ca_array_func_allocate,
|
269
|
+
ca_objmask_func_attach,
|
270
|
+
ca_objmask_func_sync,
|
271
|
+
ca_array_func_detach,
|
272
|
+
ca_objmask_func_copy_data,
|
273
|
+
ca_objmask_func_sync_data,
|
274
|
+
ca_objmask_func_fill_data,
|
275
|
+
ca_array_func_create_mask,
|
276
|
+
};
|
277
|
+
|
278
|
+
static VALUE
|
279
|
+
rb_ca_objmask_s_allocate (VALUE klass)
|
280
|
+
{
|
281
|
+
CAObjectMask *ca;
|
282
|
+
return Data_Make_Struct(klass, CAObjectMask, ca_mark, ca_free, ca);
|
283
|
+
}
|
284
|
+
|
285
|
+
static VALUE
|
286
|
+
rb_ca_objmask_initialize_copy (VALUE self, VALUE other)
|
287
|
+
{
|
288
|
+
CAObjectMask *ca, *cs;
|
289
|
+
|
290
|
+
Data_Get_Struct(self, CAObjectMask, ca);
|
291
|
+
Data_Get_Struct(other, CAObjectMask, cs);
|
292
|
+
|
293
|
+
carray_setup((CArray *)ca, CA_BOOLEAN, cs->rank, cs->dim, 0, NULL);
|
294
|
+
ca->obj_type = CA_OBJ_OBJECT_MASK;
|
295
|
+
ca->array = cs->array;
|
296
|
+
|
297
|
+
return self;
|
298
|
+
}
|
299
|
+
|
300
|
+
/* -------------------------------------------------------------------- */
|
301
|
+
|
302
|
+
static int
|
303
|
+
ca_object_setup (CAObject *ca,
|
304
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes)
|
305
|
+
{
|
306
|
+
int32_t elements;
|
307
|
+
double length;
|
308
|
+
int32_t i;
|
309
|
+
|
310
|
+
/* check arguments */
|
311
|
+
|
312
|
+
CA_CHECK_DATA_TYPE(data_type);
|
313
|
+
CA_CHECK_RANK(rank);
|
314
|
+
CA_CHECK_DIM(rank, dim);
|
315
|
+
CA_CHECK_BYTES(data_type, bytes);
|
316
|
+
|
317
|
+
/* calculate total number of elements */
|
318
|
+
|
319
|
+
elements = 1;
|
320
|
+
length = bytes;
|
321
|
+
for (i=0; i<rank; i++) {
|
322
|
+
elements *= dim[i];
|
323
|
+
length *= dim[i];
|
324
|
+
}
|
325
|
+
|
326
|
+
if ( length > CA_LENGTH_MAX ) {
|
327
|
+
rb_raise(rb_eRuntimeError, "too large byte length");
|
328
|
+
}
|
329
|
+
|
330
|
+
ca->obj_type = CA_OBJ_OBJECT;
|
331
|
+
ca->data_type = data_type;
|
332
|
+
ca->flags = 0;
|
333
|
+
ca->rank = rank;
|
334
|
+
ca->bytes = bytes;
|
335
|
+
ca->elements = elements;
|
336
|
+
ca->ptr = NULL;
|
337
|
+
ca->mask = NULL;
|
338
|
+
ca->parent = NULL;
|
339
|
+
ca->attach = 0;
|
340
|
+
ca->nosync = 0;
|
341
|
+
|
342
|
+
ca->dim = ALLOC_N(int32_t, rank);
|
343
|
+
|
344
|
+
ca->data = ca_wrap_new_null(data_type, rank, dim, bytes, NULL);
|
345
|
+
|
346
|
+
memcpy(ca->dim, dim, rank * sizeof(int32_t));
|
347
|
+
|
348
|
+
return 0;
|
349
|
+
}
|
350
|
+
|
351
|
+
static CAObject *
|
352
|
+
ca_object_new (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes)
|
353
|
+
{
|
354
|
+
CAObject *ca = ALLOC(CAObject);
|
355
|
+
ca_object_setup(ca, data_type, rank, dim, bytes);
|
356
|
+
return ca;
|
357
|
+
}
|
358
|
+
|
359
|
+
static void
|
360
|
+
free_ca_object (void *ap)
|
361
|
+
{
|
362
|
+
CAObject *ca = (CAObject *) ap;
|
363
|
+
if ( ca != NULL ) {
|
364
|
+
/* ca->mask will be GC-ed by Ruby interpreter */
|
365
|
+
xfree(ca->dim);
|
366
|
+
xfree(ca);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
/* ------------------------------------------------------------------- */
|
371
|
+
|
372
|
+
static void *
|
373
|
+
ca_object_func_clone (void *ap)
|
374
|
+
{
|
375
|
+
CAObject *ca = (CAObject *) ap;
|
376
|
+
return ca_object_new(ca->bytes, ca->rank, ca->dim, ca->bytes);
|
377
|
+
}
|
378
|
+
|
379
|
+
#define ca_object_func_ptr_at_addr ca_array_func_ptr_at_addr
|
380
|
+
#define ca_object_func_ptr_at_index ca_array_func_ptr_at_index
|
381
|
+
|
382
|
+
static void
|
383
|
+
ca_object_func_fetch_addr (void *ap, int32_t addr, void *ptr)
|
384
|
+
{
|
385
|
+
CAObject *ca = (CAObject *) ap;
|
386
|
+
volatile VALUE ridx, raddr, rval;
|
387
|
+
int i;
|
388
|
+
if ( rb_obj_respond_to(ca->self, rb_intern("fetch_addr"), Qtrue) ) {
|
389
|
+
raddr = LONG2NUM(addr);
|
390
|
+
rval = rb_funcall(ca->self, rb_intern("fetch_addr"), 1, raddr);
|
391
|
+
if ( rval == CA_UNDEF ) {
|
392
|
+
ca_update_mask(ca);
|
393
|
+
if ( ! ca->mask ) {
|
394
|
+
ca_create_mask(ca);
|
395
|
+
}
|
396
|
+
*(boolean8_t*)ca_ptr_at_addr(ca->mask, addr) = 1;
|
397
|
+
if ( ca->data_type == CA_OBJECT ) {
|
398
|
+
rb_ca_obj2ptr(ca->self, INT2FIX(0), ptr);
|
399
|
+
}
|
400
|
+
}
|
401
|
+
else {
|
402
|
+
if ( ca_has_mask(ca) ) {
|
403
|
+
*(boolean8_t*)ca_ptr_at_addr(ca->mask, addr) = 0;
|
404
|
+
}
|
405
|
+
rb_ca_obj2ptr(ca->self, rval, ptr);
|
406
|
+
}
|
407
|
+
}
|
408
|
+
else {
|
409
|
+
int32_t idx[CA_RANK_MAX];
|
410
|
+
ca_addr2index(ca, addr, idx);
|
411
|
+
ridx = rb_ary_new2(ca->rank);
|
412
|
+
for (i=0; i<ca->rank; i++) {
|
413
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
414
|
+
}
|
415
|
+
rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
|
416
|
+
if ( rval == CA_UNDEF ) {
|
417
|
+
ca_update_mask(ca);
|
418
|
+
if ( ! ca->mask ) {
|
419
|
+
ca_create_mask(ca);
|
420
|
+
}
|
421
|
+
*(boolean8_t*)ca_ptr_at_index(ca->mask, idx) = 1;
|
422
|
+
if ( ca->data_type == CA_OBJECT ) {
|
423
|
+
rb_ca_obj2ptr(ca->self, INT2FIX(0), ptr);
|
424
|
+
}
|
425
|
+
}
|
426
|
+
else {
|
427
|
+
if ( ca_has_mask(ca) ) {
|
428
|
+
*(boolean8_t*)ca_ptr_at_index(ca->mask, idx) = 0;
|
429
|
+
}
|
430
|
+
rb_ca_obj2ptr(ca->self, rval, ptr);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
static void
|
436
|
+
ca_object_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
437
|
+
{
|
438
|
+
CAObject *ca = (CAObject *) ap;
|
439
|
+
volatile VALUE ridx, raddr, rval;
|
440
|
+
int i;
|
441
|
+
if ( rb_obj_respond_to(ca->self, rb_intern("fetch_index"), Qtrue) ) {
|
442
|
+
ridx = rb_ary_new2(ca->rank);
|
443
|
+
for (i=0; i<ca->rank; i++) {
|
444
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
445
|
+
}
|
446
|
+
rval = rb_funcall(ca->self, rb_intern("fetch_index"), 1, ridx);
|
447
|
+
if ( rval == CA_UNDEF ) {
|
448
|
+
ca_update_mask(ca);
|
449
|
+
if ( ! ca->mask ) {
|
450
|
+
ca_create_mask(ca);
|
451
|
+
}
|
452
|
+
*(boolean8_t*)ca_ptr_at_index(ca->mask, idx) = 1;
|
453
|
+
if ( ca->data_type == CA_OBJECT ) {
|
454
|
+
rb_ca_obj2ptr(ca->self, INT2FIX(0), ptr);
|
455
|
+
}
|
456
|
+
}
|
457
|
+
else {
|
458
|
+
if ( ca_has_mask(ca) ) {
|
459
|
+
*(boolean8_t*)ca_ptr_at_index(ca->mask, idx) = 0;
|
460
|
+
}
|
461
|
+
rb_ca_obj2ptr(ca->self, rval, ptr);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
else {
|
465
|
+
int32_t addr = ca_index2addr(ca, idx);
|
466
|
+
raddr = LONG2NUM(addr);
|
467
|
+
rval = rb_funcall(ca->self, rb_intern("fetch_addr"), 1, raddr);
|
468
|
+
if ( rval == CA_UNDEF ) {
|
469
|
+
ca_update_mask(ca);
|
470
|
+
if ( ! ca->mask ) {
|
471
|
+
ca_create_mask(ca);
|
472
|
+
}
|
473
|
+
*(boolean8_t*)ca_ptr_at_addr(ca->mask, addr) = 1;
|
474
|
+
if ( ca->data_type == CA_OBJECT ) {
|
475
|
+
rb_ca_obj2ptr(ca->self, INT2FIX(0), ptr);
|
476
|
+
}
|
477
|
+
}
|
478
|
+
else {
|
479
|
+
if ( ca_has_mask(ca) ) {
|
480
|
+
*(boolean8_t*)ca_ptr_at_addr(ca->mask, addr) = 0;
|
481
|
+
}
|
482
|
+
rb_ca_obj2ptr(ca->self, rval, ptr);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
static void
|
488
|
+
ca_object_func_store_addr (void *ap, int32_t addr, void *ptr)
|
489
|
+
{
|
490
|
+
CAObject *ca = (CAObject *) ap;
|
491
|
+
volatile VALUE ridx, raddr, rval;
|
492
|
+
int i;
|
493
|
+
if ( rb_obj_respond_to(ca->self, rb_intern("store_addr"), Qtrue) ) {
|
494
|
+
raddr = LONG2NUM(addr);
|
495
|
+
rval = rb_ca_ptr2obj(ca->self, ptr);
|
496
|
+
rb_funcall(ca->self, rb_intern("store_addr"), 2, raddr, rval);
|
497
|
+
}
|
498
|
+
else {
|
499
|
+
int32_t idx[CA_RANK_MAX];
|
500
|
+
ca_addr2index(ca, addr, idx);
|
501
|
+
ridx = rb_ary_new2(ca->rank);
|
502
|
+
for (i=0; i<ca->rank; i++) {
|
503
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
504
|
+
}
|
505
|
+
rval = rb_ca_ptr2obj(ca->self, ptr);
|
506
|
+
rb_funcall(ca->self, rb_intern("store_index"), 2, ridx, rval);
|
507
|
+
}
|
508
|
+
}
|
509
|
+
|
510
|
+
static void
|
511
|
+
ca_object_func_store_index (void *ap, int32_t *idx, void *ptr)
|
512
|
+
{
|
513
|
+
CAObject *ca = (CAObject *) ap;
|
514
|
+
volatile VALUE ridx, raddr, rval;
|
515
|
+
int i;
|
516
|
+
if ( rb_obj_respond_to(ca->self, rb_intern("store_index"), Qtrue) ) {
|
517
|
+
ridx = rb_ary_new2(ca->rank);
|
518
|
+
for (i=0; i<ca->rank; i++) {
|
519
|
+
rb_ary_store(ridx, i, INT2NUM(idx[i]));
|
520
|
+
}
|
521
|
+
rval = rb_ca_ptr2obj(ca->self, ptr);
|
522
|
+
rb_funcall(ca->self, rb_intern("store_index"), 2, ridx, rval);
|
523
|
+
}
|
524
|
+
else {
|
525
|
+
int32_t addr = ca_index2addr(ca, idx);
|
526
|
+
raddr = LONG2NUM(addr);
|
527
|
+
rval = rb_ca_ptr2obj(ca->self, ptr);
|
528
|
+
rb_funcall(ca->self, rb_intern("store_addr"), 2, raddr, rval);
|
529
|
+
}
|
530
|
+
}
|
531
|
+
|
532
|
+
static void
|
533
|
+
ca_object_func_allocate (void *ap)
|
534
|
+
{
|
535
|
+
CAObject *ca = (CAObject *) ap;
|
536
|
+
/* ca->data->ptr = ALLOC_N(char, ca_length(ca)); */
|
537
|
+
ca->data->ptr = malloc_with_check(ca_length(ca));
|
538
|
+
if ( ca_is_object_type(ca->data) ) { /* GC safe */
|
539
|
+
VALUE *p = (VALUE *) ca->data->ptr;
|
540
|
+
VALUE zero = INT2FIX(0);
|
541
|
+
int32_t i;
|
542
|
+
for (i=0; i<ca->elements; i++) {
|
543
|
+
*p++ = zero;
|
544
|
+
}
|
545
|
+
}
|
546
|
+
ca->ptr = ca->data->ptr;
|
547
|
+
}
|
548
|
+
|
549
|
+
static void
|
550
|
+
ca_object_func_attach (void *ap)
|
551
|
+
{
|
552
|
+
CAObject *ca = (CAObject *) ap;
|
553
|
+
volatile VALUE data = rb_ivar_get(ca->self, rb_intern("__data__"));
|
554
|
+
/* ca->data->ptr = ALLOC_N(char, ca_length(ca)); */
|
555
|
+
ca->data->ptr = malloc_with_check(ca_length(ca));
|
556
|
+
if ( ca_is_object_type(ca->data) ) { /* GC safe */
|
557
|
+
VALUE *p = (VALUE *) ca->data->ptr;
|
558
|
+
VALUE zero = INT2FIX(0);
|
559
|
+
int32_t i;
|
560
|
+
for (i=0; i<ca->elements; i++) {
|
561
|
+
*p++ = zero;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
ca->ptr = ca->data->ptr;
|
565
|
+
rb_funcall(ca->self, rb_intern("copy_data"), 1, data);
|
566
|
+
if ( ca_has_mask(ca->data) ) {
|
567
|
+
ca_update_mask(ca);
|
568
|
+
if ( ! ca->mask ) {
|
569
|
+
ca_create_mask(ca);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
}
|
573
|
+
|
574
|
+
static void
|
575
|
+
ca_object_func_sync (void *ap)
|
576
|
+
{
|
577
|
+
CAObject *ca = (CAObject *) ap;
|
578
|
+
rb_funcall(ca->self, rb_intern("sync_data"),
|
579
|
+
1, rb_ivar_get(ca->self, rb_intern("__data__")));
|
580
|
+
}
|
581
|
+
|
582
|
+
static void
|
583
|
+
ca_object_func_detach (void *ap)
|
584
|
+
{
|
585
|
+
CAObject *ca = (CAObject *) ap;
|
586
|
+
free(ca->data->ptr);
|
587
|
+
ca->data->ptr = NULL;
|
588
|
+
ca->ptr = NULL;
|
589
|
+
}
|
590
|
+
|
591
|
+
static void
|
592
|
+
ca_object_func_copy_data (void *ap, void *ptr)
|
593
|
+
{
|
594
|
+
CAObject *ca = (CAObject *) ap;
|
595
|
+
char *ptr0 = ca->data->ptr;
|
596
|
+
ca->data->ptr = ptr;
|
597
|
+
rb_funcall(ca->self, rb_intern("copy_data"),
|
598
|
+
1, rb_ivar_get(ca->self, rb_intern("__data__")));
|
599
|
+
ca->data->ptr = ptr0;
|
600
|
+
}
|
601
|
+
|
602
|
+
static void
|
603
|
+
ca_object_func_sync_data (void *ap, void *ptr)
|
604
|
+
{
|
605
|
+
CAObject *ca = (CAObject *) ap;
|
606
|
+
char *ptr0 = ca->data->ptr;
|
607
|
+
ca->data->ptr = ptr;
|
608
|
+
rb_funcall(ca->self, rb_intern("sync_data"),
|
609
|
+
1, rb_ivar_get(ca->self, rb_intern("__data__")));
|
610
|
+
ca->data->ptr = ptr0;
|
611
|
+
}
|
612
|
+
|
613
|
+
static void
|
614
|
+
ca_object_func_fill_data (void *ap, void *ptr)
|
615
|
+
{
|
616
|
+
CAObject *ca = (CAObject *) ap;
|
617
|
+
volatile VALUE rval;
|
618
|
+
rval = rb_ca_ptr2obj(ca->self, ptr);
|
619
|
+
rb_funcall(ca->self, rb_intern("fill_data"), 1, rval);
|
620
|
+
}
|
621
|
+
|
622
|
+
static void
|
623
|
+
ca_object_func_create_mask (void *ap)
|
624
|
+
{
|
625
|
+
CAObject *ca = (CAObject *) ap;
|
626
|
+
volatile VALUE rmask;
|
627
|
+
if ( rb_obj_respond_to(ca->self, rb_intern("create_mask"), Qtrue) ) {
|
628
|
+
rb_funcall(ca->self, rb_intern("create_mask"), 0);
|
629
|
+
}
|
630
|
+
else {
|
631
|
+
rb_raise(rb_eRuntimeError, "can't create mask for CAObject");
|
632
|
+
}
|
633
|
+
ca_update_mask(ca->data);
|
634
|
+
if ( ! ca->data->mask ) {
|
635
|
+
ca_create_mask(ca->data);
|
636
|
+
}
|
637
|
+
ca->mask = (CArray*) ca_objmask_new(ca->self, ca->rank, ca->dim);
|
638
|
+
ca->mask->ptr = ca->data->mask->ptr;
|
639
|
+
rmask = ca_wrap_struct(ca->mask);
|
640
|
+
rb_ivar_set(ca->self, rb_intern("mask"), rmask);
|
641
|
+
}
|
642
|
+
|
643
|
+
ca_operation_function_t ca_object_func = {
|
644
|
+
-1, /* CA_OBJ_OBJECT */
|
645
|
+
CA_VIRTUAL_ARRAY,
|
646
|
+
free_ca_object,
|
647
|
+
ca_object_func_clone,
|
648
|
+
ca_object_func_ptr_at_addr,
|
649
|
+
ca_object_func_ptr_at_index,
|
650
|
+
ca_object_func_fetch_addr,
|
651
|
+
ca_object_func_fetch_index,
|
652
|
+
ca_object_func_store_addr,
|
653
|
+
ca_object_func_store_index,
|
654
|
+
ca_object_func_allocate,
|
655
|
+
ca_object_func_attach,
|
656
|
+
ca_object_func_sync,
|
657
|
+
ca_object_func_detach,
|
658
|
+
ca_object_func_copy_data,
|
659
|
+
ca_object_func_sync_data,
|
660
|
+
ca_object_func_fill_data,
|
661
|
+
ca_object_func_create_mask,
|
662
|
+
};
|
663
|
+
|
664
|
+
/* ------------------------------------------------------------------- */
|
665
|
+
|
666
|
+
static VALUE
|
667
|
+
rb_ca_object_s_allocate (VALUE klass)
|
668
|
+
{
|
669
|
+
CAObject *ca;
|
670
|
+
return Data_Make_Struct(klass, CAObject, ca_mark, ca_free, ca);
|
671
|
+
}
|
672
|
+
|
673
|
+
static VALUE
|
674
|
+
rb_ca_object_initialize_copy (VALUE self, VALUE other)
|
675
|
+
{
|
676
|
+
volatile VALUE data;
|
677
|
+
CAObject *ca, *cs;
|
678
|
+
|
679
|
+
Data_Get_Struct(self, CAObject, ca);
|
680
|
+
Data_Get_Struct(other, CAObject, cs);
|
681
|
+
|
682
|
+
ca_object_setup(ca, cs->data_type, cs->rank, cs->dim, cs->bytes);
|
683
|
+
ca->self = self;
|
684
|
+
|
685
|
+
rb_ca_data_type_inherit(self, other);
|
686
|
+
|
687
|
+
data = ca_wrap_struct(ca->data);
|
688
|
+
rb_ca_data_type_inherit(data, self);
|
689
|
+
rb_ivar_set(self, rb_intern("__data__"), data);
|
690
|
+
|
691
|
+
ca_update_mask(cs);
|
692
|
+
if ( cs->mask ) {
|
693
|
+
ca->mask = cs->mask;
|
694
|
+
rb_ivar_set(self, rb_intern("mask"),
|
695
|
+
rb_ivar_get(other, rb_intern("mask")));
|
696
|
+
}
|
697
|
+
|
698
|
+
return self;
|
699
|
+
}
|
700
|
+
|
701
|
+
static VALUE
|
702
|
+
rb_ca_object_initialize (int argc, VALUE *argv, VALUE self)
|
703
|
+
{
|
704
|
+
volatile VALUE rtype, rdim, ropt, rbytes = Qnil, rrdonly = Qnil, rparent = Qnil, rdata;
|
705
|
+
CAObject *ca;
|
706
|
+
int8_t data_type, rank;
|
707
|
+
int32_t dim[CA_RANK_MAX];
|
708
|
+
int32_t bytes;
|
709
|
+
int i;
|
710
|
+
|
711
|
+
rb_scan_args(argc, argv, "21", &rtype, &rdim, &ropt);
|
712
|
+
rb_scan_options(ropt, "bytes,read_only,parent",
|
713
|
+
&rbytes, &rrdonly, &rparent);
|
714
|
+
|
715
|
+
if ( ( ! NIL_P(rparent) ) && rb_obj_is_carray(rparent) ) {
|
716
|
+
rb_raise(rb_eRuntimeError, "option :parent should be a carray");
|
717
|
+
}
|
718
|
+
|
719
|
+
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
720
|
+
rb_ca_data_type_import(self, rtype);
|
721
|
+
|
722
|
+
Check_Type(rdim, T_ARRAY);
|
723
|
+
|
724
|
+
rank = RARRAY_LEN(rdim);
|
725
|
+
for (i=0; i<rank; i++) {
|
726
|
+
dim[i] = NUM2INT(rb_ary_entry(rdim, i));
|
727
|
+
}
|
728
|
+
|
729
|
+
Data_Get_Struct(self, CAObject, ca);
|
730
|
+
ca_object_setup(ca, data_type, rank, dim, bytes);
|
731
|
+
ca->self = self;
|
732
|
+
|
733
|
+
rdata = ca_wrap_struct(ca->data);
|
734
|
+
rb_ca_data_type_inherit(rdata, self);
|
735
|
+
|
736
|
+
rb_ivar_set(self, rb_intern("__data__"), rdata);
|
737
|
+
|
738
|
+
if ( RTEST(rrdonly) ) {
|
739
|
+
ca_set_flag(ca, CA_FLAG_READ_ONLY);
|
740
|
+
}
|
741
|
+
|
742
|
+
if ( ! NIL_P(rparent) ) {
|
743
|
+
CArray *cp;
|
744
|
+
Data_Get_Struct(rparent, CArray, cp);
|
745
|
+
ca->parent = cp;
|
746
|
+
rb_ca_set_parent(self, rparent);
|
747
|
+
}
|
748
|
+
|
749
|
+
ca_update_mask(ca);
|
750
|
+
|
751
|
+
return Qnil;
|
752
|
+
}
|
753
|
+
|
754
|
+
void
|
755
|
+
Init_ca_obj_object ()
|
756
|
+
{
|
757
|
+
rb_cCAObjectMask = rb_define_class("CAObjectMask", rb_cCArray);
|
758
|
+
|
759
|
+
CA_OBJ_OBJECT_MASK = ca_install_obj_type(rb_cCAObjectMask, ca_objmask_func);
|
760
|
+
rb_define_const(rb_cObject, "CA_OBJ_OBJECT_MASK", INT2NUM(CA_OBJ_OBJECT_MASK));
|
761
|
+
|
762
|
+
rb_define_alloc_func(rb_cCAObjectMask, rb_ca_objmask_s_allocate);
|
763
|
+
rb_define_method(rb_cCAObjectMask, "initialize_copy",
|
764
|
+
rb_ca_objmask_initialize_copy, 1);
|
765
|
+
|
766
|
+
|
767
|
+
rb_define_const(rb_cObject, "CA_OBJ_OBJECT", INT2NUM(CA_OBJ_OBJECT));
|
768
|
+
|
769
|
+
rb_define_alloc_func(rb_cCAObject, rb_ca_object_s_allocate);
|
770
|
+
rb_define_method(rb_cCAObject, "initialize_copy",
|
771
|
+
rb_ca_object_initialize_copy, 1);
|
772
|
+
rb_define_method(rb_cCAObject, "initialize",
|
773
|
+
rb_ca_object_initialize, -1);
|
774
|
+
|
775
|
+
}
|
776
|
+
|
777
|
+
|