<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraphTensorData/init(_:rank:)-1lnxg",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Metal Performance Shaders Graph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraphTensorData(im)initWithMPSMatrix:rank:"
  },
  "title" : "init(_:rank:)"
}
-->

# init(_:rank:)

Initializes a tensor data with an MPS matrix enforcing rank of the result.

```
init(_ matrix: MPSMatrix, rank: Int)
```

## Parameters

`matrix`

MPSMatrix to be used within the MPSGraphTensorData

`rank`

The rank of the resulting TensorData tensor. NOTE: must be within { 1, … ,16 }.

## Return Value

A valid MPSGraphTensorData of given rank, or nil if allocation failure.

## Discussion

The device of the MPSMatrix will be used to get the MPSDevice for this MPSGraphTensorData.

---

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)