A unary arithmetic layer.
Use a `UnaryArithmeticLayer` to perform arithmetic functions that accept one operand.
For example, the following code calculates the element-wise square roots of the values in tensor `a`:
let a = BNNSNDArrayDescriptor.allocate(initializingFrom: [4, 9, 16, 25] as [Float],
shape: [4])
let out = BNNSNDArrayDescriptor.allocateUninitialized(scalarType: Float.self,
shape: [4])
let layer = BNNS.UnaryArithmeticLayer(input: a,
inputDescriptorType: .sample,
output: out,
outputDescriptorType: .sample,
function: .squareRoot)
try? layer?.apply(batchSize: 1,
input: a,
output: out)
On return, the output tensor contains the the values `[2, 3, 4, 5]`.
Applies the layer backward to generate gradients.
- Parameter batchSize: The number of input-output pairs to process.
- Parameter input: The input descriptor.
- Parameter output: The output descriptor.
- Parameter outputGradient: The output gradient descriptor.
- Parameter inputGradient: The input gradient descriptor.
Applies the layer, writing the result to the output descriptor.
- Parameter batchSize: The number of input-output pairs to process.
- Parameter input: The input descriptor.
- Parameter output: The output descriptor.
Creates a new unary arithmetic layer.
- Parameter input: The input descriptor.
- Parameter inputDescriptorType: The descriptor type of the 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 unary arithmetic layer.