UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

331 lines (330 loc) 12.2 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'; /** * Computes the log(sum(exp(elements across the reduction dimensions)). * * Reduces the input along the dimensions given in `axis`. Unless `keepDims` * is true, the rank of the array is reduced by 1 for each entry in `axis`. * If `keepDims` is true, the reduced dimensions are retained with length 1. * If `axis` has no entries, all dimensions are reduced, and an array with a * single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.logSumExp().print(); // or tf.logSumExp(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.logSumExp(axis).print(); // or tf.logSumExp(a, axis) * ``` * @param x The input tensor. * @param axis The dimension(s) to reduce. If null (the default), * reduces all dimensions. * @param keepDims If true, retains reduced dimensions with length * of 1. Defaults to false. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function logSumExp_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the sum of elements across dimensions of a `tf.Tensor`. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in * `axes`. If `keepDims` is true, the reduced dimensions are retained with * length 1. If axes has no entries, all dimensions are reduced, and a * `tf.Tensor` with a single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.sum().print(); // or tf.sum(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.sum(axis).print(); // or tf.sum(x, axis) * ``` * * @param x The input tensor to compute the sum over. If the dtype is `bool` * it will be converted to `int32` and the output dtype will be `int32`. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function sum_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the product of elements across dimensions of a `tf.Tensor`. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in * `axes`. If `keepDims` is true, the reduced dimensions are retained with * length 1. If `axes` has no entries, all dimensions are reduced, and a * `tf.Tensor` with a single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.prod().print(); // or tf.prod(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.prod(axis).print(); // or tf.prod(x, axis) * ``` * * @param x The input tensor to compute the product over. If the dtype is `bool` * it will be converted to `int32` and the output dtype will be `int32`. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function prod_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the mean of elements across dimensions of a `tf.Tensor`. * * Reduces `x` along the dimensions given in `axis`. Unless `keepDims` is * true, the rank of the `tf.Tensor` is reduced by 1 for each entry in `axis`. * If `keepDims` is true, the reduced dimensions are retained with length 1. * If `axis` has no entries, all dimensions are reduced, and a `tf.Tensor` with * a single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.mean().print(); // or tf.mean(a) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.mean(axis).print(); // or tf.mean(x, axis) * ``` * * @param x The input tensor. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function mean_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the minimum value from the input. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the array is reduced by 1 for each entry in `axes`. * If `keepDims` is true, the reduced dimensions are retained with length 1. * If `axes` has no entries, all dimensions are reduced, and an array with a * single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.min().print(); // or tf.min(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.min(axis).print(); // or tf.min(x, axis) * ``` * * @param x The input Tensor. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function min_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the maximum of elements across dimensions of a `tf.Tensor`. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in * `axes`. If `keepDims` is true, the reduced dimensions are retained with * length 1. If `axes` has no entries, all dimensions are reduced, and an * `tf.Tensor` with a single element is returned. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.max().print(); // or tf.max(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * const axis = 1; * x.max(axis).print(); // or tf.max(x, axis) * ``` * * @param x The input tensor. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function max_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Returns the indices of the minimum values along an `axis`. * * The result has the same shape as `input` with the dimension along `axis` * removed. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.argMin().print(); // or tf.argMin(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 4, 3], [2, 2]); * * const axis = 1; * x.argMin(axis).print(); // or tf.argMin(x, axis) * ``` * * @param x The input tensor. * @param axis The dimension to reduce. Defaults to 0 (outer-most dimension). * */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function argMin_<T extends Tensor>(x: Tensor | TensorLike, axis?: number): T; /** * Returns the indices of the maximum values along an `axis`. * * The result has the same shape as `input` with the dimension along `axis` * removed. * * ```js * const x = tf.tensor1d([1, 2, 3]); * * x.argMax().print(); // or tf.argMax(x) * ``` * * ```js * const x = tf.tensor2d([1, 2, 4, 3], [2, 2]); * * const axis = 1; * x.argMax(axis).print(); // or tf.argMax(x, axis) * ``` * * @param x The input tensor. * @param axis The dimension to reduce. Defaults to 0 (outer-most dimension). */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function argMax_<T extends Tensor>(x: Tensor | TensorLike, axis?: number): T; /** * Computes the logical and of elements across dimensions of a `tf.Tensor`. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in * `axes`. If `keepDims` is true, the reduced dimensions are retained with * length 1. If `axes` has no entries, all dimensions are reduced, and an * `tf.Tensor` with a single element is returned. * * ```js * const x = tf.tensor1d([1, 1, 1], 'bool'); * * x.all().print(); // or tf.all(x) * ``` * * ```js * const x = tf.tensor2d([1, 1, 0, 0], [2, 2], 'bool'); * * const axis = 1; * x.all(axis).print(); // or tf.all(x, axis) * ``` * * @param x The input tensor. Must be of dtype bool. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function all_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Computes the logical or of elements across dimensions of a `tf.Tensor`. * * Reduces the input along the dimensions given in `axes`. Unless `keepDims` * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in * `axes`. If `keepDims` is true, the reduced dimensions are retained with * length 1. If `axes` has no entries, all dimensions are reduced, and an * `tf.Tensor` with a single element is returned. * * ```js * const x = tf.tensor1d([1, 1, 1], 'bool'); * * x.any().print(); // or tf.any(x) * ``` * * ```js * const x = tf.tensor2d([1, 1, 0, 0], [2, 2], 'bool'); * * const axis = 1; * x.any(axis).print(); // or tf.any(x, axis) * ``` * * @param x The input tensor. Must be of dtype bool. * @param axis The dimension(s) to reduce. By default it reduces * all dimensions. * @param keepDims If true, retains reduced dimensions with size 1. */ /** @doc {heading: 'Operations', subheading: 'Reduction'} */ declare function any_<T extends Tensor>(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): T; /** * Calculates the mean and variance of `x`. The mean and variance are * calculated by aggregating the contents of `x` across `axes`. If `x` is * 1-D and `axes = [0]` this is just the mean and variance of a vector. * * @param x The input tensor. * @param axis The dimension(s) along with to compute mean and * variance. By default it reduces all dimensions. * @param keepDims If true, the moments have the same dimensionality as the * input. * @return An object with two keys: `mean` and `variance`. */ /** @doc {heading: 'Operations', subheading: 'Normalization'} */ declare function moments_(x: Tensor | TensorLike, axis?: number | number[], keepDims?: boolean): { mean: Tensor; variance: Tensor; }; export declare const all: typeof all_; export declare const any: typeof any_; export declare const argMax: typeof argMax_; export declare const argMin: typeof argMin_; export declare const logSumExp: typeof logSumExp_; export declare const max: typeof max_; export declare const mean: typeof mean_; export declare const min: typeof min_; export declare const moments: typeof moments_; export declare const sum: typeof sum_; export declare const prod: typeof prod_; export {};