Skip to content

Commit cdb3eab

Browse files
tomwhitemergify[bot]
authored andcommitted
Enable caching of compiled guvectorize functions
1 parent cf33b01 commit cdb3eab

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

sgkit/distance/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"void(int8[:], int8[:], float64[:])",
1414
],
1515
"(n),(n)->()",
16+
cache=True,
1617
)
1718
def correlation(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
1819
"""Calculates the correlation between two vectors.
@@ -80,6 +81,7 @@ def correlation(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
8081
"void(int8[:], int8[:], float64[:])",
8182
],
8283
"(n),(n)->()",
84+
cache=True,
8385
)
8486
def euclidean(x: ArrayLike, y: ArrayLike, out: ArrayLike) -> None:
8587
"""Calculates the euclidean distance between two vectors.

sgkit/stats/aggregation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
],
2525
"(k),(n)->(n)",
2626
nopython=True,
27+
cache=True,
2728
)
2829
def count_alleles(g: ArrayLike, _: ArrayLike, out: ArrayLike) -> None:
2930
"""Generalized U-function for computing per sample allele counts.
@@ -61,6 +62,7 @@ def count_alleles(g: ArrayLike, _: ArrayLike, out: ArrayLike) -> None:
6162
],
6263
"(n, k),(n),(c)->(c,k)",
6364
nopython=True,
65+
cache=True,
6466
)
6567
def _count_cohort_alleles(
6668
ac: ArrayLike, cohorts: ArrayLike, _: ArrayLike, out: ArrayLike

sgkit/stats/popgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ def diversity(
121121

122122
# c = cohorts, k = alleles
123123
@guvectorize( # type: ignore
124-
["void(int64[:, :], float64[:,:])"],
125-
"(c, k)->(c,c)",
126-
nopython=True,
124+
["void(int64[:, :], float64[:,:])"], "(c, k)->(c,c)", nopython=True, cache=True
127125
)
128126
def _divergence(ac: ArrayLike, out: ArrayLike) -> None:
129127
"""Generalized U-function for computing divergence.
@@ -295,6 +293,7 @@ def divergence(
295293
],
296294
"(c,c)->(c,c)",
297295
nopython=True,
296+
cache=True,
298297
)
299298
def _Fst_Hudson(d: ArrayLike, out: ArrayLike) -> None:
300299
"""Generalized U-function for computing Fst using Hudson's estimator.
@@ -326,6 +325,7 @@ def _Fst_Hudson(d: ArrayLike, out: ArrayLike) -> None:
326325
],
327326
"(c,c)->(c,c)",
328327
nopython=True,
328+
cache=True,
329329
)
330330
def _Fst_Nei(d: ArrayLike, out: ArrayLike) -> None:
331331
"""Generalized U-function for computing Fst using Nei's estimator.

0 commit comments

Comments
 (0)