Arbitrary weight sharing in a sparse layer

I want to define a layer with arbitrary sparse connections to the previous layer, with each node having an arbitrary permutation on the same set of weights on these connections. Hense the weights and nodes indices must be implemented with a level of indirection. The purpose is to represent known symmetries through predefined weight sharing within the layer. The order of the shared weights will not be the same for different nodes.

Bi =∑ A[p[j]] * w[q[j]]

where p and q are arbitrary index arrays which are constant and known prior to training.

The layers are typically sparsely connected, so the size of p may be significantly smaller than the number of nodes in the prior layer. Thus the kernel should be processing p and q in parallel instead of A, and sparseness implement as actually fewer connections rather than zeroed weights.

Does this kind of configurable indirection exist in TensorFlow? Or any ANN tool for python with GPU acceleration?