<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraph/Builder/constant(values:rowMajor:)-6b7b8",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7BuilderV8constant6values8rowMajorAE6TensorVy__SfGSaySaySfGG_SbtF"
  },
  "title" : "constant(values:rowMajor:)"
}
-->

# constant(values:rowMajor:)

Returns a rank 2 tensor from an array of arrays.

```
func constant(values: Array<Array<Float>>, rowMajor: Bool = false) -> BNNSGraph.Builder.Tensor<Float>
```

## Discussion> 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]`.
   }
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)