Answer the question
In order to leave comments, you need to log in
How to optimize JS code to speed up work?
Good day.
The task is to calculate the values of the matrix 52000 by 52000 on JS.
The value in each cell is the result of calculating the Cosine Proximity of 300 vectors.
To speed up the calculations, I use GPUJS:
gpu.addFunction(function mF(a, b) {
return a * b;
});
const f3 = gpu.createKernel(function(inp) {
var a = 0
var b = 0
var c = 0
for (var i = 0; i < 300; i++) {
a += mF(inp[this.thread.y][i], inp[this.thread.x][i])
b += mF(inp[this.thread.y][i], inp[this.thread.y][i])
c += mF(inp[this.thread.x][i], inp[this.thread.x][i])
}
return a / (Math.pow(b, 0.5) * Math.pow(c, 0.5));
}).setOutput([52000, 52000])
Answer the question
In order to leave comments, you need to log in
The script also dies safely when calculating the entire huge matrix, you have to count it in pieces of 1000 vectors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question