Skip to content

Commit

Permalink
python alias to wrap jaccard njit #165
Browse files Browse the repository at this point in the history
  • Loading branch information
jacanchaplais committed Nov 10, 2023
1 parent e56c792 commit 4f9fe12
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion graphicle/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def spherocity(
"float64(bool_[:], bool_[:], Omitted(None))",
]
)
def jaccard_distance(
def _jaccard_distance(
u: base.BoolVector,
v: base.BoolVector,
w: ty.Optional[base.DoubleVector] = None,
Expand Down Expand Up @@ -1012,3 +1012,35 @@ def jaccard_distance(
if union_sum == 0.0:
return 0.0
return difference_sum / union_sum


def jaccard_distance(
mask_1: ty.Union[base.MaskBase, base.BoolVector],
mask_2: ty.Union[base.MaskBase, base.BoolVector],
weights: ty.Optional[base.DoubleVector] = None,
) -> float:
"""Computes the Jaccard distance between two sets.
:group: calculate
.. versionadded:: 0.3.8
Parameters
----------
mask_1, mask_2 : ndarray[bool_] or MaskBase
Boolean masks, identifying which elements belong to the
respective sets.
weights : ndarray[float64]
Weights associated with each element. If not passed,
will assume weights are 1.
Returns
-------
float
Jaccard distance between sets.
"""
if not isinstance(mask_1, np.ndarray):
mask_1 = mask_1.data
if not isinstance(mask_2, np.ndarray):
mask_2 = mask_2.data
return _jaccard_distance(mask_1, mask_2, weights)

0 comments on commit 4f9fe12

Please sign in to comment.