<!--
{
  "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/topK(_:axis:findLargest:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7BuilderV6TensorV4topK_4axis11findLargestAGy__xG6values_AGy__s5Int32VG7indicestSi_SiSbtF"
  },
  "title" : "topK(_:axis:findLargest:)"
}
-->

# topK(_:axis:findLargest:)

Adds a top-k operation to the current graph.

```
func topK(_ k: Int, axis: Int, findLargest: Bool) -> (values: BNNSGraph.Builder.Tensor<T>, indices: BNNSGraph.Builder.Tensor<Int32>)
```

## Discussion

The output of this graph is a pair of tensors `(values, indices)` that contains the top-k
values and indices from the tensor from the given dimension. If `largest` is `true`, then
output the largest `k` values and their corresponding indices, otherwise output the smallest.

---

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)