---
title: "singleGateRNN(_:recurrentWeight:inputWeight:bias:initState:mask:descriptor:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/singlegaternn(_:recurrentweight:inputweight:bias:initstate:mask:descriptor:name:)"
---

# singleGateRNN(_:recurrentWeight:inputWeight:bias:initState:mask:descriptor:name:)

Creates a single-gate RNN operation and returns the value and optionally the training state tensor.

## Declaration

```swift
func singleGateRNN(_ source: MPSGraphTensor, recurrentWeight: MPSGraphTensor, inputWeight: MPSGraphTensor?, bias: MPSGraphTensor?, initState: MPSGraphTensor?, mask: MPSGraphTensor?, descriptor: MPSGraphSingleGateRNNDescriptor, name: String?) -> [MPSGraphTensor]
```

## Parameters

- `source`: A tensor that contains the source data x[t] with the data layout [T,N,I]. In case inputWeight = nil and bidirectional = NO then the layout is [T,N,H] and for inputWeight = nil and bidirectional = YES the layout is [T,N,2H].
- `recurrentWeight`: A tensor containing the recurrent weights R. For bidirectional the layout is [2,H,H] and otherwise it is [H,H].
- `inputWeight`: A tensor containing the input weights matrix W - optional, if missing the operation assumes a diagonal unit-matrix. For bidirectional the layout is [2H,I] and otherwise it is [H,I].
- `bias`: A tensor containing the bias b - optional, if missing the operation assumes zeroes. For bidirectional the layout is [2H] and otherwise it is [H].
- `initState`: The initial internal state of the RNN h[-1] - optional, if missing the operation assumes zeroes. For bidirectional the layout is [N,2H] and otherwise it is [N,H].
- `mask`: A tensor containing the mask m - optional, if missing the operation assumes ones. This is useful for dropout support.
- `descriptor`: A descriptor that defines the parameters for the RNN operation.
- `name`: The name for the operation.

## Return Value

Return Value A valid MPSGraphTensor array of size 1 or 2, depending on value of descriptor.training. The layout of the both outputs is [T,N,H] or [T,N,2H] for bidirectional.

## Discussion

Discussion This operation returns tensors h and optionally z that are defined recursively as follows: for t = 0 to T-1    z[t] = x[t] W^T + (h[t-1]m) R^T + b   h[t] = activation( z[t] ), where W is optional inputWeight, R is recurrentWeight, b is bias, m is optional mask, x[t] is source h[t] is the first output, z[t] is the second output (optional) and h[-1] is initState. See MPSGraphSingleGateRNNDescriptor for different activation options.
