New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deeplearn

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deeplearn - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

dist/src/adagrad_optimizer.d.ts

2

dist/src/index.d.ts

@@ -17,6 +17,6 @@ import * as conv_util from './math/conv_util';

export { GPGPUContext } from './math/webgl/gpgpu_context';
export { MomentumOptimizer } from './momentum_optimizer';
export { Optimizer } from './optimizer';
export { CostReduction, FeedEntry, Session } from './session';
export { SGDOptimizer } from './sgd_optimizer';
export { MomentumOptimizer } from './momentum_optimizer';
export { conv_util, gpgpu_util, render_ndarray_gpu_util, util, webgl_util };

@@ -51,2 +51,4 @@ "use strict";

exports.GPGPUContext = gpgpu_context_1.GPGPUContext;
var momentum_optimizer_1 = require("./momentum_optimizer");
exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer;
var optimizer_1 = require("./optimizer");

@@ -59,4 +61,2 @@ exports.Optimizer = optimizer_1.Optimizer;

exports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer;
var momentum_optimizer_1 = require("./momentum_optimizer");
exports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer;
//# sourceMappingURL=index.js.map

@@ -32,5 +32,13 @@ import { ConvInfo } from './conv_util';

protected reluInternal<T extends NDArray>(ndarray: T): T;
protected absInternal<T extends NDArray>(ndarray: T): T;
protected sigmoidInternal<T extends NDArray>(ndarray: T): T;
protected sinInternal<T extends NDArray>(ndarray: T): T;
protected cosInternal<T extends NDArray>(ndarray: T): T;
protected tanInternal<T extends NDArray>(ndarray: T): T;
protected asinInternal<T extends NDArray>(ndarray: T): T;
protected acosInternal<T extends NDArray>(ndarray: T): T;
protected atanInternal<T extends NDArray>(ndarray: T): T;
protected sinhInternal<T extends NDArray>(ndarray: T): T;
protected coshInternal<T extends NDArray>(ndarray: T): T;
protected tanhInternal<T extends NDArray>(ndarray: T): T;
protected sinInternal<T extends NDArray>(ndarray: T): T;
protected stepInternal<T extends NDArray>(ndarray: T): T;

@@ -37,0 +45,0 @@ protected conv2dInternal(x: Array3D, filter: Array4D, bias: Array1D | null, convInfo: ConvInfo): Array3D;

