carray 1.3.6 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +32 -0
- data/LICENSE +22 -0
- data/NEWS.md +65 -0
- data/README.md +23 -26
- data/Rakefile +31 -0
- data/TODO.md +17 -0
- data/carray.gemspec +24 -31
- data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
- data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
- data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
- data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
- data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
- data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +38 -40
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
- data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
- data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
- data/{carray.h → ext/carray.h} +90 -59
- data/{carray_access.c → ext/carray_access.c} +244 -109
- data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
- data/{carray_cast.c → ext/carray_cast.c} +350 -149
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
- data/{carray_class.c → ext/carray_class.c} +28 -36
- data/{carray_conversion.c → ext/carray_conversion.c} +58 -70
- data/{carray_copy.c → ext/carray_copy.c} +34 -50
- data/{carray_core.c → ext/carray_core.c} +75 -62
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +34 -53
- data/{carray_generate.c → ext/carray_generate.c} +137 -50
- data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
- data/{carray_loop.c → ext/carray_loop.c} +77 -106
- data/{carray_mask.c → ext/carray_mask.c} +95 -114
- data/{carray_math.rb → ext/carray_math.rb} +47 -31
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
- data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
- data/{carray_operator.c → ext/carray_operator.c} +72 -36
- data/{carray_order.c → ext/carray_order.c} +73 -217
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
- data/{carray_stat.c → ext/carray_stat.c} +6 -8
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
- data/{carray_test.c → ext/carray_test.c} +59 -51
- data/{carray_undef.c → ext/carray_undef.c} +1 -11
- data/{carray_utils.c → ext/carray_utils.c} +12 -4
- data/{extconf.rb → ext/extconf.rb} +1 -6
- data/{mkmath.rb → ext/mkmath.rb} +13 -3
- data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +1 -3
- data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
- data/ext/version.h +16 -0
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +52 -10
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -8
- data/lib/carray/autoload/autoload_base.rb +1 -5
- data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
- data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
- data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
- data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
- data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
- data/lib/carray/basic.rb +191 -0
- data/lib/carray/broadcast.rb +82 -0
- data/lib/carray/compose.rb +315 -0
- data/lib/carray/construct.rb +460 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/info.rb +1 -3
- data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
- data/lib/carray/io/imagemagick.rb +2 -4
- data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
- data/lib/carray/mask.rb +102 -0
- data/lib/carray/{base/math.rb → math.rb} +21 -53
- data/lib/carray/math/histogram.rb +8 -10
- data/lib/carray/math/recurrence.rb +1 -3
- data/lib/carray/mkmf.rb +9 -3
- data/lib/carray/object/ca_obj_iterator.rb +1 -3
- data/lib/carray/object/ca_obj_link.rb +1 -3
- data/lib/carray/object/ca_obj_pack.rb +9 -11
- data/lib/carray/obsolete.rb +270 -0
- data/lib/carray/ordering.rb +181 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +50 -66
- data/lib/carray/string.rb +188 -0
- data/lib/carray/{base/struct.rb → struct.rb} +19 -21
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- data/lib/carray/testing.rb +51 -0
- data/lib/carray/time.rb +76 -0
- data/lib/carray/transform.rb +98 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/spec/Classes/CABitfield_spec.rb +58 -0
- data/spec/Classes/CABlockIterator_spec.rb +114 -0
- data/spec/Classes/CABlock_spec.rb +205 -0
- data/spec/Classes/CAField_spec.rb +39 -0
- data/spec/Classes/CAGrid_spec.rb +75 -0
- data/spec/Classes/CAMap_spec.rb +0 -0
- data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
- data/spec/Classes/CAObject_attribute_spec.rb +33 -0
- data/spec/Classes/CAObject_spec.rb +33 -0
- data/spec/Classes/CARefer_spec.rb +93 -0
- data/spec/Classes/CARepeat_spec.rb +65 -0
- data/spec/Classes/CASelect_spec.rb +22 -0
- data/spec/Classes/CAShift_spec.rb +16 -0
- data/spec/Classes/CAStruct_spec.rb +71 -0
- data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
- data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
- data/spec/Classes/CAWindow_spec.rb +54 -0
- data/spec/Classes/CAWrap_spec.rb +8 -0
- data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
- data/spec/Classes/CScalar_spec.rb +55 -0
- data/spec/Features/feature_130_spec.rb +19 -0
- data/spec/Features/feature_attributes_spec.rb +280 -0
- data/spec/Features/feature_boolean_spec.rb +98 -0
- data/spec/Features/feature_broadcast.rb +116 -0
- data/spec/Features/feature_cast_function.rb +19 -0
- data/spec/Features/feature_cast_spec.rb +33 -0
- data/spec/Features/feature_class_spec.rb +84 -0
- data/spec/Features/feature_complex_spec.rb +42 -0
- data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
- data/spec/Features/feature_convert_spec.rb +46 -0
- data/spec/Features/feature_copy_spec.rb +123 -0
- data/spec/Features/feature_creation_spec.rb +84 -0
- data/spec/Features/feature_element_spec.rb +144 -0
- data/spec/Features/feature_extream_spec.rb +54 -0
- data/spec/Features/feature_generate_spec.rb +74 -0
- data/spec/Features/feature_index_spec.rb +69 -0
- data/spec/Features/feature_mask_spec.rb +580 -0
- data/spec/Features/feature_math_spec.rb +97 -0
- data/spec/Features/feature_order_spec.rb +146 -0
- data/spec/Features/feature_ref_store_spec.rb +209 -0
- data/spec/Features/feature_serialization_spec.rb +125 -0
- data/spec/Features/feature_stat_spec.rb +397 -0
- data/spec/Features/feature_virtual_spec.rb +48 -0
- data/spec/Features/method_eq_spec.rb +81 -0
- data/spec/Features/method_is_nan_spec.rb +12 -0
- data/spec/Features/method_map_spec.rb +54 -0
- data/spec/Features/method_max_with.rb +20 -0
- data/spec/Features/method_min_with.rb +19 -0
- data/spec/Features/method_ne_spec.rb +18 -0
- data/spec/Features/method_project_spec.rb +188 -0
- data/spec/Features/method_ref_spec.rb +27 -0
- data/spec/Features/method_round_spec.rb +11 -0
- data/spec/Features/method_s_linspace_spec.rb +48 -0
- data/spec/Features/method_s_span_spec.rb +14 -0
- data/spec/Features/method_seq_spec.rb +47 -0
- data/spec/Features/method_sort_with.rb +43 -0
- data/spec/Features/method_sorted_with.rb +29 -0
- data/spec/Features/method_span_spec.rb +42 -0
- data/spec/Features/method_wrap_readonly_spec.rb +43 -0
- data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
- data/spec/spec_all.rb +0 -1
- data/utils/convert_test.rb +73 -0
- data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +173 -316
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/Makefile +0 -451
- data/TODO +0 -5
- data/carray_cast_func.c +0 -8670
- data/carray_config.h +0 -26
- data/carray_math.c +0 -24805
- data/carray_random.c +0 -531
- data/carray_stat_proc.c +0 -12170
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/fortio/extconf.rb +0 -3
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
- data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
- data/ext/fortio/lib/fortio.rb +0 -3
- data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
- data/ext/fortio/lib/fortio/fortran_format.y +0 -215
- data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
- data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
- data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
- data/ext/fortio/ruby_fortio.c +0 -182
- data/ext/fortio/test/test_H.rb +0 -5
- data/ext/fortio/test/test_T.rb +0 -7
- data/ext/fortio/test/test_fortran_format.rb +0 -86
- data/ext/fortio/test/test_namelist.rb +0 -25
- data/ext/fortio/test/test_namelist_write.rb +0 -10
- data/ext/fortio/test/test_sequential.rb +0 -13
- data/ext/fortio/test/test_sequential2.rb +0 -13
- data/ext/fortio/work/test.rb +0 -10
- data/ext/fortio/work/test_e.rb +0 -19
- data/ext/fortio/work/test_ep.rb +0 -10
- data/ext/fortio/work/test_parse.rb +0 -12
- data/ext/imagemap/carray_imagemap.c +0 -495
- data/ext/imagemap/doc/call_graph.dot +0 -28
- data/ext/imagemap/draw.c +0 -567
- data/ext/imagemap/extconf.rb +0 -13
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
- data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
- data/ext/imagemap/lib/image_map.rb +0 -4
- data/ext/imagemap/test/swath_index.rb +0 -83
- data/ext/imagemap/test/swath_warp.rb +0 -99
- data/ext/imagemap/test/test.rb +0 -23
- data/ext/imagemap/test/test_image.rb +0 -42
- data/ext/imagemap/test/test_line.rb +0 -14
- data/ext/imagemap/test/test_rotate.rb +0 -17
- data/ext/imagemap/test/test_triangle.rb +0 -20
- data/ext/imagemap/test/test_warp.rb +0 -26
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
- data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/ext/narray/README +0 -22
- data/ext/narray/ca_wrap_narray.c +0 -500
- data/ext/narray/carray_narray.c +0 -21
- data/ext/narray/extconf.rb +0 -57
- data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
- data/ext/narray/lib/math/narray.rb +0 -17
- data/ext/narray/lib/math/narray_miss.rb +0 -45
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
- data/lib/carray/autoload/autoload_io_csv.rb +0 -14
- data/lib/carray/autoload/autoload_io_pg.rb +0 -6
- data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1090
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/graphics/gnuplot.rb +0 -2131
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/pg.rb +0 -101
- data/lib/carray/io/sqlite3.rb +0 -215
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mkmf.log +0 -375
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_ext.rb +0 -1115
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
- data/spec/CArray/bug/store_spec.rb +0 -27
- data/spec/CArray/index/repeat_spec.rb +0 -10
- data/spec/CArray/method/eq_spec.rb +0 -80
- data/spec/CArray/method/is_nan_spec.rb +0 -12
- data/spec/CArray/method/ne_spec.rb +0 -18
- data/spec/CArray/method/round_spec.rb +0 -11
- data/spec/CArray/object/_attribute_spec.rb +0 -32
- data/spec/CArray/object/s_new_spec.rb +0 -31
- data/spec/CArray/serialize/Serialization_spec.rb +0 -89
- data/test/test_130.rb +0 -23
- data/test/test_ALL.rb +0 -51
- data/test/test_CABitfield.rb +0 -59
- data/test/test_CABlock.rb +0 -208
- data/test/test_CAField.rb +0 -40
- data/test/test_CAGrid.rb +0 -76
- data/test/test_CAMmap.rb +0 -11
- data/test/test_CARefer.rb +0 -94
- data/test/test_CARepeat.rb +0 -66
- data/test/test_CASelect.rb +0 -23
- data/test/test_CAShift.rb +0 -17
- data/test/test_CAWindow.rb +0 -55
- data/test/test_CAWrap.rb +0 -9
- data/test/test_CComplex.rb +0 -83
- data/test/test_CScalar.rb +0 -91
- data/test/test_attribute.rb +0 -281
- data/test/test_block_iterator.rb +0 -17
- data/test/test_boolean.rb +0 -99
- data/test/test_cast.rb +0 -33
- data/test/test_class.rb +0 -85
- data/test/test_complex.rb +0 -43
- data/test/test_convert.rb +0 -79
- data/test/test_copy.rb +0 -141
- data/test/test_creation.rb +0 -85
- data/test/test_element.rb +0 -146
- data/test/test_extream.rb +0 -55
- data/test/test_generate.rb +0 -75
- data/test/test_index.rb +0 -71
- data/test/test_mask.rb +0 -578
- data/test/test_math.rb +0 -98
- data/test/test_narray.rb +0 -64
- data/test/test_order.rb +0 -147
- data/test/test_random.rb +0 -15
- data/test/test_ref_store.rb +0 -211
- data/test/test_stat.rb +0 -414
- data/test/test_struct.rb +0 -72
- data/test/test_virtual.rb +0 -49
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
- data/version.h +0 -18
data/carray_random.c
DELETED
@@ -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
|
-
|