<!--
{
  "availability" : [
    "*: -",
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNS/clip(to:input:output:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4BNNSO4clip2to5input6outputySNySfG_So21BNNSNDArrayDescriptoraAJtKFZ"
  },
  "title" : "clip(to:input:output:)"
}
-->

# clip(to:input:output:)

Clips the input tensor to a closed range and writes the result to the output tensor.

```
static func clip(to bounds: ClosedRange<Float>, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor) throws
```

## Parameters

`bounds`

The clipping values.

`input`

The descriptor of the input.

`output`

The descriptor of the output.

## Discussion

Use this function to clip the values in an input tensor to a range. The function sets values below the minimum to the minimum and values above the maximum to the maximum.

The following code clips the values of the input tensor to the range `3...6`:

```swift
static func clipToBounds() {
    let input = BNNSNDArrayDescriptor.allocate(
        initializingFrom: [1, 2, 3, 4, 5, 6, 7, 8] as [Float],
        shape: .vector(8))
    
    let output = BNNSNDArrayDescriptor.allocateUninitialized(
        scalarType: Float.self,
        shape: .vector(8))
    
    try? BNNS.clip(to: 3...6,
                   input: input,
                   output: output)
    
    // Prints: `[3.0, 3.0, 3.0, 4.0, 5.0, 6.0, 6.0, 6.0]`
    print(output.makeArray(of: Float.self)!)

    input.deallocate()
    output.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)