Skip to content

Commit 44cfbb9

Browse files
committed
optimization: do not solve a second time if K is symmetric ... if it is faster at all?
1 parent 768fa70 commit 44cfbb9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pymc3/gp/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ def invert_dot(L, X):
1515

1616
def project_inverse(P, L, diag=True, P_T=None):
1717
"""Wrapper for common pattern P @ K^{-1} @ P^T where K = L @ L^T"""
18-
if P_T is None:
18+
symmetric = P_T is None
19+
if symmetric:
1920
P_T = P.T
21+
A = solve_lower(L, P_T)
2022
if diag:
21-
A = solve_lower(L, P_T)
2223
return tt.sum(A * A, axis=0) # the diagonal of A.T @ A
2324
else:
24-
return tt.dot(P, invert_dot(L, P_T))
25+
if symmetric:
26+
return tt.dot(A.T, A)
27+
else:
28+
return tt.dot(P, invert_dot(L, P_T))
2529

2630

2731
def infer_shape(X, n_points=None):

0 commit comments

Comments
 (0)