A binary arithmetic layer.
Use a `BinaryArithmeticLayer` to perform arithmetic functions that accept two operands.
For example, the following code calculates the element-wise products of the values in tensor `a` multiplied by the
corresponding values in tensor `b`:
let a = BNNSNDArrayDescriptor.allocate(initializingFrom: [1, 2, 3, 4] as [Float],
shape: [4])
let b = BNNSNDArrayDescriptor.allocate(initializingFrom: [1, 10, 100, 1000] as [Float],
shape: [4])
let out = BNNSNDArrayDescriptor.allocateUninitialized(scalarType: Float.self,
shape: [4])
let layer = BNNS.BinaryArithmeticLayer(inputA: a,
inputADescriptorType: .sample,
inputB: b,
inputBDescriptorType: .sample,
output: out,
outputDescriptorType: .sample,
function: .multiply)
try? layer?.apply(batchSize: 1,
inputA: a,
inputB: b,
output: out)
On return, the output tensor contains the the values `[1, 20, 300, 4000]`.
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 output: The output descriptor.
- Parameter outputGradient: The output gradient descriptor.
- Parameter inputAGradient: The first input gradient descriptor.
- Parameter inputBGradient: The second 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 output: The output descriptor.
Creates a new binary 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 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 binary arithmetic layer.