# [Numpy-svn] r3343 - in trunk/numpy: lib linalg

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Oct 16 12:55:33 CDT 2006

```Author: charris
Date: 2006-10-16 12:55:30 -0500 (Mon, 16 Oct 2006)
New Revision: 3343

Modified:
trunk/numpy/lib/polynomial.py
trunk/numpy/linalg/linalg.py
Log:
Fix qr decomposition. The dimensions m,n were taken from the fortran ordered array
instead of from the numpy ordered array and consequently were reversed.

Modified: trunk/numpy/lib/polynomial.py
===================================================================
--- trunk/numpy/lib/polynomial.py	2006-10-16 17:44:09 UTC (rev 3342)
+++ trunk/numpy/lib/polynomial.py	2006-10-16 17:55:30 UTC (rev 3343)
@@ -194,8 +194,8 @@

Returns

-        full == False -- coeficients
-        full == True -- coeficients, residuals, rank, singular values.
+        full == False -- coefficients
+        full == True -- coefficients, residuals, rank, singular values, rcond.

Warns

@@ -309,7 +309,7 @@
c /= vander([scale], order)[0]

if full :
-        return c, resids, rank, s
+        return c, resids, rank, s, rcond
else :
return c

Modified: trunk/numpy/linalg/linalg.py
===================================================================
--- trunk/numpy/linalg/linalg.py	2006-10-16 17:44:09 UTC (rev 3342)
+++ trunk/numpy/linalg/linalg.py	2006-10-16 17:55:30 UTC (rev 3343)
@@ -188,7 +188,7 @@
ind must be a positive integer specifying
how many indices at the front of the array are involved
in the inverse sum.
-
+
the result is ainv with shape a.shape[ind:] + a.shape[:ind]

tensordot(ainv, a, ind) is an identity operator
@@ -266,9 +266,9 @@
part of A2 is R. This is faster if you only need R
"""
_assertRank2(a)
+    m,n = a.shape
t, result_t = _commonType(a)
a = _fastCopyAndTranspose(t, a)
-    m,n = a.shape
mn = min(m,n)
tau = zeros((mn,), t)
if isComplexType(t):
@@ -282,7 +282,7 @@
lwork = 1
work = zeros((lwork,), t)
results=lapack_routine(m, n, a, m, tau, work, -1, 0)
-    if results['info'] > 0:
+    if results['info'] != 0:
raise LinAlgError, '%s returns %d' % (routine_name, results['info'])

# do qr decomposition
@@ -290,23 +290,19 @@
work = zeros((lwork,),t)
results=lapack_routine(m, n, a, m, tau, work, lwork, 0)

-    if results['info'] > 0:
+    if results['info'] != 0:
raise LinAlgError, '%s returns %d' % (routine_name, results['info'])

-    #  atemp: convert fortrag storing order to num storing order
-    atemp = a.transpose()
-
-    if atemp.dtype != result_t:
-        atemp = atemp.astype(result_t)
-
-    #  economic mode
+    #  economic mode. Isn't actually economic.
if mode[0]=='e':
-        return atemp
+        if t != result_t :
+            a = a.astype(result_t)
+        return a.T

#  generate r
-    r = zeros((mn,n), result_t)
+    r = _fastCopyAndTranspose(result_t, a[:,:mn])
for i in range(mn):
-            r[i, i:] = atemp[i, i:]
+        r[i,:i].fill(0.0)

#  'r'-mode, that is, calculate only r
if mode[0]=='r':
@@ -325,22 +321,18 @@
lwork = 1
work=zeros((lwork,), t)
results=lapack_routine(m,mn,mn, a, m, tau, work, -1, 0)
-    if results['info'] > 0:
+    if results['info'] != 0:
raise LinAlgError, '%s returns %d' % (routine_name, results['info'])

# compute q
lwork = int(abs(work[0]))
work=zeros((lwork,), t)
results=lapack_routine(m,mn,mn, a, m, tau, work, lwork, 0)
-
-    if results['info'] > 0:
+    if results['info'] != 0:
raise LinAlgError, '%s returns %d' % (routine_name, results['info'])

-    q = a[:mn,:].transpose()
+    q = _fastCopyAndTranspose(result_t, a[:mn,:])

-    if (q.dtype != result_t):
-        q = q.astype(result_t)
-
return q,r

```