Socket
Socket
Sign inDemoInstall

@tensorflow/tfjs-core

Package Overview
Dependencies
Maintainers
11
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tensorflow/tfjs-core - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

dist/ops/erf_util.d.ts

1

dist/kernels/backend_cpu.d.ts

@@ -87,2 +87,3 @@ import { Conv2DInfo } from '../ops/conv_util';

atanh<T extends Tensor>(x: T): T;
erf<T extends Tensor>(x: T): T;
step<T extends Tensor>(x: T, alpha?: number): T;

@@ -89,0 +90,0 @@ conv2d(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

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

var selu_util = require("../ops/selu_util");
var erf_util = require("../ops/erf_util");
var tensor_1 = require("../tensor");

@@ -808,2 +809,19 @@ var types = require("../types");

};
MathBackendCPU.prototype.erf = function (x) {
var resultValues = new Float32Array(x.size);
var values = x.dataSync();
var p = erf_util.ERF_P;
var a1 = erf_util.ERF_A1;
var a2 = erf_util.ERF_A2;
var a3 = erf_util.ERF_A3;
var a4 = erf_util.ERF_A4;
var a5 = erf_util.ERF_A5;
for (var i = 0; i < values.length; ++i) {
var v = values[i];
var t = 1.0 / (1.0 + p * v);
resultValues[i]
= 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-v * v);
}
return tensor_1.Tensor.make(x.shape, { values: resultValues });
};
MathBackendCPU.prototype.step = function (x, alpha) {

@@ -810,0 +828,0 @@ if (alpha === void 0) { alpha = 0; }

@@ -120,2 +120,3 @@ import { TimingInfo } from '../engine';

atanh<T extends Tensor>(x: T): T;
erf<T extends Tensor>(x: T): T;
step<T extends Tensor>(x: T, alpha: number): T;

@@ -122,0 +123,0 @@ conv2d(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

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

};
MathBackendWebGL.prototype.erf = function (x) {
var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ERF);
return this.compileAndRun(program, [x]);
};
MathBackendWebGL.prototype.step = function (x, alpha) {

@@ -678,0 +682,0 @@ var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha));

@@ -87,2 +87,3 @@ import { Conv2DInfo } from '../ops/conv_util';

atanh<T extends Tensor>(x: T): T;
erf<T extends Tensor>(x: T): T;
step<T extends Tensor>(x: T, alpha: number): T;

@@ -89,0 +90,0 @@ conv2d(x: Tensor4D, filter: Tensor4D, convInfo: Conv2DInfo): Tensor4D;

@@ -38,2 +38,3 @@ import { GPGPUProgram } from './gpgpu_math';

export declare const ATANH = "return (log(1.0 + x) - log(1.0 - x)) / 2.0;";
export declare const ERF: string;
export declare const SQUARE = "return x * x;";

@@ -40,0 +41,0 @@ export declare const RECIPROCAL = "return 1.0 / x;";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var selu_util = require("../../ops/selu_util");
var erf_util = require("../../ops/erf_util");
var UnaryOpProgram = (function () {

@@ -48,2 +49,3 @@ function UnaryOpProgram(aShape, opSnippet) {

exports.ATANH = "return (log(1.0 + x) - log(1.0 - x)) / 2.0;";
exports.ERF = "\n // Error function is calculated approximately with elementary function.\n // See \"Handbook of Mathematical Functions with Formulas, \n // Graphs, and Mathematical Tables\", Abramowitz and Stegun.\n float p = " + erf_util.ERF_P + ";\n float a1 = " + erf_util.ERF_A1 + ";\n float a2 = " + erf_util.ERF_A2 + ";\n float a3 = " + erf_util.ERF_A3 + ";\n float a4 = " + erf_util.ERF_A4 + ";\n float a5 = " + erf_util.ERF_A5 + ";\n \n float t = 1.0 / (1.0 + p * x);\n return 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);\n";
exports.SQUARE = "return x * x;";

@@ -50,0 +52,0 @@ exports.RECIPROCAL = "return 1.0 / x;";

@@ -188,2 +188,10 @@ "use strict";

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.div({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'div' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.div(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'div' must be a Tensor/);
});
});

@@ -349,2 +357,10 @@ test_util_1.describeWithFlags('mul', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.mul({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'mul' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.mul(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'mul' must be a Tensor/);
});
});

@@ -524,2 +540,10 @@ test_util_1.describeWithFlags('pow', test_util_1.ALL_ENVS, function () {

});
it('throws when passed base as a non-tensor', function () {
expect(function () { return tf.pow({}, tf.scalar(1)); })
.toThrowError(/Argument 'base' passed to 'pow' must be a Tensor/);
});
it('throws when passed exp as a non-tensor', function () {
expect(function () { return tf.pow(tf.scalar(1), {}); })
.toThrowError(/Argument 'exp' passed to 'pow' must be a Tensor/);
});
});

@@ -635,2 +659,10 @@ test_util_1.describeWithFlags('add', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.add({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'add' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.add(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'add' must be a Tensor/);
});
});

@@ -791,2 +823,10 @@ test_util_1.describeWithFlags('sub', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.sub({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'sub' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.sub(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'sub' must be a Tensor/);
});
});

@@ -142,8 +142,11 @@ "use strict";

ArrayOps.onesLike = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'onesLike');
return ArrayOps.ones(x.shape, x.dtype);
};
ArrayOps.zerosLike = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'zerosLike');
return ArrayOps.zeros(x.shape, x.dtype);
};
ArrayOps.clone = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'clone');
var der = function (dy) {

@@ -214,2 +217,3 @@ return { x: function () { return dy.toFloat(); } };

if (normalized === void 0) { normalized = false; }
util.assertArgumentsAreTensors({ logits: logits }, 'multinomial');
var numOutcomes = logits.size;

@@ -251,2 +255,3 @@ var origRank = logits.rank;

case 0:
util.assertArgumentsAreTensors({ img: img }, 'toPixels');
if (img.rank !== 2 && img.rank !== 3) {

@@ -327,2 +332,3 @@ throw new Error("toPixels only supports rank 2 or 3 tensors, got rank " + img.rank + ".");

ArrayOps.reshape = function (x, shape) {
util.assertArgumentsAreTensors({ x: x }, 'reshape');
shape = util.inferFromImplicitShape(shape, x.size);

@@ -336,5 +342,7 @@ util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.');

ArrayOps.squeeze = function (x, axis) {
util.assertArgumentsAreTensors({ x: x }, 'squeeze');
return ArrayOps.reshape(x, util.squeezeShape(x.shape, axis).newShape);
};
ArrayOps.cast = function (x, dtype) {
util.assertArgumentsAreTensors({ x: x }, 'cast');
var grad = function (dy) {

@@ -346,2 +354,3 @@ return { x: function () { return dy.clone(); } };

ArrayOps.tile = function (x, reps) {
util.assertArgumentsAreTensors({ x: x }, 'tile');
util.assert(x.rank === reps.length, "Error in transpose: rank of input " + x.rank + " " +

@@ -399,2 +408,3 @@ ("must match length of reps " + reps + "."));

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ x: x, indices: indices }, 'gather');
util.assert(indices.dtype === 'int32', 'Indices must be of dtype `int32`');

@@ -430,2 +440,3 @@ var axes = axis_util_1.parseAxisParam(axis, x.shape);

if (constantValue === void 0) { constantValue = 0; }
util.assertArgumentsAreTensors({ x: x }, 'pad');
if (x.rank === 0) {

@@ -442,2 +453,3 @@ throw new Error('pad(scalar) is not defined. Pass non-scalar to pad');

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ tensors: tensors }, 'stack');
util.assert(tensors.length >= 1, 'Pass at least one tensor to tf.stack');

@@ -462,2 +474,3 @@ if (tensors.length === 1) {

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ x: x }, 'split');
axis = axis_util_1.parseAxisParam(axis, x.shape)[0];

@@ -484,2 +497,3 @@ var splitSizes;

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ x: x }, 'expandDims');
util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor');

@@ -486,0 +500,0 @@ var newShape = x.shape.slice();

@@ -93,13 +93,13 @@ "use strict";

var varianceEpsilon = .001;
var dy = tf.tensor4d([1, 1, 1, 1], [2, 1, 1, 2]);
var dy = tf.tensor4d([-1, -1, -1, -1], [2, 1, 1, 2]);
var gradX = tf.grad(function (x) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(x, dy);
test_util_1.expectArraysClose(gradX, tf.tensor4d([1.414, 2.887, 1.414, 2.887], [2, 1, 1, 2]));
test_util_1.expectArraysClose(gradX, tf.tensor4d([-1.414, -2.887, -1.414, -2.887], [2, 1, 1, 2]));
var gradMean = tf.grad(function (mean) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(mean, dy);
test_util_1.expectArraysClose(gradMean, tf.tensor1d([-2.828, -5.773]));
test_util_1.expectArraysClose(gradMean, tf.tensor1d([2.828, 5.773]));
var gradVariance = tf.grad(function (variance) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(variance, dy);
test_util_1.expectArraysClose(gradVariance, tf.tensor1d([-1.413, -238.519]));
test_util_1.expectArraysClose(gradVariance, tf.tensor1d([1.413, 238.519]));
var gradOffset = tf.grad(function (offset) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(offset, dy);
test_util_1.expectArraysClose(gradOffset, tf.onesLike(offset).mul(tf.scalar(2)));
test_util_1.expectArraysClose(gradOffset, dy.sum([0, 1, 2]));
var gradScale = tf.grad(function (scale) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(scale, dy);
test_util_1.expectArraysClose(gradScale, tf.tensor1d([2.828, 286.318]));
test_util_1.expectArraysClose(gradScale, tf.tensor1d([-2.828, -286.318]));
});

@@ -113,13 +113,13 @@ it('batchnorm4D gradients, same shapes in x, mean and variance', function () {

var varianceEpsilon = .001;
var dy = tf.tensor4d([1, 1, 1, 1], [2, 1, 1, 2]);
var dy = tf.tensor4d([-1, -1, -1, -1], [2, 1, 1, 2]);
var gradX = tf.grad(function (x) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(x, dy);
test_util_1.expectArraysClose(gradX, tf.tensor4d([1.414, 2.500, 0.816, 1.768], [2, 1, 1, 2]));
test_util_1.expectArraysClose(gradX, tf.tensor4d([-1.414, -2.500, -0.816, -1.768], [2, 1, 1, 2]));
var gradMean = tf.grad(function (mean) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(mean, dy);
test_util_1.expectArraysClose(gradMean, tf.tensor4d([-1.414, -2.500, -0.816, -1.768], [2, 1, 1, 2]));
test_util_1.expectArraysClose(gradMean, tf.tensor4d([1.414, 2.500, 0.816, 1.768], [2, 1, 1, 2]));
var gradVariance = tf.grad(function (variance) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(variance, dy);
test_util_1.expectArraysClose(gradVariance, tf.tensor4d([-3.533, -4.686, -1.360, -2.762], [2, 1, 1, 2]));
test_util_1.expectArraysClose(gradVariance, tf.tensor4d([3.533, 4.686, 1.360, 2.762], [2, 1, 1, 2]));
var gradOffset = tf.grad(function (offset) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(offset, dy);
test_util_1.expectArraysClose(gradOffset, tf.onesLike(offset));
test_util_1.expectArraysClose(gradOffset, dy);
var gradScale = tf.grad(function (scale) { return tf.batchNormalization4d(x, mean, variance, varianceEpsilon, scale, offset); })(scale, dy);
test_util_1.expectArraysClose(gradScale, tf.tensor4d([7.069, 7.499, 8.164, 8.838], [2, 1, 1, 2]));
test_util_1.expectArraysClose(gradScale, tf.tensor4d([-7.069, -7.499, -8.164, -8.838], [2, 1, 1, 2]));
});

@@ -401,2 +401,41 @@ });

});
it('throws when passed x as a non-tensor', function () {
var mean = tf.tensor1d([1, 2]);
var variance = tf.tensor1d([2, 3]);
expect(function () { return tf.batchNormalization({}, mean, variance); })
.toThrowError(/Argument 'x' passed to 'batchNormalization' must be a Tensor/);
});
it('throws when passed mean as a non-tensor', function () {
var x = tf.tensor4d([2, 100, 4, 400], [2, 1, 1, 2]);
var variance = tf.tensor1d([2, 3]);
expect(function () { return tf.batchNormalization(x, {}, variance); })
.toThrowError(/Argument 'mean' passed to 'batchNormalization' must be a Tensor/);
});
it('throws when passed variance as a non-tensor', function () {
var x = tf.tensor4d([2, 100, 4, 400], [2, 1, 1, 2]);
var mean = tf.tensor1d([1, 2]);
var e = /Argument 'variance' passed to 'batchNormalization' must be a Tensor/;
expect(function () { return tf.batchNormalization(x, mean, {}); })
.toThrowError(e);
});
it('throws when passed scale as a non-tensor', function () {
var x = tf.tensor4d([2, 100, 4, 400], [2, 1, 1, 2]);
var mean = tf.tensor1d([1, 2]);
var variance = tf.tensor1d([2, 3]);
var epsilon = .001;
expect(function () {
return tf.batchNormalization(x, mean, variance, epsilon, {});
})
.toThrowError(/Argument 'scale' passed to 'batchNormalization' must be a Tensor/);
});
it('throws when passed offset as a non-tensor', function () {
var x = tf.tensor4d([2, 100, 4, 400], [2, 1, 1, 2]);
var mean = tf.tensor1d([1, 2]);
var variance = tf.tensor1d([2, 3]);
var epsilon = .001;
var scale = tf.tensor1d([0.62186907, 0.85673736, 0.19201061]);
var e = /Argument 'offset' passed to 'batchNormalization' must be a Tensor/;
expect(function () { return tf.batchNormalization(x, mean, variance, epsilon, scale, {}); })
.toThrowError(e);
});
});

56

dist/ops/batchnorm.js

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

var array_ops_1 = require("./array_ops");
var broadcast_util_1 = require("./broadcast_util");
var operation_1 = require("./operation");

@@ -75,2 +76,9 @@ var ops_1 = require("./ops");

if (varianceEpsilon === void 0) { varianceEpsilon = .001; }
util.assertArgumentsAreTensors({ x: x, mean: mean, variance: variance }, 'batchNormalization');
if (scale != null) {
util.assertArgumentsAreTensors({ scale: scale }, 'batchNormalization');
}
if (offset != null) {
util.assertArgumentsAreTensors({ offset: offset }, 'batchNormalization');
}
util.assert(mean.rank === variance.rank, 'Batch normalization gradient requires mean and variance to have ' +

@@ -97,16 +105,12 @@ 'equal ranks.');

var scaleValue = scale == null ? array_ops_1.ArrayOps.scalar(1) : scale;
var nonDepthMultiplier = 1;
var xMinusMean;
var reductionAxes = broadcast_util_1.getReductionAxes(mean.shape, x4D.shape);
var tileShape = [];
if (mean.rank === 1) {
for (var i = 0; i < x4D.shape.length - 1; ++i) {
nonDepthMultiplier *= x4D.shape[i];
tileShape.push(x4D.shape[i]);
}
tileShape.push(1);
xMinusMean = x.sub(mean).sum(0).reshape(mean.shape);
}
else {
xMinusMean = x.sub(mean);
}
var xMinusMean = x.sub(mean);
var dyTimesScaleValue = dy.mul(scaleValue);
var oneOverSqrtVariance = ops_1.rsqrt(variance.add(array_ops_1.ArrayOps.scalar(varianceEpsilon)));

@@ -118,4 +122,4 @@ var minusHalfRCube = oneOverSqrtVariance.mul(oneOverSqrtVariance)

if (mean.rank === 1) {
return array_ops_1.ArrayOps
.tile(oneOverSqrtVariance.as4D(1, 1, 1, mean.shape[0]), tileShape)
return dy
.mul(array_ops_1.ArrayOps.tile(oneOverSqrtVariance.as4D(1, 1, 1, mean.shape[0]), tileShape))
.mul(scaleValue)

@@ -125,27 +129,33 @@ .reshape(x.shape);

else {
return oneOverSqrtVariance.mul(scaleValue).reshape(x.shape);
return dy.mul(oneOverSqrtVariance).mul(scaleValue).reshape(x.shape);
}
};
var derMean = function () {
return oneOverSqrtVariance.mul(array_ops_1.ArrayOps.scalar(-1 * nonDepthMultiplier))
.mul(scaleValue)
.reshape(mean.shape);
var meanDer = oneOverSqrtVariance.mul(array_ops_1.ArrayOps.scalar(-1)).mul(dyTimesScaleValue);
if (mean.rank === 1) {
meanDer = meanDer.sum(reductionAxes);
}
return meanDer.reshape(mean.shape);
};
var derVariance = function () {
return minusHalfRCube.mul(xMinusMean)
.mul(scaleValue)
.reshape(variance.shape);
var varianceDer = minusHalfRCube.mul(xMinusMean).mul(dyTimesScaleValue);
if (mean.rank === 1) {
varianceDer = varianceDer.sum(reductionAxes);
}
return varianceDer.reshape(mean.shape);
};
var derScale = function () {
return xMinusMean.mul(oneOverSqrtVariance).reshape(mean.shape);
var xMinusMean2TimesRsqrt = xMinusMean.mul(oneOverSqrtVariance);
var scaleDer = dy.mul(xMinusMean2TimesRsqrt);
if (mean.rank === 1) {
scaleDer = scaleDer.sum(reductionAxes);
}
return scaleDer.reshape(mean.shape);
};
var derOffset = function () {
var offsetDer = dy;
if (mean.rank === 1) {
return array_ops_1.ArrayOps.onesLike(mean)
.mul(array_ops_1.ArrayOps.scalar(nonDepthMultiplier))
.reshape(mean.shape);
offsetDer = offsetDer.sum(reductionAxes);
}
else {
return array_ops_1.ArrayOps.onesLike(mean);
}
return offsetDer.reshape(mean.shape);
};

@@ -152,0 +162,0 @@ return {

@@ -22,2 +22,10 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
expect(function () { return tf.prelu({}, tf.scalar(1)); })
.toThrowError(/Argument 'x' passed to 'prelu' must be a Tensor/);
});
it('throws when passed alpha as a non-tensor', function () {
expect(function () { return tf.prelu(tf.scalar(1), {}); })
.toThrowError(/Argument 'alpha' passed to 'prelu' must be a Tensor/);
});
});

@@ -127,2 +135,10 @@ test_util_1.describeWithFlags('maximum', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.maximum({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'maximum' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.maximum(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'maximum' must be a Tensor/);
});
});

@@ -254,2 +270,10 @@ test_util_1.describeWithFlags('squaredDifference', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.squaredDifference({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'squaredDifference' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.squaredDifference(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'squaredDifference' must be a Tensor/);
});
});

@@ -359,2 +383,10 @@ test_util_1.describeWithFlags('minimum', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.minimum({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'minimum' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.minimum(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'minimum' must be a Tensor/);
});
});

@@ -494,2 +526,10 @@ test_util_1.describeWithFlags('mod', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.mod({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'mod' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.mod(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'mod' must be a Tensor/);
});
});

@@ -635,2 +675,10 @@ test_util_1.describeWithFlags('atan2', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.atan2({}, tf.scalar(1)); })
.toThrowError(/Argument 'a' passed to 'atan2' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.atan2(tf.scalar(1), {}); })
.toThrowError(/Argument 'b' passed to 'atan2' must be a Tensor/);
});
});

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

BinaryOps.add = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'add');
util.assertTypesMatch(a, b);

@@ -49,2 +50,3 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.sub = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'sub');
util.assertTypesMatch(a, b);

@@ -78,2 +80,3 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.pow = function (base, exp) {
util.assertArgumentsAreTensors({ base: base, exp: exp }, 'pow');
var outShape = broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape);

@@ -109,2 +112,3 @@ base = base.cast(types_1.upcastType(base.dtype, exp.dtype));

BinaryOps.mul = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'mul');
util.assertTypesMatch(a, b);

@@ -138,2 +142,3 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.div = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'div');
util.assertTypesMatch(a, b);

@@ -168,2 +173,3 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.mod = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'mod');
util.assertTypesMatch(a, b);

@@ -196,2 +202,3 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.minimum = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'minimum');
util.assertTypesMatch(a, b);

@@ -217,2 +224,3 @@ if (a.dtype === 'bool') {

BinaryOps.maximum = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'maximum');
util.assertTypesMatch(a, b);

@@ -238,2 +246,3 @@ if (a.dtype === 'bool') {

BinaryOps.squaredDifference = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'squaredDifference');
util.assertTypesMatch(a, b);

@@ -254,2 +263,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

BinaryOps.atan2 = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'atan2');
util.assertTypesMatch(a, b);

@@ -256,0 +266,0 @@ var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

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

CompareOps.notEqual = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'notEqual');
util.assertTypesMatch(a, b);

@@ -28,2 +29,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

CompareOps.less = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'less');
util.assertTypesMatch(a, b);

@@ -38,2 +40,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

CompareOps.equal = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'equal');
util.assertTypesMatch(a, b);

@@ -48,2 +51,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

CompareOps.lessEqual = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'lessEqual');
util.assertTypesMatch(a, b);

@@ -58,2 +62,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

CompareOps.greater = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'greater');
util.assertTypesMatch(a, b);

@@ -68,2 +73,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

CompareOps.greaterEqual = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'greaterEqual');
util.assertTypesMatch(a, b);

@@ -70,0 +76,0 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

@@ -210,1 +210,7 @@ "use strict";

});
test_util_1.describeWithFlags('concat throws for non-tensors', test_util_1.ALL_ENVS, function () {
it('throws when passed a non-tensor', function () {
expect(function () { return tf.concat([{}]); })
.toThrowError(/Argument 'tensors\[0\]' passed to 'concat' must be a Tensor/);
});
});

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

util.assert(tensors.length >= 1, 'Pass at least one tensor to concat');
util.assertArgumentsAreTensors({ tensors: tensors }, 'concat');
var result = tensors[0];

@@ -35,0 +36,0 @@ if (tensors.length === 1) {

import { Tensor2D, Tensor3D, Tensor4D } from '../tensor';
export declare class ConvOps {
static conv1d<T extends Tensor2D | Tensor3D>(input: T, filter: Tensor3D, stride: number, pad: 'valid' | 'same' | number, dataFormat?: 'NWC' | 'NCW', dilation?: number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;
static conv1d<T extends Tensor2D | Tensor3D>(x: T, filter: Tensor3D, stride: number, pad: 'valid' | 'same' | number, dataFormat?: 'NWC' | 'NCW', dilation?: number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;
static conv2d<T extends Tensor3D | Tensor4D>(x: T, filter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same' | number, dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number] | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;

@@ -8,4 +8,4 @@ static conv2dDerInput<T extends Tensor3D | Tensor4D>(xShape: [number, number, number, number] | [number, number, number], dy: T, filter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same' | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;

static conv2dTranspose<T extends Tensor3D | Tensor4D>(x: T, filter: Tensor4D, outputShape: [number, number, number, number] | [number, number, number], strides: [number, number] | number, pad: 'valid' | 'same' | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;
static depthwiseConv2d<T extends Tensor3D | Tensor4D>(input: T, filter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same' | number, dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number] | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;
static separableConv2d<T extends Tensor3D | Tensor4D>(input: T, depthwiseFilter: Tensor4D, pointwiseFilter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same', dilation?: [number, number] | number, dataFormat?: 'NHWC' | 'NCHW'): T;
static depthwiseConv2d<T extends Tensor3D | Tensor4D>(x: T, filter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same' | number, dataFormat?: 'NHWC' | 'NCHW', dilations?: [number, number] | number, dimRoundingMode?: 'floor' | 'round' | 'ceil'): T;
static separableConv2d<T extends Tensor3D | Tensor4D>(x: T, depthwiseFilter: Tensor4D, pointwiseFilter: Tensor4D, strides: [number, number] | number, pad: 'valid' | 'same', dilation?: [number, number] | number, dataFormat?: 'NHWC' | 'NCHW'): T;
}

@@ -17,12 +17,13 @@ "use strict";

}
ConvOps.conv1d = function (input, filter, stride, pad, dataFormat, dilation, dimRoundingMode) {
ConvOps.conv1d = function (x, filter, stride, pad, dataFormat, dilation, dimRoundingMode) {
if (dataFormat === void 0) { dataFormat = 'NWC'; }
if (dilation === void 0) { dilation = 1; }
var input3D = input;
util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv1d');
var x3D = x;
var reshapedTo3D = false;
if (input.rank === 2) {
if (x.rank === 2) {
reshapedTo3D = true;
input3D = input.as3D(1, input.shape[0], input.shape[1]);
x3D = x.as3D(1, x.shape[0], x.shape[1]);
}
util.assert(input3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + input3D.rank + ".");
util.assert(x3D.rank === 3, "Error in conv1d: input must be rank 3, but got rank " + x3D.rank + ".");
util.assert(filter.rank === 3, "Error in conv1d: filter must be rank 3, but got rank " +

@@ -34,3 +35,3 @@ (filter.rank + "."));

}
util.assert(input3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + input3D.shape[2] + ") must match " +
util.assert(x3D.shape[2] === filter.shape[1], "Error in conv1d: depth of input (" + x3D.shape[2] + ") must match " +
("input depth for filter " + filter.shape[1] + "."));

@@ -41,3 +42,3 @@ util.assert(eitherStridesOrDilationsAreOne(stride, dilation), 'Error in conv1D: Either stride or dilation must be 1.' +

var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]);
var input4D = input3D.as4D(input3D.shape[0], 1, input3D.shape[1], input3D.shape[2]);
var input4D = x3D.as4D(x3D.shape[0], 1, x3D.shape[1], x3D.shape[2]);
var strides = [1, stride];

@@ -55,2 +56,3 @@ var dilations = [1, dilation];

if (dilations === void 0) { dilations = [1, 1]; }
util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2d');
var x4D = x;

@@ -92,2 +94,3 @@ var reshapedTo4D = false;

ConvOps.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ dy: dy, filter: filter }, 'conv2dDerInput');
util.assert(xShape.length === dy.rank, "Length of inShape " +

@@ -128,2 +131,3 @@ ("(" + xShape.length + ") and rank of dy (" + dy.rank + ") must match"));

ConvOps.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ x: x, dy: dy }, 'conv2dDerFilter');
var x4D = x;

@@ -156,19 +160,21 @@ if (x.rank === 3) {

ConvOps.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2dTranspose');
return ConvOps.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode);
};
ConvOps.depthwiseConv2d = function (input, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
ConvOps.depthwiseConv2d = function (x, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {
if (dataFormat === void 0) { dataFormat = 'NHWC'; }
if (dilations === void 0) { dilations = [1, 1]; }
var input4D = input;
util.assertArgumentsAreTensors({ x: x, filter: filter }, 'depthwiseConv2d');
var x4D = x;
var reshapedTo4D = false;
if (input.rank === 3) {
if (x.rank === 3) {
reshapedTo4D = true;
input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]);
x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
}
util.assert(input4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " +
("rank " + input4D.rank + "."));
util.assert(x4D.rank === 4, "Error in depthwiseConv2D: input must be rank 4, but got " +
("rank " + x4D.rank + "."));
util.assert(filter.rank === 4, "Error in depthwiseConv2D: filter must be rank 4, but got rank " +
(filter.rank + "."));
util.assert(input4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " +
("(" + input4D.shape[3] + ") must match the inChannels dimension in ") +
util.assert(x4D.shape[3] === filter.shape[2], "Error in depthwiseConv2D: number of input channels " +
("(" + x4D.shape[3] + ") must match the inChannels dimension in ") +
("filter " + filter.shape[2] + "."));

@@ -184,4 +190,4 @@ if (dilations == null) {

}
var convInfo = conv_util.computeConv2DInfo(input4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);
var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(input4D, filter, convInfo); }, { input4D: input4D, filter: filter });
var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);
var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x4D: x4D, filter: filter });
if (reshapedTo4D) {

@@ -192,10 +198,11 @@ return res.as3D(res.shape[1], res.shape[2], res.shape[3]);

};
ConvOps.separableConv2d = function (input, depthwiseFilter, pointwiseFilter, strides, pad, dilation, dataFormat) {
ConvOps.separableConv2d = function (x, depthwiseFilter, pointwiseFilter, strides, pad, dilation, dataFormat) {
if (dilation === void 0) { dilation = [1, 1]; }
if (dataFormat === void 0) { dataFormat = 'NHWC'; }
var input4D = input;
util.assertArgumentsAreTensors({ x: x, depthwiseFilter: depthwiseFilter, pointwiseFilter: pointwiseFilter }, 'separableConv2d');
var x4D = x;
var reshapedTo4D = false;
if (input.rank === 3) {
if (x.rank === 3) {
reshapedTo4D = true;
input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]);
x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);
}

@@ -206,4 +213,4 @@ if (dataFormat === 'NCHW') {

}
util.assert(input4D.rank === 4, "Error in separableConv2d: input must be rank 4, but got " +
("rank " + input4D.rank + "."));
util.assert(x4D.rank === 4, "Error in separableConv2d: input must be rank 4, but got " +
("rank " + x4D.rank + "."));
util.assert(depthwiseFilter.rank === 4, "Error in separableConv2d: depthwise filter must be rank 4, but got " +

@@ -222,3 +229,3 @@ ("rank " + depthwiseFilter.rank + "."));

("but got " + pointwiseFilter.shape[2] + "."));
var depthwise = ConvOps.depthwiseConv2d(input4D, depthwiseFilter, strides, pad, dataFormat, dilation);
var depthwise = ConvOps.depthwiseConv2d(x4D, depthwiseFilter, strides, pad, dataFormat, dilation);
var pointwiseStride = 1;

@@ -225,0 +232,0 @@ var res = ConvOps.conv2d(depthwise, pointwiseFilter, pointwiseStride, 'valid', dataFormat);

@@ -128,2 +128,29 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
var inputDepth = 1;
var outputDepth = 1;
var fSize = 1;
var pad = 'same';
var stride = 2;
var dataFormat = 'NWC';
var dilation = 2;
var w = tf.tensor3d([3], [fSize, inputDepth, outputDepth]);
expect(function () {
return tf.conv1d({}, w, stride, pad, dataFormat, dilation);
})
.toThrowError(/Argument 'x' passed to 'conv1d' must be a Tensor/);
});
it('throws when passed filter as a non-tensor', function () {
var inputDepth = 1;
var inputShape = [2, 2, inputDepth];
var pad = 'same';
var stride = 2;
var dataFormat = 'NWC';
var dilation = 2;
var x = tf.tensor3d([1, 2, 3, 4], inputShape);
expect(function () {
return tf.conv1d(x, {}, stride, pad, dataFormat, dilation);
})
.toThrowError(/Argument 'filter' passed to 'conv1d' must be a Tensor/);
});
});

