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 matrix exponentials #46

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

sw2030
Copy link

@sw2030 sw2030 commented Apr 15, 2021

Quaternion matrix exponential added using a quick detour to complex representation.

src/Quaternion.jl Outdated Show resolved Hide resolved
@KristofferC
Copy link
Contributor

Would be good with a test as well :)

src/Quaternions.jl Outdated Show resolved Hide resolved
src/Quaternions.jl Outdated Show resolved Hide resolved
src/Quaternion.jl Outdated Show resolved Hide resolved
src/Quaternion.jl Outdated Show resolved Hide resolved
@KristofferC
Copy link
Contributor

It would be good with a test to see that the functionality is working properly and doesn't regress in the future.

@sw2030
Copy link
Author

sw2030 commented Apr 18, 2021

Added testing, fixed spacing and import issues!

@KristofferC
Copy link
Contributor

Thanks, it looks like we need to update the CI infrastructure here from Travis to Github Actions. I will do that and then CI should run on this PR.

@KristofferC KristofferC reopened this Apr 19, 2021
@hyrodium
Copy link
Collaborator

Is this PR forgotten? I think this seems ready to merge.

Copy link
Collaborator

@sethaxen sethaxen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A few suggestions.

Comment on lines 299 to 304
a = map(t->t.s, A)
b = map(t->t.v1, A)
c = map(t->t.v2, A)
d = map(t->t.v3, A)

return [a+im*b c+im*d;-c+im*d a-im*b]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently this allocates a lot of intermediate arrays. What about something like this to allocate just 1?

Suggested change
a = map(t->t.s, A)
b = map(t->t.v1, A)
c = map(t->t.v2, A)
d = map(t->t.v3, A)
return [a+im*b c+im*d;-c+im*d a-im*b]
n = size(A, 1)
Ac = Matrix{Complex{T}}(undef, 2n, 2n)
Ac[1:n, 1:n] .= complex.(getfield.(A, :s), getfield.(A, :v1))
Ac[1:n, n+1:2n] .= complex.(getfield.(A, :v2), getfield.(A, :v3))
Ac[n+1:2n, 1:n] .= .- conj.(view(Ac, 1:n, n+1:2n))
Ac[n+1:2n, n+1:2n] .= conj.(view(Ac, 1:n, 1:n))
return Ac

test/test_Quaternion.jl Outdated Show resolved Hide resolved
id = Matrix{Quaternion{Float64}}(I, 3, 3)
d = [Quaternion(randn(4)...) for i in 1:3]
expd = exp.(d)
D = exp(Array(Diagonal(d)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you include a test for a dense matrix also? Perhaps you could check it using evalpoly.

sw2030 and others added 2 commits May 29, 2023 13:50
Co-authored-by: Seth Axen <seth@sethaxen.com>
Co-authored-by: Seth Axen <seth@sethaxen.com>
@codecov
Copy link

codecov bot commented May 29, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@01d45b4). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head 6847866 differs from pull request most recent head 96efc53. Consider uploading reports for the commit 96efc53 to get more accurate results

@@           Coverage Diff           @@
##             main      #46   +/-   ##
=======================================
  Coverage        ?   41.52%           
=======================================
  Files           ?        3           
  Lines           ?      354           
  Branches        ?        0           
=======================================
  Hits            ?      147           
  Misses          ?      207           
  Partials        ?        0           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mikmoore
Copy link
Contributor

While there could be reasons for a specialized implementation like this (e.g., it looks like this could take advantage of existing complex matrix exponentiation, which is reasonably performant), it appears this PR adds support exclusively for Matrix with Quaternion elements. It would not enable support for other matrix types (e.g., Hermitian, StaticArrays.SMatrix), so would still leave a lot of holes in the functionality.

This issue could be addressed more generically by instead (or additionally) addressing JuliaLang #51008.

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

Successfully merging this pull request may close these issues.

None yet

5 participants