Browse Source

use np.empty instead of np.zeros in pairwise_intersection

quarrying 3 years ago
parent
commit
edd3c194cc
1 changed files with 4 additions and 3 deletions
  1. 4 3
      khandy/boxes/boxes_overlap.py

+ 4 - 3
khandy/boxes/boxes_overlap.py

@@ -41,13 +41,14 @@ def pairwise_intersection(boxes1, boxes2):
     """
     """
     rows = boxes1.shape[0]
     rows = boxes1.shape[0]
     cols = boxes2.shape[0]
     cols = boxes2.shape[0]
-    intersect_areas = np.zeros((rows, cols), dtype=boxes1.dtype)
     if rows * cols == 0:
     if rows * cols == 0:
-        return intersect_areas
+        return np.zeros((rows, cols), dtype=boxes1.dtype)
+
+    intersect_areas = np.empty((rows, cols), dtype=boxes1.dtype)
     swap = False
     swap = False
     if boxes1.shape[0] > boxes2.shape[0]:
     if boxes1.shape[0] > boxes2.shape[0]:
         boxes1, boxes2 = boxes2, boxes1
         boxes1, boxes2 = boxes2, boxes1
-        intersect_areas = np.zeros((cols, rows), dtype=boxes1.dtype)
+        intersect_areas = np.empty((cols, rows), dtype=boxes1.dtype)
         swap = True
         swap = True
 
 
     for i in range(boxes1.shape[0]):
     for i in range(boxes1.shape[0]):