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

# constant(_:shape:dataType:)

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

## Declaration

```swift
func constant(_ scalar: Double, shape: [NSNumber], dataType: MPSDataType) -> MPSGraphTensor
```

## Parameters

- `scalar`: The scalar value to fill the entire tensor values with.
- `shape`: The shape of the output tensor.
- `dataType`: The dataType of the constant tensor.

## Return Value

Return Value A valid MPSGraphTensor object.
