Copy for BigObjects not working
saschatimme opened this issue · 2 comments
Consider this code
P=Polymake.polytope.cube(3)
Q=copy(P)
type: Polytope<Rational>
description: cube of dimension 3
AFFINE_HULL
BOUNDED
true
CONE_AMBIENT_DIM
4
CONE_DIM
4
FACETS
1 1 0 0
1 -1 0 0
1 0 1 0
1 0 -1 0
1 0 0 1
1 0 0 -1
VERTICES_IN_FACETS
{0 2 4 6}
{1 3 5 7}
{0 1 4 5}
{2 3 6 7}
{0 1 2 3}
{4 5 6 7}
P.VERTICES
Q
type: Polytope<Rational>
description: cube of dimension 3
AFFINE_HULL
BOUNDED
true
CONE_AMBIENT_DIM
4
CONE_DIM
4
FACETS
1 1 0 0
1 -1 0 0
1 0 1 0
1 0 -1 0
1 0 0 1
1 0 0 -1
FEASIBLE
true
LINEALITY_SPACE
N_FACETS
6
N_VERTICES
8
POINTED
true
VERTICES
1 -1 -1 -1
1 1 -1 -1
1 -1 1 -1
1 1 1 -1
1 -1 -1 1
1 1 -1 1
1 -1 1 1
1 1 1 1
VERTICES_IN_FACETS
{0 2 4 6}
{1 3 5 7}
{0 1 4 5}
{2 3 6 7}
{0 1 2 3}
{4 5 6 7}
The P.VERTICES
triggers the computation of the vertices also in Q. So we definitely didn't create a proper copy. deepcopy
also doesn't work.
Some research
julia> @which copy(P)
copy(arg1::Union{CxxWrap.CxxWrapCore.ConstCxxRef{var"#s36"} where var"#s36"<:Polymake.BigObject, CxxWrap.CxxWrapCore.CxxRef{var"#s35"} where var"#s35"<:Polymake.BigObject, Union{CxxWrap.CxxWrapCore.SmartPointer{T2}, T2} where T2<:Polymake.BigObject}) in Polymake at /Users/sascha/.julia/packages/CxxWrap/OcN1Z/src/CxxWrap.jl:618
One way to get an honest copy is to do:
Q = Polymake.polytope.Polytope(P)
My Polymake foo is not enough to come up with a general solution.
I might be wrong, but it's by design: polymake objects try very hard not to be copied ;)
I was slightly surprised that Q = Polymake.polytope.Polytope(P)
does work, because the default copy constructor for BigObject
will not create a copy but just a new reference. But since we use the "type" Polytope
(the function name) for the construction using a new BigObjectType
we do get a copy in that case. (it uses a BigObject(BigObjectType,BigObject)
constructor on the C++ side)
In this case we are even dealing with perl references that also avoid copying.
But there is an easy way to solve this, we can just add a mapping for the following method for BigObject
to libpolymake-julia
:
class BigObject {
...
// construct an exact copy (up to temporary properties and local extensions)
BigObject copy() const;
I'm not totally sure what julia function we should map that to (copy
, deepcopy
, deepcopy_internal
,...) ?