@@ -221,2 +221,27 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
var inputDepth = 1;
var outputDepth = 1;
var fSize = 1;
var pad = 'same';
var stride = 2;
var dataFormat = 'NHWC';
var dilation = 2;
var w = tf.tensor4d([3], [fSize, fSize, inputDepth, outputDepth]);
var e = /Argument 'x' passed to 'depthwiseConv2d' must be a Tensor/;
expect(function () { return tf.depthwiseConv2d({}, w, stride, pad, dataFormat, dilation); })
.toThrowError(e);
});
it('throws when passed filter as a non-tensor', function () {
var inputDepth = 1;
var inputShape = [2, 2, inputDepth];
var pad = 'same';
var stride = 2;
var dataFormat = 'NHWC';
var dilation = 2;
var x = tf.tensor3d([1, 2, 3, 4], inputShape);
var e = /Argument 'filter' passed to 'depthwiseConv2d' must be a Tensor/;
expect(function () { return tf.depthwiseConv2d(x, {}, stride, pad, dataFormat, dilation); })
.toThrowError(e);
});
});

@@ -238,2 +238,41 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
var fSize = 2;
var pad = 'valid';
var stride = 1;
var chMul = 1;
var inDepth = 1;
var outDepth = 2;
var depthwiseFilter = tf.zeros([fSize, fSize, inDepth, chMul]);
var pointwiseFilter = tf.zeros([1, 1, inDepth * chMul, outDepth]);
var e = /Argument 'x' passed to 'separableConv2d' must be a Tensor/;
expect(function () { return tf.separableConv2d({}, depthwiseFilter, pointwiseFilter, stride, pad); })
.toThrowError(e);
});
it('throws when passed depthwiseFilter as a non-tensor', function () {
var pad = 'valid';
var stride = 1;
var chMul = 1;
var inDepth = 1;
var outDepth = 2;
var x = tf.zeros([1, 3, 3, inDepth]);
var pointwiseFilter = tf.zeros([1, 1, inDepth * chMul, outDepth]);
var e = new RegExp('Argument \'depthwiseFilter\' passed to \'separableConv2d\'' +
' must be a Tensor');
expect(function () { return tf.separableConv2d(x, {}, pointwiseFilter, stride, pad); })
.toThrowError(e);
});
it('throws when passed pointwiseFilter as a non-tensor', function () {
var fSize = 2;
var pad = 'valid';
var stride = 1;
var chMul = 1;
var inDepth = 1;
var x = tf.zeros([1, 3, 3, inDepth]);
var depthwiseFilter = tf.zeros([fSize, fSize, inDepth, chMul]);
var e = new RegExp('Argument \'pointwiseFilter\' passed to \'separableConv2d\'' +
' must be a Tensor');
expect(function () { return tf.separableConv2d(x, depthwiseFilter, {}, stride, pad); })
.toThrowError(e);
});
});

@@ -163,2 +163,21 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
var inputDepth = 1;
var outputDepth = 1;
var fSize = 1;
var pad = 0;
var stride = 1;
var w = tf.tensor4d([2], [fSize, fSize, inputDepth, outputDepth]);
expect(function () { return tf.conv2d({}, w, stride, pad); })
.toThrowError(/Argument 'x' passed to 'conv2d' must be a Tensor/);
});
it('throws when passed filter as a non-tensor', function () {
var inputDepth = 1;
var inputShape = [2, 2, inputDepth];
var pad = 0;
var stride = 1;
var x = tf.tensor3d([1, 2, 3, 4], inputShape);
expect(function () { return tf.conv2d(x, {}, stride, pad); })
.toThrowError(/Argument 'filter' passed to 'conv2d' must be a Tensor/);
});
});

@@ -70,2 +70,21 @@ "use strict";

});
it('throws when passed x as a non-tensor', function () {
var origInputDepth = 1;
var origOutputDepth = 1;
var fSize = 2;
var origPad = 0;
var origStride = 1;
var w = tf.tensor4d([3, 1, 5, 0], [fSize, fSize, origInputDepth, origOutputDepth]);
expect(function () { return tf.conv2dTranspose({}, w, [2, 2, 1], origStride, origPad); })
.toThrowError(/Argument 'x' passed to 'conv2dTranspose' must be a Tensor/);
});
it('throws when passed filter as a non-tensor', function () {
var origOutputDepth = 1;
var inputShape = [1, 1, origOutputDepth];
var origPad = 0;
var origStride = 1;
var x = tf.tensor3d([2], inputShape);
expect(function () { return tf.conv2dTranspose(x, {}, [2, 2, 1], origStride, origPad); })
.toThrowError(/Argument 'filter' passed to 'conv2dTranspose' must be a Tensor/);
});
});

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

if (alignCorners === void 0) { alignCorners = false; }
util.assertArgumentsAreTensors({ images: images }, 'resizeBilinear');
util.assert(images.rank === 3 || images.rank === 4, "Error in resizeBilinear: x must be rank 3 or 4, but got " +

@@ -39,2 +40,3 @@ ("rank " + images.rank + "."));

if (alignCorners === void 0) { alignCorners = false; }
util.assertArgumentsAreTensors({ images: images }, 'resizeNearestNeighbor');
util.assert(images.rank === 3 || images.rank === 4, "Error in resizeNearestNeighbor: x must be rank 3 or 4, but got " +

@@ -41,0 +43,0 @@ ("rank " + images.rank + "."));

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

LogicalOps.logicalNot = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'logicalNot');
util.assert(x.dtype === 'bool', 'Error Array must be of type bool.');

@@ -24,2 +25,3 @@ return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalNot(x); }, { x: x });

LogicalOps.logicalAnd = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalAnd');
util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');

@@ -30,2 +32,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

LogicalOps.logicalOr = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalOr');
util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');

@@ -36,2 +39,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

LogicalOps.logicalXor = function (a, b) {
util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalXor');
util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');

@@ -42,2 +46,3 @@ broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);

LogicalOps.where = function (condition, a, b) {
util.assertArgumentsAreTensors({ condition: condition, a: a, b: b }, 'where');
util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.');

@@ -44,0 +49,0 @@ util.assertShapesMatch(a.shape, b.shape, 'Error in where: ');

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.logicalNot({}); })
.toThrowError(/Argument 'x' passed to 'logicalNot' must be a Tensor/);
});
});

@@ -106,2 +110,10 @@ test_util_1.describeWithFlags('logicalAnd', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.logicalAnd({}, tf.scalar(1, 'bool')); })
.toThrowError(/Argument 'a' passed to 'logicalAnd' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.logicalAnd(tf.scalar(1, 'bool'), {}); })
.toThrowError(/Argument 'b' passed to 'logicalAnd' must be a Tensor/);
});
});

@@ -170,2 +182,10 @@ test_util_1.describeWithFlags('logicalOr', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.logicalOr({}, tf.scalar(1, 'bool')); })
.toThrowError(/Argument 'a' passed to 'logicalOr' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.logicalOr(tf.scalar(1, 'bool'), {}); })
.toThrowError(/Argument 'b' passed to 'logicalOr' must be a Tensor/);
});
});

@@ -234,2 +254,10 @@ test_util_1.describeWithFlags('logicalXor', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.logicalXor({}, tf.scalar(1, 'bool')); })
.toThrowError(/Argument 'a' passed to 'logicalXor' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.logicalXor(tf.scalar(1, 'bool'), {}); })
.toThrowError(/Argument 'b' passed to 'logicalXor' must be a Tensor/);
});
});

@@ -409,2 +437,14 @@ test_util_1.describeWithFlags('where', test_util_1.ALL_ENVS, function () {

});
it('throws when passed condition as a non-tensor', function () {
expect(function () { return tf.where({}, tf.scalar(1, 'bool'), tf.scalar(1, 'bool')); })
.toThrowError(/Argument 'condition' passed to 'where' must be a Tensor/);
});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.where(tf.scalar(1, 'bool'), {}, tf.scalar(1, 'bool')); })
.toThrowError(/Argument 'a' passed to 'where' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.where(tf.scalar(1, 'bool'), tf.scalar(1, 'bool'), {}); })
.toThrowError(/Argument 'b' passed to 'where' must be a Tensor/);
});
});

@@ -110,2 +110,14 @@ "use strict";

});
it('throws when passed losses as a non-tensor', function () {
var weights = tf.tensor2d([1, 0, 2, -5, 0, 6], [2, 3]);
var e = /Argument 'losses' passed to 'computeWeightedLoss' must be a Tensor/;
expect(function () { return tf.losses.computeWeightedLoss({}, weights, tf.Reduction.NONE); })
.toThrowError(e);
});
it('throws when passed weights as a non-tensor', function () {
var losses = tf.tensor2d([4, 8, 12, 8, 1, 3], [2, 3]);
var e = /Argument 'weights' passed to 'computeWeightedLoss' must be a Tensor/;
expect(function () { return tf.losses.computeWeightedLoss(losses, {}, tf.Reduction.NONE); })
.toThrowError(e);
});
});

@@ -209,2 +221,24 @@ test_util_1.describeWithFlags('absoluteDifference', test_util_1.ALL_ENVS, function () {

});
it('throws when passed label as a non-tensor', function () {
var predictions = tf.tensor2d([4, 8, 12, 8, 1, 3], [2, 3]);
var weights = tf.tensor2d([3, 6, 5, 0, 4, 2], [2, 3]);
var e = /Argument 'labels' passed to 'absoluteDifference' must be a Tensor/;
expect(function () { return tf.losses.absoluteDifference({}, predictions, weights, tf.Reduction.MEAN); })
.toThrowError(e);
});
it('throws when passed label as a non-tensor', function () {
var label = tf.tensor2d([1, 9, 2, -5, -2, 6], [2, 3]);
var weights = tf.tensor2d([3, 6, 5, 0, 4, 2], [2, 3]);
var e = new RegExp('Argument \'predictions\' passed to \'absoluteDifference\' ' +
'must be a Tensor');
expect(function () { return tf.losses.absoluteDifference(label, {}, weights, tf.Reduction.MEAN); })
.toThrowError(e);
});
it('throws when passed weights as a non-tensor', function () {
var predictions = tf.tensor2d([4, 8, 12, 8, 1, 3], [2, 3]);
var label = tf.tensor2d([1, 9, 2, -5, -2, 6], [2, 3]);
var e = /Argument 'weights' passed to 'absoluteDifference' must be a Tensor/;
expect(function () { return tf.losses.absoluteDifference(label, predictions, {}, tf.Reduction.MEAN); })
.toThrowError(e);
});
});

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

if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
util.assertArgumentsAreTensors({ losses: losses }, 'computeWeightedLoss');
if (weights != null) {
util.assertArgumentsAreTensors({ weights: weights }, 'computeWeightedLoss');
}
var weightedLoss = (weights == null) ? losses : losses.mul(weights);

@@ -50,2 +54,6 @@ if (reduction === Reduction.NONE) {

if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }
util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'absoluteDifference');
if (weights != null) {
util.assertArgumentsAreTensors({ weights: weights }, 'absoluteDifference');
}
util.assertShapesMatch(labels.shape, predictions.shape, 'Error in absoluteDifference: ');

@@ -52,0 +60,0 @@ var losses = labels.sub(predictions).abs();

@@ -445,2 +445,7 @@ "use strict";

});
it('throws when passed a non-tensor', function () {
var e = /Argument 'x' passed to 'localResponseNormalization' must be a Tensor/;
expect(function () { return tf.localResponseNormalization({}); })
.toThrowError(e);
});
});

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

if (beta === void 0) { beta = 0.5; }
util.assertArgumentsAreTensors({ x: x }, 'localResponseNormalization');
util.assert(x.rank === 4 || x.rank === 3, "Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank " + x.rank + ".");

@@ -23,0 +24,0 @@ util.assert(util.isInt(radius), "Error in localResponseNormalization3D: radius must be an integer\n but got radius " + radius + ".");

@@ -58,1 +58,137 @@ "use strict";

});
test_util_1.describeWithFlags('multiRNN throws when passed non-tensor', test_util_1.CPU_ENVS, function () {
it('input: data', function () {
var lstmKernel1 = tf.zeros([3, 4]);
var lstmBias1 = tf.zeros([4]);
var lstmKernel2 = tf.zeros([2, 4]);
var lstmBias2 = tf.zeros([4]);
var forgetBias = tf.scalar(1.0);
var lstm1 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel1, lstmBias1, data, c, h);
};
var lstm2 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel2, lstmBias2, data, c, h);
};
var c = [
tf.zeros([1, lstmBias1.shape[0] / 4]),
tf.zeros([1, lstmBias2.shape[0] / 4])
];
var h = [
tf.zeros([1, lstmBias1.shape[0] / 4]),
tf.zeros([1, lstmBias2.shape[0] / 4])
];
expect(function () { return tf.multiRNNCell([lstm1, lstm2], {}, c, h); })
.toThrowError(/Argument 'data' passed to 'multiRNNCell' must be a Tensor/);
});
it('input: c', function () {
var lstmKernel1 = tf.zeros([3, 4]);
var lstmBias1 = tf.zeros([4]);
var lstmKernel2 = tf.zeros([2, 4]);
var lstmBias2 = tf.zeros([4]);
var forgetBias = tf.scalar(1.0);
var lstm1 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel1, lstmBias1, data, c, h);
};
var lstm2 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel2, lstmBias2, data, c, h);
};
var h = [
tf.zeros([1, lstmBias1.shape[0] / 4]),
tf.zeros([1, lstmBias2.shape[0] / 4])
];
var data = tf.zeros([1, 2]);
expect(function () { return tf.multiRNNCell([lstm1, lstm2], data, [{}], h); })
.toThrowError(/Argument 'c\[0\]' passed to 'multiRNNCell' must be a Tensor/);
});
it('input: h', function () {
var lstmKernel1 = tf.zeros([3, 4]);
var lstmBias1 = tf.zeros([4]);
var lstmKernel2 = tf.zeros([2, 4]);
var lstmBias2 = tf.zeros([4]);
var forgetBias = tf.scalar(1.0);
var lstm1 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel1, lstmBias1, data, c, h);
};
var lstm2 = function (data, c, h) {
return tf.basicLSTMCell(forgetBias, lstmKernel2, lstmBias2, data, c, h);
};
var c = [
tf.zeros([1, lstmBias1.shape[0] / 4]),
tf.zeros([1, lstmBias2.shape[0] / 4])
];
var data = tf.zeros([1, 2]);
expect(function () { return tf.multiRNNCell([lstm1, lstm2], data, c, [{}]); })
.toThrowError(/Argument 'h\[0\]' passed to 'multiRNNCell' must be a Tensor/);
});
});
test_util_1.describeWithFlags('basicLSTMCell throws with non-tensor', test_util_1.CPU_ENVS, function () {
it('input: forgetBias', function () {
var lstmKernel = tf.randomNormal([3, 4]);
var lstmBias = tf.randomNormal([4]);
var data = tf.randomNormal([1, 2]);
var batchedData = tf.concat2d([data, data], 0);
var c = tf.randomNormal([1, 1]);
var batchedC = tf.concat2d([c, c], 0);
var h = tf.randomNormal([1, 1]);
var batchedH = tf.concat2d([h, h], 0);
expect(function () { return tf.basicLSTMCell({}, lstmKernel, lstmBias, batchedData, batchedC, batchedH); })
.toThrowError(/Argument 'forgetBias' passed to 'basicLSTMCell' must be a Tensor/);
});
it('input: lstmKernel', function () {
var lstmBias = tf.randomNormal([4]);
var forgetBias = tf.scalar(1.0);
var data = tf.randomNormal([1, 2]);
var batchedData = tf.concat2d([data, data], 0);
var c = tf.randomNormal([1, 1]);
var batchedC = tf.concat2d([c, c], 0);
var h = tf.randomNormal([1, 1]);
var batchedH = tf.concat2d([h, h], 0);
expect(function () { return tf.basicLSTMCell(forgetBias, {}, lstmBias, batchedData, batchedC, batchedH); })
.toThrowError(/Argument 'lstmKernel' passed to 'basicLSTMCell' must be a Tensor/);
});
it('input: lstmBias', function () {
var lstmKernel = tf.randomNormal([3, 4]);
var forgetBias = tf.scalar(1.0);
var data = tf.randomNormal([1, 2]);
var batchedData = tf.concat2d([data, data], 0);
var c = tf.randomNormal([1, 1]);
var batchedC = tf.concat2d([c, c], 0);
var h = tf.randomNormal([1, 1]);
var batchedH = tf.concat2d([h, h], 0);
expect(function () { return tf.basicLSTMCell(forgetBias, lstmKernel, {}, batchedData, batchedC, batchedH); })
.toThrowError(/Argument 'lstmBias' passed to 'basicLSTMCell' must be a Tensor/);
});
it('input: data', function () {
var lstmKernel = tf.randomNormal([3, 4]);
var lstmBias = tf.randomNormal([4]);
var forgetBias = tf.scalar(1.0);
var c = tf.randomNormal([1, 1]);
var batchedC = tf.concat2d([c, c], 0);
var h = tf.randomNormal([1, 1]);
var batchedH = tf.concat2d([h, h], 0);
expect(function () { return tf.basicLSTMCell(forgetBias, lstmKernel, lstmBias, {}, batchedC, batchedH); })
.toThrowError(/Argument 'data' passed to 'basicLSTMCell' must be a Tensor/);
});
it('input: c', function () {
var lstmKernel = tf.randomNormal([3, 4]);
var lstmBias = tf.randomNormal([4]);
var forgetBias = tf.scalar(1.0);
var data = tf.randomNormal([1, 2]);
var batchedData = tf.concat2d([data, data], 0);
var h = tf.randomNormal([1, 1]);
var batchedH = tf.concat2d([h, h], 0);
expect(function () { return tf.basicLSTMCell(forgetBias, lstmKernel, lstmBias, batchedData, {}, batchedH); })
.toThrowError(/Argument 'c' passed to 'basicLSTMCell' must be a Tensor/);
});
it('input: h', function () {
var lstmKernel = tf.randomNormal([3, 4]);
var lstmBias = tf.randomNormal([4]);
var forgetBias = tf.scalar(1.0);
var data = tf.randomNormal([1, 2]);
var batchedData = tf.concat2d([data, data], 0);
var c = tf.randomNormal([1, 1]);
var batchedC = tf.concat2d([c, c], 0);
expect(function () { return tf.basicLSTMCell(forgetBias, lstmKernel, lstmBias, batchedData, batchedC, {}); })
.toThrowError(/Argument 'h' passed to 'basicLSTMCell' must be a Tensor/);
});
});

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

var doc_1 = require("../doc");
var util = require("../util");
var operation_1 = require("./operation");

@@ -16,2 +17,3 @@ var LSTMOps = (function () {

LSTMOps.multiRNNCell = function (lstmCells, data, c, h) {
util.assertArgumentsAreTensors({ data: data, c: c, h: h }, 'multiRNNCell');
var input = data;

@@ -34,2 +36,3 @@ var newStates = [];

LSTMOps.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) {
util.assertArgumentsAreTensors({ forgetBias: forgetBias, lstmKernel: lstmKernel, lstmBias: lstmBias, data: data, c: c, h: h }, 'basicLSTMCell');
var combined = data.concat(h, 1);

@@ -36,0 +39,0 @@ var weighted = combined.matMul(lstmKernel);

@@ -290,2 +290,10 @@ "use strict";

});
it('throws when passed a as a non-tensor', function () {
expect(function () { return tf.matMul({}, tf.tensor2d([2], [1, 1])); })
.toThrowError(/Argument 'a' passed to 'matMul' must be a Tensor/);
});
it('throws when passed b as a non-tensor', function () {
expect(function () { return tf.matMul(tf.tensor2d([2], [1, 1]), {}); })
.toThrowError(/Argument 'b' passed to 'matMul' must be a Tensor/);
});
});

