Skip to content

Commit 7b821e8

Browse files
author
Olivia W Hsu
committed
Merge branch 'main' of github.com:tensor-compiler/array-programming-benchmarks into main
2 parents b148d5c + 2126328 commit 7b821e8

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

numpy/image.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import pytest
55
import sparse
6-
from util import ImagePydataSparseTensorLoader, safeCastPydataTensorToInts, TnsFileDumper#, plot_image
6+
from util import ImagePydataSparseTensorLoader, safeCastPydataTensorToInts, TnsFileDumper, plot_image
77

88
# import matplotlib.pyplot as plt
99

@@ -283,15 +283,14 @@ def sparse_bench():
283283
sparse_xor_img = np.logical_xor(sbi1, sbi2).astype('int')
284284
return sparse_xor_img
285285

286-
def dense_bench():
287-
bi1 = np.logical_and(bin_img1, bin_window).astype('int')
288-
bi2 = np.logical_and(bin_img2, bin_window).astype('int')
289-
xor_img = np.logical_xor(bi1, bi2).astype('int')
286+
def xor():
287+
xor_img = np.logical_xor(sparse_bin_img1, sparse_bin_img2).astype('int')
290288
return xor_img
289+
291290
ret = tacoBench(sparse_bench)
292291
sparse_xor_img = sparse_bench()
293-
xor_img = dense_bench()
294-
292+
xor_img = xor()
293+
295294
if plot:
296295
num_elements = float(np.prod(bin_img1.shape))
297296
print("Sparse xor NNZ = ", sparse_xor_img.nnz, "\t", "Dense xor NNZ = ", np.sum(xor_img != 0))
@@ -301,7 +300,6 @@ def dense_bench():
301300
sparse_xor_img = sparse_xor_img.todense()
302301
t1 = round(loader.max[num]*pt1, 2)
303302
t2 = round(loader.max[num]*(pt1 + 0.05), 2)
304-
#plot_image(loader.img[num], bin_img1, bin_img2, xor_img, sparse_xor_img, t1, t2, bin_window)
303+
#plot_image(loader.img[num], bin_img1, bin_img2, xor_img.todense(), sparse_xor_img, t1, t2, bin_window)
305304

306-
assert(sparse_xor_img.nnz == np.sum(xor_img != 0))
307305

numpy/util.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import numpy
77
import cv2
88

9+
# NEEDS TO BE COMMENTED OUT FOR LANKA
10+
# import matplotlib.pyplot as plt
11+
912
# Get the path to the directory holding random tensors. Error out
1013
# if this isn't set.
1114
TENSOR_PATH = os.environ['TACO_TENSOR_PATH']
@@ -408,31 +411,32 @@ def dense_window(self, num):
408411
result_np[m0+dm0:m0+3*dm0, m1-3*dm1:m1-dm1] = 1
409412
return result_np
410413

414+
# NEEDS TO BE COMMENTED OUT FOR LANKA
411415
# plot_image plots the given original, binned, xor, and sparse xor images
412416
# for the numpy/image.py. Used for debugging only with the --plot flag
413-
# def plot_image(img, img1, img2, xor_img, sparse_xor_img, t1, t2, window=None):
414-
# f, ax = plt.subplots(2, 3)
415-
# ax[0, 0].imshow(img1, 'gray')
416-
# ax[0, 0].title.set_text("Binned Image 1. t1 = " + str(t1))
417-
#
418-
# ax[0, 1].imshow(img2, 'gray')
419-
# ax[0, 1].title.set_text("Binned Image 2. t2 = " + str(t2))
420-
#
421-
# ax[1, 0].imshow(img, 'gray')
422-
# ax[1, 0].title.set_text("Saturdated Image")
423-
#
424-
# ax[1, 1].imshow(xor_img, 'gray')
425-
# ax[1, 1].title.set_text("XOR Image")
426-
#
427-
# ax[1, 2].imshow(sparse_xor_img, 'gray')
428-
# ax[1, 2].title.set_text("Sparse XOR Image")
429-
#
430-
# if window is not None:
431-
# ax[0, 2].imshow(window, 'gray')
432-
# ax[0, 2].title.set_text("Fused Window Image")
433-
#
434-
# f.tight_layout()
435-
# plt.show()
417+
#def plot_image(img, img1, img2, xor_img, sparse_xor_img, t1, t2, window=None):
418+
# f, ax = plt.subplots(2, 3)
419+
# ax[0, 0].imshow(img, 'gray')
420+
# ax[0, 0].title.set_text("Original Image")
421+
#
422+
# ax[0, 1].imshow(img1, 'gray')
423+
# ax[0, 1].title.set_text("Binned Image 1. t = " + str(t1))
424+
#
425+
# ax[0, 2].imshow(img2, 'gray')
426+
# ax[0, 2].title.set_text("Binned Image 2. t = " + str(t2))
427+
#
428+
# ax[1, 0].imshow(xor_img, 'gray')
429+
# ax[1, 0].title.set_text("Edge Detected Image")
430+
#
431+
# ax[1, 2].imshow(sparse_xor_img, 'gray')
432+
# ax[1, 2].title.set_text("Masked Edge Image")
433+
#
434+
# if window is not None:
435+
# ax[1, 1].imshow(window, 'gray')
436+
# ax[1, 1].title.set_text("ROI Mask")
437+
#
438+
# f.tight_layout()
439+
# plt.show()
436440

437441
# construct_minmax_tensor_key constructs a unique key that represents
438442
# an image tensor parameterized by the tensor order

0 commit comments

Comments
 (0)