Return whether *x* is a TensorFlow Tensor or Variable.
(x)
| 2476 | |
| 2477 | |
| 2478 | def _is_tensorflow_array(x): |
| 2479 | """Return whether *x* is a TensorFlow Tensor or Variable.""" |
| 2480 | try: |
| 2481 | # We're intentionally not attempting to import TensorFlow. If somebody |
| 2482 | # has created a TensorFlow array, TensorFlow should already be in |
| 2483 | # sys.modules we use `is_tensor` to not depend on the class structure |
| 2484 | # of TensorFlow arrays, as `tf.Variables` are not instances of |
| 2485 | # `tf.Tensor` (they both convert the same way). |
| 2486 | is_tensor = sys.modules.get("tensorflow").is_tensor |
| 2487 | except AttributeError: |
| 2488 | return False |
| 2489 | try: |
| 2490 | return is_tensor(x) |
| 2491 | except Exception: |
| 2492 | return False # Just in case it's a very nonstandard module. |
| 2493 | |
| 2494 | |
| 2495 | def _unpack_to_numpy(x): |
no test coverage detected
searching dependent graphs…