@@ -283,15 +283,15 @@ "use strict";

};
NDArrayMathCPU.prototype.sigmoidInternal = function (ndarray) {
NDArrayMathCPU.prototype.absInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = 1 / (1 + Math.exp(-values[i]));
resultValues[i] = Math.abs(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.tanhInternal = function (ndarray) {
NDArrayMathCPU.prototype.sigmoidInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = util.tanh(values[i]);
resultValues[i] = 1 / (1 + Math.exp(-values[i]));
}

@@ -308,2 +308,66 @@ return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });

};
NDArrayMathCPU.prototype.cosInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.cos(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.tanInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.tan(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.asinInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.asin(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.acosInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.acos(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.atanInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.atan(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.sinhInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.sinh(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.coshInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = Math.cosh(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.tanhInternal = function (ndarray) {
var resultValues = new Float32Array(ndarray.size);
var values = ndarray.getValues();
for (var i = 0; i < values.length; ++i) {
resultValues[i] = util.tanh(values[i]);
}
return ndarray_1.NDArray.make(ndarray.shape, { values: resultValues });
};
NDArrayMathCPU.prototype.stepInternal = function (ndarray) {

@@ -310,0 +374,0 @@ var resultValues = new Float32Array(ndarray.size);

@@ -43,5 +43,13 @@ import { ConvInfo } from './conv_util';

protected reluInternal<T extends NDArray>(a: T): T;
protected absInternal<T extends NDArray>(a: T): T;
protected sigmoidInternal<T extends NDArray>(a: T): T;
protected sinInternal<T extends NDArray>(a: T): T;
protected cosInternal<T extends NDArray>(a: T): T;
protected tanInternal<T extends NDArray>(a: T): T;
protected asinInternal<T extends NDArray>(a: T): T;
protected acosInternal<T extends NDArray>(a: T): T;
protected atanInternal<T extends NDArray>(a: T): T;
protected sinhInternal<T extends NDArray>(a: T): T;
protected coshInternal<T extends NDArray>(a: T): T;
protected tanhInternal<T extends NDArray>(a: T): T;
protected sinInternal<T extends NDArray>(a: T): T;
protected stepInternal<T extends NDArray>(a: T): T;

@@ -48,0 +56,0 @@ protected conv2dInternal(x: Array3D, filter: Array4D, bias: Array1D | null, convInfo: ConvInfo): Array3D;

@@ -20,2 +20,3 @@ "use strict";

var batchnorm_gpu_1 = require("./webgl/batchnorm_gpu");
var binaryop_gpu = require("./webgl/binaryop_gpu");
var binaryop_gpu_1 = require("./webgl/binaryop_gpu");

@@ -37,2 +38,3 @@ var concat3d_gpu_1 = require("./webgl/concat3d_gpu");

var texture_manager_1 = require("./webgl/texture_manager");
var unary_op = require("./webgl/unaryop_gpu");
var unaryop_gpu_1 = require("./webgl/unaryop_gpu");

@@ -88,3 +90,3 @@ var webgl_util = require("./webgl/webgl_util");

NDArrayMathGPU.prototype.negInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.NEG);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.NEG);
return this.compileAndRun(program, [a]);

@@ -114,3 +116,3 @@ };

NDArrayMathGPU.prototype.multiplyInternal = function (a, b) {
var program = new binaryop_gpu_1.BinaryOpProgram('*', a.shape, b.shape);
var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape);
return this.compileAndRun(program, [a, b]);

@@ -167,11 +169,11 @@ };

NDArrayMathGPU.prototype.divideInternal = function (a, b) {
var program = new binaryop_gpu_1.BinaryOpProgram('/', a.shape, b.shape);
var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.DIV, a.shape, b.shape);
return this.compileAndRun(program, [a, b]);
};
NDArrayMathGPU.prototype.addInternal = function (a, b) {
var program = new binaryop_gpu_1.BinaryOpProgram('+', a.shape, b.shape);
var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape);
return this.compileAndRun(program, [a, b]);
};
NDArrayMathGPU.prototype.subInternal = function (a, b) {
var program = new binaryop_gpu_1.BinaryOpProgram('-', a.shape, b.shape);
var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape);
return this.compileAndRun(program, [a, b]);

@@ -184,31 +186,63 @@ };

NDArrayMathGPU.prototype.expInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.EXP);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.EXP);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.logInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.LOG);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.LOG);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.sqrtInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.SQRT);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.SQRT);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.reluInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.RELU);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.RELU);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.sigmoidInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.SIGMOID);
NDArrayMathGPU.prototype.absInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.ABS);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.tanhInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.TANH);
NDArrayMathGPU.prototype.sigmoidInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.SIGMOID);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.sinInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.SIN);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.SIN);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.cosInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.COS);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.tanInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.TAN);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.asinInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.ASIN);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.acosInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.ACOS);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.atanInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.ATAN);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.sinhInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.SINH);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.coshInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.COSH);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.tanhInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.TANH);
return this.compileAndRun(program, [a]);
};
NDArrayMathGPU.prototype.stepInternal = function (a) {
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unaryop_gpu_1.UnaryOp.STEP);
var program = new unaryop_gpu_1.UnaryOpProgram(a.shape, unary_op.STEP);
return this.compileAndRun(program, [a]);

@@ -215,0 +249,0 @@ };

@@ -90,2 +90,4 @@ import { ConvInfo } from './conv_util';

protected abstract sqrtInternal<T extends NDArray>(ndarray: T): T;
abs<T extends NDArray>(ndarray: T): T;
protected abstract absInternal<T extends NDArray>(ndarray: T): T;
relu<T extends NDArray>(ndarray: T): T;

@@ -95,6 +97,20 @@ protected abstract reluInternal<T extends NDArray>(ndarray: T): T;

