Skip to content

Commit

Permalink
Ensure that Matrix constructor returns a Matrix for a PDMat (#196)
Browse files Browse the repository at this point in the history
* Ensure that `Matrix` constructor returns a `Matrix` for a `PDMat`

* Add test for `Matrix` constructor

* Check type of `Matrix` for static pd matrices
  • Loading branch information
devmotion authored Nov 10, 2023
1 parent ca14884 commit 9c3a301
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pdmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Base.convert(::Type{AbstractPDMat{T}}, a::PDMat) where {T<:Real} = convert(PDMat
### Basics

Base.size(a::PDMat) = (a.dim, a.dim)
Base.Matrix(a::PDMat) = copy(a.mat)
Base.Matrix(a::PDMat) = Matrix(a.mat)
LinearAlgebra.diag(a::PDMat) = diag(a.mat)
LinearAlgebra.cholesky(a::PDMat) = a.chol

Expand Down
2 changes: 2 additions & 0 deletions test/specialarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ using StaticArrays
Y = @SMatrix rand(4, 10)

for A in (PDS, D, E, C)
@test Matrix(A) isa Matrix

if !(A isa Cholesky)
# `*(::Cholesky, ::SArray)` is not defined
@test A * x isa SVector{4, Float64}
Expand Down
5 changes: 5 additions & 0 deletions test/testutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ function pdtest_basics(C, Cmat::Matrix, d::Int, verbose::Int)
if C isa AbstractPDMat
@test M === C
end

_pdt(verbose, "Matrix")
M = Matrix(C)
@test M isa Matrix
@test M == Cmat
end


Expand Down

0 comments on commit 9c3a301

Please sign in to comment.