max@0
|
1 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2009-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 //! \addtogroup glue_solve
|
max@0
|
15 //! @{
|
max@0
|
16
|
max@0
|
17
|
max@0
|
18
|
max@0
|
19 template<typename T1, typename T2>
|
max@0
|
20 inline
|
max@0
|
21 void
|
max@0
|
22 glue_solve::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve>& X)
|
max@0
|
23 {
|
max@0
|
24 arma_extra_debug_sigprint();
|
max@0
|
25
|
max@0
|
26 typedef typename T1::elem_type eT;
|
max@0
|
27
|
max@0
|
28 Mat<eT> A = X.A.get_ref();
|
max@0
|
29
|
max@0
|
30 const unwrap_check<T2> B_tmp(X.B, out);
|
max@0
|
31 const Mat<eT>& B = B_tmp.M;
|
max@0
|
32
|
max@0
|
33 arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in A and B must be the same" );
|
max@0
|
34
|
max@0
|
35 bool status;
|
max@0
|
36
|
max@0
|
37 if(A.n_rows == A.n_cols)
|
max@0
|
38 {
|
max@0
|
39 const uword mode = X.aux_uword;
|
max@0
|
40
|
max@0
|
41 status = (mode == 0) ? auxlib::solve(out, A, B) : auxlib::solve(out, A, B, true);
|
max@0
|
42 }
|
max@0
|
43 else
|
max@0
|
44 if(A.n_rows > A.n_cols)
|
max@0
|
45 {
|
max@0
|
46 arma_extra_debug_print("solve(): detected over-determined system");
|
max@0
|
47 status = auxlib::solve_od(out, A, B);
|
max@0
|
48 }
|
max@0
|
49 else
|
max@0
|
50 {
|
max@0
|
51 arma_extra_debug_print("solve(): detected under-determined system");
|
max@0
|
52 status = auxlib::solve_ud(out, A, B);
|
max@0
|
53 }
|
max@0
|
54
|
max@0
|
55 if(status == false)
|
max@0
|
56 {
|
max@0
|
57 out.reset();
|
max@0
|
58 arma_bad("solve(): solution not found");
|
max@0
|
59 }
|
max@0
|
60 }
|
max@0
|
61
|
max@0
|
62
|
max@0
|
63
|
max@0
|
64 template<typename T1, typename T2>
|
max@0
|
65 inline
|
max@0
|
66 void
|
max@0
|
67 glue_solve_tr::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve_tr>& X)
|
max@0
|
68 {
|
max@0
|
69 arma_extra_debug_sigprint();
|
max@0
|
70
|
max@0
|
71 typedef typename T1::elem_type eT;
|
max@0
|
72
|
max@0
|
73 const unwrap_check<T1> A_tmp(X.A, out);
|
max@0
|
74 const unwrap_check<T2> B_tmp(X.B, out);
|
max@0
|
75
|
max@0
|
76 const Mat<eT>& A = A_tmp.M;
|
max@0
|
77 const Mat<eT>& B = B_tmp.M;
|
max@0
|
78
|
max@0
|
79 bool err_state = false;
|
max@0
|
80 char* err_msg = 0;
|
max@0
|
81
|
max@0
|
82 arma_debug_set_error( err_state, err_msg, ((&A) == (&B)), "solve(): A is an alias of B" );
|
max@0
|
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" );
|
max@0
|
84 arma_debug_set_error( err_state, err_msg, (A.is_square() == false), "solve(): A is not a square matrix" );
|
max@0
|
85
|
max@0
|
86 arma_debug_check(err_state, err_msg);
|
max@0
|
87
|
max@0
|
88 const bool status = auxlib::solve_tr(out, A, B, X.aux_uword);
|
max@0
|
89
|
max@0
|
90 if(status == false)
|
max@0
|
91 {
|
max@0
|
92 out.reset();
|
max@0
|
93 arma_bad("solve(): solution not found");
|
max@0
|
94 }
|
max@0
|
95 }
|
max@0
|
96
|
max@0
|
97
|
max@0
|
98
|
max@0
|
99 //! @}
|