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

Method __handle_binary__

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

Source from the content-addressed store, hash-verified

45 return len(self._idx.shape)
46
47 def __handle_binary__(self, func, other):
48 if is_py_value(other):
49 return Arange.make(func(self._idx, other), self._dim_map, self._dim_order)
50 else:
51 assert isinstance(other, Arange)
52 left = self._idx
53 for i in range(other.dim):
54 left = np.expand_dims(left, axis=-1)
55 right = other._idx
56 for i in range(self.dim):
57 right = np.expand_dims(right, axis=0)
58 idx = func(left, right)
59 for k in self._dim_map.keys():
60 assert k not in other._dim_map.keys(), "Unexpected dim name collision"
61 dim_map = {k: v for k, v in self._dim_map.items()}
62 dim_map.update(other._dim_map)
63 dim_order = self._dim_order + other._dim_order
64 return Arange.make(idx, dim_map, dim_order)
65
66 def __handle_rbinary__(self, func, other):
67 if is_py_value(other):

Callers 5

__add__Method · 0.95
__sub__Method · 0.95
__mul__Method · 0.95
__div__Method · 0.95
__mod__Method · 0.95

Calls 2

is_py_valueFunction · 0.90
makeMethod · 0.80

Tested by

no test coverage detected