spectral-norm Smalltalk VW program
source code
"* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Paolo Bonzini
reworked by Isaac Gouy *"!
Smalltalk.Core defineClass: #BenchmarksGame
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: ''!
!Core.BenchmarksGame class methodsFor: 'private'!
spectralnorm: n
| u v vBv vv |
u := Array new: n withAll: 1.0d0.
10 timesRepeat:
[v := u multiplyAtAv.
u := v multiplyAtAv].
vBv := 0.0d0.
vv := 0.0d0.
1 to: n do:
[:i |
vBv := vBv + ((u at: i) * (v at: i)).
vv := vv + ((v at: i) * (v at: i))].
^(vBv / vv) sqrt! !
!Core.BenchmarksGame class methodsFor: 'initialize-release'!
program
| n |
n := CEnvironment commandLine last asNumber.
Stdout
print: (self spectralnorm: n) digits: 9;
nl.
^''! !
!Core.SmallInteger methodsFor: 'benchmarks game'!
matrixA: anInteger
^1.0d0 / ((self + anInteger - 2) * (self + anInteger - 1) /2 + self)! !
!Core.Array methodsFor: 'benchmarks game'!
multiplyAtv
| n atv sum |
n := self size.
atv := Array new: n.
1 to: n do: [:i|
sum := 0.0d0.
1 to: n do: [:j|
sum := sum + ((j matrixA: i) * (self at: j)) ].
atv at: i put: sum].
^atv!
multiplyAtAv
^(self multiplyAv) multiplyAtv!
multiplyAv
| n av sum |
n := self size.
av := Array new: n.
1 to: n do: [:i|
sum := 0.0d0.
1 to: n do: [:j|
sum := sum + ((i matrixA: j) * (self at: j)) ].
av at: i put: sum].
^av! !
!Core.Stream methodsFor: 'benchmarks game'!
nl
self nextPut: Character lf!
print: number digits: decimalPlaces
self nextPutAll:
((number asFixedPoint: decimalPlaces) printString copyWithout: $s)! !
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
VisualWorks® Personal Use Edition Release 8.2 of July 15, 2016
Tue, 02 May 2017 19:03:32 GMT
MAKE:
cp /usr/local/src/vw8.2pul/image/visualnc64.im spectralnorm.vw_run.im
/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 spectralnorm.vw_run.im -nogui -pcl MatriX -filein spectralnorm.vw -doit 'ObjectMemory snapshotThenQuit'
Autoloading MatriX from $(VISUALWORKS)/preview/matrix/MatriX.pcl
Autoloading Xtreams-Support from $(VISUALWORKS)/xtreams/Xtreams-Support.pcl
Autoloading Xtreams-Core from $(VISUALWORKS)/xtreams/Xtreams-Core.pcl
Autoloading Xtreams-Terminals from $(VISUALWORKS)/xtreams/Xtreams-Terminals.pcl
Autoloading Xtreams-Transforms from $(VISUALWORKS)/xtreams/Xtreams-Transforms.pcl
Autoloading Xtreams-Substreams from $(VISUALWORKS)/xtreams/Xtreams-Substreams.pcl
Autoloading Xtreams-Multiplexing from $(VISUALWORKS)/xtreams/Xtreams-Multiplexing.pcl
Filing in from:
spectralnorm.vw
BenchmarksGame class<private
BenchmarksGame class<initialize-release
SmallInteger<benchmarks game
Do you want to add Root.Smalltalk.Core.SmallInteger>>matrixA: to the previously unchanged package, Magnitude-Numbers
OK to continue?
Array<benchmarks game
Do you want to add Root.Smalltalk.Core.Array>>multiplyAtv to the previously unchanged package, Collections-Arrayed
OK to continue?
Stream<benchmarks game
Do you want to add Root.Smalltalk.Core.Stream>>nl to the previously unchanged package, Collections-Streams
OK to continue?
/home/dunham/benchmarksgame_quadcore/spectralnorm/tmp/spectralnorm.vw_run.im created at May 2, 2017 12:03:03 PM
4.64s to complete and log all make actions
COMMAND LINE:
/usr/local/src/vw8.2pul/bin/linuxx86_64/vwlinuxx86_64 spectralnorm.vw_run.im -nogui -evaluate "BenchmarksGame program" -a 5500
PROGRAM OUTPUT:
1.274224153