Skip to content

Support bool input tensors for argmax / argmin / sort / topk and other functions #35529

@vadimkantorov

Description

@vadimkantorov

argmax and other functions make sense for finding position of True element. Functions working with uint8 should likely be able to handle torch.bool as well.

In [16]: torch.__version__
Out[16]: '1.5.0.dev20200310'
In [11]: torch.ones(3, dtype = torch.bool).argmax()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/convasr/ot/vis.py in <module>
----> 1 torch.ones(3, dtype = torch.bool).argmax()

RuntimeError: "argmax_cpu" not implemented for 'Bool'

In [12]: torch.ones(3, dtype = torch.bool).argmin()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/convasr/ot/vis.py in <module>
----> 1 torch.ones(3, dtype = torch.bool).argmin()

RuntimeError: "argmin_cpu" not implemented for 'Bool'

In [13]: torch.ones(3, dtype = torch.bool).argsort()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/convasr/ot/vis.py in <module>
----> 1 torch.ones(3, dtype = torch.bool).argsort()

RuntimeError: _th_sort not supported on CPUType for Bool

In [14]: torch.ones(3, dtype = torch.bool).topk(1)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/convasr/ot/vis.py in <module>
----> 1 torch.ones(3, dtype = torch.bool).topk(1)

RuntimeError: "topk_cpu" not implemented for 'Bool'

In [15]: torch.ones(3, dtype = torch.bool).sort()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/convasr/ot/vis.py in <module>
----> 1 torch.ones(3, dtype = torch.bool).sort()

RuntimeError: _th_sort not supported on CPUType for Bool

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: 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