Skip to content

Commit cb171da

Browse files
authored
generic rankUpdate! method (#263)
1 parent be67f5c commit cb171da

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/linalg/rankUpdate.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ The order of the arguments
1111
"""
1212
function rankUpdate! end
1313

14+
function rankUpdate!(
15+
C::AbstractMatrix{T},
16+
A::AbstractMatrix{T},
17+
α=true,
18+
β=true) where {T}
19+
20+
m, n = size(A)
21+
m == size(C, 2) || throw(DimensionMismatch(""))
22+
@info "it is surprising that this function is called - please report a use case as a MixedModels issue"
23+
@warn "using generic method, this will be slower than usual"
24+
25+
A = A'A
26+
27+
for (i, el) in enumerate(C)
28+
C[i] = β * el + α * A[i]
29+
end
30+
C
31+
end
32+
1433
function rankUpdate!(
1534
C::HermOrSym{T,S},
1635
a::StridedVector{T},

test/linalg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ end
4949

5050
# when converting straight from diagonal to symmetric, the type is different
5151
@test Diagonal(fill(5.,2)) == MixedModels.rankUpdate!(Symmetric(Matrix(1. * I(2)), :L), d2)
52+
# generic method
53+
@test Diagonal(fill(5.,2)) == MixedModels.rankUpdate!(Matrix(1. * I(2)), d2)
5254
end
5355

5456
@testset "lmulλ!" begin

0 commit comments

Comments
 (0)