Fix for JRUBY-2882. Handle error messages related to constructors better
[jruby.git] / bench / shootout / spectralnorm.jruby
blob410a92dfa03cde11fcc72889277dafd4dc48b142
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 = ARGV[0].to_i
36 u=[1]*n
37 for i in 1..10
38         v=eval_AtA_times_u(u)
39         u=eval_AtA_times_u(v)
40 end
41 vBv=0
42 vv=0
43 for i in 0..n-1
44         vBv += u[i]*v[i]
45         vv += v[i]*v[i]
46 end
47 print "%0.9f" % (Math.sqrt(vBv/vv)), "\n"