protected abstract sigmoidInternal<T extends NDArray>(ndarray: T): T;
sin<T extends NDArray>(ndarray: T): T;
protected abstract sinInternal<T extends NDArray>(ndarray: T): T;
cos<T extends NDArray>(ndarray: T): T;
protected abstract cosInternal<T extends NDArray>(ndarray: T): T;
tan<T extends NDArray>(ndarray: T): T;
protected abstract tanInternal<T extends NDArray>(ndarray: T): T;
asin<T extends NDArray>(ndarray: T): T;
protected abstract asinInternal<T extends NDArray>(ndarray: T): T;
acos<T extends NDArray>(ndarray: T): T;
protected abstract acosInternal<T extends NDArray>(ndarray: T): T;
atan<T extends NDArray>(ndarray: T): T;
protected abstract atanInternal<T extends NDArray>(ndarray: T): T;
sinh<T extends NDArray>(ndarray: T): T;
protected abstract sinhInternal<T extends NDArray>(ndarray: T): T;
cosh<T extends NDArray>(ndarray: T): T;
protected abstract coshInternal<T extends NDArray>(ndarray: T): T;
tanh<T extends NDArray>(ndarray: T): T;
protected abstract tanhInternal<T extends NDArray>(ndarray: T): T;
sin<T extends NDArray>(ndarray: T): T;
protected abstract sinInternal<T extends NDArray>(ndarray: T): T;
step<T extends NDArray>(ndarray: T): T;

@@ -101,0 +117,0 @@ protected abstract stepInternal<T extends NDArray>(ndarray: T): T;

@@ -352,2 +352,6 @@ "use strict";

};
NDArrayMath.prototype.abs = function (ndarray) {
var _this = this;
return this.executeOp('abs', function () { return _this.absInternal(ndarray); });
};
NDArrayMath.prototype.relu = function (ndarray) {

@@ -361,2 +365,34 @@ var _this = this;

};
NDArrayMath.prototype.sin = function (ndarray) {
var _this = this;
return this.executeOp('sin', function () { return _this.sinInternal(ndarray); });
};
NDArrayMath.prototype.cos = function (ndarray) {
var _this = this;
return this.executeOp('cos', function () { return _this.cosInternal(ndarray); });
};
NDArrayMath.prototype.tan = function (ndarray) {
var _this = this;
return this.executeOp('tan', function () { return _this.tanInternal(ndarray); });
};
NDArrayMath.prototype.asin = function (ndarray) {
var _this = this;
return this.executeOp('asin', function () { return _this.asinInternal(ndarray); });
};
NDArrayMath.prototype.acos = function (ndarray) {
var _this = this;
return this.executeOp('acos', function () { return _this.acosInternal(ndarray); });
};
NDArrayMath.prototype.atan = function (ndarray) {
var _this = this;
return this.executeOp('atan', function () { return _this.atanInternal(ndarray); });
};
NDArrayMath.prototype.sinh = function (ndarray) {
var _this = this;
return this.executeOp('sinh', function () { return _this.sinhInternal(ndarray); });
};
NDArrayMath.prototype.cosh = function (ndarray) {
var _this = this;
return this.executeOp('cosh', function () { return _this.coshInternal(ndarray); });
};
NDArrayMath.prototype.tanh = function (ndarray) {

@@ -366,6 +402,2 @@ var _this = this;

};
NDArrayMath.prototype.sin = function (ndarray) {
var _this = this;
return this.executeOp('sin', function () { return _this.sinInternal(ndarray); });
};
NDArrayMath.prototype.step = function (ndarray) {

@@ -372,0 +404,0 @@ var _this = this;

import { GPGPUProgram } from './gpgpu_math';
export declare const ADD = "return a + b;";
export declare const SUB = "return a - b;";
export declare const MUL = "return a * b;";
export declare const DIV = "return a / b;";
export declare class BinaryOpProgram implements GPGPUProgram {

@@ -8,3 +12,3 @@ variableNames: string[];

supportsBroadcasting: boolean;
constructor(op: '+' | '-' | '*' | '/', aShape: number[], bShape: number[]);
constructor(op: string, aShape: number[], bShape: number[]);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util = require("../../util");
exports.ADD = 'return a + b;';
exports.SUB = 'return a - b;';
exports.MUL = 'return a * b;';
exports.DIV = 'return a / b;';
var BinaryOpProgram = (function () {

@@ -10,3 +14,3 @@ function BinaryOpProgram(op, aShape, bShape) {

this.outputShape = util.assertAndGetBroadcastedShape(aShape, bShape);
this.userCode = "\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(a " + op + " b);\n }\n ";
this.userCode = "\n float binaryOperation(float a, float b) {\n " + op + "\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n ";
}

@@ -13,0 +17,0 @@ return BinaryOpProgram;

@@ -5,3 +5,6 @@ "use strict";

function Conv2DProgram(convInfo, hasBias) {
this.variableNames = ['x', 'W', 'bias'];
this.variableNames = ['x', 'W'];
if (hasBias) {
this.variableNames.push('bias');
}
this.outputShape = convInfo.outShape;

@@ -8,0 +11,0 @@ var biasSnippet = hasBias ? 'dotProd += getBias(d2);' : '';

@@ -9,3 +9,3 @@ import { GPGPUContext } from './gpgpu_context';

constructor(srcNumCols: number, destNumCols: number);
getCustomSetupFunc(sourceStart: [number, number], destStart: [number, number], destSize: [number, number]): (gpgpu: GPGPUContext) => void;
getCustomSetupFunc(sourceStart: [number, number], destStart: [number, number], destSize: [number, number]): (gpgpu: GPGPUContext, webGLProgram: WebGLProgram) => void;
}

@@ -11,7 +11,7 @@ "use strict";

Copy2DProgram.prototype.getCustomSetupFunc = function (sourceStart, destStart, destSize) {
return function (gpgpu) {
return function (gpgpu, webGLProgram) {
gpgpu.setOutputMatrixWriteRegion(destStart[0], destSize[0], destStart[1], destSize[1]);
var sourceStartCRLoc = gpgpu.getUniformLocation('sourceStart');
var sourceStartCRLoc = gpgpu.getUniformLocation(webGLProgram, 'sourceStart');
gpgpu.gl.uniform2i(sourceStartCRLoc, sourceStart[0], sourceStart[1]);
var destStartCRLoc = gpgpu.getUniformLocation('destStart');
var destStartCRLoc = gpgpu.getUniformLocation(webGLProgram, 'destStart');
gpgpu.gl.uniform2i(destStartCRLoc, destStart[0], destStart[1]);

@@ -18,0 +18,0 @@ };

@@ -28,4 +28,4 @@ import { WebGLLoseContextExtension } from './webgl_util';

setProgram(program: WebGLProgram | null): void;
getUniformLocation(uniformName: string): WebGLUniformLocation;
setInputMatrixTexture(inputMatrixTexture: WebGLTexture, uniformName: string, textureUnit: number): void;
getUniformLocation(program: WebGLProgram, uniformName: string): WebGLUniformLocation;
setInputMatrixTexture(inputMatrixTexture: WebGLTexture, uniformLocation: WebGLUniformLocation, textureUnit: number): void;
setOutputMatrixTexture(outputMatrixTexture: WebGLTexture, rows: number, columns: number): void;

@@ -32,0 +32,0 @@ setOutputPackedMatrixTexture(outputPackedMatrixTexture: WebGLTexture, rows: number, columns: number): void;

@@ -28,3 +28,4 @@ "use strict";

}
this.loseContextExtension = webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context');
this.loseContextExtension =
webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context');
this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl);

@@ -136,11 +137,10 @@ this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl);

};
GPGPUContext.prototype.getUniformLocation = function (uniformName) {
GPGPUContext.prototype.getUniformLocation = function (program, uniformName) {
this.throwIfDisposed();
this.throwIfNoProgram();
return webgl_util.getProgramUniformLocationOrThrow(this.gl, this.program, uniformName);
return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName);
};
GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformName, textureUnit) {
GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) {
this.throwIfDisposed();
this.throwIfNoProgram();
webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformName, textureUnit);
webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit);
};

