Hi Suraj!



 Suraj:

I am getting an error while using torch.ger().
Error message:
 RuntimeError: _th_addr_out not supported on CPUType for Bool
Could it be because of pytorch version? I have the latest one installed.


I’m guessing, but yes, it is probably the pytorch version.  Unfortunately
I don’t have an up-to-date version installed to test with.
For me (version 0.3.0) rows, as returned by
rows = (A.sum (dim = 2) != 0).squeeze()
is a ByteTensor, while your error message mentions Bool.
From recollection, that is a post-0.3.0 change.
Anyway (guessing) try converting rows to a LongTensor before
calling ger(), e.g.:
C = A[torch.ger (rows.long(), rows.long())].view ((1, rows.sum(), rows.sum()))



I actually had a naive (or a long) approach to it:
for i in range(4):
    ...

Your approach is much more time efficient, right?


As a general (and usually reliable) rule, doing things solely with
pytorch tensor operations will be much more efficient than writing
a python loop that loops over elements (or rows / columns / slices)
of pytorch tensors.
If this happens inside of your training loop, for example, in your loss
function where you want to backpropagate through the results of
the loop computation, it can matter a lot.  If you’re doing it on a
one-shot basis, for example, to prepare some data prior to training,
you might not care.
Best.
K. Frank