Discussion:
[GAP Forum] Pointing objects and how to detect it
Mathieu Dutour
2018-11-08 11:02:20 UTC
Permalink
I have a question about memory management in GAP.

If we do
eList:=[0,0,0,0];
eL2:=[];
Add(eL2, eList);
Add(eL2, eList);
The state of eL2 is then [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
Now if we do eL2[1][1]:=1 then we have eL2 being
[ [ 1, 0, 0, 0 ], [ 1, 0, 0, 0 ] ]
because eL2 actually contains two pointers to eList.

On the other hand, if we write eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
and do eL3[1][1]:=1 then we have eL3 being [ [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ]
].

Therefore the GAP object behavior depend on the way they are
constructed.

If one is given a matrix, is there a way to identify which one are pointing
to another object? Because right now if one does not know how the objects
are built then I do not know how to do it.

Mathieu
Stephen Linton
2018-11-08 11:31:26 UTC
Permalink
The function you want is called IsIdenticalObj. It’s documented in the manual.

gap> eList:=[0,0,0,0];
[ 0, 0, 0, 0 ]
gap> eL2:=[];
[ ]
gap> Add(eL2, eList);
gap> Add(eL2, eList);
gap> eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
gap> IsIdenticalObj(eL2[1],eL2[2]);
true
gap> IsIdenticalObj(eL3[1],eL3[2]);
false
gap>


Steve
Post by Mathieu Dutour
I have a question about memory management in GAP.
If we do
eList:=[0,0,0,0];
eL2:=[];
Add(eL2, eList);
Add(eL2, eList);
The state of eL2 is then [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
Now if we do eL2[1][1]:=1 then we have eL2 being
[ [ 1, 0, 0, 0 ], [ 1, 0, 0, 0 ] ]
because eL2 actually contains two pointers to eList.
On the other hand, if we write eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
and do eL3[1][1]:=1 then we have eL3 being [ [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ]
].
Therefore the GAP object behavior depend on the way they are
constructed.
If one is given a matrix, is there a way to identify which one are pointing
to another object? Because right now if one does not know how the objects
are built then I do not know how to do it.
Mathieu
_______________________________________________
Forum mailing list
https://mail.gap-system.org/mailman/listinfo/forum
Sergio Siccha
2018-11-08 13:19:45 UTC
Permalink
Post by Stephen Linton
Post by Mathieu Dutour
If one is given a matrix, is there a way to identify which one are pointing
to another object? Because right now if one does not know how the objects
are built then I do not know how to do it.
If you want to make sure that no row of your matrix points to another
GAP object (which may not be part of your matrix) you can use
`StructuralCopy`. For documentation see:
?Duplication of Lists

As you can see in the documentation you then still have to check whether
two rows of the matrix are identical to each other.


Calling `StructuralCopy` on everything might be a bit overkill though. I
think documented GAP functions tell you whether they create new objects
or reuse the matrix you gave it.


Best,
Sergio
Post by Stephen Linton
The function you want is called IsIdenticalObj. It’s documented in the manual.
gap> eList:=[0,0,0,0];
[ 0, 0, 0, 0 ]
gap> eL2:=[];
[ ]
gap> Add(eL2, eList);
gap> Add(eL2, eList);
gap> eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
gap> IsIdenticalObj(eL2[1],eL2[2]);
true
gap> IsIdenticalObj(eL3[1],eL3[2]);
false
gap>
Steve
Post by Mathieu Dutour
I have a question about memory management in GAP.
If we do
eList:=[0,0,0,0];
eL2:=[];
Add(eL2, eList);
Add(eL2, eList);
The state of eL2 is then [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
Now if we do eL2[1][1]:=1 then we have eL2 being
[ [ 1, 0, 0, 0 ], [ 1, 0, 0, 0 ] ]
because eL2 actually contains two pointers to eList.
On the other hand, if we write eL3:=[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ];
and do eL3[1][1]:=1 then we have eL3 being [ [ 1, 0, 0, 0 ], [ 0, 0, 0, 0 ]
].
Therefore the GAP object behavior depend on the way they are
constructed.
If one is given a matrix, is there a way to identify which one are pointing
to another object? Because right now if one does not know how the objects
are built then I do not know how to do it.
Mathieu
_______________________________________________
Forum mailing list
https://mail.gap-system.org/mailman/listinfo/forum
_______________________________________________
Forum mailing list
https://mail.gap-system.org/mailman/listinfo/forum
Loading...