The Computer Language
24.04 Benchmarks Game

spectral-norm VW Smalltalk program

source code

"* The Computer Language Benchmarks Game
    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'!

do: n
      print: (self spectralnorm: n) digits: 9;

   ^''! !

!Core.SmallInteger methodsFor: 'benchmarks game'!

matrixA: anInteger
   ^1.0d0 / ((self + anInteger - 2) * (self + anInteger - 1) /2  + self)! !

!Core.Array methodsFor: 'benchmarks game'!

   | 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].

   ^(self multiplyAv) multiplyAtv!

   | 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'!

   self nextPut: Character lf!

print: number digits: decimalPlaces
   self nextPutAll: 
      ((number asFixedPoint: decimalPlaces) printString copyWithout: $s)! !


notes, command-line, and program output

64-bit Ubuntu quad core
VisualWorks® 8.3
Aug 19 2017

 Tue, 05 Mar 2024 07:47:23 GMT

cp /opt/src/vw8.3pul/image/
/opt/src/vw8.3pul/bin/visual -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:
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/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/ created at March 4, 2024 11:47:05 PM
7.84s to complete and log all make actions

 /opt/src/vw8.3pul/bin/visual -nogui -evaluate "BenchmarksGame do: 5500"