<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraph/Builder/Tensor/gather(indices:axis:batchDimensionCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7BuilderV6TensorV6gather7indices4axis19batchDimensionCountAGy__xGqd___S2itAE18OperationParameterRd__s5Int32V7ElementRtd__lF"
  },
  "title" : "gather(indices:axis:batchDimensionCount:)"
}
-->

# gather(indices:axis:batchDimensionCount:)

Adds a gather operation to the current graph.

```
func gather(indices: some BNNSGraph.Builder.OperationParameter<Int32>, axis: Int, batchDimensionCount: Int) -> BNNSGraph.Builder.Tensor<T>
```

## Parameters

`indices`

The indices that the operation gathers.

`axis`

The axis over which the operation gathers.

`batchDimensionCount`

The number of additional leading dimensions.

## Discussion

Register a gather operation, which gathers entire slices of the input tensor along the specified axis.
In particular, for each coordinate i valid for the indices tensor, fetch an input slice from
the input tensor by indexing the axis dimension at `indices[i...]`, then store the entire
slice into the output tensor by indexing it at `i...`.

Outputs `y` such that `y[L..., i..., T...] = x[L..., indices[i...], T...]`,
where `L` denotes leading dimensions before the axis, `T` denotes trailing dimensions after the
axis, and i… denotes indices valid for the indices tensor.
`batchDimensionCount` specifies the number of additional leading dimensions present in both `self`
and `indices` which should be only used for a batch processing loop.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)