Hi all, first post in the forum! Hoping the community can point me in the right direction.
I’m trying to implement multi-linear tensor maps in torch (more below). I have some implementations that work well, but before I go further down the rabbit hole I thought I’d ask if this is already in the torch library. My cursory searches haven’t yielded anything, but I’m fairly new to this so may not be looking in the right places.
The basic idea is I want to implement a multi-linear tensor map between n-dimensional tensors that obviates the need to flatten and unflatten tensors. So, for example, instead of taking a 2d tensor x^{ij}, flattening it, hitting it with a linear map, then unflattening it, I want to simply implement the multi-linear tensor L^{ij}_{kl} that acts as a multilinear map as follows:
x^{ij} = L^{ij}_{kl} x^{kl}
This can easily be generalized to higher order by increasing the contracted indices. nn.Bilinear is a special case, but it is a highly restricted special case of the above.
For context, the reason the reason I’m interested in this is that these multilinear maps more readily preserve spatial distance information between neighboring pixels, which tend to get lost in the flattening/unflattening steps. For example, for a multi-linear map from a MxM to an NxN tensor, you can easily implement a normalized distance tensor d^{ij}_{kl} as follows:
d^{ij}_{kl} = \sqrt{(i/N-k/M)^2 + (j/N-l/M)^2},
which tells you the normalized euclidean distance between pixel kl in the input tensor and pixel ij in the output tensor. Using this you can do some cool things like introduce a distance based attenuation function, or a non-locality penalty in the error function.
As I said I have implementations of these, but might as well use canned tools if they exists. Does this look familiar? Is it already in the library or in add-ons?