Convolution layers
Conv1D/2D/3D, groups, dilation, and depthwise.
01Constructors and layout#
Conv1D/2D/3D(in_channels,out_channels,kernel,stride=1,padding=0,dilation=1,groups=1,bias=true). Inputs use [N,C,L], [N,C,H,W], or [N,C,D,H,W]. W=[K,C/groups,kernel...]. Input and output channels must divide by groups. Channels-last is unsupported.
02Output size#
Each spatial axis is computed independently. Padding adds zeros; dilation spaces kernel samples. Conv2D also exposes a longer constructor with per-axis kernel/stride/padding/dilation.
Conv2D conv(3,32,3,1,1);auto x=Tensor::zeros({8,3,28,28});auto y=conv.forward(x); // [8,32,28,28]03Cross-correlation and im2col#
The kernel is not flipped: this is cross-correlation. im2col unfolds windows into workspace and GEMM multiplies by filters. Backward accumulates dW and db; col2im sums overlapping input contributions. Workspace grows with kernel volume and output positions.
04DepthwiseConv2D#
DepthwiseConv2D(channels,kernel,stride=1,padding=0) uses groups=channels and out_channels=channels. There is no channel multiplier option. Follow with 1×1 Conv2D to mix channels. On the evening of 2026-10-21, on this Ryzen 7 5800H, CPU Conv2d on the competitor protocol was behind PyTorch at 31.6 GFLOPS. Nexus that evening was about 4.9 to 6.8 GFLOPS. Depthwise AVX was ahead of PyTorch 4.93 and TensorFlow 0.688 on that column. There is no world ranking.