From c1f9ca0842d187eddf2112435fd3b378ea93664e Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 5 Mar 2024 11:26:56 -0600 Subject: [PATCH] Replace broadcasted lambda with explicit loop (#738) * Replace broadcasted lambda with explicit loop * version bump and NEWS * NEWS xref --- NEWS.md | 5 +++++ Project.toml | 2 +- src/remat.jl | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index f0c4aefd7..4a30410f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +MixedModels v4.22.5 Release Notes +============================== +* Replace broadcasted lambda with explicit loop and use `one`. This may result in a small performance improvement. [#738] + MixedModels v4.22.4 Release Notes ============================== * Switch to explicit imports from all included packages (i.e. replace `using Foo` by `using Foo: Foo, bar, baz`) [#748] @@ -495,5 +499,6 @@ Package dependencies [#715]: https://github.com/JuliaStats/MixedModels.jl/issues/715 [#717]: https://github.com/JuliaStats/MixedModels.jl/issues/717 [#733]: https://github.com/JuliaStats/MixedModels.jl/issues/733 +[#738]: https://github.com/JuliaStats/MixedModels.jl/issues/738 [#744]: https://github.com/JuliaStats/MixedModels.jl/issues/744 [#748]: https://github.com/JuliaStats/MixedModels.jl/issues/748 diff --git a/Project.toml b/Project.toml index 2a6d9d685..30112b4d9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MixedModels" uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316" author = ["Phillip Alday ", "Douglas Bates ", "Jose Bayoan Santiago Calderon "] -version = "4.22.4" +version = "4.22.5" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" diff --git a/src/remat.jl b/src/remat.jl index a23430190..b350cd059 100644 --- a/src/remat.jl +++ b/src/remat.jl @@ -564,7 +564,10 @@ function copyscaleinflate! end function copyscaleinflate!(Ljj::Diagonal{T}, Ajj::Diagonal{T}, Λj::ReMat{T,1}) where {T} Ldiag, Adiag = Ljj.diag, Ajj.diag - broadcast!((x, λsqr) -> x * λsqr + one(T), Ldiag, Adiag, abs2(only(Λj.λ))) + lambsq = abs2(only(Λj.λ.data)) + @inbounds for i in eachindex(Ldiag, Adiag) + Ldiag[i] = lambsq * Adiag[i] + one(T) + end return Ljj end @@ -606,14 +609,14 @@ function copyscaleinflate!( iszero(r) || throw(DimensionMismatch("size(Ljj, 1) is not a multiple of S")) λ = Λj.λ offset = 0 - @inbounds for k in 1:q + @inbounds for _ in 1:q inds = (offset + 1):(offset + S) tmp = view(Ljj, inds, inds) lmul!(adjoint(λ), rmul!(tmp, λ)) offset += S end for k in diagind(Ljj) - Ljj[k] += 1 + Ljj[k] += one(T) end return Ljj end