---
title: "applyTopK(k:input:bestValues:bestIndices:axis:batchSize:filterParameters:)"
framework: accelerate
role: symbol
role_heading: Type Method
path: "accelerate/bnns/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.

## Declaration

```swift
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

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

### Related Documentation

- [BNNSDirectApplyTopK(_:_:_:_:_:_:_:_:_:_:)](accelerate/bnnsdirectapplytopk(_:_:_:_:_:_:_:_:_:_:).md)

### Top-k layers

- [applyInTopK(k:input:testIndices:output:axis:batchSize:filterParameters:)](accelerate/bnns/applyintopk(k:input:testindices:output:axis:batchsize:filterparameters:).md)
