carray 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +56 -0
  3. data/GPL +340 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +33 -0
  6. data/LEGAL +50 -0
  7. data/NOTE +73 -0
  8. data/Rakefile +20 -0
  9. data/TODO +5 -0
  10. data/ca_iter_block.c +242 -0
  11. data/ca_iter_dimension.c +287 -0
  12. data/ca_iter_window.c +202 -0
  13. data/ca_obj_array.c +1189 -0
  14. data/ca_obj_bitarray.c +523 -0
  15. data/ca_obj_bitfield.c +636 -0
  16. data/ca_obj_block.c +885 -0
  17. data/ca_obj_fake.c +405 -0
  18. data/ca_obj_farray.c +482 -0
  19. data/ca_obj_field.c +625 -0
  20. data/ca_obj_grid.c +738 -0
  21. data/ca_obj_mapping.c +614 -0
  22. data/ca_obj_object.c +777 -0
  23. data/ca_obj_reduce.c +299 -0
  24. data/ca_obj_refer.c +627 -0
  25. data/ca_obj_repeat.c +640 -0
  26. data/ca_obj_select.c +558 -0
  27. data/ca_obj_shift.c +952 -0
  28. data/ca_obj_transpose.c +582 -0
  29. data/ca_obj_unbound_repeat.c +557 -0
  30. data/ca_obj_window.c +1023 -0
  31. data/carray.h +1381 -0
  32. data/carray_access.c +1798 -0
  33. data/carray_attribute.c +903 -0
  34. data/carray_call_cfunc.c +1107 -0
  35. data/carray_cast.c +1155 -0
  36. data/carray_cast_func.rb +498 -0
  37. data/carray_class.c +132 -0
  38. data/carray_conversion.c +518 -0
  39. data/carray_copy.c +453 -0
  40. data/carray_core.c +1307 -0
  41. data/carray_element.c +572 -0
  42. data/carray_generate.c +681 -0
  43. data/carray_iterator.c +630 -0
  44. data/carray_loop.c +462 -0
  45. data/carray_mask.c +1174 -0
  46. data/carray_math.rb +834 -0
  47. data/carray_numeric.c +257 -0
  48. data/carray_operator.c +582 -0
  49. data/carray_order.c +1040 -0
  50. data/carray_random.c +529 -0
  51. data/carray_sort_addr.c +261 -0
  52. data/carray_stat.c +2102 -0
  53. data/carray_stat_proc.rb +1990 -0
  54. data/carray_test.c +602 -0
  55. data/carray_undef.c +69 -0
  56. data/carray_utils.c +740 -0
  57. data/ext/calculus/carray_calculus.c +792 -0
  58. data/ext/calculus/carray_interp.c +355 -0
  59. data/ext/calculus/extconf.rb +12 -0
  60. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +2 -0
  61. data/ext/calculus/lib/math/calculus.rb +119 -0
  62. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +31 -0
  63. data/ext/dataframe/API.txt +11 -0
  64. data/ext/dataframe/extconf.rb +3 -0
  65. data/ext/dataframe/lib/carray/autoload/autoload_dataframe_dataframe.rb +14 -0
  66. data/ext/dataframe/lib/carray/dataframe/dataframe.rb +1104 -0
  67. data/ext/dataframe/sample/test_uniq_sort.rb +5 -0
  68. data/ext/fortio/extconf.rb +3 -0
  69. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +5 -0
  70. data/ext/fortio/lib/carray/io/fortran_format.rb +43 -0
  71. data/ext/fortio/lib/fortio.rb +3 -0
  72. data/ext/fortio/lib/fortio/fortran_format.rb +603 -0
  73. data/ext/fortio/lib/fortio/fortran_format.tab.rb +536 -0
  74. data/ext/fortio/lib/fortio/fortran_format.y +215 -0
  75. data/ext/fortio/lib/fortio/fortran_namelist.rb +151 -0
  76. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +470 -0
  77. data/ext/fortio/lib/fortio/fortran_namelist.y +213 -0
  78. data/ext/fortio/lib/fortio/fortran_sequential.rb +345 -0
  79. data/ext/fortio/ruby_fortio.c +182 -0
  80. data/ext/fortio/test/test_H.rb +5 -0
  81. data/ext/fortio/test/test_T.rb +7 -0
  82. data/ext/fortio/test/test_fortran_format.rb +86 -0
  83. data/ext/fortio/test/test_namelist.rb +25 -0
  84. data/ext/fortio/test/test_sequential.rb +13 -0
  85. data/ext/fortio/test/test_sequential2.rb +13 -0
  86. data/ext/fortio/work/test.rb +10 -0
  87. data/ext/fortio/work/test_e.rb +19 -0
  88. data/ext/fortio/work/test_ep.rb +10 -0
  89. data/ext/fortio/work/test_parse.rb +12 -0
  90. data/ext/imagemap/carray_imagemap.c +495 -0
  91. data/ext/imagemap/doc/call_graph.dot +28 -0
  92. data/ext/imagemap/draw.c +567 -0
  93. data/ext/imagemap/extconf.rb +13 -0
  94. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +1 -0
  95. data/ext/imagemap/lib/graphics/imagemap.rb +273 -0
  96. data/ext/imagemap/lib/image_map.rb +4 -0
  97. data/ext/imagemap/test/swath_index.rb +83 -0
  98. data/ext/imagemap/test/swath_warp.rb +99 -0
  99. data/ext/imagemap/test/test.rb +23 -0
  100. data/ext/imagemap/test/test_image.rb +42 -0
  101. data/ext/imagemap/test/test_line.rb +14 -0
  102. data/ext/imagemap/test/test_rotate.rb +17 -0
  103. data/ext/imagemap/test/test_triangle.rb +20 -0
  104. data/ext/imagemap/test/test_warp.rb +26 -0
  105. data/ext/mathfunc/carray_mathfunc.c +321 -0
  106. data/ext/mathfunc/extconf.rb +18 -0
  107. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +1 -0
  108. data/ext/mathfunc/lib/math/mathfunc.rb +15 -0
  109. data/ext/mathfunc/test/test_hypot.rb +5 -0
  110. data/ext/mathfunc/test/test_j0.rb +22 -0
  111. data/ext/mathfunc/test/test_jn.rb +8 -0
  112. data/ext/mathfunc/test/test_sph.rb +9 -0
  113. data/ext/narray/README +22 -0
  114. data/ext/narray/ca_wrap_narray.c +491 -0
  115. data/ext/narray/carray_narray.c +21 -0
  116. data/ext/narray/extconf.rb +57 -0
  117. data/ext/narray/lib/autoload/autoload_math_narray.rb +1 -0
  118. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +11 -0
  119. data/ext/narray/lib/math/narray.rb +17 -0
  120. data/ext/narray/lib/math/narray_miss.rb +45 -0
  121. data/extconf.rb +3 -25
  122. data/lib/carray.rb +28 -0
  123. data/lib/carray/autoload/autoload_base.rb +23 -0
  124. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +2 -0
  125. data/lib/carray/autoload/autoload_io_csv.rb +14 -0
  126. data/lib/carray/autoload/autoload_io_excel.rb +5 -0
  127. data/lib/carray/autoload/autoload_io_imagemagick.rb +6 -0
  128. data/lib/carray/autoload/autoload_io_pg.rb +6 -0
  129. data/lib/carray/autoload/autoload_io_sqlite3.rb +12 -0
  130. data/lib/carray/autoload/autoload_io_table.rb +1 -0
  131. data/lib/carray/autoload/autoload_math_histogram.rb +5 -0
  132. data/lib/carray/autoload/autoload_math_interp.rb +4 -0
  133. data/lib/carray/autoload/autoload_math_recurrence.rb +6 -0
  134. data/lib/carray/autoload/autoload_object_iterator.rb +1 -0
  135. data/lib/carray/autoload/autoload_object_link.rb +1 -0
  136. data/lib/carray/autoload/autoload_object_pack.rb +2 -0
  137. data/lib/carray/base/autoload.rb +94 -0
  138. data/lib/carray/base/basic.rb +1051 -0
  139. data/lib/carray/base/inspect.rb +252 -0
  140. data/lib/carray/base/iterator.rb +367 -0
  141. data/lib/carray/base/math.rb +403 -0
  142. data/lib/carray/base/obsolete.rb +93 -0
  143. data/lib/carray/base/serialize.rb +260 -0
  144. data/lib/carray/base/struct.rb +634 -0
  145. data/lib/carray/graphics/gnuplot.rb +2116 -0
  146. data/lib/carray/info.rb +112 -0
  147. data/lib/carray/io/csv.rb +560 -0
  148. data/lib/carray/io/excel.rb +26 -0
  149. data/lib/carray/io/imagemagick.rb +231 -0
  150. data/lib/carray/io/pg.rb +101 -0
  151. data/lib/carray/io/sqlite3.rb +202 -0
  152. data/lib/carray/io/table.rb +77 -0
  153. data/lib/carray/math/histogram.rb +179 -0
  154. data/lib/carray/math/interp.rb +57 -0
  155. data/lib/carray/math/interp/adapter_gsl_spline.rb +47 -0
  156. data/lib/carray/math/recurrence.rb +95 -0
  157. data/lib/carray/mkmf.rb +145 -0
  158. data/lib/carray/object/ca_obj_iterator.rb +52 -0
  159. data/lib/carray/object/ca_obj_link.rb +52 -0
  160. data/lib/carray/object/ca_obj_pack.rb +101 -0
  161. data/mkmath.rb +731 -0
  162. data/mt19937ar.c +182 -0
  163. data/mt19937ar.h +86 -0
  164. data/rdoc_main.rb +27 -0
  165. data/rdoc_math.rb +5 -0
  166. data/rdoc_stat.rb +31 -0
  167. data/ruby_carray.c +242 -0
  168. data/ruby_ccomplex.c +497 -0
  169. data/ruby_float_func.c +83 -0
  170. data/spec/CABlockIterator/CABlockIterator_spec.rb +113 -0
  171. data/spec/CArray/bug/store_spec.rb +27 -0
  172. data/spec/CArray/index/repeat_spec.rb +10 -0
  173. data/spec/CArray/method/eq_spec.rb +80 -0
  174. data/spec/CArray/method/is_nan_spec.rb +12 -0
  175. data/spec/CArray/method/ne_spec.rb +18 -0
  176. data/spec/CArray/method/round_spec.rb +11 -0
  177. data/spec/CArray/object/_attribute_spec.rb +32 -0
  178. data/spec/CArray/object/s_new_spec.rb +31 -0
  179. data/spec/CArray/serialize/Serialization_spec.rb +89 -0
  180. data/spec/spec_all.rb +11 -0
  181. data/test/test_ALL.rb +50 -0
  182. data/test/test_CABitfield.rb +59 -0
  183. data/test/test_CABlock.rb +208 -0
  184. data/test/test_CAField.rb +40 -0
  185. data/test/test_CAGrid.rb +76 -0
  186. data/test/test_CAMapping.rb +106 -0
  187. data/test/test_CAMmap.rb +11 -0
  188. data/test/test_CARefer.rb +94 -0
  189. data/test/test_CARepeat.rb +66 -0
  190. data/test/test_CASelect.rb +23 -0
  191. data/test/test_CAShift.rb +17 -0
  192. data/test/test_CATranspose.rb +61 -0
  193. data/test/test_CAVirtual.rb +214 -0
  194. data/test/test_CAWindow.rb +55 -0
  195. data/test/test_CAWrap.rb +9 -0
  196. data/test/test_CArray.rb +228 -0
  197. data/test/test_CComplex.rb +83 -0
  198. data/test/test_CScalar.rb +91 -0
  199. data/test/test_attribute.rb +281 -0
  200. data/test/test_block_iterator.rb +17 -0
  201. data/test/test_boolean.rb +99 -0
  202. data/test/test_cast.rb +33 -0
  203. data/test/test_class.rb +85 -0
  204. data/test/test_complex.rb +43 -0
  205. data/test/test_composite.rb +125 -0
  206. data/test/test_convert.rb +79 -0
  207. data/test/test_copy.rb +141 -0
  208. data/test/test_creation.rb +85 -0
  209. data/test/test_element.rb +146 -0
  210. data/test/test_extream.rb +55 -0
  211. data/test/test_generate.rb +75 -0
  212. data/test/test_index.rb +71 -0
  213. data/test/test_mask.rb +578 -0
  214. data/test/test_math.rb +98 -0
  215. data/test/test_narray.rb +64 -0
  216. data/test/test_order.rb +147 -0
  217. data/test/test_random.rb +15 -0
  218. data/test/test_ref_store.rb +211 -0
  219. data/test/test_stat.rb +414 -0
  220. data/test/test_struct.rb +72 -0
  221. data/test/test_virtual.rb +49 -0
  222. data/utils/ca_ase.rb +21 -0
  223. data/utils/ca_methods.rb +15 -0
  224. data/utils/cast_checker.rb +30 -0
  225. data/utils/create_rdoc.sh +9 -0
  226. data/utils/diff_method.rb +52 -0
  227. data/utils/extract_rdoc.rb +27 -0
  228. data/utils/make_tgz.sh +3 -0
  229. data/utils/remove_resource_fork.sh +5 -0
  230. data/version.h +3 -3
  231. metadata +266 -1
