forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asarray
: Add support for NumPy scalars (pytorch#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: pytorch#90914 Approved by: https://github.com/lezcano, https://github.com/mruberry
- Loading branch information
1 parent
cc4fbd1
commit 3f64c96
Showing
3 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters