narray 0.5.9.9 → 0.6.0.0

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/bench/bench.rb DELETED
@@ -1,59 +0,0 @@
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
data/src/bench/dummy.m DELETED
File without changes
data/src/bench/dummy.py DELETED
@@ -1,13 +0,0 @@
1
- import sys
2
-
3
- MODULE = sys.argv[1]
4
-
5
- if MODULE=="numeric":
6
- from Numeric import *
7
- from LinearAlgebra import *
8
- elif MODULE=="numarray":
9
- from numarray import *
10
- from LinearAlgebra import *
11
- elif MODULE=="numpy":
12
- from numpy import *
13
- from numpy.linalg import solve
data/src/bench/dummy.rb DELETED
File without changes
@@ -1,22 +0,0 @@
1
- require "narray"
2
- include NMath
3
-
4
- x = NArray[65, 63, 67, 64, 68, 62, 70, 66, 68, 67, 69, 71]
5
- y = NArray[68, 66, 68, 65, 69, 66, 68, 65, 71, 67, 68, 70]
6
-
7
- def test str, x, y=nil
8
- print str," #=> "
9
- p eval(str)
10
- end
11
-
12
- test "x",x,y
13
- test "y",x,y
14
- test "covariance(x,y)",x,y
15
-
16
- a = covariance(x,y)
17
-
18
- test "x.stddev",x
19
-
20
- test "x.sort",x
21
- test "x.median",x
22
- test "(x+y.newrank!(0)).median(0)",x,y
@@ -1,20 +0,0 @@
1
- require 'narray'
2
-
3
- a = NArray.float(3,3).indgen
4
-
5
- p NArray[a,[100,101]]
6
-
7
- b = NArray[ [ [ 0.0, 1.0, 2.0 ],
8
- [ 3.0, 4.0, 5.0 ],
9
- [ 6.0, 7.0, 8.0 ] ],
10
- [100,101] ]
11
- p b
12
-
13
- a = NArray.float(2,2).indgen
14
-
15
- b = NArray[ a,[a] ]
16
- p b
17
-
18
- b = NArray[ [ 0.0, 1.0 ],
19
- [ [ 0.0, 1.0 ] ] ]
20
- p b
data/src/test/testbit.rb DELETED
@@ -1,27 +0,0 @@
1
- require "narray"
2
-
3
- a = NArray.byte(10).indgen!
4
-
5
- def test a, str
6
- print str," #=>\n"
7
- p eval(str)
8
- end
9
-
10
- test a, "a"
11
- test a, "a & 1"
12
- test a, "a & 2"
13
- test a, "a & -1"
14
-
15
- test a, "a | 1"
16
- test a, "a | 2"
17
- test a, "a | -1"
18
-
19
- test a, "a ^ 1"
20
- test a, "a ^ 2"
21
- test a, "a ^ -1"
22
-
23
- test a, "~a"
24
-
25
- a = NArray.int(10).indgen!
26
- test a, "a"
27
- test a, "~a"
data/src/test/testcast.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'narray'
2
-
3
- def test a,b
4
- print a," #=> "
5
- p b
6
- end
7
-
8
- a = NArray.int(3,3).indgen!
9
-
10
- test "a",a
11
- test "a+1.5",a+1.5
12
- test "1.5+a",1.5+a
13
- test "a+NArray[1.2,3.4,5.6]",a+NArray[1.2,3.4,5.6]
14
- test "a+NArray[Complex(0.5,1.5)]",a+NArray[Complex(0.5,1.5)]
@@ -1,35 +0,0 @@
1
- require 'narray'
2
-
3
- def testop(a,b)
4
- print "a = "; p a
5
- print "b = "; p b
6
- print "a+b = "; p a+b
7
- print "a-b = "; p a-b
8
- print "a*b = "; p a*b
9
- print "a/b = "; p a/b
10
- print "a**b = "; p a**b
11
- end
12
-
13
- a = NArray.complex(4,1).indgen!.sbt!(-1) + 0.25.im
14
- b = NArray.complex(1,3).indgen!.add!(-0.5).mul!(0.5.im)
15
- testop(a,b)
16
-
17
- # compare a/b with real-number operation
18
- # a = NArray(4,1).indgen!.sbt!(-1)
19
- # b = NArray(1,3).fill!(1)
20
- # c = b*b + b*b
21
- # p ( (a*b + 0*b)/c )
22
- # p ( (0*b - a*b)/c )
23
-
24
- def testimag(a)
25
- print "a.real = "
26
- p a.real
27
- print "a.imag = "
28
- p a.imag
29
- print "a.angle = "
30
- p a.angle
31
- print "a.conj = "
32
- p a.conj
33
- end
34
-
35
- testimag a
data/src/test/testfftw.rb DELETED
@@ -1,16 +0,0 @@
1
- require 'narray'
2
-
3
- x = NArray.complex(1024,1024).indgen!
4
-
5
- p x
6
- puts 'executing fftw ...'
7
- t1 = Time.times.utime
8
- y = FFTW.fftw( x, 1 )
9
- t2 = Time.times.utime
10
- print "time: ",t2 - t1,"\n"
11
- p y
12
-
13
- exit
14
-
15
- x = NArray.complex(128,128).indgen!
16
- 10000.times{ x = FFTW.fftw( x, 1 ) }
@@ -1,11 +0,0 @@
1
- require 'narray'
2
-
3
- a = NArray.float(3,3).indgen!
4
-
5
- print "a #=> "; p a
6
- print "a[1, -1] #=> "; p a[1, -1]
7
- print "a[1, 2..0] #=> "; p a[1, 2..0]
8
- print "a[1...2, 0..1] #=> "; p a[1...2, 0..1] # without rank-reduce
9
- print "a[true, 0..1] #=> "; p a[true, 0..1]
10
- print "a[0..5] #=> "; p a[0..5]
11
-
@@ -1,26 +0,0 @@
1
- require 'narray'
2
-
3
- a = NArray.new(NArray::DFLOAT,5,5).indgen!
4
- print "a #=> "; p a
5
-
6
- idx = [2,0,1]
7
- print "\nidx #=> "
8
- p idx
9
-
10
- print "\na[idx,idx] # Index Array\n #=> "
11
- p a[idx,idx]
12
-
13
- idx = NArray.to_na(idx)
14
- idx += 10
15
- print "\nidx #=> "
16
- p idx
17
-
18
- print "\na[idx] #=> "
19
- p a[idx]
20
-
21
- print "\na[1,[]] # Empty Array\n #=> "
22
- p a[1,[]]
23
-
24
- print "\nFollowing will fail...\n\n"
25
- print "a[idx,0] #=> \n"
26
- p a[idx,0]
@@ -1,55 +0,0 @@
1
- require 'narray'
2
-
3
- a = NArray.float(3,3).indgen!
4
-
5
- print "a #=> "; p a
6
-
7
- print "\na[[]] = [] # Do nothing \na #=> ";
8
- a[[]] = []; p a
9
-
10
- print "\na[1,1] = 0 # 1-element replace\na #=> ";
11
- b=a.dup; b[1,1] = 0
12
- p b
13
-
14
- print "\na[0..-1, 1] = 0 # Range replace\na #=> ";
15
- b=a.dup; b[0..-1, 1] = 0
16
- p b
17
-
18
- print "\na[1,2..0] = [100,101,102] # Array replace\na #=> ";
19
- b=a.dup; b[1,2..0] = [100,101,102]
20
- p b
21
-
22
- print "\na[0,1] = [100,101,102] # Specifing Starting point \na #=> ";
23
- b=a.dup; b[0,1] = [100,101,102]
24
- p b
25
-
26
- print "\na[1,0] = [[100],[101],[102]] # Specifing Starting point \na #=> ";
27
- b=a.dup; b[1,0] = [[100],[101],[102]]
28
- p b
29
-
30
- print "\na[true,1] = [100,101,102] # `true' means entire range\na #=> ";
31
- b=a.dup; b[true,1] = [100,101,102]
32
- p b
33
-
34
- print "\na[true,true] = [[100,101,102]] \na #=> ";
35
- b=a.dup; b[true,true] = [[100,101,102]]
36
- p b
37
-
38
-
39
- print "\nFollowing will fail ...\n"
40
-
41
- print "\na[true,1] = [[100,101,102]] \na #=> ";
42
- b=a.dup; b[true,1] = [[100,101,102]]
43
- p b
44
-
45
- print "\na[true,1] = [[100],[101],[102]] \na #=> ";
46
- b=a.dup; b[true,1] = [[100],[101],[102]]
47
- p b
48
-
49
- print "\na[true,true] = [100,101,102] \na #=> ";
50
- b=a.dup; b[true,true] = [100,101,102]
51
- p b
52
-
53
- print "\na[1,0] = [100,101,102] \na #=> ";
54
- b=a.dup; b[1,0] = [100,101,102]
55
- p b
data/src/test/testmask.rb DELETED
@@ -1,40 +0,0 @@
1
- require "narray"
2
-
3
- a = NArray.byte(10)
4
- a[2..4] = 1
5
- p a.class, a.count_true, a.count_false
6
-
7
- begin
8
- a = NArray.float(10)
9
- a[2..4] = 1
10
- p a.class, a.count_true, a.count_false
11
- rescue
12
- print a.class," -- Exception raised as expected. The message was: ", $!,"\n"
13
- end
14
-
15
- #-------------------
16
- print "\n--- test masking (float) ---\n"
17
-
18
- a = NArray.float(5,3).indgen!
19
- b = (a-2)*2
20
- c = a.lt(b)
21
- p c, c.typecode
22
-
23
- p a, b, a.mask( c ), a[c]
24
-
25
- #a[c] = ( NArray.int(c.length).indgen!+100 )
26
- #p a
27
-
28
- a[c] = 10000
29
- p a
30
-
31
- #-------------------
32
- print "\n--- test masking (complex) ---\n"
33
- p a = NArray.complex(5).indgen! + Complex::I
34
-
35
- m = NArray.byte(5)
36
- m[true] = [0,0,1,1,0]
37
-
38
- p a[m]
39
- a[m] = 100.0
40
- p a
data/src/test/testmath.rb DELETED
@@ -1,48 +0,0 @@
1
- require 'narray'
2
- include NMath
3
-
4
- def pr x
5
- x.each{|i|
6
- if i.kind_of?(Complex)
7
- printf("%.3f%+.3fi ",i.real,i.image)
8
- else
9
- printf("%.3f ",i)
10
- end
11
- }
12
- print "\n"
13
- end
14
-
15
- def testmath(x)
16
- print "x = "
17
- pr x
18
- print "sqrt(x) = "
19
- pr sqrt(x)
20
- print "sin(x) = "
21
- pr sin(x)
22
- print "cos(x) = "
23
- pr cos(x)
24
- print "tan(x) = "
25
- pr tan(x)
26
- print "sinh(x) = "
27
- pr sinh(x)
28
- print "cosh(x) = "
29
- pr cosh(x)
30
- print "tanh(x) = "
31
- pr tanh(x)
32
- print "exp(x) = "
33
- pr exp(x)
34
- print "log(x) = "
35
- pr log(x)
36
- print "log10(x) = "
37
- pr log10(x)
38
- print "atan(x) = "
39
- pr atan(x)
40
- print "atan(tan(x)) = "
41
- pr atan(tan(x))
42
- end
43
-
44
- testmath NArray.sfloat(6).indgen.div!(2)
45
- testmath NArray.float(6).indgen.div!(2)
46
-
47
- testmath NArray.scomplex(6).indgen.div!(2)-2 - 1.im
48
- testmath NArray.complex(6).indgen!/5-0.5# - 0.3.im
@@ -1,46 +0,0 @@
1
- require "narray"
2
- include NMath
3
-
4
- def testm x,name
5
- f = "a#{name}(#{name}(x))"
6
- print "\n### #{f} ###\n"
7
- y = eval(f)
8
- p y
9
- #d = x-y
10
- #p d.abs
11
- end
12
-
13
- PI=Math::PI
14
-
15
- i = NArray.complex(1)
16
- i.imag=1
17
-
18
- n=7
19
- x = NArray.complex(n).random!(1)
20
- x.imag= NArray.float(n).random!(1)
21
-
22
- p x
23
- testm x,"sin"
24
- testm x,"cos"
25
- testm x,"tan"
26
- testm x,"sinh"
27
- testm x,"cosh"
28
- testm x,"tanh"
29
- testm x,"sec"
30
- testm x,"sech"
31
-
32
- p cot(1)
33
-
34
- exit
35
-
36
- a= -i * log( sqrt(1-x**2)*i + x )
37
- b= -i * log( sqrt(x**2-1) + x )
38
- p a
39
- p b
40
- p a-b
41
-
42
- a= -i * log( sqrt(1-x**2) + x*i )
43
- b= -i * log( (-sqrt(x**2-1) + x)*i )
44
- p a
45
- p b
46
- p a-b