-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Description
🚀 Feature
Function for reducing tensor along specified dim with bitwise operations.
Motivation
In my project I have a need to reduce my tensors along some dimensions with a bitwise operations.
Pitch
In pytorch I can reduce my tensor along dim in multiple ways (like t.min(dim=0), t.sum(dim=0), t.any(dim=0), t.all(dim=0).
Unfortunately it's not yet possible to reduce dimension with a bitwise operation like bitwise_or, bitwise_xor, bitwise_and.
Possible method headers could look like this:
def bitwise_or(dim=None, keepdim=False)
def bitwise_and(dim=None, keepdim=False)
def bitwise_xor(dim=None, keepdim=False)
Currently in BoolTensor there are two special methods any(dim) and all(dim) that implements logical or/and reduction. Bitwise_or/bitwise_and could be a generalization of those two to other tensor types. (Similarly as & operator that is a bitwise operation for non Bool tensors, and a logical one for BoolTensor)
Possibly loosely connected to #26824 - however it seems like it's only a pytorch distributed reduction method, not a tensor API one.
Alternatives
I implemented binary reducing operations in python using builtin pytorch functions with a loop along dimension dim. I imagine that implementing those directly in C++/CUDA could yield performance boost.