Skip to content

Commit

Permalink
use ::Matrix{T} instead of ::T to aid type inference (#773)
Browse files Browse the repository at this point in the history
* use ::Matrix{T} instead of ::T

* update NEWS.md

* JuliaFormatter run (mostly adding trailing commas).
  • Loading branch information
dmbates committed Jun 22, 2024
1 parent 39dd384 commit ce5b604
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
MixedModels v4.24.1 Release Notes
==============================
Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773]

MixedModels v4.24.0 Release Notes
==============================
* Properties for `GeneralizedLinearMixedModel` now default to delegation to the internal weighted `LinearMixedModel` when that property is not explicitly handled by `GeneralizedLinearMixedModel`. Previously, properties were delegated on an explicit basis, which meant that they had to be added manually as use cases were discovered. The downside to the new approach is that it is now possible to access properties whose definition in the LMM case doesn't match the GLMM definition when the GLMM definition hasn't been explicitly been implemented. [#767]
Expand Down Expand Up @@ -521,3 +525,4 @@ Package dependencies
[#755]: https://github.com/JuliaStats/MixedModels.jl/issues/755
[#756]: https://github.com/JuliaStats/MixedModels.jl/issues/756
[#767]: https://github.com/JuliaStats/MixedModels.jl/issues/767
[#773]: https://github.com/JuliaStats/MixedModels.jl/issues/773
4 changes: 2 additions & 2 deletions src/generalizedlinearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function GeneralizedLinearMixedModel(
tbl,
d::Distribution,
l::Type;
kwargs...
kwargs...,
)
throw(ArgumentError("Expected a Link instance (`$l()`), got a type (`$l`)."))
end
Expand All @@ -376,7 +376,7 @@ function GeneralizedLinearMixedModel(
tbl::Tables.ColumnTable,
d::Normal,
l::IdentityLink;
kwargs...
kwargs...,
)
return throw(
ArgumentError("use LinearMixedModel for Normal distribution with IdentityLink")
Expand Down
2 changes: 1 addition & 1 deletion src/likelihoodratiotest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function _iscomparable(m::LinearMixedModel...)
if any(getproperty.(getproperty.(m, :optsum), :REML))
isconstant(coefnames.(m)) || throw(
ArgumentError(
"Likelihood-ratio tests for REML-fitted models are only valid when the fixed-effects specifications are identical",
"Likelihood-ratio tests for REML-fitted models are only valid when the fixed-effects specifications are identical"
),
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/logdet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ lower Cholesky factor.
"""
function LinearAlgebra.logdet(m::LinearMixedModel{T}) where {T}
L = m.L
@inbounds s = sum(j -> LD(L[kp1choose2(j)]), axes(m.reterms, 1))::T
@inbounds s = sum(j -> LD(L[kp1choose2(j)])::T, axes(m.reterms, 1))
if m.optsum.REML
lastL = last(L)
lastL = last(L)::Matrix{T}
s += LD(lastL) # this includes the log of sqrtpwrss
s -= log(last(lastL)) # so we need to subtract it from the sum
end
Expand Down
2 changes: 1 addition & 1 deletion src/linalg/rankUpdate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function rankUpdate! end

function rankUpdate!(C::AbstractMatrix, a::AbstractArray, α, β)
return error(
"We haven't implemented a method for $(typeof(C)), $(typeof(a)). Please file an issue on GitHub.",
"We haven't implemented a method for $(typeof(C)), $(typeof(a)). Please file an issue on GitHub."
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ end
The penalized, weighted residual sum-of-squares.
"""
pwrss(m::LinearMixedModel{T}) where {T} = abs2(last(last(m.L)))::T
pwrss(m::LinearMixedModel{T}) where {T} = abs2(last(last(m.L)::Matrix{T}))

"""
ranef!(v::Vector{Matrix{T}}, m::MixedModel{T}, β, uscale::Bool) where {T}
Expand Down
4 changes: 2 additions & 2 deletions src/mixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function StatsAPI.fit(
tbl,
d::Type,
args...;
kwargs...
kwargs...,
)
throw(ArgumentError("Expected a Distribution instance (`$d()`), got a type (`$d`)."))
end
Expand All @@ -91,7 +91,7 @@ function StatsAPI.fit(
tbl,
d::Distribution,
l::Type;
kwargs...
kwargs...,
)
throw(ArgumentError("Expected a Link instance (`$l()`), got a type (`$l`)."))
end
Expand Down
2 changes: 1 addition & 1 deletion src/predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function _predict(m::MixedModel{T}, newdata, β; new_re_levels) where {T}
any(any(ismissing, Tables.getcolumn(newdata, col)) for col in respvars)
throw(
ArgumentError(
"Response column must be initialized to a non-missing numeric value.",
"Response column must be initialized to a non-missing numeric value."
),
)
end
Expand Down
2 changes: 1 addition & 1 deletion src/profile/thetapr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function optsumj(os::OptSummary, j::Integer)
return OptSummary(
deleteat!(copy(os.final), j),
deleteat!(copy(os.lowerbd), j),
os.optimizer
os.optimizer,
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/randomeffectsterm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function StatsModels.apply_schema(
if !(typeof(first) <: CategoricalTerm)
throw(
ArgumentError(
"nesting terms requires categorical grouping term, got $first. Manually specify $first as `CategoricalTerm` in hints/contrasts",
"nesting terms requires categorical grouping term, got $first. Manually specify $first as `CategoricalTerm` in hints/contrasts"
),
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/remat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ end
function copyscaleinflate!(
Ljj::UniformBlockDiagonal{T},
Ajj::UniformBlockDiagonal{T},
Λj::ReMat{T,S}
Λj::ReMat{T,S},
) where {T,S}
λ = Λj.λ
dind = diagind(S, S)
Expand All @@ -604,7 +604,7 @@ end
function copyscaleinflate!(
Ljj::Matrix{T},
Ajj::UniformBlockDiagonal{T},
Λj::ReMat{T,S}
Λj::ReMat{T,S},
) where {T,S}
copyto!(Ljj, Ajj)
n = LinearAlgebra.checksquare(Ljj)
Expand Down
2 changes: 1 addition & 1 deletion src/simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function _simulate!(
ismissing(σ) ||
throw(
ArgumentError(
"You must not specify a dispersion parameter for model families without a dispersion parameter",
"You must not specify a dispersion parameter for model families without a dispersion parameter"
),
)

Expand Down
2 changes: 1 addition & 1 deletion src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function replicate(
)
use_threads && Base.depwarn(
"use_threads is deprecated and will be removed in a future release",
:replicate
:replicate,
)
if !isnothing(hide_progress)
Base.depwarn(
Expand Down

0 comments on commit ce5b604

Please sign in to comment.