Skip to content

Commit

Permalink
Prevent division by zero in jaccard computation
Browse files Browse the repository at this point in the history
Closes #17.
  • Loading branch information
lrvdijk committed Jan 11, 2023
1 parent 50fbed1 commit 67688d9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/strainge/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def jaccard(kmers1, kmers2):
"""Computes jaccard similarity. Returns numerator and denominator
separately."""
intersection = kmerizer.count_common(kmers1, kmers2)

if kmers1.size == 0 and kmers2.size == 0:
return 0

return intersection / (kmers1.size + kmers2.size - intersection)


Expand Down

0 comments on commit 67688d9

Please sign in to comment.