Skip to content

Commit 268f878

Browse files
Enet4ViralBShah
authored andcommitted
Fix JavaScript randmatstat matrix calculations (#24385)
1 parent f927508 commit 268f878

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/perf/micro/perf.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
}
265265

266266
function randmatstat(t) {
267-
var n, P, PTransposed, PMatMul, Q, QTransposed, QMatMul,
267+
var n, P, PTransposed, Pt1P, Pt2P, Q, QTransposed, Pt1Q, Pt2Q,
268268
a, b, c, d, aSub, bSub, cSub, dSub, v, w, i, j, k,
269269
trP, trQ, v1, v2, w1, w2;
270270
n = 5;
@@ -275,8 +275,10 @@
275275
PTransposed = new Float64Array( P.length );
276276
QTransposed = new Float64Array( Q.length );
277277

278-
PMatMul = new Float64Array( n*n );
279-
QMatMul = new Float64Array( (2*n) * (2*n) );
278+
Pt1P = new Float64Array( (4*n) * (4*n) );
279+
Pt2P = new Float64Array( (4*n) * (4*n) );
280+
Pt1Q = new Float64Array( (2*n) * (2*n) );
281+
Pt2Q = new Float64Array( (2*n) * (2*n) );
280282

281283
a = new Float64Array( n*n );
282284
b = new Float64Array( n*n );
@@ -323,24 +325,24 @@
323325
}
324326

325327
transpose( PTransposed, P, n, 4*n );
326-
matmulCopy( PMatMul, PTransposed, P, n, 4*n, n );
327-
matmulCopy( PMatMul, P, P, n, n, n);
328-
matmulCopy( PMatMul, P, P, n, n, n);
328+
matmulCopy( Pt1P, PTransposed, P, 4*n, n, 4*n );
329+
matmulCopy( Pt2P, Pt1P, Pt1P, 4*n, 4*n, 4*n);
330+
matmulCopy( Pt1P, Pt2P, Pt2P, 4*n, 4*n, 4*n);
329331

330332
trP = 0;
331-
for (j = 0; j < n; j++) {
332-
trP += PMatMul[(n+1)*j];
333+
for (j = 0; j < 4*n; j++) {
334+
trP += Pt1P[(4*n+1)*j];
333335
}
334336
v[i] = trP;
335337

336338
transpose( QTransposed, Q, 2*n, 2*n );
337-
matmulCopy( QMatMul, QTransposed, Q, 2*n, 2*n, 2*n );
338-
matmulCopy( QMatMul, Q, Q, 2*n, 2*n, 2*n);
339-
matmulCopy( QMatMul, Q, Q, 2*n, 2*n, 2*n);
339+
matmulCopy( Pt1Q, QTransposed, Q, 2*n, 2*n, 2*n );
340+
matmulCopy( Pt2Q, Pt1Q, Pt1Q, 2*n, 2*n, 2*n);
341+
matmulCopy( Pt1Q, Pt2Q, Pt2Q, 2*n, 2*n, 2*n);
340342

341343
trQ = 0;
342344
for (j = 0; j < 2*n; j++) {
343-
trQ += QMatMul[(2*n+1)*j];
345+
trQ += Pt1Q[(2*n+1)*j];
344346
}
345347
w[i] = trQ;
346348
}

0 commit comments

Comments
 (0)