Equality for Matricies/Tensors of Different dimensions
Suppose you have two matrices A of shape [n,k] and B of shape [m,k]. Your desired output is C of shape [n,m], where each entry [i,j] corresponds to the equality of row A[i] and row B[j]. Implementing this straing forward would look something like this:
for i in range(A.shape[0]):
    for j in range(B.shape[0]):
        C[i, j] = th.eq(A[i, :], B[j, :]).all().float()

Example:
A = [[0., 0., 0., 0., 0., 0.],
     [1., 1., 1., 1., 1., 1.],
     [0., 0., 0., 0., 0., 0.]]

and
B = [[0., 0., 0., 0., 0., 0.],
     [1., 1., 1., 1., 1., 1.],
     [0., 0., 1., 0., 0., 0.],
     [0., 0., 0., 0., 0., 0.]]

the desired output would be:
C = [[1., 0., 0., 1.],
     [0., 1., 0., 0.],
     [1., 0., 0., 1.]]

The straight forward implementation is quite slow, do you have any ideas how to improve this on cuda hardware with pytorch? Probably without for-loops.

You can use broadcasting:
c = (A[:, None, :] == B[None, ...]).all(dim=2).float()

