Contents

BNNSLayerParametersActivation

A set of parameters that define an activation layer.

Declaration

struct BNNSLayerParametersActivation

Overview

Use an activation layer to perform type conversion. The following code shows how to convert 16-bit integer values to single-precision values:

let input: [Int16] = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var output = [Float](repeating: 0, count: input.count)

input.withUnsafeBufferPointer { inputPtr in
    output.withUnsafeMutableBufferPointer { outputPtr in
        
        let inputDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                    layout: BNNSDataLayoutVector,
                                                    size: (input.count, 0, 0, 0, 0, 0, 0, 0),
                                                    stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                    data: UnsafeMutableRawPointer(mutating: inputPtr.baseAddress),
                                                    data_type: .int16,
                                                    table_data: nil,
                                                    table_data_type: .int16,
                                                    data_scale: 1,
                                                    data_bias: 0)
        
        let ouputDescriptor = BNNSNDArrayDescriptor(flags: BNNSNDArrayFlags(0),
                                                    layout: BNNSDataLayoutVector,
                                                    size: (input.count, 0, 0, 0, 0, 0, 0, 0),
                                                    stride: (0, 0, 0, 0, 0, 0, 0, 0),
                                                    data: outputPtr.baseAddress,
                                                    data_type: .float,
                                                    table_data: nil,
                                                    table_data_type: .float,
                                                    data_scale: 1,
                                                    data_bias: 0)
        
        var layerParameters = BNNSLayerParametersActivation(i_desc: inputDescriptor,
                                                                 o_desc: ouputDescriptor,
                                                                 activation: .identity,
                                                                 axis_flags: 0)
        
        BNNSDirectApplyActivationBatch(&layerParameters,
                                       nil,
                                       1,
                                       input.count,
                                       input.count)
    }
}

// Prints "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]"
print(output)

Topics

Initializers

Instance Properties

See Also

Activation layers