---
title: BNNSArithmeticTernary
framework: accelerate
role: symbol
role_heading: Structure
path: accelerate/bnnsarithmeticternary
---

# BNNSArithmeticTernary

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

## Declaration

```swift
struct BNNSArithmeticTernary
```

## Overview

Overview Use a BNNSArithmeticTernary 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 multiply-add of two vectors: static func ternaryArithmetic() {          let aData = UnsafeMutableBufferPointer<Float>.allocate(capacity: 1)     _ = aData.initialize(from: [10])     let aDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),                                             layout: BNNSDataLayoutVector,                                             size: (1, 0, 0, 0, 0, 0, 0, 0),                                             stride: (0, 0, 0, 0, 0, 0, 0, 0),                                             data: aData.baseAddress!,                                             data_type: BNNSDataType.float,                                             table_data: nil,                                             table_data_type: BNNSDataType.float,                                             data_scale: 1, data_bias: 0)          let bData = UnsafeMutableBufferPointer<Float>.allocate(capacity: 1)     _ = bData.initialize(from: [20])     let bDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),                                             layout: BNNSDataLayoutVector,                                             size: (1, 0, 0, 0, 0, 0, 0, 0),                                             stride: (0, 0, 0, 0, 0, 0, 0, 0),                                             data: bData.baseAddress!,                                             data_type: BNNSDataType.float,                                             table_data: nil,                                             table_data_type: BNNSDataType.float,                                             data_scale: 1, data_bias: 0)          let cData = UnsafeMutableBufferPointer<Float>.allocate(capacity: 1)     _ = cData.initialize(from: [100])     let cDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),                                             layout: BNNSDataLayoutVector,                                             size: (1, 0, 0, 0, 0, 0, 0, 0),                                             stride: (0, 0, 0, 0, 0, 0, 0, 0),                                             data: cData.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: 1)     let outputDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),                                                  layout: BNNSDataLayoutVector,                                                  size: (1, 0, 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)          let fields = BNNSArithmeticTernary(in1: aDescriptor, in1_type: BNNSSample,                                        in2: bDescriptor, in2_type: BNNSSample,                                        in3: cDescriptor, in3_type: BNNSSample,                                        out: outputDescriptor, out_type: BNNSSample)          let arithmeticLayer: BNNSFilter? = withUnsafePointer(to: fields) { fieldsPtr in                  var layerParameters = BNNSLayerParametersArithmetic(             arithmetic_function: BNNSArithmeticMultiplyAdd,             arithmetic_function_fields: UnsafeMutableRawPointer(mutating: fieldsPtr),             activation: .identity)                  return BNNSFilterCreateLayerArithmetic(&layerParameters, nil)     }          var rawInputPointer = [ UnsafeRawPointer(aDescriptor.data!),                             UnsafeRawPointer(bDescriptor.data!),                             UnsafeRawPointer(cDescriptor.data!)]          BNNSArithmeticFilterApplyBatch(arithmeticLayer,                                    1,                                    3,                                    &rawInputPointer,                                    [1, 1, 1],                                    outputDescriptor.data!,                                    1)          // Prints `10 * 20 + 100 (300)`     print(Array(outputData))          aData.deallocate()     bData.deallocate()     cData.deallocate()     outputData.deallocate() }

## Topics

### Creating an Arithmetic Structure

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

### Inspecting the Properties of an Arithmetic Structure

- [in1](accelerate/bnnsarithmeticternary/in1.md)
- [in1_type](accelerate/bnnsarithmeticternary/in1_type.md)
- [in2](accelerate/bnnsarithmeticternary/in2.md)
- [in2_type](accelerate/bnnsarithmeticternary/in2_type.md)
- [in3](accelerate/bnnsarithmeticternary/in3.md)
- [in3_type](accelerate/bnnsarithmeticternary/in3_type.md)
- [out](accelerate/bnnsarithmeticternary/out.md)
- [out_type](accelerate/bnnsarithmeticternary/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)
- [BNNSArithmeticBinary](accelerate/bnnsarithmeticbinary.md)
- [BNNSArithmeticFunction](accelerate/bnnsarithmeticfunction.md)
- [BNNSLayerParametersArithmetic](accelerate/bnnslayerparametersarithmetic.md)
- [BNNSFilterCreateLayerArithmetic(_:_:)](accelerate/bnnsfiltercreatelayerarithmetic(_:_:).md)
- [BNNSArithmeticFilterApplyBatch(_:_:_:_:_:_:_:)](accelerate/bnnsarithmeticfilterapplybatch(_:_:_:_:_:_:_:).md)
- [BNNSArithmeticFilterApplyBackwardBatch(_:_:_:_:_:_:_:_:_:_:_:)](accelerate/bnnsarithmeticfilterapplybackwardbatch(_:_:_:_:_:_:_:_:_:_:_:).md)
