# GatherNd — MindSpore Signal+ 使用手册 alpha 文档

# GatherNd

根据索引张量中的坐标，从输入张量中收集切片或元素。

GatherNd 允许根据 `indices` 提供的多维索引，在 `input` 张量的指定轴上进行切片提取。如果 `indices` 的最后一个维度长度为 `K`，则它代表从 `input` 的前 `K` 个维度中提取对应的子张量（切片）。

输入：

  - input - 输入数据张量地址。

  - output - 计算结果张量地址。

  - input_shape - 输入张量的形状数组地址。

  - input_ndim - 输入张量的维度数。

  - indices - 索引张量地址（类型固定为 int32）。

  - indices_shape - 索引张量的形状数组地址。

  - indices_ndim - 索引张量的维度数。

  - core_mask(int, 可选) - 核掩码（仅适用于共享存储版本）。

输出：

  - output - 收集后的数据存放地址。

支持平台：

  `FT78NE` `MT7004`

备注

- FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128

- MT7004 支持 fp16, fp32, int16, int32, cplx64

- 索引张量 (indices) 在所有平台上均使用 int32 类型。

- 坐标索引必须在输入张量维度的合法范围内，否则行为未定义。

共享存储版本:

void i8_gather_nd_s(int8_t *input, int8_t *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void i16_gather_nd_s(int16_t *input, int16_t *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void i32_gather_nd_s(int *input, int *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void hp_gather_nd_s(half *input, half *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void fp_gather_nd_s(float *input, float *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void dp_gather_nd_s(double *input, double *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void c64_gather_nd_s(float *input, float *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

void c128_gather_nd_s(double *input, double *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim, int core_mask)

  C调用示例：

       1// FT78NE 示例（共享存储）
       2#include <stdio.h>
       3#include "78NE/utils.h"
       4
       5int main() {
       6    float *input = (float *)0xA0000000;    // 输入在 DDR 空间
       7    float *output = (float *)0xB0000000;   // 输出在 DDR 空间
       8    int *indices = (int *)0xC0000000;      // 索引在 DDR 空间
       9    int input_shape[] = {10, 10, 5};
      10    int indices_shape[] = {3, 2};          // 提取3个坐标，每个坐标深度为2
      11    int input_ndim = 3;
      12    int indices_ndim = 2;
      13    int core_mask = 0xFF;
      14
      15    fp_gather_nd_s(input, output, input_shape, input_ndim, indices, indices_shape, indices_ndim, core_mask);
      16    return 0;
      17}

私有存储版本:

void i8_gather_nd_p(int8_t *input, int8_t *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void i16_gather_nd_p(int16_t *input, int16_t *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void i32_gather_nd_p(int *input, int *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void hp_gather_nd_p(half *input, half *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void fp_gather_nd_p(float *input, float *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void dp_gather_nd_p(double *input, double *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void c64_gather_nd_p(float *input, float *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

void c128_gather_nd_p(double *input, double *output, int *input_shape, int input_ndim, int *indices, int *indices_shape, int indices_ndim)

  C调用示例：

       1// MT7004 示例（私有存储）
       2#include <stdio.h>
       3
       4int main() {
       5    float *input = (float *)0x10000000;
       6    float *output = (float *)0x10010000;
       7    int *indices = (int *)0x10020000;
       8    int input_shape[] = {4, 5, 6};
       9    int indices_shape[] = {2, 2, 2};
      10    int input_ndim = 3;
      11    int indices_ndim = 3;
      12
      13    fp_gather_nd_p(input, output, input_shape, input_ndim, indices, indices_shape, indices_ndim);
      14    return 0;
      15}