Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add matrepelem #243

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/defaultlibrary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ function resethrep!(p::DefaultPolyhedron, h::HRepresentation, redundancy = UNKNO
p.hrep = h
p.hred = redundancy
p.vrep = nothing
p.vred = UNKNOWN_REDUNDANCY
end
function resetvrep!(p::DefaultPolyhedron, v::VRepresentation, redundancy = UNKNOWN_REDUNDANCY)
p.vrep = v
p.vred = redundancy
p.hrep = nothing
p.hred = UNKNOWN_REDUNDANCY
end
64 changes: 48 additions & 16 deletions src/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ end
"""
The representation `rep` does not contain any `elem`.
"""
macro norepelem(rep, elem)
macro norepelem(rep::Symbol, elem::Symbol, typed::Bool = true)
idxs = Symbol(string(elem) * "Indices")
idx = Symbol(string(elem) * "Index")
repT = esc(typed ? :($rep{T}) : rep)
quote
Base.length(idxs::$idxs{T, <:$rep{T}}) where {T} = 0
Base.isempty(idxs::$idxs{T, <:$rep{T}}) where {T} = true
Base.iterate(idxs::$idxs{T, <:$rep{T}}) where {T} = nothing
Base.length(::$idxs{T, <:$repT}) where {T} = 0
Base.isempty(::$idxs{T, <:$repT}) where {T} = true
Base.iterate(::$idxs{T, <:$repT}) where {T} = nothing
end
end

Expand Down Expand Up @@ -138,21 +139,22 @@ _promote_reptype(P1::Type{<:VLinearSpace}, ::Type{<:VRep}) = vreptype(P1)
"""
The representation `rep` contain the elements `elem` inside a vector in the field `field`.
"""
macro vecrepelem(rep, elem, field)
macro vecrepelem(rep, elem, field, typed = true)
idxs = Symbol(string(elem) * "Indices")
idx = Symbol(string(elem) * "Index")
repT = esc(typed ? :($rep{T}) : rep)
esc(quote
Base.length(idxs::$idxs{T, <:$rep{T}}) where {T} = length(idxs.rep.$field)
Base.isempty(idxs::$idxs{T, <:$rep{T}}) where {T} = isempty(idxs.rep.$field)
function Polyhedra.startindex(idxs::$idxs{T, <:$rep{T}}) where {T}
Base.length(idxs::$idxs{T, <:$repT}) where {T} = length(idxs.rep.$field)
Base.isempty(idxs::$idxs{T, <:$repT}) where {T} = isempty(idxs.rep.$field)
function Polyhedra.startindex(idxs::$idxs{T, <:$repT}) where {T}
if isempty(idxs.rep.$field)
return nothing
else
return eltype(idxs)(1)
end
end
Base.get(rep::$rep{T}, idx::$idx{T}) where {T} = rep.$field[idx.value]
function Polyhedra.nextindex(rep::$rep{T}, idx::$idx{T}) where {T}
Base.get(rep::$repT, idx::$idx{T}) where {T} = rep.$field[idx.value]
function Polyhedra.nextindex(rep::$repT, idx::$idx{T}) where {T}
if idx.value >= length(rep.$field)
return nothing
else
Expand All @@ -162,20 +164,50 @@ macro vecrepelem(rep, elem, field)
end)
end

"""
The representation `rep` contain the elements `elem` inside a vector in the field `field`.
"""
macro matrepelem(rep, elem, field, typed = true)
idxs = Symbol(string(elem) * "Indices")
idx = Symbol(string(elem) * "Index")
repT = esc(typed ? :($rep{T}) : rep)
esc(quote
Base.length(idxs::Polyhedra.$idxs{T, <:$repT}) where {T} = size(idxs.rep.$field, 1)
Base.isempty(idxs::Polyhedra.$idxs{T, <:$repT}) where {T} = isempty(idxs.rep.$field)
function Polyhedra.startindex(idxs::Polyhedra.$idxs{T, <:$repT}) where {T}
if isempty(idxs.rep.$field)
return nothing
else
return eltype(idxs)(1)
end
end
function Polyhedra.nextindex(rep::$repT, idx::Polyhedra.$idx{T}) where {T}
if idx.value >= size(rep.$field, 1)
return nothing
else
return typeof(idx)(idx.value + 1)
end
end
end)
end



"""
The representation `rep` contain the elements `elem` inside a representation in the field `field`.
"""
macro subrepelem(rep, elem, field)
macro subrepelem(rep, elem, field, typed = true)
idxst = Symbol(string(elem) * "Indices")
idxs = :(Polyhedra.$idxst)
idxt = Symbol(string(elem) * "Index")
idx = :(Polyhedra.$idxt)
subidxs = :(Polyhedra.Indices{T, Polyhedra.valuetype(idxs)}(idxs.rep.$field))
repT = esc(typed ? :($rep{T}) : rep)
esc(quote
Base.length(idxs::$idxs{T, <:$rep{T}}) where {T} = length($subidxs)
Base.isempty(idxs::$idxs{T, <:$rep{T}}) where {T} = isempty($subidxs)
Polyhedra.startindex(idxs::$idxs{T, <:$rep{T}}) where {T} = Polyhedra.startindex($subidxs)
Base.get(rep::$rep{T}, idx::$idx{T}) where {T} = get(rep.$field, idx)
Polyhedra.nextindex(rep::$rep{T}, idx::$idx{T}) where {T} = Polyhedra.nextindex(rep.$field, idx)
Base.length(idxs::$idxs{T, <:$repT}) where {T} = length($subidxs)
Base.isempty(idxs::$idxs{T, <:$repT}) where {T} = isempty($subidxs)
Polyhedra.startindex(idxs::$idxs{T, <:$repT}) where {T} = Polyhedra.startindex($subidxs)
Base.get(rep::$repT, idx::$idx{T}) where {T} = get(rep.$field, idx)
Polyhedra.nextindex(rep::$repT, idx::$idx{T}) where {T} = Polyhedra.nextindex(rep.$field, idx)
end)
end