MCPcopy Create free account
hub / github.com/KomputeProject/kompute / plot_tensor

Function plot_tensor

examples/python_naive_matmul/matmul_plot.py:7–22  ·  view source on GitHub ↗
(window_name: str, tensor: np.ndarray, coord_highlight: tuple[int, int] = None)

Source from the content-addressed store, hash-verified

5
6
7def plot_tensor(window_name: str, tensor: np.ndarray, coord_highlight: tuple[int, int] = None):
8 font_size = 48
9 image = np.zeros((tensor.shape[1] * font_size, tensor.shape[0] * font_size, 3), dtype=np.uint8)
10
11 for y in range(tensor.shape[1]):
12 for x in range(tensor.shape[0]):
13 if coord_highlight and x == coord_highlight[1] and y == coord_highlight[0]:
14 cv2.putText(
15 image, str(int(tensor[y, x])), (x * font_size, int((y + 0.8) * font_size)),
16 cv2.FONT_HERSHEY_TRIPLEX, 1., (127, 127, 255))
17 else:
18 cv2.putText(
19 image, str(int(tensor[y, x])), (x * font_size, int((y + 0.8) * font_size)),
20 cv2.FONT_HERSHEY_TRIPLEX, 1., (255, 255, 255))
21
22 cv2.imshow(window_name, image)
23
24
25def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected