[Scipy-svn] r3911 - in trunk/scipy/sparse: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat Feb 9 16:28:47 EST 2008
Author: wnbell
Date: 2008-02-09 15:28:39 -0600 (Sat, 09 Feb 2008)
New Revision: 3911
Modified:
trunk/scipy/sparse/base.py
trunk/scipy/sparse/construct.py
trunk/scipy/sparse/tests/test_base.py
trunk/scipy/sparse/tests/test_construct.py
Log:
deprecated speye and spidentity in favor of sparse.eye and sparse.identity
Modified: trunk/scipy/sparse/base.py
===================================================================
--- trunk/scipy/sparse/base.py 2008-02-09 21:02:27 UTC (rev 3910)
+++ trunk/scipy/sparse/base.py 2008-02-09 21:28:39 UTC (rev 3911)
@@ -267,8 +267,8 @@
raise ValueError,'exponent must be >= 0'
if other == 0:
- from construct import spidentity
- return spidentity( self.shape[0], dtype=self.dtype )
+ from construct import identity
+ return identity( self.shape[0], dtype=self.dtype )
elif other == 1:
return self.copy()
else:
Modified: trunk/scipy/sparse/construct.py
===================================================================
--- trunk/scipy/sparse/construct.py 2008-02-09 21:02:27 UTC (rev 3910)
+++ trunk/scipy/sparse/construct.py 2008-02-09 21:28:39 UTC (rev 3911)
@@ -1,8 +1,8 @@
""" Functions to construct sparse matrices
"""
+__all__ = [ 'spdiags', 'eye', 'identity', 'kron', 'kronsum', 'bmat' ]
-__all__ = [ 'spdiags','speye','spidentity', 'spkron', 'kron', 'kronsum', 'bmat', 'lil_eye', 'lil_diags' ]
from itertools import izip
from warnings import warn
@@ -57,8 +57,8 @@
"""
return dia_matrix((data, diags), shape=(m,n)).asformat(format)
-def spidentity(n, dtype='d', format=None):
- """spidentity(n) returns an (n x n) identity matrix"""
+def identity(n, dtype='d', format=None):
+ """identity(n) returns a sparse (n x n) identity matrix"""
if format in ['csr','csc']:
indptr = arange(n+1, dtype=intc)
indices = arange(n, dtype=intc)
@@ -69,16 +69,15 @@
row = arange(n, dtype=intc)
col = arange(n, dtype=intc)
data = ones(n, dtype=dtype)
- cls = eval('%s_matrix' % format)
return coo_matrix((data,(row,col)),(n,n))
else:
- return spidentity( n, dtype=dtype, format='csr').asformat(format)
+ return identity( n, dtype=dtype, format='csr').asformat(format)
-def speye(m, n, k=0, dtype='d', format=None):
- """speye(m, n) returns an (m x n) matrix where the k-th diagonal
+def eye(m, n, k=0, dtype='d', format=None):
+ """eye(m, n) returns a sparse (m x n) matrix where the k-th diagonal
is all ones and everything else is zeros.
"""
- diags = ones((1, m), dtype = dtype)
+ diags = ones((1, m), dtype=dtype)
return spdiags(diags, k, m, n).asformat(format)
def kron(A, B, format=None):
@@ -194,8 +193,8 @@
dtype = upcast(A.dtype,B.dtype)
- L = kron(spidentity(B.shape[0],dtype=dtype), A, format=format)
- R = kron(B, spidentity(A.shape[0],dtype=dtype), format=format)
+ L = kron(identity(B.shape[0],dtype=dtype), A, format=format)
+ R = kron(B, identity(A.shape[0],dtype=dtype), format=format)
return (L+R).asformat(format) #since L + R is not always same format
@@ -307,10 +306,16 @@
#################################
# Deprecated functions
################################
+
+__all__ += [ 'speye','spidentity', 'spkron', 'lil_eye', 'lil_diags' ]
+
from numpy import deprecate
-spkron = deprecate(kron, oldname='spkron', newname='kron')
+spkron = deprecate(kron, oldname='spkron', newname='kron')
+speye = deprecate(eye, oldname='speye', newname='eye')
+spidentity = deprecate(identity, oldname='spidenitiy', newname='identity')
+
def lil_eye((r,c), k=0, dtype='d'):
"""Generate a lil_matrix of dimensions (r,c) with the k-th
diagonal set to 1.
@@ -326,9 +331,10 @@
- data-type of the output array.
"""
- warn("lil_eye is deprecated. use speye(... , format='lil') instead", \
+ warn("lil_eye is deprecated." \
+ "use scipy.sparse.eye(r, c, k, format='lil') instead", \
DeprecationWarning)
- return speye(r,c,k,dtype=dtype,format='lil')
+ return eye(r,c,k,dtype=dtype,format='lil')
Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py 2008-02-09 21:02:27 UTC (rev 3910)
+++ trunk/scipy/sparse/tests/test_base.py 2008-02-09 21:28:39 UTC (rev 3911)
@@ -25,7 +25,7 @@
import scipy.sparse as sparse
from scipy.sparse import csc_matrix, csr_matrix, dok_matrix, \
coo_matrix, lil_matrix, dia_matrix, bsr_matrix, \
- speye, SparseEfficiencyWarning
+ eye, SparseEfficiencyWarning
from scipy.sparse.sputils import supported_dtypes
from scipy.splinalg import splu
@@ -1147,7 +1147,7 @@
def test_lil_sequence_assignement(self):
A = lil_matrix((4,3))
- B = speye(3,4,format='lil')
+ B = eye(3,4,format='lil')
i0 = [0,1,2]
i1 = (0,1,2)
Modified: trunk/scipy/sparse/tests/test_construct.py
===================================================================
--- trunk/scipy/sparse/tests/test_construct.py 2008-02-09 21:02:27 UTC (rev 3910)
+++ trunk/scipy/sparse/tests/test_construct.py 2008-02-09 21:28:39 UTC (rev 3911)
@@ -61,20 +61,24 @@
def test_identity(self):
- a = spidentity(3)
+ a = identity(3)
b = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='d')
assert_array_equal(a.toarray(), b)
+ a = identity(1)
+ b = array([[1]], dtype='d')
+ assert_array_equal(a.toarray(), b)
+
def test_eye(self):
- a = speye(2, 3 )
+ a = eye(2, 3 )
b = array([[1, 0, 0], [0, 1, 0]], dtype='d')
assert_array_equal(a.toarray(), b)
- a = speye(3, 2)
+ a = eye(3, 2)
b = array([[1, 0], [0, 1], [0, 0]], dtype='d')
assert_array_equal( a.toarray(), b)
- a = speye(3, 3)
+ a = eye(3, 3)
b = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='d')
assert_array_equal(a.toarray(), b)
More information about the Scipy-svn
mailing list