Skip to content

Commit

Permalink
refined det syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jan 6, 2025
1 parent ab1a41e commit 708dd6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Grassmann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,12 @@ function __init__()
@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} where V = convert(GeometryBasis.Point,Chain(t))
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:TensorTerm{V,0} where V = GeometryBasics.Point(zeros(valuetype(t),mdims(V))...)
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:TensorAlgebra = GeometryBasics.Point(value(vector(t)))
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:Couple = GeometryBasics.Point(t.v.re,t.v.im)
Base.convert(::Type{GeometryBasics.Point},t::T) where T<:Phasor = GeometryBasics.Point(t.v.re,t.v.im)
Base.convert(::Type{GeometryBasics.Point},t::Chain{V,G,T}) where {V,G,T} = G == 1 ? GeometryBasics.Point(value(vector(t))) : GeometryBasics.Point(zeros(T,mdims(V))...)
Base.convert(::Type{GeometryBasics.Point},t::Chain{V,G,T}) where {V,G,T} = GeometryBasics.Point(value(t))
GeometryBasics.Point(t::T) where T<:TensorAlgebra = convert(GeometryBasics.Point,t)
pointpair(p,V) = Pair(GeometryBasics.Point.(V.(value(p)))...)
@pure ptype(::GeometryBasics.Point{N,T} where N) where T = T
Expand Down
14 changes: 7 additions & 7 deletions src/composite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,10 @@ function Base.findlast(P,t::ChainBundle)
end
Base.findall(P,t) = findall(P .∈ getindex.(points(t),value(t)))

edgelength(e) = (v=points(e)[value(e)]; value(abs(v[2]-v[1])))
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)
edgelength(e) = (v=points(e)[value(e)]; Real(abs(v[2]-v[1])))
volumes(m,dets) = Real.(abs.(dets))
volumes(m) = mdims(Manifold(m))2 ? Real.(abs.(detsimplex(m))) : edgelength.(value(m))
detsimplex(m::Vector{<:Chain{V}}) where V = det(m)/factorial(mdims(V)-1)
detsimplex(m::ChainBundle) = detsimplex(value(m))
mean(m::T) where T<:AbstractVector{<:Chain} = sum(m)/length(m)
mean(m::T) where T<:Values = sum(m)/length(m)
Expand All @@ -923,9 +923,9 @@ barycenter(m::Chain{V,1,<:Chain} where V) = barycenter(value(m))
curl(m::FixedVector{N,<:Chain{V}} where N) where V = curl(Chain{V,1}(m))
curl(m::Values{N,<:Chain{V}} where N) where V = curl(Chain{V,1}(m))
curl(m::T) where T<:TensorAlgebra = Manifold(m)(∇)×m
LinearAlgebra.det(t::Chain{V,1,<:Chain} where V) = (t)
LinearAlgebra.det(m::Vector{<:Chain{V}}) where V = (m)
LinearAlgebra.det(m::ChainBundle) = (m)
LinearAlgebra.det(t::Chain{V,1,<:Chain} where V) = !(t)
LinearAlgebra.det(m::Vector{<:Chain{V}}) where V = .!(m)
LinearAlgebra.det(m::ChainBundle) = .!(m)
(m::ChainBundle) = (value(m))
function (m::Vector{<:Chain{V}}) where V
p = points(m); pm = p[m]
Expand Down
14 changes: 9 additions & 5 deletions src/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,10 @@ Base.zero(t::Type{<:DiagonalOperator{V,T}}) where {V,T} = DiagonalOperator(zero(

scalar(m::DiagonalOperator) = tr(m)/length(value(m))
LinearAlgebra.tr(m::DiagonalOperator) = sum(value(value(m)))
LinearAlgebra.det(m::DiagonalMorphism{V}) where V = Chain{V,mdims(V)}(prod(value(value(m))))
LinearAlgebra.det(m::DiagonalOutermorphism{V}) where V = value(m)(Val(mdims(V)))
LinearAlgebra.det(m::DiagonalMorphism) = !(m)
LinearAlgebra.det(m::DiagonalOutermorphism) = !(m)
(m::DiagonalMorphism{V}) where V = Chain{V,mdims(V)}(prod(value(value(m))))
(m::DiagonalOutermorphism{V}) where V = value(m)(Val(mdims(V)))
compound(m::DiagonalMorphism{V},::Val{0}) where V = DiagonalOperator(Chain{V,0}(1))
@generated function compound(m::DiagonalMorphism{V},::Val{G}) where {V,G}
Expr(:call,:DiagonalOperator,Expr(:call,:(Chain{V,G}),Expr(:call,Values,[Expr(:call,:*,[:(@inbounds m.v[$i]) for i indices(j)]...) for j indexbasis(mdims(V),G)]...)))
Expand Down Expand Up @@ -551,7 +553,8 @@ getindex(t::TensorOperator,i::Int) = value(t.v)[i]
Base.transpose(t::TensorOperator) = TensorOperator(transpose(value(t)))
scalar(m::Endomorphism) = tr(m)/length(value(m))
LinearAlgebra.tr(m::Endomorphism) = tr(value(m))
LinearAlgebra.det(t::TensorOperator) = (value(t))
LinearAlgebra.det(t::TensorOperator) = !(value(t))
(t::TensorOperator) = (value(t))

Base.zero(t::TensorOperator) = TensorOperator(zero(value(t)))
Base.zero(t::Type{<:TensorOperator{V,W,T}}) where {V,W,T} = TensorOperator(zero(T))
Expand Down Expand Up @@ -676,7 +679,8 @@ getindex(t::Outermorphism{V},i::Int) where V = iszero(i) ? Chain{V,0}((Chain(One
Base.transpose(m::Outermorphism) = Outermorphism(map(transpose,value(m)))
scalar(m::Outermorphism{V}) where V = tr(m)/(1<<mdims(V))
LinearAlgebra.tr(m::Outermorphism) = 1+sum(map(tr,value(m)))
LinearAlgebra.det(m::Outermorphism) = (@inbounds value(value(m)[end])[1])
LinearAlgebra.det(m::Outermorphism) = !(m)
(m::Outermorphism) = (@inbounds value(value(m)[end])[1])

Base.zero(t::Outermorphism) = Outermorphism(zero.(value(t)))
@generated function Base.zero(t::Type{<:Outermorphism{V,T}}) where {V,T}
Expand Down Expand Up @@ -1156,7 +1160,7 @@ eigpolys(X::DiagonalOutermorphism) = eigpolys(value(X)(Val(1)))

eigprods(X,G::Int) = eigprods(X,Val(G))
eigprods(X::TensorNested) = eigprods(eigvalsreal(X))
eigprods(X::TensorNested{V},g::Val{G}) where {V,G} = mdims(V)G ? eigprods(eigvalsreal(X),g) : det(X)
eigprods(X::TensorNested{V},g::Val{G}) where {V,G} = mdims(V)G ? eigprods(eigvalsreal(X),g) : (X)
eigprods(X::TensorAlgebra{V},::Val{0}) where V = Chain{V,0}(1)
eigprods(x::Chain{V,1} where V,::Val{1}) = x
@generated function eigprods(x::Chain{V,1},::Val{G}) where {V,G}
Expand Down

2 comments on commit 708dd6b

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.8.28 -m "<description of version>" 708dd6bd880e74ee66d7a311f9e3aff7759f681f
git push origin v0.8.28

Please sign in to comment.