Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults for isposdef and ishermitian #123

Merged
merged 6 commits into from
Nov 4, 2021

Conversation

devmotion
Copy link
Member

@devmotion devmotion commented Jan 5, 2021

This PR adds generic definitions of LinearAlgebra.isposdef and LinearAlgebra.ishermitian. It also removes Base.eltype and Base.ndims definitions which are not needed anymore since AbstractPDMat{T} <: AbstractMatrix{T}.

Fixes #121. Fixes #118.

I am not completely sure what's the best way to test these definitions (in particular ishermitian) - maybe I should add at least the failing examples for isposdef?

@andreasnoack
Copy link
Member

maybe I should add at least the failing examples for isposdef?

Which are they? I think it would be good to add trivial tests. I'm not sure how to test anything non-trivial here since you can't construct the instances if the matrix isn't Hermitian and positive definite.

@devmotion
Copy link
Member Author

I thought about the failing examples in #121.

@andreasnoack
Copy link
Member

Ah. Yes, it would probably be good to add them.

Comment on lines +27 to +29
@test isposdef(PDMat([1.0 0.0; 0.0 1.0]))
@test isposdef(PDiagMat([1.0, 1.0]))
@test isposdef(ScalMat(2, 3.0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the same trivial tests for ishermitian?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only isposdef was broken, so I only added tests for these failing examples. ishermitian works fine for PDMat, PDiagMat, and ScalMat already without this PR, it is just more efficient since it does not have to check all entries explicitly with this PR. So the actual change in this PR can't be tested.

test/generics.jl Outdated Show resolved Hide resolved
@devmotion
Copy link
Member Author

Bump 🙂

@palday
Copy link
Member

palday commented Feb 26, 2021

LGTM, @andreasnoack ?

@andreasnoack
Copy link
Member

What is the thinking about the case PDiagMat([0.0, 0.0])? I also thinking about the consequences of allowing the zero matrix for PDMat since I have usecase where it would be handy.

@devmotion
Copy link
Member Author

My impression was that PDMats (so far) is not designed to work with positive semi-definite matrices, and therefore https://github.com/invenia/PDMatsExtras.jl was created. But maybe it would still be better to define isposdef only for PDMat, PDiagMat and ScalMat but not AbstractPDMat? It would also avoid the incorrect default isposdef(::PSDMat) = true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shouldn't isposdef return true for AbstractPDMats? PDMats.isposdef fails on PDMat type
3 participants