A ternary arithmetic layer.
Use a `TernaryArithmeticLayer` to perform arithmetic functions that accept three operands.
For example, the following code performs the multiply add operation, `10 * 20 + 100`:
let a = BNNSNDArrayDescriptor.allocate(initializingFrom: [10] as [Float],
shape: [1])
let b = BNNSNDArrayDescriptor.allocate(initializingFrom: [20] as [Float],
shape: [1])
let c = BNNSNDArrayDescriptor.allocate(initializingFrom: [100] as [Float],
shape: [1])
let out = BNNSNDArrayDescriptor.allocateUninitialized(scalarType: Float.self,
shape: [1])
let layer = BNNS.TernaryArithmeticLayer(inputA: a,
inputADescriptorType: .sample,
inputB: b,
inputBDescriptorType: .sample,
inputC: c,
inputCDescriptorType: .sample,
output: out,
outputDescriptorType: .sample,
function: .multiplyAdd)
try? layer?.apply(batchSize: 1,
inputA: a,
inputB: b,
inputC: c,
output: out)
On return, the output tensor contains the the value `300`.
Applies the layer backward to generate gradients.
- Parameter batchSize: The number of input-output pairs to process.
- Parameter inputA: The first input descriptor.
- Parameter inputB: The second input descriptor.
- Parameter inputC: The third input descriptor.///
- Parameter output: The output descriptor.
- Parameter outputGradient: The output gradient descriptor.
- Parameter inputAGradient: The first input gradient descriptor.
- Parameter inputBGradient: The second input gradient descriptor.
- Parameter inputCGradient: The third input gradient descriptor.
Applies the layer, writing the result to the output descriptor.
- Parameter batchSize: The number of input-output pairs to process.
- Parameter inputA: The first input descriptor.
- Parameter inputB: The second input descriptor.
- Parameter inputC: The third input descriptor.
- Parameter output: The output descriptor.
Creates a new ternary arithmetic layer.
- Parameter inputA: The first input descriptor.
- Parameter inputADescriptorType: The descriptor type of the first input.
- Parameter inputB: The second input descriptor.
- Parameter inputBDescriptorType: The descriptor type of the second input.
- Parameter inputC: The thrid input descriptor.
- Parameter inputCDescriptorType: The descriptor type of the thjird input.
- Parameter output: The output descriptor.
- Parameter outputDescriptorType: The descriptor type of the output.
- Parameter function: The arithmetic operation.
- Parameter activation: The activation function to apply to the result.
- Parameter filterParameters: Runtime filter parameters.
- Returns: A new ternary arithmetic layer on success or `nil` if the parameters are invalid.