Skip to content

Commit

Permalink
revised type parameter dispatch of products
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed May 17, 2019
1 parent e365e32 commit b2899b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ function declare_mutating_operations(M,F,set_val,SUB,MUL)
end
for s (sm,sb)
@eval begin
@inline function $(Symbol(:join,s))(V::VectorSpace{N,D},m::$M,A::Bits,B::Bits,v::S) where {N,D,T<:$F,S<:$F,M}
@inline function $(Symbol(:join,s))(V::W,m::$M,A::Bits,B::Bits,v::S) where W<:VectorSpace{N,D} where {N,D,T<:$F,S<:$F,M}
if v 0 && !dualcheck(V,A,B)
val = (typeof(V)<:Signature || count_ones(A&B)==0) ? (parity(A,B,V) ? $SUB(v) : v) : $MUL(parityinner(A,B,V),v)
$s(m,val,AB,Dimension{N}())
end
return m
end
@inline function $(Symbol(:geom,s))(V::VectorSpace{N,D},m::$M,A::Bits,B::Bits,v::S) where {N,D,T<:$F,S<:$F,M}
@inline function $(Symbol(:geom,s))(V::W,m::$M,A::Bits,B::Bits,v::S) where W<:VectorSpace{N,D} where {N,D,T<:$F,S<:$F,M}
if v 0 && !dualcheck(V,A,B)
pcc,bas,cc = (hasinf(V) && hasorigin(V)) ? conformal(V,A,B) : false,AB,false
val = (typeof(V)<:Signature || count_ones(A&B)==0) ? (parity(A,B,V)pcc ? $SUB(v) : v) : $MUL(parityinner(A,B,V),pcc ? $SUB(v) : v)
Expand All @@ -70,7 +70,7 @@ function declare_mutating_operations(M,F,set_val,SUB,MUL)
end
for (prod,uct) ((:meet,:regressive),(:skew,:interior),(:cross,:crossprod))
@eval begin
@inline function $(Symbol(prod,s))(V::VectorSpace{N,D},m::$M,A::Bits,B::Bits,v::T) where {N,D,T,M}
@inline function $(Symbol(prod,s))(V::W,m::$M,A::Bits,B::Bits,v::T) where W<:VectorSpace{N,D} where {N,D,T,M}
if v 0
g,C,t = $uct(A,B,V)
t && $s(m,typeof(V) <: Signature ? g ? $SUB(v) : v : $MUL(g,v),C,Dimension{N}())
Expand All @@ -86,9 +86,9 @@ function declare_mutating_operations(M,F,set_val,SUB,MUL)
end
end

@inline exteraddmulti!(V::VectorSpace,out,α,β,γ) = (count_ones&β)==0) && joinaddmulti!(V,out,α,β,γ)
@inline exteraddmulti!(V::W,out,α,β,γ) where W<:VectorSpace = (count_ones&β)==0) && joinaddmulti!(V,out,α,β,γ)

@inline outeraddblade!(V::VectorSpace,out,α,β,γ) = (count_ones&β)==0) && joinaddblade!(V,out,α,β,γ)
@inline outeraddblade!(V::W,out,α,β,γ) where W<:VectorSpace = (count_ones&β)==0) && joinaddblade!(V,out,α,β,γ)

@inline function add!(out::MultiVector{T,V},val::T,a::Int,b::Int) where {T,V}
A,B = Bits(a), Bits(b)
Expand Down
15 changes: 6 additions & 9 deletions src/multivectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export TensorTerm, TensorMixed, Basis, MultiVector, MultiGrade
abstract type TensorTerm{V,G} <: TensorAlgebra{V} end
abstract type TensorMixed{T,V} <: TensorAlgebra{V} end

# print tools

import DirectSum: shift_indices, printindices, VTI
# symbolic print types

parany = (Expr,Any)
parsym = (Expr,Symbol)
Expand Down Expand Up @@ -50,14 +48,13 @@ function Base.iterate(r::Basis, i::Int=1)
end

