Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac 15278: Only graphs that use the static backend are identical with
Browse files Browse the repository at this point in the history
their copy
  • Loading branch information
simon-king-jena committed Dec 29, 2013
1 parent 8fc9c94 commit fcf9e30
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ def __copy__(self, implementation='c_graph', data_structure=None,

NOTE:

If the graph is immutable then the graph itself is returned, rather
If the graph uses :class:`~sage.graphs.base.static_sparse_backend.StaticSparseBackend`
and uses the _immutable flag, then ``self`` is returned, rather
than a copy, unless one of the optional arguments is used.

INPUT:
Expand Down Expand Up @@ -815,6 +816,19 @@ def __copy__(self, implementation='c_graph', data_structure=None,
sage: g is g.copy(data_structure='static_sparse')
True

If a graph pretends to be immutable, but does not use the static sparse
backend, then the copy is not identic with the graph, even though it is
considered to be hashable::

sage: P = Poset(([1,2,3,4], [[1,3],[1,4],[2,3]]),
linear_extension=True, facade = False)
sage: H = P.hasse_diagram()
sage: H._immutable = True
sage: hash(H) # random
-1843552882
sage: copy(H) is H
False

"""
if sparse != None:
if data_structure != None:
Expand All @@ -823,7 +837,8 @@ def __copy__(self, implementation='c_graph', data_structure=None,
data_structure = "sparse" if sparse else "dense"

if getattr(self, '_immutable', False):
if implementation=='c_graph' and (data_structure=='static_sparse' or data_structure is None):
from sage.graphs.base.static_sparse_backend import StaticSparseBackend
if isinstance(self._backend, StaticSparseBackend) and implementation=='c_graph' and (data_structure=='static_sparse' or data_structure is None):
return self

if data_structure is None:
Expand Down

0 comments on commit fcf9e30

Please sign in to comment.