@@ -147,0 +147,0 @@ GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) {

@@ -14,2 +14,5 @@ import { NDArray } from '../ndarray';

program: GPGPUProgram;
uniformLocations: {
[name: string]: WebGLUniformLocation;
};
gpgpu: GPGPUContext;

@@ -21,3 +24,3 @@ source: string;

export declare function compileProgram<T extends NDArray, K extends NDArray>(gpgpu: GPGPUContext, program: GPGPUProgram, inputs: T[], output: K): GPGPUBinary;
export declare function runProgram<T extends NDArray, K extends NDArray>(binary: GPGPUBinary, inputs: T[], output: K, customSetup?: (gpgpu: GPGPUContext) => void): void;
export declare function runProgram<T extends NDArray, K extends NDArray>(binary: GPGPUBinary, inputs: T[], output: K, customSetup?: (gpgpu: GPGPUContext, webGLProgram: WebGLProgram) => void): void;
export declare function makeShaderKey(program: GPGPUProgram, inputs: NDArray[], output: NDArray): string;

@@ -20,6 +20,17 @@ "use strict";

var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true);
var webGLProgram = gpgpu.createProgram(source);
var uniformLocations = {};
for (var i = 0; i < program.variableNames.length; i++) {
var uniformName = program.variableNames[i];
uniformLocations[uniformName] =
gpgpu.getUniformLocation(webGLProgram, uniformName);
}
return {
program: program,
source: source,
webGLProgram: gpgpu.createProgram(source), gpgpu: gpgpu, inShapeInfos: inShapeInfos, outShapeInfo: outShapeInfo
webGLProgram: webGLProgram,
uniformLocations: uniformLocations,
gpgpu: gpgpu,
inShapeInfos: inShapeInfos,
outShapeInfo: outShapeInfo
};