@@ -292,0 +300,0 @@ test_util_1.describeWithFlags('matmul webgl-only', test_util_1.WEBGL_ENVS, function () {

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

if (transposeB === void 0) { transposeB = false; }
util.assertArgumentsAreTensors({ a: a, b: b }, 'matMul');
var innerShapeA = transposeA ? a.shape[0] : a.shape[1];

@@ -21,0 +22,0 @@ var innerShapeB = transposeB ? b.shape[1] : b.shape[0];

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

var test_util_1 = require("../test_util");
var moving_average_1 = require("./moving_average");
test_util_1.describeWithFlags('movingAverage', test_util_1.ALL_ENVS, function () {

@@ -12,6 +11,6 @@ it('zeroDebias=true, decay and step are numbers', function () {

var decay = 0.6;
var v1 = moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, 1);
var v1 = tf.movingAverage(v0, x, decay, 1);
test_util_1.expectArraysClose(v1, tf.tensor2d([[1, 2], [3, 4]], [2, 2]));
var y = tf.tensor2d([[11, 12], [13, 14]], [2, 2]);
var v2 = moving_average_1.MovingAverageOps.movingAverage(v1, y, decay, 2);
var v2 = tf.movingAverage(v1, y, decay, 2);
test_util_1.expectArraysClose(v2, tf.tensor2d([[7.25, 8.25], [9.25, 10.25]], [2, 2]));

@@ -23,6 +22,6 @@ });

var decay = tf.scalar(0.6);
var v1 = moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, tf.scalar(1));
var v1 = tf.movingAverage(v0, x, decay, tf.scalar(1));
test_util_1.expectArraysClose(v1, tf.tensor2d([[1, 2], [3, 4]], [2, 2]));
var y = tf.tensor2d([[11, 12], [13, 14]], [2, 2]);
var v2 = moving_average_1.MovingAverageOps.movingAverage(v1, y, decay, tf.scalar(2));
var v2 = tf.movingAverage(v1, y, decay, tf.scalar(2));
test_util_1.expectArraysClose(v2, tf.tensor2d([[7.25, 8.25], [9.25, 10.25]], [2, 2]));

@@ -34,6 +33,6 @@ });

var decay = 0.6;
var v1 = moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, null, false);
var v1 = tf.movingAverage(v0, x, decay, null, false);
test_util_1.expectArraysClose(v1, tf.tensor2d([[0.4, 0.8], [1.2, 1.6]], [2, 2]));
var y = tf.tensor2d([[11, 12], [13, 14]], [2, 2]);
var v2 = moving_average_1.MovingAverageOps.movingAverage(v1, y, decay, null, false);
var v2 = tf.movingAverage(v1, y, decay, null, false);
test_util_1.expectArraysClose(v2, tf.tensor2d([[4.64, 5.28], [5.92, 6.56]], [2, 2]));

@@ -45,6 +44,6 @@ });

var decay = tf.scalar(0.6);
var v1 = moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, null, false);
var v1 = tf.movingAverage(v0, x, decay, null, false);
test_util_1.expectArraysClose(v1, tf.tensor2d([[0.4, 0.8], [1.2, 1.6]], [2, 2]));
var y = tf.tensor2d([[11, 12], [13, 14]], [2, 2]);
var v2 = moving_average_1.MovingAverageOps.movingAverage(v1, y, decay, null, false);
var v2 = tf.movingAverage(v1, y, decay, null, false);
test_util_1.expectArraysClose(v2, tf.tensor2d([[4.64, 5.28], [5.92, 6.56]], [2, 2]));

@@ -56,4 +55,3 @@ });

var decay = tf.scalar(0.6);
expect(function () { return moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, null); })
.toThrowError();
expect(function () { return tf.movingAverage(v0, x, decay, null); }).toThrowError();
});

@@ -64,5 +62,14 @@ it('shape mismatch in v and x throws error', function () {

var decay = tf.scalar(0.6);
expect(function () { return moving_average_1.MovingAverageOps.movingAverage(v0, x, decay, null); })
.toThrowError();
expect(function () { return tf.movingAverage(v0, x, decay, null); }).toThrowError();
});
it('throws when passed v as a non-tensor', function () {
var x = tf.tensor2d([[1, 2], [3, 4]], [2, 2]);
expect(function () { return tf.movingAverage({}, x, 1); })
.toThrowError(/Argument 'v' passed to 'movingAverage' must be a Tensor/);
});
it('throws when passed v as a non-tensor', function () {
var v = tf.tensor2d([[0, 0], [0, 0]], [2, 2]);
expect(function () { return tf.movingAverage(v, {}, 1); })
.toThrowError(/Argument 'x' passed to 'movingAverage' must be a Tensor/);
});
});

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

if (zeroDebias === void 0) { zeroDebias = true; }
util.assertArgumentsAreTensors({ v: v, x: x }, 'movingAverage');
util.assertTypesMatch(v, x);

@@ -21,0 +22,0 @@ util.assert(util.arraysEqual(v.shape, x.shape), 'Shape mismatch in v and x');

@@ -72,2 +72,7 @@ "use strict";

});
it('throws when passed a non-tensor', function () {
var seed = null;
expect(function () { return tf.multinomial({}, NUM_SAMPLES, seed); })
.toThrowError(/Argument 'logits' passed to 'multinomial' must be a Tensor/);
});
function computeProbs(events, numOutcomes) {

@@ -74,0 +79,0 @@ var counts = [];

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

var doc_1 = require("../doc");
var util = require("../util");
var axis_util = require("./axis_util");

@@ -21,2 +22,3 @@ var operation_1 = require("./operation");

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'norm');
var norm = normImpl(x, ord, axis);

@@ -23,0 +25,0 @@ var keepDimsShape = norm.shape;

@@ -114,2 +114,3 @@ import { ArrayOps } from './array_ops';

export declare const tanh: typeof UnaryOps.tanh;
export declare const erf: typeof UnaryOps.erf;
export declare const add: typeof BinaryOps.add;

@@ -116,0 +117,0 @@ export declare const addStrict: typeof BinaryOps.addStrict;

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

exports.tanh = unary_ops_1.UnaryOps.tanh;
exports.erf = unary_ops_1.UnaryOps.erf;
exports.add = binary_ops_1.BinaryOps.add;

@@ -118,0 +119,0 @@ exports.addStrict = binary_ops_1.BinaryOps.addStrict;

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.pad({}, [[0, 0]]); })
.toThrowError(/Argument 'x' passed to 'pad' must be a Tensor/);
});
});

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.maxPool({}, 2, 1, 'valid'); })
.toThrowError(/Argument 'x' passed to 'maxPool' must be a Tensor/);
});
});

@@ -290,2 +294,6 @@ test_util_1.describeWithFlags('maxPoolBackprop', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.avgPool({}, 2, 1, 'valid'); })
.toThrowError(/Argument 'x' passed to 'avgPool' must be a Tensor/);
});
});

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

PoolOps.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ x: x }, 'maxPool');
var x4D = x;

@@ -44,2 +45,3 @@ var reshapedTo4D = false;

PoolOps.maxPoolBackprop = function (dy, input, output, filterSize, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ dy: dy, input: input, output: output }, 'maxPoolBackprop');
util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")");

@@ -59,2 +61,3 @@ util.assert(dy.rank === 4, "Error in maxPoolBackprop: dy must be rank 4 but got rank " +

PoolOps.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) {
util.assertArgumentsAreTensors({ x: x }, 'avgPool');
util.assert(x.dtype === 'float32', 'The input dtype to avgPool must be float32');

@@ -86,2 +89,3 @@ var x4D = x;

PoolOps.avgPoolBackprop = function (dy, input, filterSize, strides, pad) {
util.assertArgumentsAreTensors({ dy: dy, input: input }, 'avgPoolBackprop');
util.assert(input.rank === dy.rank, "Rank of input (" + input.rank + ") does not match rank of dy (" + dy.rank + ")");

@@ -88,0 +92,0 @@ var input4D = input;

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.min({}); })
.toThrowError(/Argument 'x' passed to 'min' must be a Tensor/);
});
});

@@ -101,2 +105,6 @@ test_util_1.describeWithFlags('max', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.max({}); })
.toThrowError(/Argument 'x' passed to 'max' must be a Tensor/);
});
});

@@ -156,2 +164,6 @@ test_util_1.describeWithFlags('argmax', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.argMax({}); })
.toThrowError(/Argument 'x' passed to 'argMax' must be a Tensor/);
});
});

@@ -206,2 +218,6 @@ test_util_1.describeWithFlags('argmin', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.argMin({}); })
.toThrowError(/Argument 'x' passed to 'argMin' must be a Tensor/);
});
});

@@ -284,2 +300,6 @@ test_util_1.describeWithFlags('logSumExp', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.logSumExp({}); })
.toThrowError(/Argument 'x' passed to 'logSumExp' must be a Tensor/);
});
});

@@ -380,2 +400,6 @@ test_util_1.describeWithFlags('sum', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.sum({}); })
.toThrowError(/Argument 'x' passed to 'sum' must be a Tensor/);
});
});

@@ -471,2 +495,6 @@ test_util_1.describeWithFlags('mean', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.mean({}); })
.toThrowError(/Argument 'x' passed to 'mean' must be a Tensor/);
});
});

@@ -566,2 +594,6 @@ test_util_1.describeWithFlags('moments', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.moments({}); })
.toThrowError(/Argument 'x' passed to 'moments' must be a Tensor/);
});
});

