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)
| 157 | |
| 158 | |
| 159 | def _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 | |
| 183 | def _as_graph_element(obj): |
no test coverage detected