New Convolutional Layer

Hi

Considering a linear convolutional layer we compute a result given by y = w^{T}x +b .

Considering a quadratic convolutional layer we can compute the value using CodeCogsEqn (1) . More specifically, given an input image X and a convolutional layer with kernel of size k x k, we decompose X as a sequense of k x k patches. Then, we vectorize each patch as a vector of length K^2. For each patch x in input image we would like to compute the aforementioned quadratic equation value where w and b are the same as those appearing in a linear convolution and Q is a k^2 x k^2 matrix which contributes a quadratic non-linearity.

How can I extend pytorch in order to create the quadratic convolutional layer? Any ideas?