Skip to content

Commit

Permalink
fix use of type parameters in defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Jun 24, 2024
1 parent d229278 commit f47fb4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MixedModels v4.24.2 Release Notes
- Fix use of kwargs in `fit!((::LinearMixedModel)`: [#772]
- user-specified `σ` is actually used, defaulting to existing value
- `REML` defaults to model's already specified REML value.
- Clean up code of keyword convenience constructor for `OptSummary`. [#772]

MixedModels v4.24.1 Release Notes
==============================
Expand Down
29 changes: 16 additions & 13 deletions src/optsummary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,37 @@ The latter four fields are MixedModels functionality and not related directly to
Base.@kwdef mutable struct OptSummary{T<:AbstractFloat}
initial::Vector{T}
lowerbd::Vector{T}
finitial::T = T(Inf)
ftol_rel::T = zero(T)
ftol_abs::T = zero(T)
xtol_rel::T = zero(T)
# the @kwdef macro isn't quite smart enough for us to use the type parameter
# for the default values, but we can fake it
finitial::T = Inf * one(eltype(initial))
ftol_rel::T = zero(eltype(initial))
ftol_abs::T = zero(eltype(initial))
xtol_rel::T = zero(eltype(initial))
xtol_abs::Vector{T} = zero(initial) .+ 1e-10
initial_step::Vector{T} = T[]
initial_step::Vector{T} = empty(initial)
maxfeval::Int = -1
maxtime::T = T(-1)
maxtime::T = -one(eltype(initial))
feval::Int = -1
final::Vector{T} = copy(initial)
fmin::T = T(Inf)
fmin::T = Inf * one(eltype(initial))
optimizer::Symbol = :LN_BOBYQA
returnvalue::Symbol = :FAILURE
ftol_zero_abs::T = T(0.001)
ftol_zero_abs::T = one(eltype(initial)) / 1000
# not SVector because we would need to parameterize on size (which breaks GLMM)
fitlog::Vector{Tuple{Vector{T},T}} = [(initial, T(Inf))]
fitlog::Vector{Tuple{Vector{T},T}} = [(initial, fmin)]
# don't really belong here but I needed a place to store them
nAGQ::Integer = 1
nAGQ::Int = 1
REML::Bool = false
sigma::Union{T,Nothing} = nothing
end

function OptSummary(
initial::Vector{T},
lowerbd::Vector{T},
lowerbd::Vector{S},
optimizer::Symbol=:LN_BOBYQA; kwargs...
) where {T<:AbstractFloat}
return OptSummary( ; initial, lowerbd, optimizer, kwargs...)
) where {T<:AbstractFloat, S<:AbstractFloat}
TS = promote_type(T, S)
return OptSummary{TS}( ; initial, lowerbd, optimizer, kwargs...)
end

"""
Expand Down

0 comments on commit f47fb4a

Please sign in to comment.