Skip to content

Commit 2647eb6

Browse files
authored
Use in-place left division (#196)
1 parent e299c69 commit 2647eb6

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/fit.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ function reg(
298298

299299
# Build
300300
newZ = hcat(Xexo, Z)
301-
Pi = cholesky!(Symmetric(newZ' * newZ)) \ (newZ' * Xendo)
301+
Pi = ldiv!(cholesky!(Symmetric(newZ'newZ)), newZ'Xendo)
302302
Xhat = hcat(Xexo, newZ * Pi)
303303
X = hcat(Xexo, Xendo)
304304

305305
# prepare residuals used for first stage F statistic
306306
## partial out Xendo in place wrt (Xexo, Z)
307307
Xendo_res = BLAS.gemm!('N', 'N', -1.0, newZ, Pi, 1.0, Xendo)
308308
## partial out Z in place wrt Xexo
309-
Pi2 = cholesky!(Symmetric(Xexo' * Xexo)) \ (Xexo' * Z)
309+
Pi2 = ldiv!(cholesky!(Symmetric(Xexo'Xexo)), Xexo'Z)
310310
Z_res = BLAS.gemm!('N', 'N', -1.0, Xexo, Pi2, 1.0, Z)
311311
else
312312
# get linearly independent columns
@@ -324,8 +324,8 @@ function reg(
324324
##
325325
##############################################################################
326326

327-
crossx = cholesky!(Symmetric(Xhat' * Xhat))
328-
coef = crossx \ (Xhat' * y)
327+
crossx = cholesky!(Symmetric(Xhat'Xhat))
328+
coef = ldiv!(crossx, Xhat'y)
329329

330330
##############################################################################
331331
##

src/partial_out.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ function partial_out(
121121
end
122122
# Compute residuals
123123
if size(X, 2) > 0
124-
residuals = Y .- X * (X \ Y)
125-
else
126-
residuals = Y
124+
mul!(Y, X, X\Y, -1.0, 1.0)
127125
end
126+
residuals = Y
128127

129128
# rescale residuals
130129
if has_weights

0 commit comments

Comments
 (0)