<!--
{
  "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/BNNSClipByNorm(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSClipByNorm"
  },
  "title" : "BNNSClipByNorm(_:_:_:_:)"
}
-->

# BNNSClipByNorm(_:_:_:_:)

Clips a tensor’s values to a maximum Euclidean norm.

```
func BNNSClipByNorm(_ dest: UnsafeMutablePointer<BNNSNDArrayDescriptor>, _ src: UnsafePointer<BNNSNDArrayDescriptor>, _ max_norm: Float, _ axis_flags: UInt32) -> Int32
```

## Parameters

`dest`

The descriptor of the output.

`src`

The descriptor of the input.

`max_norm`

The maximum Euclidean norm.

`axis_flags`

The dimensions that the function uses to compute the Euclidean norm. Set to `0` for the function to compute the norm over all dimensions.

## Discussion

Use this function to clip the values in an input tensor to a maximum Euclidean norm. The Euclidean norm is the square root of the sum of squares of the two tensors.

The function supports clipping across the entire tensor or by the norms of the dimension you specify.

The following code clips the values on axis `0b0010` to a Euclidean norm of `10`. The Euclidean norms of `[1, 2, 3]` and `[4, 5, 6]` are both less than 10, and function returns them unchanged. However, the Euclidean norm of `[7, 8, 9]` is greater than 10, and the function returns them scaled accordingly.

```swift
static func clipToNorm() {
    
    let inputData = UnsafeMutableBufferPointer<Float>.allocate(capacity: 9)
    _ = inputData.initialize(from: [1, 2, 3,
                                    4, 5, 6,
                                    7, 8, 9])
    
    var inputDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                layout: BNNSDataLayoutRowMajorMatrix,
                                                size: (3, 3, 0, 0, 0, 0, 0, 0),
                                                stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                data: inputData.baseAddress!,
                                                data_type: BNNSDataType.float,
                                                table_data: nil,
                                                table_data_type: BNNSDataType.float,
                                                data_scale: 1, data_bias: 0)
    
    let outputData = UnsafeMutableBufferPointer<Float>.allocate(capacity: 9)
    var outputDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                 layout: BNNSDataLayoutRowMajorMatrix,
                                                 size: (3, 3, 0, 0, 0, 0, 0, 0),
                                                 stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                 data: outputData.baseAddress!,
                                                 data_type: BNNSDataType.float,
                                                 table_data: nil,
                                                 table_data_type: BNNSDataType.float,
                                                 data_scale: 1, data_bias: 0)
    
    BNNSClipByNorm(&outputDescriptor,
                    &inputDescriptor,
                    10,
                    0b0010)
    
    // Prints `[1.0, 2.0, 3.0,
    //          4.0, 5.0, 6.0,
    //          5.0257072, 5.743665, 6.461623]`
    print(Array(outputData))
    
    inputData.deallocate()
    outputData.deallocate()
}
```

---

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)