* transcode.c (transcode_restartable): my_transcoder argument removed.
[ruby-svn.git] / benchmark / bm_so_spectralnorm.rb
blob6b9720668913d19899bad3d027510881b154e659
1 # The Computer Language Shootout
2 # http://shootout.alioth.debian.org/
3 # Contributed by Sokolov Yura
5 def eval_A(i,j)
6         return 1.0/((i+j)*(i+j+1)/2+i+1)
7 end
9 def eval_A_times_u(u)
10         v, i = nil, nil
11         (0..u.length-1).collect { |i|
12                 v = 0
13                 for j in 0..u.length-1
14                         v += eval_A(i,j)*u[j]
15                 end
16                 v
17         }
18 end
20 def eval_At_times_u(u)
21         v, i = nil, nil
22         (0..u.length-1).collect{|i|
23                 v = 0
24                 for j in 0..u.length-1
25                         v += eval_A(j,i)*u[j]
26                 end
27                 v
28         }
29 end
31 def eval_AtA_times_u(u)
32         return eval_At_times_u(eval_A_times_u(u))
33 end
35 n = 500 # ARGV[0].to_i
37 u=[1]*n
38 for i in 1..10
39         v=eval_AtA_times_u(u)
40         u=eval_AtA_times_u(v)
41 end
42 vBv=0
43 vv=0
44 for i in 0..n-1
45         vBv += u[i]*v[i]
46         vv += v[i]*v[i]
47 end
49 str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
50 # print str