One Logo Pool Ball
Accelerate · IOS API REFERENCE

BNNSGraph.Builder

struct · iOS 26.0+ · SDK 27.1

struct Builder

A structure thats provides a closure you can use to define the arguments and operations of a BNNS Graph.

Members (5)

method · iOS 26.0+

concatenate

TypeScript
concatenate(tensors: Array<BNNSGraph_Builder_Tensor<number>>, axis: number): BNNSGraph_Builder_Tensor<number>
Swift declaration
func concatenate<T>(_ tensors: [BNNSGraph.Builder.Tensor<T>], axis: Int) -> BNNSGraph.Builder.Tensor<T> where T : BNNSScalar

Adds a concatenation operation to the current graph. - Parameter tensors: An array that contains the tensors that the operation concatenates. - Parameter axis: The axis along which the operation performs concatenation.

method · iOS 26.0+

argument

TypeScript
argument(name: (string) | null, dataType: "Bool" | "Float", shape: Array<number>, intent?: BNNSGraph_Builder_Intent): BNNSGraph_Builder_Tensor<unknown>
Swift declaration
func argument<T>(name: String? = nil, dataType: T.Type, shape: [Int], intent: BNNSGraph.Builder.Intent = .input) -> BNNSGraph.Builder.Tensor<T> where T : BNNSScalar

Registers and returns an input or in-out tensor argument to the graph. - Parameter name: The name of the argument. - Parameter dataType: The argument's data type. - Parameter shape: An array of integers or closed ranges that define the sizes of each dimension of the argument. Pass a negative value to specify a flexible dimension. - Parameter intent: A constant that specifies whether the argument is input, output, or in-out. The following code shows how to specify inputs with flexible shapes. The code calls `setBatchSize` before executing the context to specify that the two inputs and the output tensors are 8-element vectors: ``` let context = try? BNNSGraph.makeContext ({ builder in let x = builder.argument(name: "x", dataType: Float.self, shape: [-1]) let y = builder.argument(name: "y", dataType: Float.self, shape: [-1]) let z = x + y return [z] }) var args = context.argumentNames().map { name in return context.tensor(argument: name, fillKnownDynamicShapes: false)! } defer { args.forEach { $0.deallocate() } } let n = 8 context.setBatchSize(n) args[context.argumentPosition(argument: "x")] .allocate(initializingFrom: [1, 2, 3, 4, 5, 6, 7, 8] as [Float]) args[context.argumentPosition(argument: "y")] .allocate(initializingFrom: [10, 20, 30, 40, 50, 60, 70, 80] as [Float]) // Output argument args[0].allocate(as: Float.self, count: n) try context.executeFunction(arguments: &args) ``` On return, the output tensor contains the values `[11, 22, 33, 44, 55, 66, 77, 88]`.

method · iOS 26.0+

constant

TypeScript
constantNameValue(name: (string) | null, value: number): BNNSGraph_Builder_Tensor<number>
Swift declaration
func constant<T>(name: String? = nil, value: T) -> BNNSGraph.Builder.Tensor<T> where T : BNNSScalar

Registers and returns a tensor that contains a constant scalar value. - Parameter name: The name of the tensor. - Parameter value: The scalar value that the function copies into the compiled context. For example, the following code defines the tensor `x` that contains the single-precision scalar value `10.0`: ``` let context = try BNNSGraph.makeContext ({ builder in let x = builder.constant(name: "x", value : Float(10)) let y = builder.constant(name: "y", values : [1, 2, 3, 4, 5, 6, 7, 8] as [Float]) let z = x + y return [z] }) var results = [context.allocateTensor(argument: context.argumentNames()[0], fillKnownDynamicShapes: false)!] defer { results[0].deallocate() } try context.executeFunction(arguments: &results) ``` On return, the `results[0]` tensor contains the values `[11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0]`.

method · iOS 26.0+

constant

TypeScript
constantValuesRowMajor(values: Array<Array<number>>, rowMajor?: boolean): BNNSGraph_Builder_Tensor<number>
Swift declaration
func constant(values: Array<Array<Float>>, rowMajor: Bool = false) -> BNNSGraph.Builder.Tensor<Float>

Returns a rank 2 tensor from an array of arrays. - Precondition: Each sub-array must contain the same number of elements. The following code shows how to use this function to multiply two 2x2 matrices: ``` let xValues = [[1, 2], [3, 4]] as [[Float]] let yValues = [[5, 6], [7, 8]] as [[Float]] let context = try BNNSGraph.makeContext { builder in let x = builder.constant(values: xValues) let y = builder.constant(values: yValues) let z = x.matmul(other: y) return [z] // On return, `z` equals `[19.0, 22.0, 43.0, 50.0]`. } ```

method · iOS 26.0+

constant

TypeScript
constantValuesRowMajor52001(values: Array<Array<number>>, rowMajor?: boolean): BNNSGraph_Builder_Tensor<number>
Swift declaration
func constant(values: Array<Array<Float16>>, rowMajor: Bool = false) -> BNNSGraph.Builder.Tensor<Float16>

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

BNNSGraph.Builder.constant(name:values:shape:)

This protocol needs associated types that cannot yet cross the bridge.

All Accelerate types →