Skip to content

Commit

Permalink
Call PyArray_Check only if NumPy is available (#66433) (#66629)
Browse files Browse the repository at this point in the history
Summary:
Fixes #66353

Fixes #{issue number}

Pull Request resolved: #66433

Reviewed By: seemethere, janeyx99

Differential Revision: D31548290

Pulled By: malfet

fbshipit-source-id: 3b094bc8195d0392338e0bdc6df2f39587b85bb3
  • Loading branch information
malfet committed Oct 14, 2021
1 parent c3ea586 commit 4a514dd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .jenkins/pytorch/test.sh
Expand Up @@ -230,6 +230,8 @@ test_aten() {
test_without_numpy() {
pushd "$(dirname "${BASH_SOURCE[0]}")"
python -c "import sys;sys.path.insert(0, 'fake_numpy');from unittest import TestCase;import torch;x=torch.randn(3,3);TestCase().assertRaises(RuntimeError, lambda: x.numpy())"
# Regression test for https://github.com/pytorch/pytorch/issues/66353
python -c "import sys;sys.path.insert(0, 'fake_numpy');import torch;print(torch.tensor([torch.tensor(0.), torch.tensor(1.)]))"
popd
}

Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/utils/tensor_new.cpp
Expand Up @@ -194,7 +194,7 @@ void recursive_store(char* data, IntArrayRef sizes, IntArrayRef strides, int64_t
PyObject** items = PySequence_Fast_ITEMS(seq.get());
for(const auto i : c10::irange(n)) {
#ifdef USE_NUMPY
if (PyArray_Check(items[i])) {
if (is_numpy_available() && PyArray_Check(items[i])) {
TORCH_WARN_ONCE(
"Creating a tensor from a list of numpy.ndarrays is extremely slow. "
"Please consider converting the list to a single numpy.ndarray with "
Expand Down

0 comments on commit 4a514dd

Please sign in to comment.