Skip to content

Commit

Permalink
revised nested type dispatch and CGA contraction
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed May 1, 2020
1 parent b324d1c commit d8c7101
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ Exterior product as defined by the anti-symmetric quotient Λ≡⊗/~
@inline (a::TensorAlgebra{V},b::UniformScaling{T}) where {V,T<:Field} = aV(b)
@inline (a::UniformScaling{T},b::TensorAlgebra{V}) where {V,T<:Field} = V(a)b
@generated (t::T) where T<:SVector = Expr(:call,:,[:(t[$k]) for k 1:length(t)]...)
(t::Chain{V,1,T}) where {V,T<:Chain} = (value(t))
(t::Chain{V,1,<:Chain} where V) = (value(t))
(a::X,b::Y,c::Z...) where {X<:TensorAlgebra,Y<:TensorAlgebra,Z<:TensorAlgebra} = (ab,c...)

export , ,
Expand Down Expand Up @@ -464,7 +464,7 @@ Interior (right) contraction product: ω⋅η = ω∨⋆η

# dyadic products

contraction(a::Chain{W,G,S},b::Chain{V,1,T}) where {W,G,V,S<:Chain,T<:Chain} = Chain{V,1}(a.⋅value(b))
contraction(a::Chain{W,G,<:Chain},b::Chain{V,1,<:Chain}) where {W,G,V} = Chain{V,1}(a.⋅value(b))
Base.:(:)(a::Chain{V,1,T},b::Chain{V,1,T}) where {V,T<:Chain} = sum(value(a).⋅value(b))

## cross product
Expand Down
18 changes: 9 additions & 9 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,23 @@ end=#

export detsimplex, initmesh, refinemesh, refinemesh!, select, submesh

detsimplex(m::Vector{Chain{V,G,T,X}} where {G,T,X}) where V = (m)/factorial(ndims(V)-1)
detsimplex(m::Vector{<:Chain{V}}) where V = (m)/factorial(ndims(V)-1)
detsimplex(m::ChainBundle) = detsimplex(value(m))
mean(m::Vector{Chain{V,G,T,X}} where {V,G,T,X}) = sum(m)/length(m)
mean(m::Vector{<:Chain}) = sum(m)/length(m)
mean(m::T) where T<:SVector = sum(m)/length(m)
barycenter(m::SVector{N,Chain{V,G,T,X}} where {V,G,T,X}) where N = (s=sum(m);s/s[1])
barycenter(m::Vector{Chain{V,G,T,X}} where {V,G,T,X}) = (s=sum(m);s/s[1])
curl(m::SVector{N,Chain{V,G,T,X}} where {N,G,T,X}) where V = curl(Chain{V,1}(m))
barycenter(m::SVector{N,<:Chain}) where N = (s=sum(m);s/s[1])
barycenter(m::Vector{<:Chain}) = (s=sum(m);s/s[1])
curl(m::SVector{N,<:Chain{V}} where N) where V = curl(Chain{V,1}(m))
curl(m::T) where T<:TensorAlgebra = Manifold(m)(∇)×m
LinearAlgebra.det(t::Chain{V,1,T}) where {V,T<:Chain} = (t)
LinearAlgebra.det(V::ChainBundle,m::Vector) = .∧(getindex.(Ref(V),value.(m)))
(m::Vector{Chain{V,G,T,X}} where {G,T,X}) where V = LinearAlgebra.det(V,m)
(m::Vector{<:Chain{V}}) where V = LinearAlgebra.det(V,m)
(m::ChainBundle) = LinearAlgebra.det(Manifold(m),value(m))
for op (:mean,:barycenter,:curl)
ops = Symbol(op,:s)
@eval begin
export $op, $ops
$ops(m::Vector{Chain{p,G,T,X}} where {G,T,X}) where p = $ops(m,p)
$ops(m::Vector{<:Chain{p}}) where p = $ops(m,p)
@pure $ops(m::ChainBundle{p}) where p = $ops(m,p)
@pure $ops(m,::SubManifold{p}) where p = $ops(m,p)
@pure $ops(m,p) = $op.(getindex.(Ref(p),value.(value(m))))
Expand Down Expand Up @@ -429,7 +429,7 @@ if VERSION >= v"1.4"
(T = promote_type(TA, Chain{V,G,𝕂,X}); mul!(similar(B, T, (size(transA, 1), size(B, 2))), transA, B, 1, 0))
end

