Use your own types in geometric algebra expressions
Inputs
If the type you use supports indexing, e.g. Vector
, it already works:
using SymbolicGA
x = rand(3)
y = rand(3)
@ga 3 x::1 ∧ y::1
Bivector{Float64, 3, 3}(-0.32032150242621377, -0.16697560921343702, 0.47170920621327017)
If your type does not support indexing, and you don't want it to, overload SymbolicGA.getcomponent(::T, [i::Int, [j::Int]])
:
struct MyInputType{T}
values::Vector{T}
end
SymbolicGA.getcomponent(x::MyInputType, i::Int) = x.values[i]
x = MyInputType(rand(3))
y = MyInputType(rand(3))
@ga 3 x::1 ∧ y::1
Bivector{Float64, 3, 3}(-0.006088474241441551, -0.20058559394929987, -0.41256072571757046)
For scalars and aggregates of objects with multiple grades, you will need to overload SymbolicGA.getcomponent(::T)
and SymbolicGA.getcomponent(::T, j::Int, i::Int)
respectively (see SymbolicGA.getcomponent
).
Outputs
If you want to reconstruct a custom type from components, either define a constructor for a single tuple argument, e.g. T(components::Tuple)
struct MyOutputType{T}
values::Vector{T}
end
MyOutputType(x::Tuple) = MyOutputType(collect(x))
x = rand(3)
y = rand(3)
@ga 3 MyOutputType dual(x::1 ∧ y::1)
Main.MyOutputType{Float64}([-0.2668289755855516, 0.23522626580119096, -0.048776219433212364])
If you don't want such constructor to be defined, you can overload SymbolicGA.construct(::Type{T}, ::Tuple)
directly:
struct MyOutputType2{T}
values::Vector{T}
end
SymbolicGA.construct(T::Type{<:MyOutputType2}, x::Tuple) = MyOutputType2(collect(x))
x = rand(3)
y = rand(3)
@ga 3 MyOutputType2 dual(x::1 ∧ y::1)
Main.MyOutputType2{Float64}([-0.12824981202889504, -0.08012962530329763, 0.07620125249119059])
Integrations for Vector
, Tuple
and <:Real
have already been defined:
@ga 3 Tuple dual(x::1 ∧ y::1)
(-0.12824981202889504, -0.08012962530329763, 0.07620125249119059)
@ga 3 Vector dual(x::1 ∧ y::1)
3-element Vector{Float64}:
-0.12824981202889504
-0.08012962530329763
0.07620125249119059
z = rand(3)
@ga 3 Float16 dual(x::1 ∧ y::1 ∧ z::1)
Float16(-0.0645)
This page was generated using Literate.jl.