glue_solve_meat.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2009-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 
00019 template<typename T1, typename T2>
00020 inline
00021 void
00022 glue_solve::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve>& X)
00023   {
00024   arma_extra_debug_sigprint();
00025   
00026   typedef typename T1::elem_type eT;
00027   
00028   Mat<eT> A = X.A.get_ref();
00029   
00030   const unwrap_check<T2> B_tmp(X.B, out);
00031   const Mat<eT>& B = B_tmp.M;
00032   
00033   arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" );
00034   
00035   bool status;
00036   
00037   if(A.n_rows == A.n_cols)
00038     {
00039     const uword mode = X.aux_uword;
00040     
00041     status = (mode == 0) ? auxlib::solve(out, A, B) : auxlib::solve(out, A, B, true);
00042     }
00043   else
00044   if(A.n_rows > A.n_cols)
00045     {
00046     arma_extra_debug_print("solve(): detected over-determined system");
00047     status = auxlib::solve_od(out, A, B);
00048     }
00049   else
00050     {
00051     arma_extra_debug_print("solve(): detected under-determined system");
00052     status = auxlib::solve_ud(out, A, B);
00053     }
00054   
00055   if(status == false)
00056     {
00057     out.reset();
00058     arma_bad("solve(): solution not found");
00059     }
00060   }
00061 
00062 
00063 
00064 template<typename T1, typename T2>
00065 inline
00066 void
00067 glue_solve_tr::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve_tr>& X)
00068   {
00069   arma_extra_debug_sigprint();
00070   
00071   typedef typename T1::elem_type eT;
00072   
00073   const unwrap_check<T1> A_tmp(X.A, out);
00074   const unwrap_check<T2> B_tmp(X.B, out);
00075   
00076   const Mat<eT>& A = A_tmp.M;
00077   const Mat<eT>& B = B_tmp.M;
00078   
00079   bool  err_state = false;
00080   char* err_msg   = 0;
00081   
00082   arma_debug_set_error( err_state, err_msg, ((&A) == (&B)),           "solve(): A is an alias of B" );
00083   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" );
00084   arma_debug_set_error( err_state, err_msg, (A.is_square() == false), "solve(): A is not a square matrix" );
00085   
00086   arma_debug_check(err_state, err_msg);
00087   
00088   const bool status = auxlib::solve_tr(out, A, B, X.aux_uword);
00089   
00090   if(status == false)
00091     {
00092     out.reset();
00093     arma_bad("solve(): solution not found");
00094     }
00095   }
00096 
00097 
00098 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:04