EDIT
Following the comment, numpy implementation of duo_overlap:
def duo_overlap_np(S1, S2, perc):
p1_overlapping = np.zeros(shape = (len(S1.timeline)))
p2_overlapping = np.zeros(shape = (len(S2.timeline)))
start = max(S1.t0, S2.t0) - max(S1.width, S2.width)
if start <= 0:
start = 0
start_id_S1 = 0
start_id_S2 = 0
else:
start_id_S1 = S1.find_closest_t(start)[1]
start_id_S2 = S2.find_closest_t(start)[1]
stop = min(S1.tf, S2.tf) + max(S1.width, S2.width)
for i in range(start_id_S1, len(S1.timeline)):
if S1.timeline[i] > stop:
break
for j in range(start_id_S2, len(S2.timeline)):
if S2.timeline[j] > stop:
break
d = round(abs(S2.timeline[j] - S1.timeline[i]), 3) # Computation of the distance of the 2 point
if S1.timeline[i] <= S2.timeline[j] and d < S1.width:
p1_overlapping[i] = 1
p2_overlapping[j] = 1
continue
elif S1.timeline[i] >= S2.timeline[j] and d < S2.width:
p1_overlapping[i] = 1
p2_overlapping[j] = 1
continue
else:
continue
return list(np.nonzero(p1_overlapping)[0]), list(np.nonzero(p2_overlapping)[0])
I'm quite sure I didn't get it right since it doesn't improve much. On 50 calls I get the following timing in second:
Old: 8.20273494720459
New: 8.188030004501343