@@ -760,2 +792,6 @@ test_util_1.describeWithFlags('norm', test_util_1.ALL_ENVS, function () {

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.norm({}); })
.toThrowError(/Argument 'x' passed to 'norm' must be a Tensor/);
});
});
import { Tensor } from '../tensor';
export declare class ReductionOps {
static logSumExp<T extends Tensor>(input: Tensor, axis?: number | number[], keepDims?: boolean): T;
static logSumExp<T extends Tensor>(x: Tensor, axis?: number | number[], keepDims?: boolean): T;
static sum<T extends Tensor>(x: Tensor, axis?: number | number[], keepDims?: boolean): T;

@@ -5,0 +5,0 @@ static mean<T extends Tensor>(x: Tensor, axis?: number | number[], keepDims?: boolean): T;

@@ -19,8 +19,9 @@ "use strict";

}
ReductionOps.logSumExp = function (input, axis, keepDims) {
ReductionOps.logSumExp = function (x, axis, keepDims) {
if (axis === void 0) { axis = null; }
if (keepDims === void 0) { keepDims = false; }
var axes = axis_util.parseAxisParam(axis, input.shape);
var xMax = input.max(axes, true);
var a = input.sub(xMax);
util.assertArgumentsAreTensors({ x: x }, 'logSumExp');
var axes = axis_util.parseAxisParam(axis, x.shape);
var xMax = x.max(axes, true);
var a = x.sub(xMax);
var b = a.exp();

@@ -39,2 +40,3 @@ var c = b.sum(axes);

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'sum');
if (x.dtype === 'bool') {

@@ -74,2 +76,3 @@ x = x.toInt();

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'mean');
var axes = axis_util.parseAxisParam(axis, x.shape);

@@ -102,2 +105,3 @@ var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes);

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'min');
var origAxes = axis_util.parseAxisParam(axis, x.shape);

@@ -120,2 +124,3 @@ var axes = origAxes;

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'max');
var origAxes = axis_util.parseAxisParam(axis, x.shape);

@@ -137,2 +142,3 @@ var axes = origAxes;

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ x: x }, 'argMin');
if (axis == null) {

@@ -151,2 +157,3 @@ axis = 0;

if (axis === void 0) { axis = 0; }
util.assertArgumentsAreTensors({ x: x }, 'argMax');
if (axis == null) {

@@ -166,2 +173,3 @@ axis = 0;

if (keepDims === void 0) { keepDims = false; }
util.assertArgumentsAreTensors({ x: x }, 'moments');
var axes = axis_util.parseAxisParam(axis, x.shape);

@@ -168,0 +176,0 @@ var mean = x.mean(axes, keepDims);

@@ -55,2 +55,8 @@ "use strict";

});
it('throws when passed a non-tensor', function () {
var e = /Argument 'images' passed to 'resizeBilinear' must be a Tensor/;
expect(function () { return tf.image.resizeBilinear({}, [
1, 1
]); }).toThrowError(e);
});
});

@@ -55,2 +55,8 @@ "use strict";

});
it('throws when passed a non-tensor', function () {
var e = /Argument 'images' passed to 'resizeNearestNeighbor' must be a Tensor/;
expect(function () { return tf.image.resizeNearestNeighbor({}, [
1, 1
]); }).toThrowError(e);
});
});

@@ -232,1 +232,7 @@ "use strict";

});
test_util_1.describeWithFlags('reverse', test_util_1.CPU_ENVS, function () {
it('throws when passed a non-tensor', function () {
expect(function () { return tf.reverse({}); })
.toThrowError(/Argument 'x' passed to 'reverse' must be a Tensor/);
});
});

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

ReverseOps.reverse = function (x, axis) {
util.assertArgumentsAreTensors({ x: x }, 'reverse');
if (x.rank === 0) {

@@ -36,0 +37,0 @@ return x.clone();

@@ -86,2 +86,22 @@ "use strict";

});
test_util_1.describeWithFlags('slice4d', test_util_1.ALL_ENVS, function () {
it('slices 1x1x1x1 into shape 1x1x1x1 (effectively a copy)', function () {
var a = tf.tensor4d([[[[5]]]], [1, 1, 1, 1]);
var result = a.slice([0, 0, 0, 0], [1, 1, 1, 1]);
expect(result.shape).toEqual([1, 1, 1, 1]);
test_util_1.expectArraysClose(result, [5]);
});
it('slices 2x2x2x2 array into 1x2x2x2 starting at [1, 0, 0, 0]', function () {
var a = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8, 11, 22, 33, 44, 55, 66, 77, 88], [2, 2, 2, 2]);
var result = a.slice([1, 0, 0, 0], [1, 2, 2, 2]);
expect(result.shape).toEqual([1, 2, 2, 2]);
test_util_1.expectArraysClose(result, [11, 22, 33, 44, 55, 66, 77, 88]);
});
it('slices 2x2x2x2 array into 2x1x1x1 starting at [0, 1, 1, 1]', function () {
var a = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8, 11, 22, 33, 44, 55, 66, 77, 88], [2, 2, 2, 2]);
var result = a.slice([0, 1, 1, 1], [2, 1, 1, 1]);
expect(result.shape).toEqual([2, 1, 1, 1]);
test_util_1.expectArraysClose(result, [8, 88]);
});
});
test_util_1.describeWithFlags('slice ergonomics', test_util_1.CPU_ENVS, function () {

@@ -118,22 +138,6 @@ it('slices 2x2x2 array into 2x1x1 no size', function () {

});
});
test_util_1.describeWithFlags('slice4d', test_util_1.ALL_ENVS, function () {
it('slices 1x1x1x1 into shape 1x1x1x1 (effectively a copy)', function () {
var a = tf.tensor4d([[[[5]]]], [1, 1, 1, 1]);
var result = a.slice([0, 0, 0, 0], [1, 1, 1, 1]);
expect(result.shape).toEqual([1, 1, 1, 1]);
test_util_1.expectArraysClose(result, [5]);
it('throws when passed a non-tensor', function () {
expect(function () { return tf.slice({}, 0, 0); })
.toThrowError(/Argument 'x' passed to 'slice' must be a Tensor/);
});
it('slices 2x2x2x2 array into 1x2x2x2 starting at [1, 0, 0, 0]', function () {
var a = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8, 11, 22, 33, 44, 55, 66, 77, 88], [2, 2, 2, 2]);
var result = a.slice([1, 0, 0, 0], [1, 2, 2, 2]);
expect(result.shape).toEqual([1, 2, 2, 2]);
test_util_1.expectArraysClose(result, [11, 22, 33, 44, 55, 66, 77, 88]);
});
it('slices 2x2x2x2 array into 2x1x1x1 starting at [0, 1, 1, 1]', function () {
var a = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8, 11, 22, 33, 44, 55, 66, 77, 88], [2, 2, 2, 2]);
var result = a.slice([0, 1, 1, 1], [2, 1, 1, 1]);
expect(result.shape).toEqual([2, 1, 1, 1]);
test_util_1.expectArraysClose(result, [8, 88]);
});
});

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

SliceOps.slice = function (x, begin, size) {
util.assertArgumentsAreTensors({ x: x }, 'slice');
if (x.rank === 0) {

@@ -36,0 +37,0 @@ throw new Error('Slicing scalar is not possible');

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.softmax({}); })
.toThrowError(/Argument 'logits' passed to 'softmax' must be a Tensor/);
});
});

@@ -174,2 +178,13 @@ test_util_1.describeWithFlags('softmaxCrossEntropy', test_util_1.ALL_ENVS, function () {

});
it('throws when passed labels as a non-tensor', function () {
var e = /Argument 'labels' passed to 'softmaxCrossEntropy' must be a Tensor/;
expect(function () { return tf.losses.softmaxCrossEntropy({}, tf.tensor1d([
1
])); }).toThrowError(e);
});
it('throws when passed logits as a non-tensor', function () {
var e = /Argument 'logits' passed to 'softmaxCrossEntropy' must be a Tensor/;
expect(function () { return tf.losses.softmaxCrossEntropy(tf.tensor1d([1]), {}); })
.toThrowError(e);
});
});

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

if (dim === void 0) { dim = -1; }
util.assertArgumentsAreTensors({ logits: logits }, 'softmax');
if (dim === -1) {

@@ -44,2 +45,3 @@ dim = logits.rank - 1;

if (dim === void 0) { dim = -1; }
util.assertArgumentsAreTensors({ labels: labels, logits: logits }, 'softmaxCrossEntropy');
util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: ');

@@ -46,0 +48,0 @@ if (dim === -1) {

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

});
it('throws when passed a non-tensor', function () {
expect(function () { return tf.transpose({}); })
.toThrowError(/Argument 'x' passed to 'transpose' must be a Tensor/);
});
});

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

