spectral-norm Toit program
source code
/* The Computer Language Benchmarks game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
transliterated from Sebastien Loisel's C program by Isaac Gouy*/
import math
a i/int j/int -> float:
return 1.0 / (((i + j) * (i + j + 1) / 2) + i + 1)
au n/int u/List w/List:
for i := 0; i < n; ++i:
w[i] = 0.0
for j := 0; j < n; ++j:
w[i] += (a i j) * u[j]
atu n/int w/List v/List:
for i := 0; i < n; ++i:
v[i] = 0.0
for j := 0; j < n; ++j:
v[i] += (a j i) * w[j]
atau n/int u/List v/List w/List:
au n u w; atu n w v
main args:
n := args.size == 1 ? int.parse args[0] : 0
u := List n 1.0
v := List n
w := List n
vv := 0.0
vBv := 0.0
for i := 0; i < 10; ++i:
atau n u v w
atau n v u w
for i := 0; i < n; ++i:
vBv += u[i] * v[i]
vv += v[i] * v[i]
print "$(%.9f (math.sqrt vBv / vv))"
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
v2.0.0-alpha.146
Thu, 25 Apr 2024 00:34:01 GMT
MAKE:
cp -r Include/toit/.packages .
cp -r Include/toit/package.lock .
cp -r Include/toit/package.yaml .
/opt/src/toit/bin/toit.compile -O2 --strip -o spectralnorm.toit_run spectralnorm.toit
1.40s to complete and log all make actions
COMMAND LINE:
./spectralnorm.toit_run 5500
PROGRAM OUTPUT:
1.274224153