@@ -58,6 +69,8 @@ }

var tex = input.getTexture();
gpgpu.setInputMatrixTexture(tex, binary.program.variableNames[i], i);
var variableName = binary.program.variableNames[i];
var variableUniformLocation = binary.uniformLocations[variableName];
gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i);
});
if (customSetup != null) {
customSetup(gpgpu);
customSetup(gpgpu, binary.webGLProgram);
}

@@ -64,0 +77,0 @@ gpgpu.executeProgram();

@@ -5,2 +5,3 @@ "use strict";

var gpgpu_context_1 = require("./gpgpu_context");
var webgl_util = require("./webgl_util");
function getFragmentShaderSource(sharedDimension, aOrientation, bOrientation) {

@@ -24,4 +25,6 @@ var sharedDimensionPacked = Math.ceil(sharedDimension / 2);

gpgpu.setProgram(multiplyProgram);
gpgpu.setInputMatrixTexture(a, 'matrixA', 0);
gpgpu.setInputMatrixTexture(b, 'matrixB', 1);
var matrixASamplerLocation = webgl_util.getProgramUniformLocationOrThrow(gpgpu.gl, multiplyProgram, 'matrixA');
var matrixBSamplerLocation = webgl_util.getProgramUniformLocationOrThrow(gpgpu.gl, multiplyProgram, 'matrixB');
gpgpu.setInputMatrixTexture(a, matrixASamplerLocation, 0);
gpgpu.setInputMatrixTexture(b, matrixBSamplerLocation, 1);
gpgpu.executeProgram();

@@ -28,0 +31,0 @@ }

@@ -16,3 +16,4 @@ "use strict";

gpgpu.setProgram(renderShader);
gpgpu.setInputMatrixTexture(sourceTex, 'source', 0);
var sourceSamplerLocation = webgl_util.getProgramUniformLocationOrThrow(gpgpu.gl, renderShader, 'source');
gpgpu.setInputMatrixTexture(sourceTex, sourceSamplerLocation, 0);
gpgpu.executeProgram();

@@ -19,0 +20,0 @@ }

