deep copy vs. shallow copy

107 views
Skip to first unread message

YannLC

unread,
Dec 6, 2009, 8:11:34 AM12/6/09
to sage-devel
The update of Networkx to version 1.0rc1 change the behavior of copy
from a shallow copy to a deep copy.

It exposes the following, already present in sage 4.2.1:

sage: X = species.SingletonSpecies()
sage: B = species.CombinatorialSpecies()
sage: B.define(X+B*B)
sage: g = B.digraph()
sage: s=set(g.vertices())
sage: [ deepcopy(k) in s for k in s ]
[True, False, False, False]

Is it the intended result or a bug in species or ... something else?

( of course we have:
sage: [ copy(k) in s for k in s ]
sage: [True, True, True, True] )

Nathann Cohen

unread,
Dec 6, 2009, 9:22:43 AM12/6/09
to sage-devel
Hmmm... I'm very sorry but I do not know what deep/shallow copies are
nor what they mean in Sage... Is there any page you could point me
to ?

Thank you !! :-)

Nathann

David Joyner

unread,
Dec 6, 2009, 9:34:03 AM12/6/09
to sage-...@googlegroups.com
On Sun, Dec 6, 2009 at 9:22 AM, Nathann Cohen <nathan...@gmail.com> wrote:
> Hmmm... I'm very sorry but I do not know what deep/shallow copies are
> nor what they mean in Sage... Is there any page you could point me
> to ?


http://docs.python.org/library/copy.html
I don't think Sage modifies this command in any way in the preparser - they are
both pure Python commands.


>
> Thank you !!  :-)
>
> Nathann
>
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel-...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org

Martin Albrecht

unread,
Dec 6, 2009, 9:38:59 AM12/6/09
to sage-...@googlegroups.com
> http://docs.python.org/library/copy.html
> I don't think Sage modifies this command in any way in the preparser - they
> are both pure Python commands.

From that file:

"In order for a class to define its own copy implementation, it can define
special methods __copy__() and __deepcopy__(). The former is called to
implement the shallow copy operation; no additional arguments are passed. The
latter is called to implement the deep copy operation; it is passed one
argument, the memo dictionary. If the __deepcopy__() implementation needs to
make a deep copy of a component, it should call the deepcopy() function with
the component as first argument and the memo dictionary as second argument."

I am certain that for extension classes one needs to implement both.


--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinr...@jabber.ccc.de

Reply all
Reply to author
Forward
0 new messages