Skip to content

Instantly share code, notes, and snippets.

View abhisheksoni27's full-sized avatar

Abhishek Soni abhisheksoni27

View GitHub Profile
const GOODREADS_KEY = process.env.GOODREADS_KEY;
const cors = "https://cors-anywhere.herokuapp.com/";
const goodreads = "https://www.goodreads.com/";
const goodreadsURL = cors + goodreads + "search/index.xml?";
const bookURL = cors + goodreads + "book/show.xml?";

0.0.0-semantically-released (2018-01-06)

  • refactor(rules): refactor 'valid-by-tagname' rule (f83a4b9)

1.40.0 (2017-07-11)

// Take a union of Rules later. For Testing! TODO
const rules = [
// {pattern:/\t+|\n+|\d+|([a-zA-Z_]\w*)|\;|\{|\}|\]|\[|\(|\)|\+|\-|\*|\/|( +)|\=|\'|\>|\<|\.(?=\w+)/g, name:'all'},
{ pattern: /^\s/, name: "WhiteSpace" },
{ pattern: /^\[/, name: "OpenBracket" },
{ pattern: /^\]/, name: "CloseBracket" },
{ pattern: /^\(/, name: "OpenParen" },
{ pattern: /^\)/, name: "CloseParen" },
{ pattern: /^\{/, name: "OpenBraces" },
{ pattern: /^\}/, name: "CloseBraces" },
// Generate Matrices
const matrices = generateMatrices();
const A = matrices.A;
const B = matrices.B;
//CPU
const startCPU = window.performance.now();
const cpuResult = cpuMatMult(A, B);
const endCPU = window.performance.now();
const cpuTime = endCPU - startCPU;
function generateMatrices() {
const matSize = 512;
let A = [];
let B = [];
for (let n = 0; n < matSize * matSize; n++) {
const randA = Math.random();
const randB = Math.random();
A.push(randA);
B.push(randB);
}
const gpuMatMult = gpu.createKernel(function (A, B) {
var sum = 0;
for (var i = 0; i < 512; i++) {
sum += A[this.thread.y][i] * B[i][this.thread.x];
}
return sum;
})
.setDimensions([A.length, B.length])
.setOutputToTexture(true);
function cpuMatMult(m, n) {
var result = [];
for (var i = 0; i < m.length; i++) {
result[i] = [];
for (var j = 0; j < n[0].length; j++) {
var sum = 0;
for (var k = 0; k < m[0].length; k++) {
sum += m[i][k] * n[k][j];
}
result[i][j] = sum;
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>gpu.js demo</title>
<script src='gpu-core.min.js'></script>
#extension GL_EXT_draw_buffers : require
precision highp float;
precision highp int;
precision highp sampler2D;
const float LOOP_MAX = 100.0;
#define EPSILON 0.0000001;
uniform highp vec3 uOutputDim;
uniform highp vec2 uTexSize;
#extension GL_EXT_draw_buffers : require
precision highp float;
precision highp int;
precision highp sampler2D;
const float LOOP_MAX = 100.0;
#define EPSILON 0.0000001;
uniform highp vec3 uOutputDim;
uniform highp vec2 uTexSize;