fn

conv1d

Tensor
conv1d(x: Tensor, weight: Tensor, bias: Tensor | None = None, stride: int | tuple[int, ...] = 1, padding: int | tuple[int, ...] = 0, dilation: int | tuple[int, ...] = 1, groups: int = 1)
source

1-D cross-correlation over batched 3-D input.

Slides a learned filter along a single spatial axis. As with every major deep-learning framework, the operation is technically cross-correlation rather than strict mathematical convolution (no kernel flip), but the "conv" name is kept for familiarity. Channel mixing happens through the in_channels dimension of weight.

Parameters

xTensor
Input of shape (N, C_in, L).
weightTensor
Filters of shape (C_out, C_in/groups, kL).
biasTensor= None
Per-output-channel bias of shape (C_out,).
strideint or tuple of int= 1
Step between adjacent kernel positions (default 1).
paddingint or tuple of int= 0
Zero padding applied to both sides of the spatial axis.
dilationint or tuple of int= 1
Spacing between kernel taps (atrous convolution). Default 1.
groupsint= 1
Split the channel dimension into groups independent groups.

Returns

Tensor

Output of shape (N, C_out, L_out) where

Lout=L+2pd(k1)1s+1L_{\text{out}} = \left\lfloor \frac{L + 2p - d(k - 1) - 1}{s} + 1 \right\rfloor

Notes

Math:

yi,co,l=bco+ci,mwco,ci,mxi,ci,sl+dmy_{i,\,c_o,\,l} = b_{c_o} + \sum_{c_i, m} w_{c_o,\,c_i,\,m} \cdot x_{i,\,c_i,\,s l + d m}

Backward is registered automatically; gradients flow to x, weight, and bias. Set groups == C_in and C_out == C_in for a depthwise convolution. Using dilation > 1 enlarges the receptive field without increasing parameter count — common in speech / audio models (WaveNet) and 1-D temporal CNNs.

Examples

>>> import lucid
>>> from lucid.nn.functional import conv1d
>>> x = lucid.randn(2, 4, 50)
>>> w = lucid.randn(8, 4, 3)
>>> y = conv1d(x, w, padding=1)
>>> y.shape
(2, 8, 50)