One Logo Pool Ball
Accelerate · IOS API REFERENCE

BNNS

enum · iOS 14.0+ · SDK 27.1

enum BNNS

An enum that acts as a namespace for Swift overlays to BNNS.

Members (27)

static · iOS 15.0+

clipByNorm

TypeScript
static clipByNorm(threshold: number, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes?: (Array<number>) | null): void
Swift declaration
static func clipByNorm(threshold: Float, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes: [Int]? = nil) throws

Clips the input tensor to the specified L2-norm and writes the result to the output tensor. Use this function to clip the values in an input tensor to a maximum L2-norm. The function supports clipping across the entire tensor or by the norms of a specified dimension. The following code clips a 3 x 3 matrix to a maximum L2-norm of `10` along axis `1`: let inputValues: [Float] = [1, 2, 3, 4, 5, 6, 7, 8, 9] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .matrixRowMajor(3, 3)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: input.shape) try? BNNS.clipByNorm(threshold: 10, input: input, output: output, axes: [1]) On return, the output matrix contains the following values: [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0257072, 5.743665, 6.461623 ] The L2-norms of `[1, 2, 3]` and `[4, 5, 6]` are both less than `10` and the function returns those rows unchanged. However, the L2-norm of `[7, 8, 9]` is approximately `13.92` and the function clips those values: sqrt(5.0257072² + 5.743665² + 6.461623²) = ~10 Specify more than one axis to clip by norms computed over more than one dimension. For example, given the following 3D tensor: let inputValues: [Float] = [1, 2, 3, 4, 5, 6, 10, 20, 30, 40, 50, 60, 100, 200, 300, 400, 500, 600] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .imageCHW(3, 2, 3)) Specify axes of `[0,1]` to clip the tensor into three `W x H` slices along the `C` axis: let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: input.shape) // ‖[1,2,3,4,5,6]‖₂ = 9.539392014169456 try BNNS.clipByNorm(threshold: 9.539392014169456, input: input, output: output, axes: [0,1]) On return, the output tensor contains the following values: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0] - Parameter theshold: The maximum L2-norm to clip the gradient to. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter axes: The indices of the axes over which the function computes the L2-norm. Set to `nil` to compute the norm over the entire tensor.

static · iOS 15.0+

dequantize

