From b87fbc950011d25b88f3f1fdcc2346066ef1fb51 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 12 Jun 2024 10:26:22 -0400 Subject: [PATCH] Interface new routined of the C interface --- src/ColPack.jl | 2 +- src/colpack_bicoloring.jl | 9 +++++ src/colpack_coloring.jl | 9 +++++ src/colpack_partial_coloring.jl | 9 +++++ src/libcolpack.jl | 60 ++++++++++++++++++++------------- test/coloring.jl | 4 +++ 6 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/ColPack.jl b/src/ColPack.jl index 2708c59..3173080 100644 --- a/src/ColPack.jl +++ b/src/ColPack.jl @@ -29,6 +29,6 @@ include("colpack_bicoloring.jl") # Exports -export ColPackColoring, ColPackPartialColoring, colpack, get_colors +export ColPackColoring, ColPackPartialColoring, colpack, get_colors, ncolors end #module diff --git a/src/colpack_bicoloring.jl b/src/colpack_bicoloring.jl index 4426d8a..0478782 100644 --- a/src/colpack_bicoloring.jl +++ b/src/colpack_bicoloring.jl @@ -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 diff --git a/src/colpack_coloring.jl b/src/colpack_coloring.jl index 943cdde..26ee9df 100644 --- a/src/colpack_coloring.jl +++ b/src/colpack_coloring.jl @@ -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 diff --git a/src/colpack_partial_coloring.jl b/src/colpack_partial_coloring.jl index 03f5b4f..59a048a 100644 --- a/src/colpack_partial_coloring.jl +++ b/src/colpack_partial_coloring.jl @@ -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 diff --git a/src/libcolpack.jl b/src/libcolpack.jl index 81ea9ad..9ceee14 100644 --- a/src/libcolpack.jl +++ b/src/libcolpack.jl @@ -1,51 +1,51 @@ -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}}, @@ -53,14 +53,14 @@ function build_partial_coloring_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_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}}, @@ -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}}, @@ -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 @@ -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 diff --git a/test/coloring.jl b/test/coloring.jl index b7bc4be..cddd138 100644 --- a/test/coloring.jl +++ b/test/coloring.jl @@ -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 @@ -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)) @@ -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