JuliaManifolds / Manifolds.jl

Manifolds.jl provides a library of manifolds aiming for an easy-to-use and fast implementation.
https://juliamanifolds.github.io/Manifolds.jl
MIT License
368 stars 53 forks source link

Possible allocation issue with complex groups? #668

Closed olivierverdier closed 10 months ago

olivierverdier commented 10 months ago

Consider a complex group, for instance

G = Unitary(2)

Now, the identity element is a matrix of floats (probably normal so far?)

eltype(identity_element(G)) # Float64

The problem is with allocation (I suppose?). First, this works well:

eltype(allocate_result(G, typeof(rand))) # ComplexF64

But this doesn't:

eltype(allocate_result(G, typeof(rand), identity_element(G)) # Float64 <-- wrong type?

And, what I would perhaps like best, this doesn't either:

allocate_result(G, typeof(rand), Identity(G)) # BoundsError

Note: I came across this issue by trying to implement a rand! function for complex groups, for testing purposes, and not by playing around with allocate_result, which, I understand, is for internal use.

mateuszbaran commented 10 months ago

Yes, that's something I need to fix. I will do it when I get a bit of free time.

mateuszbaran commented 10 months ago

I've prepared a PR with a fix: https://github.com/JuliaManifolds/Manifolds.jl/pull/677 . allocate_result(G, typeof(rand), Identity(G)) doesn't work but allocate_result(G, typeof(rand)) does. I can make allocate_result(G, typeof(rand), Identity(G)) also work but it's a bit more work.

olivierverdier commented 10 months ago

Nice! The Identity one is really not important, you can just ignore it.