Skip to content

torch.asarray does not detect dtype of Python scalars #70591

@pmeier

Description

@pmeier
import torch

for obj in (True, 1, 1.0):
    print(f"{obj} -> {torch.asarray(obj).dtype}")
True -> torch.float32
1 -> torch.float32
1.0 -> torch.float32

The documentation does not mention support for Python scalars, but since the function doesn't bail out, the behavior shown above is at least unexpected.

torch.asarray was added in #60627 and specifically mentions the array API standard for compatibility, but this defines behavior for scalars.

cc @gchanan @mruberry @rgommers @pmeier @asmeurer @leofang @AnirudhDagar @asi1024 @emcastillo @kmaehashi

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: python array apiIssues related to the Python Array APImodule: tensor creationtriagedThis 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