Skip to content

Commit 45f9a34

Browse files
authored
Merge pull request #123 from devmotion/patch-1
Add defaults for `isposdef` and `ishermitian`
2 parents 3c19cc6 + 12015fb commit 45f9a34

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/generics.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
## Basic functions
44

5-
Base.eltype(a::AbstractPDMat{T}) where {T<:Real} = T
6-
Base.eltype(::Type{AbstractPDMat{T}}) where {T<:Real} = T
7-
Base.ndims(a::AbstractPDMat) = 2
85
Base.size(a::AbstractPDMat) = (dim(a), dim(a))
96
Base.size(a::AbstractPDMat, i::Integer) = 1 <= i <= 2 ? dim(a) : 1
107
Base.length(a::AbstractPDMat) = abs2(dim(a))
@@ -27,6 +24,9 @@ pdadd(a::Matrix{T}, b::AbstractPDMat{S}) where {T<:Real, S<:Real} = pdadd!(simil
2724
/(a::AbstractPDMat, c::T) where {T<:Real} = a * inv(c)
2825
Base.kron(A::AbstractPDMat, B::AbstractPDMat) = PDMat(kron(Matrix(A), Matrix(B)))
2926

27+
# LinearAlgebra
28+
LinearAlgebra.isposdef(::AbstractPDMat) = true
29+
LinearAlgebra.ishermitian(::AbstractPDMat) = true
3030

3131
## whiten and unwhiten
3232
whiten!(a::AbstractPDMat, x::StridedVecOrMat) = whiten!(x, a, x)

test/generics.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ using Test
2323
@test Matrix(pmats[i] * 3) == Matrix(pmatsa[i])
2424
end
2525
end
26+
27+
# issue #121
28+
@test isposdef(PDMat([1.0 0.0; 0.0 1.0]))
29+
@test isposdef(PDiagMat([1.0, 1.0]))
30+
@test isposdef(ScalMat(2, 3.0))

test/testutils.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ function pdtest_basics(C::AbstractPDMat, Cmat::Matrix, d::Int, verbose::Int)
7878

7979
_pdt(verbose, "eltype")
8080
@test eltype(C) == eltype(Cmat)
81-
# @test eltype(typeof(C)) == eltype(typeof(Cmat))
81+
# @test eltype(typeof(C)) == eltype(typeof(Cmat))
8282

8383
_pdt(verbose, "index")
8484
@test all(C[i] == Cmat[i] for i in 1:(d^2))
8585
@test all(C[i, j] == Cmat[i, j] for j in 1:d, i in 1:d)
86+
87+
_pdt(verbose, "isposdef")
88+
@test isposdef(C)
89+
90+
_pdt(verbose, "ishermitian")
91+
@test ishermitian(C)
8692
end
8793

8894

0 commit comments

Comments
 (0)