Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call PyArray_Check only if NumPy is available (#66433) #66629

Merged
merged 1 commit into from Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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