---
title: "constant(_:shape:dataType:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/constant(_:shape:datatype:)-ylr4"
---

# constant(_:shape:dataType:)

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

## Declaration

```swift
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

Return Value A valid MPSGraphTensor object.
