MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / __bool__

Method __bool__

tensorflow/python/framework/ops.py:747–765  ·  view source on GitHub ↗

Dummy method to prevent a tensor from being used as a Python `bool`. This overload raises a `TypeError` when the user inadvertently treats a `Tensor` as a boolean (most commonly in an `if` or `while` statement), in code that was not converted by AutoGraph. For example: ```python

(self)

Source from the content-addressed store, hash-verified

745 _override_helper(Tensor, operator, func)
746
747 def __bool__(self):
748 """Dummy method to prevent a tensor from being used as a Python `bool`.
749
750 This overload raises a `TypeError` when the user inadvertently
751 treats a `Tensor` as a boolean (most commonly in an `if` or `while`
752 statement), in code that was not converted by AutoGraph. For example:
753
754 ```python
755 if tf.constant(True): # Will raise.
756 # ...
757
758 if tf.constant(5) < tf.constant(7): # Will raise.
759 # ...
760 ```
761
762 Raises:
763 `TypeError`.
764 """
765 self._disallow_bool_casting()
766
767 def __nonzero__(self):
768 """Dummy method to prevent a tensor from being used as a Python `bool`.

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected