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

Wrap dd_Matrix2Adjacency #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ function matrixappend(matrix::CDDMatrix{T}, repr::Representation{S}) where {S, T
matrixappend(matrix, cddmatrix(T, repr))
end

function dd_matrix2adjacency(matrix::Ptr{Cdd_MatrixData{Cdouble}})
return @ddf_ccall_pointer_error(
Matrix2Adjacency,
Ptr{SetFamily},
(Ptr{Cdd_MatrixData{Cdouble}}, Ref{Cdd_ErrorType}),
matrix,
)
end
function dd_matrix2adjacency(matrix::Ptr{Cdd_MatrixData{GMPRational}})
return @dd_ccall_pointer_error(
Matrix2Adjacency,
Ptr{SetFamily},
(Ptr{Cdd_MatrixData{GMPRational}}, Ref{Cdd_ErrorType}),
matrix,
)
end
function matrix2adjacency(matrix::CDDMatrix)
return convert_free(Vector{BitSet}, dd_matrix2adjacency(matrix.matrix))
end

# Redundant
function dd_redundant(matrix::Ptr{Cdd_MatrixData{Cdouble}}, i::Cdd_rowrange, len::Int)
certificate = Vector{Cdouble}(undef, len)
Expand Down Expand Up @@ -119,7 +139,7 @@ function dd_redundantrows(matrix::Ptr{Cdd_MatrixData{GMPRational}})
)
end
function redundantrows(matrix::CDDMatrix)
Base.convert(BitSet, CDDSet(dd_redundantrows(matrix.matrix), length(matrix)))
convert_free(BitSet, CDDSet(dd_redundantrows(matrix.matrix), length(matrix)))
end
function redundantrows(repr::Representation)
redundantrows(CDDMatrix(repr))
Expand Down Expand Up @@ -337,4 +357,4 @@ function blockelimination(ine::HRepresentation, delset=BitSet([fulldim(ine)]))
blockelimination(Base.convert(CDDInequalityMatrix, ine), delset)
end

export redundant, redundantrows, sredundant, fourierelimination, blockelimination, canonicalize!, redundancyremove!
export redundant, redundantrows, sredundant, matrix2adjacency, fourierelimination, blockelimination, canonicalize!, redundancyremove!
26 changes: 26 additions & 0 deletions src/settype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function CDDSet(s, maxel::Clong, offset::Integer)
end
CDDSet(s, maxel, offset::Integer) = CDDSet(s, Clong(maxel), offset)

function dd_free(set::CDDSet)
@cdd_ccall(set_free, Cvoid, (Cset_type,), set.s)
end

function Base.convert(::Type{BitSet}, st::CDDSet)
s = BitSet()
for i = 1:st.maxel
Expand All @@ -59,4 +63,26 @@ function myconvert(::Type{BitSet}, a::Matrix)
s
end

mutable struct SetFamily
famsize::Cdd_bigrange
setsize::Cdd_bigrange
set::Cdd_SetVector
end

function dd_free(set::Ptr{SetFamily})
@dd_ccall(FreeSetFamily, Cvoid, (Ptr{SetFamily},), set)
end

function Base.convert(::Type{Vector{BitSet}}, set_familty_ptr::Ptr{SetFamily})
set_family = unsafe_load(set_familty_ptr)
sets = unsafe_wrap(Array, set_family.set, set_family.famsize)
return BitSet[convert(BitSet, CDDSet(set, set_family.setsize)) for set in sets]
end

function convert_free(::Type{T}, x) where {T}
t = convert(T, x)
dd_free(x)
return t
end

export CDDSet