Skip to content

Commit

Permalink
Add support for copy
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 21, 2016
1 parent 0c1aa65 commit 0cc1d5f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CDDLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

@dd_ccall set_global_constants Void ()

import Base.show, Base.convert, Base.push!, Base.eltype
import Base.show, Base.convert, Base.push!, Base.eltype, Base.copy

include("cddtypes.jl")

Expand Down
15 changes: 15 additions & 0 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ function dd_setmatrixrepresentationtype(matrix::Ptr{Cdd_MatrixData{GMPRational}}
@dd_ccall SetMatrixRepresentationType Void (Ptr{Cdd_MatrixData{GMPRational}}, Cdd_RepresentationType) matrix (inequality ? dd_Inequality : dd_Generator)
end

function dd_matrixcopy(matrix::Ptr{Cdd_MatrixData{Cdouble}})
@ddf_ccall MatrixCopy Ptr{Cdd_MatrixData{Cdouble}} (Ptr{Cdd_MatrixData{Cdouble}},) matrix
end
function dd_matrixcopy(matrix::Ptr{Cdd_MatrixData{GMPRational}})
@dd_ccall MatrixCopy Ptr{Cdd_MatrixData{GMPRational}} (Ptr{Cdd_MatrixData{GMPRational}},) matrix
end


function initmatrix{T<:MyType}(M::Array{T, 2}, linset, inequality::Bool)
m = Cdd_rowrange(size(M, 1))
Expand Down Expand Up @@ -99,6 +106,10 @@ end

CDDInequalityMatrix{T<:MyType}(matrix::Ptr{Cdd_MatrixData{T}}) = CDDInequalityMatrix{unsafe_load(matrix).colsize-1, T}(matrix)

function Base.copy{N, T}(matrix::CDDInequalityMatrix{N, T})
CDDInequalityMatrix{N, T}(dd_matrixcopy(matrix.matrix))
end

function isaninequalityrepresentation(matrix::CDDInequalityMatrix)
true
end
Expand All @@ -115,6 +126,10 @@ end

CDDGeneratorMatrix{T<:MyType}(matrix::Ptr{Cdd_MatrixData{T}}) = CDDGeneratorMatrix{unsafe_load(matrix).colsize-1, T}(matrix)

function Base.copy{N, T}(matrix::CDDGeneratorMatrix{N, T})
CDDGeneratorMatrix{N, T}(dd_matrixcopy(matrix.matrix))
end

function isaninequalityrepresentation(matrix::CDDGeneratorMatrix)
false
end
Expand Down
24 changes: 24 additions & 0 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ function updatepoly!{N}(p::CDDPolyhedron{N}, poly::CDDPolyhedra{N})
p.poly = poly
end

function Base.copy{N, T}(p::CDDPolyhedron{N, T})
pcopy = nothing
if !isnull(p.ine)
pcopy = CDDPolyhedron{N, T}(copy(get(p.ine)))
end
if !isnull(p.ext)
if pcopy == nothing
pcopy = CDDPolyhedron{N, T}(copy(get(p.ext)))
else
pcopy.ext = copy(get(p.ext))
end
end
if pcopy == nothing
# copy of ine and ext may be not necessary here
# but I do it to be sure
pcopy = CDDPolyhedron{N, T}(copy(getine(p)))
pcopy.ext = copy(getext(p))
end
pcopy.linearitydetected = p.linearitydetected
pcopy.noredundantinequality = p.noredundantinequality
pcopy.noredundantgenerator = p.noredundantgenerator
pcopy
end

# Implementation of Polyhedron's mandatory interface
function polyhedron(desc::Description, lib::CDDLibrary)
CDDPolyhedron(desc, lib.precision)
Expand Down

0 comments on commit 0cc1d5f

Please sign in to comment.