Does deepcopy work properly with Cython?

678 views
Skip to first unread message

Kyungwon Chun

unread,
Nov 21, 2011, 2:11:18 AM11/21/11
to cython-users
Does deepcopy work properly with Cython? I got False from 'B(A(1)).a.v
== 1' with the following code.

from copy import deepcopy

cdef class A(object):
cdef public double v
def __init__(self, double v):
self.v = v

cdef class B(object):
cdef public A a
def __init__(self, A a):
self.a = deepcopy(a)

Lisandro Dalcin

unread,
Nov 21, 2011, 1:18:43 PM11/21/11
to cython...@googlegroups.com

No. In this case (you are using extension types, i.e cdef classes) you
have to implement the pickle protocol for your class
http://docs.python.org/library/pickle.html#pickling-and-unpickling-extension-types


--
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169

전경원

unread,
Nov 21, 2011, 9:00:51 PM11/21/11
to cython...@googlegroups.com
I got the point.
Thanks, Lisandro.

2011/11/22 Lisandro Dalcin <dal...@gmail.com>
Reply all
Reply to author
Forward
0 new messages