<!--
{
  "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/MPSGraph/constant(_:shape:dataType:)-ylr4",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)constantWithData:shape:dataType:"
  },
  "title" : "constant(_:shape:dataType:)"
}
-->

# constant(_:shape:dataType:)

Creates a constant op with a given shape and data, and returns the result tensor.

```
func constant(_ data: Data, shape: [NSNumber], dataType: MPSDataType) -> MPSGraphTensor
```

## Parameters

`data`

The data for the tensor. The number of bytes should be sizeof(dataType)numberOfElements.

`shape`

The shape of the output tensor. This has to be statically shaped.

`dataType`

The dataType of theconstant tensor.

## Return Value

A valid MPSGraphTensor object.

---

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)