diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-16 01:30:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-16 01:30:29 +0000 |
commit | 75feee0968c9345e7ffd2bda9835fcd60b4c0880 (patch) | |
tree | fa4216d535d8b5dcc45f39c19c64385172e710bf /benchmark/bm_so_spectralnorm.rb | |
parent | 501407d3af04a2a7c4b4d49168d512fb89327b6b (diff) |
* set eol-style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark/bm_so_spectralnorm.rb')
-rw-r--r-- | benchmark/bm_so_spectralnorm.rb | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/benchmark/bm_so_spectralnorm.rb b/benchmark/bm_so_spectralnorm.rb index 3617da5236..6b97206689 100644 --- a/benchmark/bm_so_spectralnorm.rb +++ b/benchmark/bm_so_spectralnorm.rb @@ -1,50 +1,50 @@ -# The Computer Language Shootout
-# http://shootout.alioth.debian.org/
-# Contributed by Sokolov Yura
-
-def eval_A(i,j)
- return 1.0/((i+j)*(i+j+1)/2+i+1)
-end
-
-def eval_A_times_u(u)
- v, i = nil, nil
- (0..u.length-1).collect { |i|
- v = 0
- for j in 0..u.length-1
- v += eval_A(i,j)*u[j]
- end
- v
- }
-end
-
-def eval_At_times_u(u)
- v, i = nil, nil
- (0..u.length-1).collect{|i|
- v = 0
- for j in 0..u.length-1
- v += eval_A(j,i)*u[j]
- end
- v
- }
-end
-
-def eval_AtA_times_u(u)
- return eval_At_times_u(eval_A_times_u(u))
-end
-
-n = 500 # ARGV[0].to_i
-
-u=[1]*n
-for i in 1..10
- v=eval_AtA_times_u(u)
- u=eval_AtA_times_u(v)
-end
-vBv=0
-vv=0
-for i in 0..n-1
- vBv += u[i]*v[i]
- vv += v[i]*v[i]
-end
-
-str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
-# print str
+# The Computer Language Shootout +# http://shootout.alioth.debian.org/ +# Contributed by Sokolov Yura + +def eval_A(i,j) + return 1.0/((i+j)*(i+j+1)/2+i+1) +end + +def eval_A_times_u(u) + v, i = nil, nil + (0..u.length-1).collect { |i| + v = 0 + for j in 0..u.length-1 + v += eval_A(i,j)*u[j] + end + v + } +end + +def eval_At_times_u(u) + v, i = nil, nil + (0..u.length-1).collect{|i| + v = 0 + for j in 0..u.length-1 + v += eval_A(j,i)*u[j] + end + v + } +end + +def eval_AtA_times_u(u) + return eval_At_times_u(eval_A_times_u(u)) +end + +n = 500 # ARGV[0].to_i + +u=[1]*n +for i in 1..10 + v=eval_AtA_times_u(u) + u=eval_AtA_times_u(v) +end +vBv=0 +vv=0 +for i in 0..n-1 + vBv += u[i]*v[i] + vv += v[i]*v[i] +end + +str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n" +# print str |