Skip to content

Enable caching of compiled guvectorize functions #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sgkit/distance/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"void(int8[:], int8[:], float64[:])",
],
"(n),(n)->()",
nopython=True,
cache=True,
)
def correlation(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
"""Calculates the correlation between two vectors.
Expand Down Expand Up @@ -80,6 +82,8 @@ def correlation(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
"void(int8[:], int8[:], float64[:])",
],
"(n),(n)->()",
nopython=True,
cache=True,
)
def euclidean(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
"""Calculates the euclidean distance between two vectors.
Expand Down
2 changes: 2 additions & 0 deletions sgkit/stats/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"(k),(n)->(n)",
nopython=True,
cache=True,
)
def count_alleles(g: ArrayLike, _: ArrayLike, out: ArrayLike) -> None:
"""Generalized U-function for computing per sample allele counts.
Expand Down Expand Up @@ -61,6 +62,7 @@ def count_alleles(g: ArrayLike, _: ArrayLike, out: ArrayLike) -> None:
],
"(n, k),(n),(c)->(c,k)",
nopython=True,
cache=True,
)
def _count_cohort_alleles(
ac: ArrayLike, cohorts: ArrayLike, _: ArrayLike, out: ArrayLike
Expand Down
6 changes: 3 additions & 3 deletions sgkit/stats/popgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ def diversity(

# c = cohorts, k = alleles
@guvectorize( # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any good reason not to have cache=True for our use-case? Perhaps it's worth us having our own local guvectorize decorator that does this by default?

This is the sort of thing that's hard to test for and easy to forget, so maybe it's worth a little indirection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? It's not hard to add and now we have the convention started it is likely to be propagated in our code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #371

["void(int64[:, :], float64[:,:])"],
"(c, k)->(c,c)",
nopython=True,
["void(int64[:, :], float64[:,:])"], "(c, k)->(c,c)", nopython=True, cache=True
)
def _divergence(ac: ArrayLike, out: ArrayLike) -> None:
"""Generalized U-function for computing divergence.
Expand Down Expand Up @@ -295,6 +293,7 @@ def divergence(
],
"(c,c)->(c,c)",
nopython=True,
cache=True,
)
def _Fst_Hudson(d: ArrayLike, out: ArrayLike) -> None:
"""Generalized U-function for computing Fst using Hudson's estimator.
Expand Down Expand Up @@ -326,6 +325,7 @@ def _Fst_Hudson(d: ArrayLike, out: ArrayLike) -> None:
],
"(c,c)->(c,c)",
nopython=True,
cache=True,
)
def _Fst_Nei(d: ArrayLike, out: ArrayLike) -> None:
"""Generalized U-function for computing Fst using Nei's estimator.
Expand Down