10000 ENH: Add a force argument to `numpy()` by HaoZeke · Pull Request #78564 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add a force argument to numpy() #78564

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

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unified error messages in tensor.numpy(), fixing test, making tests m…
…ore specific with assertRaisesRegex
  • Loading branch information
martinPasen authored and HaoZeke committed May 29, 2022
commit 5905324b962fbd09085b4c37ac6dcd349cb7eeeb
5 changes: 3 additions & 2 deletions test/test_numpy_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ def test_to_numpy_force_argument(self, device) -> None:
y = x.resolve_conj()
expect_error = requires_grad or sparse or conj or not device == 'cpu'
if not force and expect_error:
self.assertRaises((RuntimeError, TypeError), lambda: x.numpy())
self.assertRaisesRegex((RuntimeError, TypeError), "Use tensor\..*\.numpy\(\) instead\.", lambda: x.numpy())
self.assertRaisesRegex((RuntimeError, TypeError), "Use tensor\..*\.numpy\(\) instead\.", lambda: x.numpy(force=False))
elif force and sparse:
self.assertRaises(TypeError, lambda: x.numpy())
self.assertRaisesRegex(TypeError, "Use tensor\..*\.numpy\(\) instead\.", lambda: x.numpy(force=True))
else:
self.assertEqual(x.numpy(force=force), y)

Expand Down
0