constant(values:rowMajor:)
Returns a rank 2 tensor from an array of arrays.
Declaration
func constant(values: Array<Array<Float>>, rowMajor: Bool = false) -> BNNSGraph.Builder.Tensor<Float>Discussion
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]`.
}