Skip to content

Commit

Permalink
improved SubManifold and GeometryTypes.Point interoperability for fas…
Browse files Browse the repository at this point in the history
…t performance
  • Loading branch information
chakravala committed Oct 12, 2019
1 parent 0737421 commit 9e7f457
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ function __init__()
end
@require GeometryTypes="4d00f742-c7ba-57c2-abde-4428a4b178cb" begin
Base.convert(::Type{GeometryTypes.Point},t::T) where T<:TensorTerm{V} where V = GeometryTypes.Point(value(SChain{valuetype(t),V}(vector(t))))
Base.convert(::Type{GeometryTypes.Point},t::T) where T<:TensorTerm{V,0} where V = GeometryTypes.Point(zeros(valuetype(t),ndims(V))...)
Base.convert(::Type{GeometryTypes.Point},t::T) where T<:TensorAlgebra{V} where V = GeometryTypes.Point(value(vector(t)))
Base.convert(::Type{GeometryTypes.Point},t::MChain{T,V,G}) where {T,V,G} = G == 1 ? GeometryTypes.Point(value(vector(t))) : GeometryTypes.Point(zeros(T,ndims(V))...)
Base.convert(::Type{GeometryTypes.Point},t::SChain{T,V,G}) where {T,V,G} = G == 1 ? GeometryTypes.Point(value(vector(t))) : GeometryTypes.Point(zeros(T,ndims(V))...)
GeometryTypes.Point(t::T) where T<:TensorAlgebra = convert(GeometryTypes.Point,t)
end
#@require AbstractPlotting="537997a7-5e4e-5d89-9595-2241ea00577e" nothing
Expand Down
4 changes: 0 additions & 4 deletions src/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ function generate_mutators(M,F,set_val,SUB,MUL)
end
end
end
@eval @inline function $sb(out::Q,val::S,i::Int) where Q<:$M where {M,T<:$F,S<:$F}
@inbounds $(set_val(set,:(out[i]),:val))
return out
end
for s (sm,sb)
@eval begin
@inline function $(Symbol(:join,s))(V::W,m::$M,a::Bits,b::Bits,v::S) where W<:Manifold{N} where {N,T<:$F,S<:$F,M}
Expand Down
21 changes: 13 additions & 8 deletions src/multivectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,8 @@ end
throw(error("arbitrary Manifold intersection not yet implemented."))
end
end
@pure function (W::SubManifold{M,V,S})(b::Basis{V}) where {M,V,S}
B,N = bits(b),ndims(V)
iszero(B(B&S)) ? getbasis(W,lowerbits(N,S,B)) : g_zero(W)
@pure function (W::SubManifold{M,V,S})(b::Basis{V,G,B}) where {M,V,S,G,B}
count_ones(B&S)==G ? getbasis(W,lowerbits(ndims(V),S,B)) : g_zero(W)
end

@pure choicevec(M,G,T) = T (Any,BigFloat,BigInt,Complex{BigFloat},Rational{BigInt},Complex{BigInt}) ? svec(M,G,T) : mvec(M,G,T)
Expand Down Expand Up @@ -676,8 +675,10 @@ for Chain ∈ MSC
out,N = zeros(choicevec(M,G,valuetype(b))),ndims(V)
ib = indexbasis(N,G)
for k 1:length(ib)
if b[k] 0
@inbounds setblade!(out,b[k],lowerbits(N,S,ib[k]),Dimension{M}())
@inbounds if b[k] 0
@inbounds if count_ones(ib[k]&S) == G
@inbounds setblade!(out,b[k],lowerbits(N,S,ib[k]),Dimension{M}())
end
end
end
return $Chain{T,W,G}(out)
Expand Down Expand Up @@ -721,11 +722,15 @@ end

function (W::SubManifold{M,V,S})(m::MultiVector{T,V}) where {M,V,S,T}
out,N = zeros(choicevec(M,valuetype(m))),ndims(V)
for i 1:M+1
bs = binomsum_set(N)
for i 1:N+1
ib = indexbasis(N,i-1)
for k 1:length(ib)
@inbounds if m.v[k] 0
@inbounds setmulti!(out,m.v[k],lowerbits(N,S,ib[k]),Dimension{M}())
@inbounds s = k+bs[i]
@inbounds if m.v[s] 0
@inbounds if count_ones(ib[k]&S) == i-1
@inbounds setmulti!(out,m.v[s],lowerbits(N,S,ib[k]),Dimension{M}())
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ const lowerbits_extra = Dict{UInt,Dict{UInt,UInt}}[]
@pure function lowerbits(N,S,B)
if N>cache_limit
n = N-cache_limit
for k length(lowerbits_cache)+1:n
push!(lowerbits_cache,Dict{UInt,Dict{UInt,UInt}}())
for k length(lowerbits_extra)+1:n
push!(lowerbits_extra,Dict{UInt,Dict{UInt,UInt}}())
end
@inbounds !haskey(lowerbits_extra[n],S) && push!(lowerbits_extra[n],S=>Dict{UInt,UInt}())
@inbounds !haskey(lowerbits_extra[n][S],B) && push!(lowerbits_extra[n][S],B=>lowerbits_calc(N,S,B))
Expand Down

3 comments on commit 9e7f457

@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 updated: JuliaRegistries/General/4304

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.2 -m "<description of version>" 9e7f457446fc5b4683874c4827547e8c05b6da68
git push origin v0.3.2

@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.

#31

Please sign in to comment.