import { GPGPUProgram } from './gpgpu_math';
export declare enum UnaryOp {
EXP = 0,
LOG = 1,
SQRT = 2,
NEG = 3,
RELU = 4,
SIGMOID = 5,
STEP = 6,
SIN = 7,
TANH = 8,
}
export declare class UnaryOpProgram implements GPGPUProgram {

@@ -18,3 +7,21 @@ variableNames: string[];

outputShape: number[];
constructor(aShape: number[], op: UnaryOp);
constructor(aShape: number[], opSnippet: string);
}
export declare const CHECK_NAN_SNIPPET: string;
export declare const ABS: string;
export declare const RELU: string;
export declare const STEP: string;
export declare const NEG: string;
export declare const EXP: string;
export declare const LOG: string;
export declare const SQRT: string;
export declare const SIGMOID: string;
export declare const SIN: string;
export declare const COS: string;
export declare const TAN: string;
export declare const ASIN: string;
export declare const ACOS: string;
export declare const ATAN: string;
export declare const SINH: string;
export declare const COSH: string;
export declare const TANH: string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var UnaryOp;
(function (UnaryOp) {
UnaryOp[UnaryOp["EXP"] = 0] = "EXP";
UnaryOp[UnaryOp["LOG"] = 1] = "LOG";
UnaryOp[UnaryOp["SQRT"] = 2] = "SQRT";
UnaryOp[UnaryOp["NEG"] = 3] = "NEG";
UnaryOp[UnaryOp["RELU"] = 4] = "RELU";
UnaryOp[UnaryOp["SIGMOID"] = 5] = "SIGMOID";
UnaryOp[UnaryOp["STEP"] = 6] = "STEP";
UnaryOp[UnaryOp["SIN"] = 7] = "SIN";
UnaryOp[UnaryOp["TANH"] = 8] = "TANH";
})(UnaryOp = exports.UnaryOp || (exports.UnaryOp = {}));
var UnaryOpProgram = (function () {
function UnaryOpProgram(aShape, op) {
function UnaryOpProgram(aShape, opSnippet) {
this.variableNames = ['A'];
this.outputShape = aShape;
this.params = [op];
this.userCode = "\n void main() {\n float v = getAAtOutCoords();\n " + getOpSnippet(op) + "\n setOutput(r);\n }\n ";
this.params = [opSnippet];
this.userCode = "\n float unaryOperation(float x) {\n " + opSnippet + "\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n ";
}

@@ -25,29 +13,20 @@ return UnaryOpProgram;

exports.UnaryOpProgram = UnaryOpProgram;
var CHECK_NAN_SNIPPET = "\n if (isNaN(v)) {\n setOutput(v);\n return;\n }\n";
function getOpSnippet(op) {
switch (op) {
case UnaryOp.EXP:
return 'float r = exp(v);';
case UnaryOp.LOG:
return 'float r = log(v);';
case UnaryOp.SQRT:
return CHECK_NAN_SNIPPET +
'float r = sqrt(v);';
case UnaryOp.NEG:
return 'float r = -v;';
case UnaryOp.RELU:
return 'float r = (v < 0.0) ? 0.0 : v;';
case UnaryOp.SIGMOID:
return 'float r = 1.0 / (1.0 + exp(-1.0 * v));';
case UnaryOp.STEP:
return 'float r = (v == v) ? (v > 0.0 ? 1.0 : 0.0) : v;';
case UnaryOp.SIN:
return CHECK_NAN_SNIPPET +
'float r = sin(v);';
case UnaryOp.TANH:
return "float e2x = exp(-2.0 * abs(v));\n float r = sign(v) * (1.0 - e2x) / (1.0 + e2x);";
default:
throw Error('Unrecognized unary op type ' + op);
}
}
exports.CHECK_NAN_SNIPPET = "\n if (isNaN(x)) {\n return x;\n }\n";
exports.ABS = "\n return abs(x);\n";
exports.RELU = "\n return (x < 0.0) ? 0.0 : x;\n";
exports.STEP = "\n return (x == x) ? (x > 0.0 ? 1.0 : 0.0) : x;\n";
exports.NEG = "\n return -x;\n";
exports.EXP = "\n return exp(x);\n";
exports.LOG = "\n return log(x);\n";
exports.SQRT = exports.CHECK_NAN_SNIPPET + "\n return sqrt(x);\n";
exports.SIGMOID = "\n return 1.0 / (1.0 + exp(-1.0 * x));\n";
exports.SIN = exports.CHECK_NAN_SNIPPET + "\n return sin(x);\n";
exports.COS = exports.CHECK_NAN_SNIPPET + "\n return cos(x);\n";
exports.TAN = "\n return tan(x);\n";
exports.ASIN = exports.CHECK_NAN_SNIPPET + "\n return asin(x);\n";
exports.ACOS = exports.CHECK_NAN_SNIPPET + "\n return acos(x);\n";
exports.ATAN = exports.CHECK_NAN_SNIPPET + "\n return atan(x);\n";
exports.SINH = "\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n";
exports.COSH = "\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n";
exports.TANH = "\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n";
//# sourceMappingURL=unaryop_gpu.js.map

@@ -39,3 +39,3 @@ export interface WebGLContextAttributes {

export declare function getProgramUniformLocationOrThrow(gl: WebGLRenderingContext, program: WebGLProgram, uniformName: string): WebGLUniformLocation;
export declare function bindTextureToProgramUniformSampler(gl: WebGLRenderingContext, program: WebGLProgram, texture: WebGLTexture, uniformSamplerName: string, textureUnit: number): void;
export declare function bindTextureToProgramUniformSampler(gl: WebGLRenderingContext, program: WebGLProgram, texture: WebGLTexture, uniformSamplerLocation: WebGLUniformLocation, textureUnit: number): void;
export declare function bindCanvasToFramebuffer(gl: WebGLRenderingContext): void;

@@ -42,0 +42,0 @@ export declare function bindColorTextureToFramebuffer(gl: WebGLRenderingContext, texture: WebGLTexture, framebuffer: WebGLFramebuffer): void;

@@ -49,5 +49,4 @@ "use strict";

else {
gl =
(canvas.getContext('webgl', attributes) ||
canvas.getContext('experimental-webgl', attributes));
gl = (canvas.getContext('webgl', attributes) ||
canvas.getContext('experimental-webgl', attributes));
}

@@ -121,4 +120,3 @@ if (gl == null) {

if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) {
console.log(fragmentShaderSource);
console.log(gl.getShaderInfoLog(fragmentShader));
logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader));
throw new Error('Failed to compile fragment shader.');

@@ -129,2 +127,20 @@ }

exports.createFragmentShader = createFragmentShader;
var lineNumberRegex = /^ERROR: [0-9]+:([0-9]+):/g;
function logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) {
var lineNumber = +lineNumberRegex.exec(shaderInfoLog)[1];
var shaderLines = shaderSource.split('\n');
var pad = ('' + shaderLines.length).length + 2;
var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) { return util.rightPad('' + (lineNumber + 1), pad) + line; });
var maxLineLength = 0;
for (var i = 0; i < linesWithLineNumbers.length; i++) {
maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength);
}
var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1);
var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber);
var afterErrorLines = linesWithLineNumbers.slice(lineNumber);
console.log(beforeErrorLines.join('\n'));
console.log(shaderInfoLog.split('\n')[0]);
console.log("%c " + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717');
console.log(afterErrorLines.join('\n'));
}
function createProgram(gl) {

@@ -230,6 +246,5 @@ return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.');

exports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow;
function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerName, textureUnit) {
function bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) {
callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); });
var samplerLocation = getProgramUniformLocationOrThrow(gl, program, uniformSamplerName);
callAndCheck(gl, function () { return gl.uniform1i(samplerLocation, textureUnit); });
callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); });
}

