diff --git a/rank.js b/rank.js index 16a46a2..33e0a35 100644 --- a/rank.js +++ b/rank.js @@ -1,7 +1,7 @@ import { GPU, input, Input } from "gpu.js"; // derived from https://git.dervland.net/biglyderv/new-bigly-chat/src/branch/master/docs/stats.php -function rankCalc(result, iterations = 10, main = [], domain_mode = false) { +function rankCalc(result, iterations = 10, main = [], domainMode = false) { let fng = {}; let fnc = {}; @@ -19,7 +19,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) { let keys = Object.keys(result); for (let unn in result) { let v = true; - if (domain_mode) { + if (domainMode) { v = false; try { let test = new URL(unn); @@ -36,7 +36,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) { fng[unn] = result[unn].following || []; let lf = Object.keys(fng[unn]).length; - if (domain_mode) { + if (domainMode) { let domains = []; for (let x of fng[unn]) { try { @@ -75,7 +75,7 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) { let h = new URL(unn); if (!(h.pathname == '/' || h.pathname == '')) fail *= 0.5; if (!(h.search == '')) fail *= 0.4; - if (main.indexOf(unn) != -1) fail = 10; + if (main.indexOf(unn) != -1) fail = 10; } catch (err) { } @@ -90,13 +90,31 @@ function rankCalc(result, iterations = 10, main = [], domain_mode = false) { let mm = (iterations); let gpu = new GPU(); - const multiplyMatrix = gpu.createKernel(function (a, b, c) { - let sum = 0; - for (let i = 0; i < c; i++) { - sum += a[(this.thread.x % c) * c + i] * b[i * c + this.thread.x / c]; + let isGpu = process.env.isGpu; + let multiplyMatrix; + + if (isGpu) { + multiplyMatrix = gpu.createKernel(function (a, b, c) { + let sum = 0; + for (let i = 0; i < c; i++) { + sum += a[(this.thread.x % c) * c + i] * b[i * c + this.thread.x / c]; + } + return sum; + }).setOutput([keys.length ** 2, 1]); + } else { + console.warn(`GPU mode not enabled. Using CPU multiplication...`) + multiplyMatrix = function (a, b, c) { + let outMatrix = new Float32Array(keys.length ** 2); + for (let i in outMatrix) { + let sum = 0; + for (let j = 0; j < c; j++) { + sum += a[(i % c) * c + j] * b[j * c + Math.floor(i / c)]; + } + outMatrix[i] = sum; + } + return [outMatrix]; } - return sum; - }).setOutput([keys.length ** 2, 1]); + } for (let i = 0; i < mm; i++) { let prold = pr;