Skip to content

Commit

Permalink
Interface new routined of the C interface
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jun 12, 2024
1 parent 4b64646 commit b87fbc9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/ColPack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ include("colpack_bicoloring.jl")

# Exports

export ColPackColoring, ColPackPartialColoring, colpack, get_colors
export ColPackColoring, ColPackPartialColoring, colpack, get_colors, ncolors

end #module
9 changes: 9 additions & 0 deletions src/colpack_bicoloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ function get_colors(coloring::ColPackBiColoring)
coloring.coloring2 .+= Cint(1)
return coloring.coloring1, coloring.coloring2
end

"""
ncolors(coloring::ColPackBiColoring)
Retrieve the number of colors from a [`ColPackBiColoring`](@ref).
"""
function ncolors(coloring::ColPackBiColoring)
return ncolors_bicoloring(coloring.refColPack[])
end
9 changes: 9 additions & 0 deletions src/colpack_coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,12 @@ function get_colors(coloring::ColPackColoring)
coloring.coloring .+= Cint(1)
return coloring.coloring
end

"""
ncolors(coloring::ColPackColoring)
Retrieve the number of colors from a [`ColPackColoring`](@ref).
"""
function ncolors(coloring::ColPackColoring)
return ncolors_coloring(coloring.refColPack[])
end
9 changes: 9 additions & 0 deletions src/colpack_partial_coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,12 @@ function get_colors(coloring::ColPackPartialColoring)
coloring.coloring .+= Cint(1)
return coloring.coloring
end

"""
ncolors(coloring::ColPackPartialColoring)
Retrieve the number of colors from a [`ColPackPartialColoring`](@ref).
"""
function ncolors(coloring::ColPackPartialColoring)
return ncolors_partial_coloring(coloring.refColPack[])
end
60 changes: 36 additions & 24 deletions src/libcolpack.jl
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
function build_coloring_from_file(ref, len, _filename, _method, _order, verbose)
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::Ptr{Cchar},
_method::Ptr{Cchar},
_order::Ptr{Cchar},
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)
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},
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)
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::Ptr{Cchar},
_method::Ptr{Cchar},
_order::Ptr{Cchar},
filename::Ptr{Cchar},
method::Ptr{Cchar},
order::Ptr{Cchar},
verbose::Cint,
)::Cint
end

function build_coloring_from_adolc(ref, len, adolc, rowcount, _method, _order, verbose)
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},
method::Ptr{Cchar},
order::Ptr{Cchar},
verbose::Cint,
)::Cint
end

function build_partial_coloring_from_adolc(
ref, len, adolc, rowcount, colcount, _method, _order, verbose
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},
method::Ptr{Cchar},
order::Ptr{Cchar},
verbose::Cint,
)::Cint
end

function build_bicoloring_from_adolc(
ref, len1, len2, adolc, rowcount, colcount, _method, _order, verbose
ref, len1, len2, adolc, rowcount, colcount, method, order, verbose
)
@ccall libcolpack.build_bicoloring_from_adolc(
ref::Ptr{Ptr{Cvoid}},
Expand All @@ -69,14 +69,14 @@ function build_bicoloring_from_adolc(
adolc::Ptr{Ptr{Cuint}},
rowcount::Cint,
colcount::Cint,
_method::Ptr{Cchar},
_order::Ptr{Cchar},
method::Ptr{Cchar},
order::Ptr{Cchar},
verbose::Cint,
)::Cint
end

function build_partial_coloring_from_csr(
ref, len, rows, cols, rowcount, colcount, _method, _order, verbose
ref, len, rows, cols, rowcount, colcount, method, order, verbose
)
@ccall libcolpack.build_partial_coloring_from_csr(
ref::Ptr{Ptr{Cvoid}},
Expand All @@ -85,8 +85,8 @@ function build_partial_coloring_from_csr(
cols::Ptr{Cint},
rowcount::Cint,
colcount::Cint,
_method::Ptr{Cchar},
_order::Ptr{Cchar},
method::Ptr{Cchar},
order::Ptr{Cchar},
verbose::Cint,
)::Cint
end
Expand All @@ -105,6 +105,18 @@ function get_bicoloring(ref, left_coloring, right_coloring)
)::Cvoid
end

function ncolors_coloring(ref)
@ccall libcolpack.ncolors_coloring(ref::Ptr{Cvoid})::Cint
end

function ncolors_partial_coloring(ref)
@ccall libcolpack.ncolors_partial_coloring(ref::Ptr{Cvoid})::Cint
end

function ncolors_bicoloring(ref)
@ccall libcolpack.ncolors_bicoloring(ref::Ptr{Cvoid})::Cint
end

function free_coloring(ref)
@ccall libcolpack.free_coloring(ref::Ptr{Cvoid})::Cvoid
end
Expand Down
4 changes: 4 additions & 0 deletions test/coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ end
coloring_mat = ColPackColoring(H, method, order; verbose=false)
coloring_file = ColPackColoring(filename, method, order; verbose=false)
@test get_colors(coloring_mat) == get_colors(coloring_file)
@test ncolors(coloring_mat) == ncolors(coloring_file)
colors = get_colors(coloring_file)
test_colors(H, method, colors)
end
Expand All @@ -81,6 +82,8 @@ end;
filename, method, order; verbose=false
)
@test length(get_colors(coloring_mat)) == length(get_colors(coloring_file))
@test ncolors(coloring_mat) 1
@test ncolors(coloring_file) 1
# this is not always true since we use different algorithms
# @test get_colors(coloring_mat) == get_colors(coloring_file)
test_colors(J, method, get_colors(coloring_mat))
Expand All @@ -98,6 +101,7 @@ end;
filename = joinpath(@__DIR__, "J.mtx")
MatrixMarket.mmwrite(filename, J)
coloring_file = ColPackBiColoring(filename, method, order; verbose=false)
@test ncolors(coloring_file) 1
colors1, colors2 = get_colors(coloring_file)
test_colors(J, method, colors1, colors2)
end
Expand Down

0 comments on commit b87fbc9

Please sign in to comment.