pytorch
3f64c966 - `asarray`: Add support for NumPy scalars (#90914)

Commit
1 year ago
`asarray`: Add support for NumPy scalars (#90914) Follow up from: Quansight-Labs/numpy_pytorch_interop#3 This PR adds support for NumPy scalars for `torch.asarray`. **Before:** treats the scalar as an object that implements the buffer protocol. Thus, interprets the data as the default data type (`float32`) ```python >>> torch.asarray(numpy.float64(0.5)) tensor([0.0000, 1.7500]) ``` **After:** identifies the NumPy scalar, and does the "right" thing. i.e. creates a 0-dimensional tensor from the NumPy array that doesn't share its memory ```python >>> torch.asarray(numpy.float64(0.5)) tensor(0.5000, dtype=torch.float64) ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/90914 Approved by: https://github.com/lezcano, https://github.com/mruberry
Author
Committer
Parents
Loading