2 ! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all
3 USING: float-arrays kernel math math.functions math.vectors
4 sequences sequences.private prettyprint words tools.time hints ;
5 IN: benchmark.spectral-norm
7 : fast-truncate >fixnum >float ; inline
11 dupd + dup 1+ * 2 /f fast-truncate + 1+
14 : (eval-A-times-u) ( u i j -- x )
15 tuck eval-A >r swap nth-unsafe r> * ; inline
17 : eval-A-times-u ( n u -- seq )
20 swap >r >r 2dup r> (eval-A-times-u) r> +
22 ] F{ } map-as 2nip ; inline
24 : (eval-At-times-u) ( u i j -- x )
25 tuck swap eval-A >r swap nth-unsafe r> * ; inline
27 : eval-At-times-u ( n u -- seq )
30 swap >r >r 2dup r> (eval-At-times-u) r> +
32 ] F{ } map-as 2nip ; inline
34 : eval-AtA-times-u ( n u -- seq )
35 dupd eval-A-times-u eval-At-times-u ; inline
38 dup 1.0 <float-array> dup
47 : spectral-norm ( n -- norm )
48 u/v [ v. ] keep norm-sq /f sqrt ;
50 HINTS: spectral-norm fixnum ;
52 : spectral-norm-main ( -- )
53 2000 spectral-norm . ;
55 MAIN: spectral-norm-main