max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup op_inv max@0: //! @{ max@0: max@0: max@0: //! immediate inverse of a matrix, storing the result in a dense matrix max@0: template max@0: inline max@0: void max@0: op_inv::apply(Mat& out, const Mat& A, const bool slow) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // no need to check for aliasing, due to: max@0: // - auxlib::inv() copies A to out before inversion max@0: // - for 2x2 and 3x3 matrices the code is alias safe max@0: max@0: bool status = auxlib::inv(out, A, slow); max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("inv(): matrix appears to be singular"); max@0: } max@0: } max@0: max@0: max@0: max@0: //! immediate inverse of T1, storing the result in a dense matrix max@0: template max@0: inline max@0: void max@0: op_inv::apply(Mat& out, const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const strip_diagmat strip(X.m); max@0: max@0: if(strip.do_diagmat == true) max@0: { max@0: op_inv::apply_diag(out, strip.M); max@0: } max@0: else max@0: { max@0: const uword mode = X.aux_uword_a; max@0: max@0: const bool status = (mode == 0) ? auxlib::inv(out, X.m) : auxlib::inv(out, X.m, true); max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("inv(): matrix appears to be singular"); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: op_inv::apply_diag(Mat& out, const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const diagmat_proxy_check A(X.get_ref(), out); max@0: max@0: const uword N = A.n_elem; max@0: max@0: out.set_size(N,N); max@0: max@0: for(uword col=0; col max@0: inline max@0: void max@0: op_inv_tr::apply(Mat& out, const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool status = auxlib::inv_tr(out, X.m, X.aux_uword_a); max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("inv(): matrix appears to be singular"); max@0: } max@0: } max@0: max@0: max@0: max@0: //! inverse of T1 (symmetric positive definite matrices) max@0: template max@0: inline max@0: void max@0: op_inv_sympd::apply(Mat& out, const Op& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool status = auxlib::inv_sympd(out, X.m, X.aux_uword_a); max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("inv(): matrix appears to be singular"); max@0: } max@0: } max@0: max@0: max@0: max@0: //! @}