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_iter_window.c
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_iter_window.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
|
+
int8_t rank;
|
17
|
+
int32_t dim[CA_RANK_MAX];
|
18
|
+
CArray *reference;
|
19
|
+
CArray * (*kernel_at_addr)(void *, int32_t, CArray *);
|
20
|
+
CArray * (*kernel_at_index)(void *, int32_t *, CArray *);
|
21
|
+
CArray * (*kernel_move_to_addr)(void *, int32_t, CArray *);
|
22
|
+
CArray * (*kernel_move_to_index)(void *, int32_t *, CArray *);
|
23
|
+
/* ----------- */
|
24
|
+
CArray *kernel;
|
25
|
+
int32_t offset[CA_RANK_MAX];
|
26
|
+
} CAWindowIterator;
|
27
|
+
|
28
|
+
VALUE rb_cCAWindowIterator;
|
29
|
+
|
30
|
+
/* rdoc:
|
31
|
+
class CAWindowIterator < CAIterator # :nodoc:
|
32
|
+
end
|
33
|
+
*/
|
34
|
+
|
35
|
+
extern int8_t CA_OBJ_WINDOW;
|
36
|
+
|
37
|
+
/* ----------------------------------------------------------------- */
|
38
|
+
|
39
|
+
CAWindow *
|
40
|
+
ca_window_new (CArray *carray,
|
41
|
+
int32_t *start, int32_t *count, int8_t bounds, char *fill);
|
42
|
+
|
43
|
+
|
44
|
+
static CArray *
|
45
|
+
ca_vi_kernel_at_index (void *it, int32_t *idx, CArray *ref)
|
46
|
+
{
|
47
|
+
CAWindowIterator *vit = (CAWindowIterator *) it;
|
48
|
+
CAWindow *kernel;
|
49
|
+
int32_t i, j;
|
50
|
+
|
51
|
+
if ( ref == vit->reference ) {
|
52
|
+
kernel = (CAWindow *)ca_clone(vit->kernel);
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
CAWindow *ck = (CAWindow *)vit->kernel;
|
56
|
+
kernel = ca_window_new(ref, ck->start, ck->count, ck->bounds, ck->fill);
|
57
|
+
}
|
58
|
+
|
59
|
+
ca_update_mask(kernel);
|
60
|
+
|
61
|
+
for (i=0; i<kernel->rank; i++) {
|
62
|
+
j = idx[i];
|
63
|
+
CA_CHECK_INDEX(j, vit->dim[i]);
|
64
|
+
kernel->start[i] = j - vit->offset[i];
|
65
|
+
if ( kernel->mask ) {
|
66
|
+
((CAWindow*)(kernel->mask))->start[i] = j - vit->offset[i];
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
return (CArray*) kernel;
|
71
|
+
}
|
72
|
+
|
73
|
+
static CArray *
|
74
|
+
ca_vi_kernel_at_addr (void *it, int32_t addr, CArray *ref)
|
75
|
+
{
|
76
|
+
CAWindowIterator *vit = (CAWindowIterator *) it;
|
77
|
+
int32_t *dim = vit->dim;
|
78
|
+
int32_t idx[CA_RANK_MAX];
|
79
|
+
int32_t i;
|
80
|
+
for (i=vit->rank-1; i>=0; i--) {
|
81
|
+
idx[i] = addr % dim[i];
|
82
|
+
addr /= dim[i];
|
83
|
+
}
|
84
|
+
return ca_vi_kernel_at_index(it, idx, ref);
|
85
|
+
}
|
86
|
+
|
87
|
+
static CArray *
|
88
|
+
ca_vi_kernel_move_to_index (void *it, int32_t *idx, CArray *kern)
|
89
|
+
{
|
90
|
+
CAWindowIterator *vit = (CAWindowIterator *) it;
|
91
|
+
CAWindow *kernel = (CAWindow *) kern;
|
92
|
+
int32_t *dim = vit->dim;
|
93
|
+
int32_t *offset = vit->offset;
|
94
|
+
int32_t i, j;
|
95
|
+
|
96
|
+
ca_update_mask(kernel);
|
97
|
+
|
98
|
+
for (i=0; i<kernel->rank; i++) {
|
99
|
+
j = idx[i];
|
100
|
+
CA_CHECK_INDEX(j, dim[i]);
|
101
|
+
kernel->start[i] = j - offset[i];
|
102
|
+
if ( kernel->mask ) {
|
103
|
+
((CAWindow*)(kernel->mask))->start[i] = j - offset[i];
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
return (CArray*) kernel;
|
108
|
+
}
|
109
|
+
|
110
|
+
static CArray *
|
111
|
+
ca_vi_kernel_move_to_addr (void *it, int32_t addr, CArray *ref)
|
112
|
+
{
|
113
|
+
CAWindowIterator *vit = (CAWindowIterator *) it;
|
114
|
+
int32_t *dim = vit->dim;
|
115
|
+
int32_t idx[CA_RANK_MAX];
|
116
|
+
int32_t i;
|
117
|
+
for (i=vit->rank-1; i>=0; i--) {
|
118
|
+
idx[i] = addr % dim[i];
|
119
|
+
addr /= dim[i];
|
120
|
+
}
|
121
|
+
return ca_vi_kernel_move_to_index(it, idx, ref);
|
122
|
+
}
|
123
|
+
|
124
|
+
void
|
125
|
+
ca_vi_setup (VALUE self, VALUE rref, VALUE rker)
|
126
|
+
{
|
127
|
+
CAWindowIterator *it;
|
128
|
+
CArray *ref, *ker;
|
129
|
+
int32_t i;
|
130
|
+
|
131
|
+
rker = rb_obj_clone(rker);
|
132
|
+
|
133
|
+
Data_Get_Struct(self, CAWindowIterator, it);
|
134
|
+
Data_Get_Struct(rref, CArray, ref);
|
135
|
+
Data_Get_Struct(rker, CArray, ker);
|
136
|
+
|
137
|
+
if ( ref->rank != ker->rank ) {
|
138
|
+
rb_raise(rb_eRuntimeError, "rank mismatch between reference and kernel");
|
139
|
+
}
|
140
|
+
|
141
|
+
it->rank = ref->rank;
|
142
|
+
memcpy(it->dim, ref->dim, it->rank * sizeof(int32_t));
|
143
|
+
it->reference = ref;
|
144
|
+
it->kernel = ker;
|
145
|
+
it->kernel_at_addr = ca_vi_kernel_at_addr;
|
146
|
+
it->kernel_at_index = ca_vi_kernel_at_index;
|
147
|
+
it->kernel_move_to_addr = ca_vi_kernel_move_to_addr;
|
148
|
+
it->kernel_move_to_index = ca_vi_kernel_move_to_index;
|
149
|
+
|
150
|
+
for (i=0; i<it->rank; i++) {
|
151
|
+
it->offset[i] = -(((CAWindow*)ker)->start[i]);
|
152
|
+
}
|
153
|
+
|
154
|
+
rb_ivar_set(self, rb_intern("@reference"), rref); /* required ivar */
|
155
|
+
rb_ivar_set(self, rb_intern("@kernel"), rker);
|
156
|
+
}
|
157
|
+
|
158
|
+
/* ----------------------------------------------------------------- */
|
159
|
+
|
160
|
+
static VALUE
|
161
|
+
rb_vi_s_allocate (VALUE klass)
|
162
|
+
{
|
163
|
+
CAWindowIterator *it;
|
164
|
+
return Data_Make_Struct(klass, CAWindowIterator, 0, free, it);
|
165
|
+
}
|
166
|
+
|
167
|
+
static VALUE
|
168
|
+
rb_vi_initialize (VALUE self, VALUE rker)
|
169
|
+
{
|
170
|
+
CArray *ker;
|
171
|
+
|
172
|
+
rb_check_carray_object(rker);
|
173
|
+
Data_Get_Struct(rker, CArray, ker);
|
174
|
+
if ( ker->obj_type != CA_OBJ_WINDOW ) {
|
175
|
+
rb_raise(rb_eRuntimeError, "kernel must be CAWindow object");
|
176
|
+
}
|
177
|
+
|
178
|
+
ca_vi_setup(self, rb_ca_parent(rker), rker);
|
179
|
+
|
180
|
+
return Qnil;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
rb_vi_initialize_copy (VALUE self, VALUE other)
|
185
|
+
{
|
186
|
+
ca_vi_setup(other, rb_ivar_get(self, rb_intern("@reference")),
|
187
|
+
rb_ivar_get(self, rb_intern("@kernel")));
|
188
|
+
return self;
|
189
|
+
}
|
190
|
+
|
191
|
+
void
|
192
|
+
Init_ca_iter_window ()
|
193
|
+
{
|
194
|
+
rb_cCAWindowIterator = rb_define_class("CAWindowIterator", rb_cCAIterator);
|
195
|
+
rb_define_const(rb_cCAWindowIterator, "UNIFORM_KERNEL", Qtrue);
|
196
|
+
|
197
|
+
rb_define_alloc_func(rb_cCAWindowIterator, rb_vi_s_allocate);
|
198
|
+
rb_define_method(rb_cCAWindowIterator, "initialize", rb_vi_initialize, 1);
|
199
|
+
rb_define_method(rb_cCAWindowIterator, "initialize_copy",
|
200
|
+
rb_vi_initialize_copy, 1);
|
201
|
+
}
|
202
|
+
|
data/ca_obj_array.c
ADDED
@@ -0,0 +1,1189 @@
|
|
1
|
+
/* ---------------------------------------------------------------------------
|
2
|
+
|
3
|
+
ca_obj_array.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
|
+
#if RUBY_VERSION_CODE < 190
|
15
|
+
#include "rubysig.h"
|
16
|
+
#endif
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
/* ------------------------------------------------------------------- */
|
21
|
+
|
22
|
+
VALUE rb_cCArray, rb_cCAWrap, rb_cCScalar, rb_cCAVirtual;
|
23
|
+
|
24
|
+
/* rdoc:
|
25
|
+
class CArray
|
26
|
+
end
|
27
|
+
class CAWrap < CArray # :nodoc:
|
28
|
+
end
|
29
|
+
class CScalar < CArray
|
30
|
+
end
|
31
|
+
class CAVirtual < CArray # :nodoc:
|
32
|
+
end
|
33
|
+
*/
|
34
|
+
|
35
|
+
/* ------------------------------------------------------------------- */
|
36
|
+
|
37
|
+
/* Monitering newly allocated memory size to do gc at appropreate timing */
|
38
|
+
/* This GC technique is based on NArray library. */
|
39
|
+
|
40
|
+
/* monitoring memory usage */
|
41
|
+
|
42
|
+
double ca_mem_usage = 0.0;
|
43
|
+
double ca_mem_count = 0.0;
|
44
|
+
|
45
|
+
/* Threshold for forced garbage collection and its default value */
|
46
|
+
double ca_gc_interval;
|
47
|
+
const double ca_default_gc_interval = 40.0; /* 40MB */
|
48
|
+
|
49
|
+
#define MB (1024*1024)
|
50
|
+
|
51
|
+
static void
|
52
|
+
ca_check_mem_count()
|
53
|
+
{
|
54
|
+
VALUE is_gc_disabled = rb_gc_enable();
|
55
|
+
if ( is_gc_disabled ) {
|
56
|
+
rb_gc_disable();
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
else if ( ca_mem_count > (ca_gc_interval * MB) ) {
|
60
|
+
rb_gc();
|
61
|
+
ca_mem_count = 0;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
/* rdoc:
|
66
|
+
# returns the threshold of incremented memory (MB) used by carray object
|
67
|
+
# until start GC.
|
68
|
+
def CArray.gc_interval ()
|
69
|
+
end
|
70
|
+
# set the threshold of incremented memory (MB) used by carray object
|
71
|
+
# until start GC.
|
72
|
+
def CArray.gc_interval= (val)
|
73
|
+
end
|
74
|
+
# reset the counter for the GC start when the incremented memory
|
75
|
+
# get larger than `CArray.gc_interval`.
|
76
|
+
def CArray.reset_gc_interval ()
|
77
|
+
end
|
78
|
+
*/
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
rb_ca_get_gc_interval (VALUE self)
|
82
|
+
{
|
83
|
+
return rb_float_new(ca_gc_interval);
|
84
|
+
}
|
85
|
+
|
86
|
+
static VALUE
|
87
|
+
rb_ca_set_gc_interval (VALUE self, VALUE rth)
|
88
|
+
{
|
89
|
+
double th = NUM2INT(rth);
|
90
|
+
if ( th <= 0 ) {
|
91
|
+
th = 0;
|
92
|
+
}
|
93
|
+
ca_gc_interval = th;
|
94
|
+
return rb_float_new(ca_gc_interval);
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE
|
98
|
+
rb_ca_reset_gc_interval (VALUE self)
|
99
|
+
{
|
100
|
+
ca_gc_interval = ca_default_gc_interval;
|
101
|
+
return rb_float_new(ca_gc_interval);
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
/* ------------------------------------------------------------------- */
|
106
|
+
|
107
|
+
/*
|
108
|
+
internal routine for carray_setup, carray_safe_setup,
|
109
|
+
carray_wrap_setup
|
110
|
+
|
111
|
+
flag for CArray CArray(Safe) CAWrap
|
112
|
+
=========== ======== ============= =========
|
113
|
+
allocate 1 1 0
|
114
|
+
use_calloc 0 1 0
|
115
|
+
=========== ======== ============= =========
|
116
|
+
|
117
|
+
safe -> filled by 0
|
118
|
+
*/
|
119
|
+
|
120
|
+
static int
|
121
|
+
carray_setup_i (CArray *ca,
|
122
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
123
|
+
CArray *mask, int allocate, int use_calloc)
|
124
|
+
{
|
125
|
+
int32_t elements;
|
126
|
+
double length;
|
127
|
+
int32_t i;
|
128
|
+
|
129
|
+
/* check arguments */
|
130
|
+
CA_CHECK_DATA_TYPE(data_type);
|
131
|
+
CA_CHECK_RANK(rank);
|
132
|
+
CA_CHECK_DIM(rank, dim);
|
133
|
+
CA_CHECK_BYTES(data_type, bytes);
|
134
|
+
|
135
|
+
/* calculate total number of elements */
|
136
|
+
elements = 1;
|
137
|
+
length = bytes;
|
138
|
+
for (i=0; i<rank; i++) {
|
139
|
+
elements *= dim[i];
|
140
|
+
length *= dim[i];
|
141
|
+
}
|
142
|
+
|
143
|
+
if ( length > CA_LENGTH_MAX ) {
|
144
|
+
rb_raise(rb_eRuntimeError, "too large byte length");
|
145
|
+
}
|
146
|
+
|
147
|
+
/* set values to the struct members */
|
148
|
+
if ( allocate ) {
|
149
|
+
ca->obj_type = CA_OBJ_ARRAY;
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
ca->obj_type = CA_OBJ_ARRAY_WRAP;
|
153
|
+
}
|
154
|
+
|
155
|
+
ca->data_type = data_type;
|
156
|
+
ca->flags = 0;
|
157
|
+
ca->rank = rank;
|
158
|
+
ca->bytes = bytes;
|
159
|
+
ca->elements = elements;
|
160
|
+
ca->dim = ALLOC_N(int32_t, rank);
|
161
|
+
memcpy(ca->dim, dim, rank*sizeof(int32_t));
|
162
|
+
|
163
|
+
if ( allocate ) { /* allocate == true */
|
164
|
+
|
165
|
+
/* allocate memory for entity */
|
166
|
+
if ( use_calloc ) {
|
167
|
+
/* ca->ptr = ALLOC_N(char, elements * bytes); */
|
168
|
+
ca->ptr = malloc_with_check(elements * bytes);
|
169
|
+
MEMZERO(ca->ptr, char, elements * bytes);
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
/* ca->ptr = ALLOC_N(char, elements * bytes); */
|
173
|
+
ca->ptr = malloc_with_check(elements * bytes);
|
174
|
+
}
|
175
|
+
|
176
|
+
ca_mem_count += (double)(ca_length(ca));
|
177
|
+
ca_mem_usage += (double)(ca_length(ca));
|
178
|
+
|
179
|
+
/* initialize elements with Qnil for CA_OBJECT data_type */
|
180
|
+
if ( allocate && data_type == CA_OBJECT ) {
|
181
|
+
volatile VALUE zero = INT2FIX(0);
|
182
|
+
VALUE *p = (VALUE *) ca->ptr;
|
183
|
+
for (i=0; i<elements; i++) {
|
184
|
+
*p++ = zero;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
}
|
189
|
+
else { /* allocate == false */
|
190
|
+
ca->ptr = NULL;
|
191
|
+
}
|
192
|
+
|
193
|
+
ca->mask = NULL;
|
194
|
+
if ( mask ) {
|
195
|
+
ca_setup_mask(ca, mask);
|
196
|
+
}
|
197
|
+
|
198
|
+
ca_check_mem_count();
|
199
|
+
|
200
|
+
return 0;
|
201
|
+
}
|
202
|
+
|
203
|
+
int
|
204
|
+
carray_setup (CArray *ca,
|
205
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes, CArray *mask)
|
206
|
+
{
|
207
|
+
return carray_setup_i(ca, data_type, rank, dim, bytes, mask, 1, 0);
|
208
|
+
}
|
209
|
+
|
210
|
+
int
|
211
|
+
carray_safe_setup (CArray *ca,
|
212
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes, CArray *mask)
|
213
|
+
{
|
214
|
+
return carray_setup_i(ca, data_type, rank, dim, bytes, mask, 1, 1);
|
215
|
+
}
|
216
|
+
|
217
|
+
int
|
218
|
+
ca_wrap_setup (CArray *ca,
|
219
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
220
|
+
CArray *mask, char *ptr)
|
221
|
+
{
|
222
|
+
int ret;
|
223
|
+
|
224
|
+
ret = carray_setup_i(ca, data_type, rank, dim, bytes, mask, 0, 0);
|
225
|
+
if ( (!ptr) && (ca->elements != 0) ) {
|
226
|
+
rb_raise(rb_eRuntimeError, "wrapping NULL pointer with an non-empty array");
|
227
|
+
}
|
228
|
+
ca->ptr = ptr;
|
229
|
+
return ret;
|
230
|
+
}
|
231
|
+
|
232
|
+
int
|
233
|
+
ca_wrap_setup_null (CArray *ca,
|
234
|
+
int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
235
|
+
CArray *mask)
|
236
|
+
{
|
237
|
+
int ret;
|
238
|
+
|
239
|
+
ret = carray_setup_i(ca, data_type, rank, dim, bytes, mask, 0, 0);
|
240
|
+
ca->ptr = NULL;
|
241
|
+
return ret;
|
242
|
+
}
|
243
|
+
|
244
|
+
CArray *
|
245
|
+
carray_new (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
246
|
+
CArray *mask)
|
247
|
+
{
|
248
|
+
CArray *ca = ALLOC(CArray);
|
249
|
+
carray_setup(ca, data_type, rank, dim, bytes, mask);
|
250
|
+
return ca;
|
251
|
+
}
|
252
|
+
|
253
|
+
CArray *
|
254
|
+
carray_new_safe (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
255
|
+
CArray *mask)
|
256
|
+
{
|
257
|
+
CArray *ca = ALLOC(CArray);
|
258
|
+
carray_safe_setup(ca, data_type, rank, dim, bytes, mask);
|
259
|
+
return ca;
|
260
|
+
}
|
261
|
+
|
262
|
+
CAWrap *
|
263
|
+
ca_wrap_new (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
264
|
+
CArray *mask, char *ptr)
|
265
|
+
{
|
266
|
+
CAWrap *ca = ALLOC(CAWrap);
|
267
|
+
ca_wrap_setup(ca, data_type, rank, dim, bytes, mask, ptr);
|
268
|
+
return ca;
|
269
|
+
}
|
270
|
+
|
271
|
+
CAWrap *
|
272
|
+
ca_wrap_new_null (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
273
|
+
CArray *mask)
|
274
|
+
{
|
275
|
+
CAWrap *ca = ALLOC(CAWrap);
|
276
|
+
ca_wrap_setup_null(ca, data_type, rank, dim, bytes, mask);
|
277
|
+
return ca;
|
278
|
+
}
|
279
|
+
|
280
|
+
void
|
281
|
+
free_carray (void *ap)
|
282
|
+
{
|
283
|
+
CArray *ca = (CArray *) ap;
|
284
|
+
if ( ca != NULL ) {
|
285
|
+
ca_mem_usage -= (double)(ca_length(ca));
|
286
|
+
ca_free(ca->mask);
|
287
|
+
free(ca->ptr);
|
288
|
+
xfree(ca->dim);
|
289
|
+
xfree(ca);
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
void
|
294
|
+
free_ca_wrap (void *ap)
|
295
|
+
{
|
296
|
+
CArray *ca = (CArray *) ap;
|
297
|
+
if ( ca != NULL ) {
|
298
|
+
/* free(ca->ptr); */ /* don't free ca->ptr for CAWrap */
|
299
|
+
ca_free(ca->mask);
|
300
|
+
xfree(ca->dim);
|
301
|
+
xfree(ca);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
/* ------------------------------------------------------------------- */
|
306
|
+
|
307
|
+
static int
|
308
|
+
cscalar_setup (CScalar *ca,
|
309
|
+
int8_t data_type, int32_t bytes, CArray *mask)
|
310
|
+
{
|
311
|
+
CA_CHECK_DATA_TYPE(data_type);
|
312
|
+
CA_CHECK_BYTES(data_type, bytes);
|
313
|
+
|
314
|
+
ca->obj_type = CA_OBJ_SCALAR;
|
315
|
+
ca->data_type = data_type;
|
316
|
+
ca->flags = 0;
|
317
|
+
ca->rank = 1;
|
318
|
+
ca->bytes = bytes;
|
319
|
+
ca->elements = 1;
|
320
|
+
ca->dim = &(ca->_dim);
|
321
|
+
ca->ptr = xmalloc(bytes);
|
322
|
+
ca->mask = NULL;
|
323
|
+
|
324
|
+
ca->dim[0] = 1;
|
325
|
+
|
326
|
+
ca_mem_usage += (double)(ca->bytes);
|
327
|
+
|
328
|
+
if ( data_type == CA_OBJECT ) {
|
329
|
+
*((VALUE*) ca->ptr) = INT2FIX(0);
|
330
|
+
}
|
331
|
+
else {
|
332
|
+
MEMZERO(ca->ptr, char, ca->bytes);
|
333
|
+
}
|
334
|
+
|
335
|
+
if ( mask ) {
|
336
|
+
ca_setup_mask((CArray *)ca, mask);
|
337
|
+
}
|
338
|
+
|
339
|
+
ca_set_flag(ca, CA_FLAG_SCALAR);
|
340
|
+
|
341
|
+
return 0;
|
342
|
+
}
|
343
|
+
|
344
|
+
/*
|
345
|
+
* constructs a CScalar struct without initialization
|
346
|
+
*/
|
347
|
+
|
348
|
+
CScalar *
|
349
|
+
cscalar_new (int8_t data_type, int32_t bytes, CArray *mask)
|
350
|
+
{
|
351
|
+
CScalar *ca = ALLOC(CScalar);
|
352
|
+
cscalar_setup(ca, data_type, bytes, mask);
|
353
|
+
return ca;
|
354
|
+
}
|
355
|
+
|
356
|
+
/*
|
357
|
+
* constructs a CScalar struct initialized with a value
|
358
|
+
*/
|
359
|
+
|
360
|
+
CScalar *
|
361
|
+
cscalar_new2 (int8_t data_type, int32_t bytes, char *val)
|
362
|
+
{
|
363
|
+
CScalar *ca = ALLOC(CScalar);
|
364
|
+
cscalar_setup(ca, data_type, bytes, NULL);
|
365
|
+
memcpy(ca->ptr, val, ca->bytes);
|
366
|
+
return ca;
|
367
|
+
}
|
368
|
+
|
369
|
+
/*
|
370
|
+
* free a CScalar struct
|
371
|
+
*/
|
372
|
+
|
373
|
+
static void
|
374
|
+
free_cscalar (void *ap)
|
375
|
+
{
|
376
|
+
CScalar *ca = (CScalar *) ap;
|
377
|
+
if ( ca != NULL ) {
|
378
|
+
ca_mem_usage -= (double)(ca->bytes);
|
379
|
+
free(ca->ptr);
|
380
|
+
ca_free(ca->mask);
|
381
|
+
xfree(ca);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
/* ------------------------------------------------------------------- */
|
386
|
+
|
387
|
+
void *
|
388
|
+
ca_array_func_clone (void *ap)
|
389
|
+
{
|
390
|
+
CArray *ca = (CArray *) ap;
|
391
|
+
CArray *co;
|
392
|
+
co = carray_new(ca->data_type, ca->rank, ca->dim, ca->bytes, ca->mask);
|
393
|
+
memcpy(co->ptr, ca->ptr, ca_length(ca));
|
394
|
+
return co;
|
395
|
+
}
|
396
|
+
|
397
|
+
char *
|
398
|
+
ca_array_func_ptr_at_addr (void *ap, int32_t addr)
|
399
|
+
{
|
400
|
+
CArray *ca = (CArray *) ap;
|
401
|
+
return ca->ptr + ca->bytes * addr;
|
402
|
+
}
|
403
|
+
|
404
|
+
char *
|
405
|
+
ca_array_func_ptr_at_index (void *ap, int32_t *idx)
|
406
|
+
{
|
407
|
+
CArray *ca = (CArray *) ap;
|
408
|
+
int32_t *dim = ca->dim;
|
409
|
+
int32_t n, i;
|
410
|
+
n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[rank-1] */
|
411
|
+
for (i=1; i<ca->rank; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[rank-1] */
|
412
|
+
n = dim[i]*n+idx[i]; /* ... + idx[rank-2]*dim[1] + idx[rank-1] */
|
413
|
+
}
|
414
|
+
return ca->ptr + ca->bytes * n;
|
415
|
+
}
|
416
|
+
|
417
|
+
void
|
418
|
+
ca_array_func_fetch_addr (void *ap, int32_t addr, void *ptr)
|
419
|
+
{
|
420
|
+
CArray *ca = (CArray *) ap;
|
421
|
+
memcpy(ptr, ca->ptr + ca->bytes * addr, ca->bytes);
|
422
|
+
}
|
423
|
+
|
424
|
+
void
|
425
|
+
ca_array_func_fetch_index (void *ap, int32_t *idx, void *ptr)
|
426
|
+
{
|
427
|
+
CArray *ca = (CArray *) ap;
|
428
|
+
int32_t *dim = ca->dim;
|
429
|
+
int32_t n, i;
|
430
|
+
n = idx[0];
|
431
|
+
for (i=1; i<ca->rank; i++) {
|
432
|
+
n = dim[i]*n+idx[i];
|
433
|
+
}
|
434
|
+
memcpy(ptr, ca->ptr + ca->bytes * n, ca->bytes);
|
435
|
+
}
|
436
|
+
|
437
|
+
void
|
438
|
+
ca_array_func_store_addr (void *ap, int32_t addr, void *ptr)
|
439
|
+
{
|
440
|
+
CArray *ca = (CArray *) ap;
|
441
|
+
memcpy(ca->ptr + ca->bytes * addr, ptr, ca->bytes);
|
442
|
+
}
|
443
|
+
|
444
|
+
void
|
445
|
+
ca_array_func_store_index (void *ap, int32_t *idx, void *ptr)
|
446
|
+
{
|
447
|
+
CArray *ca = (CArray *) ap;
|
448
|
+
int32_t *dim = ca->dim;
|
449
|
+
int32_t n, i;
|
450
|
+
n = idx[0];
|
451
|
+
for (i=1; i<ca->rank; i++) {
|
452
|
+
n = dim[i]*n+idx[i];
|
453
|
+
}
|
454
|
+
memcpy(ca->ptr + ca->bytes * n, ptr, ca->bytes);
|
455
|
+
}
|
456
|
+
|
457
|
+
void
|
458
|
+
ca_array_func_allocate (void *ap)
|
459
|
+
{
|
460
|
+
/* no operation */
|
461
|
+
}
|
462
|
+
|
463
|
+
void
|
464
|
+
ca_array_func_attach (void *ap)
|
465
|
+
{
|
466
|
+
/* no operation */
|
467
|
+
}
|
468
|
+
|
469
|
+
void
|
470
|
+
ca_array_func_sync (void *ap)
|
471
|
+
{
|
472
|
+
/* no operation */
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
void
|
477
|
+
ca_array_func_detach (void *ap)
|
478
|
+
{
|
479
|
+
/* no operation */
|
480
|
+
}
|
481
|
+
|
482
|
+
void
|
483
|
+
ca_array_func_copy_data (void *ap, void *ptr)
|
484
|
+
{
|
485
|
+
CArray *ca = (CArray *) ap;
|
486
|
+
memmove(ptr, ca->ptr, ca_length(ca));
|
487
|
+
}
|
488
|
+
|
489
|
+
void
|
490
|
+
ca_array_func_sync_data (void *ap, void *ptr)
|
491
|
+
{
|
492
|
+
CArray *ca = (CArray *) ap;
|
493
|
+
memmove(ca->ptr, ptr, ca_length(ca));
|
494
|
+
}
|
495
|
+
|
496
|
+
#define proc_fill_bang_fixlen() \
|
497
|
+
{ \
|
498
|
+
int32_t i; \
|
499
|
+
int32_t bytes = ca->bytes; \
|
500
|
+
char *p = ca->ptr; \
|
501
|
+
for (i=ca->elements; i; i--, p+=bytes) { \
|
502
|
+
memcpy(p, val, bytes); \
|
503
|
+
} \
|
504
|
+
}
|
505
|
+
|
506
|
+
#define proc_fill_bang(type) \
|
507
|
+
{ \
|
508
|
+
int32_t i; \
|
509
|
+
type *p = (type *)ca->ptr; \
|
510
|
+
type v = *(type *)val; \
|
511
|
+
for (i=ca->elements; i; i--, p++) { \
|
512
|
+
*p = v; \
|
513
|
+
} \
|
514
|
+
}
|
515
|
+
|
516
|
+
void
|
517
|
+
ca_array_func_fill_data (void *ap, void *val)
|
518
|
+
{
|
519
|
+
CArray *ca = (CArray *) ap;
|
520
|
+
switch ( ca->data_type ) {
|
521
|
+
case CA_FIXLEN: proc_fill_bang_fixlen(); break;
|
522
|
+
case CA_BOOLEAN:
|
523
|
+
case CA_INT8:
|
524
|
+
case CA_UINT8: proc_fill_bang(int8_t); break;
|
525
|
+
case CA_INT16:
|
526
|
+
case CA_UINT16: proc_fill_bang(int16_t); break;
|
527
|
+
case CA_INT32:
|
528
|
+
case CA_UINT32:
|
529
|
+
case CA_FLOAT32: proc_fill_bang(int32_t); break;
|
530
|
+
case CA_INT64:
|
531
|
+
case CA_UINT64:
|
532
|
+
case CA_FLOAT64: proc_fill_bang(float64_t); break;
|
533
|
+
case CA_FLOAT128: proc_fill_bang(float128_t); break;
|
534
|
+
#ifdef HAVE_COMPLEX_H
|
535
|
+
case CA_CMPLX64: proc_fill_bang(cmplx64_t); break;
|
536
|
+
case CA_CMPLX128: proc_fill_bang(cmplx128_t); break;
|
537
|
+
case CA_CMPLX256: proc_fill_bang(cmplx256_t); break;
|
538
|
+
#endif
|
539
|
+
case CA_OBJECT: proc_fill_bang(VALUE); break;
|
540
|
+
default: rb_bug("array has an unknown data type");
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
544
|
+
void
|
545
|
+
ca_array_func_create_mask (void *ap)
|
546
|
+
{
|
547
|
+
CArray *ca = (CArray *) ap;
|
548
|
+
ca->mask = carray_new_safe(CA_BOOLEAN, ca->rank, ca->dim, 0, NULL);
|
549
|
+
}
|
550
|
+
|
551
|
+
ca_operation_function_t ca_array_func = {
|
552
|
+
CA_OBJ_ARRAY,
|
553
|
+
CA_REAL_ARRAY,
|
554
|
+
free_carray,
|
555
|
+
ca_array_func_clone,
|
556
|
+
ca_array_func_ptr_at_addr,
|
557
|
+
ca_array_func_ptr_at_index,
|
558
|
+
NULL,
|
559
|
+
ca_array_func_fetch_index,
|
560
|
+
NULL,
|
561
|
+
ca_array_func_store_index,
|
562
|
+
ca_array_func_allocate,
|
563
|
+
ca_array_func_attach,
|
564
|
+
ca_array_func_sync,
|
565
|
+
ca_array_func_detach,
|
566
|
+
ca_array_func_copy_data,
|
567
|
+
ca_array_func_sync_data,
|
568
|
+
ca_array_func_fill_data,
|
569
|
+
ca_array_func_create_mask,
|
570
|
+
};
|
571
|
+
|
572
|
+
ca_operation_function_t ca_wrap_func = {
|
573
|
+
CA_OBJ_ARRAY_WRAP,
|
574
|
+
CA_REAL_ARRAY,
|
575
|
+
free_ca_wrap,
|
576
|
+
ca_array_func_clone,
|
577
|
+
ca_array_func_ptr_at_addr,
|
578
|
+
ca_array_func_ptr_at_index,
|
579
|
+
NULL,
|
580
|
+
ca_array_func_fetch_index,
|
581
|
+
NULL,
|
582
|
+
ca_array_func_store_index,
|
583
|
+
ca_array_func_allocate,
|
584
|
+
ca_array_func_attach,
|
585
|
+
ca_array_func_sync,
|
586
|
+
ca_array_func_detach,
|
587
|
+
ca_array_func_copy_data,
|
588
|
+
ca_array_func_sync_data,
|
589
|
+
ca_array_func_fill_data,
|
590
|
+
ca_array_func_create_mask,
|
591
|
+
};
|
592
|
+
|
593
|
+
/* ------------------------------------------------------------------- */
|
594
|
+
|
595
|
+
static void *
|
596
|
+
ca_scalar_func_clone (void *ap)
|
597
|
+
{
|
598
|
+
CScalar *ca = (CScalar *) ap;
|
599
|
+
CScalar *co;
|
600
|
+
ca_update_mask(ca);
|
601
|
+
co = cscalar_new(ca->data_type, ca->bytes, ca->mask);
|
602
|
+
memcpy(co->ptr, ca->ptr, ca->bytes);
|
603
|
+
return co;
|
604
|
+
}
|
605
|
+
|
606
|
+
char *
|
607
|
+
ca_scalar_func_ptr_at_addr (void *ap, int32_t addr)
|
608
|
+
{
|
609
|
+
CArray *ca = (CArray *) ap;
|
610
|
+
return ca->ptr;
|
611
|
+
}
|
612
|
+
|
613
|
+
char *
|
614
|
+
ca_scalar_func_ptr_at_index (void *ap, int32_t *idx)
|
615
|
+
{
|
616
|
+
CArray *ca = (CArray *) ap;
|
617
|
+
return ca->ptr;
|
618
|
+
}
|
619
|
+
|
620
|
+
#define ca_scalar_func_fetch_index ca_array_func_fetch_index
|
621
|
+
#define ca_scalar_func_store_index ca_array_func_store_index
|
622
|
+
#define ca_scalar_func_allocate ca_array_func_allocate
|
623
|
+
#define ca_scalar_func_attach ca_array_func_attach
|
624
|
+
#define ca_scalar_func_sync ca_array_func_sync
|
625
|
+
#define ca_scalar_func_detach ca_array_func_detach
|
626
|
+
#define ca_scalar_func_copy_data ca_array_func_copy_data
|
627
|
+
#define ca_scalar_func_sync_data ca_array_func_sync_data
|
628
|
+
#define ca_scalar_func_fill_data ca_array_func_fill_data
|
629
|
+
#define ca_scalar_func_create_mask ca_array_func_create_mask
|
630
|
+
|
631
|
+
ca_operation_function_t ca_scalar_func = {
|
632
|
+
CA_OBJ_SCALAR,
|
633
|
+
CA_REAL_ARRAY,
|
634
|
+
free_cscalar,
|
635
|
+
ca_scalar_func_clone,
|
636
|
+
ca_scalar_func_ptr_at_addr,
|
637
|
+
ca_scalar_func_ptr_at_index,
|
638
|
+
NULL,
|
639
|
+
ca_scalar_func_fetch_index,
|
640
|
+
NULL,
|
641
|
+
ca_scalar_func_store_index,
|
642
|
+
ca_scalar_func_allocate,
|
643
|
+
ca_scalar_func_attach,
|
644
|
+
ca_scalar_func_sync,
|
645
|
+
ca_scalar_func_detach,
|
646
|
+
ca_scalar_func_copy_data,
|
647
|
+
ca_scalar_func_sync_data,
|
648
|
+
ca_scalar_func_fill_data,
|
649
|
+
ca_scalar_func_create_mask,
|
650
|
+
};
|
651
|
+
|
652
|
+
/* ------------------------------------------------------------------- */
|
653
|
+
|
654
|
+
VALUE
|
655
|
+
rb_carray_new (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
656
|
+
CArray *mask)
|
657
|
+
{
|
658
|
+
CArray *ca = carray_new(data_type, rank, dim, bytes, mask);
|
659
|
+
return ca_wrap_struct(ca);
|
660
|
+
}
|
661
|
+
|
662
|
+
VALUE
|
663
|
+
rb_carray_new_safe (int8_t data_type, int8_t rank, int32_t *dim, int32_t bytes,
|
664
|
+
CArray *mask)
|
665
|
+
{
|
666
|
+
CArray *ca = carray_new_safe(data_type, rank, dim, bytes, mask);
|
667
|
+
return ca_wrap_struct(ca);
|
668
|
+
}
|
669
|
+
|
670
|
+
VALUE
|
671
|
+
rb_cscalar_new (int8_t data_type, int32_t bytes, CArray *mask)
|
672
|
+
{
|
673
|
+
CScalar *ca = cscalar_new(data_type, bytes, mask);
|
674
|
+
return ca_wrap_struct(ca);
|
675
|
+
}
|
676
|
+
|
677
|
+
VALUE
|
678
|
+
rb_cscalar_new_with_value (int8_t data_type, int32_t bytes, VALUE rval)
|
679
|
+
{
|
680
|
+
volatile VALUE obj;
|
681
|
+
obj = rb_cscalar_new(data_type, bytes, NULL);
|
682
|
+
rb_ca_store_addr(obj, 0, rval);
|
683
|
+
return obj;
|
684
|
+
}
|
685
|
+
|
686
|
+
/* ------------------------------------------------------------------- */
|
687
|
+
|
688
|
+
/*
|
689
|
+
* CArray.allocate()
|
690
|
+
*/
|
691
|
+
|
692
|
+
static VALUE
|
693
|
+
rb_ca_s_allocate (VALUE klass)
|
694
|
+
{
|
695
|
+
CArray *ca;
|
696
|
+
ca_check_mem_count();
|
697
|
+
return Data_Make_Struct(klass, CArray, ca_mark, ca_free, ca);
|
698
|
+
}
|
699
|
+
|
700
|
+
/* rdoc:
|
701
|
+
# call-seq:
|
702
|
+
# CArray.new(data_type, dim, bytes=0) { ... }
|
703
|
+
#
|
704
|
+
# Constructs a new CArray object of <i>data_type</i>, which has the
|
705
|
+
# rank and the dimensions specified by an <code>Array</code> of
|
706
|
+
# <code>Integer</code> or an argument list of <code>Integer</code>.
|
707
|
+
# The byte size of each element for the fixed length data type
|
708
|
+
# (<code>data_type == CA_FIXLEN</code>) is specified optional argument
|
709
|
+
# <i>bytes</i>. Otherwise, this optional argument has no
|
710
|
+
# effect. If the block is given, the new CArray
|
711
|
+
# object will be initialized by the value returned from the block.
|
712
|
+
def CArray.new(data_type, dim, bytes=0)
|
713
|
+
end
|
714
|
+
*/
|
715
|
+
|
716
|
+
static VALUE
|
717
|
+
rb_ca_initialize (int argc, VALUE *argv, VALUE self)
|
718
|
+
{
|
719
|
+
volatile VALUE rtype, rdim, ropt, rbytes = Qnil;
|
720
|
+
CArray *ca;
|
721
|
+
int8_t data_type, rank;
|
722
|
+
int32_t dim[CA_RANK_MAX];
|
723
|
+
int32_t bytes;
|
724
|
+
int32_t i;
|
725
|
+
|
726
|
+
rb_scan_args(argc, argv, "21", &rtype, &rdim, &ropt);
|
727
|
+
rb_scan_options(ropt, "bytes", &rbytes);
|
728
|
+
|
729
|
+
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
730
|
+
rb_ca_data_type_import(self, rtype);
|
731
|
+
|
732
|
+
Check_Type(rdim, T_ARRAY);
|
733
|
+
rank = RARRAY_LEN(rdim);
|
734
|
+
for (i=0; i<rank; i++) {
|
735
|
+
dim[i] = NUM2INT(rb_ary_entry(rdim, i));
|
736
|
+
}
|
737
|
+
|
738
|
+
Data_Get_Struct(self, CArray, ca);
|
739
|
+
carray_safe_setup(ca, data_type, rank, dim, bytes, NULL);
|
740
|
+
|
741
|
+
if ( rb_block_given_p() ) {
|
742
|
+
volatile VALUE rval = rb_yield(self);
|
743
|
+
if ( rval != self ) {
|
744
|
+
rb_ca_store_all(self, rval);
|
745
|
+
}
|
746
|
+
}
|
747
|
+
|
748
|
+
return Qnil;
|
749
|
+
}
|
750
|
+
|
751
|
+
static VALUE
|
752
|
+
rb_ca_s_fixlen (int argc, VALUE *argv, VALUE klass)
|
753
|
+
{
|
754
|
+
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
755
|
+
volatile VALUE rdim = rb_ary_new4(argc, argv);
|
756
|
+
VALUE args[3] = { INT2NUM(CA_FIXLEN), rdim, ropt };
|
757
|
+
return rb_class_new_instance(3, args, klass);
|
758
|
+
}
|
759
|
+
|
760
|
+
#define rb_ca_s_type(type, code) \
|
761
|
+
rb_ca_s_## type (int argc, VALUE *argv, VALUE klass) \
|
762
|
+
{ \
|
763
|
+
volatile VALUE ropt = rb_pop_options(&argc, &argv); \
|
764
|
+
volatile VALUE rdim = rb_ary_new4(argc, argv); \
|
765
|
+
VALUE args[3] = { INT2NUM(code), rdim, ropt }; \
|
766
|
+
return rb_class_new_instance(3, args, klass); \
|
767
|
+
}
|
768
|
+
|
769
|
+
/*
|
770
|
+
* call-seq:
|
771
|
+
* CArray.int8(dim0, dim1, ...) { ... } -> CArray
|
772
|
+
* CArray.uint8(dim0, dim1, ...) { ... } -> CArray
|
773
|
+
* CArray.int16(dim0, dim1, ...) { ... } -> CArray
|
774
|
+
* CArray.uint16(dim0, dim1, ...) { ... } -> CArray
|
775
|
+
* CArray.int32(dim0, dim1, ...) { ... } -> CArray
|
776
|
+
* CArray.uint32(dim0, dim1, ...) { ... } -> CArray
|
777
|
+
* CArray.int64(dim0, dim1, ...) { ... } -> CArray
|
778
|
+
* CArray.uint64(dim0, dim1, ...) { ... } -> CArray
|
779
|
+
* CArray.float32(dim0, dim1, ...) { ... } -> CArray
|
780
|
+
* CArray.float64(dim0, dim1, ...) { ... } -> CArray
|
781
|
+
* CArray.float128(dim0, dim1, ...) { ... } -> CArray
|
782
|
+
* CArray.cmplx64(dim0, dim1, ...) { ... } -> CArray
|
783
|
+
* CArray.cmplx128(dim0, dim1, ...) { ... } -> CArray
|
784
|
+
* CArray.cmplx256(dim0, dim1, ...) { ... } -> CArray
|
785
|
+
* CArray.object(dim0, dim1, ...) { ... } -> CArray
|
786
|
+
*
|
787
|
+
*/
|
788
|
+
|
789
|
+
static VALUE rb_ca_s_VALUE();
|
790
|
+
|
791
|
+
static VALUE rb_ca_s_type(boolean, CA_BOOLEAN);
|
792
|
+
static VALUE rb_ca_s_type(int8, CA_INT8);
|
793
|
+
static VALUE rb_ca_s_type(uint8, CA_UINT8);
|
794
|
+
static VALUE rb_ca_s_type(int16, CA_INT16);
|
795
|
+
static VALUE rb_ca_s_type(uint16, CA_UINT16);
|
796
|
+
static VALUE rb_ca_s_type(int32, CA_INT32);
|
797
|
+
static VALUE rb_ca_s_type(uint32, CA_UINT32);
|
798
|
+
static VALUE rb_ca_s_type(int64, CA_INT64);
|
799
|
+
static VALUE rb_ca_s_type(uint64, CA_UINT64);
|
800
|
+
static VALUE rb_ca_s_type(float32, CA_FLOAT32);
|
801
|
+
static VALUE rb_ca_s_type(float64, CA_FLOAT64);
|
802
|
+
static VALUE rb_ca_s_type(float128, CA_FLOAT128);
|
803
|
+
#ifdef HAVE_COMPLEX_H
|
804
|
+
static VALUE rb_ca_s_type(cmplx64, CA_CMPLX64);
|
805
|
+
static VALUE rb_ca_s_type(cmplx128, CA_CMPLX128);
|
806
|
+
static VALUE rb_ca_s_type(cmplx256, CA_CMPLX256);
|
807
|
+
#endif
|
808
|
+
static VALUE rb_ca_s_type(VALUE, CA_OBJECT);
|
809
|
+
|
810
|
+
static VALUE
|
811
|
+
rb_ca_initialize_copy (VALUE self, VALUE other)
|
812
|
+
{
|
813
|
+
CArray *ca, *cs;
|
814
|
+
|
815
|
+
rb_call_super(1, &other);
|
816
|
+
|
817
|
+
Data_Get_Struct(self, CArray, ca);
|
818
|
+
Data_Get_Struct(other, CArray, cs);
|
819
|
+
|
820
|
+
ca_update_mask(cs);
|
821
|
+
carray_setup(ca, cs->data_type, cs->rank, cs->dim, cs->bytes, cs->mask);
|
822
|
+
|
823
|
+
memcpy(ca->ptr, cs->ptr, ca_length(cs));
|
824
|
+
|
825
|
+
return self;
|
826
|
+
}
|
827
|
+
|
828
|
+
/* rdoc:
|
829
|
+
def CArray.wrap (data_type, dim, bytes=0) # { wrapped_object }
|
830
|
+
end
|
831
|
+
*/
|
832
|
+
|
833
|
+
static VALUE
|
834
|
+
rb_ca_s_wrap (int argc, VALUE *argv, VALUE self)
|
835
|
+
{
|
836
|
+
volatile VALUE obj, target, rtype, rdim, ropt, rbytes = Qnil;
|
837
|
+
CArray *ca;
|
838
|
+
int8_t data_type, rank;
|
839
|
+
int32_t dim[CA_RANK_MAX];
|
840
|
+
int32_t bytes;
|
841
|
+
int32_t i;
|
842
|
+
|
843
|
+
rb_scan_args(argc, argv, "21", &rtype, &rdim, &ropt);
|
844
|
+
rb_scan_options(ropt, "bytes", &rbytes);
|
845
|
+
|
846
|
+
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
847
|
+
|
848
|
+
Check_Type(rdim, T_ARRAY);
|
849
|
+
rank = RARRAY_LEN(rdim);
|
850
|
+
for (i=0; i<rank; i++) {
|
851
|
+
dim[i] = NUM2INT(rb_ary_entry(rdim, i));
|
852
|
+
}
|
853
|
+
|
854
|
+
target = rb_yield_values(0);
|
855
|
+
|
856
|
+
obj = Data_Make_Struct(rb_cCAWrap, CAWrap, ca_mark, ca_free, ca);
|
857
|
+
ca_wrap_setup_null(ca, data_type, rank, dim, bytes, NULL);
|
858
|
+
|
859
|
+
rb_funcall(target, rb_intern("wrap_as_carray"), 1, obj);
|
860
|
+
rb_ivar_set(obj, rb_intern("referred_object"), target);
|
861
|
+
|
862
|
+
return obj;
|
863
|
+
}
|
864
|
+
|
865
|
+
VALUE
|
866
|
+
rb_carray_wrap_ptr (int8_t data_type, int8_t rank, int32_t *dim,
|
867
|
+
int32_t bytes, CArray *mask, char *ptr, VALUE refer)
|
868
|
+
{
|
869
|
+
volatile VALUE obj;
|
870
|
+
CArray *ca;
|
871
|
+
|
872
|
+
ca = ca_wrap_new(data_type, rank, dim, bytes, mask, ptr);
|
873
|
+
obj = ca_wrap_struct(ca);
|
874
|
+
|
875
|
+
rb_ivar_set(obj, rb_intern("referred_object"), refer);
|
876
|
+
|
877
|
+
return obj;
|
878
|
+
}
|
879
|
+
|
880
|
+
/* ------------------------------------------------------------------- */
|
881
|
+
|
882
|
+
static VALUE
|
883
|
+
rb_cs_s_allocate (VALUE klass)
|
884
|
+
{
|
885
|
+
CScalar *ca;
|
886
|
+
return Data_Make_Struct(klass, CScalar, ca_mark, ca_free, ca);
|
887
|
+
}
|
888
|
+
|
889
|
+
/* rdoc:
|
890
|
+
# call-seq:
|
891
|
+
# CScalar.new(data_type, bytes=0) { ... }
|
892
|
+
#
|
893
|
+
# Constructs a new CScalar object of <i>data_type</i>.
|
894
|
+
# The byte size of each element for the fixed length data type
|
895
|
+
# (<code>data_type == CA_FIXLEN</code>) is specified optional argument
|
896
|
+
# <i>bytes</i>. Otherwise, this optional argument has no
|
897
|
+
# effect. If the block is given, the new CScalar
|
898
|
+
# object will be initialized by the value returned from the block.
|
899
|
+
def CScalar.new(data_type,bytes=0)
|
900
|
+
end
|
901
|
+
*/
|
902
|
+
|
903
|
+
static VALUE
|
904
|
+
rb_cs_initialize (int argc, VALUE *argv, VALUE self)
|
905
|
+
{
|
906
|
+
volatile VALUE rtype, ropt, rbytes = Qnil;
|
907
|
+
CScalar *ca;
|
908
|
+
int8_t data_type;
|
909
|
+
int32_t bytes;
|
910
|
+
|
911
|
+
rb_scan_args(argc, argv, "11", &rtype, &ropt);
|
912
|
+
rb_scan_options(ropt, "bytes", &rbytes);
|
913
|
+
|
914
|
+
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
915
|
+
rb_ca_data_type_import(self, rtype);
|
916
|
+
|
917
|
+
Data_Get_Struct(self, CScalar, ca);
|
918
|
+
cscalar_setup(ca, data_type, bytes, NULL);
|
919
|
+
|
920
|
+
if ( rb_block_given_p() ) {
|
921
|
+
volatile VALUE rval = rb_yield(self);
|
922
|
+
if ( rval != self ) {
|
923
|
+
rb_ca_store_addr(self, 0, rval);
|
924
|
+
}
|
925
|
+
}
|
926
|
+
|
927
|
+
return Qnil;
|
928
|
+
}
|
929
|
+
|
930
|
+
static VALUE
|
931
|
+
rb_cs_s_fixlen (int argc, VALUE *argv, VALUE klass)
|
932
|
+
{
|
933
|
+
volatile VALUE ropt = rb_pop_options(&argc, &argv);
|
934
|
+
VALUE args[2] = { INT2NUM(CA_FIXLEN), ropt };
|
935
|
+
if ( argc > 0 ) {
|
936
|
+
rb_raise(rb_eArgError, "invalid number of arguments");
|
937
|
+
}
|
938
|
+
return rb_class_new_instance(2, args, klass);
|
939
|
+
}
|
940
|
+
|
941
|
+
#define rb_cs_s_type(type, code) \
|
942
|
+
rb_cs_s_## type (int argc, VALUE *argv, VALUE klass) \
|
943
|
+
{ \
|
944
|
+
volatile VALUE ropt = rb_pop_options(&argc, &argv); \
|
945
|
+
VALUE args[2] = { INT2NUM(code), ropt }; \
|
946
|
+
if ( argc > 0 ) { \
|
947
|
+
rb_raise(rb_eArgError, "invalid number of arguments"); \
|
948
|
+
} \
|
949
|
+
return rb_class_new_instance(2, args, klass); \
|
950
|
+
}
|
951
|
+
|
952
|
+
static VALUE rb_cs_s_type(boolean, CA_BOOLEAN);
|
953
|
+
static VALUE rb_cs_s_type(int8, CA_INT8);
|
954
|
+
static VALUE rb_cs_s_type(uint8, CA_UINT8);
|
955
|
+
static VALUE rb_cs_s_type(int16, CA_INT16);
|
956
|
+
static VALUE rb_cs_s_type(uint16, CA_UINT16);
|
957
|
+
static VALUE rb_cs_s_type(int32, CA_INT32);
|
958
|
+
static VALUE rb_cs_s_type(uint32, CA_UINT32);
|
959
|
+
static VALUE rb_cs_s_type(int64, CA_INT64);
|
960
|
+
static VALUE rb_cs_s_type(uint64, CA_UINT64);
|
961
|
+
static VALUE rb_cs_s_type(float32, CA_FLOAT32);
|
962
|
+
static VALUE rb_cs_s_type(float64, CA_FLOAT64);
|
963
|
+
static VALUE rb_cs_s_type(float128, CA_FLOAT128);
|
964
|
+
#ifdef HAVE_COMPLEX_H
|
965
|
+
static VALUE rb_cs_s_type(cmplx64, CA_CMPLX64);
|
966
|
+
static VALUE rb_cs_s_type(cmplx128, CA_CMPLX128);
|
967
|
+
static VALUE rb_cs_s_type(cmplx256, CA_CMPLX256);
|
968
|
+
#endif
|
969
|
+
static VALUE rb_cs_s_type(VALUE, CA_OBJECT);
|
970
|
+
|
971
|
+
/*
|
972
|
+
* call-seq:
|
973
|
+
* CScalar.int8() { ... } -> CScalar
|
974
|
+
* CScalar.uint8() { ... } -> CScalar
|
975
|
+
* CScalar.int16() { ... } -> CScalar
|
976
|
+
* CScalar.uint16() { ... } -> CScalar
|
977
|
+
* CScalar.int32() { ... } -> CScalar
|
978
|
+
* CScalar.uint32() { ... } -> CScalar
|
979
|
+
* CScalar.int64() { ... } -> CScalar
|
980
|
+
* CScalar.uint64() { ... } -> CScalar
|
981
|
+
* CScalar.float32() { ... } -> CScalar
|
982
|
+
* CScalar.float64() { ... } -> CScalar
|
983
|
+
* CScalar.float128() { ... } -> CScalar
|
984
|
+
* CScalar.cmplx64() { ... } -> CScalar
|
985
|
+
* CScalar.cmplx128() { ... } -> CScalar
|
986
|
+
* CScalar.cmplx256() { ... } -> CScalar
|
987
|
+
* CScalar.object() { ... } -> CScalar
|
988
|
+
*
|
989
|
+
*/
|
990
|
+
|
991
|
+
static VALUE
|
992
|
+
rb_cs_s_VALUE();
|
993
|
+
|
994
|
+
static VALUE
|
995
|
+
rb_cs_initialize_copy (VALUE self, VALUE other)
|
996
|
+
{
|
997
|
+
CScalar *ca, *cs;
|
998
|
+
|
999
|
+
Data_Get_Struct(self, CScalar, ca);
|
1000
|
+
Data_Get_Struct(other, CScalar, cs);
|
1001
|
+
|
1002
|
+
cscalar_setup(ca, cs->data_type, cs->bytes, NULL);
|
1003
|
+
memcpy(ca->ptr, cs->ptr, ca->bytes);
|
1004
|
+
|
1005
|
+
rb_ca_data_type_inherit(self, other);
|
1006
|
+
|
1007
|
+
return self;
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
/*
|
1011
|
+
* call-seq:
|
1012
|
+
* cs.coerce(o) -> array
|
1013
|
+
*
|
1014
|
+
*/
|
1015
|
+
|
1016
|
+
/*
|
1017
|
+
static VALUE
|
1018
|
+
rb_cs_coerce (VALUE self, VALUE other)
|
1019
|
+
{
|
1020
|
+
CScalar *ca;
|
1021
|
+
Data_Get_Struct(self, CScalar, ca);
|
1022
|
+
return rb_assoc_new(rb_cscalar_new_with_value(ca->data_type, ca->bytes, other),
|
1023
|
+
self);
|
1024
|
+
}
|
1025
|
+
*/
|
1026
|
+
|
1027
|
+
static VALUE
|
1028
|
+
rb_ca_mem_usage (VALUE self)
|
1029
|
+
{
|
1030
|
+
return rb_float_new(ca_mem_usage);
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
void
|
1034
|
+
Init_ca_obj_array ()
|
1035
|
+
{
|
1036
|
+
/* rb_cCArray, CA_OBJ_ARRAY are defined in rb_carray.c */
|
1037
|
+
/* rb_cCAWrap, CA_OBJ_ARRAY_WRAP are defined in rb_carray.c */
|
1038
|
+
/* rb_cCScalar, CA_OBJ_SCALAR are defined in rb_carray.c */
|
1039
|
+
|
1040
|
+
/* ------------------------------------------------------------------- */
|
1041
|
+
ca_gc_interval = ca_default_gc_interval;
|
1042
|
+
rb_define_const(rb_cCArray, "DEFAULT_GC_INTERVAL", rb_float_new(ca_default_gc_interval));
|
1043
|
+
rb_define_singleton_method(rb_cCArray, "gc_interval", rb_ca_get_gc_interval, 0);
|
1044
|
+
rb_define_singleton_method(rb_cCArray, "gc_interval=", rb_ca_set_gc_interval, 1);
|
1045
|
+
rb_define_singleton_method(rb_cCArray, "reset_gc_interval", rb_ca_reset_gc_interval, 0);
|
1046
|
+
|
1047
|
+
rb_define_alloc_func(rb_cCArray, rb_ca_s_allocate);
|
1048
|
+
rb_define_method(rb_cCArray, "initialize", rb_ca_initialize, -1);
|
1049
|
+
|
1050
|
+
rb_define_singleton_method(rb_cCArray, "fixlen", rb_ca_s_fixlen, -1);
|
1051
|
+
rb_define_singleton_method(rb_cCArray, "boolean", rb_ca_s_boolean, -1);
|
1052
|
+
rb_define_singleton_method(rb_cCArray, "int8", rb_ca_s_int8, -1);
|
1053
|
+
rb_define_singleton_method(rb_cCArray, "uint8", rb_ca_s_uint8, -1);
|
1054
|
+
rb_define_singleton_method(rb_cCArray, "int16", rb_ca_s_int16, -1);
|
1055
|
+
rb_define_singleton_method(rb_cCArray, "uint16", rb_ca_s_uint16, -1);
|
1056
|
+
rb_define_singleton_method(rb_cCArray, "int32", rb_ca_s_int32, -1);
|
1057
|
+
rb_define_singleton_method(rb_cCArray, "uint32", rb_ca_s_uint32, -1);
|
1058
|
+
rb_define_singleton_method(rb_cCArray, "int64", rb_ca_s_int64, -1);
|
1059
|
+
rb_define_singleton_method(rb_cCArray, "uint64", rb_ca_s_uint64, -1);
|
1060
|
+
rb_define_singleton_method(rb_cCArray, "float32", rb_ca_s_float32, -1);
|
1061
|
+
rb_define_singleton_method(rb_cCArray, "float64", rb_ca_s_float64, -1);
|
1062
|
+
rb_define_singleton_method(rb_cCArray, "float128", rb_ca_s_float128, -1);
|
1063
|
+
#ifdef HAVE_COMPLEX_H
|
1064
|
+
rb_define_singleton_method(rb_cCArray, "cmplx64", rb_ca_s_cmplx64, -1);
|
1065
|
+
rb_define_singleton_method(rb_cCArray, "cmplx128", rb_ca_s_cmplx128, -1);
|
1066
|
+
rb_define_singleton_method(rb_cCArray, "cmplx256", rb_ca_s_cmplx256, -1);
|
1067
|
+
#endif
|
1068
|
+
rb_define_singleton_method(rb_cCArray, "object", rb_ca_s_VALUE, -1);
|
1069
|
+
|
1070
|
+
rb_define_singleton_method(rb_cCArray, "byte", rb_ca_s_uint8, -1);
|
1071
|
+
rb_define_singleton_method(rb_cCArray, "short", rb_ca_s_int16, -1);
|
1072
|
+
rb_define_singleton_method(rb_cCArray, "int", rb_ca_s_int32, -1);
|
1073
|
+
rb_define_singleton_method(rb_cCArray, "float", rb_ca_s_float32, -1);
|
1074
|
+
rb_define_singleton_method(rb_cCArray, "double", rb_ca_s_float64, -1);
|
1075
|
+
#ifdef HAVE_COMPLEX_H
|
1076
|
+
rb_define_singleton_method(rb_cCArray, "complex", rb_ca_s_cmplx64, -1);
|
1077
|
+
rb_define_singleton_method(rb_cCArray, "dcomplex", rb_ca_s_cmplx128, -1);
|
1078
|
+
#endif
|
1079
|
+
|
1080
|
+
rb_define_method(rb_cCArray, "initialize_copy", rb_ca_initialize_copy, 1);
|
1081
|
+
rb_define_singleton_method(rb_cCArray, "wrap", rb_ca_s_wrap, -1);
|
1082
|
+
|
1083
|
+
/* ------------------------------------------------------------------- */
|
1084
|
+
|
1085
|
+
/* CScalar creation */
|
1086
|
+
rb_define_alloc_func(rb_cCScalar, rb_cs_s_allocate);
|
1087
|
+
rb_define_method(rb_cCScalar, "initialize", rb_cs_initialize, -1);
|
1088
|
+
|
1089
|
+
rb_define_singleton_method(rb_cCScalar, "fixlen", rb_cs_s_fixlen, -1);
|
1090
|
+
rb_define_singleton_method(rb_cCScalar, "boolean", rb_cs_s_boolean, -1);
|
1091
|
+
rb_define_singleton_method(rb_cCScalar, "int8", rb_cs_s_int8, -1);
|
1092
|
+
rb_define_singleton_method(rb_cCScalar, "uint8", rb_cs_s_uint8, -1);
|
1093
|
+
rb_define_singleton_method(rb_cCScalar, "int16", rb_cs_s_int16, -1);
|
1094
|
+
rb_define_singleton_method(rb_cCScalar, "uint16", rb_cs_s_uint16, -1);
|
1095
|
+
rb_define_singleton_method(rb_cCScalar, "int32", rb_cs_s_int32, -1);
|
1096
|
+
rb_define_singleton_method(rb_cCScalar, "uint32", rb_cs_s_uint32, -1);
|
1097
|
+
rb_define_singleton_method(rb_cCScalar, "int64", rb_cs_s_int64, -1);
|
1098
|
+
rb_define_singleton_method(rb_cCScalar, "uint64", rb_cs_s_uint64, -1);
|
1099
|
+
rb_define_singleton_method(rb_cCScalar, "float32", rb_cs_s_float32, -1);
|
1100
|
+
rb_define_singleton_method(rb_cCScalar, "float64", rb_cs_s_float64, -1);
|
1101
|
+
rb_define_singleton_method(rb_cCScalar, "float128", rb_cs_s_float128, -1);
|
1102
|
+
#ifdef HAVE_COMPLEX_H
|
1103
|
+
rb_define_singleton_method(rb_cCScalar, "cmplx64", rb_cs_s_cmplx64, -1);
|
1104
|
+
rb_define_singleton_method(rb_cCScalar, "cmplx128", rb_cs_s_cmplx128, -1);
|
1105
|
+
rb_define_singleton_method(rb_cCScalar, "cmplx256", rb_cs_s_cmplx256, -1);
|
1106
|
+
#endif
|
1107
|
+
rb_define_singleton_method(rb_cCScalar, "object", rb_cs_s_VALUE, -1);
|
1108
|
+
|
1109
|
+
rb_define_singleton_method(rb_cCScalar, "byte", rb_cs_s_uint8, -1);
|
1110
|
+
rb_define_singleton_method(rb_cCScalar, "short", rb_cs_s_int16, -1);
|
1111
|
+
rb_define_singleton_method(rb_cCScalar, "int", rb_cs_s_int32, -1);
|
1112
|
+
rb_define_singleton_method(rb_cCScalar, "float", rb_cs_s_float32, -1);
|
1113
|
+
rb_define_singleton_method(rb_cCScalar, "double", rb_cs_s_float64, -1);
|
1114
|
+
#ifdef HAVE_COMPLEX_H
|
1115
|
+
rb_define_singleton_method(rb_cCScalar, "complex", rb_cs_s_cmplx64, -1);
|
1116
|
+
rb_define_singleton_method(rb_cCScalar, "dcomplex", rb_cs_s_cmplx128, -1);
|
1117
|
+
#endif
|
1118
|
+
|
1119
|
+
rb_define_method(rb_cCScalar, "initialize_copy", rb_cs_initialize_copy, 1);
|
1120
|
+
// rb_define_method(rb_cCScalar, "coerce", rb_cs_coerce, 1);
|
1121
|
+
|
1122
|
+
rb_define_const(rb_cObject, "CA_OBJ_ARRAY", INT2NUM(CA_OBJ_ARRAY));
|
1123
|
+
rb_define_const(rb_cObject, "CA_OBJ_ARRAY_WRAP", INT2NUM(CA_OBJ_ARRAY_WRAP));
|
1124
|
+
rb_define_const(rb_cObject, "CA_OBJ_SCALAR", INT2NUM(CA_OBJ_SCALAR));
|
1125
|
+
|
1126
|
+
rb_define_singleton_method(rb_cCArray, "mem_usage", rb_ca_mem_usage, 0);
|
1127
|
+
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
|
1131
|
+
/* rdoc:
|
1132
|
+
# call-seq:
|
1133
|
+
# CArray.boolean(...) { init_value }
|
1134
|
+
# CArray.int8(...) { init_value }
|
1135
|
+
# CArray.uint8(...) { init_value }
|
1136
|
+
# CArray.int16(...) { init_value }
|
1137
|
+
# CArray.uint16(...) { init_value }
|
1138
|
+
# CArray.int32(...) { init_value }
|
1139
|
+
# CArray.uint32(...) { init_value }
|
1140
|
+
# CArray.int64(...) { init_value }
|
1141
|
+
# CArray.uint64(...) { init_value }
|
1142
|
+
# CArray.float32(...) { init_value }
|
1143
|
+
# CArray.float64(...) { init_value }
|
1144
|
+
# CArray.float128(...) { init_value }
|
1145
|
+
# CArray.cmplx64(...) { init_value }
|
1146
|
+
# CArray.cmplx128(...) { init_value }
|
1147
|
+
# CArray.cmplx256(...) { init_value }
|
1148
|
+
# CArray.fixlen(...) { init_value }
|
1149
|
+
# CArray.object(...) { init_value }
|
1150
|
+
# CArray.byte(...) { init_value }
|
1151
|
+
# CArray.short(...) { init_value }
|
1152
|
+
# CArray.int(...) { init_value }
|
1153
|
+
# CArray.float(...) { init_value }
|
1154
|
+
# CArray.double(...) { init_value }
|
1155
|
+
# CArray.complex(...) { init_value }
|
1156
|
+
# CArray.dcomplex(...) { init_value }
|
1157
|
+
#
|
1158
|
+
def CArray.type
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
# call-seq:
|
1162
|
+
# CScalar.boolean { init_value }
|
1163
|
+
# CScalar.int8 { init_value }
|
1164
|
+
# CScalar.uint8 { init_value }
|
1165
|
+
# CScalar.int16 { init_value }
|
1166
|
+
# CScalar.uint16 { init_value }
|
1167
|
+
# CScalar.int32 { init_value }
|
1168
|
+
# CScalar.uint32 { init_value }
|
1169
|
+
# CScalar.int64 { init_value }
|
1170
|
+
# CScalar.uint64 { init_value }
|
1171
|
+
# CScalar.float32 { init_value }
|
1172
|
+
# CScalar.float64 { init_value }
|
1173
|
+
# CScalar.float128 { init_value }
|
1174
|
+
# CScalar.cmplx64 { init_value }
|
1175
|
+
# CScalar.cmplx128 { init_value }
|
1176
|
+
# CScalar.cmplx256 { init_value }
|
1177
|
+
# CScalar.fixlen { init_value }
|
1178
|
+
# CScalar.object { init_value }
|
1179
|
+
# CScalar.byte { init_value }
|
1180
|
+
# CScalar.short { init_value }
|
1181
|
+
# CScalar.int { init_value }
|
1182
|
+
# CScalar.float { init_value }
|
1183
|
+
# CScalar.double { init_value }
|
1184
|
+
# CScalar.complex { init_value }
|
1185
|
+
# CScalar.dcomplex { init_value }
|
1186
|
+
#
|
1187
|
+
def CScalar.type
|
1188
|
+
end
|
1189
|
+
*/
|