Skip to content

Commit

Permalink
improved SizedArray and Number dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Oct 5, 2019
1 parent bcde7d6 commit 5a6e9e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
function $op(a::$Blade{V,G,A,S} where A,b::MultiVector{T,V}) where {T<:$Field,V,G,S<:$Field}
$(insert_expr((:N,:t),VEC)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,t))),)))
out = convert($VEC(N,t),$(bcast(bop,:(copy(value(b,$VEC(N,t))),))))
addmulti!(out,value(a,t),bits(basis(a)),Dimension{N}())
return MultiVector{t,V}(out)
end
Expand All @@ -1118,7 +1118,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
$op(a::MultiVector{T,V}) where {T<:$Field,V} = MultiVector{$TF,V}($(bcast(bop,:(value(a),))))
function $op(a::Basis{V,G},b::MultiVector{T,V}) where {T<:$Field,V,G}
$(insert_expr((:N,:t),VEC)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,t))),)))
out = convert($VEC(N,t),$(bcast(bop,:(copy(value(b,$VEC(N,t))),))))
addmulti!(out,value(a,t),bits(basis(a)),Dimension{N}())
return MultiVector{t,V}(out)
end
Expand All @@ -1138,7 +1138,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
$(insert_expr((:N,),VEC)...)
at = terms(a)
t = promote_type(T,valuetype.(at)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,t))),)))
out = convert($VEC(N,t),$(bcast(bop,:(copy(value(b,$VEC(N,t))),))))
for A at
addmulti!(out,value(A,t),bits(A),Dimension{N}())
end
Expand All @@ -1158,7 +1158,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
$(insert_expr((:N,),VEC)...)
at = terms(a)
t = promote_type(T,valuetype.(at)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,t))),)))
out = convert($VEC(N,t),$(bcast(bop,:(copy(value(b,$VEC(N,t))),))))
for A at
TA = typeof(A)
if TA <: TensorTerm
Expand Down Expand Up @@ -1224,7 +1224,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
function $op(a::$Blade{V,G,A,S} where A,b::$Chain{T,V,G}) where {T<:$Field,V,G,S<:$Field}
$(insert_expr((:N,:t),VEC)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,G,t))),)))
out = convert($VEC(N,G,t),$(bcast(bop,:(copy(value(b,$VEC(N,G,t))),))))
addblade!(out,value(a,t),basis(a),Dimension{N}())
return MChain{t,V,G}(out)
end
Expand Down Expand Up @@ -1252,7 +1252,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
function $op(a::Basis{V,G},b::$Chain{T,V,G}) where {T<:$Field,V,G}
$(insert_expr((:N,:t),VEC)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,G,t))),)))
out = convert($VEC(N,G,t),$(bcast(bop,:(copy(value(b,$VEC(N,G,t))),))))
addblade!(out,value(a,t),basis(a),Dimension{N}())
return MChain{t,V,G}(out)
end
Expand All @@ -1264,7 +1264,7 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
function $op(a::Basis{V,L},b::$Chain{T,V,G}) where {T<:$Field,V,G,L}
$(insert_expr((:N,:t,:out,:r,:bng),VEC)...)
@inbounds out[r+1:r+bng] = $(bcast(bop,:(value(b,$VEC(N,G,t)),)))
@inbounds out[r+1:r+bng] = $(bcast(bop,:(copy(value(b,$VEC(N,G,t))),)))
addmulti!(out,value(a,t),bits(basis(a)),Dimension{N}())
return MultiVector{t,V}(out)
end
Expand All @@ -1282,15 +1282,15 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
$(insert_expr((:N,),VEC)...)
at = terms(a)
t = promote_type(T,valuetype.(at)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,G,t))),)))
out = convert($VEC(N,G,t),$(bcast(bop,:(copy(value(b,$VEC(N,G,t))),))))
for A at
addblade!(out,value(A,t),basis(A),Dimension{N}())
end
return MChain{t,V,G}(out)
end
function $op(a::$Chain{T,V,G},b::MultiVector{S,V}) where {T<:$Field,V,G,S}
$(insert_expr((:N,:t,:r,:bng),VEC)...)
out = $(bcast(bop,:(copy(value(b,$VEC(N,t))),)))
out = convert($VEC(N,t),$(bcast(bop,:(copy(value(b,$VEC(N,t))),))))
@inbounds out[r+1:r+bng] += value(a,$VEC(N,G,t))
return MultiVector{t,V}(out)
end
Expand All @@ -1305,6 +1305,23 @@ function generate_products(Field=Field,VEC=:mvec,MUL=:*,ADD=:+,SUB=:-,CONJ=:conj
end
end

@eval begin
*(a::F,b::MultiVector{T,V}) where {F<:Number,T,V} = MultiVector{promote_type(T,F),V}(broadcast($Sym.:∏,a,b.v))
*(a::MultiVector{T,V},b::F) where {F<:Number,T,V} = MultiVector{promote_type(T,F),V}(broadcast($Sym.:∏,a.v,b))
end
for Blade MSB
@eval begin
*(a::F,b::$Blade{V,G,B,T} where B) where {F<:Number,V,G,T} = SBlade{V,G}($Sym.:∏(a,b.v),basis(b))
*(a::$Blade{V,G,B,T} where B,b::F) where {F<:Number,V,G,T} = SBlade{V,G}($Sym.:∏(a.v,b),basis(a))
end
end
for Chain MSC
@eval begin
*(a::F,b::$Chain{T,V,G}) where {F<:Number,T,V,G} = SChain{promote_type(T,F),V,G}(broadcast($Sym.:∏,a,b.v))
*(a::$Chain{T,V,G},b::F) where {F<:Number,T,V,G} = SChain{promote_type(T,F),V,G}(broadcast($Sym.:∏,a.v,b))
end
end

for F Fields
@eval begin
*(a::F,b::MultiVector{T,V}) where {F<:$F,T<:Number,V} = MultiVector{promote_type(T,F),V}(broadcast(*,a,b.v))
Expand Down
2 changes: 1 addition & 1 deletion src/parity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end
@pure function complement(N::Int,B::UInt,D::Int=0,P::Int=0)::UInt
UP,ND = UInt(1)<<P-1, N-D
C = ((~B)&(UP(UInt(1)<<ND-1)))|(B&(UP((UInt(1)<<D-1)<<ND)))
count_ones(C&UP)>1 ? CUP : C
count_ones(C&UP)1 ? CUP : C
end

## product parities
Expand Down

2 comments on commit 5a6e9e5

@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/4124

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.3.1 -m "<description of version>" 5a6e9e5fa7d0c6940ce9b81675d90e92ec8b4690
git push origin v0.3.1

Please sign in to comment.