2 ! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all
3 USING: specialized-arrays.double kernel math math.functions
4 math.vectors sequences sequences.private prettyprint words hints
6 IN: benchmark.spectral-norm
8 :: inner-loop ( u n quot -- seq )
13 ] double-array{ } map-as ; inline
17 [ drop ] [ + [ ] [ 1 + ] bi * 0.5 * ] 2bi
20 : (eval-A-times-u) ( u i j -- x )
21 tuck [ swap nth-unsafe ] [ eval-A ] 2bi* * ; inline
23 : eval-A-times-u ( n u -- seq )
24 [ (eval-A-times-u) ] inner-loop ; inline
26 : (eval-At-times-u) ( u i j -- x )
27 tuck [ swap nth-unsafe ] [ swap eval-A ] 2bi* * ; inline
29 : eval-At-times-u ( u n -- seq )
30 [ (eval-At-times-u) ] inner-loop ; inline
32 : eval-AtA-times-u ( u n -- seq )
33 [ eval-A-times-u ] [ eval-At-times-u ] bi ; inline
35 : ones ( n -- seq ) [ 1.0 ] double-array{ } replicate-as ; inline
42 [ n eval-AtA-times-u ] keep
45 : spectral-norm ( n -- norm )
46 u/v [ v. ] [ norm-sq ] bi /f sqrt ;
48 HINTS: spectral-norm fixnum ;
50 : spectral-norm-main ( -- )
51 5500 spectral-norm . ;
53 MAIN: spectral-norm-main