/**
|
* @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, Tensor1D, Tensor2D, Tensor3D, Tensor4D, TensorBuffer } from '../tensor';
|
import { DataType, DataTypeMap, Rank, ShapeMap, TensorLike, TensorLike4D } from '../types';
|
/**
|
* Broadcast an array to a compatible shape NumPy-style.
|
*
|
* The tensor's shape is compared to the broadcast shape from end to beginning.
|
* Ones are prepended to the tensor's shape until is has the same length as
|
* the broadcast shape. If input.shape[i]==shape[i], the (i+1)-th axis is
|
* already broadcast-compatible. If input.shape[i]==1 and shape[i]==N, then
|
* the input tensor is tiled N times along that axis (using tf.tile).
|
*
|
* @param input The tensor that is to be broadcasted.
|
* @param shape The input is to be broadcast to this shape.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function broadcastTo_<R extends Rank>(x: Tensor | TensorLike, shape: ShapeMap[R]): Tensor<R>;
|
/**
|
* Creates a new tensor with the same values and shape as the specified
|
* tensor.
|
*
|
* ```js
|
* const x = tf.tensor([1, 2]);
|
*
|
* x.clone().print();
|
* ```
|
*
|
* @param x The tensor to clone.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function clone_<T extends Tensor>(x: T | TensorLike): T;
|
/**
|
* Create an identity matrix.
|
*
|
* @param numRows Number of rows.
|
* @param numColumns Number of columns. Defaults to `numRows`.
|
* @param batchShape If provided, will add the batch shape to the beginning
|
* of the shape of the returned `tf.Tensor` by repeating the identity
|
* matrix.
|
* @param dtype Data type.
|
* @returns Identity matrix of the specified size and data type, possibly
|
* with batch repetition if `batchShape` is specified.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function eye_(numRows: number, numColumns?: number, batchShape?: [number] | [number, number] | [number, number, number] | [number, number, number, number], dtype?: DataType): Tensor2D;
|
/**
|
* Creates a `tf.Tensor` with values sampled from a normal distribution.
|
*
|
* ```js
|
* tf.randomNormal([2, 2]).print();
|
* ```
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param mean The mean of the normal distribution.
|
* @param stdDev The standard deviation of the normal distribution.
|
* @param dtype The data type of the output.
|
* @param seed The seed for the random number generator.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Random'} */
|
declare function randomNormal_<R extends Rank>(shape: ShapeMap[R], mean?: number, stdDev?: number, dtype?: 'float32' | 'int32', seed?: number): Tensor<R>;
|
/**
|
* Creates a `tf.Tensor` with values sampled from a truncated normal
|
* distribution.
|
*
|
* ```js
|
* tf.truncatedNormal([2, 2]).print();
|
* ```
|
*
|
* The generated values follow a normal distribution with specified mean and
|
* standard deviation, except that values whose magnitude is more than 2
|
* standard deviations from the mean are dropped and re-picked.
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param mean The mean of the normal distribution.
|
* @param stdDev The standard deviation of the normal distribution.
|
* @param dtype The data type of the output tensor.
|
* @param seed The seed for the random number generator.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function truncatedNormal_<R extends Rank>(shape: ShapeMap[R], mean?: number, stdDev?: number, dtype?: 'float32' | 'int32', seed?: number): Tensor<R>;
|
/**
|
* Creates a `tf.Tensor` with values sampled from a gamma distribution.
|
*
|
* ```js
|
* tf.randomGamma([2, 2], 1).print();
|
* ```
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param alpha The shape parameter of the gamma distribution.
|
* @param beta The inverse scale parameter of the gamma distribution. Defaults
|
* to 1.
|
* @param dtype The data type of the output. Defaults to float32.
|
* @param seed The seed for the random number generator.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Random'} */
|
declare function randomGamma_<R extends Rank>(shape: ShapeMap[R], alpha: number, beta?: number, dtype?: 'float32' | 'int32', seed?: number): Tensor<R>;
|
/**
|
* Creates a `tf.Tensor` with values sampled from a uniform distribution.
|
*
|
* The generated values follow a uniform distribution in the range [minval,
|
* maxval). The lower bound minval is included in the range, while the upper
|
* bound maxval is excluded.
|
*
|
* ```js
|
* tf.randomUniform([2, 2]).print();
|
* ```
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param minval The lower bound on the range of random values to generate.
|
* Defaults to 0.
|
* @param maxval The upper bound on the range of random values to generate.
|
* Defaults to 1.
|
* @param dtype The data type of the output tensor. Defaults to 'float32'.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Random'} */
|
declare function randomUniform_<R extends Rank>(shape: ShapeMap[R], minval?: number, maxval?: number, dtype?: DataType, seed?: number | string): Tensor<R>;
|
/**
|
* Creates a `tf.Tensor` with values sampled from a random number generator
|
* function defined by the user.
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param randFunction A random number generator function which is called
|
* for each element in the output tensor.
|
* @param dtype The data type of the output tensor. Defaults to 'float32'.
|
*/
|
declare function rand_<R extends Rank>(shape: ShapeMap[R], randFunction: () => number, dtype?: DataType): Tensor<R>;
|
/**
|
* Creates a `tf.Tensor` with values drawn from a multinomial distribution.
|
*
|
* ```js
|
* const probs = tf.tensor([.75, .25]);
|
* tf.multinomial(probs, 3).print();
|
* ```
|
*
|
* @param logits 1D array with unnormalized log-probabilities, or
|
* 2D array of shape `[batchSize, numOutcomes]`. See the `normalized`
|
* parameter.
|
* @param numSamples Number of samples to draw for each row slice.
|
* @param seed The seed number.
|
* @param normalized Whether the provided `logits` are normalized true
|
* probabilities (sum to 1). Defaults to false.
|
* @return 1D array of shape `[numSamples]`, or 2D array of shape
|
* `[batchSize, numSamples]`, depending on the rank of the input.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Random'} */
|
declare function multinomial_(logits: Tensor1D | Tensor2D | TensorLike, numSamples: number, seed?: number, normalized?: boolean): Tensor1D | Tensor2D;
|
/**
|
* Creates a one-hot `tf.Tensor`. The locations represented by `indices` take
|
* value `onValue` (defaults to 1), while all other locations take value
|
* `offValue` (defaults to 0). If `indices` is rank `R`, the output has rank
|
* `R+1` with the last axis of size `depth`.
|
*
|
* ```js
|
* tf.oneHot(tf.tensor1d([0, 1], 'int32'), 3).print();
|
* ```
|
*
|
* @param indices `tf.Tensor` of indices with dtype `int32`.
|
* @param depth The depth of the one hot dimension.
|
* @param onValue A number used to fill in the output when the index matches
|
* the location.
|
* @param offValue A number used to fill in the output when the index does
|
* not match the location.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function oneHot_(indices: Tensor | TensorLike, depth: number, onValue?: number, offValue?: number): Tensor;
|
/**
|
* Reshapes a `tf.Tensor` to a given shape.
|
*
|
* Given an input tensor, returns a new tensor with the same values as the
|
* input tensor with shape `shape`.
|
*
|
* If one component of shape is the special value -1, the size of that
|
* dimension is computed so that the total size remains constant. In
|
* particular, a shape of [-1] flattens into 1-D. At most one component of
|
* shape can be -1.
|
*
|
* If shape is 1-D or higher, then the operation returns a tensor with shape
|
* shape filled with the values of tensor. In this case, the number of
|
* elements implied by shape must be the same as the number of elements in
|
* tensor.
|
*
|
* ```js
|
* const x = tf.tensor1d([1, 2, 3, 4]);
|
* x.reshape([2, 2]).print();
|
* ```
|
*
|
* @param x The input tensor to be reshaped.
|
* @param shape An array of integers defining the output tensor shape.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function reshape_<R2 extends Rank>(x: Tensor | TensorLike, shape: ShapeMap[R2]): Tensor<R2>;
|
/**
|
* Removes dimensions of size 1 from the shape of a `tf.Tensor`.
|
*
|
* ```js
|
* const x = tf.tensor([1, 2, 3, 4], [1, 1, 4]);
|
* x.squeeze().print();
|
* ```
|
*
|
* @param x The input tensor to be squeezed.
|
* @param axis An optional list of numbers. If specified, only
|
* squeezes the dimensions listed. The dimension index starts at 0. It
|
* is an error to squeeze a dimension that is not 1.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function squeeze_<T extends Tensor>(x: Tensor | TensorLike, axis?: number[]): T;
|
/**
|
* Casts a `tf.Tensor` to a new dtype.
|
*
|
* ```js
|
* const x = tf.tensor1d([1.5, 2.5, 3]);
|
* tf.cast(x, 'int32').print();
|
* ```
|
* @param x The input tensor to be casted.
|
* @param dtype The dtype to cast the input tensor to.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function cast_<T extends Tensor>(x: T | TensorLike, dtype: DataType): T;
|
/**
|
* Construct a tensor by repeating it the number of times given by reps.
|
*
|
* This operation creates a new tensor by replicating `input` `reps`
|
* times. The output tensor's i'th dimension has `input.shape[i] *
|
* reps[i]` elements, and the values of `input` are replicated
|
* `reps[i]` times along the i'th dimension. For example, tiling
|
* `[a, b, c, d]` by `[2]` produces `[a, b, c, d, a, b, c, d]`.
|
*
|
* ```js
|
* const a = tf.tensor1d([1, 2]);
|
*
|
* a.tile([2]).print(); // or a.tile([2])
|
* ```
|
*
|
* ```js
|
* const a = tf.tensor2d([1, 2, 3, 4], [2, 2]);
|
*
|
* a.tile([1, 2]).print(); // or a.tile([1, 2])
|
* ```
|
* @param x The tensor to tile.
|
* @param reps Determines the number of replications per dimension.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Slicing and Joining'} */
|
declare function tile_<T extends Tensor>(x: T | TensorLike, reps: number[]): T;
|
/**
|
* Pads a `tf.Tensor1D` with a given value and paddings. See `pad` for details.
|
*/
|
declare function pad1d_(x: Tensor1D | TensorLike, paddings: [number, number], constantValue?: number): Tensor1D;
|
/**
|
* Pads a `tf.Tensor2D` with a given value and paddings. See `pad` for details.
|
*/
|
declare function pad2d_(x: Tensor2D | TensorLike, paddings: [[number, number], [number, number]], constantValue?: number): Tensor2D;
|
/**
|
* Pads a `tf.Tensor3D` with a given value and paddings. See `pad` for details.
|
*/
|
declare function pad3d_(x: Tensor3D | TensorLike, paddings: [[number, number], [number, number], [number, number]], constantValue?: number): Tensor3D;
|
/**
|
* Pads a `tf.Tensor4D` with a given value and paddings. See `pad` for details.
|
*/
|
declare function pad4d_(x: Tensor4D | TensorLike, paddings: [[number, number], [number, number], [number, number], [number, number]], constantValue?: number): Tensor4D;
|
/**
|
* Pads a `tf.Tensor` with a given value and paddings.
|
*
|
* This operation currently only implements the `CONSTANT` mode.
|
*
|
* Also available are stricter rank-specific methods with the same signature
|
* as this method that assert that `paddings` is of given length.
|
* - `tf.pad1d`
|
* - `tf.pad2d`
|
* - `tf.pad3d`
|
* - `tf.pad4d`
|
*
|
* ```js
|
* const x = tf.tensor1d([1, 2, 3, 4]);
|
* x.pad([[1, 2]]).print();
|
* ```
|
* @param x The tensor to pad.
|
* @param paddings An array of length `R` (the rank of the tensor), where
|
* each element is a length-2 tuple of ints `[padBefore, padAfter]`,
|
* specifying how much to pad along each dimension of the tensor.
|
* @param constantValue The pad value to use. Defaults to 0.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function pad_<T extends Tensor>(x: T | TensorLike, paddings: Array<[number, number]>, constantValue?: number): T;
|
/**
|
* Stacks a list of rank-`R` `tf.Tensor`s into one rank-`(R+1)` `tf.Tensor`.
|
*
|
* ```js
|
* const a = tf.tensor1d([1, 2]);
|
* const b = tf.tensor1d([3, 4]);
|
* const c = tf.tensor1d([5, 6]);
|
* tf.stack([a, b, c]).print();
|
* ```
|
*
|
* @param tensors A list of tensor objects with the same shape and dtype.
|
* @param axis The axis to stack along. Defaults to 0 (the first dim).
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Slicing and Joining'} */
|
declare function stack_<T extends Tensor>(tensors: Array<T | TensorLike>, axis?: number): Tensor;
|
/**
|
* This operation reshapes the "batch" dimension 0 into `M + 1` dimensions of
|
* shape `blockShape + [batch]`, interleaves these blocks back into the grid
|
* defined by the spatial dimensions `[1, ..., M]`, to obtain a result with
|
* the same rank as the input. The spatial dimensions of this intermediate
|
* result are then optionally cropped according to `crops` to produce the
|
* output. This is the reverse of `tf.spaceToBatchND`. See below for a precise
|
* description.
|
*
|
* ```js
|
* const x = tf.tensor4d([1, 2, 3, 4], [4, 1, 1, 1]);
|
* const blockShape = [2, 2];
|
* const crops = [[0, 0], [0, 0]];
|
*
|
* x.batchToSpaceND(blockShape, crops).print();
|
* ```
|
*
|
* @param x A `tf.Tensor`. N-D with `x.shape` = `[batch] + spatialShape +
|
* remainingShape`, where spatialShape has `M` dimensions.
|
* @param blockShape A 1-D array. Must have shape `[M]`, all values must
|
* be >= 1.
|
* @param crops A 2-D array. Must have shape `[M, 2]`, all values must be >= 0.
|
* `crops[i] = [cropStart, cropEnd]` specifies the amount to crop from input
|
* dimension `i + 1`, which corresponds to spatial dimension `i`. It is required
|
* that `cropStart[i] + cropEnd[i] <= blockShape[i] * inputShape[i + 1]`
|
*
|
* This operation is equivalent to the following steps:
|
*
|
* 1. Reshape `x` to `reshaped` of shape: `[blockShape[0], ...,
|
* blockShape[M-1], batch / prod(blockShape), x.shape[1], ...,
|
* x.shape[N-1]]`
|
*
|
* 2. Permute dimensions of `reshaped`to produce `permuted` of shape `[batch /
|
* prod(blockShape),x.shape[1], blockShape[0], ..., x.shape[M],
|
* blockShape[M-1],x.shape[M+1], ..., x.shape[N-1]]`
|
*
|
* 3. Reshape `permuted` to produce `reshapedPermuted` of shape `[batch /
|
* prod(blockShape),x.shape[1] * blockShape[0], ..., x.shape[M] *
|
* blockShape[M-1],x.shape[M+1], ..., x.shape[N-1]]`
|
*
|
* 4. Crop the start and end of dimensions `[1, ..., M]` of `reshapedPermuted`
|
* according to `crops` to produce the output of shape: `[batch /
|
* prod(blockShape),x.shape[1] * blockShape[0] - crops[0,0] - crops[0,1],
|
* ..., x.shape[M] * blockShape[M-1] - crops[M-1,0] -
|
* crops[M-1,1],x.shape[M+1], ..., x.shape[N-1]]`
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function batchToSpaceND_<T extends Tensor>(x: T | TensorLike, blockShape: number[], crops: number[][]): T;
|
/**
|
* This operation divides "spatial" dimensions `[1, ..., M]` of the input into
|
* a grid of blocks of shape `blockShape`, and interleaves these blocks with
|
* the "batch" dimension (0) such that in the output, the spatial
|
* dimensions `[1, ..., M]` correspond to the position within the grid,
|
* and the batch dimension combines both the position within a spatial block
|
* and the original batch position. Prior to division into blocks,
|
* the spatial dimensions of the input are optionally zero padded
|
* according to `paddings`. See below for a precise description.
|
*
|
* ```js
|
* const x = tf.tensor4d([1, 2, 3, 4], [1, 2, 2, 1]);
|
* const blockShape = [2, 2];
|
* const paddings = [[0, 0], [0, 0]];
|
*
|
* x.spaceToBatchND(blockShape, paddings).print();
|
* ```
|
*
|
* @param x A `tf.Tensor`. N-D with `x.shape` = `[batch] + spatialShape +
|
* remainingShape`, where spatialShape has `M` dimensions.
|
* @param blockShape A 1-D array. Must have shape `[M]`, all values must
|
* be >= 1.
|
* @param paddings A 2-D array. Must have shape `[M, 2]`, all values must be >=
|
* 0. `paddings[i] = [padStart, padEnd]` specifies the amount to zero-pad
|
* from input dimension `i + 1`, which corresponds to spatial dimension `i`. It
|
* is required that
|
* `(inputShape[i + 1] + padStart + padEnd) % blockShape[i] === 0`
|
*
|
* This operation is equivalent to the following steps:
|
*
|
* 1. Zero-pad the start and end of dimensions `[1, ..., M]` of the input
|
* according to `paddings` to produce `padded` of shape paddedShape.
|
*
|
* 2. Reshape `padded` to `reshapedPadded` of shape:
|
* `[batch] + [paddedShape[1] / blockShape[0], blockShape[0], ...,
|
* paddedShape[M] / blockShape[M-1], blockShape[M-1]] + remainingShape`
|
*
|
* 3. Permute dimensions of `reshapedPadded` to produce `permutedReshapedPadded`
|
* of shape: `blockShape + [batch] + [paddedShape[1] / blockShape[0], ...,
|
* paddedShape[M] / blockShape[M-1]] + remainingShape`
|
*
|
* 4. Reshape `permutedReshapedPadded` to flatten `blockShape` into the
|
* batch dimension, producing an output tensor of shape:
|
* `[batch * prod(blockShape)] + [paddedShape[1] / blockShape[0], ...,
|
* paddedShape[M] / blockShape[M-1]] + remainingShape`
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function spaceToBatchND_<T extends Tensor>(x: T | TensorLike, blockShape: number[], paddings: number[][]): T;
|
/**
|
* Unstacks a `tf.Tensor` of rank-`R` into a list of rank-`(R-1)` `tf.Tensor`s.
|
*
|
* ```js
|
* const a = tf.tensor2d([1, 2, 3, 4], [2, 2]);
|
*
|
* tf.unstack(a).forEach(tensor => tensor.print());
|
* ```
|
*
|
* @param x A tensor object.
|
* @param axis The axis to unstack along. Defaults to 0 (the first dim).
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Slicing and Joining'} */
|
declare function unstack_(x: Tensor | TensorLike, axis?: number): Tensor[];
|
/**
|
* Computes the cumulative sum of a `tf.Tensor` along `axis`.
|
*
|
* ```js
|
* const x = tf.tensor([1, 2, 3, 4]);
|
* x.cumsum().print();
|
* ```
|
* ```js
|
* const x = tf.tensor([[1, 2], [3, 4]]);
|
* x.cumsum().print();
|
* ```
|
*
|
* @param x The input tensor to be summed.
|
* @param axis The axis along which to sum. Optional. Defaults to 0.
|
* @param exclusive Whether to perform exclusive cumulative sum. Optional.
|
* Defaults to false. If set to true then the sum of each tensor entry
|
* does not include its own value, but only the values previous to it
|
* along the specified axis.
|
* @param reverse Whether to sum in the opposite direction. Optional.
|
* Defaults to false.
|
*/
|
/** @doc {heading: 'Operations', subheading: 'Scan'} */
|
declare function cumsum_<T extends Tensor>(x: Tensor | TensorLike, axis?: number, exclusive?: boolean, reverse?: boolean): T;
|
/**
|
* Returns a `tf.Tensor` that has expanded rank, by inserting a dimension
|
* into the tensor's shape.
|
*
|
* ```js
|
* const x = tf.tensor1d([1, 2, 3, 4]);
|
* const axis = 1;
|
* x.expandDims(axis).print();
|
* ```
|
*
|
* @param x The input tensor whose dimensions to be expanded.
|
* @param axis The dimension index at which to insert shape of `1`. Defaults
|
* to 0 (the first dimension).
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function expandDims_<R2 extends Rank>(x: Tensor | TensorLike, axis?: number): Tensor<R2>;
|
/**
|
* Rearranges data from depth into blocks of spatial data. More specifically,
|
* this op outputs a copy of the input tensor where values from the `depth`
|
* dimension are moved in spatial blocks to the `height` and `width` dimensions.
|
* The attr `blockSize` indicates the input block size and how the data is
|
* moved.
|
*
|
* - Chunks of data of size `blockSize * blockSize` from depth are rearranged
|
* into non-overlapping blocks of size `blockSize x blockSize`
|
*
|
* - The width the output tensor is `inputWidth * blockSize`, whereas the
|
* height is `inputHeight * blockSize`
|
*
|
* - The Y, X coordinates within each block of the output image are determined
|
* by the high order component of the input channel index
|
*
|
* - The depth of the input tensor must be divisible by `blockSize *
|
* blockSize`
|
*
|
* The `dataFormat` attr specifies the layout of the input and output tensors
|
* with the following options: "NHWC": [ `batch, height, width, channels` ]
|
* "NCHW": [ `batch, channels, height, width` ]
|
*
|
* ```js
|
* const x = tf.tensor4d([1, 2, 3, 4], [1, 1, 1, 4]);
|
* const blockSize = 2;
|
* const dataFormat = "NHWC";
|
*
|
* tf.depthToSpace(x, blockSize, dataFormat).print();
|
* ```
|
*
|
* @param x The input tensor of rank 4
|
* @param blockSIze An `int` that is `>= 2`. The size of the spatial block
|
* @param dataFormat An optional string from: "NHWC", "NCHW". Defaults to "NHWC"
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function depthToSpace_(x: Tensor4D | TensorLike4D, blockSize: number, dataFormat?: 'NHWC' | 'NCHW'): Tensor4D;
|
/**
|
* Computes the difference between two lists of numbers.
|
*
|
* Given a Tensor `x` and a Tensor `y`, this operation returns a Tensor `out`
|
* that represents all values that are in `x` but not in `y`. The returned
|
* Tensor `out` is sorted in the same order that the numbers appear in `x`
|
* (duplicates are preserved). This operation also returns a Tensor indices that
|
* represents the position of each out element in `x`. In other words:
|
*
|
* `out[i] = x[idx[i]] for i in [0, 1, ..., out.length - 1]`
|
*
|
* ```js
|
* const x = [1, 2, 3, 4, 5, 6];
|
* const y = [1, 3, 5];
|
*
|
* const [out, indices] = await tf.setdiff1dAsync(x, y);
|
* out.print(); // [2, 4, 6]
|
* indices.print(); // [1, 3, 5]
|
* ```
|
*
|
* @param x 1-D Tensor. Values to keep.
|
* @param y 1-D Tensor. Must have the same type as x. Values to exclude in the
|
* output.
|
* @returns Promise of Tensor tuple [out, indices].
|
* out: Tensor with the same type as x.
|
* indices: A Tensor of type int32.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Transformations'} */
|
declare function setdiff1dAsync_(x: Tensor | TensorLike, y: Tensor | TensorLike): Promise<[Tensor, Tensor]>;
|
/**
|
* Creates an empty `tf.TensorBuffer` with the specified `shape` and `dtype`.
|
*
|
* The values are stored in CPU as `TypedArray`. Fill the buffer using
|
* `buffer.set()`, or by modifying directly `buffer.values`.
|
*
|
* When done, call `buffer.toTensor()` to get an immutable `tf.Tensor` with
|
* those values.
|
*
|
* ```js
|
* // Create a buffer and set values at particular indices.
|
* const buffer = tf.buffer([2, 2]);
|
* buffer.set(3, 0, 0);
|
* buffer.set(5, 1, 0);
|
*
|
* // Convert the buffer back to a tensor.
|
* buffer.toTensor().print();
|
* ```
|
*
|
* @param shape An array of integers defining the output tensor shape.
|
* @param dtype The dtype of the buffer. Defaults to 'float32'.
|
* @param values The values of the buffer as `TypedArray`. Defaults to
|
* zeros.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function buffer<R extends Rank, D extends DataType = 'float32'>(shape: ShapeMap[R], dtype?: D, values?: DataTypeMap[D]): TensorBuffer<R, D>;
|
/**
|
* Prints information about the `tf.Tensor` including its data.
|
*
|
* ```js
|
* const verbose = true;
|
* tf.tensor2d([1, 2, 3, 4], [2, 2]).print(verbose);
|
* ```
|
* @param x The tensor to be printed.
|
* @param verbose Whether to print verbose information about the ` Tensor`,
|
* including dtype and size.
|
*/
|
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
|
declare function print<T extends Tensor>(x: T, verbose?: boolean): void;
|
export { buffer, // Not wrapped in op() since no tensors.
|
print };
|
export declare const batchToSpaceND: typeof batchToSpaceND_;
|
export declare const broadcastTo: typeof broadcastTo_;
|
export declare const cast: typeof cast_;
|
export declare const clone: typeof clone_;
|
export declare const cumsum: typeof cumsum_;
|
export declare const depthToSpace: typeof depthToSpace_;
|
export declare const expandDims: typeof expandDims_;
|
export declare const eye: typeof eye_;
|
export declare const multinomial: typeof multinomial_;
|
export declare const oneHot: typeof oneHot_;
|
export declare const pad: typeof pad_;
|
export declare const pad1d: typeof pad1d_;
|
export declare const pad2d: typeof pad2d_;
|
export declare const pad3d: typeof pad3d_;
|
export declare const pad4d: typeof pad4d_;
|
export declare const rand: typeof rand_;
|
export declare const randomNormal: typeof randomNormal_;
|
export declare const randomGamma: typeof randomGamma_;
|
export declare const randomUniform: typeof randomUniform_;
|
export declare const reshape: typeof reshape_;
|
export declare const spaceToBatchND: typeof spaceToBatchND_;
|
export declare const squeeze: typeof squeeze_;
|
export declare const stack: typeof stack_;
|
export declare const tile: typeof tile_;
|
export declare const truncatedNormal: typeof truncatedNormal_;
|
export declare const unstack: typeof unstack_;
|
export declare const setdiff1dAsync: typeof setdiff1dAsync_;
|