@inline indices(b::Basis{V}) where V = indices(bits(b),ndims(V))
@inline shift_indices(b::Basis{V}) where V = shift_indices(V,indices(b,ndims(V)))

@pure Basis{V}(i::Bits) where V = getbasis(V,i)
Basis{V}(b::BitArray{1}) where V = getbasis(V,bit2int(b))

for t ((:V,),(:V,:G))
@eval begin
function Basis{$(t...)}(b::VTI) where {$(t...)}
function Basis{$(t...)}(b::DirectSum.VTI) where {$(t...)}
Basis{V}(indexbits(ndims(V),b))
end
function Basis{$(t...)}(b::Int...) where {$(t...)}
Expand All @@ -73,7 +70,7 @@ end
==(a::Number,b::TensorTerm{V,G} where V) where G = G==0 ? a==value(b) : 0==a==value(b)
==(a::TensorTerm{V,G} where V,b::Number) where G = G==0 ? value(a)==b : 0==value(a)==b

@inline show(io::IO, e::Basis) = printindices(io,vectorspace(e),bits(e))
@inline show(io::IO, e::Basis) = DirectSum.printindices(io,vectorspace(e),bits(e))

## S/MValue{N}

Expand Down Expand Up @@ -145,14 +142,14 @@ for (Blade,vector,Value) ∈ ((MSB[1],:MVector,MSV[1]),(MSB[2],:SVector,MSV[2]))
else
@inbounds print(io,m.v[1])
end
@inbounds printindices(io,V,ib[1])
@inbounds DirectSum.printindices(io,V,ib[1])
for k 2:length(ib)
if T == Any && typeof(m.v[k]) parsym
@inbounds typeof(m.v[k])parval ? print(io," + ",m.v[k]) : print(io," + (",m.v[k],")")
else
@inbounds print(io,signbit(m.v[k]) ? " - " : " + ",abs(m.v[k]))
end
@inbounds printindices(io,V,ib[k])
@inbounds DirectSum.printindices(io,V,ib[k])
end
end
function ==(a::$Blade{S,V,G} where S,b::T) where T<:TensorTerm{V,G} where {V,G}
Expand Down Expand Up @@ -283,7 +280,7 @@ function show(io::IO, m::MultiVector{T,V}) where {T,V}
else
@inbounds print(io,signbit(m.v[s]) ? " - " : " + ",abs(m.v[s]))
end
@inbounds printindices(io,V,ib[k])
@inbounds DirectSum.printindices(io,V,ib[k])
basis_count = false
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end

@pure conformalmask(V::T) where T<:VectorSpace = UInt(2)^(hasinf(V)+hasorigin(V))-1

@pure function conformalcheck(V,A,B)
@pure function conformalcheck(V::T,A,B) where T<:VectorSpace
bt = conformalmask(V)
i2o,o2i = DirectSum.hasi2o(V,A,B),DirectSum.haso2i(V,A,B)
A&bt, B&bt, i2o, o2i, i2o o2i
Expand Down Expand Up @@ -160,7 +160,7 @@ for par ∈ (:conformal,:regressive,:interior,:crossprod)
@eval begin
const $cache = Vector{Dict{Bits,Vector{Vector{$T}}}}[]
const $extra = Vector{Dict{Bits,Dict{Bits,Dict{Bits,$T}}}}[]
@pure function ($par(a,b,V::$space{n,m,s})::$T) where {n,m,s}
@pure function ($par(a,b,V::W)::$T) where W<:$space{n,m,s} where {n,m,s}
m1 = m+1
if n > sparse_limit
N = n-sparse_limit
Expand Down

2 comments on commit b2899b3

@chakravala
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/845

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.5 -m "<description of version>" b2899b3b048cd4ab68291e15a211210b352b50ce
git push origin v0.1.5

Please sign in to comment.