MCPcopy Create free account
hub / github.com/ai-techsystems/deepC / overload_python_operator

Function overload_python_operator

deepC/tensor_interface_helper.py:492–528  ·  view source on GitHub ↗
(dc_operator, operator_python, dtype_precedence_dict, flag)

Source from the content-addressed store, hash-verified

490
491
492def overload_python_operator(dc_operator, operator_python, dtype_precedence_dict, flag):
493 s = ""
494 if flag == "logical" or flag == "binary":
495 s = '''
496def __<operand>__(self, other):
497 return <operator>(self, other)
498
499def __r<operand>__(self, other):
500 return <operator>(other, self)
501
502def __i<operand>__(self, other):
503 """
504 making sure left hand operand is immutable
505 """
506 dtype_precedence_dict = ''&#x27;
507 s += str(dtype_precedence_dict) + ''&#x27;
508 left_operand_dtype = right_operand_dtype = ""
509 if "Tensor" in str(type(self)):
510 left_operand_dtype = str(type(self)).split(".")[-1].split("Tensor")[0]
511 else:
512 left_operand_dtype = str(type(self)).split("'")[1]
513 if "Tensor" in str(type(other)):
514 right_operand_dtype = str(type(other)).split(".")[-1].split("Tensor")[0]
515 else:
516 right_operand_dtype = str(type(other)).split("'")[1]
517 if (dtype_precedence_dict[left_operand_dtype] < dtype_precedence_dict[right_operand_dtype]):
518 errorMsg = "cannot modify left hand operand datatype."
519 raise TypeError(errorMsg)
520 return <operator>(self, other)
521''&#x27;
522 elif flag == "comparison":
523 s = ''&#x27;
524def __<operand>__(self, other):
525 return <operator>(self, other)
526''&#x27;
527 s = s.replace("<operator>",dc_operator).replace("<operand>",operator_python)
528 return s

Callers 2

binary_operatorsFunction · 0.85
comparison_operatorsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected