-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Consistency of return type for matrix functions #12408
Conversation
This fails the whitespace checker. |
5df6507
to
d4a5850
Compare
0a894fa
to
e57939f
Compare
I made the templates clearer, as suggested by @jiahao, and added a bunch of tests to cover a few missing lines in dense.jl. |
I think the convertions with
I think this is only correct for real elements. E.g. julia> A = [1 im; -im 1.0]
2x2 Array{Complex{Float64},2}:
1.0+0.0im 0.0+1.0im
0.0-1.0im 1.0+0.0im
julia> ishermitian(A)
true
julia> expm(A) |> t -> norm(t - t.')
6.38905609893065 I'm not an expert on matrix functions, but we probably want for keep separate defition loops for entire and non-entire functions. I guess we can ensure type stability for entire functions with I forgot to mention that it's a great update of the documentation. |
|
||
.. function:: logm(A) | ||
|
||
Compute the matrix logarithm of ``A``. | ||
If ``A`` has no negative real eigenvalue, compute the principal matrix logarithm of ``A``, i.e. the unique matrix :math:`X` such that :math:`e^X = A` and :math:`-\pi < Im(\lambda) < \pi` for all the eigenvalues :math:`\lambda` of :math:`X`. If ``A`` has nonpositive eigenvalues, a warning is printed and whenever possible a nonprimary matrix function is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible a nonprimary matrix function is returned
Should it be "non-principal"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreasnoack You're right, thank you for spotting this, I'll fix it and submit a separate PR just for the documentation (I'll have to adapt it to #11943).
The documentation in now in #12432. |
e57939f
to
75008f7
Compare
@andreasnoack You're right, that condition is true only for real
If you check EDIT: it looks like this can happen even if
which quite settles the question, I think. If |
@mfasi Part of the point in having the |
75008f7
to
a21980b
Compare
@andreasnoack I submitted a version that enforces the return type when the perturbation of the Hermitian structure is due to rounding errors. As the exponential is the only entire function we have, I didn't implement a loop for it. |
if isposdef(F) | ||
retmat = F.vectors * Diagonal(($func)(F.values)) * F.vectors' | ||
if T <: Real | ||
return real(Hermitian(retmat)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is real
necessary here?
a21980b
to
d16bf3d
Compare
@mfasi Is this ready? I don't think I have more comment. Would you do a |
d16bf3d
to
acbd540
Compare
@andreasnoack Yes, I thought it was ready. I rebased on the master branch, but now the apple build on Travis fails as well. Not sure what happened, since I cannot access the whole log file, but I'm pretty sure the problem is not related to what I changed, it looks like it's trying to compile some fortran library. I'll try to rebase and force again as soon as a new commit is merged to the master branch. |
…atrices, fix type returned by logm and sqrtm
acbd540
to
5d71e05
Compare
Both Travis and AppVeyor managed to build and check, feel free to merge. |
Consistency of return type for matrix functions
Great. Thanks. |
I added specialized versions of expm, logm and sqrtm for symmetric and Hermitian matrices.
EDIT: The documentation is now in #12432