examples: spectral: minor fixes

pull/5115/head
Pradeep Verghese 2020-05-29 10:11:56 +05:30 committed by GitHub
parent 3a340cbffc
commit 4b362862ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -12,6 +12,7 @@ module main
import math import math
import os import os
import strconv
fn evala(i, j int) int { fn evala(i, j int) int {
return ((i + j) * (i + j + 1) / 2 + i + 1) return ((i + j) * (i + j + 1) / 2 + i + 1)
@ -38,23 +39,24 @@ fn times_trans(v mut []f64, u []f64) {
} }
fn a_times_transp(v mut []f64, u []f64) { fn a_times_transp(v mut []f64, u []f64) {
mut x := [f64(0)].repeat(u.len) mut x := []f64{len:u.len, init:0}
times(mut x, u) times(mut x, u)
times_trans(mut v, x) times_trans(mut v, x)
} }
fn main() { fn main() {
args := os.args args := os.args
mut n := int(0) mut n := 0
if args.len == 2 { if args.len == 2 {
n = args[1].int() n = strconv.atoi(args[1])
} }
else { else {
n = 0 n = 0
} }
mut u := [f64(1.0)].repeat(n) mut u := []f64{len:n, init:1}
mut v := [f64(1.0)].repeat(n) mut v := []f64{len:n, init:1}
for i in 0..10 { for _ in 0..10 {
a_times_transp(mut v, u) a_times_transp(mut v, u)
a_times_transp(mut u, v) a_times_transp(mut u, v)
} }