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

Cint limited to Int32 #30

Open
andreadegirolamo99 opened this issue Feb 12, 2024 · 2 comments
Open

Cint limited to Int32 #30

andreadegirolamo99 opened this issue Feb 12, 2024 · 2 comments

Comments

@andreadegirolamo99
Copy link

Hi :)

I am trying to create hypergraphs with pretty huge hyperedge weights. As a consequence, when these get too large I get this error log:

ERROR: InexactError: trunc(Int32, 1099511627776)
Stacktrace:
  [1] throw_inexacterror(f::Symbol, #unused#::Type{Int32}, val::Int64)
    @ Core ./boot.jl:634
  [2] checked_trunc_sint
    @ ./boot.jl:656 [inlined]
  [3] toInt32
    @ ./boot.jl:693 [inlined]
  [4] Int32(x::Int64)
    @ Core ./boot.jl:783
  [5] _broadcast_getindex_evalf
    @ ./broadcast.jl:683 [inlined]
  [6] _broadcast_getindex
    @ ./broadcast.jl:656 [inlined]
  [7] getindex
    @ ./broadcast.jl:610 [inlined]
  [8] copy
    @ ./broadcast.jl:912 [inlined]
  [9] materialize
    @ ./broadcast.jl:873 [inlined]
 [10] KaHyPar.HyperGraph(A::SparseArrays.SparseMatrixCSC{Float64, Int64}, vertex_weights::Vector{Float64}, edge_weights::Vector{Any})
    @ KaHyPar ~/.julia/packages/KaHyPar/63UEh/src/KaHyPar.jl:82

This is due to the fact that all constants in kahypar_h.jl, including kahypar_hyperedge_weight_t, are declared as Cint or Cuint, corresponding to julia's Int32, which is not enough bits to represent these larger integers.
In kahypar_h.jl, lines 1-5:

const kahypar_hypernode_id_t = Cuint
const kahypar_hyperedge_id_t = Cuint
const kahypar_hypernode_weight_t = Cint
const kahypar_hyperedge_weight_t = Cint
const kahypar_partition_id_t = Cint

For now, I have temporarily solved this issue with a try-catch-else clause:

try 
	Int32(my_huge_number)
catch
else
	# my_huge_number can be used for computation
end

Could this be solved by parsing a larger integer, e.g. Int64, to C?

@jalving
Copy link
Member

jalving commented Feb 13, 2024

good question @andreadegirolamo99. I am not sure whether the KaHyPar C interface assumes node and edge weights need to be int32 or not. Can the int type be 64 bit @SebastianSchlag?

@SebastianSchlag
Copy link
Member

Hey @andreadegirolamo99, thank for reaching out and sorry for the delayed response.
It is correct that KaHyPar uses 32bit integers by default.

However, if you build it from source, it should be relatively easy to get a version that supported 64bit edge weights. The main typedefs for node IDs, edge IDs, node weights and edge weights are located in the definitions.h file located in the kahypar-shared-resources submodule.

Those would need to be changed to int64_t along with the typedefs of the C interface in libkahypar.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants