carray 1.3.5 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSES +22 -0
  3. data/README.md +18 -21
  4. data/Rakefile +31 -0
  5. data/carray.gemspec +13 -26
  6. data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
  7. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
  8. data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
  9. data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
  10. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
  11. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
  12. data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
  13. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
  14. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
  15. data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
  16. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
  17. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
  18. data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
  19. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
  20. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
  21. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
  22. data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
  23. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
  24. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
  25. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
  26. data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
  27. data/{carray.h → ext/carray.h} +77 -51
  28. data/{carray_access.c → ext/carray_access.c} +133 -91
  29. data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
  30. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
  31. data/{carray_cast.c → ext/carray_cast.c} +6 -6
  32. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
  33. data/{carray_class.c → ext/carray_class.c} +0 -0
  34. data/{carray_conversion.c → ext/carray_conversion.c} +11 -13
  35. data/{carray_copy.c → ext/carray_copy.c} +19 -19
  36. data/{carray_core.c → ext/carray_core.c} +2 -2
  37. data/ext/carray_data_type.c +66 -0
  38. data/{carray_element.c → ext/carray_element.c} +9 -9
  39. data/{carray_generate.c → ext/carray_generate.c} +67 -1
  40. data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
  41. data/{carray_loop.c → ext/carray_loop.c} +24 -24
  42. data/{carray_mask.c → ext/carray_mask.c} +17 -6
  43. data/{carray_math.rb → ext/carray_math.rb} +25 -25
  44. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
  45. data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
  46. data/{carray_operator.c → ext/carray_operator.c} +32 -9
  47. data/{carray_order.c → ext/carray_order.c} +2 -153
  48. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
  49. data/{carray_stat.c → ext/carray_stat.c} +5 -5
  50. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
  51. data/{carray_test.c → ext/carray_test.c} +22 -21
  52. data/{carray_undef.c → ext/carray_undef.c} +0 -0
  53. data/{carray_utils.c → ext/carray_utils.c} +0 -0
  54. data/{extconf.rb → ext/extconf.rb} +0 -5
  55. data/{mkmath.rb → ext/mkmath.rb} +12 -2
  56. data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
  57. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
  58. data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
  59. data/{version.h → ext/version.h} +5 -5
  60. data/{version.rb → ext/version.rb} +0 -0
  61. data/lib/carray.rb +49 -7
  62. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
  63. data/lib/carray/autoload/autoload_base.rb +1 -5
  64. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  65. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  66. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  67. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  68. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  69. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  70. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  71. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  72. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  73. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  74. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  75. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  76. data/lib/carray/basic.rb +193 -0
  77. data/lib/carray/compose.rb +291 -0
  78. data/lib/carray/construct.rb +445 -0
  79. data/lib/carray/convert.rb +115 -0
  80. data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
  81. data/lib/carray/io/imagemagick.rb +1 -1
  82. data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
  83. data/lib/carray/mask.rb +91 -0
  84. data/lib/carray/{base/math.rb → math.rb} +17 -47
  85. data/lib/carray/math/histogram.rb +7 -7
  86. data/lib/carray/mkmf.rb +8 -0
  87. data/lib/carray/object/ca_obj_pack.rb +8 -8
  88. data/lib/carray/obsolete.rb +272 -0
  89. data/lib/carray/ordering.rb +157 -0
  90. data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
  91. data/lib/carray/string.rb +190 -0
  92. data/lib/carray/{base/struct.rb → struct.rb} +20 -20
  93. data/lib/carray/{io/table.rb → table.rb} +1 -9
  94. data/lib/carray/testing.rb +56 -0
  95. data/lib/carray/time.rb +78 -0
  96. data/lib/carray/transform.rb +100 -0
  97. data/misc/Methods.ja.md +182 -0
  98. data/{NOTE → misc/NOTE} +0 -0
  99. data/test/test_ALL.rb +0 -2
  100. data/test/test_order.rb +7 -7
  101. data/test/test_ref_store.rb +13 -13
  102. data/test/test_stat.rb +7 -15
  103. data/{devel → utils}/guess_shape.rb +0 -0
  104. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  105. metadata +100 -254
  106. data/COPYING +0 -56
  107. data/GPL +0 -340
  108. data/Gemfile +0 -8
  109. data/Gemfile.lock +0 -33
  110. data/LEGAL +0 -50
  111. data/TODO +0 -5
  112. data/carray_random.c +0 -531
  113. data/ext/calculus/carray_calculus.c +0 -931
  114. data/ext/calculus/carray_interp.c +0 -358
  115. data/ext/calculus/extconf.rb +0 -12
  116. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  117. data/ext/calculus/lib/math/calculus.rb +0 -119
  118. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  119. data/ext/fortio/extconf.rb +0 -3
  120. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  121. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  122. data/ext/fortio/lib/fortio.rb +0 -3
  123. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  124. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  125. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  126. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  127. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  128. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  129. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  130. data/ext/fortio/ruby_fortio.c +0 -182
  131. data/ext/fortio/test/test_H.rb +0 -5
  132. data/ext/fortio/test/test_T.rb +0 -7
  133. data/ext/fortio/test/test_fortran_format.rb +0 -86
  134. data/ext/fortio/test/test_namelist.rb +0 -25
  135. data/ext/fortio/test/test_namelist_write.rb +0 -10
  136. data/ext/fortio/test/test_sequential.rb +0 -13
  137. data/ext/fortio/test/test_sequential2.rb +0 -13
  138. data/ext/fortio/work/test.rb +0 -10
  139. data/ext/fortio/work/test_e.rb +0 -19
  140. data/ext/fortio/work/test_ep.rb +0 -10
  141. data/ext/fortio/work/test_parse.rb +0 -12
  142. data/ext/imagemap/carray_imagemap.c +0 -495
  143. data/ext/imagemap/doc/call_graph.dot +0 -28
  144. data/ext/imagemap/draw.c +0 -567
  145. data/ext/imagemap/extconf.rb +0 -13
  146. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
  147. data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
  148. data/ext/imagemap/lib/image_map.rb +0 -4
  149. data/ext/imagemap/test/swath_index.rb +0 -83
  150. data/ext/imagemap/test/swath_warp.rb +0 -99
  151. data/ext/imagemap/test/test.rb +0 -23
  152. data/ext/imagemap/test/test_image.rb +0 -42
  153. data/ext/imagemap/test/test_line.rb +0 -14
  154. data/ext/imagemap/test/test_rotate.rb +0 -17
  155. data/ext/imagemap/test/test_triangle.rb +0 -20
  156. data/ext/imagemap/test/test_warp.rb +0 -26
  157. data/ext/mathfunc/extconf.rb +0 -18
  158. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  159. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  160. data/ext/mathfunc/test/test_hypot.rb +0 -5
  161. data/ext/mathfunc/test/test_j0.rb +0 -22
  162. data/ext/mathfunc/test/test_jn.rb +0 -8
  163. data/ext/mathfunc/test/test_sph.rb +0 -9
  164. data/ext/narray/README +0 -22
  165. data/ext/narray/ca_wrap_narray.c +0 -500
  166. data/ext/narray/carray_narray.c +0 -21
  167. data/ext/narray/extconf.rb +0 -57
  168. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  169. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  170. data/ext/narray/lib/math/narray.rb +0 -17
  171. data/ext/narray/lib/math/narray_miss.rb +0 -45
  172. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  173. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  174. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  175. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  176. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  177. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  178. data/lib/carray/base/basic.rb +0 -1090
  179. data/lib/carray/base/obsolete.rb +0 -131
  180. data/lib/carray/graphics/gnuplot.rb +0 -2131
  181. data/lib/carray/graphics/zimg.rb +0 -296
  182. data/lib/carray/io/csv.rb +0 -572
  183. data/lib/carray/io/pg.rb +0 -101
  184. data/lib/carray/io/sqlite3.rb +0 -215
  185. data/lib/carray/math/interp.rb +0 -57
  186. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  187. data/mt19937ar.c +0 -182
  188. data/mt19937ar.h +0 -86
  189. data/rdoc_main.rb +0 -27
  190. data/rdoc_math.rb +0 -5
  191. data/rdoc_stat.rb +0 -31
  192. data/test/test_narray.rb +0 -64
  193. data/test/test_random.rb +0 -15
  194. data/utils/create_rdoc.sh +0 -9
  195. data/utils/make_tgz.sh +0 -3
