JuliaReach/LazySets.jl

vertices_list returns Float64 type for Float32 type input

Wei-TianHao opened this issue · 1 comments

julia> x = HPolytope(HalfSpace[HalfSpace(Float32[1.0, 0.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 1.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, 1.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, 0.0, 1.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, 0.0, 0.0, 1.0], 1.0f0), HalfSpace(Float32[-1.0, 0.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, -1.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, -1.0, 0.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, 0.0, -1.0, 0.0], 1.0f0), HalfSpace(Float32[0.0, 0.0, 0.0, 0.0, -1.0], 1.0f0)])
HPolytope{Float32, Vector{Float32}}(HalfSpace{Float32, Vector{Float32}}[HalfSpace{Float32, Vector{Float32}}(Float32[1.0, 0.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 1.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, 1.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, 0.0, 1.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, 0.0, 0.0, 1.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[-1.0, 0.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, -1.0, 0.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, -1.0, 0.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, 0.0, -1.0, 0.0], 1.0f0), HalfSpace{Float32, Vector{Float32}}(Float32[0.0, 0.0, 0.0, 0.0, -1.0], 1.0f0)])

julia> tovrep(x)
VPolytope{Float64, Vector{Float64}}([[-1.0, -1.0, -1.0, -1.0, -1.0], [1.0, -1.0, -1.0, -1.0, -1.0], [-1.0, 1.0, -1.0, -1.0, -1.0], [-1.0, -1.0, 1.0, -1.0, -1.0], [-1.0, -1.0, -1.0, 1.0, -1.0], [-1.0, -1.0, -1.0, -1.0, 1.0], [1.0, -1.0, -1.0, -1.0, 1.0], [-1.0, 1.0, -1.0, -1.0, 1.0], [-1.0, -1.0, 1.0, -1.0, 1.0], [-1.0, -1.0, -1.0, 1.0, 1.0]    [1.0, -1.0, 1.0, 1.0, 1.0], [-1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, -1.0, -1.0, -1.0], [1.0, 1.0, -1.0, -1.0, 1.0], [1.0, 1.0, -1.0, 1.0, -1.0], [1.0, 1.0, -1.0, 1.0, 1.0], [1.0, 1.0, 1.0, -1.0, -1.0], [1.0, 1.0, 1.0, -1.0, 1.0], [1.0, 1.0, 1.0, 1.0, -1.0], [1.0, 1.0, 1.0, 1.0, 1.0]])

julia> vertices_list(x)
32-element Vector{Vector{Float64}}:
 [-1.0, -1.0, -1.0, -1.0, -1.0]
 [1.0, -1.0, -1.0, -1.0, -1.0]
 [-1.0, 1.0, -1.0, -1.0, -1.0]
 [-1.0, -1.0, 1.0, -1.0, -1.0]
 [-1.0, -1.0, -1.0, 1.0, -1.0]
 [-1.0, -1.0, -1.0, -1.0, 1.0]
 
 [1.0, 1.0, -1.0, 1.0, -1.0]
 [1.0, 1.0, -1.0, 1.0, 1.0]
 [1.0, 1.0, 1.0, -1.0, -1.0]
 [1.0, 1.0, 1.0, -1.0, 1.0]
 [1.0, 1.0, 1.0, 1.0, -1.0]
 [1.0, 1.0, 1.0, 1.0, 1.0]

Sorry, I just saw that nobody ever reacted here.

We use Polyhedra to convert between n-dimensional polytopes (such as HPolytope and VPolytope). The conversion is based on LP solving. Most LP solvers only work with Float64, and that is why you get this result.

Of course, we could take the result and convert it to Float32 afterward. But we decided against that because the main reason for using Float32 is higher efficiency. The work has already been done with Float64. Another conversion would also take even more time.

You can pass a backend to the tovrep function. If that backend supports Float32 results, it will do what you want.