public snapshot · system/tools/nib/bench/xlang/ · system@main · commit a92f56ab098e · shared 2026-11-22T22:43:57Z· frozen: this page does not change when the repository does
1 package main
2
3 import (
4 "fmt"
5 "math"
6 )
7
8 func a(i, j int) float64 {
9 return 1.0 / float64((i+j)*(i+j+1)/2+i+1)
10 }
11
12 func mulAv(v, out []float64) {
13 for i := range v {
14 s := 0.0
15 for j := range v {
16 s += a(i, j) * v[j]
17 }
18 out[i] = s
19 }
20 }
21
22 func mulAtv(v, out []float64) {
23 for i := range v {
24 s := 0.0
25 for j := range v {
26 s += a(j, i) * v[j]
27 }
28 out[i] = s
29 }
30 }
31
32 func mulAtAv(v, out, tmp []float64) {
33 mulAv(v, tmp)
34 mulAtv(tmp, out)
35 }
36
37 func main() {
38 n := 2500
39 u := make([]float64, n)
40 v := make([]float64, n)
41 tmp := make([]float64, n)
42 for i := range u {
43 u[i] = 1.0
44 }
45 for i := 0; i < 10; i++ {
46 mulAtAv(u, v, tmp)
47 mulAtAv(v, u, tmp)
48 }
49 vbv, vv := 0.0, 0.0
50 for i := 0; i < n; i++ {
51 vbv += u[i] * v[i]
52 vv += v[i] * v[i]
53 }
54 fmt.Printf("%.9f\n", math.Sqrt(vbv/vv))
55 }
snapshot of a92f56ab098e · 2858 files · browse