TransposeOps.transpose = function (x, perm) {
util.assertArgumentsAreTensors({ x: x }, 'transpose');
if (perm == null) {

@@ -20,0 +21,0 @@ perm = x.shape.map(function (s, i) { return i; }).reverse();

@@ -38,3 +38,4 @@ import { Tensor } from '../tensor';

static atanh<T extends Tensor>(x: T): T;
static erf<T extends Tensor>(x: T): T;
static step<T extends Tensor>(x: T, alpha?: number): T;
}

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

UnaryOps.neg = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'neg');
var grad = function (dy) {

@@ -27,2 +28,3 @@ return { x: function () { return dy.neg(); } };

UnaryOps.ceil = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'ceil');
var grad = function (dy) {

@@ -34,2 +36,3 @@ return { x: function () { return ops.zerosLike(dy); } };

UnaryOps.floor = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'floor');
var grad = function (dy) {

@@ -41,2 +44,3 @@ return { x: function () { return ops.zerosLike(dy); } };

UnaryOps.sign = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'sign');
var grad = function (dy) {

@@ -48,2 +52,3 @@ return { x: function () { return ops.zerosLike(dy); } };

UnaryOps.round = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'round');
var grad = function (dy) {

@@ -55,2 +60,3 @@ return { x: function () { return ops.zerosLike(dy); } };

UnaryOps.exp = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'exp');
var bck = function (dy, saved) {

@@ -63,2 +69,3 @@ var y = saved[0];

UnaryOps.expm1 = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'expm1');
var grad = function (dy) {

@@ -70,2 +77,3 @@ return { x: function () { return dy.mulStrict(x.exp()); } };

UnaryOps.log = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'log');
var grad = function (dy) {

@@ -77,2 +85,3 @@ return { x: function () { return dy.divStrict(x.toFloat()); } };

UnaryOps.log1p = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'log1p');
var grad = function (dy) {

@@ -84,2 +93,3 @@ return { x: function () { return dy.divStrict(x.add(ops.scalar(1))); } };

UnaryOps.sqrt = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'sqrt');
var grad = function (dy) {

@@ -91,2 +101,3 @@ return { x: function () { return dy.divStrict(x.toFloat().sqrt().mul(ops.scalar(2))); } };

UnaryOps.rsqrt = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'rsqrt');
var grad = function (dy) {

@@ -100,2 +111,3 @@ return {

UnaryOps.square = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'square');
var grad = function (dy) {

@@ -107,2 +119,3 @@ return { x: function () { return dy.mulStrict(x.toFloat().mul(ops.scalar(2))); } };

UnaryOps.reciprocal = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'reciprocal');
var grad = function (dy) {

@@ -114,2 +127,3 @@ return { x: function () { return dy.divStrict(x.square().neg()); } };

UnaryOps.abs = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'abs');
var grad = function (dy) {

@@ -121,2 +135,3 @@ return { x: function () { return dy.mulStrict(x.toFloat().step(-1)); } };

UnaryOps.clipByValue = function (x, clipValueMin, clipValueMax) {
util.assertArgumentsAreTensors({ x: x }, 'clipByValue');
util.assert((clipValueMin <= clipValueMax), "Error in clip: min (" + clipValueMin + ") must be " +

@@ -133,2 +148,3 @@ ("less than or equal to max (" + clipValueMax + ")."));

UnaryOps.relu = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'relu');
if (x.dtype === 'bool') {

@@ -144,2 +160,3 @@ return x.toInt();

UnaryOps.elu = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'elu');
var grad = function (dy, saved) {

@@ -156,2 +173,3 @@ var y = saved[0];

UnaryOps.selu = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'selu');
var grad = function (dy) {

@@ -173,5 +191,7 @@ return {

if (alpha === void 0) { alpha = 0.2; }
util.assertArgumentsAreTensors({ x: x }, 'leakyRelu');
return ops.maximum(ops.scalar(alpha).mul(x), x);
};
UnaryOps.prelu = function (x, alpha) {
util.assertArgumentsAreTensors({ x: x, alpha: alpha }, 'prelu');
var zero = ops.scalar(0);

@@ -181,2 +201,3 @@ return ops.maximum(zero, x).add(alpha.mul(ops.minimum(zero, x)));

UnaryOps.sigmoid = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'sigmoid');
var grad = function (dy, saved) {

@@ -189,2 +210,3 @@ var y = saved[0];

UnaryOps.logSigmoid = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'logSigmoid');
var grad = function (dy) {

@@ -196,2 +218,3 @@ return { x: function () { return dy.mulStrict(x.neg().sigmoid()); } };

UnaryOps.softplus = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'softplus');
var grad = function (dy) {

@@ -203,2 +226,3 @@ return { x: function () { return dy.mulStrict(x.sigmoid()); } };

UnaryOps.sin = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'sin');
var grad = function (dy) {

@@ -210,2 +234,3 @@ return { x: function () { return x.toFloat().cos().mulStrict(dy); } };

UnaryOps.cos = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'cos');
var grad = function (dy) {

@@ -217,2 +242,3 @@ return { x: function () { return x.toFloat().sin().neg().mulStrict(dy); } };

UnaryOps.tan = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'tan');
var grad = function (dy) {

@@ -224,2 +250,3 @@ return { x: function () { return dy.divStrict(x.cos().square()); } };

UnaryOps.asin = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'asin');
var grad = function (dy) {

@@ -235,2 +262,3 @@ return {

UnaryOps.acos = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'acos');
var grad = function (dy) {

@@ -247,2 +275,3 @@ return {

UnaryOps.atan = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'atan');
var grad = function (dy) {

@@ -254,2 +283,3 @@ return { x: function () { return dy.divStrict(ops.scalar(1).add(x.toFloat().square())); } };

UnaryOps.sinh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'sinh');
var grad = function (dy) {

@@ -261,2 +291,3 @@ return { x: function () { return x.toFloat().cosh().mulStrict(dy); } };

UnaryOps.cosh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'cosh');
var grad = function (dy) {

@@ -268,2 +299,3 @@ return { x: function () { return x.toFloat().sinh().mulStrict(dy); } };

UnaryOps.tanh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'tanh');
var grad = function (dy, saved) {

@@ -276,2 +308,3 @@ var y = saved[0];

UnaryOps.asinh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'asinh');
var grad = function (dy) {

@@ -287,2 +320,3 @@ return {

UnaryOps.acosh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'acosh');
var grad = function (dy) {

@@ -298,2 +332,3 @@ return {

UnaryOps.atanh = function (x) {
util.assertArgumentsAreTensors({ x: x }, 'atanh');
var grad = function (dy) {

@@ -304,4 +339,20 @@ return { x: function () { return dy.divStrict(ops.scalar(1).sub(x.toFloat().square())); } };

};
UnaryOps.erf = function (x) {
util.assert(x.dtype === 'int32' || x.dtype === 'float32', 'Input dtype must be `int32` or `float32`.');
if (x.dtype === 'int32') {
x = x.toFloat();
}
var grad = function (dy) {
return {
x: function () {
return dy.mulStrict(ops.scalar(2 / Math.sqrt(Math.PI))
.mul(x.square().neg().exp()));
}
};
};
return environment_1.ENV.engine.runKernel(function (backend) { return backend.erf(x); }, { x: x }, grad);
};
UnaryOps.step = function (x, alpha) {
if (alpha === void 0) { alpha = 0.0; }
util.assertArgumentsAreTensors({ x: x }, 'step');
var grad = function (dy) {

@@ -455,2 +506,6 @@ return { x: function () { return ops.zerosLike(dy); } };

operation_1.operation
], UnaryOps, "erf", null);
__decorate([
doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),
operation_1.operation
], UnaryOps, "step", null);

@@ -457,0 +512,0 @@ return UnaryOps;

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

});
it('reshape throws when passed a non-tensor', function () {
expect(function () { return tf.reshape({}, []); })
.toThrowError(/Argument 'x' passed to 'reshape' must be a Tensor/);
});
it('cast bool -> bool', function () {

@@ -666,2 +670,6 @@ var a = tf.tensor1d([1, 0], 'bool');

});
it('cast throws when passed a non-tensor', function () {
expect(function () { return tf.cast({}, 'float32'); })
.toThrowError(/Argument 'x' passed to 'cast' must be a Tensor/);
});
it('scalar bool -> int32', function () {

@@ -727,2 +735,6 @@ var a = tf.scalar(true, 'bool').toInt();

});
it('squeeze throws when passed a non-tensor', function () {
expect(function () { return tf.squeeze({}); })
.toThrowError(/Argument 'x' passed to 'squeeze' must be a Tensor/);
});
it('scalar -> 2d', function () {

@@ -729,0 +741,0 @@ var a = tf.scalar(4, 'int32');

@@ -145,2 +145,3 @@ import { DataType, Rank, ShapeMap, TypedArray } from './types';

atanh<T extends Tensor>(this: T): T;
erf<T extends Tensor>(this: T): T;
step<T extends Tensor>(this: T, alpha?: number): T;

@@ -147,0 +148,0 @@ softmax<T extends this>(this: T, dim?: number): T;

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

};
Tensor.prototype.erf = function () {
this.throwIfDisposed();
return ops.erf(this);
};
Tensor.prototype.step = function (alpha) {

@@ -667,0 +671,0 @@ if (alpha === void 0) { alpha = 0.0; }

import { Tensor } from './tensor';
import { DataType, DataTypeMap, FlatVector, NamedTensorMap, RecursiveArray, RegularArray, TensorContainer, TypedArray } from './types';
export declare function assertArgumentsAreTensors(args: {
[argName: string]: Tensor | Tensor[];
}, functionName: string): void;
export declare function shuffle(array: any[] | Uint32Array | Int32Array | Float32Array): void;

@@ -4,0 +7,0 @@ export declare function clamp(min: number, x: number, max: number): number;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tensor_1 = require("./tensor");
function assertArgumentIsTensor(x, argName, functionName) {
assert(x instanceof tensor_1.Tensor, "Argument '" + argName + "' passed to '" + functionName + "' must be a Tensor, " +
("but got " + typeof x + "."));
}
function assertArgumentsAreTensors(args, functionName) {
var _loop_1 = function (argName) {
var arg = args[argName];
if (Array.isArray(arg)) {
arg.forEach(function (t, i) {
assertArgumentIsTensor(t, argName + "[" + i + "]", functionName);
});
}
else {
assertArgumentIsTensor(arg, argName, functionName);
}
};
for (var argName in args) {
_loop_1(argName);
}
}
exports.assertArgumentsAreTensors = assertArgumentsAreTensors;
function shuffle(array) {

@@ -42,8 +63,8 @@ var counter = array.length;

if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; }
assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + ("Shapes " + shapeA + " and " + shapeB + " must match"));
assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + (" Shapes " + shapeA + " and " + shapeB + " must match"));
}
exports.assertShapesMatch = assertShapesMatch;
function assertTypesMatch(a, b) {
assert(a.dtype === b.dtype, "The dtypes of the first (" + a.dtype + ") and " +
("second (" + b.dtype + ") input must match"));
assert(a.dtype === b.dtype, " The dtypes of the first(" + a.dtype + ") and" +
(" second(" + b.dtype + ") input must match"));
}

@@ -198,3 +219,3 @@ exports.assertTypesMatch = assertTypesMatch;

throw Error("Shapes can only have 1 implicit size. " +
("Found -1 at dim " + implicitIdx + " and dim " + i));
("Found - 1 at dim " + implicitIdx + " and dim " + i));
}

@@ -209,3 +230,3 @@ implicitIdx = i;

if (size > 0 && size !== shapeProd) {
throw Error("Size (" + size + ") must match the product of shape " + shape);
throw Error("Size(" + size + ") must match the product of shape " + shape);
}

@@ -212,0 +233,0 @@ return shape;

@@ -1,2 +0,2 @@

declare const version = "0.8.0";
declare const version = "0.8.1";
export { version };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var version = '0.8.0';
var version = '0.8.1';
exports.version = version;
{
"name": "@tensorflow/tfjs-core",
"version": "0.8.0",
"version": "0.8.1",
"description": "Hardware-accelerated JavaScript library for machine intelligence",

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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