I’m trying to implement a causal 2D convolution, wherein the “width” of my “image” is temporal in domain. What I’ve implemented so far is as follows (it’s rather simple and only works with kernel sizes that are odd):
class CausalConv2d(nn.Module):
    def __init__(
        in_channels: int,
        out_channels: int,
        kernel_size: tuple = (3, 3)
    ):
        super(CausalConv2d, self).__init__()
        self.pad = nn.ZeroPad2d((kernel_size[1] - 1, 0, kernel_size[0] // 2,
            kernel_size[0] // 2))
        self.conv = nn.Conv2d(in_channels, out_channels, kernel_size)

    def forward(self, x: Tensor):
        x = self.pad(x)
        x = self.conv(x)
        return x

Is this implementation correct? Any help would be great.