UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

61 lines (60 loc) 2.68 kB
/** * @license * Copyright 2018 Google LLC. 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. * ============================================================================= */ /// <amd-module name="@tensorflow/tfjs-core/dist/ops/norm" /> import { Tensor } from '../tensor'; import { TensorLike } from '../types'; /** * Computes the norm of scalar, vectors, and matrices. * This function can compute several different vector norms (the 1-norm, the * Euclidean or 2-norm, the inf-norm, and in general the p-norm for p > 0) * and matrix norms (Frobenius, 1-norm, and inf-norm). * * ```js * const x = tf.tensor1d([1, 2, 3, 4]); * * x.norm().print(); // or tf.norm(x) * ``` * * @param x The input array. * @param ord Optional. Order of the norm. Supported norm types are * following: * * | ord | norm for matrices | norm for vectors * |------------|---------------------------|--------------------- * |'euclidean' |Frobenius norm |2-norm * |'fro' |Frobenius norm | * |Infinity |max(sum(abs(x), axis=1)) |max(abs(x)) * |-Infinity |min(sum(abs(x), axis=1)) |min(abs(x)) * |1 |max(sum(abs(x), axis=0)) |sum(abs(x)) * |2 | |sum(abs(x)^2)^(1/2) * * @param axis Optional. If axis is null (the default), the input is * considered a vector and a single vector norm is computed over the entire * set of values in the Tensor, i.e. norm(x, ord) is equivalent * to norm(x.reshape([-1]), ord). If axis is an integer, the input * is considered a batch of vectors, and axis determines the axis in x * over which to compute vector norms. If axis is a 2-tuple of integer it is * considered a batch of matrices and axis determines the axes in NDArray * over which to compute a matrix norm. * @param keepDims Optional. If true, the norm has the same dimensionality * as the input. * * @doc {heading: 'Operations', subheading: 'Matrices'} */ declare function norm_(x: Tensor | TensorLike, ord?: number | 'euclidean' | 'fro', axis?: number | number[], keepDims?: boolean): Tensor; export declare const norm: typeof norm_; export {};