---
title: "gradients(of:with:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/gradients(of:with:name:)"
---

# gradients(of:with:name:)

Calculates a partial derivative of primaryTensor with respect to the tensors.

## Declaration

```swift
func gradients(of primaryTensor: MPSGraphTensor, with tensors: [MPSGraphTensor], name: String?) -> [MPSGraphTensor : MPSGraphTensor]
```

## Parameters

- `primaryTensor`: Tensor to be differentiated (numerator).
- `tensors`: Tensors to do the differentiation with (denominator).
- `name`: Name for the gradient operation.

## Return Value

Return Value A valid MPSGraphTensor dictionary object containing partial derivative d(primaryTensor)/d(secondaryTensor) for each tensor as key.
