UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

453 lines (452 loc) 15.7 kB
/** * @license * Copyright 2018 Google Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ import { Tensor } from '../tensor'; import { TensorLike } from '../types'; /** * 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]); * const b = tf.tensor1d([10, 20, 30, 40]); * * a.add(b).print(); // or tf.add(a, b) * ``` * * ```js * // Broadcast add a with b. * const a = tf.scalar(5); * const b = tf.tensor1d([10, 20, 30, 40]); * * a.add(b).print(); // or tf.add(a, b) * ``` * @param a The first `tf.Tensor` to add. * @param b The second `tf.Tensor` to add. Must have the same type as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function add_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * Adds a list of `tf.Tensor`s element-wise, each with the same shape and dtype. * * ```js * const a = tf.tensor1d([1, 2]); * const b = tf.tensor1d([3, 4]); * const c = tf.tensor1d([5, 6]); * * tf.addN([a, b, c]).print(); * ``` * @param tensors A list of tensors with the same shape and dtype. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function addN_<T extends Tensor>(tensors: Array<T | TensorLike>): T; /** * Adds two `tf.Tensor`s element-wise, A + B. * * Inputs must be the same shape. For broadcasting support, use add() instead. * * @param a The first Tensor to add element-wise. * @param b The second Tensor to add element-wise. */ declare function addStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Subtracts two `tf.Tensor`s element-wise, A - B. Supports broadcasting. * * We also expose `tf.subStrict` 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([10, 20, 30, 40]); * const b = tf.tensor1d([1, 2, 3, 4]); * * a.sub(b).print(); // or tf.sub(a, b) * ``` * * ```js * // Broadcast subtract a with b. * const a = tf.tensor1d([10, 20, 30, 40]); * const b = tf.scalar(5); * * a.sub(b).print(); // or tf.sub(a, b) * ``` * @param a The first `tf.Tensor` to subtract from. * @param b The second `tf.Tensor` to be subtracted. Must have the same dtype as * `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function sub_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * Subtracts two `tf.Tensor`s element-wise, A - B. Inputs must * be the same shape. * * For broadcasting support, use `tf.sub` instead. * * @param a The first Tensor to subtract element-wise. * @param b The second Tensor to subtract element-wise. */ declare function subStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Computes the power of one `tf.Tensor` to another. Supports broadcasting. * * Given a `tf.Tensor` x and a `tf.Tensor` y, this operation computes x^y for * corresponding elements in x and y. The result's dtype will be the upcasted * type of the `base` and `exp` dtypes. * * ```js * const a = tf.tensor([[2, 3], [4, 5]]) * const b = tf.tensor([[1, 2], [3, 0]]).toInt(); * * a.pow(b).print(); // or tf.pow(a, b) * ``` * * ```js * const a = tf.tensor([[1, 2], [3, 4]]) * const b = tf.tensor(2).toInt(); * * a.pow(b).print(); // or tf.pow(a, b) * ``` * We also expose `powStrict` which has the same signature as this op and * asserts that `base` and `exp` are the same shape (does not broadcast). * * @param base The base `tf.Tensor` to pow element-wise. * @param exp The exponent `tf.Tensor` to pow element-wise. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function pow_<T extends Tensor>(base: T | TensorLike, exp: Tensor | TensorLike): T; /** * Computes the power of one `tf.Tensor` to another. Inputs must * be the same shape. * * For broadcasting support, use `tf.pow` instead. * * @param base The base tensor to pow element-wise. * @param exp The exponent tensor to pow element-wise. */ declare function powStrict_<T extends Tensor>(base: T, exp: Tensor): T; /** * Multiplies two `tf.Tensor`s element-wise, A * B. Supports broadcasting. * * We also expose `tf.mulStrict` 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]); * const b = tf.tensor1d([2, 3, 4, 5]); * * a.mul(b).print(); // or tf.mul(a, b) * ``` * * ```js * // Broadcast mul a with b. * const a = tf.tensor1d([1, 2, 3, 4]); * const b = tf.scalar(5); * * a.mul(b).print(); // or tf.mul(a, b) * ``` * @param a The first tensor to multiply. * @param b The second tensor to multiply. Must have the same dtype as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function mul_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * Multiplies two `tf.Tensor`s element-wise, A * B. * * Inputs must be the same shape. For broadcasting support, use `tf.mul`. * * @param a The first tensor to multiply. * @param b The first tensor to multiply. Must have the same * dtype as `a`. */ declare function mulStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * 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]); * * a.div(b).print(); // or tf.div(a, b) * ``` * * ```js * // Broadcast div a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(2); * * a.div(b).print(); // or tf.div(a, b) * ``` * * @param a The first tensor as the numerator. * @param b The second tensor as the denominator. Must have the same dtype as * `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function div_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * 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]); * const b = tf.tensor1d([1, 2, 3, 4]); * const c = tf.tensor1d([0, 0, 0, 0]); * * a.divNoNan(b).print(); // or tf.divNoNan(a, b) * a.divNoNan(c).print(); // or tf.divNoNan(a, c) * ``` * * ```js * // Broadcast div a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(2); * const c = tf.scalar(0); * * a.divNoNan(b).print(); // or tf.divNoNan(a, b) * a.divNoNan(c).print(); // or tf.divNoNan(a, c) * ``` * * @param a The first tensor as the numerator. * @param b The second tensor as the denominator. Must have the same dtype as * `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function divNoNan_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * Divides two `tf.Tensor`s element-wise, A / B. Supports broadcasting. * The result is rounded with floor function. * * * ```js * const a = tf.tensor1d([1, 4, 9, 16]); * const b = tf.tensor1d([1, 2, 3, 4]); * * a.floorDiv(b).print(); // or tf.div(a, b) * ``` * * ```js * // Broadcast div a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(2); * * a.floorDiv(b).print(); // or tf.floorDiv(a, b) * ``` * * @param a The first tensor as the numerator. * @param b The second tensor as the denominator. Must have the same dtype as * `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function floorDiv_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * 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. */ declare function divStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Returns the mod of a and b element-wise. * `floor(x / y) * y + mod(x, y) = x` * Supports broadcasting. * * We also expose `tf.modStrict` 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, 3, 16]); * const b = tf.tensor1d([1, 2, 9, 4]); * * a.mod(b).print(); // or tf.mod(a, b) * ``` * * ```js * // Broadcast a mod b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(5); * * a.mod(b).print(); // or tf.mod(a, b) * ``` * * @param a The first tensor. * @param b The second tensor. Must have the same type as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function mod_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * 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`. */ declare function modStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Returns the min of a and b (`a < b ? a : b`) element-wise. * Supports broadcasting. * * We also expose `minimumStrict` 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, 3, 16]); * const b = tf.tensor1d([1, 2, 9, 4]); * * a.minimum(b).print(); // or tf.minimum(a, b) * ``` * * ```js * // Broadcast minimum a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(5); * * a.minimum(b).print(); // or tf.minimum(a, b) * ``` * * @param a The first tensor. * @param b The second tensor. Must have the same type as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function minimum_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * 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`. */ declare function minimumStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Returns the max of a and b (`a > b ? a : b`) element-wise. * Supports broadcasting. * * We also expose `tf.maximumStrict` 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, 3, 16]); * const b = tf.tensor1d([1, 2, 9, 4]); * * a.maximum(b).print(); // or tf.maximum(a, b) * ``` * * ```js * // Broadcast maximum a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(5); * * a.maximum(b).print(); // or tf.maximum(a, b) * ``` * * @param a The first tensor. * @param b The second tensor. Must have the same type as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function maximum_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * 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`. */ declare function maximumStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Returns (a - b) * (a - b) element-wise. * Supports broadcasting. * * We also expose `tf.squaredDifferenceStrict` 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, 3, 16]); * const b = tf.tensor1d([1, 2, 9, 4]); * * a.squaredDifference(b).print(); // or tf.squaredDifference(a, b) * ``` * * ```js * // Broadcast squared difference a with b. * const a = tf.tensor1d([2, 4, 6, 8]); * const b = tf.scalar(5); * * a.squaredDifference(b).print(); // or tf.squaredDifference(a, b) * ``` * * @param a The first tensor. * @param b The second tensor. Must have the same type as `a`. */ /** @doc {heading: 'Operations', subheading: 'Arithmetic'} */ declare function squaredDifference_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; /** * Returns (a - b) * (a - b) element-wise. * * Inputs must be the same shape. For broadcasting support, use * `tf.squaredDifference` instead. * * @param a The first tensor. * @param b The second tensor. Must have the same type as `a`. */ declare function squaredDifferenceStrict_<T extends Tensor>(a: T | TensorLike, b: T | TensorLike): T; /** * Computes arctangent of `tf.Tensor`s a / b element-wise: `atan2(a, b)`. * Supports broadcasting. * * ```js * const a = tf.tensor1d([1.0, 1.0, -1.0, .7]); * const b = tf.tensor1d([2.0, 13.0, 3.5, .21]); * * tf.atan2(a, b).print() * ``` * * @param a The first tensor. * @param b The second tensor. Must have the same dtype as `a`. * */ /** @doc {heading: 'Operations', subheading: 'Basic math'} */ declare function atan2_<T extends Tensor>(a: Tensor | TensorLike, b: Tensor | TensorLike): T; export declare const add: typeof add_; export declare const addN: typeof addN_; export declare const addStrict: typeof addStrict_; export declare const atan2: typeof atan2_; export declare const div: typeof div_; export declare const divNoNan: typeof divNoNan_; export declare const divStrict: typeof divStrict_; export declare const floorDiv: typeof floorDiv_; export declare const maximum: typeof maximum_; export declare const maximumStrict: typeof maximumStrict_; export declare const minimum: typeof minimum_; export declare const minimumStrict: typeof minimumStrict_; export declare const mod: typeof mod_; export declare const modStrict: typeof modStrict_; export declare const mul: typeof mul_; export declare const mulStrict: typeof mulStrict_; export declare const pow: typeof pow_; export declare const powStrict: typeof powStrict_; export declare const squaredDifference: typeof squaredDifference_; export declare const squaredDifferenceStrict: typeof squaredDifferenceStrict_; export declare const sub: typeof sub_; export declare const subStrict: typeof subStrict_; export {};