glue_solve_meat.hpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2009-2011 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12 
13 
16 
17 
18 
19 template<typename T1, typename T2>
20 inline
21 void
23  {
25 
26  typedef typename T1::elem_type eT;
27 
28  Mat<eT> A = X.A.get_ref();
29 
30  const unwrap_check<T2> B_tmp(X.B, out);
31  const Mat<eT>& B = B_tmp.M;
32 
33  arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" );
34 
35  bool status;
36 
37  if(A.n_rows == A.n_cols)
38  {
39  const uword mode = X.aux_uword;
40 
41  status = (mode == 0) ? auxlib::solve(out, A, B) : auxlib::solve(out, A, B, true);
42  }
43  else
44  if(A.n_rows > A.n_cols)
45  {
46  arma_extra_debug_print("solve(): detected over-determined system");
47  status = auxlib::solve_od(out, A, B);
48  }
49  else
50  {
51  arma_extra_debug_print("solve(): detected under-determined system");
52  status = auxlib::solve_ud(out, A, B);
53  }
54 
55  if(status == false)
56  {
57  out.reset();
58  arma_bad("solve(): solution not found");
59  }
60  }
61 
62 
63 
64 template<typename T1, typename T2>
65 inline
66 void
68  {
70 
71  typedef typename T1::elem_type eT;
72 
73  const unwrap_check<T1> A_tmp(X.A, out);
74  const unwrap_check<T2> B_tmp(X.B, out);
75 
76  const Mat<eT>& A = A_tmp.M;
77  const Mat<eT>& B = B_tmp.M;
78 
79  bool err_state = false;
80  char* err_msg = 0;
81 
82  arma_debug_set_error( err_state, err_msg, ((&A) == (&B)), "solve(): A is an alias of B" );
83  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" );
84  arma_debug_set_error( err_state, err_msg, (A.is_square() == false), "solve(): A is not a square matrix" );
85 
86  arma_debug_check(err_state, err_msg);
87 
88  const bool status = auxlib::solve_tr(out, A, B, X.aux_uword);
89 
90  if(status == false)
91  {
92  out.reset();
93  arma_bad("solve(): solution not found");
94  }
95  }
96 
97 
98 
static bool solve_tr(Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B, const uword layout)
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_solve > &X)
static void apply(Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_solve_tr > &X)
#define arma_debug_set_error
Definition: debug.hpp:1085
const uword n_cols
number of columns in the matrix (read-only)
Definition: Mat_bones.hpp:30
const uword n_rows
number of rows in the matrix (read-only)
Definition: Mat_bones.hpp:29
#define arma_extra_debug_print
Definition: debug.hpp:1118
static bool solve(Mat< eT > &out, Mat< eT > &A, const Mat< eT > &B, const bool slow=false)
u32 uword
Definition: typedef.hpp:85
#define arma_debug_check
Definition: debug.hpp:1084
const T1 & A
first operand
Definition: Glue_bones.hpp:44
arma_inline arma_warn_unused bool is_square() const
returns true if the object has the same number of non-zero rows and columnns
Definition: Mat_meat.hpp:3860
const T2 & B
second operand
Definition: Glue_bones.hpp:45
void reset()
Definition: Mat_meat.hpp:4553
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
void arma_cold arma_bad(const T1 &x, const bool hurl=true)
print a message to get_stream_err2() and/or throw a run-time error exception
Definition: debug.hpp:150
static bool solve_ud(Mat< eT > &out, Mat< eT > &A, const Mat< eT > &B)
Dense matrix class.
const Mat< eT > M
Definition: unwrap.hpp:142
static bool solve_od(Mat< eT > &out, Mat< eT > &A, const Mat< eT > &B)
uword aux_uword
storage of auxiliary data, uword format
Definition: Glue_bones.hpp:46


armadillo_matrix
Author(s):
autogenerated on Fri Apr 16 2021 02:31:57