---
title: "clamp(_:min:max:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/clamp(_:min:max:name:)"
---

# clamp(_:min:max:name:)

Clamps the values in the first tensor between the corresponding values in the minimum and maximum value tensor.

## Declaration

```swift
func clamp(_ tensor: MPSGraphTensor, min minValueTensor: MPSGraphTensor, max maxValueTensor: MPSGraphTensor, name: String?) -> MPSGraphTensor
```

## Parameters

- `tensor`: The tensor to be clamped.
- `minValueTensor`: The tensor with min values to clamp to.
- `name`: An optional string which serves as an identifier for the operation.

## Return Value

Return Value A valid MPSGraphTensor object containing the elementwise result of the applied operation.

## Discussion

Discussion This operation creates a clamp operation and returns the result tensor. It supports broadcasting as well. resultTensor = clamp(tensor, minValueTensor, maxValueTensor)
