Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
simsurace and github-actions[bot] authored Feb 10, 2024
1 parent 7f07352 commit 73ad032
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/ParameterHandling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ using LinearAlgebra
using SparseArrays

export flatten,
value_flatten, positive, bounded, fixed, deferred, orthogonal, positive_definite,
value_flatten,
positive,
bounded,
fixed,
deferred,
orthogonal,
positive_definite,
positive_semidefinite

include("flatten.jl")
Expand Down
8 changes: 5 additions & 3 deletions src/parameters_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ be a positive real number.
The unconstrained parameter is a `LowerTriangular` matrix, stored as a vector.
"""
function positive_definite(X::AbstractMatrix{T}, ε = eps(T)) where T <: Real
function positive_definite(X::AbstractMatrix{T}, ε=eps(T)) where {T<:Real}
ε > 0 || throw(ArgumentError("ε is not positive. Use `positive_semidefinite` instead."))
_X = X - ε * I
isposdef(_X) || throw(ArgumentError("X-ε*I is not positive-definite for ε="))
Expand All @@ -87,11 +87,13 @@ value(X::PositiveSemiDefinite) = A_At(vec_to_tril(X.L))

function flatten(::Type{T}, X::PositiveSemiDefinite) where {T<:Real}
v, unflatten_v = flatten(T, X.L)
unflatten_PositiveSemiDefinite(v_new::Vector{T}) = PositiveSemiDefinite(unflatten_v(v_new))
function unflatten_PositiveSemiDefinite(v_new::Vector{T})
return PositiveSemiDefinite(unflatten_v(v_new))
end
return v, unflatten_PositiveSemiDefinite
end

struct PositiveDefinite{TL<:AbstractVector{<:Real}, <:Real} <: AbstractParameter
struct PositiveDefinite{TL<:AbstractVector{<:Real},Tε<:Real} <: AbstractParameter
L::TL
ε::Tε
end
Expand Down
2 changes: 1 addition & 1 deletion test/parameters_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using ParameterHandling: vec_to_tril, tril_to_vec
X.L .= 0 # zero the unconstrained value
@test isposdef(value(X))
@test_throws ArgumentError positive_definite(zeros(3, 3))
@test_throws ArgumentError positive_definite(X_mat, 0.)
@test_throws ArgumentError positive_definite(X_mat, 0.0)
test_parameter_interface(X)

x, re = flatten(X)
Expand Down

0 comments on commit 73ad032

Please sign in to comment.