Simplify script.
This commit is contained in:
parent
01f0cc028b
commit
9a409b5b49
@ -12,7 +12,7 @@ fn new_mat(x, y) {
|
|||||||
|
|
||||||
fn mat_gen(n) {
|
fn mat_gen(n) {
|
||||||
let m = new_mat(n, n);
|
let m = new_mat(n, n);
|
||||||
let tmp = 1.0 / n / n;
|
const tmp = 1.0 / n / n;
|
||||||
|
|
||||||
for i in range(0, n) {
|
for i in range(0, n) {
|
||||||
for j in range(0, n) {
|
for j in range(0, n) {
|
||||||
@ -24,43 +24,36 @@ fn mat_gen(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mat_mul(a, b) {
|
fn mat_mul(a, b) {
|
||||||
let m = a.len;
|
let b2 = new_mat(a[0].len, b[0].len);
|
||||||
let n = a[0].len;
|
|
||||||
let p = b[0].len;
|
|
||||||
|
|
||||||
let b2 = new_mat(n, p);
|
|
||||||
|
|
||||||
for i in range(0, n) {
|
for i in range(0, a[0].len) {
|
||||||
for j in range(0, p) {
|
for j in range(0, b[0].len) {
|
||||||
b2[j][i] = b[i][j];
|
b2[j][i] = b[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let c = new_mat(m, p);
|
let c = new_mat(a.len, b[0].len);
|
||||||
|
|
||||||
for i in range(0, c.len) {
|
for i in range(0, c.len) {
|
||||||
let ci = c[i];
|
for j in range(0, c[i].len) {
|
||||||
for j in range(0, ci.len) {
|
c[i][j] = 0.0;
|
||||||
let b2j = b2[j];
|
|
||||||
ci[j] = 0.0;
|
|
||||||
|
|
||||||
for z in range(0, a[i].len) {
|
for z in range(0, a[i].len) {
|
||||||
let x = a[i][z];
|
let x = a[i][z];
|
||||||
let y = b2j[z];
|
let y = b2[j][z];
|
||||||
ci[j] += x * y;
|
c[i][j] += x * y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c[i] = ci;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = timestamp();
|
const now = timestamp();
|
||||||
|
|
||||||
let a = mat_gen(SIZE);
|
const a = mat_gen(SIZE);
|
||||||
let b = mat_gen(SIZE);
|
const b = mat_gen(SIZE);
|
||||||
let c = mat_mul(a, b);
|
const c = mat_mul(a, b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for i in range(0, SIZE) {
|
for i in range(0, SIZE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user