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

Compatibility with Unitful Quantity types #26

Closed
mikeingold opened this issue Oct 15, 2024 · 2 comments · Fixed by #28
Closed

Compatibility with Unitful Quantity types #26

mikeingold opened this issue Oct 15, 2024 · 2 comments · Fixed by #28

Comments

@mikeingold
Copy link

mikeingold commented Oct 15, 2024

Following up from #25, I would love to be able to use this package with Unitful.Quantity types. The following MWE demonstrates a usage that I would like to have work, but that currently doesn't.

using CliffordNumbers: KVector, VGA, 
using LinearAlgebra: norm
using Unitful

a = KVector{1, VGA(3)}(1.0u"m", 0.0u"m", 0.0u"m")
b = KVector{1, VGA(3)}(0.0u"m", 2.0u"m", 0.0u"m")
c = KVector{1, VGA(3)}(0.0u"m", 0.0u"m", 3.0u"m")

norm(a  b  c)
# -> 6.0u"m^3"
@brainandforce
Copy link
Owner

One thing I'll note here is the restriction of the scalars of AbstractCliffordNumber subtypes to Union{Real,Complex}. This is very much intentional: it would be a bad idea to use a Quaternion or an AbstractCliffordNumber as the scalar field when Clifford algebras are restricted to real or complex scalars. Unitful.Quantity does not subtype Real or Complex so it cannot be used as an element type for an AbstractCliffordNumber.

To get around this, you can just wrap a KVector or other AbstractCliffordNumber directly in a Quantity, since any subtype of Number is allowed to be wrapped:

julia> using CliffordNumbers, Unitful

julia> KVector{1,VGA(3)}(1, 2, 3)u"m"
3-element KVector{1, VGA(3), Int64}:
1e₁ + 2e₂ + 3e₃ m

julia> typeof(ans)
Quantity{KVector{1, VGA(3), Int64, 3}, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}

(There is a printing issue here since Base.show(::IO, ::Quantity) calls Base.show(::IO, ::AbstractCliffordNumber), which then calls Base.summary(::IO, ::AbstractCliffordNumber), so the summary for the wrapped type is printed instead of the one for the type itself.)

@brainandforce
Copy link
Owner

I still need to include support for a few other operations, but your use case should be covered by this initial package extension.

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 a pull request may close this issue.

2 participants