You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importnumpyasnpimportnumbaimporthausdorff.distancesasdistancesfrominspectimportgetmembersdefgen_hausdorff_dist(inner_dist,outer_dist,shape_1):
@numba.jit(nopython=True, fastmath=True)def_hausdorff_dist(XA, XB):
assertXA.ndim==2andXB.ndim==2, \
'arrays must be 2-dimensional'assertXA.shape[1] ==shape_1, \
'arrays must have predifened shape[1]'assertXB.shape[1] ==shape_1, \
'arrays must have predifened shape[1]'nA=XA.shape[0]
nB=XB.shape[0]
cmax=0.foriinrange(nA):
cmin=np.infforjinrange(nB):
d=inner_dist(XA[i,:], XB[j,:])
ifd<cmin:
cmin=difcmin<cmax:
breakifcmin>cmaxandnp.inf>cmin:
cmax=cminforjinrange(nB):
cmin=np.infforiinrange(nA):
d=inner_dist(XA[i,:], XB[j,:])
ifd<cmin:
cmin=difcmin<cmax:
breakifcmin>cmaxandnp.inf>cmin:
cmax=cminreturnouter_dist(cmax)
return_hausdorff_distdefgen_hausdorff_distance(shape_1, distance='euclidean'):
distance_function=getattr(distances, distance)
inner_dist,outer_dist=distance_function(shape_1)
returngen_hausdorff_dist(inner_dist,outer_dist,shape_1)
Timings
#Only declare it one if possible, redeclaring in a loop will lead to recompilationhausdorff_distance=hausdorff.gen_hausdorff_distance(u.shape[1])
%timeithausdorff_distance(u, v)
20.4ms ± 41µsperloop (mean ± std. dev. of7runs, 1loopeach)
The text was updated successfully, but these errors were encountered:
Let's start with a small example (possible speedup by a factor of 20)
Two issues are reducing performance:
Possible workarounds
Example for function generation
distance.py
hausdorff.py
Timings
The text was updated successfully, but these errors were encountered: