---
title: "stencil(withSourceTensor:weightsTensor:descriptor:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/stencil(withsourcetensor:weightstensor:descriptor:name:)"
---

# stencil(withSourceTensor:weightsTensor:descriptor:name:)

Creates a stencil operation and returns the result tensor.

## Declaration

```swift
func stencil(withSourceTensor source: MPSGraphTensor, weightsTensor weights: MPSGraphTensor, descriptor: MPSGraphStencilOpDescriptor, name: String?) -> MPSGraphTensor
```

## Parameters

- `source`: The tensor containing the source data. Must be of rank 4 or greater.
- `weights`: A 4-D tensor containing the weights data.
- `descriptor`: The descriptor object that specifies the parameters for the stencil operation.
- `name`: The name for the operation.

## Return Value

Return Value A valid MPSGraphTensor object.

## Discussion

Discussion Performs a weighted reduction operation (See reductionMode) on the last 4 dimensions of the source over the window determined by weights, according to the value defined in descriptor.    y[i] = reduction{j \in w} ( x[ i + j ]w[j] )
