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

Function _override_helper

tensorflow/python/framework/ops.py:159–180  ·  view source on GitHub ↗

Overrides (string) operator on Tensors to call func. Args: clazz_object: the class to override for; either Tensor or SparseTensor. operator: the string name of the operator to override. func: the function that replaces the overridden operator. Raises: ValueError: If operator ha

(clazz_object, operator, func)

Source from the content-addressed store, hash-verified

157
158
159def _override_helper(clazz_object, operator, func):
160 """Overrides (string) operator on Tensors to call func.
161
162 Args:
163 clazz_object: the class to override for; either Tensor or SparseTensor.
164 operator: the string name of the operator to override.
165 func: the function that replaces the overridden operator.
166
167 Raises:
168 ValueError: If operator has already been overwritten,
169 or if operator is not allowed to be overwritten.
170 """
171 existing = getattr(clazz_object, operator, None)
172 if existing is not None:
173 # Check to see if this is a default method-wrapper or slot wrapper which
174 # will be true for the comparison operators.
175 if not isinstance(existing, type(object.__lt__)):
176 raise ValueError("operator %s cannot be overwritten again on class %s." %
177 (operator, clazz_object))
178 if operator not in Tensor.OVERLOADABLE_OPERATORS:
179 raise ValueError("Overriding %s is disallowed" % operator)
180 setattr(clazz_object, operator, func)
181
182
183def _as_graph_element(obj):

Callers 2

_override_operatorMethod · 0.85
_override_operatorMethod · 0.85

Calls 1

typeFunction · 0.85

Tested by

no test coverage detected