Skip to content

Dimension reducing variants of bitwise operations (bitwise_or, bitwise_and, bitwise_xor) #35641

@Ajk4

Description

@Ajk4

🚀 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    function requestA request for a new function or the addition of new arguments/modes to an existing function.module: reductionstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions