MCPcopy Create free account
hub / github.com/KnowingNothing/MatmulTutorial / __handle_rbinary__

Method __handle_rbinary__

util/simulator/kernel.py:66–83  ·  view source on GitHub ↗
(self, func, other)

Source from the content-addressed store, hash-verified

64 return Arange.make(idx, dim_map, dim_order)
65
66 def __handle_rbinary__(self, func, other):
67 if is_py_value(other):
68 return Arange.make(func(other, self._idx), self._dim_map, self._dim_order)
69 else:
70 assert isinstance(other, Arange)
71 left = self._idx
72 for i in range(other.dim):
73 left = np.expand_dims(left, axis=-1)
74 right = other._idx
75 for i in range(self.dim):
76 right = np.expand_dims(right, axis=0)
77 idx = func(right, left)
78 for k in self._dim_map.keys():
79 assert k not in other._dim_map.keys(), "Unexpected dim name collision"
80 dim_map = {k: v for k, v in self._dim_map.items()}
81 dim_map.update(other._dim_map)
82 dim_order = other._dim_order + self._dim_order
83 return Arange.make(idx, dim_map, dim_order)
84
85 def __add__(self, other):
86 return self.__handle_binary__(lambda x, y: x + y, other)

Callers 5

__radd__Method · 0.95
__rsub__Method · 0.95
__rmul__Method · 0.95
__rdiv__Method · 0.95
__rmod__Method · 0.95

Calls 2

is_py_valueFunction · 0.90
makeMethod · 0.80

Tested by

no test coverage detected