Imagine that you have a tensor $T_{ijkl}$ (0<=i,j,k,l< N)
that has the following property
T_{ijkl}
is nonzero if i+j=k+l
which acts as a "selection rule".
You want to contract the tensor T with another tensor u to make a third tensor v as follows
$$v_{ij} = sum_{kl=0}^N T_{ijkl} u_{kl}$$
is there a way to do this construction such that:
a. Uses the tensor contraction machinery of numpy and/or tensorflow? Things like einsum and the like.
b. Uses the explicit symmetry of the tensor, i.e the above operation should require $O(N^3)$ operations, not $O(N^4)$
.
One could use einsum directly getting $O(N^4)$ operations:
v = np.einsum('ijkl,ij->kl',T,u)
Or one could do a custom triple loop as
v = np.zeros_like(u)
for i in range(N):
for j in range(N):
for k in range(max(1+i+j-N,0),min(i+j,N-1)+1):
v[i,j]+=T[i,j,k,i+j-k]*u[k,i+j-k]
But neither of this satisfy both a. and b. above