def invtr(A, overwrite=False, lower=False): """Compute the inverse of a triangular matrix Uses the corresponding LAPACK routine. Parameters ---------- A : ndarray An upper or lower triangular matrix. overwrite : bool Whether to overwrite the input array (may increase performance). lower : bool Whether the input array is lower-triangular, rather than upper-triangular. Returns ------- inv_A : ndarray The inverse of A, which is also triangular. """ trtri, = la.lapack.get_lapack_funcs(('trtri', ), (A, )) inv_A, info = trtri(A, lower=lower, overwrite_c=overwrite) if info > 0: raise sp.LinAlgError("%d-th diagonal element of the matrix is zero" % info) if info < 0: raise ValueError('illegal value in %d-th argument of internal potri' % -info) return inv_A
def invpo(A, out=None, lower=False): """Efficient inversion of positive definite matrices using Cholesky decomposition. NOT YET WORKING """ t = la.cholesky(A, lower=lower) print sp.allclose(sp.dot(H(t), t), A) #a, lower = la.cho_factor(A, lower=lower) #no.. we need a clean answer, it seems potri, = la.lapack.get_lapack_funcs(('potri',), (A,)) inv_A, info = potri(t, lower=lower, overwrite_c=1, rowmajor=1) #rowmajor (C-order) is the default... if info > 0: raise sp.LinAlgError("%d-th diagonal element of the Cholesky factor is zero" % info) if info < 0: raise ValueError('illegal value in %d-th argument of internal potri' % -info) return inv_A