[Scipy-svn] r5054 - in trunk/scipy/sparse: . tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Mon Nov 10 14:01:16 EST 2008
Author: wnbell
Date: 2008-11-10 13:01:13 -0600 (Mon, 10 Nov 2008)
New Revision: 5054
Modified:
trunk/scipy/sparse/construct.py
trunk/scipy/sparse/sputils.py
trunk/scipy/sparse/tests/test_construct.py
Log:
fixed bug in eye(1,1) caused by isshape([[1]]) returning True
Modified: trunk/scipy/sparse/construct.py
===================================================================
--- trunk/scipy/sparse/construct.py 2008-11-10 17:48:25 UTC (rev 5053)
+++ trunk/scipy/sparse/construct.py 2008-11-10 19:01:13 UTC (rev 5054)
@@ -103,7 +103,8 @@
"""eye(m, n) returns a sparse (m x n) matrix where the k-th diagonal
is all ones and everything else is zeros.
"""
- diags = np.ones((1, m), dtype=dtype)
+ m,n = int(m),int(n)
+ diags = np.ones((1, min(m,n)), dtype=dtype)
return spdiags(diags, k, m, n).asformat(format)
def kron(A, B, format=None):
@@ -111,10 +112,10 @@
Parameters
----------
- A
- matrix
- B
- matrix
+ A : sparse or dense matrix
+ first matrix of the product
+ B : sparse or dense matrix
+ second matrix of the product
format : string
format of the result (e.g. "csr")
Modified: trunk/scipy/sparse/sputils.py
===================================================================
--- trunk/scipy/sparse/sputils.py 2008-11-10 17:48:25 UTC (rev 5053)
+++ trunk/scipy/sparse/sputils.py 2008-11-10 19:01:13 UTC (rev 5054)
@@ -99,12 +99,14 @@
try:
# Assume it's a tuple of matrix dimensions (M, N)
(M, N) = x
- assert isintlike(M) and isintlike(N) # raises TypeError unless integers
- #assert M > 0 and N > 0
- except (ValueError, TypeError, AssertionError):
+ except:
return False
else:
- return True
+ if isintlike(M) and isintlike(N):
+ if np.rank(M) == 0 and np.rank(N) == 0:
+ return True
+ return False
+
def issequence(t):
return isinstance(t, (list, tuple))\
Modified: trunk/scipy/sparse/tests/test_construct.py
===================================================================
--- trunk/scipy/sparse/tests/test_construct.py 2008-11-10 17:48:25 UTC (rev 5053)
+++ trunk/scipy/sparse/tests/test_construct.py 2008-11-10 19:01:13 UTC (rev 5054)
@@ -76,18 +76,13 @@
assert_equal( I.toarray(), [[1,0,0],[0,1,0],[0,0,1]])
def test_eye(self):
- a = eye(2, 3 )
- b = array([[1, 0, 0], [0, 1, 0]], dtype='d')
- assert_array_equal(a.toarray(), b)
+ assert_equal(eye(1,1).toarray(), [[1]])
+ assert_equal(eye(2,3).toarray(), [[1,0,0],[0,1,0]])
+ assert_equal(eye(3,2).toarray(), [[1,0],[0,1],[0,0]])
+ assert_equal(eye(3,3).toarray(), [[1,0,0],[0,1,0],[0,0,1]])
- a = eye(3, 2)
- b = array([[1, 0], [0, 1], [0, 0]], dtype='d')
- assert_array_equal( a.toarray(), b)
+ assert_equal(eye(3,3,dtype='int16').dtype, 'int16')
- a = eye(3, 3)
- b = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype='d')
- assert_array_equal(a.toarray(), b)
-
def test_kron(self):
cases = []
More information about the Scipy-svn
mailing list