Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tfjs-core/src/globals_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describeWithFlags('tidy', ALL_ENVS, () => {
expect(tf.memory().numTensors).toBe(2);
tf.tidy(() => {
const result = tf.tidy(() => {
b = tf.addStrict(a, b);
b = tf.addStrict(a, b);
b = tf.addStrict(a, b);
b = tf.add(a, b);
b = tf.add(a, b);
b = tf.add(a, b);
return tf.add(a, b);
});

Expand Down Expand Up @@ -167,9 +167,9 @@ describeWithFlags('tidy', ALL_ENVS, () => {
expect(tf.memory().numTensors).toBe(2);

tf.tidy(() => {
b = tf.addStrict(a, b);
b = tf.addStrict(a, b);
b = tf.addStrict(a, b);
b = tf.add(a, b);
b = tf.add(a, b);
b = tf.add(a, b);
tf.add(a, b);
});

Expand All @@ -185,25 +185,25 @@ describeWithFlags('tidy', ALL_ENVS, () => {

tf.tidy(() => {
const result = tf.tidy(() => {
b = tf.addStrict(a, b);
b = tf.add(a, b);
b = tf.tidy(() => {
b = tf.tidy(() => {
return tf.addStrict(a, b);
return tf.add(a, b);
});
// original a, b, and two intermediates.
expect(tf.memory().numTensors).toBe(4);

tf.tidy(() => {
tf.addStrict(a, b);
tf.add(a, b);
});
// All the intermediates should be cleaned up.
expect(tf.memory().numTensors).toBe(4);

return tf.addStrict(a, b);
return tf.add(a, b);
});
expect(tf.memory().numTensors).toBe(4);

return tf.addStrict(a, b);
return tf.add(a, b);
});

expect(tf.memory().numTensors).toBe(3);
Expand Down
2 changes: 0 additions & 2 deletions tfjs-core/src/ops/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {op} from './operation';
/**
* Adds two `tf.Tensor`s element-wise, A + B. Supports broadcasting.
*
* We also expose `tf.addStrict` which has the same signature as this op and
* asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3, 4]);
Expand Down
44 changes: 44 additions & 0 deletions tfjs-core/src/ops/binary_ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

import {ENGINE} from '../engine';
import {deprecationWarn} from '../globals';
import {Tensor} from '../tensor';
import {makeTypesMatch} from '../tensor_util';
import {convertToTensor} from '../tensor_util_env';
Expand All @@ -29,6 +30,7 @@ import {scalar, zerosLike} from './tensor_ops';
import {neg} from './unary_ops';

/**
* @deprecated
* Adds two `tf.Tensor`s element-wise, A + B.
*
* Inputs must be the same shape. For broadcasting support, use add() instead.
Expand All @@ -37,13 +39,17 @@ import {neg} from './unary_ops';
* @param b The second Tensor to add element-wise.
*/
function addStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'addStrict');
const $b = convertToTensor(b, 'b', 'addStrict');
util.assertShapesMatch($a.shape, $b.shape, 'Error in addStrict: ');
return $a.add($b);
}

/**
* @deprecated
* Subtracts two `tf.Tensor`s element-wise, A - B. Inputs must
* be the same shape.
*
Expand All @@ -53,6 +59,10 @@ function addStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
* @param b The second Tensor to subtract element-wise.
*/
function subStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'subStrict');
const $b = convertToTensor(b, 'b', 'subStrict');
util.assertShapesMatch($a.shape, $b.shape, 'Error in subStrict: ');
Expand Down Expand Up @@ -129,6 +139,7 @@ function pow_<T extends Tensor>(
}

/**
* @deprecated
* Computes the power of one `tf.Tensor` to another. Inputs must
* be the same shape.
*
Expand All @@ -138,6 +149,10 @@ function pow_<T extends Tensor>(
* @param exp The exponent tensor to pow element-wise.
*/
function powStrict_<T extends Tensor>(base: T, exp: Tensor): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: ');
return base.pow(exp);
}
Expand Down Expand Up @@ -202,6 +217,7 @@ function mul_<T extends Tensor>(a: Tensor|TensorLike, b: Tensor|TensorLike): T {
}

/**
* @deprecated
* Multiplies two `tf.Tensor`s element-wise, A * B.
*
* Inputs must be the same shape. For broadcasting support, use `tf.mul`.
Expand All @@ -211,6 +227,10 @@ function mul_<T extends Tensor>(a: Tensor|TensorLike, b: Tensor|TensorLike): T {
* dtype as `a`.
*/
function mulStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'mul');
const $b = convertToTensor(b, 'b', 'mul');
util.assertShapesMatch($a.shape, $b.shape, 'Error in multiplyStrict: ');
Expand Down Expand Up @@ -279,13 +299,18 @@ function floorDiv_<T extends Tensor>(
}

/**
* @deprecated
* Divides two `tf.Tensor`s element-wise, A / B. Inputs must
* be the same shape.
*
* @param a The first tensor as the numerator for element-wise division.
* @param b The second tensor as the denominator for element-wise division.
*/
function divStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'div');
const $b = convertToTensor(b, 'b', 'div');
util.assertShapesMatch($a.shape, $b.shape, 'Error in divideStrict: ');
Expand Down Expand Up @@ -353,13 +378,18 @@ function mod_<T extends Tensor>(a: Tensor|TensorLike, b: Tensor|TensorLike): T {
}

/**
* @deprecated
* Returns the mod of a and b (`a < b ? a : b`) element-wise. Inputs must
* be the same shape. For broadcasting support, use mod().
*
* @param a The first tensor.
* @param b The second tensor. Must have the same dtype as `a`.
*/
function modStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'modStrict');
const $b = convertToTensor(b, 'b', 'modStrict');
util.assertShapesMatch($a.shape, $b.shape, 'Error in modStrict: ');
Expand Down Expand Up @@ -418,13 +448,18 @@ function minimum_<T extends Tensor>(
}

/**
* @deprecated
* Returns the min of a and b (`a < b ? a : b`) element-wise. Inputs must
* be the same shape. For broadcasting support, use minimum().
*
* @param a The first tensor.
* @param b The second tensor. Must have the same dtype as `a`.
*/
function minimumStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'minimumStrict');
const $b = convertToTensor(b, 'b', 'minimumStrict');
util.assertShapesMatch($a.shape, $b.shape, 'Error in minimumStrict: ');
Expand Down Expand Up @@ -483,20 +518,26 @@ function maximum_<T extends Tensor>(
}

/**
* @deprecated
* Returns the max of a and b (`a > b ? a : b`) element-wise. Inputs must
* be the same shape. For broadcasting support, use maximum().
*
* @param a The first tensor.
* @param b The second tensor. Must have the same dtype as `a`.
*/
function maximumStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');

const $a = convertToTensor(a, 'a', 'maximumStrict');
const $b = convertToTensor(b, 'b', 'maximumStrict');
util.assertShapesMatch($a.shape, $b.shape, 'Error in maximumStrict: ');
return $a.maximum($b);
}

/**
* @deprecated
* Returns (a - b) * (a - b) element-wise.
*
* Inputs must be the same shape. For broadcasting support, use
Expand All @@ -507,6 +548,9 @@ function maximumStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
*/
function squaredDifferenceStrict_<T extends Tensor>(
a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'squaredDifferenceStrict');
const $b = convertToTensor(b, 'b', 'squaredDifferenceStrict');
util.assertShapesMatch(
Expand Down
22 changes: 22 additions & 0 deletions tfjs-core/src/ops/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* limitations under the License.
* =============================================================================
*/
import {deprecationWarn} from '../globals';
import {Tensor} from '../tensor';
import {convertToTensor} from '../tensor_util_env';
import {TensorLike} from '../types';
import {assertShapesMatch} from '../util';

import {op} from './operation';

/**
* @deprecated
* Strict version of `tf.notEqual` that forces `a` and `b` to be of the same
* shape.
*
Expand All @@ -30,13 +33,17 @@ import {op} from './operation';
*/
function notEqualStrict_<T extends Tensor>(
a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'notEqualStrict');
const $b = convertToTensor(b, 'b', 'notEqualStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in notEqualStrict: ');
return $a.notEqual($b);
}

/**
* @deprecated
* Strict version of `tf.less` that forces `a` and `b` to be of the same
* shape.
*
Expand All @@ -45,13 +52,19 @@ function notEqualStrict_<T extends Tensor>(
* `a`.
*/
function lessStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'lessStrict');
const $b = convertToTensor(b, 'b', 'lessStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in lessStrict: ');
return $a.less($b);
}

function equalStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'equalStrict');
const $b = convertToTensor(b, 'b', 'equalStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in equalStrict: ');
Expand All @@ -60,13 +73,19 @@ function equalStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {

function lessEqualStrict_<T extends Tensor>(
a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'lessEqualStrict');
const $b = convertToTensor(b, 'b', 'lessEqualStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in lessEqualStrict: ');
return $a.lessEqual($b);
}

function greaterStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'greaterStrict');
const $b = convertToTensor(b, 'b', 'greaterStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in greaterStrict: ');
Expand All @@ -75,6 +94,9 @@ function greaterStrict_<T extends Tensor>(a: T|TensorLike, b: T|TensorLike): T {

function greaterEqualStrict_<T extends Tensor>(
a: T|TensorLike, b: T|TensorLike): T {
deprecationWarn(
'strict variants of ops have been deprecated ' +
'and will be removed in future');
const $a = convertToTensor(a, 'a', 'greaterEqualStrict');
const $b = convertToTensor(b, 'b', 'greaterEqualStrict');
assertShapesMatch($a.shape, $b.shape, 'Error in greaterEqualStrict: ');
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/div.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import {op} from './operation';
/**
* Divides two `tf.Tensor`s element-wise, A / B. Supports broadcasting.
*
* We also expose `tf.divStrict` which has the same signature as this op and
* asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 4, 9, 16]);
* const b = tf.tensor1d([1, 2, 3, 4]);
Expand Down
2 changes: 0 additions & 2 deletions tfjs-core/src/ops/div_no_nan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import {zerosLike} from './tensor_ops';
* Divides two `tf.Tensor`s element-wise, A / B. Supports broadcasting. Return 0
* if denominator is 0.
*
* We also expose `tf.divStrict` which has the same signature as this op and
* asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 4, 9, 16]);
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {op} from './operation';
/**
* Returns the truth value of (a == b) element-wise. Supports broadcasting.
*
* We also expose `tf.equalStrict` which has the same signature as this op
* and asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3]);
* const b = tf.tensor1d([2, 2, 2]);
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/greater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {op} from './operation';
/**
* Returns the truth value of (a > b) element-wise. Supports broadcasting.
*
* We also expose `tf.greaterStrict` which has the same signature as this
* op and asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3]);
* const b = tf.tensor1d([2, 2, 2]);
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/greater_equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {op} from './operation';
/**
* Returns the truth value of (a >= b) element-wise. Supports broadcasting.
*
* We also expose `tf.greaterEqualStrict` which has the same signature as this
* op and asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3]);
* const b = tf.tensor1d([2, 2, 2]);
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {op} from './operation';
/**
* Returns the truth value of (a < b) element-wise. Supports broadcasting.
*
* We also expose `tf.lessStrict` which has the same signature as this op and
* asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3]);
* const b = tf.tensor1d([2, 2, 2]);
Expand Down
3 changes: 0 additions & 3 deletions tfjs-core/src/ops/less_equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import {op} from './operation';
/**
* Returns the truth value of (a <= b) element-wise. Supports broadcasting.
*
* We also expose `tf.lessEqualStrict` which has the same signature as this op
* and asserts that `a` and `b` are the same shape (does not broadcast).
*
* ```js
* const a = tf.tensor1d([1, 2, 3]);
* const b = tf.tensor1d([2, 2, 2]);
Expand Down
Loading