UNPKG

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