---
title: "cast(_:to:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/cast(_:to:name:)"
---

# cast(_:to:name:)

Creates a cast operation and returns the result tensor.

## Declaration

```swift
func cast(_ tensor: MPSGraphTensor, to type: MPSDataType, name: String?) -> MPSGraphTensor
```

## Parameters

- `tensor`: The input tensor.
- `type`: The datatype to which MPSGraph casts the input.
- `name`: The name for the operation.

## Return Value

Return Value A valid MPSGraphTensor object.

## Discussion

Discussion Returns the input tensor casted to the specied data type.
