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,1023 @@
1
+ /* ---------------------------------------------------------------------------
2
+
3
+ ca_obj_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
+ /* should not be static variable as used by CAIteratorWindow */
16
+
17
+ VALUE rb_cCAWindow;
18
+ int8_t CA_OBJ_WINDOW;
19
+
20
+ /* rdoc:
21
+ class CAWindow < CAVirtual # :nodoc:
22
+ end
23
+ */
24
+
25
+
26
+ /* ------------------------------------------------------------------- */
27
+
28
+ int
29
+ ca_window_setup (CAWindow *ca, CArray *parent,
30
+ int32_t *start, int32_t *count, int8_t bounds, char *fill)
31
+ {
32
+ int8_t data_type, rank;
33
+ int32_t *dim;
34
+ int32_t bytes, elements;
35
+ int i;
36
+
37
+ data_type = parent->data_type;
38
+ rank = parent->rank;
39
+ bytes = parent->bytes;
40
+ dim = parent->dim;
41
+
42
+ elements = 1;
43
+ for (i=0; i<rank; i++) {
44
+ if ( count[i] <= 0 ) {
45
+ rb_raise(rb_eIndexError,
46
+ "invalid size for %i-th dimension (negative or zero)", i);
47
+ }
48
+ elements *= count[i];
49
+ }
50
+
51
+ ca->obj_type = CA_OBJ_WINDOW;
52
+ ca->data_type = data_type;
53
+ ca->flags = 0;
54
+ ca->rank = rank;
55
+ ca->bytes = bytes;
56
+ ca->elements = elements;
57
+ ca->ptr = NULL;
58
+ ca->mask = NULL;
59
+ /* ca->dim will set as ca->count below */
60
+
61
+ ca->parent = parent;
62
+ ca->attach = 0;
63
+ ca->nosync = 0;
64
+ ca->bounds = bounds;
65
+ ca->start = ALLOC_N(int32_t, rank);
66
+ ca->count = ALLOC_N(int32_t, rank);
67
+ ca->size0 = ALLOC_N(int32_t, rank);
68
+ ca->fill = ALLOC_N(char, ca->bytes);
69
+
70
+ ca->dim = ca->count;
71
+
72
+ memcpy(ca->start, start, rank * sizeof(int32_t));
73
+ memcpy(ca->count, count, rank * sizeof(int32_t));
74
+ memcpy(ca->size0, dim, rank * sizeof(int32_t));
75
+
76
+ if ( fill ) {
77
+ memcpy(ca->fill, fill, ca->bytes);
78
+ }
79
+ else {
80
+ if ( ca_is_object_type(ca) ) {
81
+ *(VALUE *)ca->fill = INT2FIX(0);
82
+ }
83
+ else {
84
+ memset(ca->fill, 0, ca->bytes);
85
+ }
86
+ }
87
+
88
+ if ( ca->bounds == CA_BOUNDS_MASK ) {
89
+ ca_create_mask(ca);
90
+ }
91
+
92
+ return 0;
93
+ }
94
+
95
+ CAWindow *
96
+ ca_window_new (CArray *parent,
97
+ int32_t *start, int32_t *count, int8_t bounds, char *fill)
98
+ {
99
+ CAWindow *ca = ALLOC(CAWindow);
100
+ ca_window_setup(ca, parent, start, count, bounds, fill);
101
+ return ca;
102
+ }
103
+
104
+ static void
105
+ free_ca_window (void *ap)
106
+ {
107
+ CAWindow *ca = (CAWindow *) ap;
108
+ if ( ca != NULL ) {
109
+ ca_free(ca->mask);
110
+ xfree(ca->fill);
111
+ xfree(ca->start);
112
+ xfree(ca->count);
113
+ xfree(ca->size0);
114
+ /* xfree(ca->dim); */
115
+ xfree(ca);
116
+ }
117
+ }
118
+
119
+ static void ca_window_attach (CAWindow *ca);
120
+ static void ca_window_sync (CAWindow *ca);
121
+ static void ca_window_fill (CAWindow *ca, char *ptr);
122
+
123
+ /* ------------------------------------------------------------------- */
124
+
125
+ static void *
126
+ ca_window_func_clone (void *ap)
127
+ {
128
+ CAWindow *ca = (CAWindow *) ap;
129
+ return ca_window_new(ca->parent, ca->start, ca->count, ca->bounds, ca->fill);
130
+ }
131
+
132
+ static char *
133
+ ca_window_func_ptr_at_index (void *ap, int32_t *idx) ;
134
+
135
+ static char *
136
+ ca_window_func_ptr_at_addr (void *ap, int32_t addr)
137
+ {
138
+ CAWindow *ca = (CAWindow *) ap;
139
+ if ( ca->ptr ) {
140
+ return ca->ptr + ca->bytes * addr;
141
+ }
142
+ else {
143
+ int32_t idx[CA_RANK_MAX];
144
+ ca_addr2index((CArray *)ca, addr, idx);
145
+ return ca_window_func_ptr_at_index(ca, idx);
146
+ }
147
+ }
148
+
149
+ static char *
150
+ ca_window_func_ptr_at_index (void *ap, int32_t *idx)
151
+ {
152
+ int32_t k;
153
+ CAWindow *ca = (CAWindow *) ap;
154
+ if ( ! ca->ptr ) {
155
+ int32_t *start = ca->start;
156
+ int32_t *size0 = ca->size0;
157
+ int32_t n, i;
158
+ n = 0;
159
+ for (i=0; i<ca->rank; i++) {
160
+ k = start[i] + idx[i];
161
+ k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
162
+ if ( k < 0 || k >= size0[i] ) {
163
+ return ca->fill;
164
+ }
165
+ n = size0[i] * n + k;
166
+ }
167
+
168
+ if ( ! ca->parent->ptr ) {
169
+ return ca_ptr_at_addr(ca->parent, n);
170
+ }
171
+ else {
172
+ return ca->parent->ptr + ca->bytes * n;
173
+ }
174
+ }
175
+ else {
176
+ return ca_func[CA_OBJ_ARRAY].ptr_at_index(ca, idx);
177
+ }
178
+ }
179
+
180
+ static void
181
+ ca_window_func_fetch_index (void *ap, int32_t *idx, void *ptr)
182
+ {
183
+ CAWindow *ca = (CAWindow *) ap;
184
+ int32_t *start = ca->start;
185
+ int32_t *size0 = ca->size0;
186
+ int32_t idx0[CA_RANK_MAX];
187
+ int32_t i, k;
188
+ for (i=0; i<ca->rank; i++) {
189
+ k = start[i] + idx[i];
190
+ k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
191
+ if ( k < 0 || k >= size0[i] ) {
192
+ memcpy(ptr, ca->fill, ca->bytes);
193
+ return;
194
+ }
195
+ idx0[i] = k;
196
+ }
197
+ ca_fetch_index(ca->parent, idx0, ptr);
198
+ }
199
+
200
+ static void
201
+ ca_window_func_store_index (void *ap, int32_t *idx, void *ptr)
202
+ {
203
+ CAWindow *ca = (CAWindow *) ap;
204
+ int32_t *start = ca->start;
205
+ int32_t *size0 = ca->size0;
206
+ int32_t idx0[CA_RANK_MAX];
207
+ int32_t i, k;
208
+ for (i=0; i<ca->rank; i++) {
209
+ k = start[i] + idx[i];
210
+ k = ca_bounds_normalize_index(ca->bounds, size0[i], k);
211
+ if ( k < 0 || k >= size0[i] ) {
212
+ return;
213
+ }
214
+ idx0[i] = k;
215
+ }
216
+ ca_store_index(ca->parent, idx0, ptr);
217
+ }
218
+
219
+ static void
220
+ ca_window_func_allocate (void *ap)
221
+ {
222
+ CAWindow *ca = (CAWindow *) ap;
223
+ ca_attach(ca->parent);
224
+ /* ca->ptr = ALLOC_N(char, ca_length(ca)); */
225
+ ca->ptr = malloc_with_check(ca_length(ca));
226
+ }
227
+
228
+ static void
229
+ ca_window_func_attach (void *ap)
230
+ {
231
+ void ca_window_attach (CAWindow *cb);
232
+
233
+ CAWindow *ca = (CAWindow *) ap;
234
+ ca_attach(ca->parent);
235
+ /* ca->ptr = ALLOC_N(char, ca_length(ca)); */
236
+ ca->ptr = malloc_with_check(ca_length(ca));
237
+ ca_window_attach(ca);
238
+ }
239
+
240
+ static void
241
+ ca_window_func_sync (void *ap)
242
+ {
243
+ CAWindow *ca = (CAWindow *) ap;
244
+ ca_window_sync(ca);
245
+ ca_sync(ca->parent);
246
+ }
247
+
248
+ static void
249
+ ca_window_func_detach (void *ap)
250
+ {
251
+ CAWindow *ca = (CAWindow *) ap;
252
+ free(ca->ptr);
253
+ ca->ptr = NULL;
254
+ ca_detach(ca->parent);
255
+ }
256
+
257
+ static void
258
+ ca_window_func_copy_data (void *ap, void *ptr)
259
+ {
260
+ CAWindow *ca = (CAWindow *) ap;
261
+ char *ptr0 = ca->ptr;
262
+ ca_attach(ca->parent);
263
+ ca->ptr = ptr;
264
+ ca_window_attach(ca);
265
+ ca->ptr = ptr0;
266
+ ca_detach(ca->parent);
267
+ }
268
+
269
+ static void
270
+ ca_window_func_sync_data (void *ap, void *ptr)
271
+ {
272
+ CAWindow *ca = (CAWindow *) ap;
273
+ char *ptr0 = ca->ptr;
274
+ ca_attach(ca->parent);
275
+ ca->ptr = ptr;
276
+ ca_window_sync(ca);
277
+ ca->ptr = ptr0;
278
+ ca_sync(ca->parent);
279
+ ca_detach(ca->parent);
280
+ }
281
+
282
+ static void
283
+ ca_window_func_fill_data (void *ap, void *ptr)
284
+ {
285
+ CAWindow *ca = (CAWindow *) ap;
286
+ ca_attach(ca->parent);
287
+ ca_window_fill(ca, ptr);
288
+ ca_sync(ca->parent);
289
+ ca_detach(ca->parent);
290
+ }
291
+
292
+ static void
293
+ ca_window_func_create_mask (void *ap)
294
+ {
295
+ CAWindow *ca = (CAWindow *) ap;
296
+ boolean8_t fill;
297
+ int32_t bounds = ca->bounds;
298
+
299
+ ca_update_mask(ca->parent);
300
+ if ( ! ca->parent->mask ) {
301
+ ca_create_mask(ca->parent);
302
+ }
303
+
304
+ if ( bounds == CA_BOUNDS_MASK ) {
305
+ bounds = CA_BOUNDS_FILL;
306
+ fill = 1;
307
+ }
308
+ else {
309
+ fill = 0;
310
+ }
311
+
312
+ ca->mask = (CArray *) ca_window_new(ca->parent->mask,
313
+ ca->start, ca->count, bounds, (char*)&fill);
314
+ }
315
+
316
+ ca_operation_function_t ca_window_func = {
317
+ -1, /* CA_OBJ_WINDOW */
318
+ CA_VIRTUAL_ARRAY,
319
+ free_ca_window,
320
+ ca_window_func_clone,
321
+ ca_window_func_ptr_at_addr,
322
+ ca_window_func_ptr_at_index,
323
+ NULL,
324
+ ca_window_func_fetch_index,
325
+ NULL,
326
+ ca_window_func_store_index,
327
+ ca_window_func_allocate,
328
+ ca_window_func_attach,
329
+ ca_window_func_sync,
330
+ ca_window_func_detach,
331
+ ca_window_func_copy_data,
332
+ ca_window_func_sync_data,
333
+ ca_window_func_fill_data,
334
+ ca_window_func_create_mask,
335
+ };
336
+
337
+ /* ------------------------------------------------------------------- */
338
+
339
+ #define proc_window_attach_get(type) \
340
+ if ( fill ) { \
341
+ type *p, *v; \
342
+ idx[level] = 0; \
343
+ p = ca_ptr_at_index((CArray*)cb, idx); \
344
+ v = (type*)cb->fill; \
345
+ for (i=0; i<count; i++, p++) { \
346
+ *p = *v; \
347
+ } \
348
+ } \
349
+ else { \
350
+ CArray *parent = cb->parent; \
351
+ int32_t start = cb->start[level]; \
352
+ int32_t size0 = cb->size0[level]; \
353
+ type *p, *q, *v; \
354
+ idx[level] = 0; \
355
+ p = (type*)ca_ptr_at_index((CArray*)cb, idx); \
356
+ v = (type*)cb->fill; \
357
+ i = 0; \
358
+ while ( start+i<0 && i<count ) { \
359
+ k = start + i; \
360
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
361
+ if ( k < 0 || k >= size0 ) { \
362
+ *p = *v; \
363
+ } \
364
+ else { \
365
+ idx0[level] = k; \
366
+ *p = *(type*) ca_ptr_at_index(parent, idx0); \
367
+ } \
368
+ i++; p++; \
369
+ } \
370
+ idx0[level] = start+i; \
371
+ q = (type*)ca_ptr_at_index(parent, idx0);\
372
+ while ( start+i<size0 && i < count ) { \
373
+ *p = *q; \
374
+ i++, p++, q++; \
375
+ } \
376
+ while ( i < count ) { \
377
+ k = start + i; \
378
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
379
+ if ( k < 0 || k >= size0 ) { \
380
+ *p = *v; \
381
+ } \
382
+ else { \
383
+ idx0[level] = k; \
384
+ *p = *(type*) ca_ptr_at_index(parent, idx0); \
385
+ } \
386
+ i++, p++; \
387
+ } \
388
+ }
389
+
390
+ static void
391
+ ca_window_attach_loop (CAWindow *cb, int8_t level,
392
+ int32_t *idx, int32_t *idx0, int fill)
393
+ {
394
+ int32_t count = cb->count[level];
395
+ int32_t i, k;
396
+
397
+ if ( level == cb->rank - 1 ) {
398
+ switch ( cb->data_type ) {
399
+ case CA_BOOLEAN:
400
+ case CA_INT8: proc_window_attach_get(int8_t); break;
401
+ case CA_UINT8: proc_window_attach_get(uint8_t); break;
402
+ case CA_INT16: proc_window_attach_get(int16_t); break;
403
+ case CA_UINT16: proc_window_attach_get(uint16_t); break;
404
+ case CA_INT32: proc_window_attach_get(int32_t); break;
405
+ case CA_UINT32: proc_window_attach_get(uint32_t); break;
406
+ case CA_INT64: proc_window_attach_get(int64_t); break;
407
+ case CA_UINT64: proc_window_attach_get(uint64_t); break;
408
+ case CA_FLOAT32: proc_window_attach_get(float32_t); break;
409
+ case CA_FLOAT64: proc_window_attach_get(float64_t); break;
410
+ case CA_FLOAT128: proc_window_attach_get(float128_t); break;
411
+ #ifdef HAVE_COMPLEX_H
412
+ case CA_CMPLX64: proc_window_attach_get(cmplx64_t); break;
413
+ case CA_CMPLX128: proc_window_attach_get(cmplx128_t); break;
414
+ case CA_CMPLX256: proc_window_attach_get(cmplx256_t); break;
415
+ #endif
416
+ default:
417
+ if ( fill ) {
418
+ for (i=0; i<count; i++) {
419
+ idx[level] = i;
420
+ memcpy(ca_ptr_at_index((CArray*)cb, idx), cb->fill, cb->bytes);
421
+ }
422
+ }
423
+ else {
424
+ int32_t start = cb->start[level];
425
+ int32_t size0 = cb->size0[level];
426
+ for (i=0; i<count; i++) {
427
+ idx[level] = i;
428
+ k = start + i;
429
+ if ( k < 0 || k >= size0 ) {
430
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
431
+ if ( k < 0 || k >= size0 ) {
432
+ memcpy(ca_ptr_at_index((CArray*)cb, idx), cb->fill, cb->bytes);
433
+ continue;
434
+ }
435
+ }
436
+ idx0[level] = k;
437
+ memcpy(ca_ptr_at_index((CArray*)cb, idx), ca_ptr_at_index(cb->parent, idx0), cb->bytes);
438
+ }
439
+ }
440
+ }
441
+ }
442
+ else {
443
+ if ( fill ) {
444
+ for (i=0; i<count; i++) {
445
+ idx[level] = i;
446
+ ca_window_attach_loop(cb, level+1, idx, idx0, 1);
447
+ }
448
+ }
449
+ else {
450
+ int32_t start = cb->start[level];
451
+ int32_t size0 = cb->size0[level];
452
+ for (i=0; i<count; i++) {
453
+ idx[level] = i;
454
+ k = start + i;
455
+ if ( k < 0 || k >= size0 ) {
456
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
457
+ if ( k < 0 || k >= size0 ) {
458
+ ca_window_attach_loop(cb, level+1, idx, idx0, 1); /* fill */
459
+ continue;
460
+ }
461
+ }
462
+ idx0[level] = k;
463
+ ca_window_attach_loop(cb, level+1, idx, idx0, 0); /* not-fill */
464
+ }
465
+ }
466
+ }
467
+ }
468
+
469
+ void
470
+ ca_window_attach (CAWindow *cb)
471
+ {
472
+ int32_t idx[CA_RANK_MAX];
473
+ int32_t idx0[CA_RANK_MAX];
474
+ ca_window_attach_loop(cb, (int8_t) 0, idx, idx0, 0);
475
+ }
476
+
477
+ #define proc_window_sync_set(type) \
478
+ { \
479
+ CArray *parent = cb->parent; \
480
+ type *p, *q; \
481
+ idx[level] = 0; \
482
+ p = (type*)ca_ptr_at_index((CArray*)cb, idx); \
483
+ i = 0; \
484
+ while ( start+i<0 && i<count ) { \
485
+ k = start + i; \
486
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
487
+ if ( k < 0 || k >= size0 ) { \
488
+ ; \
489
+ } \
490
+ else { \
491
+ idx0[level] = k; \
492
+ *(type *)ca_ptr_at_index(parent, idx0) = *p; \
493
+ } \
494
+ i++; p++; \
495
+ }\
496
+ idx0[level] = start + i; \
497
+ q = (type*)ca_ptr_at_index(parent, idx0);\
498
+ while ( start+i < size0 && i<count ) { \
499
+ *q = *p; \
500
+ i++; p++; q++; \
501
+ } \
502
+ while ( i<count ) { \
503
+ k = start + i; \
504
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
505
+ if ( k < 0 || k >= size0 ) { \
506
+ ; \
507
+ } \
508
+ else { \
509
+ idx0[level] = k; \
510
+ *(type*)ca_ptr_at_index(parent, idx0) = *p; \
511
+ } \
512
+ i++; p++; \
513
+ } \
514
+ }
515
+
516
+ static void
517
+ ca_window_sync_loop (CAWindow *cb, int8_t level,
518
+ int32_t *idx, int32_t *idx0)
519
+ {
520
+ int32_t count = cb->count[level];
521
+ int32_t start = cb->start[level];
522
+ int32_t size0 = cb->size0[level];
523
+ int32_t i, k;
524
+
525
+ if ( level == cb->rank - 1 ) {
526
+ switch ( cb->data_type ) {
527
+ case CA_BOOLEAN:
528
+ case CA_INT8: proc_window_sync_set(int8_t); break;
529
+ case CA_UINT8: proc_window_sync_set(uint8_t); break;
530
+ case CA_INT16: proc_window_sync_set(int16_t); break;
531
+ case CA_UINT16: proc_window_sync_set(uint16_t); break;
532
+ case CA_INT32: proc_window_sync_set(int32_t); break;
533
+ case CA_UINT32: proc_window_sync_set(uint32_t); break;
534
+ case CA_INT64: proc_window_sync_set(int64_t); break;
535
+ case CA_UINT64: proc_window_sync_set(uint64_t); break;
536
+ case CA_FLOAT32: proc_window_sync_set(float32_t); break;
537
+ case CA_FLOAT64: proc_window_sync_set(float64_t); break;
538
+ case CA_FLOAT128: proc_window_sync_set(float128_t); break;
539
+ #ifdef HAVE_COMPLEX_H
540
+ case CA_CMPLX64: proc_window_sync_set(cmplx64_t); break;
541
+ case CA_CMPLX128: proc_window_sync_set(cmplx128_t); break;
542
+ case CA_CMPLX256: proc_window_sync_set(cmplx256_t); break;
543
+ #endif
544
+ default:
545
+ for (i=0; i<count; i++) {
546
+ idx[level] = i;
547
+ k = start + i;
548
+ if ( k < 0 || k >= size0 ) {
549
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
550
+ if ( k < 0 || k >= size0 ) {
551
+ continue;
552
+ }
553
+ }
554
+ idx0[level] = k;
555
+ memcpy(ca_ptr_at_index(cb->parent, idx0), ca_ptr_at_index((CArray*)cb, idx), cb->bytes);
556
+ }
557
+ }
558
+ }
559
+ else {
560
+ for (i=0; i<count; i++) {
561
+ idx[level] = i;
562
+ k = start + i;
563
+ if ( k < 0 || k >= size0 ) {
564
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
565
+ if ( k < 0 || k >= size0 ) {
566
+ continue;
567
+ }
568
+ }
569
+ idx0[level] = k;
570
+ ca_window_sync_loop(cb, level+1, idx, idx0);
571
+ }
572
+ }
573
+ }
574
+
575
+ void
576
+ ca_window_sync (CAWindow *cb)
577
+ {
578
+ int32_t idx[CA_RANK_MAX];
579
+ int32_t idx0[CA_RANK_MAX];
580
+ ca_window_sync_loop(cb, (int8_t) 0, idx, idx0);
581
+ }
582
+
583
+ #define proc_window_fill_set(type) \
584
+ { \
585
+ CArray *parent = cb->parent; \
586
+ type *q; \
587
+ i = 0; \
588
+ while ( start+i<0 && i<count ) { \
589
+ k = start + i; \
590
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
591
+ if ( k < 0 || k >= size0 ) { \
592
+ ; \
593
+ } \
594
+ else { \
595
+ idx0[level] = k; \
596
+ *(type *)ca_ptr_at_index(parent, idx0) = *ptr; \
597
+ } \
598
+ i++; \
599
+ }\
600
+ idx0[level] = start + i; \
601
+ q = (type*)ca_ptr_at_index(parent, idx0);\
602
+ while ( start+i < size0 && i<count ) { \
603
+ *q = *ptr; \
604
+ i++; q++; \
605
+ } \
606
+ while ( i<count ) { \
607
+ k = start + i; \
608
+ k = ca_bounds_normalize_index(cb->bounds, size0, k); \
609
+ if ( k < 0 || k >= size0 ) { \
610
+ ; \
611
+ } \
612
+ else { \
613
+ idx0[level] = k; \
614
+ *(type*)ca_ptr_at_index(parent, idx0) = *ptr; \
615
+ } \
616
+ i++; \
617
+ } \
618
+ }
619
+
620
+ static void
621
+ ca_window_fill_loop (CAWindow *cb, char *ptr,
622
+ int8_t level, int32_t *idx0)
623
+ {
624
+ int32_t count = cb->count[level];
625
+ int32_t start = cb->start[level];
626
+ int32_t size0 = cb->size0[level];
627
+ int32_t i, k;
628
+
629
+ if ( level == cb->rank - 1 ) {
630
+ switch ( cb->data_type ) {
631
+ case CA_BOOLEAN:
632
+ case CA_INT8: proc_window_fill_set(int8_t); break;
633
+ case CA_UINT8: proc_window_fill_set(uint8_t); break;
634
+ case CA_INT16: proc_window_fill_set(int16_t); break;
635
+ case CA_UINT16: proc_window_fill_set(uint16_t); break;
636
+ case CA_INT32: proc_window_fill_set(int32_t); break;
637
+ case CA_UINT32: proc_window_fill_set(uint32_t); break;
638
+ case CA_INT64: proc_window_fill_set(int64_t); break;
639
+ case CA_UINT64: proc_window_fill_set(uint64_t); break;
640
+ case CA_FLOAT32: proc_window_fill_set(float32_t); break;
641
+ case CA_FLOAT64: proc_window_fill_set(float64_t); break;
642
+ case CA_FLOAT128: proc_window_fill_set(float128_t); break;
643
+ #ifdef HAVE_COMPLEX_H
644
+ case CA_CMPLX64: proc_window_fill_set(cmplx64_t); break;
645
+ case CA_CMPLX128: proc_window_fill_set(cmplx128_t); break;
646
+ case CA_CMPLX256: proc_window_fill_set(cmplx256_t); break;
647
+ #endif
648
+ default:
649
+ for (i=0; i<count; i++) {
650
+ k = start + i;
651
+ if ( k < 0 || k >= size0 ) {
652
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
653
+ if ( k < 0 || k >= size0 ) {
654
+ continue;
655
+ }
656
+ }
657
+ idx0[level] = k;
658
+ memcpy(ca_ptr_at_index(cb->parent, idx0), ptr, cb->bytes);
659
+ }
660
+ }
661
+ }
662
+ else {
663
+ for (i=0; i<count; i++) {
664
+ k = start + i;
665
+ if ( k < 0 || k >= size0 ) {
666
+ k = ca_bounds_normalize_index(cb->bounds, size0, k);
667
+ if ( k < 0 || k >= size0 ) {
668
+ continue;
669
+ }
670
+ }
671
+ idx0[level] = k;
672
+ ca_window_fill_loop(cb, ptr, level+1, idx0);
673
+ }
674
+ }
675
+
676
+ }
677
+
678
+ void
679
+ ca_window_fill (CAWindow *cb, char *ptr)
680
+ {
681
+ int32_t idx0[CA_RANK_MAX];
682
+ ca_window_fill_loop(cb, ptr, (int8_t) 0, idx0);
683
+ }
684
+
685
+ /* ------------------------------------------------------------------- */
686
+
687
+ VALUE
688
+ rb_ca_window_new (VALUE cary,
689
+ int32_t *start, int32_t *count, int8_t bounds, char *fill)
690
+ {
691
+ volatile VALUE obj;
692
+ CArray *parent;
693
+ CAWindow *ca;
694
+ rb_check_carray_object(cary);
695
+ Data_Get_Struct(cary, CArray, parent);
696
+ ca = ca_window_new(parent, start, count, bounds, fill);
697
+ obj = ca_wrap_struct(ca);
698
+ rb_ca_set_parent(obj, cary);
699
+ rb_ca_data_type_inherit(obj, cary);
700
+ return obj;
701
+ }
702
+
703
+ /* rdoc:
704
+ class CArray
705
+ def window (*argv)
706
+ end
707
+ end
708
+ */
709
+
710
+ VALUE
711
+ rb_ca_window (int argc, VALUE *argv, VALUE self)
712
+ {
713
+ volatile VALUE obj, ropt, rfval = CA_NIL, rbounds = Qnil, rcs;
714
+ CArray *ca;
715
+ CScalar *cs;
716
+ int32_t start[CA_RANK_MAX];
717
+ int32_t count[CA_RANK_MAX];
718
+ int32_t bounds = CA_BOUNDS_FILL;
719
+ char *fill = NULL;
720
+ char *cbounds;
721
+ int32_t i;
722
+
723
+ Data_Get_Struct(self, CArray, ca);
724
+
725
+ ropt = rb_pop_options(&argc, &argv);
726
+ rb_scan_options(ropt, "bounds,fill_value", &rbounds, &rfval);
727
+
728
+ if ( argc != ca->rank ) {
729
+ rb_raise(rb_eArgError, "rank mismatch");
730
+ }
731
+
732
+ for (i=0; i<argc; i++) {
733
+ int offset, len, step;
734
+ volatile VALUE arg = argv[i];
735
+ ca_parse_range_without_check(arg, ca->dim[i], &offset, &len, &step);
736
+ if ( step != 1 || len < 0 ) {
737
+ rb_raise(rb_eArgError,
738
+ "first index should smaller than last index. "
739
+ "The index range notation such as 0..-1 can't be used in CArray#window");
740
+ }
741
+ start[i] = offset;
742
+ count[i] = len;
743
+ }
744
+
745
+ if ( rfval == CA_NIL ) {
746
+ if ( rb_block_given_p() ) {
747
+ rfval = rb_yield(self);
748
+ }
749
+ }
750
+ else {
751
+ /* rb_warn(":fill_value option for CArray#window will be obsoleted."); */
752
+ }
753
+
754
+ if ( rfval == CA_NIL ) {
755
+ ;
756
+ }
757
+ else if ( rfval == CA_UNDEF ) {
758
+ bounds = CA_BOUNDS_MASK;
759
+ }
760
+ else {
761
+ rcs = rb_cscalar_new_with_value(ca->data_type, ca->bytes, rfval);
762
+ Data_Get_Struct(rcs, CScalar, cs);
763
+ fill = cs->ptr;
764
+ }
765
+
766
+ if ( ! NIL_P(rbounds) ) {
767
+ switch ( TYPE(rbounds) ) {
768
+ case T_STRING:
769
+ cbounds = StringValuePtr(rbounds);
770
+ if ( rfval == CA_UNDEF && strncmp(cbounds, "fill", 4)
771
+ && strncmp(cbounds, "mask", 4) ) {
772
+ rb_raise(rb_eRuntimeError, "conflicted bounds and fill_value");
773
+ }
774
+ if ( ! strncmp(cbounds, "ruby", 4) ) {
775
+ bounds = CA_BOUNDS_RUBY;
776
+ }
777
+ else if ( ! strncmp(cbounds, "strict", 6) ) {
778
+ bounds = CA_BOUNDS_STRICT;
779
+ }
780
+ else if ( ! strncmp(cbounds, "nearest", 7) ) {
781
+ bounds = CA_BOUNDS_NEAREST;
782
+ }
783
+ else if ( ! strncmp(cbounds, "periodic", 8) ) {
784
+ bounds = CA_BOUNDS_PERIODIC;
785
+ }
786
+ else if ( ! strncmp(cbounds, "reflect", 7) ) {
787
+ bounds = CA_BOUNDS_REFLECT;
788
+ }
789
+ else if ( ! strncmp(cbounds, "mask", 4) ) {
790
+ rb_warn("CAWindow option :bounds=>\"mask\" will be obsolete");
791
+ rb_warn("use ca.window(...) { UNDEF }");
792
+ bounds = CA_BOUNDS_MASK;
793
+ }
794
+ else if ( ! strncmp(cbounds, "fill", 4) ) {
795
+ bounds = CA_BOUNDS_FILL;
796
+ }
797
+ else {
798
+ rb_raise(rb_eRuntimeError,
799
+ "unknown option value '%s' for :bounds", cbounds);
800
+ }
801
+ break;
802
+ case T_FIXNUM:
803
+ bounds = NUM2INT(rbounds);
804
+ break;
805
+ default:
806
+ rb_raise(rb_eRuntimeError, "invalid option value for :bounds");
807
+ }
808
+ }
809
+
810
+ obj = rb_ca_window_new(self, start, count, bounds, fill);
811
+
812
+ return obj;
813
+ }
814
+
815
+ /* ------------------------------------------------------------------- */
816
+
817
+ static VALUE
818
+ rb_ca_window_s_allocate (VALUE klass)
819
+ {
820
+ CAWindow *ca;
821
+ return Data_Make_Struct(klass, CAWindow, ca_mark, ca_free, ca);
822
+ }
823
+
824
+ static VALUE
825
+ rb_ca_window_initialize_copy (VALUE self, VALUE other)
826
+ {
827
+ CAWindow *ca, *cs;
828
+
829
+ Data_Get_Struct(self, CAWindow, ca);
830
+ Data_Get_Struct(other, CAWindow, cs);
831
+
832
+ ca_window_setup(ca, cs->parent, cs->start, cs->count, cs->bounds, cs->fill);
833
+
834
+ return self;
835
+ }
836
+
837
+ /* rdoc:
838
+ class CAWindow
839
+ def index2addr0 (idx)
840
+ end
841
+ end
842
+ */
843
+
844
+ static VALUE
845
+ rb_ca_window_idx2addr0 (int argc, VALUE *argv, VALUE self)
846
+ {
847
+ CAWindow *cw;
848
+ int32_t addr;
849
+ int32_t i, idxi;
850
+
851
+ Data_Get_Struct(self, CAWindow, cw);
852
+
853
+ if ( argc != cw->rank ) {
854
+ rb_raise(rb_eArgError,
855
+ "invalid # of arguments (should be <%i>)", cw->rank);
856
+ }
857
+
858
+ addr = 0;
859
+ for (i=0; i<cw->rank; i++) {
860
+ idxi = NUM2INT(argv[i]);
861
+ CA_CHECK_INDEX(idxi, cw->dim[i]);
862
+ addr = cw->size0[i] * addr + cw->start[i] + idxi;
863
+ }
864
+
865
+ if ( addr < 0 || addr >= cw->parent->elements ) {
866
+ return Qnil;
867
+ }
868
+ else {
869
+ return INT2NUM(addr);
870
+ }
871
+ }
872
+
873
+ /* rdoc:
874
+ class CAWindow
875
+ def addr2addr0 (addr)
876
+ end
877
+ end
878
+ */
879
+
880
+ static VALUE
881
+ rb_ca_window_addr2addr0 (VALUE self, VALUE raddr)
882
+ {
883
+ CAWindow *cw;
884
+ int32_t addr = NUM2INT(raddr);
885
+ int32_t idx[CA_RANK_MAX];
886
+ int32_t i;
887
+
888
+ Data_Get_Struct(self, CAWindow, cw);
889
+
890
+ ca_addr2index((CArray*)cw, addr, idx);
891
+
892
+ addr = 0;
893
+ for (i=0; i<cw->rank; i++) {
894
+ addr *= cw->size0[i];
895
+ addr += cw->start[i] + idx[i];
896
+ }
897
+
898
+ return INT2NUM(addr);
899
+ }
900
+
901
+
902
+ static VALUE
903
+ rb_ca_window_move (int argc, VALUE *argv, VALUE self)
904
+ {
905
+ CAWindow *cw;
906
+ int32_t start, i;
907
+
908
+ Data_Get_Struct(self, CAWindow, cw);
909
+
910
+ if ( argc != cw->rank ) {
911
+ rb_raise(rb_eArgError, "invalid # of arguments");
912
+ }
913
+
914
+ ca_update_mask(cw);
915
+ for (i=0; i<cw->rank; i++) {
916
+ start = NUM2LONG(argv[i]);
917
+ cw->start[i] = start;
918
+ if ( cw->mask ) {
919
+ ((CAWindow*)(cw->mask))->start[i] = start;
920
+ }
921
+ }
922
+
923
+ return self;
924
+ }
925
+
926
+ /* rdoc:
927
+ class CAWindow
928
+ def fill_value
929
+ end
930
+ def fill_value= (val)
931
+ end
932
+ end
933
+ */
934
+
935
+ static VALUE
936
+ rb_ca_window_set_fill_value (VALUE self, VALUE rfval)
937
+ {
938
+ CAWindow *cw;
939
+ Data_Get_Struct(self, CAWindow, cw);
940
+ rb_ca_obj2ptr(self, rfval, cw->fill);
941
+ return Qnil;
942
+ }
943
+
944
+ static VALUE
945
+ rb_ca_window_get_fill_value (VALUE self)
946
+ {
947
+ CAWindow *cw;
948
+ Data_Get_Struct(self, CAWindow, cw);
949
+ return rb_ca_ptr2obj(self, cw->fill);
950
+ }
951
+
952
+ static VALUE
953
+ rb_ca_window_get_bounds (VALUE self)
954
+ {
955
+ CAWindow *cw;
956
+ Data_Get_Struct(self, CAWindow, cw);
957
+ return INT2NUM(cw->bounds);
958
+ }
959
+
960
+ #define rb_cw_get_attr_ary(name) \
961
+ rb_cw_## name (VALUE self) \
962
+ { \
963
+ volatile VALUE ary; \
964
+ CAWindow *cw; \
965
+ int32_t i; \
966
+ Data_Get_Struct(self, CAWindow, cw); \
967
+ ary = rb_ary_new2(cw->rank); \
968
+ for (i=0; i<cw->rank; i++) { \
969
+ rb_ary_store(ary, i, LONG2NUM(cw->name[i])); \
970
+ } \
971
+ return ary; \
972
+ }
973
+
974
+ /* rdoc:
975
+ class CAWindow
976
+ def size0
977
+ end
978
+ def start
979
+ end
980
+ def step
981
+ end
982
+ def count
983
+ end
984
+ def offset
985
+ end
986
+ end
987
+ */
988
+
989
+ static VALUE rb_cw_get_attr_ary(start);
990
+ static VALUE rb_cw_get_attr_ary(count);
991
+ static VALUE rb_cw_get_attr_ary(size0);
992
+
993
+ void
994
+ Init_ca_obj_window ()
995
+ {
996
+
997
+ rb_cCAWindow = rb_define_class("CAWindow", rb_cCAVirtual);
998
+
999
+ CA_OBJ_WINDOW = ca_install_obj_type(rb_cCAWindow, ca_window_func);
1000
+ rb_define_const(rb_cObject, "CA_OBJ_WINDOW", INT2NUM(CA_OBJ_WINDOW));
1001
+
1002
+ rb_define_method(rb_cCArray, "window", rb_ca_window, -1);
1003
+
1004
+ rb_define_alloc_func(rb_cCAWindow, rb_ca_window_s_allocate);
1005
+ rb_define_method(rb_cCAWindow, "initialize_copy",
1006
+ rb_ca_window_initialize_copy, 1);
1007
+
1008
+ rb_define_method(rb_cCAWindow, "move", rb_ca_window_move, -1);
1009
+
1010
+ rb_define_method(rb_cCAWindow, "index2addr0", rb_ca_window_idx2addr0, -1);
1011
+ rb_define_method(rb_cCAWindow, "addr2addr0", rb_ca_window_addr2addr0, 1);
1012
+
1013
+ rb_define_method(rb_cCAWindow, "fill_value", rb_ca_window_get_fill_value, 0);
1014
+ rb_define_method(rb_cCAWindow, "fill_value=", rb_ca_window_set_fill_value, 1);
1015
+
1016
+ rb_define_method(rb_cCAWindow, "bounds", rb_ca_window_get_bounds, 0);
1017
+
1018
+ rb_define_method(rb_cCAWindow, "start", rb_cw_start, 0);
1019
+ rb_define_method(rb_cCAWindow, "count", rb_cw_count, 0);
1020
+ rb_define_method(rb_cCAWindow, "size0", rb_cw_size0, 0);
1021
+
1022
+ }
1023
+