---
title: "BNNSGatherND(_:_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/bnnsgathernd(_:_:_:_:)"
---

# BNNSGatherND(_:_:_:_:)

Gathers the slices of a tensor.

## Declaration

```swift
func BNNSGatherND(_ input: UnsafePointer<BNNSNDArrayDescriptor>, _ indices: UnsafePointer<BNNSNDArrayDescriptor>, _ output: UnsafeMutablePointer<BNNSNDArrayDescriptor>, _ filter_params: UnsafePointer<BNNSFilterParameters>?) -> Int32
```

## Parameters

- `input`: A pointer to the input descriptor.
- `indices`: A pointer to the indices descriptor.
- `output`: A pointer to the output descriptor.
- `filter_params`: The filter runtime parameters.

## Discussion

Discussion Use BNNSGatherND(_:_:_:_:) to gather slices — that you specify by index — into an output tensor. The function interprets the indices array as a k - 1 dimensional set of lookup vectors, therefore, the indices tensor must have (k - 1) + 1 or k dimensions. If the lookup vectors don’t define a full set of indices, the function treats the undefined indices as a slice. For example, given the following input values: let values: [Float] = [10, 11,                        12, 13,                                                20, 21,                        22, 23,                                                30, 31,                        32, 33]

var inputDescriptor = BNNSNDArrayDescriptor.allocate(     initializingFrom: values,     shape: .tensor3DFirstMajor(3, 2, 2)) The following code shows that a scalar index gathers a 2D slice: let indices: [Int32] = [1] // Elements `20, 21, 22, 23` from slice `1` var indicesDescriptor = BNNSNDArrayDescriptor.allocate(     initializingFrom: indices,     shape: .vector(1))

var outputDescriptor = BNNSNDArrayDescriptor.allocateUninitialized(     scalarType: Float.self,     shape: .matrixFirstMajor(2, 2))

let error = BNNSGatherND(&inputDescriptor,                          &indicesDescriptor,                          &outputDescriptor,                          nil)                           // `outputDescriptor` contains `[20.0, 21.0, 22.0, 23.0]`    The following code shows that a 2D index gathers a 1D slice: let indices: [Int32] = [1, 0] // Elements `20, 21` from row `0` of slice `1` var indicesDescriptor = BNNSNDArrayDescriptor.allocate(     initializingFrom: indices,     shape: .matrixFirstMajor(1, 2))

var outputDescriptor = BNNSNDArrayDescriptor.allocateUninitialized(     scalarType: Float.self,     shape: .matrixFirstMajor(1, 2))

let error = BNNSGatherND(&inputDescriptor,                          &indicesDescriptor,                          &outputDescriptor,                          nil)

// `outputDescriptor` contains `[20.0, 21.0]` The following code shows that a 3D index gathers a single element: let indices: [Int32] = [1, 1, 1] // Element `23` (index `1`) from row `1` of slice `1` var indicesDescriptor = BNNSNDArrayDescriptor.allocate(     initializingFrom: indices,     shape: .tensor3DFirstMajor(1, 1, 3))

var outputDescriptor = BNNSNDArrayDescriptor.allocateUninitialized(     scalarType: Float.self,     shape: .matrixFirstMajor(1, 1))

let error = BNNSGatherND(&inputDescriptor,                          &indicesDescriptor,                          &outputDescriptor,                          nil)                           // `outputDescriptor` contains `[23.0]`

## See Also

### Gather and scatter operations

- [Calculating the dominant colors in an image](accelerate/calculating-the-dominant-colors-in-an-image.md)
- [gather(input:indices:output:axis:filterParameters:)](accelerate/bnns/gather(input:indices:output:axis:filterparameters:).md)
- [gatherND(input:indices:output:filterParameters:)](accelerate/bnns/gathernd(input:indices:output:filterparameters:).md)
- [scatter(input:indices:output:axis:reductionFunction:filterParameters:)](accelerate/bnns/scatter(input:indices:output:axis:reductionfunction:filterparameters:).md)
- [scatterND(input:indices:output:reductionFunction:filterParameters:)](accelerate/bnns/scatternd(input:indices:output:reductionfunction:filterparameters:).md)
- [BNNSGather(_:_:_:_:_:)](accelerate/bnnsgather(_:_:_:_:_:).md)
- [BNNSScatter(_:_:_:_:_:_:)](accelerate/bnnsscatter(_:_:_:_:_:_:).md)
- [BNNSScatterND(_:_:_:_:_:)](accelerate/bnnsscatternd(_:_:_:_:_:).md)
