comparison armadillo-2.4.4/include/armadillo_bits/fn_inv.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) 2008-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-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 fn_inv
15 //! @{
16
17
18
19 //! delayed matrix inverse (general matrices)
20 template<typename T1>
21 arma_inline
22 const Op<T1, op_inv>
23 inv
24 (
25 const Base<typename T1::elem_type,T1>& X,
26 const bool slow = false,
27 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
28 )
29 {
30 arma_extra_debug_sigprint();
31 arma_ignore(junk);
32
33 return Op<T1, op_inv>(X.get_ref(), ((slow == false) ? 0 : 1), 0);
34 }
35
36
37
38 //! remove the inverse operation if applied twice consecutively
39 template<typename T1>
40 arma_inline
41 const T1&
42 inv(const Op<T1, op_inv>& X, const bool slow = false)
43 {
44 arma_extra_debug_sigprint();
45 arma_ignore(slow);
46
47 return X.m;
48 }
49
50
51
52 //! delayed matrix inverse (triangular matrices)
53 template<typename T1>
54 arma_inline
55 const Op<T1, op_inv_tr>
56 inv
57 (
58 const Op<T1, op_trimat>& X,
59 const bool slow = false,
60 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
61 )
62 {
63 arma_extra_debug_sigprint();
64 arma_ignore(slow);
65 arma_ignore(junk);
66
67 return Op<T1, op_inv_tr>(X.m, X.aux_uword_a, 0);
68 }
69
70
71
72 //! delayed matrix inverse (symmetric positive definite matrices)
73 template<typename T1>
74 arma_inline
75 const Op<T1, op_inv_sympd>
76 inv
77 (
78 const Op<T1, op_sympd>& X,
79 const bool slow = false,
80 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
81 )
82 {
83 arma_extra_debug_sigprint();
84 arma_ignore(slow);
85 arma_ignore(junk);
86
87 return Op<T1, op_inv_sympd>(X.m, 0, 0);
88 }
89
90
91
92 template<typename T1>
93 inline
94 bool
95 inv
96 (
97 Mat<typename T1::elem_type>& out,
98 const Base<typename T1::elem_type,T1>& X,
99 const bool slow = false,
100 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
101 )
102 {
103 arma_extra_debug_sigprint();
104 arma_ignore(junk);
105
106 try
107 {
108 out = inv(X,slow);
109 }
110 catch(std::runtime_error&)
111 {
112 return false;
113 }
114
115 return true;
116 }
117
118
119
120 //! @}