def matrix_powers(m): """Generates infinite sequence of matrix powers, starting from m^0""" yield eye(len(m)) # m^0 yield m # m^1 m_i = mmul(m, m) while True: yield m_i m_i = mmul(m_i, m)
def matrix_powers(m): """Generates infinite sequence of matrix powers, starting from m^0""" yield eye(len(m)) # m^0 yield m # m^1 m_i = mmul( m, m ) while True: yield m_i m_i = mmul( m_i, m )
def qr_inverse(M, context=FloatContext, eps=1e-14): """Matrix inverse, using QR transformation""" n, n_ = shape_mat(M) assert (n == n_) IQ, R = qrl_givens(M, context=context, eps=eps, inverse_q=True) IR = ltri_inverse(R, context=context) return mmul(IR, IQ)
def qr_inverse( M, context=FloatContext, eps=1e-14): """Matrix inverse, using QR transformation""" n,n_ = shape_mat(M) assert(n==n_) IQ,R = qrl_givens(M, context=context, eps=eps, inverse_q = True) IR = ltri_inverse(R, context=context) return mmul( IR, IQ )