Skip to content

Commit 73ba367

Browse files
mbudisicmtsch
andauthored
Computing distances between two empty PersistenceDiagrams (#54)
* Added unit test for distances between two empty persistence diagrams * Distances between empty persistence diagrams return zero instantaneously * Update test/matching.jl Co-authored-by: mtsch <matijacufar@gmail.com> * Update src/matching.jl Co-authored-by: mtsch <matijacufar@gmail.com> * Update src/matching.jl Co-authored-by: mtsch <matijacufar@gmail.com> Co-authored-by: mtsch <matijacufar@gmail.com>
1 parent e761e58 commit 73ba367

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/matching.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ function (::Bottleneck)(left::PersistenceDiagram, right::PersistenceDiagram; mat
402402
end
403403
end
404404

405+
if length(left) == 0 & length(right) == 0
406+
if matching
407+
return Matching(left, right, 0, Pair{Int,Int}[], true)
408+
else
409+
return 0.0
410+
end
411+
end
412+
405413
graph = BottleneckGraph(left, right)
406414
edges = graph.edges
407415

@@ -494,6 +502,15 @@ end
494502
function (w::Wasserstein)(
495503
left::PersistenceDiagram, right::PersistenceDiagram; matching=false
496504
)
505+
506+
if length(left) == 0 & length(right) == 0
507+
if matching
508+
return Matching(left, right, 0, Pair{Int,Int}[], false)
509+
else
510+
return 0.0
511+
end
512+
end
513+
497514
if count(!isfinite, left) == count(!isfinite, right)
498515
adj = _adjacency_matrix(right, left, w.q)
499516
match = collect(i => j for (i, j) in enumerate(hungarian(adj)[1]))

test/matching.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ end
7979
@test weight(Wasserstein(), diag1, diag1) 0.0
8080
end
8181

82+
@testset "Empty diagrams" begin
83+
diag = PersistenceDiagram([])
84+
85+
@test Wasserstein()(diag,diag; matching = false) 0.0
86+
@test Bottleneck()(diag,diag; matching = false) 0.0
87+
88+
end
89+
8290
@testset "Infinite intervals" begin
8391
diag1 = PersistenceDiagram([(1, 2), (5, 8), (1, Inf)])
8492
diag2 = PersistenceDiagram([(1, 2), (3, 4), (5, 10)])

0 commit comments

Comments
 (0)