---
title: BNNSArithmeticBinary
framework: accelerate
role: symbol
role_heading: Structure
path: accelerate/bnnsarithmeticbinary
---

# BNNSArithmeticBinary

A structure that contains the inputs and output of an arithmetic operation with two inputs.

## Declaration

```swift
struct BNNSArithmeticBinary
```

## Overview

Overview Use a BNNSArithmeticUnary structure to pass the descriptions and types of the inputs and output of a binary arithmetic operation to BNNSLayerParametersArithmetic. The following code shows how to calculate the element-wise sums of two vectors: let inputOne: [Float] = [ 1,  2,  3,  4,  5,  6,  7,  8,  9,  10] let inputTwo: [Float] = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] let count = inputOne.count var outputs = [Float](repeating: 0,                       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 = BNNSArithmeticBinary(in1: descriptor, in1_type: BNNSSample,                                   in2: descriptor, in2_type: BNNSConstant,                                   out: descriptor, out_type: BNNSSample)

let function = BNNSArithmeticAdd

withUnsafeMutableBytes(of: &fields) { fieldsPtr in          var layerParameters = BNNSLayerParametersArithmetic(arithmetic_function: function,                                                         arithmetic_function_fields: fieldsPtr.baseAddress!,                                                         activation: .identity)          guard let arithmeticLayer = BNNSFilterCreateLayerArithmetic(&layerParameters, nil) else {         print("Binary BNNSFilterCreateLayerArithmetic returned nil")         return     }     defer {         BNNSFilterDestroy(arithmeticLayer)     }          inputOne.withUnsafeBytes { in1Ptr in         inputTwo.withUnsafeBytes { in2Ptr in                          var input = [in1Ptr.baseAddress!, in2Ptr.baseAddress!]                          let error = BNNSArithmeticFilterApplyBatch(arithmeticLayer,                                                        1,                                                        2,                                                        &input,                                                        [inputOne.count, inputTwo.count],                                                        &outputs,                                                        outputs.count)                          print("BNNSArithmeticFilterApplyBatch: error", error)         }     } }

// Prints "[11.0, 22.0, 33.0, 44.0, 55.0, 66.0, 77.0, 88.0, 99.0, 110.0]" print("Binary Arithmetic: outputs", outputs)

## Topics

### Creating an Arithmetic Structure

- [init(in1:in1_type:in2:in2_type:out:out_type:)](accelerate/bnnsarithmeticbinary/init(in1:in1_type:in2:in2_type:out:out_type:).md)
- [init()](accelerate/bnnsarithmeticbinary/init().md)

### Inspecting the Properties of an Arithmetic Structure

- [in1](accelerate/bnnsarithmeticbinary/in1.md)
- [in1_type](accelerate/bnnsarithmeticbinary/in1_type.md)
- [in2](accelerate/bnnsarithmeticbinary/in2.md)
- [in2_type](accelerate/bnnsarithmeticbinary/in2_type.md)
- [out](accelerate/bnnsarithmeticbinary/out.md)
- [out_type](accelerate/bnnsarithmeticbinary/out_type.md)

## Relationships

### Conforms To

- [BitwiseCopyable](swift/bitwisecopyable.md)

## See Also

### Arithmetic layers

- [BNNS.UnaryArithmeticLayer](accelerate/bnns/unaryarithmeticlayer.md)
- [BNNS.BinaryArithmeticLayer](accelerate/bnns/binaryarithmeticlayer.md)
- [BNNS.TernaryArithmeticLayer](accelerate/bnns/ternaryarithmeticlayer.md)
- [BNNSDescriptorType](accelerate/bnnsdescriptortype.md)
- [BNNSArithmeticUnary](accelerate/bnnsarithmeticunary.md)
- [BNNSArithmeticTernary](accelerate/bnnsarithmeticternary.md)
- [BNNSArithmeticFunction](accelerate/bnnsarithmeticfunction.md)
- [BNNSLayerParametersArithmetic](accelerate/bnnslayerparametersarithmetic.md)
- [BNNSFilterCreateLayerArithmetic(_:_:)](accelerate/bnnsfiltercreatelayerarithmetic(_:_:).md)
- [BNNSArithmeticFilterApplyBatch(_:_:_:_:_:_:_:)](accelerate/bnnsarithmeticfilterapplybatch(_:_:_:_:_:_:_:).md)
- [BNNSArithmeticFilterApplyBackwardBatch(_:_:_:_:_:_:_:_:_:_:_:)](accelerate/bnnsarithmeticfilterapplybackwardbatch(_:_:_:_:_:_:_:_:_:_:_:).md)
