narray 0.5.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/src/ChangeLog +614 -0
- data/src/MANIFEST +82 -0
- data/src/README.en +54 -0
- data/src/README.ja +63 -0
- data/src/SPEC.en +300 -0
- data/src/SPEC.ja +284 -0
- data/src/depend +14 -0
- data/src/extconf.rb +111 -0
- data/src/lib/narray_ext.rb +211 -0
- data/src/lib/nmatrix.rb +244 -0
- data/src/mkmath.rb +780 -0
- data/src/mknafunc.rb +190 -0
- data/src/mkop.rb +638 -0
- data/src/na_array.c +644 -0
- data/src/na_func.c +1624 -0
- data/src/na_index.c +988 -0
- data/src/na_linalg.c +616 -0
- data/src/na_random.c +409 -0
- data/src/narray.c +1308 -0
- data/src/narray.def +29 -0
- data/src/narray.h +170 -0
- data/src/narray_local.h +210 -0
- data/src/nimage/README.en +38 -0
- data/src/nimage/demo/fits.rb +97 -0
- data/src/nimage/demo/fits_convol.rb +28 -0
- data/src/nimage/demo/fits_fftdemo.rb +27 -0
- data/src/nimage/demo/fitsdemo1.rb +13 -0
- data/src/nimage/demo/fitsdemo2.rb +30 -0
- data/src/nimage/demo/fitsdemo3.rb +26 -0
- data/src/nimage/demo/fitsmorph.rb +39 -0
- data/src/nimage/demo/life_na.rb +57 -0
- data/src/nimage/demo/mandel.rb +41 -0
- data/src/nimage/extconf.rb +12 -0
- data/src/nimage/lib/nimage.rb +51 -0
- data/src/nimage/nimage.c +328 -0
- data/src/speed/add.py +12 -0
- data/src/speed/add.rb +8 -0
- data/src/speed/add_int.py +12 -0
- data/src/speed/add_int.rb +9 -0
- data/src/speed/lu.m +14 -0
- data/src/speed/lu.rb +22 -0
- data/src/speed/mat.m +23 -0
- data/src/speed/mat.rb +28 -0
- data/src/speed/mul.py +12 -0
- data/src/speed/mul.rb +9 -0
- data/src/speed/mul2.py +15 -0
- data/src/speed/mul2.rb +13 -0
- data/src/speed/mul_comp.py +12 -0
- data/src/speed/mul_comp.rb +9 -0
- data/src/speed/mul_int.py +12 -0
- data/src/speed/mul_int.rb +9 -0
- data/src/speed/mybench.py +15 -0
- data/src/speed/mybench.rb +31 -0
- data/src/speed/solve.m +18 -0
- data/src/speed/solve.py +16 -0
- data/src/speed/solve.rb +21 -0
- data/src/test/statistics.rb +22 -0
- data/src/test/testarray.rb +20 -0
- data/src/test/testbit.rb +27 -0
- data/src/test/testcast.rb +14 -0
- data/src/test/testcomplex.rb +35 -0
- data/src/test/testfftw.rb +16 -0
- data/src/test/testindex.rb +11 -0
- data/src/test/testindexary.rb +26 -0
- data/src/test/testindexset.rb +55 -0
- data/src/test/testmask.rb +40 -0
- data/src/test/testmath.rb +48 -0
- data/src/test/testmath2.rb +46 -0
- data/src/test/testmatrix.rb +13 -0
- data/src/test/testmatrix2.rb +33 -0
- data/src/test/testmatrix3.rb +19 -0
- data/src/test/testminmax.rb +46 -0
- data/src/test/testobject.rb +29 -0
- data/src/test/testpow.rb +19 -0
- data/src/test/testrandom.rb +23 -0
- data/src/test/testround.rb +11 -0
- data/src/test/testsort.rb +37 -0
- data/src/test/teststr.rb +13 -0
- data/src/test/testtrans.rb +18 -0
- data/src/test/testwhere.rb +27 -0
- metadata +127 -0
data/src/README.en
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Ruby/NArray ver 0.5.9 (2006-08-09) by Masahiro TANAKA
|
2
|
+
|
3
|
+
* NArray properties:
|
4
|
+
|
5
|
+
+ Fast and easy calculation for large numerical array.
|
6
|
+
+ Accepting Elements:
|
7
|
+
8,16,32 bit integer, single/double float/complex, Ruby Object.
|
8
|
+
+ Easy extraction/substitution of array subset,
|
9
|
+
using assignment with number, range, array index.
|
10
|
+
+ Operator: +,-,*,/,%,**, etc.
|
11
|
+
+ FFTW version 2 or 3 is separately supported.
|
12
|
+
http://www.ir.isas.ac.jp/~masa/ruby/dist/ruby-fftw3-0.1.0.tar.gz
|
13
|
+
+ NImage: Image viewer class.
|
14
|
+
+ Ruby/PGPLOT: Graphics library interface (separately distributed)
|
15
|
+
X-Y Graph, Histogram, Contour map, Image map, etc.
|
16
|
+
|
17
|
+
* NArray is similar to:
|
18
|
+
|
19
|
+
+ Python/NumPy, Perl/PDL, Yorick, IDL
|
20
|
+
|
21
|
+
* NArray is far from completed!
|
22
|
+
|
23
|
+
+ Experimental! Specification may be changed.
|
24
|
+
+ Far from completed.
|
25
|
+
+ Bugs may be included.
|
26
|
+
+ No document.
|
27
|
+
|
28
|
+
* Installation
|
29
|
+
|
30
|
+
+ If you want to use FFTW, install it.
|
31
|
+
http://www.fftw.org/ or http://www.netlib.org/
|
32
|
+
|
33
|
+
+ Compile & Install NArray
|
34
|
+
|
35
|
+
ruby extconf.rb
|
36
|
+
make
|
37
|
+
make site-install
|
38
|
+
(or, make install)
|
39
|
+
|
40
|
+
* Tested Platform
|
41
|
+
|
42
|
+
ruby 1.8.4 (2005-12-24) [i686-linux]
|
43
|
+
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
|
44
|
+
|
45
|
+
* License
|
46
|
+
|
47
|
+
This program is free software.
|
48
|
+
You can distribute/modify this program
|
49
|
+
under the same terms as Ruby itself.
|
50
|
+
NO WARRANTY.
|
51
|
+
|
52
|
+
* Author
|
53
|
+
|
54
|
+
Masahiro TANAKA <masa@ir.isas.ac.jp>
|
data/src/README.ja
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
Ruby/NArray ver 0.5.9 (2006-08-09) by Masahiro TANAKA
|
2
|
+
|
3
|
+
* Ruby/NArray$B$NFCD'!#(B
|
4
|
+
|
5
|
+
+ Ruby$B$G!"9bB.$J?tCM7W;;$,2DG=!#(B
|
6
|
+
+ $BMWAG$K$O!"(B8,16,32 bit $B@0?t!"C1@:EY(B/$BG\@:EY$N<B?t(B/$BJ#AG?t!"(B
|
7
|
+
$B$*$h$S(B Ruby$B%*%V%8%'%/%H$r%5%]!<%H!#(B
|
8
|
+
+ $BItJ,G[Ns$N<h=P$7!"BeF~$bMF0W!#(B
|
9
|
+
$BMWAG0LCV$N;XDj$K$O!"?tCM!"HO0O!"%$%s%G%C%/%9$NG[Ns$,;HMQ2DG=!#(B
|
10
|
+
+ +,-,*,/,%,** $B$d(B $B;;=Q4X?t$N1i;;$O!"MWAG(B-$BBP(B-$BMWAG$G$*$3$J$&!#(B
|
11
|
+
+ $BG[NsF1;N$N1i;;!&BeF~$O!"3F<!85$N%5%$%:$,F1$8$G$"$k$3$H$,I,MW!#(B
|
12
|
+
$B$?$@$7!"%5%$%:$,(B1$B$N<!85$O!"B>J}$NG[Ns$N%5%$%:$K9g$o$;$F(B
|
13
|
+
$B!V7+$jJV$7!WF1$8MWAG$,E,MQ$5$l$k!#(B
|
14
|
+
+ FFTW ($B9bB.%U!<%j%(JQ49(B) version 3 $B$O<!$N%b%8%e!<%k$G%5%]!<%H!#(B
|
15
|
+
http://www.ir.isas.ac.jp/~masa/ruby/dist/ruby-fftw3-0.1.0.tar.gz
|
16
|
+
+ NImage (X11$B%$%a!<%8I=<((B) $B%/%i%9ImB0!#(B(nimage/ $B%G%#%l%/%H%j;2>H(B)
|
17
|
+
+ Ruby/PGPLOT ($B%0%i%U%#%C%/%9%i%$%V%i%j!"JLW}(B) $B$K$F(B
|
18
|
+
XY$B%0%i%U!"%R%9%H%0%i%`!"Ey9b@~!"%$%a!<%8I=<(2DG=!#(B
|
19
|
+
+ $B?tCM7W;;!&2hA|=hM}!&%G!<%?2r@O$J$II}9-$$1~MQ$,2DG=(B($B$H;W$&(B)$B!#(B
|
20
|
+
|
21
|
+
* $BN`;wIJ(B
|
22
|
+
|
23
|
+
+ Python/NumPy, Perl/PDL, Yorick, IDL
|
24
|
+
|
25
|
+
* $BIT==J,$JE@(B
|
26
|
+
|
27
|
+
+ $B%a%=%C%I$,ITB-!#(B
|
28
|
+
+ $B%P%0=P$7$,IT==J,!#(B
|
29
|
+
+ $B%I%-%e%a%s%H$,$J$$!#(B
|
30
|
+
|
31
|
+
* $B%$%s%9%H!<%kJ}K!(B
|
32
|
+
|
33
|
+
Ruby$B$NI8=`E*$J3HD%%i%$%V%i%j$HF1$8$G$9!#%=!<%9$rE83+$7$?%G%#%l%/%H%j$G!"(B
|
34
|
+
|
35
|
+
ruby extconf.rb
|
36
|
+
make
|
37
|
+
make site-install
|
38
|
+
($B$^$?$O(B make install)
|
39
|
+
|
40
|
+
$B$H<B9T$7$^$9!#(B
|
41
|
+
|
42
|
+
* $BF0:n3NG'(B
|
43
|
+
|
44
|
+
ruby 1.8.4 (2005-12-24) [i686-linux]
|
45
|
+
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)
|
46
|
+
|
47
|
+
* $BG[I[>r7o(B
|
48
|
+
|
49
|
+
Ruby$B$N%i%$%;%s%9$K=`5r$7$^$9!#(B
|
50
|
+
|
51
|
+
* $BCx<T(B
|
52
|
+
|
53
|
+
$BEDCf>;9((B
|
54
|
+
$B$40U8+!$%P%0%l%]!<%H$=$NB>$O(B masa@ir.isas.ac.jp $B$^$G$*4j$$$7$^$9!#(B
|
55
|
+
|
56
|
+
* $B<U<-(B
|
57
|
+
|
58
|
+
$B$^$D$b$H$f$-$R$m(B $B$5$s(B $B$r$O$8$a$H$9$k(BRuby$B3+H/<T$N$_$J$5$^(B for Ruby
|
59
|
+
|
60
|
+
$B0KF#(B $B>4B'(B $B$5$s(B for MDArray
|
61
|
+
$B3HD%%i%$%V%i%j$N:n$jJ}$d!"(BArray$B$+$iB?<!85G[Ns$KJQ49$9$kItJ,$r(B
|
62
|
+
$B;29M$K$5$;$F$$$?$@$-$^$7$?!#(B
|
63
|
+
|
data/src/SPEC.en
ADDED
@@ -0,0 +1,300 @@
|
|
1
|
+
|
2
|
+
Ruby/NArray ver 0.5.9 (2006-08-09) by Masahiro TANAKA
|
3
|
+
|
4
|
+
|
5
|
+
Class method:
|
6
|
+
NArray.new(typecode, size, ...) create new NArray. initialize with 0.
|
7
|
+
|
8
|
+
NArray.byte(size,...) 1 byte unsigned integer
|
9
|
+
NArray.sint(size,...) 2 byte signed integer
|
10
|
+
NArray.int(size,...) 4 byte signed integer
|
11
|
+
NArray.sfloat(size,...) single precision float
|
12
|
+
NArray.float(size,...) double precision float
|
13
|
+
NArray.scomplex(size,...) single precision complex
|
14
|
+
NArray.complex(size,...) double precision complex
|
15
|
+
NArray.object(size,...) Ruby object
|
16
|
+
all above method initialize with 0 or nil.
|
17
|
+
|
18
|
+
NArray.to_na(array) convert to NArray
|
19
|
+
NArray.to_na(string,type[,size,...])
|
20
|
+
NArray[...]
|
21
|
+
NArray[1,5,10.0] #=> NArray.float(3):[1.0, 5.0, 10.0]
|
22
|
+
NArray[1..10] #=> NArray.int(10):[1,2,3,4,5,6,7,8,9,10]
|
23
|
+
|
24
|
+
|
25
|
+
Class constant:
|
26
|
+
CLASS_DIMENSION # of dimension treated as data.
|
27
|
+
0 for NArray, 1 for NVector, 2 for NMatrix.
|
28
|
+
|
29
|
+
NArray information
|
30
|
+
self.dim Return the dimension = the number of indices
|
31
|
+
self.rank same as dim
|
32
|
+
self.shape Return the array of sizes of each index
|
33
|
+
self.total Return the number of total elements
|
34
|
+
|
35
|
+
Slicing Array
|
36
|
+
- Index components: Integer, Range, Array, true.
|
37
|
+
- Index order: FORTRAN type.
|
38
|
+
a[ 1, 2, -1 ] element slicing.
|
39
|
+
If negative, counts backward from the end.
|
40
|
+
Element-dimensions are contracted.
|
41
|
+
a[ 0..3, 4..1 ] extract in the range.
|
42
|
+
If the former of the range is bigger,
|
43
|
+
return elements in reversed order.
|
44
|
+
a[ [1,3,2,4] ] an array with the elements of the indices.
|
45
|
+
If `a' has multi-dimension but, in [],
|
46
|
+
single index is specified,
|
47
|
+
`a' is treated as a single dimension array.
|
48
|
+
a[ 1, 2..3, [1,3,2,4], true ] compound index.
|
49
|
+
This returns 3-dim array.
|
50
|
+
a[] same as a.dup.
|
51
|
+
a[ 0, true ] sams as a[0,0..-1]. `true' means all.
|
52
|
+
a[ false, 0 ] same as a[true,true,0], if a is a 3-d array,
|
53
|
+
`false' means ellipsis dimension.
|
54
|
+
a[ mask ] masking. "mask" is a byte NArray with its
|
55
|
+
length equal to that of "a". According to the
|
56
|
+
value of each element of mask, the corresponding
|
57
|
+
element in "a" is eliminated (when 0) or
|
58
|
+
retained (when not 0).
|
59
|
+
Example:
|
60
|
+
a=NArray.float(2,2).indgen!
|
61
|
+
p a[ a.lt 3 ]
|
62
|
+
--> [ 0.0, 1.0, 2.0 ]
|
63
|
+
(Here, a.lt 3 gives a byte NArray)
|
64
|
+
(This is also done by a[ (a.lt 3).where ])
|
65
|
+
|
66
|
+
- A 2-or-more-dim array object with only one argument in `[ ]',
|
67
|
+
is treated as a flat 1-d array.
|
68
|
+
e.g.: a[3] is same as a[0,1] if a is 3x3 array.
|
69
|
+
|
70
|
+
- self.slice(...) Same as self[...] but keeps the rank of
|
71
|
+
original array by not elimiting dimensions
|
72
|
+
whose length became equal to 1 (which self[]
|
73
|
+
does). This is not the case with the
|
74
|
+
1-dimensional indexing and masking (same as []).
|
75
|
+
|
76
|
+
Replacing Elements -- Same rule as slicing
|
77
|
+
|
78
|
+
a[ 1, 2, 3 ] = 1
|
79
|
+
a[ 0..3, 1..4, 2..5 ] = 2
|
80
|
+
a[ [1,3,2,4], true ] = 3
|
81
|
+
a[] = 4 Same as a.fill!(4)
|
82
|
+
|
83
|
+
a[0..2] = b[1..5] --> Error! due to different num of elements.
|
84
|
+
a[1,2] = b[0..2,1..3] Storing elements from index [1,2]
|
85
|
+
( a[1,2]=b[0,1],a[2,2]=b[1,1],... )
|
86
|
+
a[0..2,0..3] = b[0..2,1] Storing repetitively
|
87
|
+
( a[0,0]=b[0,1],..,a[0,3]=b[0,1] )
|
88
|
+
|
89
|
+
Filling values
|
90
|
+
self.indgen!([start[,step]]) Generate index;
|
91
|
+
Set values from 'start' with 'step' increment
|
92
|
+
self.fill!(value) Fill elements with 'value'
|
93
|
+
self.random!(max) Set random values between 0<=x<max
|
94
|
+
using MT19337
|
95
|
+
self.randomn Set Normally distributed random values
|
96
|
+
with mean=0, dispersion=1 (Box-Muller)
|
97
|
+
NArray.srand([seed]) Set random seed.
|
98
|
+
A time-depend seed is choosed if omitted.
|
99
|
+
|
100
|
+
Operation: performed element by element
|
101
|
+
a = NArray.float(3,3).indgen
|
102
|
+
b = NArray.float(3,3).fill(10)
|
103
|
+
c = a*b # --> NArray.float(3,3)
|
104
|
+
|
105
|
+
a = NArray.float(3,1).indgen
|
106
|
+
b = NArray.float(1,3).fill(10)
|
107
|
+
c = a*b # --> NArray.float(3,3) -- size=1 dimension is extensible.
|
108
|
+
|
109
|
+
Arithmetic operator
|
110
|
+
-self
|
111
|
+
self + other
|
112
|
+
self - other
|
113
|
+
self * other
|
114
|
+
self / other
|
115
|
+
self % other
|
116
|
+
self ** other
|
117
|
+
self.abs
|
118
|
+
|
119
|
+
self.add! other
|
120
|
+
self.sbt! other
|
121
|
+
self.mul! other
|
122
|
+
self.div! other
|
123
|
+
self.mod! other
|
124
|
+
|
125
|
+
Bitwise operator (only for integers)
|
126
|
+
~self
|
127
|
+
self & other
|
128
|
+
self | other
|
129
|
+
self ^ other
|
130
|
+
|
131
|
+
Comparison
|
132
|
+
-- element-wise comparison, results in BYTE-type NArray;
|
133
|
+
Note that not true nor false is returned.
|
134
|
+
self.eq other ( == operator was obsolete after ver 0.5.4 )
|
135
|
+
self.ne other
|
136
|
+
self.gt other
|
137
|
+
self > other
|
138
|
+
self.ge other
|
139
|
+
self >= other
|
140
|
+
self.lt other
|
141
|
+
self < other
|
142
|
+
self.le other
|
143
|
+
self <= other
|
144
|
+
|
145
|
+
self.and other element-wise condition.
|
146
|
+
self.or other
|
147
|
+
self.xor other
|
148
|
+
self.not other
|
149
|
+
|
150
|
+
self.all? true if all the elements are true.
|
151
|
+
self.any? true if any element is true.
|
152
|
+
self.none? true if none of the element is true.
|
153
|
+
self.where Return NArray of indices where elements are true.
|
154
|
+
self.where2 Return Array including two NArrays of indices,
|
155
|
+
where elements are true and false, respectively.
|
156
|
+
|
157
|
+
e.g.: idx_t,idx_f = (a>12).where2
|
158
|
+
|
159
|
+
Statistics
|
160
|
+
self.sum(dim,..) Summation of elements in specified dimensions.
|
161
|
+
self.mean(dim,..) Mean of elements in specified dimensions.
|
162
|
+
self.stddev(dim,..) Standard deviation of elements in the dimensions.
|
163
|
+
self.min(dim,..) Minimum in the specified dimensions.
|
164
|
+
self.max(dim,..) Maximum in the specified dimensions.
|
165
|
+
(All dimensions if omitted, Range can be used)
|
166
|
+
self.median(dim) Median in 0..dim (All dimensions if omitted)
|
167
|
+
|
168
|
+
Sort
|
169
|
+
self.sort(dim) Sort in the 0..dim (All dimensions if omitted)
|
170
|
+
self.sort_index(dim) Return index of Sort result.
|
171
|
+
self[self.sort_index] equals to self.sort.
|
172
|
+
|
173
|
+
Transpose
|
174
|
+
self.transpose( dim0, dim1, .. )
|
175
|
+
Transpose array.
|
176
|
+
The dim0-th dimension goes to the 0-th dimension of new array.
|
177
|
+
Negative number counts backward.
|
178
|
+
transpose(-1,1..-2,0) is replacement between the first and the last.
|
179
|
+
|
180
|
+
Changing Shapes of indices
|
181
|
+
self.reshape!(size,...)
|
182
|
+
self.shape=(size,...)
|
183
|
+
self.newdim=(dim) Insert new dimension with size=1
|
184
|
+
|
185
|
+
Reference to another NArray
|
186
|
+
self.refer create NArray obj referring to another NArray
|
187
|
+
self.reshape(size,...) same as self.refer.reshape!
|
188
|
+
self.newdim(dim,...) same as self.refer.newdim!
|
189
|
+
|
190
|
+
Type conversion
|
191
|
+
self.floor Return integer NArray whose elements processed 'floor'
|
192
|
+
self.ceil
|
193
|
+
self.round
|
194
|
+
self.to_f Convert NArray type to float
|
195
|
+
self.to_i Convert NArray type to integer
|
196
|
+
self.to_a Convert NArray type to Ruby-object
|
197
|
+
self.to_s Convert NArray data to String as a binary data.
|
198
|
+
self.to_string Convert NArray type to Ruby-object
|
199
|
+
containing Strings as printed elements
|
200
|
+
|
201
|
+
Iteration
|
202
|
+
self.each {|i| ...}
|
203
|
+
self.collect {|i| ...}
|
204
|
+
self.collect! {|i| ...}
|
205
|
+
|
206
|
+
Byte swap
|
207
|
+
self.swap_byte swap byte order
|
208
|
+
self.hton convert to network byte order
|
209
|
+
self.ntoh
|
210
|
+
self.htov convert to VAX byte order
|
211
|
+
self.vtoh
|
212
|
+
|
213
|
+
Boolean / mask related
|
214
|
+
self.count_false count # of elements whose value == 0 (only for
|
215
|
+
byte, sint, and int)
|
216
|
+
self.count_true count # of elements whose value != 0 (only for
|
217
|
+
byte, sint, and int)
|
218
|
+
self.mask( mask ) same as self[ mask ], but exclusively for masking.
|
219
|
+
Unlike [], a int or sint mask is accepted.
|
220
|
+
|
221
|
+
Complex compound number
|
222
|
+
self.real
|
223
|
+
self.imag
|
224
|
+
self.conj
|
225
|
+
self.angle atan2(self.imag, self.real)
|
226
|
+
self.imag= other set imaginary part
|
227
|
+
self.im multiply by imaginary unit
|
228
|
+
|
229
|
+
NMath module
|
230
|
+
sqrt(x)
|
231
|
+
exp(x)
|
232
|
+
log(x)
|
233
|
+
log10(x)
|
234
|
+
log2(x)
|
235
|
+
atan2(x,y)
|
236
|
+
sin,cos,tan
|
237
|
+
sinh,cosh,tanh
|
238
|
+
asin,acos,atan
|
239
|
+
asinh,acosh,atanh
|
240
|
+
csc,sec,cot
|
241
|
+
csch,sech,coth
|
242
|
+
acsc,asec,acot
|
243
|
+
acsch,asech,acoth
|
244
|
+
covariance (no idea why NMath::covariance doesn't work)
|
245
|
+
|
246
|
+
|
247
|
+
FFTW module
|
248
|
+
(separate module)
|
249
|
+
fftw(x,[1|-1])
|
250
|
+
convol(a,b) convolution with FFTW
|
251
|
+
|
252
|
+
|
253
|
+
NMatrix
|
254
|
+
|
255
|
+
Subclass of NArray. First 2 dimensions are used as Matrix.
|
256
|
+
Residual dimensions are treated as Multi-dimensional array.
|
257
|
+
The order of Matrix dimensions is opposite from
|
258
|
+
the notation of mathematics: a_ij => a[j,i]
|
259
|
+
|
260
|
+
Methods:
|
261
|
+
+,- enable if other is NMatrix.
|
262
|
+
* Matrix product if other is NMatrix or NVector.
|
263
|
+
Scalar product if other is Numeric or NArray.
|
264
|
+
ex: NMatrix[[1,2],[3,4]] * [1,10]
|
265
|
+
== NMatrix[ [[1,2],[3,4]], [[10,20],[30,40]] ]
|
266
|
+
/ Scalar division if other is Numeric or NArray.
|
267
|
+
Solve Linear Equation with LU factorization
|
268
|
+
if other is square NMatrix. a/b == b.lu.solve(a)
|
269
|
+
|
270
|
+
transpose transpose Matrix dimensions if argument omitted.
|
271
|
+
diagonal(val)
|
272
|
+
diagonal!(val) set val to diagonal elements. (set 1 if omitted)
|
273
|
+
unit set 1 to diagonal elements.
|
274
|
+
inverse Inverse matrix.
|
275
|
+
lu compute LU factorization.
|
276
|
+
return NMatrixLU class object.
|
277
|
+
|
278
|
+
NVector
|
279
|
+
|
280
|
+
Subclass of NArray. First 1 dimension is used as Vector.
|
281
|
+
Residual dimensions are treated as Multi-dimensional array.
|
282
|
+
|
283
|
+
Methods:
|
284
|
+
+,- enable if other is NVector.
|
285
|
+
* Matrix product if other is NMatrix.
|
286
|
+
Inner product if other is NVector.
|
287
|
+
Scalar product if other is Numeric or NArray.
|
288
|
+
/ Scalar division if other is Numeric or NArray.
|
289
|
+
Solve Linear Equation with LU factorization
|
290
|
+
if other is square NMatrix. v/m == m.lu.solve(v)
|
291
|
+
|
292
|
+
|
293
|
+
NMatrixLU
|
294
|
+
|
295
|
+
Created by NMatrix#lu method.
|
296
|
+
Including LU (NMatrix) and pivot (NVector).
|
297
|
+
|
298
|
+
Methods:
|
299
|
+
solve(other) Solve with the result of LU factorization.
|
300
|
+
other should be NMatrix or NVector instance.
|
data/src/SPEC.ja
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
|
2
|
+
Ruby/NArray ver 0.5.9 (2006-08-09) by Masahiro TANAKA
|
3
|
+
|
4
|
+
|
5
|
+
$B%/%i%9%a%=%C%I(B:
|
6
|
+
NArray.new(typecode, size, ...) $BG[Ns$r@8@.$9$k!#MWAG$O(B0$B$G=i4|2=!#(B
|
7
|
+
|
8
|
+
NArray.byte(size,...) 1 byte unsigned integer
|
9
|
+
NArray.sint(size,...) 2 byte signed integer
|
10
|
+
NArray.int(size,...) 4 byte signed integer
|
11
|
+
NArray.sfloat(size,...) single precision float
|
12
|
+
NArray.float(size,...) double precision float
|
13
|
+
NArray.scomplex(size,...) single precision complex
|
14
|
+
NArray.complex(size,...) double precision complex
|
15
|
+
NArray.object(size,...) Ruby object
|
16
|
+
$B0J>eMWAG$O(B0$B$^$?$O(Bnil$B$G=i4|2=!#(B
|
17
|
+
|
18
|
+
NArray.to_na(array) NArray$B$KJQ49(B
|
19
|
+
NArray.to_na(string,type[,size,..])
|
20
|
+
NArray[...]
|
21
|
+
NArray[1,5,10.0] #=> NArray.float(3):[1.0, 5.0, 10.0]
|
22
|
+
NArray[1..10] #=> NArray.int(10):[1,2,3,4,5,6,7,8,9,10]
|
23
|
+
|
24
|
+
|
25
|
+
$B%/%i%9JQ?t(B:
|
26
|
+
CLASS_DIMENSION $B%G!<%?$H$7$F07$o$l$k<!85!#(B
|
27
|
+
NArray$B$O(B0$B!#(BNVector$B$O(B1$B!#(BNMatrix$B$O(B2$B!#(B
|
28
|
+
|
29
|
+
$BG[Ns>pJs;2>H(B
|
30
|
+
self.dim $B<!85(B($B%$%s%G%C%/%9$N?t(B)$B$rJV$9!#(B
|
31
|
+
self.rank $B<!85(B($B%$%s%G%C%/%9$N?t(B)$B$rJV$9!#(B
|
32
|
+
self.shape $B<!85$4$H$N%5%$%:$rJV$9!#(B
|
33
|
+
self.total $BA4MWAG?t$rJV$9!#(B
|
34
|
+
|
35
|
+
$B%$%s%G%C%/%9;2>H(B
|
36
|
+
self[ dim0, dim1, ... ]
|
37
|
+
|
38
|
+
-- $B%$%s%G%C%/%90z?t$K;XDj$G$-$k$b$N(B: $B?tCM!"HO0O!"G[Ns!"(Btrue, false
|
39
|
+
-- $B%$%s%G%C%/%9$N=g=x(B: FORTRAN $B7?(B
|
40
|
+
-- $BE:;z0z?t$,(B1$B$D$N>l9g!"B?<!85G[Ns$O(Bflatten$B$5$l$?(B1$B<!85G[Ns$H$_$J$5$l$k!#(B
|
41
|
+
$BNc(B: a $B$,(B 3x3 $BG[Ns$N$H$-!"(Ba[3] $B$O(B a[0,1] $B$NMWAG$r;X$9!#(B
|
42
|
+
|
43
|
+
a[ 1, 2, -1 ] $BMWAG$N<h$j=P$7!#Ii?t$O:G8e$+$i?t$($k(B(-1$B$,:G8e(B)
|
44
|
+
$BMWAG;XDj$N<!85$O=LLs$5$l$k!#(B
|
45
|
+
a[ 0..3, 4..1 ] $BHO0O<h$j=P$7!#HO0O$N:G8e$,:G=i$h$jA0$J$i$P5U=g$K$J$k!#(B
|
46
|
+
a[ [1,4,2] ] $B%$%s%G%C%/%9G[Ns!#MWAG$,(B[a[1],a[4],a[2]]$B$N(BNArray$B$,JV$k!#(B
|
47
|
+
a[] a.dup $B$HF1$8!#(B
|
48
|
+
a[ 0, true ] a[0, 0..-1] $B$HF1$8!#(B
|
49
|
+
a[ 0, false ] a$B$,(B3$B<!85$N$H$-!"(Ba[0,true,true] $B$HF1$8!#(B
|
50
|
+
$B>JN,$5$l$?<!85$9$Y$F$K(Btrue$B$r;XDj$7$?$N$HF1$8!#(B
|
51
|
+
a[ mask ] $B%^%9%-%s%0(B. mask $B$OD9$5$,(B a $B$HEy$7$$(B byte $B7?(B
|
52
|
+
NArray. mask $B$N3FMWAG$NCM$K1~$8$F!"(Ba $B$N$=$l$>(B
|
53
|
+
$B$l$OMn$5$l$k(B(0$B$N>l9g(B)$B$+!"J];}$5$l$k(B(0$B0J30$N>l9g(B)$B!#(B
|
54
|
+
$BNc(B:
|
55
|
+
a=NArray.float(2,2).indgen!
|
56
|
+
p a[ a.lt 3 ]
|
57
|
+
--> [ 0.0, 1.0, 2.0 ]
|
58
|
+
(a.lt 3 $B$O(B byte $B7?(B NArray $B$rJV$9(B)
|
59
|
+
($BF1$8$3$H$O(B a[ (a.lt 3).where ] $B$G$b=PMh$k(B)
|
60
|
+
|
61
|
+
-- self.slice(...) self[...] $B$HF1$8$@$,!"D9$5$,#1$K$J$C$?<!85$rMn(B
|
62
|
+
$B$5$:(B(self[]$B$OMn$9(B)$B!"$b$H$N%i%s%/$rJ]$D!#C"$7!"(B
|
63
|
+
1$B<!85%$%s%G%C%/%9IU$1$H%^%9%-%s%0$ONc30(B([]$B$HF1(B
|
64
|
+
$B$8(B)$B!#(B
|
65
|
+
|
66
|
+
$B%$%s%G%C%/%9BeF~!#(B-- $B<h=P$7$H$[$\F1$8%k!<%k!#(B
|
67
|
+
|
68
|
+
a[ 1, 2, 3 ] = 1
|
69
|
+
a[ 0..3, 1..4, 2..5 ] = 2
|
70
|
+
a[ [1,3,2,4], true ] = 3
|
71
|
+
a[] = 4 a.fill!(4) $B$HF1$8!#(B
|
72
|
+
|
73
|
+
a[0..2] = b[1..5] --> $BMWAG?t$,0[$J$k$N$G%(%i!<!#(B
|
74
|
+
a[1,2] = b[0..2,1..3] [1,2]$B$r;OE@$H$7$FBeF~!#(B
|
75
|
+
a[0..2,0..3] = b[0..2,1] $B7+$jJV$7BeF~!#(B
|
76
|
+
( a[0,0]=b[0,1],..,a[0,3]=b[0,1] )
|
77
|
+
|
78
|
+
$BCM$N%;%C%H!#(B
|
79
|
+
self.indgen!([start[,step]]) start$B$+$i(Bstep$B$E$DA}2C$7$?CM$r%;%C%H!#(B
|
80
|
+
self.fill!(value) $B$9$Y$F$NMWAG$K(Bvalue$B$r%;%C%H!#(B
|
81
|
+
self.random!(max) 0<=x<max $B$N0lMM$J%i%s%@%`CM$r@8@.!#(B
|
82
|
+
using MT19337
|
83
|
+
self.randomn $BJ?6Q(B0$B!"J,;6(B1$B$N@55,J,I[$N%i%s%@%`CM$r@8@.!#(B
|
84
|
+
(Box-Muller)
|
85
|
+
NArray.srand([seed]) $BMp?t$N%7!<%I$r@_Dj!#(B
|
86
|
+
$B>JN,;~$O;~9o$+$i<+F0@8@.!#(B
|
87
|
+
|
88
|
+
$B1i;;(B: $BMWAG$4$H$K$*$3$J$&!#(B
|
89
|
+
a = NArray.float(3,3).indgen
|
90
|
+
b = NArray.float(3,3).fill(10)
|
91
|
+
c = a*b # --> NArray.float(3,3)
|
92
|
+
|
93
|
+
a = NArray.float(3,1).indgen
|
94
|
+
b = NArray.float(1,3).fill(10)
|
95
|
+
c = a*b # --> NArray.float(3,3) -- size=1$B$N<!85$O3HD%$9$k!#(B
|
96
|
+
|
97
|
+
$B;;=Q1i;;;R(B
|
98
|
+
-self
|
99
|
+
self + other
|
100
|
+
self - other
|
101
|
+
self * other
|
102
|
+
self / other
|
103
|
+
self % other
|
104
|
+
self ** other
|
105
|
+
self.abs
|
106
|
+
|
107
|
+
self.add! other
|
108
|
+
self.sbt! other
|
109
|
+
self.mul! other
|
110
|
+
self.div! other
|
111
|
+
self.mod! other
|
112
|
+
|
113
|
+
self.mul_add(other,dim,...) (self * other).sum(dim,...)$B$H$[$\F1$8!#(B
|
114
|
+
$B$?$@$7ESCf$GG[Ns$r:n$i$J$$!#(B
|
115
|
+
|
116
|
+
$B%S%C%H1i;;;R(B($B@0?t$N$_2DG=(B)
|
117
|
+
~self
|
118
|
+
self & other
|
119
|
+
self | other
|
120
|
+
self ^ other
|
121
|
+
|
122
|
+
$BHf3S(B
|
123
|
+
-- $BMWAG$4$H$KCM$rHf3S$7!"7k2L$r(BBYTE$B7?(B NArray$B$rJV$9!#(B
|
124
|
+
true/false$B$G$J$$$3$H$KCm0U!#(B
|
125
|
+
self.eq other ( ver 0.5.4 $B0J9_!"(B== $B1i;;;R$OGQ;_$7$^$7$?!#(B)
|
126
|
+
self.ne other
|
127
|
+
self.gt other
|
128
|
+
self > other
|
129
|
+
self.ge other
|
130
|
+
self >= other
|
131
|
+
self.lt other
|
132
|
+
self < other
|
133
|
+
self.le other
|
134
|
+
self <= other
|
135
|
+
|
136
|
+
self.and other $BMWAG$4$H$N>r7oHf3S!#(B
|
137
|
+
self.or other
|
138
|
+
self.xor other
|
139
|
+
self.not other
|
140
|
+
|
141
|
+
self.all? $BMWAG$,$9$Y$F??$J$i$P??!#(B
|
142
|
+
self.any? $BMWAG$N$I$l$+$,??$J$i$P??!#(B
|
143
|
+
self.none? $BMWAG$N$I$l$+$,??$J$i$P??!#(B
|
144
|
+
self.where $BMWAG$,??$N%$%s%G%C%/%9G[Ns$rJV$9!#(B
|
145
|
+
self.where2 $BMWAG$,??$H56$N%$%s%G%C%/%9G[Ns$r4^$`(B(Ruby)$BG[Ns$rJV$9!#(B
|
146
|
+
|
147
|
+
$BNc(B: idx_t,idx_f = (a>12).where2
|
148
|
+
|
149
|
+
$BE}7W(B
|
150
|
+
self.sum(dim,..) $B;XDj$7$?<!85$NOB!#(B
|
151
|
+
self.mean(dim,..) $B;XDj$7$?<!85$NJ?6Q!#(B
|
152
|
+
self.stddev(dim,..) $B;XDj$7$?<!85$NI8=`JP:9!#(B
|
153
|
+
self.min(dim,..) $B;XDj$7$?<!85$N:G>.!#(B
|
154
|
+
self.max(dim,..) $B;XDj$7$?<!85$N:GBg!#(B
|
155
|
+
($B>JN,;~$OA4$F$N<!85!#(BRange$B;XDj2D!#(B)
|
156
|
+
self.median(dim) 0..dim$B$N<!85$NCf1{CM!#>JN,;~$O$9$Y$F$N<!85!#(B
|
157
|
+
|
158
|
+
$B%=!<%H(B
|
159
|
+
self.sort(dim) 0..dim$B$N<!85$G%=!<%H!#>JN,;~$O$9$Y$F$N<!85!#(B
|
160
|
+
self.sort_index(dim) $B%=!<%H$7$?%$%s%G%C%/%9$rJV$9!#(B
|
161
|
+
self[self.sort_index] $B$O(B self.sort $B$HF1Ey!#(B
|
162
|
+
|
163
|
+
$BE>CV(B
|
164
|
+
self.transpose( dim0, dim1, .. )
|
165
|
+
$BG[Ns$NE>CV!#(Bself$B$NBh(B(dim0)$B<!85$,?7$7$$G[Ns$NBh(B0$B<!85$K$J$k!#(B
|
166
|
+
$BIi?t$O8e$+$i$N=gHV!#(B
|
167
|
+
transpose(-1,1..-2,0) $B$G:G=i$H:G8e$rF~$l49$(!#(B
|
168
|
+
|
169
|
+
$B%$%s%G%C%/%9$NJQ99(B ($BMWAG?t$OITJQ(B)
|
170
|
+
self.reshape!(size,...)
|
171
|
+
self.shape= size,...
|
172
|
+
self.newdim!(dim,...) $B;XDj0LCV$K%5%$%:(B1$B$N<!85$rA^F~$9$k!#(B
|
173
|
+
|
174
|
+
$B%G!<%?$N;2>H(B
|
175
|
+
self.refer self$B$N%G!<%?$r;2>H$9$kJL$N%*%V%8%'%/%H$r:n@.!#(B
|
176
|
+
self.reshape(size,...) self.refer.reshape! $B$HF1MM!#(B
|
177
|
+
self.newdim(dim,...) self.refer.newdim! $B$HF1MM!#(B
|
178
|
+
|
179
|
+
$B7?JQ49(B
|
180
|
+
self.floor self$B$h$j>.$5$$:GBg$N@0?t$rJV$9!#(B
|
181
|
+
self.ceil self$B$h$jBg$-$$:G>.$N@0?t$rJV$9!#(B
|
182
|
+
self.round self$B$K$b$C$H$b6a$$@0?t$rJV$9!#(B
|
183
|
+
self.to_f $BCM$rIbF0>.?tE@?t$KJQ49$9$k!#(B
|
184
|
+
self.to_i $BCM$r@0?t$KJQ49$9$k!#(B
|
185
|
+
self.to_a $BCM$r(BRuby$B$NG[Ns$KJQ49$9$k!#(B
|
186
|
+
self.to_s $B%P%$%J%j%G!<%?$r$=$N$^$^(BRuby$B$NJ8;zNs%G!<%?$KJQ49$9$k!#(B
|
187
|
+
self.to_string $B3FMWAG$rJ8;zNs$KJQ49$9$k!#(B
|
188
|
+
|
189
|
+
$B%$%F%l!<%?(B
|
190
|
+
self.each {|i| ...}
|
191
|
+
self.collect {|i| ...}
|
192
|
+
self.collect! {|i| ...}
|
193
|
+
|
194
|
+
$B%P%$%H%9%o%C%W(B
|
195
|
+
self.swap_byte $B%P%$%H%9%o%C%W(B
|
196
|
+
self.hton $B%M%C%H%o!<%/%P%$%H%*!<%@!<$KJQ49(B
|
197
|
+
self.ntoh
|
198
|
+
self.htov VAX$B%P%$%H%*!<%@!<$KJQ49(B
|
199
|
+
self.vtoh
|
200
|
+
|
201
|
+
Boolean / $B%^%9%/4X78(B
|
202
|
+
self.count_false $BCM(B == 0 $B$NMWAG?t(B (byte, sint, int $B$N$_(B)
|
203
|
+
self.count_true $BCM(B == 1 $B$NMWAG?t(B (byte, sint, int $B$N$_(B)
|
204
|
+
self.mask( mask ) self[ mask ] $B$HF1$8$@$+%^%9%-%s%0@lMQ(B.
|
205
|
+
[] $B$H0c$$(B int, sint $B$N%^%9%/$b;H$($k(B.
|
206
|
+
|
207
|
+
$BJ#AG?t(B
|
208
|
+
self.real
|
209
|
+
self.imag
|
210
|
+
self.conj
|
211
|
+
self.angle atan2(self.imag, self.real)
|
212
|
+
self.imag= other $B5u?tItJ,$K(Bother$B$r%;%C%H!#(B
|
213
|
+
self.im $B5u?tG\!#(B
|
214
|
+
|
215
|
+
NMath $B%b%8%e!<%k(B
|
216
|
+
sqrt(x)
|
217
|
+
exp(x)
|
218
|
+
log(x)
|
219
|
+
log10(x)
|
220
|
+
log2(x)
|
221
|
+
atan2(x,y)
|
222
|
+
sin,cos,tan
|
223
|
+
sinh,cosh,tanh
|
224
|
+
asin,acos,atan
|
225
|
+
asinh,acosh,atanh
|
226
|
+
csc,sec,cot
|
227
|
+
csch,sech,coth
|
228
|
+
acsc,asec,acot
|
229
|
+
acsch,asech,acoth
|
230
|
+
covariance
|
231
|
+
|
232
|
+
|
233
|
+
FFTW $B%b%8%e!<%k(B (fftw-2.1.3$B$r(Bshared lib$B$G%3%s%Q%$%k$7$?$b$N$G3NG'(B)
|
234
|
+
($BJL%b%8%e!<%k(B)
|
235
|
+
fftw(x,[1|-1])
|
236
|
+
convol(a,b) FFTW$B$rMQ$$$?>v$_9~$_!#(B
|
237
|
+
|
238
|
+
|
239
|
+
NMatrix
|
240
|
+
|
241
|
+
NArray$B$N%5%V%/%i%9!#:G=i$N(B2$B<!85$r(BMatrix$B$H$7$FMQ$$$k!#(B
|
242
|
+
$B;D$j$N<!85$OB?<!85G[Ns$H$7$F07$o$l$k!#(B
|
243
|
+
$B<!85$N=g=x$O!"?t3X$G$NI=5-$H$O5U(B: a_ij => a[j,i]
|
244
|
+
|
245
|
+
$B%a%=%C%I(B:
|
246
|
+
+,- $BAj<j$,(B NMatrix $B$N$H$-$K1i;;2D!#(B
|
247
|
+
* $BAj<j$,(B NMatrix $B$^$?$O(B NVector $B$N$H$-$O(B Matrix$B@Q!#(B
|
248
|
+
$BAj<j$,(B Numeric $B$^$?$O(B NArray $B$N$H$-$O(B Scalar$B@Q!#(B
|
249
|
+
$BNc(B: NMatrix[[1,2],[3,4]] * [1,10]
|
250
|
+
== NMatrix[ [[1,2],[3,4]], [[10,20],[30,40]] ]
|
251
|
+
/ $BAj<j$,(B Numeric $B$^$?$O(B NArray $B$N$H$-$O(BScalar$B=|;;!#(B
|
252
|
+
$BAj<j$,(B square NMatrix $B$N$H$-$O(BLU$B$K$h$j@~7AJ}Dx<0$r2r$/!#(B
|
253
|
+
a/b == b.lu.solve(a)
|
254
|
+
|
255
|
+
transpose $B0z?t$r>JN,$7$?>l9g$O!":G=i$N(BMatrix$B<!85$r8r49!#(B
|
256
|
+
diagonal(other)
|
257
|
+
diagonal!(other) $BBP3QMWAG$KCM$r%;%C%H!#0z?t>JN,;~$O(B1$B$r%;%C%H!#(B
|
258
|
+
I $BBP3QMWAG$KCM$K(B1$B$r%;%C%H!#(B
|
259
|
+
inverse $B5U9TNs(B
|
260
|
+
lu LU$BJ,2r$r7W;;!#(BNMatrixLU $B%/%i%9$N%$%s%9%?%s%9$rJV$9!#(B
|
261
|
+
|
262
|
+
|
263
|
+
NVector
|
264
|
+
|
265
|
+
NArray$B$N%5%V%/%i%9!#:G=i$N(B1$B<!85$r(BVector$B$H$7$FMQ$$$k!#(B
|
266
|
+
$B;D$j$N<!85$OB?<!85G[Ns$H$7$F07$o$l$k!#(B
|
267
|
+
|
268
|
+
$B%a%=%C%I(B:
|
269
|
+
+,- $BAj<j$,(B NVector $B$N$H$-$K1i;;2D!#(B
|
270
|
+
* $BAj<j$,(B NMatrix $B$N$H$-$O(B Matrix$B@Q!#(B
|
271
|
+
$BAj<j$,(B NVector $B$N$H$-$O(B $BFb@Q!#(B
|
272
|
+
$BAj<j$,(B Numeric $B$^$?$O(B NArray $B$N$H$-$O(B Scalar$B@Q!#(B
|
273
|
+
/ $BAj<j$,(B Numeric $B$^$?$O(B NArray $B$N$H$-$O(B Scalar$B=|;;!#(B
|
274
|
+
$BAj<j$,(B square NMatrix $B$N$H$-$O(BLU$B$K$h$j@~7AJ}Dx<0$r2r$/!#(B
|
275
|
+
v/m == m.lu.solve(v)
|
276
|
+
|
277
|
+
NMatrixLU
|
278
|
+
|
279
|
+
NMatrix#lu $B%a%=%C%I$K$h$j:n$i$l$k!#(B
|
280
|
+
LU (NMatrix) $B$H(B pivot (NVector) $B$r4^$`!#(B
|
281
|
+
|
282
|
+
$B%a%=%C%I(B:
|
283
|
+
solve(other) LU$BJ,2r$N7k2L$r;H$C$F(B other $B$r2r$/!#(B
|
284
|
+
other $B$O(B NMatrix $B$^$?$O(B NVector $B$N%$%s%9%?%s%9!#(B
|