Return whether *x* is a PyTorch Tensor.
(x)
| 2428 | |
| 2429 | |
| 2430 | def _is_torch_array(x): |
| 2431 | """Return whether *x* is a PyTorch Tensor.""" |
| 2432 | try: |
| 2433 | # We're intentionally not attempting to import torch. If somebody |
| 2434 | # has created a torch array, torch should already be in sys.modules. |
| 2435 | tp = sys.modules.get("torch").Tensor |
| 2436 | except AttributeError: |
| 2437 | return False # Module not imported or a nonstandard module with no Tensor attr. |
| 2438 | return (isinstance(tp, type) # Just in case it's a very nonstandard module. |
| 2439 | and isinstance(x, tp)) |
| 2440 | |
| 2441 | |
| 2442 | def _is_jax_array(x): |
no test coverage detected
searching dependent graphs…