carray 1.3.6 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/LICENSE +22 -0
  4. data/NEWS.md +65 -0
  5. data/README.md +23 -26
  6. data/Rakefile +31 -0
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +24 -31
  9. data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
  10. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
  11. data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
  12. data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
  13. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
  14. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
  15. data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
  16. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
  17. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
  18. data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
  19. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
  20. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
  21. data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
  22. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
  23. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +38 -40
  24. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
  25. data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
  26. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
  27. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
  28. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
  29. data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
  30. data/{carray.h → ext/carray.h} +90 -59
  31. data/{carray_access.c → ext/carray_access.c} +244 -109
  32. data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
  33. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
  34. data/{carray_cast.c → ext/carray_cast.c} +350 -149
  35. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
  36. data/{carray_class.c → ext/carray_class.c} +28 -36
  37. data/{carray_conversion.c → ext/carray_conversion.c} +58 -70
  38. data/{carray_copy.c → ext/carray_copy.c} +34 -50
  39. data/{carray_core.c → ext/carray_core.c} +75 -62
  40. data/ext/carray_data_type.c +66 -0
  41. data/{carray_element.c → ext/carray_element.c} +34 -53
  42. data/{carray_generate.c → ext/carray_generate.c} +137 -50
  43. data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
  44. data/{carray_loop.c → ext/carray_loop.c} +77 -106
  45. data/{carray_mask.c → ext/carray_mask.c} +95 -114
  46. data/{carray_math.rb → ext/carray_math.rb} +47 -31
  47. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
  48. data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
  49. data/{carray_operator.c → ext/carray_operator.c} +72 -36
  50. data/{carray_order.c → ext/carray_order.c} +73 -217
  51. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
  52. data/{carray_stat.c → ext/carray_stat.c} +6 -8
  53. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
  54. data/{carray_test.c → ext/carray_test.c} +59 -51
  55. data/{carray_undef.c → ext/carray_undef.c} +1 -11
  56. data/{carray_utils.c → ext/carray_utils.c} +12 -4
  57. data/{extconf.rb → ext/extconf.rb} +1 -6
  58. data/{mkmath.rb → ext/mkmath.rb} +13 -3
  59. data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
  60. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +1 -3
  61. data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
  62. data/ext/version.h +16 -0
  63. data/{version.rb → ext/version.rb} +0 -0
  64. data/lib/carray.rb +52 -10
  65. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -8
  66. data/lib/carray/autoload/autoload_base.rb +1 -5
  67. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  68. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  69. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  70. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  71. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  72. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  73. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  74. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  75. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  76. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  77. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  78. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  79. data/lib/carray/basic.rb +191 -0
  80. data/lib/carray/broadcast.rb +82 -0
  81. data/lib/carray/compose.rb +315 -0
  82. data/lib/carray/construct.rb +460 -0
  83. data/lib/carray/convert.rb +115 -0
  84. data/lib/carray/info.rb +1 -3
  85. data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
  86. data/lib/carray/io/imagemagick.rb +2 -4
  87. data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
  88. data/lib/carray/mask.rb +102 -0
  89. data/lib/carray/{base/math.rb → math.rb} +21 -53
  90. data/lib/carray/math/histogram.rb +8 -10
  91. data/lib/carray/math/recurrence.rb +1 -3
  92. data/lib/carray/mkmf.rb +9 -3
  93. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  94. data/lib/carray/object/ca_obj_link.rb +1 -3
  95. data/lib/carray/object/ca_obj_pack.rb +9 -11
  96. data/lib/carray/obsolete.rb +270 -0
  97. data/lib/carray/ordering.rb +181 -0
  98. data/lib/carray/{base/serialize.rb → serialize.rb} +50 -66
  99. data/lib/carray/string.rb +188 -0
  100. data/lib/carray/{base/struct.rb → struct.rb} +19 -21
  101. data/lib/carray/{io/table.rb → table.rb} +1 -9
  102. data/lib/carray/testing.rb +51 -0
  103. data/lib/carray/time.rb +76 -0
  104. data/lib/carray/transform.rb +98 -0
  105. data/misc/Methods.ja.md +182 -0
  106. data/{NOTE → misc/NOTE} +0 -0
  107. data/spec/Classes/CABitfield_spec.rb +58 -0
  108. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  109. data/spec/Classes/CABlock_spec.rb +205 -0
  110. data/spec/Classes/CAField_spec.rb +39 -0
  111. data/spec/Classes/CAGrid_spec.rb +75 -0
  112. data/spec/Classes/CAMap_spec.rb +0 -0
  113. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  114. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  115. data/spec/Classes/CAObject_spec.rb +33 -0
  116. data/spec/Classes/CARefer_spec.rb +93 -0
  117. data/spec/Classes/CARepeat_spec.rb +65 -0
  118. data/spec/Classes/CASelect_spec.rb +22 -0
  119. data/spec/Classes/CAShift_spec.rb +16 -0
  120. data/spec/Classes/CAStruct_spec.rb +71 -0
  121. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  122. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  123. data/spec/Classes/CAWindow_spec.rb +54 -0
  124. data/spec/Classes/CAWrap_spec.rb +8 -0
  125. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  126. data/spec/Classes/CScalar_spec.rb +55 -0
  127. data/spec/Features/feature_130_spec.rb +19 -0
  128. data/spec/Features/feature_attributes_spec.rb +280 -0
  129. data/spec/Features/feature_boolean_spec.rb +98 -0
  130. data/spec/Features/feature_broadcast.rb +116 -0
  131. data/spec/Features/feature_cast_function.rb +19 -0
  132. data/spec/Features/feature_cast_spec.rb +33 -0
  133. data/spec/Features/feature_class_spec.rb +84 -0
  134. data/spec/Features/feature_complex_spec.rb +42 -0
  135. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  136. data/spec/Features/feature_convert_spec.rb +46 -0
  137. data/spec/Features/feature_copy_spec.rb +123 -0
  138. data/spec/Features/feature_creation_spec.rb +84 -0
  139. data/spec/Features/feature_element_spec.rb +144 -0
  140. data/spec/Features/feature_extream_spec.rb +54 -0
  141. data/spec/Features/feature_generate_spec.rb +74 -0
  142. data/spec/Features/feature_index_spec.rb +69 -0
  143. data/spec/Features/feature_mask_spec.rb +580 -0
  144. data/spec/Features/feature_math_spec.rb +97 -0
  145. data/spec/Features/feature_order_spec.rb +146 -0
  146. data/spec/Features/feature_ref_store_spec.rb +209 -0
  147. data/spec/Features/feature_serialization_spec.rb +125 -0
  148. data/spec/Features/feature_stat_spec.rb +397 -0
  149. data/spec/Features/feature_virtual_spec.rb +48 -0
  150. data/spec/Features/method_eq_spec.rb +81 -0
  151. data/spec/Features/method_is_nan_spec.rb +12 -0
  152. data/spec/Features/method_map_spec.rb +54 -0
  153. data/spec/Features/method_max_with.rb +20 -0
  154. data/spec/Features/method_min_with.rb +19 -0
  155. data/spec/Features/method_ne_spec.rb +18 -0
  156. data/spec/Features/method_project_spec.rb +188 -0
  157. data/spec/Features/method_ref_spec.rb +27 -0
  158. data/spec/Features/method_round_spec.rb +11 -0
  159. data/spec/Features/method_s_linspace_spec.rb +48 -0
  160. data/spec/Features/method_s_span_spec.rb +14 -0
  161. data/spec/Features/method_seq_spec.rb +47 -0
  162. data/spec/Features/method_sort_with.rb +43 -0
  163. data/spec/Features/method_sorted_with.rb +29 -0
  164. data/spec/Features/method_span_spec.rb +42 -0
  165. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  166. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  167. data/spec/spec_all.rb +0 -1
  168. data/utils/convert_test.rb +73 -0
  169. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  170. data/{devel → utils}/guess_shape.rb +0 -0
  171. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  172. metadata +173 -316
  173. data/COPYING +0 -56
  174. data/GPL +0 -340
  175. data/Gemfile +0 -8
  176. data/Gemfile.lock +0 -33
  177. data/LEGAL +0 -50
  178. data/Makefile +0 -451
  179. data/TODO +0 -5
  180. data/carray_cast_func.c +0 -8670
  181. data/carray_config.h +0 -26
  182. data/carray_math.c +0 -24805
  183. data/carray_random.c +0 -531
  184. data/carray_stat_proc.c +0 -12170
  185. data/ext/calculus/carray_calculus.c +0 -931
  186. data/ext/calculus/carray_interp.c +0 -358
  187. data/ext/calculus/extconf.rb +0 -12
  188. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  189. data/ext/calculus/lib/math/calculus.rb +0 -119
  190. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  191. data/ext/fortio/extconf.rb +0 -3
  192. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  193. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  194. data/ext/fortio/lib/fortio.rb +0 -3
  195. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  196. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  197. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  198. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  199. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  200. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  201. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  202. data/ext/fortio/ruby_fortio.c +0 -182
  203. data/ext/fortio/test/test_H.rb +0 -5
  204. data/ext/fortio/test/test_T.rb +0 -7
  205. data/ext/fortio/test/test_fortran_format.rb +0 -86
  206. data/ext/fortio/test/test_namelist.rb +0 -25
  207. data/ext/fortio/test/test_namelist_write.rb +0 -10
  208. data/ext/fortio/test/test_sequential.rb +0 -13
  209. data/ext/fortio/test/test_sequential2.rb +0 -13
  210. data/ext/fortio/work/test.rb +0 -10
  211. data/ext/fortio/work/test_e.rb +0 -19
  212. data/ext/fortio/work/test_ep.rb +0 -10
  213. data/ext/fortio/work/test_parse.rb +0 -12
  214. data/ext/imagemap/carray_imagemap.c +0 -495
  215. data/ext/imagemap/doc/call_graph.dot +0 -28
  216. data/ext/imagemap/draw.c +0 -567
  217. data/ext/imagemap/extconf.rb +0 -13
  218. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
  219. data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
  220. data/ext/imagemap/lib/image_map.rb +0 -4
  221. data/ext/imagemap/test/swath_index.rb +0 -83
  222. data/ext/imagemap/test/swath_warp.rb +0 -99
  223. data/ext/imagemap/test/test.rb +0 -23
  224. data/ext/imagemap/test/test_image.rb +0 -42
  225. data/ext/imagemap/test/test_line.rb +0 -14
  226. data/ext/imagemap/test/test_rotate.rb +0 -17
  227. data/ext/imagemap/test/test_triangle.rb +0 -20
  228. data/ext/imagemap/test/test_warp.rb +0 -26
  229. data/ext/mathfunc/extconf.rb +0 -18
  230. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  231. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  232. data/ext/mathfunc/test/test_hypot.rb +0 -5
  233. data/ext/mathfunc/test/test_j0.rb +0 -22
  234. data/ext/mathfunc/test/test_jn.rb +0 -8
  235. data/ext/mathfunc/test/test_sph.rb +0 -9
  236. data/ext/narray/README +0 -22
  237. data/ext/narray/ca_wrap_narray.c +0 -500
  238. data/ext/narray/carray_narray.c +0 -21
  239. data/ext/narray/extconf.rb +0 -57
  240. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  241. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  242. data/ext/narray/lib/math/narray.rb +0 -17
  243. data/ext/narray/lib/math/narray_miss.rb +0 -45
  244. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  245. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  246. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  247. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  248. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  249. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  250. data/lib/carray/base/basic.rb +0 -1090
  251. data/lib/carray/base/obsolete.rb +0 -131
  252. data/lib/carray/graphics/gnuplot.rb +0 -2131
  253. data/lib/carray/graphics/zimg.rb +0 -296
  254. data/lib/carray/io/csv.rb +0 -572
  255. data/lib/carray/io/pg.rb +0 -101
  256. data/lib/carray/io/sqlite3.rb +0 -215
  257. data/lib/carray/math/interp.rb +0 -57
  258. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  259. data/mkmf.log +0 -375
  260. data/mt19937ar.c +0 -182
  261. data/mt19937ar.h +0 -86
  262. data/rdoc_ext.rb +0 -1115
  263. data/rdoc_main.rb +0 -27
  264. data/rdoc_math.rb +0 -5
  265. data/rdoc_stat.rb +0 -31
  266. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  267. data/spec/CArray/bug/store_spec.rb +0 -27
  268. data/spec/CArray/index/repeat_spec.rb +0 -10
  269. data/spec/CArray/method/eq_spec.rb +0 -80
  270. data/spec/CArray/method/is_nan_spec.rb +0 -12
  271. data/spec/CArray/method/ne_spec.rb +0 -18
  272. data/spec/CArray/method/round_spec.rb +0 -11
  273. data/spec/CArray/object/_attribute_spec.rb +0 -32
  274. data/spec/CArray/object/s_new_spec.rb +0 -31
  275. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  276. data/test/test_130.rb +0 -23
  277. data/test/test_ALL.rb +0 -51
  278. data/test/test_CABitfield.rb +0 -59
  279. data/test/test_CABlock.rb +0 -208
  280. data/test/test_CAField.rb +0 -40
  281. data/test/test_CAGrid.rb +0 -76
  282. data/test/test_CAMmap.rb +0 -11
  283. data/test/test_CARefer.rb +0 -94
  284. data/test/test_CARepeat.rb +0 -66
  285. data/test/test_CASelect.rb +0 -23
  286. data/test/test_CAShift.rb +0 -17
  287. data/test/test_CAWindow.rb +0 -55
  288. data/test/test_CAWrap.rb +0 -9
  289. data/test/test_CComplex.rb +0 -83
  290. data/test/test_CScalar.rb +0 -91
  291. data/test/test_attribute.rb +0 -281
  292. data/test/test_block_iterator.rb +0 -17
  293. data/test/test_boolean.rb +0 -99
  294. data/test/test_cast.rb +0 -33
  295. data/test/test_class.rb +0 -85
  296. data/test/test_complex.rb +0 -43
  297. data/test/test_convert.rb +0 -79
  298. data/test/test_copy.rb +0 -141
  299. data/test/test_creation.rb +0 -85
  300. data/test/test_element.rb +0 -146
  301. data/test/test_extream.rb +0 -55
  302. data/test/test_generate.rb +0 -75
  303. data/test/test_index.rb +0 -71
  304. data/test/test_mask.rb +0 -578
  305. data/test/test_math.rb +0 -98
  306. data/test/test_narray.rb +0 -64
  307. data/test/test_order.rb +0 -147
  308. data/test/test_random.rb +0 -15
  309. data/test/test_ref_store.rb +0 -211
  310. data/test/test_stat.rb +0 -414
  311. data/test/test_struct.rb +0 -72
  312. data/test/test_virtual.rb +0 -49
  313. data/utils/create_rdoc.sh +0 -9
  314. data/utils/make_tgz.sh +0 -3
  315. data/version.h +0 -18
@@ -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
-