op_inv_meat.hpp
Go to the documentation of this file.
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 
16 
17 
19 template<typename eT>
20 inline
21 void
22 op_inv::apply(Mat<eT>& out, const Mat<eT>& A, const bool slow)
23  {
25 
26  // no need to check for aliasing, due to:
27  // - auxlib::inv() copies A to out before inversion
28  // - for 2x2 and 3x3 matrices the code is alias safe
29 
30  bool status = auxlib::inv(out, A, slow);
31 
32  if(status == false)
33  {
34  out.reset();
35  arma_bad("inv(): matrix appears to be singular");
36  }
37  }
38 
39 
40 
42 template<typename T1>
43 inline
44 void
46  {
48 
49  typedef typename T1::elem_type eT;
50 
51  const strip_diagmat<T1> strip(X.m);
52 
53  if(strip.do_diagmat == true)
54  {
55  op_inv::apply_diag(out, strip.M);
56  }
57  else
58  {
59  const uword mode = X.aux_uword_a;
60 
61  const bool status = (mode == 0) ? auxlib::inv(out, X.m) : auxlib::inv(out, X.m, true);
62 
63  if(status == false)
64  {
65  out.reset();
66  arma_bad("inv(): matrix appears to be singular");
67  }
68  }
69  }
70 
71 
72 
73 template<typename T1>
74 inline
75 void
77  {
79 
80  typedef typename T1::elem_type eT;
81 
82  const diagmat_proxy_check<T1> A(X.get_ref(), out);
83 
84  const uword N = A.n_elem;
85 
86  out.set_size(N,N);
87 
88  for(uword col=0; col<N; ++col)
89  {
90  for(uword row=0; row<col; ++row) { out.at(row,col) = eT(0); }
91 
92  out.at(col,col) = eT(1) / A[col];
93 
94  for(uword row=col+1; row<N; ++row) { out.at(row,col) = eT(0); }
95  }
96 
97  }
98 
99 
100 
102 template<typename T1>
103 inline
104 void
106  {
108 
109  const bool status = auxlib::inv_tr(out, X.m, X.aux_uword_a);
110 
111  if(status == false)
112  {
113  out.reset();
114  arma_bad("inv(): matrix appears to be singular");
115  }
116  }
117 
118 
119 
121 template<typename T1>
122 inline
123 void
125  {
127 
128  const bool status = auxlib::inv_sympd(out, X.m, X.aux_uword_a);
129 
130  if(status == false)
131  {
132  out.reset();
133  arma_bad("inv(): matrix appears to be singular");
134  }
135  }
136 
137 
138 
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
Definition: Mat_meat.hpp:4211
arma_inline const derived & get_ref() const
Definition: Base_meat.hpp:22
arma_aligned const T1 & m
storage of reference to the operand (eg. a matrix)
Definition: Op_bones.hpp:45
u32 uword
Definition: typedef.hpp:85
static const bool do_diagmat
Definition: strip.hpp:30
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_inv_sympd > &in)
inverse of T1 (symmetric positive definite matrices)
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
Definition: Mat_meat.hpp:3692
static bool inv(Mat< eT > &out, const Base< eT, T1 > &X, const bool slow=false)
immediate matrix inverse
Definition: auxlib_meat.hpp:26
static void apply(Mat< typename T1::elem_type > &out, const Op< T1, op_inv_tr > &in)
inverse of T1 (triangular matrices)
void reset()
Definition: Mat_meat.hpp:4553
const T1 & M
Definition: strip.hpp:32
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
static void apply(Mat< eT > &out, const Mat< eT > &A, const bool slow=false)
immediate inverse of a matrix, storing the result in a dense matrix
Definition: op_inv_meat.hpp:22
static void apply_diag(Mat< typename T1::elem_type > &out, const Base< typename T1::elem_type, T1 > &X)
Definition: op_inv_meat.hpp:76
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
Dense matrix class.
static bool inv_sympd(Mat< eT > &out, const Base< eT, T1 > &X, const uword layout)
arma_aligned uword aux_uword_a
storage of auxiliary data, uword format
Definition: Op_bones.hpp:47
static bool inv_tr(Mat< eT > &out, const Base< eT, T1 > &X, const uword layout)


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