-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Condition sparse-dot-topn version on Python version
- Loading branch information
Showing
3 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
import importlib.util | ||
from scipy.sparse import csr_matrix | ||
|
||
from typing import Optional | ||
|
||
_HAVE_SPARSE_DOT = importlib.util.find_spec("sparse_dot_topn") is not None | ||
if _HAVE_SPARSE_DOT: | ||
if sys.version_info > (3, 7): | ||
from sparse_dot_topn import sp_matmul_topn | ||
else: | ||
from sparse_dot_topn import awesome_cossim_topn | ||
|
||
def sp_matmul_topn( | ||
A: csr_matrix, | ||
B: csr_matrix, | ||
top_n: int, | ||
threshold: float, | ||
sort: bool = True, | ||
n_threads: Optional[int] = None, | ||
): | ||
n_threads = n_threads or 1 | ||
use_threads = n_threads > 1 | ||
return awesome_cossim_topn( | ||
A, | ||
B.T, | ||
ntop=max(top_n, 2), | ||
lower_bound=threshold, | ||
use_threads=use_threads, | ||
n_jobs=n_threads, | ||
) | ||
|
||
|
||
__all__ = ["sp_matmul_topn"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters