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::1Bivector{Float64, 3, 3}(-0.3753518510019566, -0.22658318853678086, 0.12402905735619474)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::1Bivector{Float64, 3, 3}(0.1375440829604353, 0.6085181284164427, 0.5144376206777057)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.08795144376406026, 0.015265442901235493, 0.3377092354499345])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.4301865791358209, -0.05077055488785375, 0.06272737641596948])Integrations for Vector, Tuple and <:Real have already been defined:
@ga 3 Tuple dual(x::1 ∧ y::1)(0.4301865791358209, -0.05077055488785375, 0.06272737641596948)@ga 3 Vector dual(x::1 ∧ y::1)3-element Vector{Float64}:
0.4301865791358209
-0.05077055488785375
0.06272737641596948z = rand(3)
@ga 3 Float16 dual(x::1 ∧ y::1 ∧ z::1)Float16(0.3618)This page was generated using Literate.jl.