js/src/jit-test/tests/sunspider/check-math-spectral-norm.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // The Great Computer Language Shootout
michael@0 2 // http://shootout.alioth.debian.org/
michael@0 3 //
michael@0 4 // contributed by Ian Osgood
michael@0 5
michael@0 6 function A(i,j) {
michael@0 7 return 1/((i+j)*(i+j+1)/2+i+1);
michael@0 8 }
michael@0 9
michael@0 10 function Au(u,v) {
michael@0 11 for (var i=0; i<u.length; ++i) {
michael@0 12 var t = 0;
michael@0 13 for (var j=0; j<u.length; ++j)
michael@0 14 t += A(i,j) * u[j];
michael@0 15 v[i] = t;
michael@0 16 }
michael@0 17 }
michael@0 18
michael@0 19 function Atu(u,v) {
michael@0 20 for (var i=0; i<u.length; ++i) {
michael@0 21 var t = 0;
michael@0 22 for (var j=0; j<u.length; ++j)
michael@0 23 t += A(j,i) * u[j];
michael@0 24 v[i] = t;
michael@0 25 }
michael@0 26 }
michael@0 27
michael@0 28 function AtAu(u,v,w) {
michael@0 29 Au(u,w);
michael@0 30 Atu(w,v);
michael@0 31 }
michael@0 32
michael@0 33 function spectralnorm(n) {
michael@0 34 var i, u=[], v=[], w=[], vv=0, vBv=0;
michael@0 35 for (i=0; i<n; ++i) {
michael@0 36 u[i] = 1; v[i] = w[i] = 0;
michael@0 37 }
michael@0 38 for (i=0; i<10; ++i) {
michael@0 39 AtAu(u,v,w);
michael@0 40 AtAu(v,u,w);
michael@0 41 }
michael@0 42 for (i=0; i<n; ++i) {
michael@0 43 vBv += u[i]*v[i];
michael@0 44 vv += v[i]*v[i];
michael@0 45 }
michael@0 46 return Math.sqrt(vBv/vv);
michael@0 47 }
michael@0 48
michael@0 49 var actual = '';
michael@0 50 for (var i = 6; i <= 48; i *= 2) {
michael@0 51 actual += spectralnorm(i) + ',';
michael@0 52 }
michael@0 53 assertEq(actual, "1.2657786149754053,1.2727355112619148,1.273989979775574,1.274190125290389,");

mercurial