carray 1.3.7 → 1.5.4
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 +78 -0
- data/README.md +43 -30
- data/Rakefile +31 -0
- data/TODO.md +17 -0
- data/carray.gemspec +21 -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} +44 -48
- 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} +65 -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} +105 -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} +232 -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} +6 -7
- data/{mkmath.rb → ext/mkmath.rb} +14 -4
- data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +2 -4
- 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 +101 -0
- data/lib/carray/compose.rb +315 -0
- data/lib/carray/construct.rb +484 -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 +256 -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 -10
- data/lib/carray/testing.rb +51 -0
- data/lib/carray/time.rb +76 -0
- data/lib/carray/transform.rb +109 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +16 -38
- 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 +171 -298
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- 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/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_numo.rb +0 -9
- 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 -2141
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/numo.rb +0 -52
- 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/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- 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/mt19937ar.c
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The names of routines in original mt19937ar.c are all prefixed with "ca_"
|
3
|
-
to avoid collision with ruby's runtime library.
|
4
|
-
*/
|
5
|
-
|
6
|
-
#include "mt19937ar.h"
|
7
|
-
|
8
|
-
/*
|
9
|
-
A C-program for MT19937, with initialization improved 2002/1/26.
|
10
|
-
Coded by Takuji Nishimura and Makoto Matsumoto.
|
11
|
-
|
12
|
-
Before using, initialize the state by using init_genrand(seed)
|
13
|
-
or init_by_array(init_key, key_length).
|
14
|
-
|
15
|
-
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
16
|
-
All rights reserved.
|
17
|
-
Copyright (C) 2005, Mutsuo Saito,
|
18
|
-
All rights reserved.
|
19
|
-
|
20
|
-
Redistribution and use in source and binary forms, with or without
|
21
|
-
modification, are permitted provided that the following conditions
|
22
|
-
are met:
|
23
|
-
|
24
|
-
1. Redistributions of source code must retain the above copyright
|
25
|
-
notice, this list of conditions and the following disclaimer.
|
26
|
-
|
27
|
-
2. Redistributions in binary form must reproduce the above copyright
|
28
|
-
notice, this list of conditions and the following disclaimer in the
|
29
|
-
documentation and/or other materials provided with the distribution.
|
30
|
-
|
31
|
-
3. The names of its contributors may not be used to endorse or promote
|
32
|
-
products derived from this software without specific prior written
|
33
|
-
permission.
|
34
|
-
|
35
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
36
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
37
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
38
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
39
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
40
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
41
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
42
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
43
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
44
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
45
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
46
|
-
|
47
|
-
|
48
|
-
Any feedback is very welcome.
|
49
|
-
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
50
|
-
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
51
|
-
*/
|
52
|
-
|
53
|
-
#include <stdio.h>
|
54
|
-
#include "mt19937ar.h"
|
55
|
-
|
56
|
-
/* Period parameters */
|
57
|
-
#define N 624
|
58
|
-
#define M 397
|
59
|
-
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
60
|
-
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
61
|
-
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
62
|
-
|
63
|
-
static unsigned long mt[N]; /* the array for the state vector */
|
64
|
-
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
|
65
|
-
|
66
|
-
/* initializes mt[N] with a seed */
|
67
|
-
void init_genrand(unsigned long s)
|
68
|
-
{
|
69
|
-
mt[0]= s & 0xffffffffUL;
|
70
|
-
for (mti=1; mti<N; mti++) {
|
71
|
-
mt[mti] =
|
72
|
-
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
|
73
|
-
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
74
|
-
/* In the previous versions, MSBs of the seed affect */
|
75
|
-
/* only MSBs of the array mt[]. */
|
76
|
-
/* 2002/01/09 modified by Makoto Matsumoto */
|
77
|
-
mt[mti] &= 0xffffffffUL;
|
78
|
-
/* for >32 bit machines */
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
/* initialize by an array with array-length */
|
83
|
-
/* init_key is the array for initializing keys */
|
84
|
-
/* key_length is its length */
|
85
|
-
/* slight change for C++, 2004/2/26 */
|
86
|
-
void init_by_array(unsigned long init_key[], int key_length)
|
87
|
-
{
|
88
|
-
int i, j, k;
|
89
|
-
init_genrand(19650218UL);
|
90
|
-
i=1; j=0;
|
91
|
-
k = (N>key_length ? N : key_length);
|
92
|
-
for (; k; k--) {
|
93
|
-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
|
94
|
-
+ init_key[j] + j; /* non linear */
|
95
|
-
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
96
|
-
i++; j++;
|
97
|
-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
98
|
-
if (j>=key_length) j=0;
|
99
|
-
}
|
100
|
-
for (k=N-1; k; k--) {
|
101
|
-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
|
102
|
-
- i; /* non linear */
|
103
|
-
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
104
|
-
i++;
|
105
|
-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
106
|
-
}
|
107
|
-
|
108
|
-
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
109
|
-
}
|
110
|
-
|
111
|
-
/* generates a random number on [0,0xffffffff]-interval */
|
112
|
-
unsigned long genrand_int32(void)
|
113
|
-
{
|
114
|
-
unsigned long y;
|
115
|
-
static unsigned long mag01[2]={0x0UL, MATRIX_A};
|
116
|
-
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
117
|
-
|
118
|
-
if (mti >= N) { /* generate N words at one time */
|
119
|
-
int kk;
|
120
|
-
|
121
|
-
if (mti == N+1) /* if init_genrand() has not been called, */
|
122
|
-
init_genrand(5489UL); /* a default initial seed is used */
|
123
|
-
|
124
|
-
for (kk=0;kk<N-M;kk++) {
|
125
|
-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
126
|
-
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
127
|
-
}
|
128
|
-
for (;kk<N-1;kk++) {
|
129
|
-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
130
|
-
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
131
|
-
}
|
132
|
-
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
|
133
|
-
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
134
|
-
|
135
|
-
mti = 0;
|
136
|
-
}
|
137
|
-
|
138
|
-
y = mt[mti++];
|
139
|
-
|
140
|
-
/* Tempering */
|
141
|
-
y ^= (y >> 11);
|
142
|
-
y ^= (y << 7) & 0x9d2c5680UL;
|
143
|
-
y ^= (y << 15) & 0xefc60000UL;
|
144
|
-
y ^= (y >> 18);
|
145
|
-
|
146
|
-
return y;
|
147
|
-
}
|
148
|
-
|
149
|
-
/* generates a random number on [0,0x7fffffff]-interval */
|
150
|
-
long genrand_int31(void)
|
151
|
-
{
|
152
|
-
return (long)(genrand_int32()>>1);
|
153
|
-
}
|
154
|
-
|
155
|
-
/* generates a random number on [0,1]-real-interval */
|
156
|
-
double genrand_real1(void)
|
157
|
-
{
|
158
|
-
return genrand_int32()*(1.0/4294967295.0);
|
159
|
-
/* divided by 2^32-1 */
|
160
|
-
}
|
161
|
-
|
162
|
-
/* generates a random number on [0,1)-real-interval */
|
163
|
-
double genrand_real2(void)
|
164
|
-
{
|
165
|
-
return genrand_int32()*(1.0/4294967296.0);
|
166
|
-
/* divided by 2^32 */
|
167
|
-
}
|
168
|
-
|
169
|
-
/* generates a random number on (0,1)-real-interval */
|
170
|
-
double genrand_real3(void)
|
171
|
-
{
|
172
|
-
return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
|
173
|
-
/* divided by 2^32 */
|
174
|
-
}
|
175
|
-
|
176
|
-
/* generates a random number on [0,1) with 53-bit resolution*/
|
177
|
-
double genrand_res53(void)
|
178
|
-
{
|
179
|
-
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
|
180
|
-
return(a*67108864.0+b)*(1.0/9007199254740992.0);
|
181
|
-
}
|
182
|
-
/* These real versions are due to Isaku Wada, 2002/01/09 added */
|
data/mt19937ar.h
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The names of routines in original mt19937ar.c are all prefixed with "ca_"
|
3
|
-
to avoid collision with ruby's runtime library.
|
4
|
-
*/
|
5
|
-
|
6
|
-
#define init_genrand ca_init_genrand
|
7
|
-
#define init_by_array ca_init_by_array
|
8
|
-
#define genrand_int32 ca_genrand_int32
|
9
|
-
#define genrand_int31 ca_genrand_int31
|
10
|
-
#define genrand_real1 ca_genrand_real1
|
11
|
-
#define genrand_real2 ca_genrand_real2
|
12
|
-
#define genrand_real3 ca_genrand_real3
|
13
|
-
#define genrand_res53 ca_genrand_res53
|
14
|
-
|
15
|
-
/*
|
16
|
-
A C-program for MT19937, with initialization improved 2002/1/26.
|
17
|
-
Coded by Takuji Nishimura and Makoto Matsumoto.
|
18
|
-
|
19
|
-
Before using, initialize the state by using init_genrand(seed)
|
20
|
-
or init_by_array(init_key, key_length).
|
21
|
-
|
22
|
-
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
23
|
-
All rights reserved.
|
24
|
-
Copyright (C) 2005, Mutsuo Saito
|
25
|
-
All rights reserved.
|
26
|
-
|
27
|
-
Redistribution and use in source and binary forms, with or without
|
28
|
-
modification, are permitted provided that the following conditions
|
29
|
-
are met:
|
30
|
-
|
31
|
-
1. Redistributions of source code must retain the above copyright
|
32
|
-
notice, this list of conditions and the following disclaimer.
|
33
|
-
|
34
|
-
2. Redistributions in binary form must reproduce the above copyright
|
35
|
-
notice, this list of conditions and the following disclaimer in the
|
36
|
-
documentation and/or other materials provided with the distribution.
|
37
|
-
|
38
|
-
3. The names of its contributors may not be used to endorse or promote
|
39
|
-
products derived from this software without specific prior written
|
40
|
-
permission.
|
41
|
-
|
42
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
43
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
44
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
45
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
46
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
47
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
48
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
49
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
50
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
51
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
52
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
-
|
54
|
-
|
55
|
-
Any feedback is very welcome.
|
56
|
-
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
57
|
-
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
58
|
-
*/
|
59
|
-
|
60
|
-
/* initializes mt[N] with a seed */
|
61
|
-
void init_genrand(unsigned long s);
|
62
|
-
|
63
|
-
/* initialize by an array with array-length */
|
64
|
-
/* init_key is the array for initializing keys */
|
65
|
-
/* key_length is its length */
|
66
|
-
/* slight change for C++, 2004/2/26 */
|
67
|
-
void init_by_array(unsigned long init_key[], int key_length);
|
68
|
-
|
69
|
-
/* generates a random number on [0,0xffffffff]-interval */
|
70
|
-
unsigned long genrand_int32(void);
|
71
|
-
|
72
|
-
/* generates a random number on [0,0x7fffffff]-interval */
|
73
|
-
long genrand_int31(void);
|
74
|
-
|
75
|
-
/* These real versions are due to Isaku Wada, 2002/01/09 added */
|
76
|
-
/* generates a random number on [0,1]-real-interval */
|
77
|
-
double genrand_real1(void);
|
78
|
-
|
79
|
-
/* generates a random number on [0,1)-real-interval */
|
80
|
-
double genrand_real2(void);
|
81
|
-
|
82
|
-
/* generates a random number on (0,1)-real-interval */
|
83
|
-
double genrand_real3(void);
|
84
|
-
|
85
|
-
/* generates a random number on [0,1) with 53-bit resolution*/
|
86
|
-
double genrand_res53(void);
|
data/rdoc_main.rb
DELETED
data/rdoc_stat.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class CArray
|
2
|
-
|
3
|
-
# Accumulates the all elements. The overflow is treated in
|
4
|
-
# the C-language way.
|
5
|
-
#
|
6
|
-
# a = CArray.int8(2) { [127,1] };
|
7
|
-
# a.sum
|
8
|
-
# => 128.0
|
9
|
-
# a.accumulate
|
10
|
-
# => -128
|
11
|
-
#
|
12
|
-
# a = CArray.uint32(2) { [0xffffffff,1] };
|
13
|
-
# a.sum
|
14
|
-
# => 4294967296.0
|
15
|
-
# a.accumulate
|
16
|
-
# => 0
|
17
|
-
#
|
18
|
-
# a = CArray.float(2) { [0xffffffff,1] };
|
19
|
-
# a.sum
|
20
|
-
# => 4294967297.0
|
21
|
-
# a.accumulate
|
22
|
-
# => 4294967296.0
|
23
|
-
#
|
24
|
-
# a = CArray.object(2) { [0xffffffff,1] };
|
25
|
-
# a.sum
|
26
|
-
# => 4294967296
|
27
|
-
# a.accumulate
|
28
|
-
# => 4294967296
|
29
|
-
def accumulate (options={})
|
30
|
-
end
|
31
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require "carray"
|
2
|
-
|
3
|
-
describe CABlockIterator do
|
4
|
-
|
5
|
-
describe "each method" do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@original = CArray.object(4,4).seq!
|
9
|
-
@it = @original.blocks(0..1, 0..1)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should call 4-times its block" do
|
13
|
-
count = 0
|
14
|
-
@it.each do |blk|
|
15
|
-
count += 1
|
16
|
-
end
|
17
|
-
( count ).should == 4
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should have the block parameter of 2x2 CABlock object" do
|
21
|
-
@it.each do |blk|
|
22
|
-
( blk ).should be_an_instance_of(CABlock)
|
23
|
-
( blk.data_type ).should == CA_OBJECT
|
24
|
-
( blk.dim ).should == [2,2]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "reference method []" do
|
31
|
-
|
32
|
-
before do
|
33
|
-
@original = CArray.object(4,4).seq!
|
34
|
-
@it = @original.blocks(0..1, 0..1)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should return a 2x2 CABlock object" do
|
38
|
-
blk = @it[0]
|
39
|
-
( blk ).should be_an_instance_of(CABlock)
|
40
|
-
( blk.data_type ).should == CA_OBJECT
|
41
|
-
( blk ).should == CA_OBJECT([[0,1],[4,5]])
|
42
|
-
blk = @it[1,0]
|
43
|
-
( blk ).should be_an_instance_of(CABlock)
|
44
|
-
( blk.data_type ).should == CA_OBJECT
|
45
|
-
( blk ).should == CA_OBJECT([[8,9],[12,13]])
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return a 2x2 CABlock object" do
|
49
|
-
( @it[0] ).should == @it.kernel_at_addr(0, @it.reference)
|
50
|
-
( @it[1,0] ).should == @it.kernel_at_index([1,0], @it.reference)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "store method []=" do
|
56
|
-
|
57
|
-
before do
|
58
|
-
@original = CArray.object(4,4).seq!
|
59
|
-
@it = @original.blocks(0..1, 0..1)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should return a 2x2 CABlock object" do
|
63
|
-
@it[0] = 1
|
64
|
-
@it[1,0] = 2
|
65
|
-
( @it.reference ).should == CA_OBJECT( [ [ 1, 1, 2, 3 ],
|
66
|
-
[ 1, 1, 6, 7 ],
|
67
|
-
[ 2, 2, 10, 11 ],
|
68
|
-
[ 2, 2, 14, 15 ] ] )
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "pick method" do
|
74
|
-
|
75
|
-
before do
|
76
|
-
@original = CArray.object(4,4).seq!
|
77
|
-
@it = @original.blocks(0..1, 0..1)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should return a 2x2 CABlock object" do
|
81
|
-
blk = @it.pick(0)
|
82
|
-
( blk ).should be_an_instance_of(CArray)
|
83
|
-
( blk.data_type ).should == CA_OBJECT
|
84
|
-
( blk ).should == CA_OBJECT([[0,2],[8,10]])
|
85
|
-
blk = @it.pick(1,0)
|
86
|
-
( blk ).should be_an_instance_of(CArray)
|
87
|
-
( blk.data_type ).should == CA_OBJECT
|
88
|
-
( blk ).should == CA_OBJECT([[4,6],[12,14]])
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "put method" do
|
94
|
-
|
95
|
-
before do
|
96
|
-
@original = CArray.object(4,4).seq!
|
97
|
-
@it = @original.blocks(0..1, 0..1)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should store value via 2x2 CBlock object" do
|
101
|
-
@it.put(0,1)
|
102
|
-
@it.put(0,1,2)
|
103
|
-
( @it.pick(0) ).should == CA_OBJECT([[1,1],[1,1]])
|
104
|
-
( @it.pick(0,1) ).should == CA_OBJECT([[2,2],[2,2]])
|
105
|
-
( @it.reference ).should == CA_OBJECT([[ 1, 2, 1, 2 ],
|
106
|
-
[ 4, 5, 6, 7 ],
|
107
|
-
[ 1, 2, 1, 2 ],
|
108
|
-
[ 12, 13, 14, 15 ]])
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|