Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/glue_solve_meat.hpp @ 0:8b6102e2a9b0
Armadillo Library
author | maxzanoni76 <max.zanoni@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 09:27:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b6102e2a9b0 |
---|---|
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 | |
14 //! \addtogroup glue_solve | |
15 //! @{ | |
16 | |
17 | |
18 | |
19 template<typename T1, typename T2> | |
20 inline | |
21 void | |
22 glue_solve::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve>& X) | |
23 { | |
24 arma_extra_debug_sigprint(); | |
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 | |
67 glue_solve_tr::apply(Mat<typename T1::elem_type>& out, const Glue<T1,T2,glue_solve_tr>& X) | |
68 { | |
69 arma_extra_debug_sigprint(); | |
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 | |
99 //! @} |