UNPKG

1.71 kBTypeScriptView Raw
1import { Tensor } from '../tensor';
2import { TensorLike } from '../types';
3/**
4 * Gather slices from input tensor into a Tensor with shape specified by
5 * `indices`.
6 *
7 * `indices` is an K-dimensional integer tensor, best thought of as a
8 * (K-1)-dimensional tensor of indices into input, where each element defines a
9 * slice of input:
10 * output[\\(i_0, ..., i_{K-2}\\)] = input[indices[\\(i_0, ..., i_{K-2}\\)]]
11 *
12 * Whereas in `tf.gather`, `indices` defines slices into the first dimension of
13 * input, in `tf.gatherND`, `indices` defines slices into the first N dimensions
14 * of input, where N = indices.shape[-1].
15 *
16 * The last dimension of indices can be at most the rank of input:
17 * indices.shape[-1] <= input.rank
18 *
19 * The last dimension of `indices` corresponds to elements
20 * (if indices.shape[-1] == input.rank) or slices
21 * (if indices.shape[-1] < input.rank) along dimension indices.shape[-1] of
22 * input.
23 * The output tensor has shape
24 * indices.shape[:-1] + input.shape[indices.shape[-1]:]
25 *
26 * Note that on CPU, if an out of bound index is found, an error is returned. On
27 * GPU, if an out of bound index is found, a 0 is stored in the corresponding
28 * output value.
29 *
30 * ```js
31 * const indices = tf.tensor2d([0, 1, 1, 0], [2,2], 'int32');
32 * const input = tf.tensor2d([9, 10, 11, 12], [2, 2]);
33 * tf.gatherND(input, indices).print() // [10, 11]
34 * ```
35 *
36 * @param x The tensor from which to gather values.
37 * @param indices Index tensor, must be of type int32.
38 *
39 * @doc {heading: 'Operations', subheading: 'Slicing and Joining'}
40 */
41declare function gatherND_(x: Tensor | TensorLike, indices: Tensor | TensorLike): Tensor;
42export declare const gatherND: typeof gatherND_;
43export {};