KEMBAR78
[discussion] Have PyTorch functions support python scalars (like NumPy) + introduce convenience constants like `torch.pi` and `torch.e` and maybe analogue of `scipy.constants` namespace · Issue #110636 · pytorch/pytorch · GitHub
Skip to content

[discussion] Have PyTorch functions support python scalars (like NumPy) + introduce convenience constants like torch.pi and torch.e and maybe analogue of scipy.constants namespace #110636

@vadimkantorov

Description

@vadimkantorov

🚀 The feature, motivation and pitch

OP: #110351 (comment)

As an example, it would be nice to have torch.sqrt(python scalar) -> python scalar without having to dispatch between torch.sqrt and math.sqrt and to enable a bit more polymorphic code

Another idea is to also have torch.pi and other constants (like NumPy), in order to avoid importing numpy or math in order to get these constants.

Please close this if it's duplicate. I tried to search for similar previous discussions, but the keywords are a bit too generic :(

For torch.sqrt specifically, the polymorphic equivalent currently exists: x ** 0.5 which works both for tensor and python scalar inputs. But it is useful to have this behavior for many (at least simple) functions like torch.exp and so forth

Alternatives

No response

Additional context

No response

cc @mruberry @rgommers @albanD

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: numpyRelated to numpy support, and also numpy compatibility of our operatorsmodule: python frontendFor issues relating to PyTorch's Python frontendtriagedThis 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