@@ -0,0 +1,625 @@
1
+ /* ---------------------------------------------------------------------------
2
+
3
+ ca_obj_field.c
4
+
5
+ This file is part of Ruby/CArray extension library.
6
+ You can redistribute it and/or modify it under the terms of
7
+ the Ruby Licence.
8
+
9
+ Copyright (C) 2005 Hiroki Motoyoshi
10
+
11
+ ---------------------------------------------------------------------------- */
12
+
13
+ #include "carray.h"
14
+
15
+ typedef struct {
16
+ int16_t obj_type;
17
+ int8_t data_type;
18
+ int8_t rank;
19
+ int32_t flags;
20
+ int32_t bytes;
21
+ int32_t elements;
22
+ int32_t *dim;
23
+ char *ptr;
24
+ CArray *mask;
25
+ CArray *parent;
26
+ uint32_t attach;
27
+ uint8_t nosync;
28
+ /* -------------*/
29
+ int32_t offset;
30
+ } CAField;
31
+
32
+ static int8_t CA_OBJ_FIELD;
33
+
34
+ static VALUE rb_cCAField;
35
+
36
+ /* rdoc:
37
+ class CAField < CAVirtual # :nodoc:
38
+ end
39
+ */
40
+
41
+ /* ------------------------------------------------------------------- */
42
+
43
+ int
44
+ ca_field_setup (CAField *ca, CArray *parent,
45
+ int32_t offset, int8_t data_type, int32_t bytes)
46
+ {
47
+ int8_t rank;
48
+ int32_t elements;
49
+
50
+ /* check arguments */
51
+
52
+ CA_CHECK_DATA_TYPE(data_type);
53
+ CA_CHECK_BYTES(data_type, bytes);
54
+ if ( offset < 0 ) {
55
+ rb_raise(rb_eRuntimeError, "negative offset");
56
+ }
57
+
58
+ if ( data_type == CA_OBJECT ) {
59
+ rb_raise(rb_eCADataTypeError,
60
+ "CA_OBJECT can not to be a data_type for CAField");
61
+ }
62
+
63
+ if ( parent->bytes < offset + bytes ) {
64
+ rb_raise(rb_eRuntimeError, "offset or bytes out of range");
65
+ }
66
+
67
+ rank = parent->rank;
68
+ elements = parent->elements;
69
+
70
+ ca->obj_type = CA_OBJ_FIELD;
71
+ ca->data_type = data_type;
72
+ ca->flags = 0;
73
+ ca->rank = rank;
74
+ ca->bytes = bytes;
75
+ ca->elements = elements;
76
+ ca->ptr = NULL;
77
+ ca->mask = NULL;
78
+ ca->dim = ALLOC_N(int32_t, rank);
79
+
80
+ ca->parent = parent;
81
+ ca->attach = 0;
82
+ ca->nosync = 0;
83
+ ca->offset = offset;
84
+
85
+ memcpy(ca->dim, parent->dim, rank * sizeof(int32_t));
86
+
87
+ if ( ca_has_mask(parent) ) {
88
+ ca_create_mask(ca);
89
+ }
90
+
91
+ if ( ca_is_scalar(parent) ) {
92
+ ca_set_flag(ca, CA_FLAG_SCALAR);
93
+ }
94
+
95
+ return 0;
96
+ }
97
+
98
+ CAField *
99
+ ca_field_new (CArray *parent, int32_t offset, int8_t data_type, int32_t bytes)
100
+ {
101
+ CAField *ca = ALLOC(CAField);
102
+ ca_field_setup(ca, parent, offset, data_type, bytes);
103
+ return ca;
104
+ }
105
+
106
+ static void
107
+ free_ca_field (void *ap)
108
+ {
109
+ CAField *ca = (CAField *) ap;
110
+ if ( ca != NULL ) {
111
+ ca_free(ca->mask);
112
+ xfree(ca->dim);
113
+ xfree(ca);
114
+ }
115
+ }
116
+
117
+ static void ca_field_attach (CAField *ca);
118
+ static void ca_field_sync (CAField *ca);
119
+ static void ca_field_fill (CAField *ca, char *ptr);
120
+
121
+ /* ------------------------------------------------------------------- */
122
+
123
+ static void *
124
+ ca_field_func_clone (void *ap)
125
+ {
126
+ CAField *ca = (CAField *) ap;
127
+ return ca_field_new(ca->parent, ca->offset, ca->data_type, ca->bytes);
128
+ }
129
+
130
+ static char *
131
+ ca_field_func_ptr_at_addr (void *ap, int32_t addr)
132
+ {
133
+ CAField *ca = (CAField *) ap;
134
+ if ( ! ca->ptr ) {
135
+ int32_t idx[CA_RANK_MAX];
136
+ ca_addr2index((CArray *)ca, addr, idx);
137
+ return ca_ptr_at_index(ca, idx);
138
+ }
139
+ else {
140
+ return ca->ptr + ca->bytes * addr;
141
+ }
142
+ }
143
+
144
+ static char *
145
+ ca_field_func_ptr_at_index (void *ap, int32_t *idx)
146
+ {
147
+ CAField *ca = (CAField *) ap;
148
+ if ( ! ca->ptr ) {
149
+ int32_t *dim = ca->dim;
150
+ int32_t i, n;
151
+ n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[rank-1] */
152
+ for (i=1; i<ca->rank; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[rank-1] */
153
+ n = dim[i]*n+idx[i]; /* ... + idx[rank-2]*dim[1] + idx[rank-1] */
154
+ }
155
+
156
+ if ( ca->parent->ptr == NULL ) {
157
+ return ca_ptr_at_addr(ca->parent, n) + ca->offset;
158
+ }
159
+ else {
160
+ return ca->parent->ptr + ca->parent->bytes * n + ca->offset;
161
+ }
162
+ }
163
+ else {
164
+ return ca_func[CA_OBJ_ARRAY].ptr_at_index(ca, idx);
165
+ }
166
+ }
167
+
168
+ static void
169
+ ca_field_func_fetch_index (void *ap, int32_t *idx, void *ptr)
170
+ {
171
+ CAField *ca = (CAField *) ap;
172
+ if ( ca->parent->bytes <= 32 ) {
173
+ char v[32];
174
+ ca_fetch_index(ca->parent, idx, v);
175
+ memcpy(ptr, v + ca->offset, ca->bytes);
176
+ }
177
+ else {
178
+ char *v = malloc_with_check(ca->parent->bytes);
179
+ ca_fetch_index(ca->parent, idx, v);
180
+ memcpy(ptr, v + ca->offset, ca->bytes);
181
+ free(v);
182
+ }
183
+ }
184
+
185
+ static void
186
+ ca_field_func_store_index (void *ap, int32_t *idx, void *ptr)
187
+ {
188
+ CAField *ca = (CAField *) ap;
189
+ if ( ca->parent->bytes <= 32 ) {
190
+ char v[32];
191
+ ca_fetch_index(ca->parent, idx, v);
192
+ memcpy(v + ca->offset, ptr, ca->bytes);
193
+ ca_store_index(ca->parent, idx, v);
194
+ }
195
+ else {
196
+ char *v = malloc_with_check(ca->parent->bytes);
197
+ ca_fetch_index(ca->parent, idx, v);
198
+ memcpy(v + ca->offset, ptr, ca->bytes);
199
+ ca_store_index(ca->parent, idx, v);
200
+ free(v);
201
+ }
202
+ }
203
+
204
+ static void
205
+ ca_field_func_allocate (void *ap)
206
+ {
207
+ CAField *ca = (CAField *) ap;
208
+ ca_attach(ca->parent);
209
+ /* ca->ptr = ALLOC_N(char, ca_length(ca)); */
210
+ ca->ptr = malloc_with_check(ca_length(ca));
211
+ }
212
+
213
+ static void
214
+ ca_field_func_attach (void *ap)
215
+ {
216
+ void ca_field_attach (CAField *cb);
217
+
218
+ CAField *ca = (CAField *) ap;
219
+ ca_attach(ca->parent);
220
+ /* ca->ptr = ALLOC_N(char, ca_length(ca)); */
221
+ ca->ptr = malloc_with_check(ca_length(ca));
222
+ ca_field_attach(ca);
223
+ }
224
+
225
+ static void
226
+ ca_field_func_sync (void *ap)
227
+ {
228
+ CAField *ca = (CAField *) ap;
229
+ ca_field_sync(ca);
230
+ ca_sync(ca->parent);
231
+ }
232
+
233
+ static void
234
+ ca_field_func_detach (void *ap)
235
+ {
236
+ CAField *ca = (CAField *) ap;
237
+ free(ca->ptr);
238
+ ca->ptr = NULL;
239
+ ca_detach(ca->parent);
240
+ }
241
+
242
+ static void
243
+ ca_field_func_copy_data (void *ap, void *ptr)
244
+ {
245
+ CAField *ca = (CAField *) ap;
246
+ char *ptr0 = ca->ptr;
247
+ ca_attach(ca->parent);
248
+ ca->ptr = ptr;
249
+ ca_field_attach(ca);
250
+ ca->ptr = ptr0;
251
+ ca_detach(ca->parent);
252
+ }
253
+
254
+ static void
255
+ ca_field_func_sync_data (void *ap, void *ptr)
256
+ {
257
+ CAField *ca = (CAField *) ap;
258
+ char *ptr0 = ca->ptr;
259
+ ca_attach(ca->parent);
260
+ ca->ptr = ptr;
261
+ ca_field_sync(ca);
262
+ ca->ptr = ptr0;
263
+ ca_sync(ca->parent);
264
+ ca_detach(ca->parent);
265
+ }
266
+
267
+ static void
268
+ ca_field_func_fill_data (void *ap, void *ptr)
269
+ {
270
+ CAField *ca = (CAField *) ap;
271
+ ca_attach(ca->parent);
272
+ ca_field_fill(ca, ptr);
273
+ ca_sync(ca->parent);
274
+ ca_detach(ca->parent);
275
+ }
276
+
277
+ static void
278
+ ca_field_func_create_mask (void *ap)
279
+ {
280
+ CAField *ca = (CAField *) ap;
281
+ ca_update_mask(ca->parent);
282
+ if ( ! ca->parent->mask ) {
283
+ ca_create_mask(ca->parent);
284
+ }
285
+ ca->mask =
286
+ (CArray *) ca_refer_new(ca->parent->mask,
287
+ CA_BOOLEAN, ca->rank, ca->dim, 0, 0);
288
+ }
289
+
290
+ ca_operation_function_t ca_field_func = {
291
+ -1, /* CA_OBJ_FIELD */
292
+ CA_VIRTUAL_ARRAY,
293
+ free_ca_field,
294
+ ca_field_func_clone,
295
+ ca_field_func_ptr_at_addr,
296
+ ca_field_func_ptr_at_index,
297
+ NULL,
298
+ ca_field_func_fetch_index,
299
+ NULL,
300
+ ca_field_func_store_index,
301
+ ca_field_func_allocate,
302
+ ca_field_func_attach,
303
+ ca_field_func_sync,
304
+ ca_field_func_detach,
305
+ ca_field_func_copy_data,
306
+ ca_field_func_sync_data,
307
+ ca_field_func_fill_data,
308
+ ca_field_func_create_mask,
309
+ };
310
+
311
+ /* ------------------------------------------------------------------- */
312
+
313
+ static void
314
+ ca_field_attach (CAField *ca)
315
+ {
316
+ int32_t pbytes = ca->parent->bytes;
317
+ int32_t bytes = ca->bytes;
318
+ int32_t n = ca->elements;
319
+
320
+ switch ( ca->data_type ) {
321
+ case CA_BOOLEAN:
322
+ case CA_INT8:
323
+ case CA_UINT8:
324
+ {
325
+ char *p = ca_ptr_at_addr(ca, 0);
326
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
327
+ while ( n-- ) {
328
+ *p = *q;
329
+ p += 1; q += pbytes;
330
+ }
331
+ }
332
+ break;
333
+ case CA_INT16:
334
+ case CA_UINT16:
335
+ {
336
+ int16_t *p = (int16_t*) ca_ptr_at_addr(ca, 0);
337
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
338
+ while ( n-- ) {
339
+ *p = *(int16_t*) q;
340
+ p += 1; q += pbytes;
341
+ }
342
+ }
343
+ break;
344
+ case CA_INT32:
345
+ case CA_UINT32:
346
+ case CA_FLOAT32:
347
+ {
348
+ int32_t *p = (int32_t*) ca_ptr_at_addr(ca, 0);
349
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
350
+ while ( n-- ) {
351
+ *p = *(int32_t*) q;
352
+ p += 1; q += pbytes;
353
+ }
354
+ }
355
+ break;
356
+ case CA_INT64:
357
+ case CA_UINT64:
358
+ case CA_FLOAT64:
359
+ {
360
+ float64_t *p = (float64_t*) ca_ptr_at_addr(ca, 0);
361
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
362
+ while ( n-- ) {
363
+ *p = *(float64_t*) q;
364
+ p += 1; q += pbytes;
365
+ }
366
+ }
367
+ break;
368
+ default:
369
+ {
370
+ char *p = ca_ptr_at_addr(ca, 0);
371
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
372
+ while ( n-- ) {
373
+ memcpy(p, q, ca->bytes);
374
+ p += bytes; q += pbytes;
375
+ }
376
+ }
377
+ }
378
+ }
379
+
380
+ static void
381
+ ca_field_sync (CAField *ca)
382
+ {
383
+ int32_t pbytes = ca->parent->bytes;
384
+ int32_t bytes = ca->bytes;
385
+ int32_t n = ca->elements;
386
+
387
+ switch ( ca->data_type ) {
388
+ case CA_BOOLEAN:
389
+ case CA_INT8:
390
+ case CA_UINT8:
391
+ {
392
+ char *p = ca_ptr_at_addr(ca, 0);
393
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
394
+ while ( n-- ) {
395
+ *q = *p;
396
+ p += 1; q += pbytes;
397
+ }
398
+ }
399
+ break;
400
+ case CA_INT16:
401
+ case CA_UINT16:
402
+ {
403
+ int16_t *p = (int16_t*) ca_ptr_at_addr(ca, 0);
404
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
405
+ while ( n-- ) {
406
+ *(int16_t*) q = *p;
407
+ p += 1; q += pbytes;
408
+ }
409
+ }
410
+ break;
411
+ case CA_INT32:
412
+ case CA_UINT32:
413
+ case CA_FLOAT32:
414
+ {
415
+ int32_t *p = (int32_t*) ca_ptr_at_addr(ca, 0);
416
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
417
+ while ( n-- ) {
418
+ *(int32_t*) q = *p;
419
+ p += 1; q += pbytes;
420
+ }
421
+ }
422
+ break;
423
+ case CA_INT64:
424
+ case CA_UINT64:
425
+ case CA_FLOAT64:
426
+ {
427
+ float64_t *p = (float64_t*) ca_ptr_at_addr(ca, 0);
428
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
429
+ while ( n-- ) {
430
+ *(float64_t*) q = *p;
431
+ p += 1; q += pbytes;
432
+ }
433
+ }
434
+ break;
435
+ default:
436
+ {
437
+ char *p = ca_ptr_at_addr(ca, 0);
438
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
439
+ while ( n-- ) {
440
+ memcpy(q, p, ca->bytes);
441
+ p += bytes; q += pbytes;
442
+ }
443
+ }
444
+ }
445
+ }
446
+
447
+ static void
448
+ ca_field_fill (CAField *ca, char *ptr)
449
+ {
450
+ int32_t pbytes = ca->parent->bytes;
451
+ int32_t n = ca->elements;
452
+ char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
453
+
454
+ switch ( ca->data_type ) {
455
+ case CA_BOOLEAN:
456
+ case CA_INT8:
457
+ case CA_UINT8:
458
+ {
459
+ char *p = ptr;
460
+ while ( n-- ) {
461
+ *q = *p;
462
+ q += pbytes;
463
+ }
464
+ }
465
+ break;
466
+ case CA_INT16:
467
+ case CA_UINT16:
468
+ {
469
+ int16_t *p = (int16_t*) ptr;
470
+ while ( n-- ) {
471
+ *(int16_t*) q = *p;
472
+ q += pbytes;
473
+ }
474
+ }
475
+ break;
476
+ case CA_INT32:
477
+ case CA_UINT32:
478
+ case CA_FLOAT32:
479
+ {
480
+ int32_t *p = (int32_t*) ptr;
481
+ while ( n-- ) {
482
+ *(int32_t*) q = *p;
483
+ q += pbytes;
484
+ }
485
+ }
486
+ break;
487
+ case CA_INT64:
488
+ case CA_UINT64:
489
+ case CA_FLOAT64:
490
+ {
491
+ float64_t *p = (float64_t*) ptr;
492
+ while ( n-- ) {
493
+ *(float64_t*) q = *p;
494
+ q += pbytes;
495
+ }
496
+ }
497
+ break;
498
+ default:
499
+ {
500
+ while ( n-- ) {
501
+ memcpy(q, ptr, ca->bytes);
502
+ q += pbytes;
503
+ }
504
+ }
505
+ }
506
+
507
+ }
508
+
509
+ /* ------------------------------------------------------------------- */
510
+
511
+ VALUE
512
+ rb_ca_field_new (VALUE cary, int32_t offset, int8_t data_type, int32_t bytes)
513
+ {
514
+ volatile VALUE obj;
515
+ CArray *parent;
516
+ CAField *ca;
517
+ rb_check_carray_object(cary);
518
+ Data_Get_Struct(cary, CArray, parent);
519
+ ca = ca_field_new(parent, offset, data_type, bytes);
520
+ obj = ca_wrap_struct(ca);
521
+ rb_ca_set_parent(obj, cary);
522
+ return obj;
523
+ }
524
+
525
+ static VALUE
526
+ rb_ca_field_s_allocate (VALUE klass)
527
+ {
528
+ CAField *ca;
529
+ return Data_Make_Struct(klass, CAField, ca_mark, ca_free, ca);
530
+ }
531
+
532
+ static VALUE
533
+ rb_ca_field_initialize_copy (VALUE self, VALUE other)
534
+ {
535
+ CAField *ca, *cs;
536
+
537
+ Data_Get_Struct(self, CAField, ca);
538
+ Data_Get_Struct(other, CAField, cs);
539
+
540
+ ca_field_setup(ca, cs->parent, cs->offset, cs->data_type, cs->bytes);
541
+
542
+ return self;
543
+ }
544
+
545
+ /* ----------------------------------------------------------------------- */
546
+
547
+ /* rdoc:
548
+ class CArray
549
+ # call-seq:
550
+ # CArray#field(offset, data_type[, :bytes=>bytes])
551
+ # CArray#field(offset, data_class)
552
+ # CArray#field(offset, template)
553
+ #
554
+ def field (offset, data_type)
555
+ end
556
+ end
557
+ */
558
+
559
+ VALUE
560
+ rb_ca_field (int argc, VALUE *argv, VALUE self)
561
+ {
562
+ volatile VALUE obj, voffset, rtype, ropt, rbytes = Qnil;
563
+ CArray *ca;
564
+ int8_t data_type;
565
+ int32_t offset, bytes;
566
+
567
+ if ( argc == 1 ) {
568
+ return rb_ca_field_as_member(self, argv[0]);
569
+ }
570
+
571
+ Data_Get_Struct(self, CArray, ca);
572
+
573
+ /* CArray#field(offset, data_type[, :bytes=>bytes]) */
574
+ /* CArray#field(offset, data_class) */
575
+ /* CArray#field(offset, template) */
576
+
577
+ rb_scan_args(argc, argv, "21", &voffset, &rtype, &ropt);
578
+ rb_scan_options(ropt, "bytes", &rbytes);
579
+
580
+ offset = NUM2INT(voffset);
581
+
582
+ if ( rb_obj_is_carray(rtype) ) {
583
+ CArray *ct;
584
+ int32_t dim[CA_RANK_MAX];
585
+ int8_t rank;
586
+ int i, j;
587
+ Data_Get_Struct(rtype, CArray, ct);
588
+ data_type = CA_FIXLEN;
589
+ bytes = ct->bytes * ct->elements;
590
+ obj = rb_ca_field_new(self, offset, data_type, bytes);
591
+ rb_ca_data_type_inherit(obj, rtype);
592
+ rank = ca->rank + ct->rank;
593
+ for (i=0; i<ca->rank; i++) {
594
+ dim[i] = ca->dim[i];
595
+ }
596
+ for (j=0; j<ct->rank; j++, i++) {
597
+ dim[i] = ct->dim[j];
598
+ }
599
+ obj = rb_ca_refer_new(obj, ct->data_type, rank, dim, ct->bytes, 0);
600
+ }
601
+ else {
602
+ rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
603
+ obj = rb_ca_field_new(self, offset, data_type, bytes);
604
+ rb_ca_data_type_import(obj, rtype);
605
+ }
606
+
607
+ return obj;
608
+ }
609
+
610
+
611
+ void
612
+ Init_ca_obj_field ()
613
+ {
614
+ rb_cCAField = rb_define_class("CAField", rb_cCAVirtual);
615
+
616
+ CA_OBJ_FIELD = ca_install_obj_type(rb_cCAField, ca_field_func);
617
+ rb_define_const(rb_cObject, "CA_OBJ_FIELD", INT2NUM(CA_OBJ_FIELD));
618
+
619
+ rb_define_method(rb_cCArray, "field", rb_ca_field, -1);
620
+
621
+ rb_define_alloc_func(rb_cCAField, rb_ca_field_s_allocate);
622
+ rb_define_method(rb_cCAField, "initialize_copy",
623
+ rb_ca_field_initialize_copy, 1);
624
+ }
625
+