Skip to content

Instantly share code, notes, and snippets.

View Dens49's full-sized avatar
🐳

Den Dens49

🐳
View GitHub Profile
@Dens49
Dens49 / gpujsComparison.js
Created June 9, 2020 08:14
Matrix-Vector multiplication runtime comparison: gpu.js, mathjs, own implementation
import GPU from "gpu.js";
import { multiply } from "mathjs";
const gpu = new GPU();
// multiply the point identified by this.thread.y with the given transformation matrix
const baseHtmKernel = gpu.createKernel(function (mat, points) {
let sum = 0;
for (let i = 0; i < 4; i++) {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Dens49
Dens49 / createBatchesFromArray.js
Last active November 13, 2019 15:26
Simple function that creates batches from an array. The last batch will contain fewer elements in case "data.length % batchSize != 0"
const createBatchesFromArray = (data, batchSize) => {
const batches = [];
let i = batchSize;
let currentBatch = [];
do {
currentBatch = data.slice(i - batchSize, i);
i += batchSize;
if (currentBatch.length !== 0) {
batches.push(currentBatch);
}