@@ -3,32 +3,36 @@ export LiftedHRepresentation, LiftedVRepresentation
33# H-Represenation
44
55# No copy since I do not modify anything and a copy is done when building a polyhedron
6- mutable struct LiftedHRepresentation{N, T} <: MixedHRep{N, T}
6+ mutable struct LiftedHRepresentation{N, T, MT <: AbstractMatrix{T} } <: MixedHRep{N, T}
77 # Ax >= 0, it is [b -A] * [z; x] where z = 1
8- A:: AbstractMatrix{T}
8+ A:: MT
99 linset:: IntSet
1010
11- function LiftedHRepresentation {N, T} (A:: AbstractMatrix , linset:: IntSet = IntSet ()) where {N, T}
11+ function LiftedHRepresentation {N, T, MT } (A:: MT , linset:: IntSet = IntSet ()) where {N, T, MT }
1212 if ! isempty (linset) && last (linset) > size (A, 1 )
1313 error (" The elements of linset should be between 1 and the number of rows of A" )
1414 end
1515 if size (A, 2 ) != N+ 1
1616 error (" dimension does not match" )
1717 end
18- new {N, T} (A, linset)
18+ new {N, T, MT } (A, linset)
1919 end
2020end
2121
22- similar_type (:: Type{<: LiftedHRepresentation} , :: FullDim{N} , :: Type{T} ) where {N,T } = LiftedHRepresentation{N,T }
23- arraytype (p:: Union{LiftedHRepresentation{N, T}, Type{LiftedHRepresentation{N, T}}} ) where {N, T} = Vector{T}
22+ similar_type (:: Type{LiftedHRepresentation{M, S, MT}} , :: FullDim{N} , :: Type{T} ) where {M, S, N, T, MT } = LiftedHRepresentation{N, T, similar_type (MT, T) }
23+ arraytype (p:: Union{LiftedHRepresentation{N, T, MT }, Type{LiftedHRepresentation{N, T, MT }}} ) where {N, T, MT } = arraytype (MT)
2424
25- LiftedHRepresentation (A:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where {T <: Real } = LiftedHRepresentation {size(A,2)-1,T} (A, linset)
26- LiftedHRepresentation (h:: HRepresentation{N,T} ) where {N,T} = LiftedHRepresentation {N,T} (h)
25+ LiftedHRepresentation {N, T} (A:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where {N, T} = LiftedHRepresentation {N, T, typeof(A)} (A, linset)
26+ LiftedHRepresentation {N, T} (A:: AbstractMatrix , linset:: IntSet = IntSet ()) where {N, T} = LiftedHRepresentation {N, T} (AbstractMatrix {T} (A), linset)
27+ LiftedHRepresentation (A:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where T = LiftedHRepresentation {size(A, 2) - 1, T} (A, linset)
28+ function LiftedHRepresentation (h:: HRepresentation{N, T} ) where {N, T}
29+ LiftedHRepresentation {N, T, arraytype(h) <: AbstractSparseVector ? SparseMatrixCSC{T, Int} : Matrix{T}} (h)
30+ end
2731
28- function LiftedHRepresentation {N, T} (hyperplanes:: ElemIt{<:HyperPlane{N, T}} , halfspaces:: ElemIt{<:HalfSpace{N, T}} ) where {N, T}
32+ function LiftedHRepresentation {N, T, MT } (hyperplanes:: ElemIt{<:HyperPlane{N, T}} , halfspaces:: ElemIt{<:HalfSpace{N, T}} ) where {N, T, MT }
2933 nhyperplane = length (hyperplanes)
3034 nhrep = nhyperplane + length (halfspaces)
31- A = Matrix {T} ( nhrep, N+ 1 )
35+ A = emptymatrix (MT, nhrep, N+ 1 )
3236 linset = IntSet (1 : nhyperplane)
3337 for (i, h) in enumerate (hyperplanes)
3438 A[i,2 : end ] = - h. a
@@ -49,34 +53,36 @@ Base.get(hrep::LiftedHRepresentation{N, T}, idx::HIndex{N, T}) where {N, T} = va
4953
5054# V-Representation
5155
52- mutable struct LiftedVRepresentation{N,T} <: MixedVRep{N,T}
53- R:: AbstractMatrix{T} # each row is a vertex if the first element is 1 and a ray otherwise
56+ mutable struct LiftedVRepresentation{N, T, MT <: AbstractMatrix{T} } <: MixedVRep{N, T}
57+ R:: MT # each row is a vertex if the first element is 1 and a ray otherwise
5458 linset:: IntSet
5559
56- function LiftedVRepresentation {N, T} (R:: AbstractMatrix , linset:: IntSet = IntSet ([])) where {N, T}
60+ function LiftedVRepresentation {N, T, MT } (R:: MT , linset:: IntSet = IntSet ([])) where {N, T, MT }
5761 if length (R) > 0 && size (R, 2 ) != N+ 1
5862 error (" dimension does not match" )
5963 end
6064 if ! isempty (linset) && last (linset) > size (R, 1 )
6165 error (" The elements of linset should be between 1 and the number of rows of R" )
6266 end
63- new {N, T} (R, linset)
67+ new {N, T, MT } (R, linset)
6468 end
6569end
6670
67- similar_type (:: Type{<: LiftedVRepresentation} , :: FullDim{N} , :: Type{T} ) where {N,T } = LiftedVRepresentation{N,T }
68- arraytype (p:: Union{LiftedVRepresentation{N, T}, Type{LiftedVRepresentation{N, T}}} ) where {N, T} = Vector{T}
71+ similar_type (:: Type{LiftedVRepresentation{M, S, MT}} , :: FullDim{N} , :: Type{T} ) where {M, S, N, T, MT } = LiftedVRepresentation{N, T, similar_type (MT, T) }
72+ arraytype (p:: Union{LiftedVRepresentation{N, T, MT }, Type{LiftedVRepresentation{N, T, MT }}} ) where {N, T, MT } = arraytype (MT)
6973
70- LiftedVRepresentation (R:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where {T <: Real } = LiftedVRepresentation {size(R,2)-1,T} (R, linset)
71- LiftedVRepresentation (v:: VRepresentation{N,T} ) where {N,T} = LiftedVRepresentation {N,T} (v)
74+ LiftedVRepresentation {N, T} (R:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where {N, T} = LiftedVRepresentation {N, T, typeof(R)} (R, linset)
75+ LiftedVRepresentation {N, T} (R:: AbstractMatrix , linset:: IntSet = IntSet ()) where {N, T} = LiftedVRepresentation {N, T} (AbstractMatrix {T} (R), linset)
76+ LiftedVRepresentation (R:: AbstractMatrix{T} , linset:: IntSet = IntSet ()) where T = LiftedVRepresentation {size(R, 2) - 1, T} (R, linset)
77+ LiftedVRepresentation (v:: VRepresentation{N,T} ) where {N, T} = LiftedVRepresentation {N, T, Matrix{T}} (v)
7278
73- function LiftedVRepresentation {N, T} (vits:: VIt{N, T} ...) where {N, T}
79+ function LiftedVRepresentation {N, T, MT } (vits:: VIt{N, T} ...) where {N, T, MT }
7480 points, lines, rays = fillvits (FullDim {N} (), vits... )
7581 npoint = length (points)
7682 nline = length (lines)
7783 nray = length (rays)
7884 nvrep = npoint + nline + nray
79- R = Matrix {T} ( nvrep, N+ 1 )
85+ R = emptymatrix (MT, nvrep, N+ 1 )
8086 linset = IntSet ()
8187 function _fill (offset, z, ps)
8288 for (i, p) in enumerate (ps)
0 commit comments