<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNS/applyTopK(k:input:bestValues:bestIndices:axis:batchSize:filterParameters:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4BNNSO9applyTopK1k5input10bestValues0F7Indices4axis9batchSize16filterParametersySi_So21BNNSNDArrayDescriptoraA2MS2iSo010BNNSFilterM0aSgtKFZ"
  },
  "title" : "applyTopK(k:input:bestValues:bestIndices:axis:batchSize:filterParameters:)"
}
-->

# applyTopK(k:input:bestValues:bestIndices:axis:batchSize:filterParameters:)

Applies a top-k filter directly to an input.

```
static func applyTopK(k: Int, input: BNNSNDArrayDescriptor, bestValues: BNNSNDArrayDescriptor, bestIndices: BNNSNDArrayDescriptor, axis: Int, batchSize: Int, filterParameters: BNNSFilterParameters? = nil) throws
```

## Parameters

`k`

The number of entries the operation finds.

`input`

The descriptor of the input.

`bestValues`

The descriptor of the k best values generated by the operation.

`bestIndices`

The descriptor of the indices of the k best values generated by the operation.

`axis`

The axis along which the operation finds top-k entries.

`batchSize`

The number of input-output pairs to process.

`filterParameters`

The filter runtime parameters.

## Discussion

> Important:
> The input data type and best values data type must be `float`, and the best indices data type must be `int32`.

## See Also

[`func BNNSDirectApplyTopK(Int, Int, Int, UnsafePointer<BNNSNDArrayDescriptor>, Int, UnsafeMutablePointer<BNNSNDArrayDescriptor>, Int, UnsafeMutablePointer<BNNSNDArrayDescriptor>?, Int, UnsafePointer<BNNSFilterParameters>?) -> Int32`](/documentation/Accelerate/BNNSDirectApplyTopK(_:_:_:_:_:_:_:_:_:_:))

Applies a top-k filter directly to an input.



---

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)