Skip to content

Torch 2 regression: torch.asarray(np.array(1)) fail (scalar array) #97021

@Conchylicultor

Description

@Conchylicultor

🐛 Describe the bug

It looks like torch 2 cannot convert float to int when the input is a scalar np.ndarray.

torch.asarray(1., dtype=torch.int32)  # Works
torch.asarray(np.array(1.), dtype=torch.int32)  # Fail
torch.asarray(np.array([1.]), dtype=torch.int32)  # Works

Traceback

>>> torch.asarray(np.asarray(1.), dtype=torch.int32)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

Versions

2.0.0

cc @ezyang @gchanan @zou3519 @mruberry @rgommers

Metadata

Metadata

Assignees

Labels

high prioritymodule: numpyRelated to numpy support, and also numpy compatibility of our operatorsmodule: regressionIt used to work, and now it doesn'ttriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions