JuliaGeometry / Rotations.jl

Julia implementations for different rotation parameterizations
https://juliageometry.github.io/Rotations.jl
MIT License
176 stars 44 forks source link

Use internal inverse function instead of Base.inv #274

Closed juliohm closed 10 months ago

juliohm commented 10 months ago

Apparently Base.inv is only intended for multiplicative inverses:

 inv(x)

  Return the multiplicative inverse of x, such that x*inv(x) or inv(x)*x yields
  one(x) (the multiplicative identity) up to roundoff errors.

  If x is a number, this is essentially the same as one(x)/x, but for some types
  inv(x) may be slightly more efficient.

We recently learned about InverseFunctions.jl, which introduces a inverse function for inverse functions. Rotations.jl could use the same function or add an internal name inverse that is not exported by default.

We are fixing all our packages to avoid the misuse of Base.inv.

hyrodium commented 10 months ago

Base.inv is an inverse operation about the binary operator *, and InverseFunctions.inverse is an inverse operation about the binary operator (\circle).

The current usage in this package inv(::Rotation) is related to *, so we don't have to switch to InverseFunctions.inverse.

julia> using Rotations

julia> r = QuatRotation(2,1,0,0)
3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(0.894427, 0.447214, 0.0, 0.0)):
 1.0  0.0   0.0
 0.0  0.6  -0.8
 0.0  0.8   0.6

julia> r * inv(r)
3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(1.0, 0.0, 0.0, 0.0)):
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0
juliohm commented 10 months ago

It makes sense if we think of rotations as matrix multiplication always. Feel free to close the issue if inv is intended.

Em ter., 7 de nov. de 2023 00:09, Yuto Horikawa @.***> escreveu:

Base.inv is an inverse operation about the binary operator *, and InverseFunctions.inverse is an inverse operation about the binary operator ∘ (\circle).

The current usage in this package inv(::Rotation) is related to *, so we don't have to switch to InverseFunctions.inverse.

julia> using Rotations

julia> r = QuatRotation(2,1,0,0)3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(0.894427, 0.447214, 0.0, 0.0)): 1.0 0.0 0.0 0.0 0.6 -0.8 0.0 0.8 0.6

julia> r * inv(r)3×3 QuatRotation{Float64} with indices SOneTo(3)×SOneTo(3)(QuaternionF64(1.0, 0.0, 0.0, 0.0)): 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0

— Reply to this email directly, view it on GitHub https://github.com/JuliaGeometry/Rotations.jl/issues/274#issuecomment-1797419931, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZQW3KC5EYZG7DRF26DBC3YDGQ6ZAVCNFSM6AAAAAA7AB3RHSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJXGQYTSOJTGE . You are receiving this because you authored the thread.Message ID: @.***>