data/TODO DELETED
@@ -1,5 +0,0 @@
1
- - CArray#section should treat mask (-> currently CArray#bin uses inherit_mask)
2
- - CArray#differentiate should treat mask
3
- * CArray#search should permit a CArray argument (use lfind ?)
4
- * append API ca_get_range(vrange, size, *first, *last)
5
- * ca_cast_self_or_other should treat NArray directly
@@ -1,531 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- carray_random.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
- This file is partially based on the codes in the following two files:
12
-
13
- * random.c in Ruby distribution ( ruby-1.8.6 )
14
- Copyright (C) 1993-2003 Yukihiro Matsumoto
15
-
16
- * na_random.c in Ruby/NArray distribution ( narray-0.5.9 )
17
- (C) Copyright 2003 by Masahiro TANAKA
18
-
19
- ---------------------------------------------------------------------------- */
20
-
21
- #include "carray.h"
22
- #include <math.h>
23
- #include "mt19937ar.h"
24
-
25
- static int first = 1;
26
-
27
- static VALUE
28
- rb_ca_s_srand(int argc, VALUE *argv, VALUE self)
29
- {
30
- volatile VALUE seeds;
31
- unsigned long *init_key;
32
- int key_length;
33
- int i;
34
-
35
- if ( argc == 0 ) {
36
- volatile VALUE limit = ULONG2NUM(0xffffffff), val;
37
- seeds = rb_ary_new2(4);
38
- for (i=0; i<4; i++) {
39
- val = rb_funcall(rb_mKernel, rb_intern("rand"), 1, limit);
40
- rb_ary_store(seeds, i, val);
41
- }
42
- }
43
- else {
44
- seeds = rb_ary_new4(argc, argv);
45
- }
46
-
47
- key_length = RARRAY_LEN(seeds);
48
- init_key = malloc_with_check(sizeof(unsigned long)*key_length);
49
-
50
- for (i=0; i<key_length; i++) {
51
- init_key[i] = NUM2ULONG(rb_ary_entry(seeds, i));
52
- }
53
-
54
- init_by_array(init_key, key_length);
55
-
56
- free(init_key);
57
-
58
- first = 0;
59
-
60
- return Qnil;
61
- }
62
-
63
- /* -------------------------------------------------------------------- */
64
-
65
- static int
66
- bit_width (uint32_t max)
67
- {
68
- static uint32_t bits[32] = {
69
- 1, 2, 4, 8, 16, 32, 64, 128, 256,
70
- 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
71
- 131072, 262144, 524288, 1048576, 2097152, 4194304,
72
- 8388608, 16777216, 33554432, 67108864, 134217728,
73
- 268435456, 536870912, 1073741824, 2147483648UL
74
- };
75
- int i;
76
- if ( max == 0 ) {
77
- return 0;
78
- }
79
- for (i=0; i<32; i++) {
80
- if ( max <= bits[i] ) {
81
- return i+1;
82
- }
83
- }
84
- return 32;
85
- }
86
-
87
- static void
88
- ca_monop_random_boolean8_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
89
- {
90
- boolean8_t *q1 = (boolean8_t *) ptr1, *p1;
91
- uint32_t val;
92
- ca_size_t k;
93
-
94
- if ( max > 1 ) {
95
- rb_raise(rb_eArgError, "given maximum number is out of range");
96
- }
97
-
98
- #ifdef _OPENMP
99
- #pragma omp parallel for private(p1)
100
- #endif
101
- for (k=0; k<n; k++) {
102
- p1 = q1 + k*i1;
103
- val = (uint32_t) genrand_int32();
104
- val >>= 31;
105
- *(int8_t*)p1 = (int8_t) val;
106
- }
107
- }
108
-
109
- static void
110
- ca_monop_random_int8_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
111
- {
112
- int8_t *q1 = (int8_t *) ptr1, *p1;
113
- uint32_t val;
114
- int shift;
115
- ca_size_t k;
116
-
117
- if ( max > 0x80 ) {
118
- rb_raise(rb_eArgError, "given maximum number is out of range");
119
- }
120
-
121
- shift = 32 - bit_width(max);
122
-
123
- #ifdef _OPENMP
124
- #pragma omp parallel for private(p1)
125
- #endif
126
- for (k=0; k<n; k++) {
127
- p1 = q1 + k*i1;
128
- do {
129
- val = (uint32_t) genrand_int32();
130
- val >>= shift;
131
- } while ( val >= max );
132
- *(int8_t*)p1 = (int8_t) val;
133
- }
134
- }
135
-
136
- static void
137
- ca_monop_random_uint8_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
138
- {
139
- uint8_t *q1 = (uint8_t *) ptr1, *p1;
140
- uint32_t val;
141
- int shift;
142
- ca_size_t k;
143
-
144
- if ( max > 0x100 ) {
145
- rb_raise(rb_eArgError, "given maximum number is out of range");
146
- }
147
-
148
- shift = 32 - bit_width(max);
149
-
150
- #ifdef _OPENMP
151
- #pragma omp parallel for private(p1)
152
- #endif
153
- for (k=0; k<n; k++) {
154
- p1 = q1 + k*i1;
155
- do {
156
- val = (uint32_t) genrand_int32();
157
- val >>= shift;
158
- } while ( val >= max );
159
- *(uint8_t*)p1 = (uint8_t) val;
160
- }
161
- }
162
-
163
- static void
164
- ca_monop_random_int16_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
165
- {
166
- int16_t *q1 = (int16_t *) ptr1, *p1;
167
- uint32_t val;
168
- int shift;
169
- ca_size_t k;
170
-
171
- if ( max > 0x8000 ) {
172
- rb_raise(rb_eArgError, "given maximum number is out of range");
173
- }
174
-
175
- shift = 32 - bit_width(max);
176
-
177
- #ifdef _OPENMP
178
- #pragma omp parallel for private(p1)
179
- #endif
180
- for (k=0; k<n; k++) {
181
- p1 = q1 + k*i1;
182
- do {
183
- val = (uint32_t) genrand_int32();
184
- val >>= shift;
185
- } while ( val >= max );
186
- *(int16_t*)p1 = (int16_t) val;
187
- }
188
- }
189
-
190
- static void
191
- ca_monop_random_uint16_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
192
- {
193
- uint16_t *q1 = (uint16_t *) ptr1, *p1;
194
- uint32_t val;
195
- int shift;
196
- ca_size_t k;
197
-
198
- if ( max > 0x10000 ) {
199
- rb_raise(rb_eArgError, "given maximum number is out of range");
200
- }
201
-
202
- shift = 32 - bit_width(max);
203
-
204
- #ifdef _OPENMP
205
- #pragma omp parallel for private(p1)
206
- #endif
207
- for (k=0; k<n; k++) {
208
- p1 = q1 + k*i1;
209
- do {
210
- val = (uint32_t) genrand_int32();
211
- val >>= shift;
212
- } while ( val >= max );
213
- *(uint16_t*)p1 = (uint16_t) val;
214
- }
215
- }
216
-
217
-
218
- static void
219
- ca_monop_random_int32_t (ca_size_t n, char *ptr1, int i1, uint32_t max)
220
- {
221
- int32_t *q1 = (int32_t *) ptr1, *p1;
222
- uint32_t val;
223
- int shift;
224
- ca_size_t k;
225
-
226
- if ( max > 0x80000000 ) {
227
- rb_raise(rb_eArgError, "given maximum number is out of range");
228
- }
229
-
230
- shift = 32 - bit_width(max);
231
-
232
- #ifdef _OPENMP
233
- #pragma omp parallel for private(p1)
234
- #endif
235
- for (k=0; k<n; k++) {
236
- p1 = q1 + k*i1;
237
- do {
238
- val = (uint32_t) genrand_int32();
239
- val >>= shift;
240
- } while ( val >= max );
241
- *(int32_t*)p1 = (int32_t) val;
242
- }
243
- }
244
-
245
- static void
246
- ca_monop_random_uint32_t (ca_size_t n, char *ptr1, int i1, double max)
247
- {
248
- uint32_t *q1 = (uint32_t *) ptr1, *p1;
249
- uint32_t val;
250
- int shift;
251
- ca_size_t k;
252
-
253
- if ( max > 4294967296.0 ) { /* 0x100000000 */
254
- rb_raise(rb_eArgError, "given maximum number is out of range");
255
- }
256
-
257
- if ( max > 4294967295.0 ) { /* 0xffffffff */
258
- shift = 0;
259
- }
260
- else {
261
- shift = 32 - bit_width((uint32_t) max);
262
- }
263
-
264
- #ifdef _OPENMP
265
- #pragma omp parallel for private(p1)
266
- #endif
267
- for (k=0; k<n; k++) {
268
- p1 = q1 + k*i1;
269
- do {
270
- val = (uint32_t) genrand_int32();
271
- val >>= shift;
272
- } while ( val >= max );
273
- *(uint32_t*)p1 = (uint32_t) val;
274
- }
275
- }
276
-
277
- static void
278
- ca_monop_random_float32_t(ca_size_t n, char *ptr1, int i1, double rmax)
279
- {
280
- float32_t *q1 = (float32_t *) ptr1, *p1;
281
- ca_size_t k;
282
- #ifdef _OPENMP
283
- #pragma omp parallel for private(p1)
284
- #endif
285
- for (k=0; k<n; k++) {
286
- p1 = q1 + k*i1;
287
- *(float32_t*)p1 = genrand_real2() * rmax;
288
- }
289
- }
290
-
291
- static void
292
- ca_monop_random_float64_t(ca_size_t n, char *ptr1, int i1, double rmax)
293
- {
294
- float64_t *q1 = (float64_t *) ptr1, *p1;
295
- ca_size_t k;
296
- #ifdef _OPENMP
297
- #pragma omp parallel for private(p1)
298
- #endif
299
- for (k=0; k<n; k++) {
300
- p1 = q1 + k*i1;
301
- *(float64_t*)p1 = genrand_res53() * rmax;
302
- }
303
- }
304
-
305
- #ifdef HAVE_COMPLEX_H
306
-
307
- static void
308
- ca_monop_random_cmplx64_t(ca_size_t n, char *ptr1, int i1, double rmax, double imax)
309
- {
310
- cmplx64_t *q1 = (cmplx64_t *) ptr1, *p1;
311
- ca_size_t k;
312
- #ifdef _OPENMP
313
- #pragma omp parallel for private(p1)
314
- #endif
315
- for (k=0; k<n; k++) {
316
- p1 = q1 + k*i1;
317
- *(cmplx64_t*)p1 = genrand_real2() * rmax + I * (genrand_real2() * rmax);
318
- }
319
- }
320
-
321
- static void
322
- ca_monop_random_cmplx128_t(ca_size_t n, char *ptr1, int i1, double rmax, double imax)
323
- {
324
- cmplx128_t *q1 = (cmplx128_t *) ptr1, *p1;
325
- ca_size_t k;
326
- #ifdef _OPENMP
327
- #pragma omp parallel for private(p1)
328
- #endif
329
- for (k=0; k<n; k++) {
330
- p1 = q1 + k*i1;
331
- *(cmplx128_t*)p1 = genrand_res53() * rmax + I * (genrand_res53() * rmax);
332
- }
333
- }
334
-
335
- #endif
336
-
337
- typedef void (*ca_random_func_t)();
338
-
339
- ca_random_func_t
340
- ca_monop_random[CA_NTYPE] = {
341
- ca_monop_not_implement,
342
- ca_monop_random_boolean8_t,
343
- ca_monop_random_int8_t,
344
- ca_monop_random_uint8_t,
345
- ca_monop_random_int16_t,
346
- ca_monop_random_uint16_t,
347
- ca_monop_random_int32_t,
348
- ca_monop_random_uint32_t,
349
- ca_monop_not_implement, /* ca_monop_random_int64_t, */
350
- ca_monop_not_implement, /* ca_monop_random_uint64_t, */
351
- ca_monop_random_float32_t,
352
- ca_monop_random_float64_t,
353
- ca_monop_not_implement, /* ca_monop_random_float128_t, */
354
- #ifdef HAVE_COMPLEX_H
355
- ca_monop_random_cmplx64_t,
356
- ca_monop_random_cmplx128_t,
357
- ca_monop_not_implement, /* ca_monop_random_cmplx256_t, */
358
- #else
359
- ca_monop_not_implement,
360
- ca_monop_not_implement,
361
- ca_monop_not_implement,
362
- #endif
363
- ca_monop_not_implement,
364
- };
365
-
366
- /* rdoc:
367
- class CArray
368
- def random! (max=1.0)
369
- end
370
- end
371
- */
372
-
373
- static VALUE
374
- rb_ca_random (int argc, VALUE *argv, VALUE self)
375
- {
376
- VALUE rrmax, rimax = Qnil;
377
- CArray *ca;
378
- double rmax, imax = 1;
379
-
380
- rb_ca_modify(self);
381
-
382
- Data_Get_Struct(self, CArray, ca);
383
-
384
- if ( ca_is_object_type(ca) ) {
385
- CArray *dmy;
386
- VALUE *p;
387
- ca_size_t i;
388
-
389
- rb_scan_args(argc, argv, "01", &rrmax);
390
- if ( NIL_P(rrmax) ) {
391
- rrmax = rb_float_new(1.0);
392
- }
393
-
394
- ca_clear_mask(ca);
395
-
396
- ca_attach(ca);
397
-
398
- if ( rb_obj_is_kind_of(rrmax, rb_cInteger) ) {
399
- int32_t *q;
400
- rmax = (double)NUM2INT(rrmax);
401
- dmy = carray_new(CA_INT32, ca->rank, ca->dim, ca->bytes, NULL);
402
- (*ca_monop_random[dmy->data_type])(dmy->elements,
403
- dmy->ptr, 1, (uint32_t)rmax);
404
- p = (VALUE *)ca->ptr;
405
- q = (int32_t *)dmy->ptr;
406
- for (i=0; i<ca->elements; i++) {
407
- *p = INT2NUM(*q);
408
- p++; q++;
409
- }
410
- }
411
- else if ( rb_obj_is_kind_of(rrmax, rb_cFloat) ) {
412
- float64_t *q;
413
- rmax = NUM2DBL(rrmax);
414
- dmy = carray_new(CA_FLOAT64, ca->rank, ca->dim, ca->bytes, NULL);
415
- (*ca_monop_random[dmy->data_type])(dmy->elements,
416
- dmy->ptr, 1, rmax);
417
- p = (VALUE *)ca->ptr;
418
- q = (float64_t *)dmy->ptr;
419
- for (i=0; i<ca->elements; i++) {
420
- *p = rb_float_new(*q);
421
- p++; q++;
422
- }
423
- }
424
- else {
425
- rb_raise(rb_eArgError,
426
- "maximum number should be an integer or a float number");
427
- }
428
-
429
- ca_sync(ca);
430
- ca_detach(ca);
431
-
432
- ca_free(dmy);
433
-
434
- return self;
435
- }
436
-
437
- rb_scan_args(argc, argv, "02", &rrmax, &rimax);
438
-
439
- if ( first ) {
440
- rb_ca_s_srand(0, NULL, rb_cCArray);
441
- }
442
-
443
- rmax = ( NIL_P(rrmax) ) ? 1.0 : NUM2DBL(rrmax);
444
- imax = ( NIL_P(rimax) ) ? rmax : NUM2DBL(rimax);
445
-
446
- if ( isinf(rmax) || isnan(rmax) || isinf(imax) || isnan(imax) ) {
447
- rb_raise(rb_eArgError,
448
- "maximum number should be finite");
449
- }
450
-
451
- if ( rmax < 0 || imax < 0 ) {
452
- rb_raise(rb_eArgError,
453
- "maximum number should be positive");
454
- }
455
-
456
- ca_clear_mask(ca);
457
- ca_attach(ca);
458
-
459
- switch ( ca->data_type ) {
460
- case CA_CMPLX64:
461
- case CA_CMPLX128:
462
- if ( rmax < 0 || imax < 0 ) {
463
- rb_raise(rb_eArgError,
464
- "maximum number should be positive");
465
- }
466
- (*ca_monop_random[ca->data_type])(ca->elements,
467
- ca->ptr, 1, rmax, imax);
468
- break;
469
- case CA_UINT32:
470
- case CA_FLOAT32:
471
- case CA_FLOAT64:
472
- if ( rmax < 0 ) {
473
- rb_raise(rb_eArgError,
474
- "maximum number should be positive");
475
- }
476
- (*ca_monop_random[ca->data_type])(ca->elements,
477
- ca->ptr, 1, rmax);
478
- break;
479
- default:
480
- if ( rmax < 1 ) {
481
- rb_raise(rb_eArgError,
482
- "maximum number should be positive");
483
- }
484
- (*ca_monop_random[ca->data_type])(ca->elements,
485
- ca->ptr, 1, (uint32_t)rmax);
486
- }
487
-
488
- ca_sync(ca);
489
- ca_detach(ca);
490
-
491
- return self;
492
- }
493
-
494
- void
495
- ca_check_rand_init ()
496
- {
497
- if ( first ) {
498
- rb_ca_s_srand(0, NULL, rb_cCArray);
499
- }
500
- }
501
-
502
- int32_t
503
- ca_rand (double rmax)
504
- {
505
- uint32_t val;
506
- int shift;
507
-
508
- ca_check_rand_init();
509
-
510
- if ( rmax < 0 || rmax > 0x7fffffff ) {
511
- rb_raise(rb_eArgError,
512
- "given maximum number is out of range");
513
- }
514
-
515
- shift = 32 - bit_width((uint32_t)rmax);
516
-
517
- do {
518
- val = (uint32_t) genrand_int32();
519
- val >>= shift;
520
- } while ( val >= (uint32_t) rmax );
521
-
522
- return (int32_t) val;
523
- }
524
-
525
- void
526
- Init_carray_random()
527
- {
528
- rb_define_singleton_method(rb_cCArray,"srand", rb_ca_s_srand,-1);
529
- rb_define_method(rb_cCArray, "random!", rb_ca_random, -1);
530
- }
531
-