narray 0.5.9.4 → 0.5.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/src/ChangeLog +29 -0
- data/src/MANIFEST +7 -36
- data/src/README.en +1 -5
- data/src/README.ja +1 -2
- data/src/SPEC.en +15 -8
- data/src/SPEC.ja +5 -2
- data/src/bench/all.rb +88 -0
- data/src/bench/bench.m +61 -0
- data/src/bench/bench.py +89 -0
- data/src/bench/bench.rb +59 -0
- data/src/bench/dummy.m +0 -0
- data/src/bench/dummy.py +13 -0
- data/src/bench/dummy.rb +0 -0
- data/src/lib/narray_ext.rb +36 -2
- data/src/mkmath.rb +4 -4
- data/src/mkop.rb +16 -16
- data/src/na_array.c +32 -32
- data/src/na_func.c +50 -50
- data/src/na_index.c +26 -32
- data/src/na_linalg.c +23 -26
- data/src/na_random.c +15 -18
- data/src/narray.c +22 -32
- data/src/narray.h +3 -3
- data/src/narray_local.h +1 -1
- metadata +10 -39
- data/src/nimage/README.en +0 -38
- data/src/nimage/demo/fits.rb +0 -97
- data/src/nimage/demo/fits_convol.rb +0 -28
- data/src/nimage/demo/fits_fftdemo.rb +0 -27
- data/src/nimage/demo/fitsdemo1.rb +0 -13
- data/src/nimage/demo/fitsdemo2.rb +0 -30
- data/src/nimage/demo/fitsdemo3.rb +0 -26
- data/src/nimage/demo/fitsmorph.rb +0 -39
- data/src/nimage/demo/life_na.rb +0 -57
- data/src/nimage/demo/mandel.rb +0 -41
- data/src/nimage/extconf.rb +0 -12
- data/src/nimage/lib/nimage.rb +0 -51
- data/src/nimage/nimage.c +0 -328
- data/src/speed/add.py +0 -12
- data/src/speed/add.rb +0 -8
- data/src/speed/add_int.py +0 -12
- data/src/speed/add_int.rb +0 -9
- data/src/speed/lu.m +0 -14
- data/src/speed/lu.rb +0 -22
- data/src/speed/mat.m +0 -23
- data/src/speed/mat.rb +0 -28
- data/src/speed/mul.py +0 -12
- data/src/speed/mul.rb +0 -9
- data/src/speed/mul2.py +0 -15
- data/src/speed/mul2.rb +0 -13
- data/src/speed/mul_comp.py +0 -12
- data/src/speed/mul_comp.rb +0 -9
- data/src/speed/mul_int.py +0 -12
- data/src/speed/mul_int.rb +0 -9
- data/src/speed/mybench.py +0 -15
- data/src/speed/mybench.rb +0 -31
- data/src/speed/solve.m +0 -18
- data/src/speed/solve.py +0 -16
- data/src/speed/solve.rb +0 -21
data/src/ChangeLog
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
2008-06-10 Masahiro TANAKA <masa16.tanaka at gmail.com>
|
2
|
+
|
3
|
+
* bench/: new sophisticated benchmark script.
|
4
|
+
|
5
|
+
* ver 0.5.9p5
|
6
|
+
|
7
|
+
2008-05-27 Jose M <braket at hotmai...>
|
8
|
+
|
9
|
+
* na_array.c, na_index.c, na_random.c, na_func.c:
|
10
|
+
* na_linalg.c, narray.c, mkmath.rb, mkop.rb:
|
11
|
+
change var++ to ++var: make NArray perform faster.
|
12
|
+
|
13
|
+
2008-05-24 Hiroki Motoyoshi <himotoyoshi at yahoo.co...>
|
14
|
+
|
15
|
+
* mkmath.rb:
|
16
|
+
fix bug in powOO.
|
17
|
+
|
18
|
+
2008-04-02 David MacMahon <davidm at astro.berkeley...>
|
19
|
+
|
20
|
+
* na_func.c:
|
21
|
+
new methods: conj!, conjugate!
|
22
|
+
|
23
|
+
2008-01-11 David MacMahon <davidm at astro.berkeley...>
|
24
|
+
|
25
|
+
* lib/narray_ext.rb (stddev):
|
26
|
+
fix for complex NArrays.
|
27
|
+
* lib/narray_ext.rb (rms, rmsdev):
|
28
|
+
new methods.
|
29
|
+
|
1
30
|
2008-01-28 Masahiro TANAKA <masa16.tanaka at gmail.com>
|
2
31
|
|
3
32
|
* na_array.c (na_range_to_sequence, na_do_mdai):
|
data/src/MANIFEST
CHANGED
@@ -20,42 +20,6 @@ narray.h
|
|
20
20
|
narray_local.h
|
21
21
|
lib/narray_ext.rb
|
22
22
|
lib/nmatrix.rb
|
23
|
-
nimage/README.en
|
24
|
-
nimage/extconf.rb
|
25
|
-
nimage/nimage.c
|
26
|
-
nimage/demo
|
27
|
-
nimage/demo/fits.rb
|
28
|
-
nimage/demo/fits_convol.rb
|
29
|
-
nimage/demo/fits_fftdemo.rb
|
30
|
-
nimage/demo/fitsdemo1.rb
|
31
|
-
nimage/demo/fitsdemo2.rb
|
32
|
-
nimage/demo/fitsdemo3.rb
|
33
|
-
nimage/demo/fitsmorph.rb
|
34
|
-
nimage/demo/life_na.rb
|
35
|
-
nimage/demo/mandel.rb
|
36
|
-
nimage/lib
|
37
|
-
nimage/lib/nimage.rb
|
38
|
-
speed/add.py
|
39
|
-
speed/add.rb
|
40
|
-
speed/add_int.py
|
41
|
-
speed/add_int.rb
|
42
|
-
speed/lu.m
|
43
|
-
speed/lu.rb
|
44
|
-
speed/mat.m
|
45
|
-
speed/mat.rb
|
46
|
-
speed/mul.py
|
47
|
-
speed/mul.rb
|
48
|
-
speed/mul2.py
|
49
|
-
speed/mul2.rb
|
50
|
-
speed/mul_comp.py
|
51
|
-
speed/mul_comp.rb
|
52
|
-
speed/mul_int.py
|
53
|
-
speed/mul_int.rb
|
54
|
-
speed/mybench.py
|
55
|
-
speed/mybench.rb
|
56
|
-
speed/solve.m
|
57
|
-
speed/solve.py
|
58
|
-
speed/solve.rb
|
59
23
|
test/statistics.rb
|
60
24
|
test/testarray.rb
|
61
25
|
test/testbit.rb
|
@@ -80,3 +44,10 @@ test/testsort.rb
|
|
80
44
|
test/teststr.rb
|
81
45
|
test/testtrans.rb
|
82
46
|
test/testwhere.rb
|
47
|
+
bench/all.rb
|
48
|
+
bench/bench.m
|
49
|
+
bench/bench.py
|
50
|
+
bench/bench.rb
|
51
|
+
bench/dummy.m
|
52
|
+
bench/dummy.py
|
53
|
+
bench/dummy.rb
|
data/src/README.en
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
using assignment with number, range, array index.
|
10
10
|
+ Operator: +,-,*,/,%,**, etc.
|
11
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
12
|
+ NImage: Image viewer class.
|
14
13
|
+ Ruby/PGPLOT: Graphics library interface (separately distributed)
|
15
14
|
X-Y Graph, Histogram, Contour map, Image map, etc.
|
@@ -27,9 +26,6 @@
|
|
27
26
|
|
28
27
|
* Installation
|
29
28
|
|
30
|
-
+ If you want to use FFTW, install it.
|
31
|
-
http://www.fftw.org/ or http://www.netlib.org/
|
32
|
-
|
33
29
|
+ Compile & Install NArray
|
34
30
|
|
35
31
|
ruby extconf.rb
|
@@ -51,4 +47,4 @@
|
|
51
47
|
|
52
48
|
* Author
|
53
49
|
|
54
|
-
Masahiro TANAKA <
|
50
|
+
Masahiro TANAKA <masa16.tanaka@gmail.com>
|
data/src/README.ja
CHANGED
@@ -12,7 +12,6 @@
|
|
12
12
|
$B$?$@$7!"%5%$%:$,(B1$B$N<!85$O!"B>J}$NG[Ns$N%5%$%:$K9g$o$;$F(B
|
13
13
|
$B!V7+$jJV$7!WF1$8MWAG$,E,MQ$5$l$k!#(B
|
14
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
15
|
+ NImage (X11$B%$%a!<%8I=<((B) $B%/%i%9ImB0!#(B(nimage/ $B%G%#%l%/%H%j;2>H(B)
|
17
16
|
+ Ruby/PGPLOT ($B%0%i%U%#%C%/%9%i%$%V%i%j!"JLW}(B) $B$K$F(B
|
18
17
|
XY$B%0%i%U!"%R%9%H%0%i%`!"Ey9b@~!"%$%a!<%8I=<(2DG=!#(B
|
@@ -51,7 +50,7 @@
|
|
51
50
|
* $BCx<T(B
|
52
51
|
|
53
52
|
$BEDCf>;9((B
|
54
|
-
$B$40U8+!$%P%0%l%]!<%H$=$NB>$O(B
|
53
|
+
$B$40U8+!$%P%0%l%]!<%H$=$NB>$O(B masa16.tanaka@gmail.com $B$^$G$*4j$$$7$^$9!#(B
|
55
54
|
|
56
55
|
* $B<U<-(B
|
57
56
|
|
data/src/SPEC.en
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Ruby/NArray ver 0.5.
|
2
|
+
Ruby/NArray ver 0.5.9p5 (2008-05-28) by Masahiro TANAKA
|
3
3
|
|
4
4
|
|
5
5
|
Class method:
|
@@ -157,16 +157,22 @@ Comparison
|
|
157
157
|
e.g.: idx_t,idx_f = (a>12).where2
|
158
158
|
|
159
159
|
Statistics
|
160
|
-
self.sum(dim,..) Summation
|
161
|
-
self.mean(dim,..) Mean
|
162
|
-
self.stddev(dim,..) Standard deviation
|
163
|
-
self.
|
164
|
-
self.
|
165
|
-
|
160
|
+
self.sum(dim,..) Summation
|
161
|
+
self.mean(dim,..) Mean
|
162
|
+
self.stddev(dim,..) Standard deviation
|
163
|
+
self.rms(dim,..) Root mean square
|
164
|
+
self.rmsdev(dim,..) Root mean square deviation
|
165
|
+
self.min(dim,..) Minimum
|
166
|
+
self.max(dim,..) Maximum
|
167
|
+
note: * If dimensions are specified, statistics are performed
|
168
|
+
on those dimensions and the rest dimensions are kept.
|
169
|
+
* Range can be used.
|
170
|
+
* If dimension is not specified, statistics are performed
|
171
|
+
for all the elements.
|
166
172
|
self.median(dim) Median in 0..dim (All dimensions if omitted)
|
167
173
|
|
168
174
|
Sort
|
169
|
-
self.sort(dim) Sort in
|
175
|
+
self.sort(dim) Sort in 0..dim (All dimensions if omitted)
|
170
176
|
self.sort_index(dim) Return index of Sort result.
|
171
177
|
self[self.sort_index] equals to self.sort.
|
172
178
|
|
@@ -222,6 +228,7 @@ Complex compound number
|
|
222
228
|
self.real
|
223
229
|
self.imag
|
224
230
|
self.conj
|
231
|
+
self.conj!
|
225
232
|
self.angle atan2(self.imag, self.real)
|
226
233
|
self.imag= other set imaginary part
|
227
234
|
self.im multiply by imaginary unit
|
data/src/SPEC.ja
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Ruby/NArray ver 0.5.
|
2
|
+
Ruby/NArray ver 0.5.9p5 (2008-05-28) by Masahiro TANAKA
|
3
3
|
|
4
4
|
|
5
5
|
$B%/%i%9%a%=%C%I(B:
|
@@ -149,7 +149,9 @@
|
|
149
149
|
$BE}7W(B
|
150
150
|
self.sum(dim,..) $B;XDj$7$?<!85$NOB!#(B
|
151
151
|
self.mean(dim,..) $B;XDj$7$?<!85$NJ?6Q!#(B
|
152
|
-
self.stddev(dim,..) $B;XDj$7$?<!85$NI8=`JP:9!#(B
|
152
|
+
self.stddev(dim,..) $B;XDj$7$?<!85$NI8=`JP:9(B($BI8K\I8=`JP:9(B)$B!#(B
|
153
|
+
self.rms(dim,..) $B;XDj$7$?<!85$N(Broot mean square$B!#(B
|
154
|
+
self.rmsdev(dim,..) $B;XDj$7$?<!85$N(Broot mean square deviation$B!#(B
|
153
155
|
self.min(dim,..) $B;XDj$7$?<!85$N:G>.!#(B
|
154
156
|
self.max(dim,..) $B;XDj$7$?<!85$N:GBg!#(B
|
155
157
|
($B>JN,;~$OA4$F$N<!85!#(BRange$B;XDj2D!#(B)
|
@@ -208,6 +210,7 @@ Boolean / $B%^%9%/4X78(B
|
|
208
210
|
self.real
|
209
211
|
self.imag
|
210
212
|
self.conj
|
213
|
+
self.conj!
|
211
214
|
self.angle atan2(self.imag, self.real)
|
212
215
|
self.imag= other $B5u?tItJ,$K(Bother$B$r%;%C%H!#(B
|
213
216
|
self.im $B5u?tG\!#(B
|
data/src/bench/all.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require "narray"
|
2
|
+
T = (RUBY_VERSION<"1.8.0") ? Time : Process
|
3
|
+
|
4
|
+
ruby_narray = system( "ruby -r narray dummy.rb" )
|
5
|
+
python_numeric = system( "python dummy.py numeric" )
|
6
|
+
python_numarray = system( "python dummy.py numarray" )
|
7
|
+
python_numpy = system( "python dummy.py numpy" )
|
8
|
+
octave = system( "octave -qf dummy.m" )
|
9
|
+
|
10
|
+
def array_size
|
11
|
+
list = [
|
12
|
+
100000, 200000, 500000,
|
13
|
+
1000000, 2000000, 5000000,
|
14
|
+
10000000, 20000000, 50000000
|
15
|
+
]
|
16
|
+
mlist = [
|
17
|
+
150, 200, 300, 500, 700, 1000, 1500, 2000, 3000
|
18
|
+
#300, 400, 700, 1000, 1400, 2000, 3000, 4000, 7000
|
19
|
+
]
|
20
|
+
|
21
|
+
r = 50
|
22
|
+
n = nil
|
23
|
+
i = nil
|
24
|
+
list.each_with_index do |n,i|
|
25
|
+
a = NArray.float(n)
|
26
|
+
b = NArray.float(n)
|
27
|
+
t = bench_time(r) { c = a+b }
|
28
|
+
break if t>0.5
|
29
|
+
end
|
30
|
+
[n, mlist[i], r*2]
|
31
|
+
end
|
32
|
+
|
33
|
+
def bench_time(n)
|
34
|
+
t1 = T.times.utime
|
35
|
+
for i in 1..n
|
36
|
+
yield
|
37
|
+
end
|
38
|
+
t = T.times.utime - t1
|
39
|
+
puts " Time: %.2f sec\n" % [t]
|
40
|
+
t
|
41
|
+
end
|
42
|
+
|
43
|
+
n,m,r = array_size
|
44
|
+
puts "array size = #{n}, repeat = #{r}\n\n"
|
45
|
+
|
46
|
+
system "ruby bench.rb float mul #{n} #{r}" if ruby_narray
|
47
|
+
system "python bench.py numeric float mul #{n} #{r}" if python_numeric
|
48
|
+
system "python bench.py numarray float mul #{n} #{r}" if python_numarray
|
49
|
+
system "python bench.py numpy float mul #{n} #{r}" if python_numpy
|
50
|
+
system "octave -qf bench.m float mul #{n} #{r}" if octave
|
51
|
+
puts
|
52
|
+
|
53
|
+
system "ruby bench.rb int add #{n} #{r}" if ruby_narray
|
54
|
+
system "python bench.py numeric int add #{n} #{r}" if python_numeric
|
55
|
+
system "python bench.py numarray int add #{n} #{r}" if python_numarray
|
56
|
+
system "python bench.py numpy int add #{n} #{r}" if python_numpy
|
57
|
+
system "octave -qf bench.m int add #{n} #{r}" if octave
|
58
|
+
puts
|
59
|
+
|
60
|
+
system "ruby bench.rb complex mul #{n} #{r}" if ruby_narray
|
61
|
+
system "python bench.py numeric complex mul #{n} #{r}" if python_numeric
|
62
|
+
system "python bench.py numarray complex mul #{n} #{r}" if python_numarray
|
63
|
+
system "python bench.py numpy complex mul #{n} #{r}" if python_numpy
|
64
|
+
system "octave -qf bench.m complex mul #{n} #{r}" if octave
|
65
|
+
puts
|
66
|
+
|
67
|
+
system "ruby bench.rb float_cross mul #{m*2} #{r}" if ruby_narray
|
68
|
+
system "python bench.py numeric float_cross mul #{m*2} #{r}" if python_numeric
|
69
|
+
system "python bench.py numarray float_cross mul #{m*2} #{r}" if python_numarray
|
70
|
+
system "python bench.py numpy float_cross mul #{m*2} #{r}" if python_numpy
|
71
|
+
system "octave -qf bench.m float_cross matmul #{m*2} #{r}" if octave
|
72
|
+
puts
|
73
|
+
|
74
|
+
system "ruby bench.rb float_matrix mul #{m} 4" if ruby_narray
|
75
|
+
system "python bench.py numeric float_matrix matmul #{m} 4" if python_numeric
|
76
|
+
system "python bench.py numarray float_matrix matmul #{m} 4" if python_numarray
|
77
|
+
system "python bench.py numpy float_matrix matmul #{m} 4" if python_numpy
|
78
|
+
system "octave -qf bench.m float_matrix matmul #{m} 4" if octave
|
79
|
+
puts
|
80
|
+
|
81
|
+
system "ruby bench.rb float_solve solve #{m} 2" if ruby_narray
|
82
|
+
system "python bench.py numeric float_solve solve #{m} 2" if python_numeric
|
83
|
+
system "python bench.py numarray float_solve solve #{m} 2" if python_numarray
|
84
|
+
system "python bench.py numpy float_solve solve #{m} 2" if python_numpy
|
85
|
+
system "octave -qf bench.m float_solve solve #{m} 2" if octave
|
86
|
+
puts
|
87
|
+
|
88
|
+
exit
|
data/src/bench/bench.m
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#! /bin/octave -qf
|
2
|
+
|
3
|
+
arg_list = argv();
|
4
|
+
TYPE = arg_list{1};
|
5
|
+
OP = arg_list{2};
|
6
|
+
ARRSZ = str2num(arg_list{3});
|
7
|
+
REPEAT = str2num(arg_list{4});
|
8
|
+
n = ARRSZ;
|
9
|
+
|
10
|
+
switch(TYPE)
|
11
|
+
case "float"
|
12
|
+
a = linspace(0,n-1,n);
|
13
|
+
b = linspace(0,n-1,n);
|
14
|
+
case "int"
|
15
|
+
a = int32(linspace(0,n-1,n));
|
16
|
+
b = int32(linspace(0,n-1,n));
|
17
|
+
case "complex"
|
18
|
+
a = complex(linspace(0,n-1,n));
|
19
|
+
b = complex(linspace(0,n-1,n));
|
20
|
+
case "float_cross"
|
21
|
+
a = linspace(0,n-1,n)';
|
22
|
+
b = linspace(0,n-1,n);
|
23
|
+
case "float_matrix"
|
24
|
+
a = linspace(0,n*n-1,n*n);
|
25
|
+
a = rem(a, n+1) + 1;
|
26
|
+
a = reshape(a,n,n);
|
27
|
+
b = linspace(0,n*n-1,n*n);
|
28
|
+
b = rem(b, n-1) + 1;
|
29
|
+
b = reshape(b,n,n);
|
30
|
+
case "float_solve"
|
31
|
+
a = linspace(0,n*n-1,n*n);
|
32
|
+
a = rem(a, n+1) + 1;
|
33
|
+
a = reshape(a,n,n);
|
34
|
+
b = reshape(linspace(1,n*n,n*n),n,n);
|
35
|
+
endswitch
|
36
|
+
|
37
|
+
[t1, u1, s1] = cputime ();
|
38
|
+
switch(OP)
|
39
|
+
case "add"
|
40
|
+
for i = 1:REPEAT
|
41
|
+
c = a + b;
|
42
|
+
endfor
|
43
|
+
case "mul"
|
44
|
+
for i = 1:REPEAT
|
45
|
+
c = a .* b;
|
46
|
+
endfor
|
47
|
+
case "matmul"
|
48
|
+
for i = 1:REPEAT
|
49
|
+
c = a * b;
|
50
|
+
endfor
|
51
|
+
#size(c)
|
52
|
+
case "solve"
|
53
|
+
for i = 1:REPEAT
|
54
|
+
c = a \ b;
|
55
|
+
endfor
|
56
|
+
#size(c)
|
57
|
+
endswitch
|
58
|
+
[t2, u2, s2] = cputime ();
|
59
|
+
|
60
|
+
printf ("Octave type=%s size=%d op=%s repeat=%d Time: %.2f sec",
|
61
|
+
TYPE,ARRSZ,OP,REPEAT,u2 - u1);
|
data/src/bench/bench.py
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
import time
|
2
|
+
import sys
|
3
|
+
|
4
|
+
MODULE = sys.argv[1]
|
5
|
+
TYPE = sys.argv[2]
|
6
|
+
OP = sys.argv[3]
|
7
|
+
ARRSZ = int(sys.argv[4])
|
8
|
+
REPEAT = int(sys.argv[5])
|
9
|
+
|
10
|
+
if MODULE=="numeric":
|
11
|
+
from Numeric import *
|
12
|
+
from LinearAlgebra import *
|
13
|
+
elif MODULE=="numarray":
|
14
|
+
from numarray import *
|
15
|
+
from LinearAlgebra import *
|
16
|
+
elif MODULE=="numpy":
|
17
|
+
from numpy import *
|
18
|
+
from numpy.linalg import solve
|
19
|
+
|
20
|
+
def bench_time(func,repeat=REPEAT):
|
21
|
+
start = time.clock()
|
22
|
+
for i in range(repeat):
|
23
|
+
c = func()
|
24
|
+
stop = time.clock()
|
25
|
+
print "Python %s type=%s size=%d op=%s repeat=%d Time: %.2f sec" % \
|
26
|
+
(MODULE,TYPE,ARRSZ,OP,REPEAT,stop-start)
|
27
|
+
#print shape(c)
|
28
|
+
|
29
|
+
n = ARRSZ
|
30
|
+
|
31
|
+
if MODULE=="numpy":
|
32
|
+
def bench_array(type=float):
|
33
|
+
return arange(ARRSZ,dtype=type)
|
34
|
+
|
35
|
+
if TYPE=="float":
|
36
|
+
a = bench_array(float)
|
37
|
+
b = bench_array(float)
|
38
|
+
elif TYPE=="int":
|
39
|
+
a = bench_array(int)
|
40
|
+
b = bench_array(int)
|
41
|
+
elif TYPE=="complex":
|
42
|
+
a = bench_array(complex)
|
43
|
+
b = bench_array(complex)
|
44
|
+
elif TYPE=="float_cross":
|
45
|
+
a = reshape(arange(ARRSZ,dtype=float),(ARRSZ,1))
|
46
|
+
b = reshape(arange(ARRSZ,dtype=float),(1,ARRSZ))
|
47
|
+
elif TYPE=="float_matrix":
|
48
|
+
a = reshape(arange(ARRSZ**2,dtype=float),(ARRSZ,ARRSZ))
|
49
|
+
b = reshape(arange(ARRSZ**2,dtype=float),(ARRSZ,ARRSZ))
|
50
|
+
elif TYPE=="float_solve":
|
51
|
+
a = reshape(arange(n**2,dtype=float)%(n+1)+1,(n,n))
|
52
|
+
b = reshape(arange(n**2,dtype=float)+1,(n,n))
|
53
|
+
else:
|
54
|
+
def bench_array(type=float):
|
55
|
+
return arrayrange(ARRSZ).astype(type)
|
56
|
+
if TYPE=="float":
|
57
|
+
a = bench_array(Float64)
|
58
|
+
b = bench_array(Float64)
|
59
|
+
elif TYPE=="int":
|
60
|
+
a = bench_array(Int32)
|
61
|
+
b = bench_array(Int32)
|
62
|
+
elif TYPE=="complex":
|
63
|
+
a = bench_array(Complex64)
|
64
|
+
b = bench_array(Complex64)
|
65
|
+
elif TYPE=="float_cross":
|
66
|
+
a = reshape(arrayrange(ARRSZ),(ARRSZ,1)).astype(Float64)
|
67
|
+
b = reshape(arrayrange(ARRSZ),(1,ARRSZ)).astype(Float64)
|
68
|
+
elif TYPE=="float_matrix":
|
69
|
+
a = reshape(arrayrange(ARRSZ**2),(ARRSZ,ARRSZ)).astype(Float64)
|
70
|
+
b = reshape(arrayrange(ARRSZ**2),(ARRSZ,ARRSZ)).astype(Float64)
|
71
|
+
elif TYPE=="float_solve":
|
72
|
+
a = reshape(arrayrange(n*n)%(n+1)+1,(n,n)).astype(Float64)
|
73
|
+
b = reshape(arrayrange(n*n)+1,(n,n)).astype(Float64)
|
74
|
+
dot = matrixmultiply
|
75
|
+
solve = solve_linear_equations
|
76
|
+
|
77
|
+
def lambda_add(a=a,b=b): c = a+b; return c;
|
78
|
+
def lambda_mul(a=a,b=b): c = a*b; return c;
|
79
|
+
def lambda_matmul(a=a,b=b): c = dot(a,b); return c;
|
80
|
+
def lambda_solve(a=a,b=b): c = solve(a,b); return c;
|
81
|
+
|
82
|
+
if OP=="add":
|
83
|
+
bench_time(lambda_add)
|
84
|
+
elif OP=="mul":
|
85
|
+
bench_time(lambda_mul)
|
86
|
+
elif OP=="matmul":
|
87
|
+
bench_time(lambda_matmul)
|
88
|
+
elif OP=="solve":
|
89
|
+
bench_time(lambda_solve)
|
data/src/bench/bench.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'narray'
|
2
|
+
T = (RUBY_VERSION<"1.8.0") ? Time : Process
|
3
|
+
|
4
|
+
TYPE = ARGV[0]
|
5
|
+
OP = ARGV[1]
|
6
|
+
ARRSZ = Integer(ARGV[2])
|
7
|
+
REPEAT = Integer(ARGV[3])
|
8
|
+
|
9
|
+
def bench_array(type=Float)
|
10
|
+
[ NArray.new(type,ARRSZ).indgen!,
|
11
|
+
NArray.new(type,ARRSZ).indgen! ]
|
12
|
+
end
|
13
|
+
|
14
|
+
def bench_time(n=REPEAT)
|
15
|
+
t1 = T.times.utime
|
16
|
+
for i in 1..n
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
t = T.times.utime - t1
|
20
|
+
printf "Ruby NArray type=%s size=%d op=%s repeat=%d Time: %.2f sec\n",
|
21
|
+
TYPE,ARRSZ,OP,REPEAT,t
|
22
|
+
end
|
23
|
+
|
24
|
+
n = ARRSZ
|
25
|
+
|
26
|
+
case TYPE
|
27
|
+
when "float"
|
28
|
+
a,b = bench_array(Float)
|
29
|
+
when "int"
|
30
|
+
a,b = bench_array(Integer)
|
31
|
+
when "complex"
|
32
|
+
a,b = bench_array(Complex)
|
33
|
+
when "float_cross"
|
34
|
+
a = NArray.float(n,1).indgen!
|
35
|
+
b = NArray.float(1,n).indgen!
|
36
|
+
when "float_matrix"
|
37
|
+
a = NArray.float(n,n).indgen!
|
38
|
+
a = a % (n+1) + 1
|
39
|
+
a = NMatrix.ref(a)#.transpose
|
40
|
+
b = NArray.float(n,n).indgen!
|
41
|
+
b = b % (n-1) + 1
|
42
|
+
b = NMatrix.ref(b)#.transpose
|
43
|
+
when "float_solve"
|
44
|
+
a = NMatrix.float(n,n).indgen!(1).transpose
|
45
|
+
b = NArray.float(n,n).indgen!
|
46
|
+
b = b % (n+1) + 1
|
47
|
+
b = NMatrix.ref(b).transpose
|
48
|
+
end
|
49
|
+
|
50
|
+
c = 0
|
51
|
+
|
52
|
+
case OP
|
53
|
+
when "add"
|
54
|
+
bench_time{ c = a+b }
|
55
|
+
when "mul"
|
56
|
+
bench_time{ c = a*b }
|
57
|
+
when "solve"
|
58
|
+
bench_time{ c = a/b }
|
59
|
+
end
|