<!--
{
  "availability" : [
    "iOS: 14.0.0 - 18.0.0",
    "iPadOS: 14.0.0 - 18.0.0",
    "macCatalyst: 14.0.0 - 18.0.0",
    "macOS: 11.0.0 - 15.0.0",
    "tvOS: 14.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0",
    "watchOS: 7.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSArithmeticUnary",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@SA@BNNSArithmeticUnary"
  },
  "title" : "BNNSArithmeticUnary"
}
-->

# BNNSArithmeticUnary

A structure that contains the input and output of an arithmetic operation with a single input.

```
struct BNNSArithmeticUnary
```

## Overview

Use a [`BNNSArithmeticUnary`](/documentation/Accelerate/BNNSArithmeticUnary) structure to pass the descriptions and types of the input and output of a unary arithmetic operation to [`BNNSLayerParametersArithmetic`](/documentation/Accelerate/BNNSLayerParametersArithmetic).

The following code shows how to calculate the element-wise square roots of a vector:

```swift
let input: [Float] = [4, 16, 9, 25, 100]
let count = input.count
var output = [Float](repeating: .nan,
                     count: count)

let descriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                       layout: BNNSDataLayoutVector,
                                       size: (count, 0, 0, 0, 0, 0, 0, 0),
                                       stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                       data: nil,
                                       data_type: .float,
                                       table_data: nil,
                                       table_data_type: .float,
                                       data_scale: 1,
                                       data_bias: 0)

var fields = BNNSArithmeticUnary(in: descriptor,
                                 in_type: BNNSSample,
                                 out: descriptor,
                                 out_type: BNNSSample)

withUnsafeMutablePointer(to: &fields) { fieldsPtr in
    
    var layerParameters = BNNSLayerParametersArithmetic(arithmetic_function: BNNSArithmeticSquareRoot,
                                                        arithmetic_function_fields: fieldsPtr,
                                                        activation: .identity)
    
    guard let arithmeticLayer = BNNSFilterCreateLayerArithmetic(&layerParameters, nil) else {
        print("Unary BNNSFilterCreateLayerArithmetic returns nil")
        return
    }
    defer {
        BNNSFilterDestroy(arithmeticLayer)
    }
    
    input.withUnsafeBytes { inPtr in
        var rawPtr = inPtr.baseAddress!
        
        BNNSArithmeticFilterApplyBatch(arithmeticLayer, 1, 1,
                                       &rawPtr,
                                       [count],
                                       &output,
                                       count)
    }
}

// Prints "[2.0, 4.0, 3.0, 5.0, 10.0]"
print("Unary Arithmetic: outputs", output)
```

## Topics

### Creating an Arithmetic Structure

[`init(in:in_type:out:out_type:)`](/documentation/Accelerate/BNNSArithmeticUnary/init(in:in_type:out:out_type:))

Returns a new arithmetic structure that takes a single input from the specified parameters.

[`init()`](/documentation/Accelerate/BNNSArithmeticUnary/init())

Returns a new arithmetic structure that takes a single input.

### Inspecting the Properties of an Arithmetic Structure

[`in`](/documentation/Accelerate/BNNSArithmeticUnary/in)

The descriptor of the input.

[`in_type`](/documentation/Accelerate/BNNSArithmeticUnary/in_type)

The descriptor type of the input.

[`out`](/documentation/Accelerate/BNNSArithmeticUnary/out)

The descriptor of the output.

[`out_type`](/documentation/Accelerate/BNNSArithmeticUnary/out_type)

The descriptor type of the output.



---

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)