Does PyTorch provide a way to do the bitwise-xor of all elements in a tensor and return the output value?
I need to do this for a tensor of tensors, hence need a way to parallelize this computation, instead of using loops. Any kind of help would be great.
Thanks in advance.
Do you mean
x = torch.rand(2, 3, 4, 5) > 0.5
y = torch.rand(3, 4, 5) > 0.5
z = x | y
Thanks for replying.
No, actually I have to do something like this:
# Sample tensor
X = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
lst = 
for i in X:
XorI = 0
for elem in i:
XorI = elem ^ XorI
But without loops.
P.S. It would be better if there’s way for more than 2 dimensions as well, where I can reduce in 1 specified direction.
Sorry, since pytorch only have
bitwise_xor, I have to find some “math expression” for this operator. See here, it is too complicated!
I think the best way is to make a pytorch extension.
See here , it is too complicated!
Yeah, this one seems a bit too complicated.
I think the best way is to make a pytorch extension .
I never knew about this feature of PyTorch. Can give it a try!
Thanks, @Eta_C ; though let’s keep the discussion open for any other possible solutions.