Skip to content

Instantly share code, notes, and snippets.

View robertleeplummerjr's full-sized avatar

Robert Plummer robertleeplummerjr

View GitHub Profile
@robertleeplummerjr
robertleeplummerjr / jest-test-permutations.ts
Created February 22, 2024 18:48
A mental exercise in testing all the permutations of a single line which I didn't complete
export interface ITestCaseSubject {
subject: string;
}
export interface IEachTestCase extends ITestCaseSubject {
each: Array<() => any>;
}
export type ArrayMoreThanOne<T> = [T, T, ...T[]];
export function testPermutations(subjectCases: ArrayMoreThanOne<IEachTestCase>) {
function traverseAll(
@robertleeplummerjr
robertleeplummerjr / regex.txt
Created April 1, 2020 13:58
regex for finding function like things
[_a-zA-Z]+[_a-zA-Z0-9]*(?=[\(])
function kernel(settings) {
const { context, constants } = settings;
const gl = context;
const glVariables0 = gl.getExtension('OES_texture_float');
const glVariables1 = gl.getExtension('OES_texture_float_linear');
const glVariables2 = gl.getExtension('OES_element_index_uint');
const glVariables3 = gl.getExtension('WEBGL_draw_buffers');
const glVariables4 = gl.getExtension('WEBGL_color_buffer_float');
const { GPU } = require('./src');
const gpu = new GPU();
// language=GLSL
const clz32 = `float clz32(float x) {
int _x = int(x);
_x -= bitwiseAnd(bitwiseSignedRightShift(_x, 1), ${0x55555555});
_x = bitwiseAnd(bitwiseSignedRightShift(_x, 2), ${0x33333333}) + bitwiseAnd(_x, ${0x33333333});
_x = bitwiseAnd((bitwiseSignedRightShift(_x, 4) + _x), ${0x0f0f0f0f});
_x += bitwiseSignedRightShift(_x, 8);
_x += bitwiseSignedRightShift(_x, 16);
const gpu = new GPU();
const kernel = gpu.createKernel(function (baseImage, overlayImages, overlayImagesCount, overlayImagesSizes, offsets) {
const pixel = baseImage[this.thread.y][this.thread.x];
for (let i = 0; i < overlayImagesCount; i++) {
const offset = offsets[i];
const size = overlayImagesSizes[i];
if (this.thread.x >= offset[0] && this.thread.x <= size[0] - offset[0]) {
if (this.thread.y >= offset[1] && this.thread.x <= size[1] - offset[1]) {
const mixPixel = overlayImagesCount[i][this.thread.y - offset[1]][this.thread.x - offset[0]];
//mix mixPixel with pixel
const { GPU } = require('gpu.js');
const gpu = new GPU();
// possible solution to confusing kernel maps
const kernel = gpu.createKernel(function(input1, input2) {
const value1 = input1[this.thread.z][this.thread.y][this.thread.x];
const value2 = input1[this.thread.z][this.thread.y][this.thread.x];
/*
up sides:
function kernel(settings) {
const { context, constants } = settings;
const gl = context;
const glVariables0 = gl.getExtension('OES_texture_float');
const glVariables1 = gl.getExtension('OES_texture_float_linear');
const glVariables2 = gl.getExtension('OES_element_index_uint');
const glVariables3 = gl.getExtension('WEBGL_draw_buffers');
const glVariables4 = gl.getExtension('WEBGL_color_buffer_float');
class GPU {
createKernel<KF extends KernelFunction>(kernel: KF, settings?: IGPUKernelSettings):
((...args: Parameters<KF>) =>
ReturnType<KF>[]
| ReturnType<KF>[][]
| ReturnType<KF>[][][]
| Texture
| void
)
& Kernel;
const NeuralNetwork = require('./src/neural-network-gpu');
const NeuralNetworkGPU = require('./src/neural-network-gpu');
const { FeedForward } = require('./src/feed-forward');
const { input, feedForward, target } = require('./src/layer');
const { GPU } = require('gpu.js');
const { setup } = require('./src/utilities/kernel');
const { setLogInternalWeights, setLogInternalDeltas, setCheckWeights, setCheckDeltas } = require('./src/layer/debug/strict-watch');
const xorTrainingData = [
{ input: [0, 1], output: [1] },
@robertleeplummerjr
robertleeplummerjr / math-random-uniformly-distributed.js
Created November 22, 2019 15:10
Playing around with better random values in GPU.js
// language=GLSL
const source = `// https://www.shadertoy.com/view/4t2SDh
//note: uniformly distributed, normalized rand, [0,1]
highp float randomSeedShift = 0.0;
highp float previousRandomSeedShift = 0.0;
bool flip = false;
const highp float factor = 9999.0;
uniform highp float randomSeed1;
uniform highp float randomSeed2;
highp float nrand(highp vec2 n) {