@generated function StaticArrays._diff(::Size{S}, a::SVector{Q,Chain{V,G,W,X}}, ::Val{D}) where {S,D,Q,V,G,W,X}
@generated function StaticArrays._diff(::Size{S}, a::SVector{Q,<:Chain}, ::Val{D}) where {S,D,Q}
N = length(S)
Snew = ([n==D ? S[n]-1 : S[n] for n = 1:N]...,)

Expand Down Expand Up @@ -458,7 +458,7 @@ Base.rand(::AbstractRNG,::SamplerType{Chain}) = rand(Chain{rand(Manifold)})
Base.rand(::AbstractRNG,::SamplerType{Chain{V}}) where V = rand(Chain{V,rand(0:ndims(V))})
Base.rand(::AbstractRNG,::SamplerType{Chain{V,G}}) where {V,G} = Chain{V,G}(DirectSum.orand(svec(ndims(V),G,Float64)))
Base.rand(::AbstractRNG,::SamplerType{Chain{V,G,T}}) where {V,G,T} = Chain{V,G}(rand(svec(ndims(V),G,T)))
Base.rand(::AbstractRNG,::SamplerType{Chain{V,G,T} where G}) where {V,T} = rand(Chain{V,rand(0:ndims(V)),Float64})
Base.rand(::AbstractRNG,::SamplerType{Chain{V,G,T} where G}) where {V,T} = rand(Chain{V,rand(0:ndims(V)),T})
Base.rand(::AbstractRNG,::SamplerType{MultiVector}) = rand(MultiVector{rand(Manifold)})
Base.rand(::AbstractRNG,::SamplerType{MultiVector{V}}) where V = MultiVector{V}(DirectSum.orand(svec(ndims(V),Float64)))
Base.rand(::AbstractRNG,::SamplerType{MultiVector{V,T}}) where {V,T} = MultiVector{V}(rand(svec(ndims(V),T)))
11 changes: 7 additions & 4 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function paritycomplementinverse(N,G)#,S)
parityreverse(N-G)parityreverse(G)isodd(binomial(N,2))#⊻isodd(count_ones(S))
end

function cga(V,A,B)
(hasinforigin(V,A,B) || hasorigininf(V,A,B)) && iszero(getbasis(V,A)∨⋆(getbasis(V,B)))
end

@pure function parityregressive(V::Signature{N,M,S},a,b,::Val{skew}=Val{false}()) where {N,M,S,skew}
D = diffvars(V)
A,B,Q,Z = symmetricmask(V,a,b)
Expand All @@ -57,8 +61,7 @@ end
false, A+B0 ? bas : g_zero(UInt)
end
par = parityright(S,A,N)parityright(S,B,N)parityright(S,C,N)
invert = paritycomplementinverse(N-D,count_ones(C))#,UInt(0))
return (invertparparity(N,S,α,β)pcc)::Bool, bas|Q, true, Z
return (isodd(L*(L-grade(V)))parparity(N,S,α,β)pcc)::Bool, bas|Q, true, Z
else
return false, g_zero(UInt), false, Z
end
Expand All @@ -78,13 +81,13 @@ end=#

@pure function parityinterior(V::M,a,b) where M<:Manifold{N} where N
A,B,Q,Z = symmetricmask(V,a,b)
diffcheck(V,A,B) && (return false,g_zero(UInt),false,Z)
(diffcheck(V,A,B) || cga(V,A,B)) && (return false,g_zero(UInt),false,Z)
p,C,t = parityregressive(Signature(V),A,complement(N,B,diffvars(V)),Val{true}())
ind = indices(B,N); g = prod(V[ind])
return t ? (pparityright(0,sum(ind),count_ones(B)) ? -(g) : g) : g, C|Q, t, Z
end

@pure function parityinner(V::M,a::Bits,b::Bits) where M<:Manifold
@pure function parityinner(V::M,a::UInt,b::UInt) where M<:Manifold
A,B = symmetricmask(V,a,b)
g = abs(prod(V[indices(A&B,ndims(V))]))
parity(Signature(V),A,B) ? -(g) : g
Expand Down
6 changes: 1 addition & 5 deletions src/products.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
end
return if μ
if !istangent(V)
insert_t(:(MultiVector{$V}($(Expr(:call,tvec(N,:t),out...)))))
else
insert_t(:(MultiVector{$V}($(Expr(:call,tvec(N),out...)))))
end
insert_t(:(MultiVector{$V}($(Expr(:call,istangent(V) ? tvec(N) : tvec(N,:t),out...)))))
else
insert_t(:(value_diff(Chain{$V,G-L}($(Expr(:call,tvec(N,G-L,:t),out...))))))
end
Expand Down

0 comments on commit d8c7101

Please sign in to comment.