[SciPy-dev] Arrays and matrices share memory?
Stephen Walton
stephen.walton at csun.edu
Wed Oct 19 11:21:27 CDT 2005
I began tracking down the failures in scipy.test (full new install) this
morning on the bus and hit two problems right off, both in expm3. The
first is easy to fix: line 84 needs to change from
eA = eye(*A.shape,**{'typecode':t})
to
eA = eye(*A.shape,**{'dtype':t})
The second one is more subtle and here's a brief demonstration of the
problem:
In [1]:import scipy as S
In [2]:A=S.array([[1.,1],[1,1]])
In [3]:trm = S.mat(A)
In [4]:trm
Out[4]:
matrix([[ 1., 1.],
[ 1., 1.]])
In [5]:A
Out[5]:
array([[ 1., 1.],
[ 1., 1.]])
In [6]:trm is A
Out[6]:False
In [7]:trm *= 0
In [8]:trm
Out[8]:
matrix([[ 0., 0.],
[ 0., 0.]])
In [9]:A
Out[9]:
array([[ 0., 0.],
[ 0., 0.]])
Notice that A has been set to zeros even though "trm is A" returns
False. My guess, without delving deeply into the code, is that in
newcore A and trm are sharing the same array object. expm3 (and
probably many other routines in scipy) depend on B=mat(A) creating a
completely new copy of A. Should this be changed?
More information about the Scipy-dev
mailing list