Skip to content

Commit

Permalink
improved interoperability for non-metric algebras
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Aug 27, 2020
1 parent c9e92a2 commit 85c3843
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
julia: 1.5
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.add("Documenter"); Pkg.add("DirectSum"); Pkg.add("AbstractTensors"); Pkg.add("Leibniz"); Pkg.add("Adapode"); Pkg.add("StaticArrays"); Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=docs/ -e 'using Pkg; Pkg.add("Documenter"); Pkg.add("DirectSum"); Pkg.add("AbstractTensors"); Pkg.add("Leibniz"); Pkg.add("StaticArrays"); Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=docs/ docs/make.jl
after_success: skip
notifications:
Expand Down
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file is part of Grassmann.jl. It is licensed under the GPL license
# Grassmann Copyright (C) 2019 Michael Reed

using Documenter, AbstractTensors, DirectSum, Leibniz, Grassmann, Adapode, StaticArrays
using Documenter, AbstractTensors, DirectSum, Leibniz, Grassmann, StaticArrays

makedocs(
# options
modules = [AbstractTensors,DirectSum,Leibniz,Grassmann,Adapode],
modules = [AbstractTensors,DirectSum,Leibniz,Grassmann],#Adapode],
doctest = false,
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
sitename = "Grassmann.jl",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Pages = ["library.md"]
```

```@autodocs
Modules = [AbstractTensors, DirectSum, Grassmann, Leibniz, Adapode]
Modules = [AbstractTensors, DirectSum, Grassmann, Leibniz]
```
6 changes: 4 additions & 2 deletions src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import AbstractTensors: vector, isvector, bivector, isbivector, volume, isvolume
import Leibniz: algebra_limit, sparse_limit, cache_limit, fill_limit
import Leibniz: binomial, binomial_set, binomsum, binomsum_set, lowerbits, expandbits
import Leibniz: bladeindex, basisindex, indexbasis, indexbasis_set, loworder, intlog
import Leibniz: promote_type, mvec, svec, intlog, insert_expr
import Leibniz: promote_type, mvec, svec, intlog, insert_expr, supermanifold

include("multivectors.jl")
include("parity.jl")
Expand Down Expand Up @@ -233,7 +233,7 @@ end
initpoints(P::T) where T<:AbstractVector = Chain{ℝ2,1}.(1.0,P)
initpoints(P::T) where T<:AbstractRange = Chain{ℝ2,1}.(1.0,P)
@generated function initpoints(P,::Val{n}=Val(size(P,1))) where n
Expr(:.,:(Chain{$(SubManifold(^(n+1))),1}),
Expr(:.,:(Chain{$(SubManifold(n+1)),1}),
Expr(:tuple,1.0,[:(P[$k,:]) for k 1:n]...))
end

Expand Down Expand Up @@ -515,6 +515,8 @@ function __init__()
Chain{V,1,Chain{W,1}}(m::StaticArrays.SMatrix{M,N}) where {V,W,M,N} = Chain{V,1}(Chain{W,1}.(getindex.(Ref(m),:,StaticArrays.SVector{N}(1:N))))
end
@require GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" begin
GeometryBasics.Point(t::Values) = GeometryBasics.Point(Tuple(t.v))
GeometryBasics.Point(t::Variables) = GeometryBasics.Point(Tuple(t.v))
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:TensorTerm{V} where V = GeometryBasics.Point(value(Chain{V,valuetype(t)}(vector(t))))
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:TensorTerm{V,0} where V = GeometryBasics.Point(zeros(valuetype(t),ndims(V))...)
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:TensorAlgebra = GeometryBasics.Point(value(vector(t)))
Expand Down
14 changes: 7 additions & 7 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function Cramer(N::Int,j=0)
end

@generated function Base.:\(t::SVector{M,<:Chain{V,1}},v::Chain{V,1}) where {M,V}
W = Mmdims(V) ? M : V; N = M-1
W = Mmdims(V) ? SubManifold(M) : V; N = M-1
if M == 1 && (V === ℝ1 || V == 1)
return :(Chain{V,1}(Values(v[1]/t[1][1])))
elseif M == 2 && (V === ℝ2 || V == 2)
Expand Down Expand Up @@ -393,7 +393,7 @@ end
end

@generated function Base.inv(t::Values{M,<:Chain{V,1}}) where {M,V}
W = Mmdims(V) ? SubManifold(Manifold(M)) : V; N = M-1
W = Mmdims(V) ? SubManifold(M) : V; N = M-1
N<1 && (return :(_transpose(Values(inv(t[1])),$W)))
M > mdims(V) && (return :(tt = _transpose(t,$W); ttinv(Chain{$W,1}(t)tt)))
x,y,xy = Grassmann.Cramer(N)
Expand All @@ -413,7 +413,7 @@ end
end

@generated function grad(T::SVector{M,<:Chain{V,1}}) where {M,V}
W = Mmdims(V) ? SubManifold(Manifold(M)) : V; N = mdims(V)-1
W = Mmdims(V) ? SubManifold(M) : V; N = mdims(V)-1
M < mdims(V) && (return :(ct = Chain{$W,1}(T); map((V),ctinv(_transpose(T,$W)ct))))
x,y,xy = Grassmann.Cramer(N)
val = if iseven(N)
Expand All @@ -432,7 +432,7 @@ end
end

@generated function Base.:\(t::SVector{N,<:Chain{M,1}},v::Chain{V,1}) where {N,M,V}
W = Mmdims(V) ? SubManifold(Manifold(N)) : V
W = Mmdims(V) ? SubManifold(N) : V
if mdims(M) > mdims(V)
:(ct=Chain{$W,1}(t); ct(inv(_transpose(t,$W)ct)v))
else # mdims(M) < mdims(V) ? inv(tt⋅t)⋅(tt⋅v) : tt⋅(inv(t⋅tt)⋅v)
Expand Down Expand Up @@ -468,8 +468,8 @@ end
vandermonde(x,y,V) = (length(x)mdims(V) ? _vandermonde(x,V) : vandermonde(x,V))\y
vandermonde(x,V) = transpose(_vandermonde(x,V))
_vandermonde(x::Chain,V) = _vandermonde(value(x),V)
@generated _vandermonde(x::SVector{N},V) where N = :(Chain{$(SubManifold(Manifold(N))),1}(polynom.(x,$(Val(mdims(V))))))
@generated polynom(x,::Val{N}) where N = Expr(:call,:(Chain{$(SubManifold(Manifold(N))),1}),Expr(:call,:SVector,[:(x^$i) for i 0:N-1]...))
@generated _vandermonde(x::SVector{N},V) where N = :(Chain{$(SubManifold(N)),1}(polynom.(x,$(Val(mdims(V))))))
@generated polynom(x,::Val{N}) where N = Expr(:call,:(Chain{$(SubManifold(N)),1}),Expr(:call,:SVector,[:(x^$i) for i 0:N-1]...))

function vandermondeinterp(x,y,V,grid) # grid=384
coef = vandermonde(x,y,V) # Vandermonde ((inv(X'*X))*X')*y
Expand Down Expand Up @@ -537,7 +537,7 @@ volumes(m,dets) = value.(abs.(.⋆(dets)))
volumes(m) = mdims(Manifold(m))2 ? volumes(m,detsimplex(m)) : edgelength.(value(m))
detsimplex(m::Vector{<:Chain{V}}) where V = (m)/factorial(mdims(V)-1)
detsimplex(m::ChainBundle) = detsimplex(value(m))
mean(m::Vector{<:Chain}) = sum(m)/length(m)
mean(m::T) where T<:AbstractVector{<:Chain} = sum(m)/length(m)
mean(m::T) where T<:SVector = sum(m)/length(m)
mean(m::Chain{V,1,<:Chain} where V) = mean(value(m))
barycenter(m::SVector{N,<:Chain}) where N = (s=sum(m);s/s[1])
Expand Down
4 changes: 4 additions & 0 deletions src/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
end
return Chain{w,G}(out)
end
elseif V == V''
return :(w(Chain{$(V''),G}(value(b))))
else
:(throw(error("cannot convert from $V to $w")))
end
Expand Down Expand Up @@ -124,6 +126,8 @@ function (W::SubManifold{Q,M,S})(m::MultiVector{V,T}) where {Q,M,V,S,T}
end
end
return MultiVector{W}(out)
elseif V == V''
return W((V'')(m))
else
throw(error("cannot convert from $(V) to $(W)"))
end
Expand Down
17 changes: 9 additions & 8 deletions src/multivectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ end
end

@generated function Chain(args::𝕂...) where 𝕂
V = length(args)
ref = SVector{V}([:(args[$i]) for i 1:V])
:(Chain{$V,1}($(Expr(:call,:(SVector{$V,𝕂}),ref...))))
N = length(args)
V = SubManifold(N)
ref = SVector{N}([:(args[$i]) for i 1:N])
:(Chain{$V,1}($(Expr(:call,:(SVector{$N,𝕂}),ref...))))
end

Chain(v::Chain{V,G,𝕂}) where {V,G,𝕂} = Chain{V,G}(SVector{binomial(mdims(V),G),𝕂}(v.v))
Expand All @@ -55,7 +56,7 @@ export Chain
getindex(m::Chain,i::Int) = m.v[i]
getindex(m::Chain,i::UnitRange{Int}) = m.v[i]
getindex(m::Chain,i::T) where T<:AbstractVector = m.v[i]
getindex(m::Chain{V,G,<:Chain} where {V,G},i::Int,j::Int) = getindex.(m[i],j)
getindex(m::Chain{V,G,<:Chain} where {V,G},i::Int,j::Int) = m[i][j]
setindex!(m::Chain{V,G,T} where {V,G},k::T,i::Int) where T = (m.v[i] = k)
Base.firstindex(m::Chain) = 1
@pure Base.lastindex(m::Chain{V,G}) where {V,G} = binomial(mdims(V),G)
Expand All @@ -66,8 +67,8 @@ Base.zero(::Chain{V,G,T}) where {V,G,T} = Chain{V,G}(zeros(svec(mdims(V),G,T)))
transpose_row(t::SVector{N,<:Chain{V}},i,W=V) where {N,V} = Chain{W,1}(getindex.(t,i))
transpose_row(t::FixedVector{N,<:Chain{V}},i,W=V) where {N,V} = Chain{W,1}(getindex.(t,i))
transpose_row(t::Chain{V,1,<:Chain},i) where V = transpose_row(value(t),i,V)
@generated _transpose(t::Values{N,<:Chain{V,1}},W=V) where {N,V} = :(Chain{V,1}(transpose_row.(Ref(t),$(Values{mdims(V)}(1:mdims(V))),Ref(W))))
@generated _transpose(t::FixedVector{N,<:Chain{V,1}},W=V) where {N,V} = :(Chain{V,1}(transpose_row.(Ref(t),$(Values{mdims(V)}(1:mdims(V))),Ref(W))))
@generated _transpose(t::Values{N,<:Chain{V,1}},W=V) where {N,V} = :(Chain{V,1}(transpose_row.(Ref(t),$(Values{mdims(V)}(1:mdims(V))),W)))
@generated _transpose(t::FixedVector{N,<:Chain{V,1}},W=V) where {N,V} = :(Chain{V,1}(transpose_row.(Ref(t),$(Values{mdims(V)}(1:mdims(V))),W)))
Base.transpose(t::Chain{V,1,<:Chain{V,1}}) where V = _transpose(value(t))
Base.transpose(t::Chain{V,1,<:Chain{W,1}}) where {V,W} = _transpose(value(t),V)

Expand Down Expand Up @@ -175,8 +176,8 @@ end
@pure AbstractTensors.mdims(::Vector{<:Chain{V}}) where V = mdims(V)
@pure Base.parent(::ChainBundle{V}) where V = isbundle(V) ? parent(V) : V
@pure Base.parent(::Vector{<:Chain{V}}) where V = isbundle(V) ? parent(V) : V
#@pure DirectSum.supermanifold(m::ChainBundle{V}) where V = V
#@pure DirectSum.supermanifold(m::Vector{<:Chain{V}}) where V = V
@pure DirectSum.supermanifold(m::ChainBundle{V}) where V = V
@pure DirectSum.supermanifold(m::Vector{<:Chain{V}}) where V = V
@pure points(t::ChainBundle{p}) where p = isbundle(p) ? p : DirectSum.supermanifold(p)
@pure points(t::Vector{<:Chain{p}}) where p = isbundle(p) ? p : DirectSum.supermanifold(p)
@pure points(t::Chain{p}) where p = isbundle(p) ? p : DirectSum.supermanifold(p)
Expand Down

2 comments on commit 85c3843

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

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 85c38436c9ce8d4227d2c298f3f1061bcd224263
git push origin v0.6.0

Please sign in to comment.