def eigenvectors(a): """eigenvectors(a) returns u,v where u is the eigenvalues and v is a matrix of eigenvectors with vector v[i] corresponds to eigenvalue u[i]. Satisfies the equation dot(a, v[i]) = u[i]*v[i] """ _assertRank2(a) _assertSquareness(a) t =_commonType(a) real_t = _array_type[0][_array_precision[t]] a = _fastCopyAndTranspose(t, a) n = a.getshape()[0] dummy = num.zeros((1,), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite2.zgeev w = num.zeros((n,), t) v = num.zeros((n,n), t) lwork = 1 work = num.zeros((lwork,),t) rwork = num.zeros((2*n,),real_t) results = lapack_routine('N', 'V', n, a, n, w, dummy, 1, v, n, work, -1, rwork, 0) lwork = int(abs(work[0])) work = num.zeros((lwork,),t) results = lapack_routine('N', 'V', n, a, n, w, dummy, 1, v, n, work, lwork, rwork, 0) else: lapack_routine = lapack_lite2.dgeev wr = num.zeros((n,), t) wi = num.zeros((n,), t) vr = num.zeros((n,n), t) lwork = 1 work = num.zeros((lwork,),t) results = lapack_routine('N', 'V', n, a, n, wr, wi, dummy, 1, vr, n, work, -1, 0) lwork = int(work[0]) work = num.zeros((lwork,),t) results = lapack_routine('N', 'V', n, a, n, wr, wi, dummy, 1, vr, n, work, lwork, 0) if num.logical_and.reduce(num.equal(wi, 0.)): w = wr v = vr else: w = wr+1j*wi v = num.array(vr,type=num.Complex) ind = num.nonzero( num.equal( num.equal(wi,0.0) # true for real e-vals ,0) # true for complex e-vals ) # indices of complex e-vals for i in range(len(ind)/2): v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]] v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]] if results['info'] > 0: raise LinAlgError, 'Eigenvalues did not converge' return w,v
def eigenvalues(a): _assertRank2(a) _assertSquareness(a) t =_commonType(a) real_t = _array_type[0][_array_precision[t]] a = _fastCopyAndTranspose(t, a) n = a.getshape()[0] dummy = num.zeros((1,), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite2.zgeev w = num.zeros((n,), t) rwork = num.zeros((n,),real_t) lwork = 1 work = num.zeros((lwork,), t) results = lapack_routine('N', 'N', n, a, n, w, dummy, 1, dummy, 1, work, -1, rwork, 0) lwork = int(abs(work[0])) work = num.zeros((lwork,), t) results = lapack_routine('N', 'N', n, a, n, w, dummy, 1, dummy, 1, work, lwork, rwork, 0) else: lapack_routine = lapack_lite2.dgeev wr = num.zeros((n,), t) wi = num.zeros((n,), t) lwork = 1 work = num.zeros((lwork,), t) results = lapack_routine('N', 'N', n, a, n, wr, wi, dummy, 1, dummy, 1, work, -1, 0) lwork = int(work[0]) work = num.zeros((lwork,), t) results = lapack_routine('N', 'N', n, a, n, wr, wi, dummy, 1, dummy, 1, work, lwork, 0) if num.logical_and.reduce(num.equal(wi, 0.)): w = wr else: w = wr+1j*wi if results['info'] > 0: raise LinAlgError, 'Eigenvalues did not converge' return w