max@0: // Copyright (C) 2009-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2009-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 glue_solve max@0: //! @{ max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: glue_solve::apply(Mat& out, const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: Mat A = X.A.get_ref(); max@0: max@0: const unwrap_check B_tmp(X.B, out); max@0: const Mat& B = B_tmp.M; max@0: max@0: arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" ); max@0: max@0: bool status; max@0: max@0: if(A.n_rows == A.n_cols) max@0: { max@0: const uword mode = X.aux_uword; max@0: max@0: status = (mode == 0) ? auxlib::solve(out, A, B) : auxlib::solve(out, A, B, true); max@0: } max@0: else max@0: if(A.n_rows > A.n_cols) max@0: { max@0: arma_extra_debug_print("solve(): detected over-determined system"); max@0: status = auxlib::solve_od(out, A, B); max@0: } max@0: else max@0: { max@0: arma_extra_debug_print("solve(): detected under-determined system"); max@0: status = auxlib::solve_ud(out, A, B); max@0: } max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("solve(): solution not found"); max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: glue_solve_tr::apply(Mat& out, const Glue& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: typedef typename T1::elem_type eT; max@0: max@0: const unwrap_check A_tmp(X.A, out); max@0: const unwrap_check B_tmp(X.B, out); max@0: max@0: const Mat& A = A_tmp.M; max@0: const Mat& B = B_tmp.M; max@0: max@0: bool err_state = false; max@0: char* err_msg = 0; max@0: max@0: arma_debug_set_error( err_state, err_msg, ((&A) == (&B)), "solve(): A is an alias of B" ); max@0: arma_debug_set_error( err_state, err_msg, (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" ); max@0: arma_debug_set_error( err_state, err_msg, (A.is_square() == false), "solve(): A is not a square matrix" ); max@0: max@0: arma_debug_check(err_state, err_msg); max@0: max@0: const bool status = auxlib::solve_tr(out, A, B, X.aux_uword); max@0: max@0: if(status == false) max@0: { max@0: out.reset(); max@0: arma_bad("solve(): solution not found"); max@0: } max@0: } max@0: max@0: max@0: max@0: //! @}