Skip to content

Commit 55848ab

Browse files
committed
upgraded to AbstractTensors v0.6
1 parent c8d413c commit 55848ab

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DirectSum"
22
uuid = "22fd7b30-a8c0-5bf2-aabe-97783860d07c"
33
authors = ["Michael Reed"]
4-
version = "0.7.2"
4+
version = "0.7.3"
55

66
[deps]
77
ComputedFieldTypes = "459fdd68-db75-56b8-8c15-d717a790f88e"
@@ -13,7 +13,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1313
[compat]
1414
julia = "1"
1515
Leibniz = "0.1"
16-
AbstractTensors = "0.5.2"
16+
AbstractTensors = "0.6"
1717
ComputedFieldTypes = "0.1"
1818

1919
[extras]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Sponsor this at [liberapay](https://liberapay.com/chakravala), [GitHub Sponsors]
2323

2424
## DirectSum yields `TensorBundle` parametric type polymorphism ⨁
2525

26-
Let `n` be the rank of a `Manifold{n}`.
26+
Let `n` be the rank of a `Manifold`.
2727
The type `TensorBundle{n,ℙ,g,ν,μ}` uses *byte-encoded* data available at pre-compilation, where
2828
`` specifies the basis for up and down projection,
2929
`g` is a bilinear form that specifies the metric of the space,

src/DirectSum.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module DirectSum
33
# This file is part of DirectSum.jl. It is licensed under the AGPL license
44
# Grassmann Copyright (C) 2019 Michael Reed
55

6-
export TensorBundle, Signature, DiagonalForm, Manifold, SubManifold, ℝ,
6+
export TensorBundle, Signature, DiagonalForm, Manifold, SubManifold, ℝ, , mdims
77
import Base: getindex, convert, @pure, +, *, , , , , ==
88
import LinearAlgebra, AbstractTensors
99
import LinearAlgebra: det, rank
@@ -45,6 +45,8 @@ and `μ` is an integer specifying the order of the tangent bundle (i.e. multipli
4545
Lastly, `ν` is the number of tangent variables.
4646
"""
4747
abstract type TensorBundle{n,Options,Metrics,Vars,Diff,Name} <: Manifold{n} end
48+
rank(::TensorBundle{n}) where n = n
49+
mdims(M::TensorBundle) = rank(M)
4850

4951
@pure doc2m(d,o,c=0,C=0) = (1<<(d-1))|(1<<(2*o-1))|(c<0 ? 8 : (1<<(3*c-1)))|(1<<(5*C-1))
5052

@@ -192,8 +194,8 @@ struct SubManifold{V,n,Indices} <: TensorTerm{V,n}
192194
end
193195

194196
@pure SubManifold(V::Int) where N = SubManifold{V,V}()
195-
@pure SubManifold(V::M) where M<:Manifold{N} where N = SubManifold{V,N}()
196-
@pure SubManifold{M}() where M<:Manifold{N} where N = SubManifold{V,N}()
197+
@pure SubManifold(V::M) where M<:Manifold = SubManifold{V,rank(V)}()
198+
#@pure SubManifold{M}() where M = SubManifold{M isa Int ? SubManifold(M) : M,rank(M)}()
197199
@pure SubManifold{V,N}() where {V,N} = SubManifold{V,N}(UInt(1)<<N-1)
198200
@pure SubManifold{M,N}(b::UInt) where {M,N} = SubManifold{M,N,b}()
199201
SubManifold{M,N}(b::Values{N}) where {M,N} = SubManifold{M,N}(bit2int(indexbits(mdims(M),b)))
@@ -203,6 +205,9 @@ SubManifold{M}(b::Tuple) where M = SubManifold{M,length(b)}(Values(b...))
203205
SubManifold{M}(b::Values) where M = SubManifold{M,length(b)}(b)
204206
SubManifold{M}(b...) where M = SubManifold{M}(b)
205207

208+
@pure issubmanifold(V::SubManifold) = true
209+
@pure issubmanifold(V) = false
210+
206211
for t ((:V,),(:V,:G))
207212
@eval begin
208213
function SubManifold{$(t...)}(b::VTI) where {$(t...)}

src/basis.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424
#@pure labels(V::T) where T<:Manifold = labels(V,pre[1],pre[2],pre[3],pre[4])
2525

2626
generate(V::Int) = generate(SubManifold(V),V)
27-
generate(V::Manifold{N}) where N = generate(V,N)
27+
generate(V::Manifold) = generate(V,rank(V))
2828
function generate(V,N)
2929
exp = SubManifold{V}[SubManifold{V,0}(g_zero(UInt))]
3030
for i 1:N
@@ -44,18 +44,17 @@ export @basis, @basis_str, @dualbasis, @dualbasis_str, @mixedbasis, @mixedbasis_
4444
Generates `Basis` declaration having `Manifold` specified by `V`.
4545
The first argument provides pseudoscalar specifications, the second argument is the variable name for the `Manifold`, and the third and fourth argument are variable prefixes of the `SubManifold` vector names (and covector basis names).
4646
"""
47-
function basis(V,sig=vsn[1],vec=pre[1],cov=pre[2],duo=pre[3],dif=pre[4])
47+
function alloc(V,sig=vsn[1],vec=pre[1],cov=pre[2],duo=pre[3],dif=pre[4])
4848
N = mdims(V)
4949
if N > algebra_limit
50-
Λ(V) # fill cache
50+
G = Λ(V) # fill cache
5151
basis = generate(V)
5252
sym = labels(V,string.([vec,cov,duo,dif])...)
5353
else
5454
basis = Λ(V).b
5555
sym = labels(V,string.([vec,cov,duo,dif])...)
5656
end
57-
T = typeof(V)
58-
@inbounds exp = Expr[Expr(:(=),esc(sig),T<:SubManifold ? V : SubManifold(V)),
57+
@inbounds exp = Expr[Expr(:(=),esc(sig),convert(SubManifold,V)),
5958
Expr(:(=),esc(Symbol(vec)),basis[1])]
6059
for i 2:1<<N
6160
@inbounds push!(exp,Expr(:(=),esc(Symbol("$(basis[i])")),basis[i]))
@@ -64,6 +63,7 @@ function basis(V,sig=vsn[1],vec=pre[1],cov=pre[2],duo=pre[3],dif=pre[4])
6463
push!(exp,Expr(:(=),esc(Symbol(vec,'')) ,esc(vec)))
6564
return Expr(:block,exp...,Expr(:tuple,esc(sig),esc.(sym)...))
6665
end
66+
alloc(V::TensorBundle,args...) = alloc(SubManifold(V),args...)
6767

6868
"""
6969
@basis
@@ -76,11 +76,11 @@ Default for `@basis M` is `@basis M V v w ∂ ϵ`.
7676
macro basis(q,sig=vsn[1],vec=pre[1],cov=pre[2],duo=pre[3],dif=pre[4])
7777
T = typeof(q)
7878
V = T(Symbol,Expr) ? (@eval(__module__,$q)) : T<:Int ? q : Manifold(q)
79-
basis(V,sig,string.([vec,cov,duo,dif])...)
79+
alloc(V,sig,string.([vec,cov,duo,dif])...)
8080
end
8181

8282
macro basis_str(str)
83-
basis(Manifold(str))
83+
alloc(Manifold(str))
8484
end
8585

8686
"""
@@ -92,11 +92,11 @@ The first argument provides pseudoscalar specifications, the second argument is
9292
Default for `@dualbasis M` is `@dualbasis M VV w ϵ`.
9393
"""
9494
macro dualbasis(q,sig=vsn[2],cov=pre[2],dif=pre[4])
95-
basis((typeof(q)(Symbol,Expr) ? (@eval(__module__,$q)) : Manifold(q))',sig,string.([pre[1],cov,pre[3],dif])...)
95+
alloc((typeof(q)(Symbol,Expr) ? (@eval(__module__,$q)) : Manifold(q))',sig,string.([pre[1],cov,pre[3],dif])...)
9696
end
9797

9898
macro dualbasis_str(str)
99-
basis(Manifold(str)',vsn[2])
99+
alloc(Manifold(str)',vsn[2])
100100
end
101101

102102
"""
@@ -109,14 +109,14 @@ Default for `@mixedbasis M` is `@mixedbasis M V v w ∂ ϵ`.
109109
"""
110110
macro mixedbasis(q,sig=vsn[3],vec=pre[1],cov=pre[2],duo=pre[3],dif=pre[4])
111111
V = typeof(q)(Symbol,Expr) ? (@eval(__module__,$q)) : Manifold(q)
112-
bases = basis(VV',sig,string.([vec,cov,duo,dif])...)
113-
Expr(:block,bases,basis(V',vsn[2]),basis(V),bases.args[end])
112+
bases = alloc(VV',sig,string.([vec,cov,duo,dif])...)
113+
Expr(:block,bases,alloc(V',vsn[2]),alloc(V),bases.args[end])
114114
end
115115

116116
macro mixedbasis_str(str)
117117
V = Manifold(str)
118-
bases = basis(VV',vsn[3])
119-
Expr(:block,bases,basis(V',vsn[2]),basis(V),bases.args[end])
118+
bases = alloc(VV',vsn[3])
119+
Expr(:block,bases,alloc(V',vsn[2]),alloc(V),bases.args[end])
120120
end
121121

122122
@inline function lookup_basis(V,v::Symbol)::Union{Simplex,SubManifold}
@@ -144,7 +144,7 @@ Base.length(a::T) where T<:SubAlgebra{V} where V = 1<<mdims(V)
144144
## Algebra{N}
145145

146146
@computed struct Basis{V} <: SubAlgebra{V}
147-
b::Values{1<<(typeof(V)<:Int ? V : mdims(V)),SubManifold{V}}
147+
b::Values{1<<mdims(V),SubManifold{V}}
148148
g::Dict{Symbol,Int}
149149
end
150150

src/generic.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ export valuetype, value, hasinf, hasorigin, isorigin, norm, indices, tangent, is
1515
(M::DiagonalForm)(b::T) where T<:AbstractRange{Int} = SubManifold{M}(b)
1616
(M::SubManifold)(b::T) where T<:AbstractRange{Int} = SubManifold{supermanifold(M)}(b)
1717

18-
@pure Base.ndims(S::SubManifold{M,G}) where {G,M} = isbasis(S) ? mdims(M) : G
18+
@pure _polymode(M::Int) = iszero(M&16)
19+
@pure _dyadmode(M::Int) = M%16 8:11 ? -1 : Int(M%16 (4,5,6,7))
20+
@pure _hasinf(M::Int) = M%16 (1,3,5,7,9,11)
21+
@pure _hasorigin(M::Int) = M%16 (2,3,6,7,10,11)
22+
23+
#@pure Base.ndims(S::SubManifold{M,G}) where {G,M} = isbasis(S) ? mdims(M) : G
1924
@pure AbstractTensors.mdims(S::SubManifold{M,G}) where {G,M} = isbasis(S) ? mdims(M) : G
2025
@pure order(m::SubManifold{V,G,B} where G) where {V,B} = count_ones(symmetricmask(V,B,B)[4])
2126
@pure order(m::Simplex) = order(basis(m))+order(value(m))
2227
@pure options(::T) where T<:TensorBundle{N,M} where N where M = M
2328
@pure options_list(V::M) where M<:Manifold = hasinf(V),hasorigin(V),dyadmode(V),polymode(V)
2429
@pure metric(::T) where T<:TensorBundle{N,M,S} where {N,M} where S = S
2530
@pure metric(V::Signature,b::UInt) = isodd(count_ones(metric(V)&b)) ? -1 : 1
26-
@pure _polymode(M::Int) = iszero(M&16)
2731
@pure polymode(::T) where T<:TensorBundle{N,M} where N where M = _polymode(M)
28-
@pure _dyadmode(M::Int) = M%16 8:11 ? -1 : Int(M%16 (4,5,6,7))
2932
@pure dyadmode(::T) where T<:TensorBundle{N,M} where N where M = _dyadmode(M)
3033
@pure diffmode(::T) where T<:TensorBundle{N,M,S,F,D} where {N,M,S,F} where D = D
3134
@pure diffvars(::T) where T<:TensorBundle{N,M,S,F} where {N,M,S} where F = F
@@ -53,6 +56,7 @@ for T ∈ (:T,:(Type{T}))
5356
@pure basis(m::$T) where T<:SubManifold = isbasis(m) ? m : SubManifold(m)
5457
@pure basis(m::$T) where T<:Simplex{V,G,B} where {V,G} where B = B
5558
@pure UInt(b::$T) where T<:SubManifold{V,G,B} where {V,G} where B = B::UInt
59+
@pure UInt(b::$T) where T<:Simplex = UInt(basis(b))
5660
end
5761
end
5862
@pure det(s::Signature) = isodd(count_ones(metric(s))) ? -1 : 1
@@ -76,11 +80,9 @@ for T ∈ (Expr,Symbol)
7680
@eval @inline Base.iszero(t::Simplex{V,G,B,$T} where {V,G,B}) = false
7781
end
7882

79-
@pure _hasinf(M::Int) = M%16 (1,3,5,7,9,11)
8083
@pure hasinf(::T) where T<:TensorBundle{N,M} where N where M = _hasinf(M)
8184
@pure hasinf(::SubManifold{M,N,S} where N) where {M,S} = hasinf(M) && isodd(S)
8285
@pure hasinf(t::Simplex) = hasinf(basis(t))
83-
@pure _hasorigin(M::Int) = M%16 (2,3,6,7,10,11)
8486
@pure hasorigin(::T) where T<:TensorBundle{N,M} where N where M = _hasorigin(M)
8587
@pure hasorigin(V::SubManifold{M,N,S} where N) where {M,S} = hasorigin(M) && (hasinf(M) ? (d=UInt(2);(d&S)==d) : isodd(S))
8688
@pure hasorigin(t::Simplex) = hasorigin(basis(t))
@@ -100,13 +102,14 @@ for M ∈ (:Signature,:DiagonalForm)
100102
@eval @pure loworder(V::$M{N,M,S,D,O}) where {N,M,S,D,O} = O0 ? $M{N,M,S,D,O-1}() : V
101103
end
102104
@pure loworder(::SubManifold{M,N,S}) where {N,M,S} = SubManifold{loworder(M),N,S}()
105+
@pure loworder(::Type{T}) where T = loworder(T())
103106

104107
# dual involution
105108

106109
@pure flip_sig(N,S::UInt) = UInt(2^N-1) & (~S)
107110

108111
@pure dual(V::T) where T<:Manifold = isdyadic(V) ? V : V'
109-
@pure dual(V::T,B,M=Int(N/2)) where T<:Manifold{N} where N = ((B<<M)&((1<<N)-1))|(B>>M)
112+
@pure dual(V::T,B,M=Int(rank(V)/2)) where T<:Manifold = ((B<<M)&((1<<rank(V))-1))|(B>>M)
110113

111114
@pure function Base.adjoint(V::Signature{N,M,S,F,D}) where {N,M,S,F,D}
112115
C = dyadmode(V)

0 commit comments

Comments
 (0)