TypeScript
static dequantize(batchSize: number, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis?: (number) | null, scale?: (BNNSNDArrayDescriptor) | null, bias?: (BNNSNDArrayDescriptor) | null, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func dequantize(batchSize: Int, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int? = nil, scale: BNNSNDArrayDescriptor?, bias: BNNSNDArrayDescriptor?, filterParameters: BNNSFilterParameters? = nil) throws

Dequantizes the input tensor and writes the result to the output tensor. Use this functon to convert lower-precision tensors to higher precision. You can optionally supply scale and bias to compute the result using `output = (input-bias)/scale`. Dequantization supports the following conversions: [int8 | uint8 | int16 | uint16 | int32 | uint32] -> [fp32 | fp16 | int32] The scale and bias descriptors, if supplied, must have a vector layout and a size that matches the size of the specified axis. If you're applying scale and bias to the entire tensor, scale and bias descriptors must have a size of 1. For example, the following code dequantizes a 16-bit integer matrix to a single-precision matrix. The code applies the scale along the zeroth axis and, therefore, the scale tensor contains four elements. let inputValues = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000] as [Int16] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .matrixRowMajor(4, 2)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: input.shape) let scale = BNNSNDArrayDescriptor.allocate( initializingFrom: [1, 10, 100, 1000] as [Int16], shape: .vector(4)) try? BNNS.dequantize(batchSize: 1, input: input, output: output, axis: 0, scale: scale, bias: nil) On return, `output` contains the following values: [1000.0, 200.0, 30.0, 4.0, 5000.0, 600.0, 70.0, 8.0] - Parameter batchSize: The number of input-output pairs to process. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter axis: The index of the axis on which the function applies scale and bias. Set to `nil` to dequantize the entire tensor using scale and bias. - Parameter scale: Optional scale, set to `nil` for a scale of `1.0`. - Parameter bias: Optional bias, set to `nil` for a bias of `0.0`. - Parameter filterParameters: Runtime filter parameters.

static · iOS 14.0+

applyInTopK

TypeScript
static applyInTopK(k: number, input: BNNSNDArrayDescriptor, testIndices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: number, batchSize: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyInTopK(k: Int, input: BNNSNDArrayDescriptor, testIndices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int, batchSize: Int, filterParameters: BNNSFilterParameters? = nil) throws

Directly applies an in top-k filter to an input, writing out the result to a specified output. - Parameter k: The number of entries to find. - Parameter input: The input descriptor. - Parameter testIndices: The test indices descriptor. - Parameter output: The output descriptor. - Parameter axis: The axis along which to find top K entries. - Parameter batchSize: The number of input-output pairs to process. - Parameter filterParameters: Runtime filter parameters.

static · iOS 15.0+

computeNorm

TypeScript
static computeNorm(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes?: (Array<number>) | null): void
Swift declaration
static func computeNorm(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes: [Int]? = nil) throws

Computes the L2-norm and writes the result to the output tensor. Use this function to compute the norm of either an entire tensor or a specified axis or axes of a tensor. The following code computes the L2-norm of an entire tensor, in this case, the output tensor has vector layout with a size of `1`: let inputValues: [Float] = [1, 2, 3, 4, 5, 6, 7, 8, 9] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .matrixRowMajor(3, 3)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(1)) try BNNS.computeNorm(input: input, output: output, axes: nil) On return, the output descriptor contains the value `16.881943`: sqrt(1² + 2² + 3² + 4² + 5² + 6² + 7² + 8² + 9²) Pass an axis index to the function to specify the axis or axes to compute the norm. The following code computes the norm along the zeroth dimension: let inputValues: [Float] = [1, 2, 3, 4, 5, 6, 7, 8, 9] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .matrixRowMajor(3, 3)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(3)) try BNNS.computeNorm(input: input, output: output, axes: [0]) On return, the output descriptor contains the values `[8.124039, 9.643651, 11.224972]`: [ sqrt(1² + 4² + 7²), sqrt(2² + 5² + 8²), sqrt(3² + 6² + 9²) ] To compute the norm along more that one dimension, define the destination tensor as a vector with a size that is the number of dimensions you're calculating over. For example, the following code defines `axes` with a value of `[0, 1]` to compute the norm of dimensions zero and one: let inputValues: [Float] = [1, 2, 3, 4, 5, 6, 10, 20, 30, 40, 50, 60] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .tensor3DLastMajor(3, 2, 2)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(2)) try BNNS.computeNorm(input: input, output: output, axes: [0, 1]) On return, the output descriptor contains the values `[9.539392, 95.39392]`: [ sqrt(1² + 2² + 3² + 4² + 5² + 6²), sqrt(10² + 20² + 30² + 40² + 50² + 60²)] Define the shape of the output tensor as the noncomputed axes of the input tensor. For example, given a 3D input tensor with teh size (2, 3, 4), in the case where you're computing the norm over axis 2, the output tensor should have the size (3, 2). - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter axes: The indices of the axes over which the function computes the norm. Set to `nil` to compute the norm over the entire tensor.

static · iOS 16.0+

copyBandPart

TypeScript
static copyBandPart(source: BNNSNDArrayDescriptor, destination: BNNSNDArrayDescriptor, lowerBandCount?: (number) | null, upperBandCount?: (number) | null, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func copyBandPart(_ source: BNNSNDArrayDescriptor, to destination: BNNSNDArrayDescriptor, lowerBandCount: Int?, upperBandCount: Int?, filterParameters: BNNSFilterParameters? = nil) throws

Copies the specified subdiagonals and superdiagonals of a matrix and sets other elements to zero. - Parameter source: The input descriptor. - Parameter destination: The output descriptor. - Parameter lowerBandCount: The number of subdiagonals that the function copies. Set to `nil` to copy the entire lower triangle. - Parameter upperBandCount: The number of superdiagonals that the function copies. Set to `nil` to copy the entire upper triangle. - Parameter filterParameters: Runtime filter parameters. - Note: This function requires contiguous input and output. - Note: This source and destination sizes must match. - seealso: `BNNSBandPart`

static · iOS 16.0+

tileBackward

TypeScript
static tileBackward(outputGradient: BNNSNDArrayDescriptor, inputGradient: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func tileBackward(outputGradient: BNNSNDArrayDescriptor, generatingInputGradient inputGradient: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Applies tiling backward to generate gradients. - Parameter outputGradient: The output gradient descriptor. - Parameter inputGradient: The input gradient descriptor. - Parameter filterParameters: Runtime filter parameters. - seealso: `BNNSTileBackward`.

static · iOS 14.0+

applyReduction

TypeScript
static applyReduction(reductionFunction: BNNS_ReductionFunction, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, weights?: (BNNSNDArrayDescriptor) | null, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyReduction(_ reductionFunction: BNNS.ReductionFunction, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, weights: BNNSNDArrayDescriptor?, filterParameters: BNNSFilterParameters? = nil) throws

Applies reduction to a single input-output batch. To perform reduction on an n-dimensional array, create an output array of the same rank, and specify a size of `1` for the dimension the operation should reduce. For example, given the following code: ``` let input = BNNSNDArrayDescriptor.allocate( initializingFrom: [1, 2, 3, 4, 5, 6, 7, 8, 9] as [Float], shape: .matrixRowMajor(3, 3)) let outputRows = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .matrixRowMajor(1, 3)) let outputColumns = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .matrixRowMajor(3, 1)) ``` Applying a `.sum` reduction to `outputRows` returns ` [6, 15, 24]`, and applying a `.sum` reduction to `outputColumns` returns `[12, 15, 18]`. - Parameter reduceFunction: The reduction function. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter weights: The weights descriptor. - Parameter filterParameters: Runtime filter parameters.

static · iOS 15.0+

applyActivation

TypeScript
static applyActivationActivationAxesInputOutputBatchSizeFilterParameters(activation: BNNS_ActivationFunction, axes: Array<number>, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, batchSize: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyActivation(activation: BNNS.ActivationFunction, axes: [Int], input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, batchSize: Int, filterParameters: BNNSFilterParameters? = nil) throws

Directly applies an activation layer to several pairs of (input, output) data. - Parameter activation: The activation function. - Parameter axes: The indices of the axes on which to conduct certain activation functions applications (e.g. softmax). - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter batchSize: The number of input-output pairs to process. - Parameter filterParameters: Runtime filter parameters.

static · iOS 14.0+

applyActivation

TypeScript
static applyActivationActivationInputOutputBatchSizeFilterParameters(activation: BNNS_ActivationFunction, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, batchSize: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyActivation(activation: BNNS.ActivationFunction, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, batchSize: Int, filterParameters: BNNSFilterParameters? = nil) throws

Directly applies an activation layer to several pairs of (input, output) data. - Parameter activation: The activation function. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter batchSize: The number of input-output pairs to process. - Parameter filterParameters: Runtime filter parameters.

static · iOS 15.0+

clipByGlobalNorm

TypeScript
static clipByGlobalNorm(threshold: number, inputs: Array<BNNSNDArrayDescriptor>, outputs: Array<BNNSNDArrayDescriptor>, globalNorm?: number): void
Swift declaration
static func clipByGlobalNorm(threshold: Float, inputs: [BNNSNDArrayDescriptor], outputs: [BNNSNDArrayDescriptor], globalNorm: Float = 0) throws

Clips the input tensors to the specified L2-norm and writes the result to the output tensors. Use this function to clip the values in an array of input tensors to a maximum L2-norm. If you know the global norm of the input tensors, pass this value as the `globalNorm`, otherwise pass `0` to have the function calculate the norm. The following code clips the L2 norm of two input tensors to half of the global L2 norm. The L2 norm is the square root of the sum of squares of the two tensors. let inputOne = BNNSNDArrayDescriptor.allocate( initializingFrom: [1, 2, 3, 4] as [Float], shape: .vector(4)) let inputTwo = BNNSNDArrayDescriptor.allocate( initializingFrom: [5, 6, 7, 8] as [Float], shape: .vector(4)) let outputOne = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(4)) let outputTwo = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(4)) try? BNNS.clipByGlobalNorm(threshold: 0.5 * 14.2828568570857, inputs: [inputOne, inputTwo], outputs: [outputOne, outputTwo]) On return, `outputOne` contains the values `[0.5, 1.0, 1.5, 2.0]` and `outputTwo` contains the values `[2.5, 3.0, 3.5, 4.0]`. - Parameter theshold: The maximum L2-norm to clip the gradient to. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter globalNorm: The global norm to use. If zero, the operation computes the global norm.

static · iOS 15.0+

computeNormBackward

TypeScript
static computeNormBackward(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes: (Array<number>) | null, outputGradient: BNNSNDArrayDescriptor, inputGradient: BNNSNDArrayDescriptor): void
Swift declaration
static func computeNormBackward(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axes: [Int]? = nil, outputGradient: BNNSNDArrayDescriptor, generatingInputGradient inputGradient: BNNSNDArrayDescriptor) throws

Computes the L2-norm backward to generate gradients. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter axes: The indices of the axes over which the function computes the norm. Set to `nil` to compute the norm over the entire tensor. - Parameter outputGradient: The output gradient descriptor. - Parameter inputGradient: The input gradient descriptor.

static · iOS 16.0+

applyMatrixMultiplication

TypeScript
static applyMatrixMultiplication(inputA: BNNSNDArrayDescriptor, transposeA: boolean, inputB: BNNSNDArrayDescriptor, transposeB: boolean, output: BNNSNDArrayDescriptor, alpha: number, workspace?: (ArrayBuffer) | null, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyMatrixMultiplication(inputA: BNNSNDArrayDescriptor, transposed transposeA: Bool, inputB: BNNSNDArrayDescriptor, transposed transposeB: Bool, output: BNNSNDArrayDescriptor, alpha: Float, workspace: UnsafeMutableRawBufferPointer?, filterParameters: BNNSFilterParameters? = nil) throws

Directly apply a broadcast matrix multiplication layer. - Parameter inputA: The descriptor of matrix _A_. - Parameter transposeA: A Boolean value indicating whether to transpose the last two dimensions of _A_. - Parameter inputB: The descriptor of matrix _B_. - Parameter transposeB: A Boolean value indicating whether to transpose the last two dimensions of _B_. - Parameter output: The output descriptor. - Parameter alpha: A scalar value that scales the result. - Parameter workspace: A pointer to a memory region that the function uses as scratch space. This must have a size no less that the value returned by `matrixMultiplyWorkspaceSize`. - Parameter filterParameters: Runtime filter parameters. - seealso: `BNNSMatMul`.

static · iOS 16.0+

matrixMultiplicationWorkspaceSize

TypeScript
static matrixMultiplicationWorkspaceSize(inputA: BNNSNDArrayDescriptor, transposeA: boolean, inputB: BNNSNDArrayDescriptor, transposeB: boolean, output: BNNSNDArrayDescriptor, alpha: number, filterParameters?: (BNNSFilterParameters) | null): (number) | null
Swift declaration
static func matrixMultiplicationWorkspaceSize(inputA: BNNSNDArrayDescriptor, transposed transposeA: Bool, inputB: BNNSNDArrayDescriptor, transposed transposeB: Bool, output: BNNSNDArrayDescriptor, alpha: Float, filterParameters: BNNSFilterParameters? = nil) -> Int?

Returns required workspace size, in bytes, for a call to `applyMatrixMultiply`. - Parameter inputA: The descriptor of matrix _A_. - Parameter transposeA: A Boolean value indicating whether to transpose the last two dimensions of _A_. - Parameter inputB: The descriptor of matrix _B_. - Parameter transposeB: A Boolean value indicating whether to transpose the last two dimensions of _B_. - Parameter output: The output descriptor. - Parameter alpha: A scalar value that scales the result. - Parameter filterParameters: Runtime filter parameters. - seealso: `BNNSMatMulWorkspaceSize`. - returns: The required allocation size, in bytes, for the workspace parameter to `static BNNS.applyMatrixMultiplication()` or `nil` if the parameters are invalid.

static · iOS 15.0+

clip

TypeScript
static clip(bounds: SDKHandle, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor): void
Swift declaration
static func clip(to bounds: ClosedRange<Float>, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor) throws

Clips the input tensor to the specified bounds and writes the result to the output tensor. Use this function to clip the values in an input tensor to a specified closed range. Values below the range's lower bound are set to the lower band, and values above the range's upper band are set to the upper band. The following code clips the values of the input tensor to the range `3...6`: let input = BNNSNDArrayDescriptor.allocate( initializingFrom: [1, 2, 3, 4, 5, 6, 7, 8] as [Float], shape: .vector(8)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Float.self, shape: .vector(8)) try? BNNS.clip(to: 3...6, input: input, output: output) On return, the output tensor contains the folloring values: [3.0, 3.0, 3.0, 4.0, 5.0, 6.0, 6.0, 6.0] - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter bounds: The range to clip the gradient within.

static · iOS 14.0+

copy

TypeScript
static copy(source: BNNSNDArrayDescriptor, destination: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func copy(_ source: BNNSNDArrayDescriptor, to destination: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Copies the contents from one descriptor to another. - Parameter source: The input descriptor. - Parameter destination: The output descriptor. - Parameter filterParameters: Runtime filter parameters.

static · iOS 16.0+

tile

TypeScript
static tile(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func tile(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Populates the output tensor by replicating the input tensor multiple times. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter filterParameters: Runtime filter parameters. - Note: The size of output tensor along each dimension must be a multiple of the correspoinding input tensor dimension. - seealso: `BNNSTile`.

static · iOS 16.0+

gather

TypeScript
static gather(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func gather(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int, filterParameters: BNNSFilterParameters? = nil) throws

Gather elements along a single axis. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter axis: The axis along which the function gathers indices. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSGather`. Maps one n dimensional tensor to another n dimensional tensor, only with indices along the given axis gathered as according to the given indices tensor. `output[i_0, ... i_axis, ... i_{n-1}] = input[i_0, ... idx_axis, ... i_{n-1}]` where the value `idx_axis` is drawn from the indices tensor as follows: 1) If indices is a 1d vector, `idx_axis = indices[i_axis]` 2) If indices shape matches output shape, `idx_axis = indices[i_0, ... i_axis, ... i_{n-1}]` (Note that in the degeneate case where output is a 1d vector the two definitions are equivalent)

static · iOS 14.0+

compare

TypeScript
static compare(inputA: BNNSNDArrayDescriptor, inputB: BNNSNDArrayDescriptor, relationalOperator: BNNS_RelationalOperator, output: BNNSNDArrayDescriptor): void
Swift declaration
static func compare(_ inputA: BNNSNDArrayDescriptor, _ inputB: BNNSNDArrayDescriptor, using relationalOperator: BNNS.RelationalOperator, output: BNNSNDArrayDescriptor) throws

Performs an element-wise comparison of two tensors. - Parameter inputA: The first input descriptor. - Parameter inputB: The second input descriptor. - Parameter relationalOperator: The comparison operator. - Parameter output: The output descriptor.

static · iOS 18.0+

scatter

TypeScript
static scatterInputIndicesOutputAxisFilterParameters(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func scatter(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int, filterParameters: BNNSFilterParameters? = nil) throws

Scatters elements along a single axis with no reduction. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter axis: An enumeration that specifies whether the operation scatters along a single axis of a (k-1)-dimensional set of slices or elements from the input array. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSScatter`. The indices array is interpreted as a `(k-1)` dimensional set of 1d lookup vectors (thus the indices tensor has `(k-1) + 1 = k` dimensions total). If the 1d lookup vectors do not give a full set of indices, the remaining indices are treated as a slice. e.g. If the output array is 3 dimensional, then: * `indices[i] = {1}` would refer to the 2d slice `output[1, :, :]` * `indices[i] = {3,2}` would refer to the 1d slice `output[3, 2, :]` * `indices[i] = {2,1,3}` would refer to the `output[2, 1, 3]` As such, the shape of the input is given by the concatenation of the shape for the first k-1 dimensions of indices and the shape of the slice gathered (which is itself given by the shape of the last p dimensions of the output tensor, where `p=ndim(output)-indices.size[k-1])`. Output values that are scattered to reduced with the existing value as `output[output_idx] = op(output[output_idx], input[input_idx])` If multiple input values update the same output element, the order of update operations is undefined and there is no guarantee any particular value will result.

static · iOS 16.0+

scatter

TypeScript
static scatterInputIndicesOutputAxisReductionFunctionFilterParameters(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: number, reductionFunction: BNNS_ReductionFunction, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func scatter(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int, reductionFunction: BNNS.ReductionFunction, filterParameters: BNNSFilterParameters? = nil) throws

Scatters elements along a single axis. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter axis: An enumeration that specifies whether the operation scatters along a single axis of a (k-1)-dimensional set of slices or elements from the input array. - Parameter reductionFunction: The reduction operation that the function uses to reduce existing output value with scattered value. Must be`BNNSReduceFunctionSum`. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSScatter`. The indices array is interpreted as a `(k-1)` dimensional set of 1d lookup vectors (thus the indices tensor has `(k-1) + 1 = k` dimensions total). If the 1d lookup vectors do not give a full set of indices, the remaining indices are treated as a slice. e.g. If the output array is 3 dimensional, then: * `indices[i] = {1}` would refer to the 2d slice `output[1, :, :]` * `indices[i] = {3,2}` would refer to the 1d slice `output[3, 2, :]` * `indices[i] = {2,1,3}` would refer to the `output[2, 1, 3]` As such, the shape of the input is given by the concatenation of the shape for the first k-1 dimensions of indices and the shape of the slice gathered (which is itself given by the shape of the last p dimensions of the output tensor, where `p=ndim(output)-indices.size[k-1])`. Output values that are scattered to reduced with the existing value as `output[output_idx] = op(output[output_idx], input[input_idx])` If multiple input values update the same output element, the order of update operations is undefined.

static · iOS 16.0+

shuffle

TypeScript
static shuffle(shuffleType: BNNS_ShuffleType, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func shuffle(_ shuffleType: BNNS.ShuffleType, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Rearranges the elements in a tensor according to a shuffle type. - Parameter shuffleType: The shuffle operation that the function performs. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter filterParameters: Runtime filter parameters. - note: Both input and output tensors must have a rank of 4. - seealso: `BNNSShuffle`.

static · iOS 16.0+

gatherND

TypeScript
static gatherND(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func gatherND(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Gathers a (k-1)-dimensional set of slices or elements from the input array. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSGatherND`. The indices array is interpreted as a `(k-1)` dimensional set of 1d lookup vectors (thus the indices tensor has `(k-1) + 1 = k` dimensions total). If the 1d lookup vectors do not give a full set of indices, the remaining indices are treated as a slice. e.g. If the input array is 3 dimensional, then: * `indices[i] = {1}` would gather the 2d slice `input[1, :, :]` * `indices[i] = {3,2}` would gather the 1d slice `input[3, 2, :]` * `indices[i] = {2,1,3}` would gather the element `input[2, 1, 3]` As such, the shape of the output is given by the concatenation of the shape for the first `k-1` dimensions of indices and the shape of the slice gathered (which is itself given by the shape of the last p dimensions of the input tensor, where `p=ndim(input)-indices.size[k-1]`).

static · iOS 15.0+

quantize

TypeScript
static quantize(batchSize: number, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis?: (number) | null, scale?: (BNNSNDArrayDescriptor) | null, bias?: (BNNSNDArrayDescriptor) | null, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func quantize(batchSize: Int, input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, axis: Int? = nil, scale: BNNSNDArrayDescriptor?, bias: BNNSNDArrayDescriptor?, filterParameters: BNNSFilterParameters? = nil) throws

Quantizes the input tensor and writes the result to the output tensor. Use this function to convert higher-precision tensors to lower precision. You can optionally supply scale and bias to compute the result using `output = scale*input + bias`. Quantization supports the following conversions: [fp32 | fp16 | int32] -> [int8 | uint8 | int16 | uint16 | int32 | uint32] The scale and bias descriptors, if supplied, must have a vector layout and a size that matches the size of the specified axis. If you're applying scale and bias to the entire tensor, scale and bias descriptors must have a size of 1. For example, the following code quantizes a single-precision matrix to a 16-bit integer matrix. The code applies the scale along the zeroth axis and, therefore, the scale tensor contains four elements. let inputValues = [1, 2, 3, 4, 5, 6, 7, 8] as [Float] let input = BNNSNDArrayDescriptor.allocate( initializingFrom: inputValues, shape: .matrixRowMajor(4, 2)) let output = BNNSNDArrayDescriptor.allocateUninitialized( scalarType: Int16.self, shape: input.shape) let scale = BNNSNDArrayDescriptor.allocate( initializingFrom: [1, 10, 100, 1000] as [Float], shape: .vector(4)) try? BNNS.quantize(batchSize: 1, input: input, output: output, axis: 0, scale: scale, bias: nil) On return, `output` contains the following values: [1, 20, 300, 4000, 5, 60, 700, 8000] - Parameter batchSize: The number of input-output pairs to process. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter axis: The axis on which the function applies scale and bias. Set to `nil` to quantize the entire tensor using scale and bias. - Parameter scale: Optional scale, set to `nil` for a scale of `1.0`. - Parameter bias: Optional bias, set to `nil` for a bias of `0.0`. - Parameter filterParameters: Runtime filter parameters.

static · iOS 14.0+

applyTopK

TypeScript
static applyTopK(k: number, input: BNNSNDArrayDescriptor, bestValues: BNNSNDArrayDescriptor, bestIndices: BNNSNDArrayDescriptor, axis: number, batchSize: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func applyTopK(k: Int, input: BNNSNDArrayDescriptor, bestValues: BNNSNDArrayDescriptor, bestIndices: BNNSNDArrayDescriptor, axis: Int, batchSize: Int, filterParameters: BNNSFilterParameters? = nil) throws

Computes the top K entries from the input. - Parameter k: The number of entries to find. - Parameter input: The input descriptor. - Parameter bestValues: A descriptor of `k` length that the function writes the `k` best values to. - Parameter bestIndices: A descriptor of `k` length that the function writes the indices of the `k` best values to. - Parameter axis: The axis along which to find top K entries. - Parameter batchSize: The number of input-output pairs to process. - Parameter filterParameters: Runtime filter parameters.

static · iOS 18.0+

scatterND

TypeScript
static scatterNDInputIndicesOutputFilterParameters(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func scatterND(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, filterParameters: BNNSFilterParameters? = nil) throws

Scatters elements along a single axis or a (k-1)-dimensional set of slices or elements or elements specified by indices, with no reduction. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSScatterND`. The indices array is interpreted as a `(k-1)` dimensional set of 1d lookup vectors (thus the indices tensor has `(k-1) + 1 = k` dimensions total). If the 1d lookup vectors do not give a full set of indices, the remaining indices are treated as a slice. e.g. If the output array is 3 dimensional, then: * `indices[i] = {1}` would refer to the 2d slice `output[1, :, :]` * `indices[i] = {3,2}` would refer to the 1d slice `output[3, 2, :]` * `indices[i] = {2,1,3}` would refer to the `output[2, 1, 3]` As such, the shape of the input is given by the concatenation of the shape for the first k-1 dimensions of indices and the shape of the slice gathered (which is itself given by the shape of the last p dimensions of the output tensor, where `p=ndim(output)-indices.size[k-1])`. Output values that are scattered to reduced with the existing value as `output[output_idx] = op(output[output_idx], input[input_idx])` If multiple input values update the same output element, the order of update operations is undefined and there is no guarantee any particular value will result.

static · iOS 16.0+

scatterND

TypeScript
static scatterNDInputIndicesOutputReductionFunctionFilterParameters(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, reductionFunction: BNNS_ReductionFunction, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func scatterND(input: BNNSNDArrayDescriptor, indices: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, reductionFunction: BNNS.ReductionFunction, filterParameters: BNNSFilterParameters? = nil) throws

Scatters elements along a single axis or a (k-1)-dimensional set of slices or elements or elements specified by indices. - Parameter input: The input descriptor. - Parameter indices: The indices descriptor. - Parameter output: The output descriptor. - Parameter reductionFunction: The reduction operation that the function uses to reduce existing output value with scattered value. Must be `BNNSReduceFunctionSum`. - Parameter filterParameters: Runtime filter parameters. - Throws: If any indices value are out of range, the operation throws an error. - Seealso: `BNNSScatterND`. The indices array is interpreted as a `(k-1)` dimensional set of 1d lookup vectors (thus the indices tensor has `(k-1) + 1 = k` dimensions total). If the 1d lookup vectors do not give a full set of indices, the remaining indices are treated as a slice. e.g. If the output array is 3 dimensional, then: * `indices[i] = {1}` would refer to the 2d slice `output[1, :, :]` * `indices[i] = {3,2}` would refer to the 1d slice `output[3, 2, :]` * `indices[i] = {2,1,3}` would refer to the `output[2, 1, 3]` As such, the shape of the input is given by the concatenation of the shape for the first k-1 dimensions of indices and the shape of the slice gathered (which is itself given by the shape of the last p dimensions of the output tensor, where `p=ndim(output)-indices.size[k-1])`. Output values that are scattered to reduced with the existing value as `output[output_idx] = op(output[output_idx], input[input_idx])` If multiple input values update the same output element, the order of update operations is undefined.

static · iOS 14.0+

transpose

TypeScript
static transpose(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, firstTransposeAxis: number, secondTransposeAxis: number, filterParameters?: (BNNSFilterParameters) | null): void
Swift declaration
static func transpose(input: BNNSNDArrayDescriptor, output: BNNSNDArrayDescriptor, firstTransposeAxis: Int, secondTransposeAxis: Int, filterParameters: BNNSFilterParameters? = nil) throws

Transposes a tensor by swapping two of its dimensions. - Parameter input: The input descriptor. - Parameter output: The output descriptor. - Parameter firstTransposeAxis: The first axis of transposition. - Parameter secondTransposeAxis: The second axis of transposition. - Parameter filterParameters: Runtime filter parameters.

Skipped declarations

No declarations were skipped in this snapshot.

All Accelerate types →