@@ -236,0 +251,0 @@ exports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler;

@@ -23,2 +23,3 @@ "use strict";

_this.variableVelocities = new tensor_array_map_1.TensorArrayMap();
_this.m = ndarray_1.Scalar.new(_this.momentum);
return _this;

@@ -29,3 +30,2 @@ }

_super.prototype.beforeBatch.call(this, math, batchSize, runtime, activationArrayMap, gradientArrayMap);
this.m = ndarray_1.Scalar.new(this.momentum);
if (this.variableVelocities.size() === 0) {

@@ -57,9 +57,4 @@ this.variableNodes.forEach(function (node) {

MomentumOptimizer.prototype.dispose = function () {
if (this.c != null) {
this.c.dispose();
}
if (this.m != null) {
this.m.dispose();
}
this.one.dispose();
_super.prototype.dispose.call(this);
this.m.dispose();
this.variableVelocities.dispose();

@@ -66,0 +61,0 @@ };

import { Node, VariableNode } from './graph';
import { NDArrayMath } from './math/math';
import { Scalar } from './math/ndarray';
import { SessionRuntime } from './session';
import { TensorArrayMap, SummedTensorArrayMap } from './tensor_array_map';
import { SummedTensorArrayMap, TensorArrayMap } from './tensor_array_map';
export declare abstract class Optimizer {
protected learningRate: number;
protected variableNodes: VariableNode[];
protected specifiedVariableNodes: VariableNode[] | null;
constructor(specifiedVariableList?: Node[]);
abstract beforeBatch(math: NDArrayMath, batchSize: number, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
abstract afterExample(math: NDArrayMath, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
constructor(learningRate: number, specifiedVariableList?: Node[]);
beforeBatch(math: NDArrayMath, batchSize: number, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
afterExample(math: NDArrayMath, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
abstract afterBatch(math: NDArrayMath, batchSize: number, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
abstract dispose(): void;
dispose(): void;
protected variableGradients: TensorArrayMap;
protected prevBatchSize: number;
protected one: Scalar;
protected c: Scalar;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ndarray_1 = require("./math/ndarray");
var session_util = require("./session_util");
var tensor_array_map_1 = require("./tensor_array_map");
var Optimizer = (function () {
function Optimizer(specifiedVariableList) {
function Optimizer(learningRate, specifiedVariableList) {
this.learningRate = learningRate;
this.variableGradients = new tensor_array_map_1.TensorArrayMap();
this.one = ndarray_1.Scalar.new(1);
if (specifiedVariableList != null) {

@@ -9,2 +15,33 @@ this.specifiedVariableNodes = specifiedVariableList;

}
Optimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) {
var _this = this;
this.variableNodes = this.specifiedVariableNodes == null ?
session_util.getVariableNodesFromEvaluationSet(runtime.nodes) :
this.specifiedVariableNodes;
if (batchSize !== this.prevBatchSize) {
if (this.c != null) {
this.c.dispose();
}
this.prevBatchSize = batchSize;
this.c = ndarray_1.Scalar.new(-this.learningRate / batchSize);
}
this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, ndarray_1.NDArray.zeros(node.output.shape)); });
};
Optimizer.prototype.afterExample = function (math, runtime, activationArrayMap, gradientArrayMap) {
var _this = this;
math.scope(function (keep) {
_this.variableNodes.forEach(function (node) {
var gradient = gradientArrayMap.get(node.output);
var accumulatedGradient = _this.variableGradients.get(node.output);
_this.variableGradients.set(node.output, keep(math.add(gradient, accumulatedGradient)));
accumulatedGradient.dispose();
});
});
};
Optimizer.prototype.dispose = function () {
if (this.c != null) {
this.c.dispose();
}
this.one.dispose();
};
return Optimizer;

@@ -11,0 +48,0 @@ }());

import { Node } from './graph';
import { NDArrayMath } from './math/math';
import { Scalar } from './math/ndarray';
import { Optimizer } from './optimizer';
import { SessionRuntime } from './session';
import { TensorArrayMap, SummedTensorArrayMap } from './tensor_array_map';
import { SummedTensorArrayMap, TensorArrayMap } from './tensor_array_map';
export declare class SGDOptimizer extends Optimizer {
protected learningRate: number;
constructor(learningRate: number, specifiedVariableList?: Node[]);
beforeBatch(math: NDArrayMath, batchSize: number, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
afterExample(math: NDArrayMath, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
afterBatch(math: NDArrayMath, batchSize: number, runtime: SessionRuntime, activationArrayMap: TensorArrayMap, gradientArrayMap: SummedTensorArrayMap): void;
dispose(): void;
setLearningRate(learningRate: number): void;
protected variableGradients: TensorArrayMap;
protected prevBatchSize: number;
protected one: Scalar;
protected c: Scalar;
}

@@ -13,5 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var ndarray_1 = require("./math/ndarray");
var optimizer_1 = require("./optimizer");
var session_util = require("./session_util");
var tensor_array_map_1 = require("./tensor_array_map");

@@ -21,30 +19,6 @@ var SGDOptimizer = (function (_super) {

function SGDOptimizer(learningRate, specifiedVariableList) {
var _this = _super.call(this, specifiedVariableList) || this;
var _this = _super.call(this, learningRate, specifiedVariableList) || this;
_this.learningRate = learningRate;
_this.variableGradients = new tensor_array_map_1.TensorArrayMap();
_this.one = ndarray_1.Scalar.new(1);
return _this;
}
SGDOptimizer.prototype.beforeBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) {
var _this = this;
this.variableNodes = this.specifiedVariableNodes == null ?
session_util.getVariableNodesFromEvaluationSet(runtime.nodes) :
this.specifiedVariableNodes;
if (batchSize !== this.prevBatchSize) {
this.prevBatchSize = batchSize;
this.c = ndarray_1.Scalar.new(-this.learningRate / batchSize);
}
this.variableNodes.forEach(function (node) { return _this.variableGradients.set(node.output, ndarray_1.NDArray.zeros(node.output.shape)); });
};
SGDOptimizer.prototype.afterExample = function (math, runtime, activationArrayMap, gradientArrayMap) {
var _this = this;
math.scope(function (keep) {
_this.variableNodes.forEach(function (node) {
var gradient = gradientArrayMap.get(node.output);
var accumulatedGradient = _this.variableGradients.get(node.output);
_this.variableGradients.set(node.output, keep(math.add(gradient, accumulatedGradient)));
accumulatedGradient.dispose();
});
});
};
SGDOptimizer.prototype.afterBatch = function (math, batchSize, runtime, activationArrayMap, gradientArrayMap) {

@@ -66,6 +40,3 @@ var _this = this;

SGDOptimizer.prototype.dispose = function () {
if (this.c != null) {
this.c.dispose();
}
this.one.dispose();
_super.prototype.dispose.call(this);
};

@@ -72,0 +43,0 @@ SGDOptimizer.prototype.setLearningRate = function (learningRate) {

{
"name": "deeplearn",
"version": "0.2.1",
"version": "0.2.2",
"description": "Hardware-accelerated JavaScript library for machine intelligence",

@@ -5,0 +5,0 @@ "private": false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc