-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b20b0a6
commit 4e1f940
Showing
8 changed files
with
287 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
ColPackBiColoring | ||
Struct holding the parameters of a bicoloring as well as its results (which can be queried with [`get_colors`](@ref)). | ||
# Fields | ||
The fields of this struct are not part of the public API, they are only useful to interface with the C++ library [ColPack](https://github.com/CSCsw/ColPack). | ||
# Constructors | ||
ColPackBiColoring( | ||
filename::AbstractString, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false | ||
) | ||
ColPackBiColoring( | ||
M::SparseMatrixCSC, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false | ||
) | ||
Perform the coloring of a matrix that is either given directly or read from a file. | ||
The users needs to specify a bicoloring `method` and an `order` on the vertices. | ||
# See also | ||
- [`ColoringMethod`](@ref) | ||
- [`ColoringOrder`](@ref) | ||
""" | ||
mutable struct ColPackBiColoring | ||
refColPack::Base.RefValue{Ptr{Cvoid}} | ||
coloring1::Vector{Cint} | ||
coloring2::Vector{Cint} | ||
method::ColoringMethod | ||
order::ColoringOrder | ||
end | ||
|
||
Base.unsafe_convert(::Type{Ptr{Cvoid}}, coloring::ColPackBiColoring) = coloring.refColPack[] | ||
|
||
function ColPackBiColoring( | ||
filename::AbstractString, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false, | ||
) | ||
refColPack = Ref{Ptr{Cvoid}}(C_NULL) | ||
reflen1 = Ref{Cint}(0) | ||
reflen2 = Ref{Cint}(0) | ||
ret = build_bicoloring_from_file(refColPack, reflen1, reflen2, filename, method.method, order.order, verbose) | ||
(ret == 0) && error("ColPack bicoloring failed.") | ||
coloring1 = zeros(Cint, reflen1[]) | ||
coloring2 = zeros(Cint, reflen2[]) | ||
g = ColPackBiColoring(refColPack, coloring1, coloring2, method, order) | ||
finalizer(free_bicoloring, g) | ||
return g | ||
end | ||
|
||
""" | ||
get_colors(coloring::ColPackBiColoring) | ||
Retrieve the colors from a [`ColPackBiColoring`](@ref) as vectors of integers. | ||
""" | ||
function get_colors(coloring::ColPackBiColoring) | ||
get_bicoloring(coloring.refColPack[], coloring.coloring1, coloring.coloring2) | ||
coloring.coloring1 .+= Cint(1) | ||
coloring.coloring2 .+= Cint(1) | ||
return coloring.coloring1, coloring.coloring2 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
ColPackPartialColoring | ||
Struct holding the parameters of a partial coloring as well as its results (which can be queried with [`get_colors`](@ref)). | ||
# Fields | ||
The fields of this struct are not part of the public API, they are only useful to interface with the C++ library [ColPack](https://github.com/CSCsw/ColPack). | ||
# Constructors | ||
ColPackPartialColoring( | ||
filename::AbstractString, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false | ||
) | ||
ColPackPartialColoring( | ||
M::SparseMatrixCSC, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false | ||
) | ||
Perform the partial coloring of a matrix that is either given directly or read from a file. | ||
The users needs to specify a partial coloring `method` and an `order` on the vertices. | ||
# See also | ||
- [`ColoringMethod`](@ref) | ||
- [`ColoringOrder`](@ref) | ||
""" | ||
mutable struct ColPackPartialColoring | ||
refColPack::Base.RefValue{Ptr{Cvoid}} | ||
coloring::Vector{Cint} | ||
method::ColoringMethod | ||
order::ColoringOrder | ||
end | ||
|
||
Base.unsafe_convert(::Type{Ptr{Cvoid}}, coloring::ColPackPartialColoring) = coloring.refColPack[] | ||
|
||
function ColPackPartialColoring( | ||
filename::AbstractString, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false, | ||
) | ||
refColPack = Ref{Ptr{Cvoid}}(C_NULL) | ||
reflen = Ref{Cint}(0) | ||
ret = build_partial_coloring_from_file(refColPack, reflen, filename, method.method, order.order, verbose) | ||
(ret == 0) && error("ColPack partial coloring failed.") | ||
coloring = zeros(Cint, reflen[]) | ||
g = ColPackPartialColoring(refColPack, coloring, method, order) | ||
finalizer(free_partial_coloring, g) | ||
return g | ||
end | ||
|
||
function ColPackPartialColoring( | ||
M::SparseMatrixCSC, | ||
method::ColoringMethod, | ||
order::ColoringOrder; | ||
verbose::Bool=false, | ||
) | ||
reflen = Ref{Cint}(0) | ||
refColPack = Ref{Ptr{Cvoid}}(C_NULL) | ||
nrows, ncols = size(M) | ||
|
||
# The CSC format of M is the CSR format of Mᵀ. | ||
Mt_cols = Cint.(M.rowval) | ||
Mt_rows = Cint.(M.colptr) | ||
|
||
# ColPack expects sparse CSR matrices with 0-based indexing. | ||
Mt_cols .-= Cint(1) | ||
Mt_rows .-= Cint(1) | ||
|
||
(method.method == "ROW_PARTIAL_DISTANCE_TWO") && (colpack_method = "COLUMN_PARTIAL_DISTANCE_TWO") | ||
(method.method == "COLUMN_PARTIAL_DISTANCE_TWO") && (colpack_method = "ROW_PARTIAL_DISTANCE_TWO") | ||
ret = build_partial_coloring_from_csr(refColPack, reflen, Mt_rows, Mt_cols, ncols, nrows, colpack_method, order.order, verbose) | ||
(ret == 0) && error("ColPack partial coloring failed.") | ||
coloring = zeros(Cint, reflen[]) | ||
g = ColPackPartialColoring(refColPack, coloring, ColoringMethod(colpack_method), order) | ||
finalizer(free_partial_coloring, g) | ||
return g | ||
end | ||
|
||
""" | ||
get_colors(coloring::ColPackPartialColoring) | ||
Retrieve the colors from a [`ColPackPartialColoring`](@ref) as a vector of integers. | ||
""" | ||
function get_colors(coloring::ColPackPartialColoring) | ||
get_partial_coloring(coloring.refColPack[], coloring.coloring) | ||
coloring.coloring .+= Cint(1) | ||
return coloring.coloring | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,58 @@ | ||
function build_coloring_from_file(ref, len, _filename, _method, _order, verbose) | ||
@ccall libcolpack.build_coloring_from_file(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, _filename::Cstring, | ||
_method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
@ccall libcolpack.build_coloring_from_file(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, _filename::Ptr{Cchar}, | ||
_method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_partial_coloring_from_file(ref, len, _filename, _method, _order, verbose) | ||
@ccall libcolpack.build_partial_coloring_from_file(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, _filename::Ptr{Cchar}, | ||
_method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_bicoloring_from_file(ref, len1, len2, _filename, _method, _order, verbose) | ||
@ccall libcolpack.build_bicoloring_from_file(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, _filename::Cstring, | ||
_method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
@ccall libcolpack.build_bicoloring_from_file(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, _filename::Ptr{Cchar}, | ||
_method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_partial_coloring_from_file(ref, len1, len2, _filename, _method, _order, verbose) | ||
@ccall libcolpack.build_partial_coloring_from_file(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, _filename::Cstring, | ||
_method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
function build_coloring_from_adolc(ref, len, adolc, rowcount, _method, _order, verbose) | ||
@ccall libcolpack.build_coloring_from_adolc(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, adolc::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, _method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_coloring_from_csr(ref, len, csr, rowcount, _method, _order, verbose) | ||
@ccall libcolpack.build_coloring_from_csr(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, csr::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, _method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
function build_partial_coloring_from_adolc(ref, len, adolc, rowcount, colcount, _method, _order, verbose) | ||
@ccall libcolpack.build_partial_coloring_from_adolc(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, adolc::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, colcount::Cint, _method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_bicoloring_from_csr(ref, len1, len2, csr, rowcount, colcount, _method, _order, verbose) | ||
@ccall libcolpack.build_bicoloring_from_csr(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, csr::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, colcount::Cint, _method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
function build_bicoloring_from_adolc(ref, len1, len2, adolc, rowcount, colcount, _method, _order, verbose) | ||
@ccall libcolpack.build_bicoloring_from_adolc(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, adolc::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, colcount::Cint, _method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function build_partial_coloring_from_csr(ref, len1, len2, csr, rowcount, colcount, _method, _order, verbose) | ||
@ccall libcolpack.build_partial_coloring_from_csr(ref::Ptr{Ptr{Cvoid}}, len1::Ptr{Cint}, len2::Ptr{Cint}, csr::Ptr{Ptr{Cuint}}, | ||
rowcount::Cint, colcount::Cint, _method::Cstring, _order::Cstring, verbose::Cint)::Cint | ||
function build_partial_coloring_from_csr(ref, len, rows, cols, rowcount, colcount, _method, _order, verbose) | ||
@ccall libcolpack.build_partial_coloring_from_csr(ref::Ptr{Ptr{Cvoid}}, len::Ptr{Cint}, rows::Ptr{Cint}, cols::Ptr{Cint}, | ||
rowcount::Cint, colcount::Cint, _method::Ptr{Cchar}, _order::Ptr{Cchar}, verbose::Cint)::Cint | ||
end | ||
|
||
function get_coloring(ref, coloring) | ||
@ccall libcolpack.get_coloring(ref::Ptr{Cvoid}, coloring::Ptr{Cint})::Cvoid | ||
end | ||
|
||
function get_bicoloring(ref, left_coloring, right_coloring) | ||
@ccall libcolpack.get_bicoloring(ref::Ptr{Cvoid}, left_coloring::Ptr{Cint}, right_coloring::Ptr{Cint})::Cvoid | ||
function get_partial_coloring(ref, coloring) | ||
@ccall libcolpack.get_partial_coloring(ref::Ptr{Cvoid}, coloring::Ptr{Cint})::Cvoid | ||
end | ||
|
||
function get_partial_coloring(ref, left_coloring, right_coloring) | ||
@ccall libcolpack.get_partial_coloring(ref::Ptr{Cvoid}, left_coloring::Ptr{Cint}, right_coloring::Ptr{Cint})::Cvoid | ||
function get_bicoloring(ref, left_coloring, right_coloring) | ||
@ccall libcolpack.get_bicoloring(ref::Ptr{Cvoid}, left_coloring::Ptr{Cint}, right_coloring::Ptr{Cint})::Cvoid | ||
end | ||
|
||
function free_coloring(ref) | ||
@ccall libcolpack.free_coloring(ref::Ptr{Cvoid})::Cvoid | ||
end | ||
|
||
function free_bicoloring(ref) | ||
@ccall libcolpack.free_bicoloring(ref::Ptr{Cvoid})::Cvoid | ||
end | ||
|
||
function free_partial_coloring(ref) | ||
@ccall libcolpack.free_partial_coloring(ref::Ptr{Cvoid})::Cvoid | ||
end | ||
|
||
function free_bicoloring(ref) | ||
@ccall libcolpack.free_bicoloring(ref::Ptr{Cvoid})::Cvoid | ||
end |
Oops, something went wrong.