<!--
{
  "availability" : [
    "iOS: 15.0.0 - 18.0.0",
    "iPadOS: 15.0.0 - 18.0.0",
    "macCatalyst: 15.0.0 - 18.0.0",
    "macOS: 12.0.0 - 15.0.0",
    "tvOS: 15.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0",
    "watchOS: 8.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSDirectApplyQuantizer(_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSDirectApplyQuantizer"
  },
  "title" : "BNNSDirectApplyQuantizer(_:_:_:_:_:)"
}
-->

# BNNSDirectApplyQuantizer(_:_:_:_:_:)

Applies a quantization layer directly to two input matrices.

```
func BNNSDirectApplyQuantizer(_ layer_params: UnsafePointer<BNNSLayerParametersQuantization>, _ filter_params: UnsafePointer<BNNSFilterParameters>?, _ batch_size: Int, _ input_stride: Int, _ output_stride: Int) -> Int32
```

## Parameters

`layer_params`

The layer parameters.

`filter_params`

The filter runtime parameters.

`batch_size`

The number of input-output pairs.

`input_stride`

The increment, in values, between inputs.

`output_stride`

The increment, in values, between outputs.

## Discussion

Use this function, in conjunction with a [`BNNSLayerParametersQuantization`](/documentation/Accelerate/BNNSLayerParametersQuantization), to convert tensors to different precisions. Pass the [`BNNSQuantizerFunctionQuantize`](/documentation/Accelerate/BNNSQuantizerFunctionQuantize) quantizer function to convert a higher-precsion tensor to a lower-precision tensor. Pass [`BNNSQuantizerFunctionDequantize`](/documentation/Accelerate/BNNSQuantizerFunctionDequantize) to convert a lower-precsion tensor to a higher-precision tensor.

Quantization supports the following conversions:

|Source                                                                                 |Destination                                                                                                                                                                         |
|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`BNNSDataTypeInt32` ![](spacer) `BNNSDataTypeFloat16` ![](spacer) `BNNSDataTypeFloat32`|`BNNSDataTypeInt8` ![](spacer) `BNNSDataTypeUInt8` ![](spacer) `BNNSDataTypeInt16` ![](spacer) `BNNSDataTypeUInt16` ![](spacer) `BNNSDataTypeInt32` ![](spacer) `BNNSDataTypeUInt32`|

Dequantization supports the following conversions:

|Source                                                                                                                                                                              |Destination                                                                            |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|
|`BNNSDataTypeInt8` ![](spacer) `BNNSDataTypeUInt8` ![](spacer) `BNNSDataTypeInt16` ![](spacer) `BNNSDataTypeUInt16` ![](spacer) `BNNSDataTypeInt32` ![](spacer) `BNNSDataTypeUInt32`|`BNNSDataTypeInt32` ![](spacer) `BNNSDataTypeFloat16` ![](spacer) `BNNSDataTypeFloat32`|

You can provide optional scale and bias that the function applies during conversion. Quantization returns `y = scale*x + bias`, and dequantization returns `y = (x-bias)/scale`.

If you supply scale and bias descriptors, they must have a vector layout and a size that matches the size of the axis that you specify. If you’re applying scale and bias to the entire tensor, scale and bias descriptors must have a size of 1.

See [`BNNSQuantizerFunctionDequantize`](/documentation/Accelerate/BNNSQuantizerFunctionDequantize) and [`BNNSQuantizerFunctionQuantize`](/documentation/Accelerate/BNNSQuantizerFunctionQuantize) for examples of using this function.

---

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)