fn_log_det.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
2 // Copyright (C) 2010-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 
20 template<typename T1>
21 inline
22 bool
23 log_det
24  (
25  typename T1::elem_type& out_val,
26  typename T1::pod_type& out_sign,
29  )
30  {
33 
34  return auxlib::log_det(out_val, out_sign, X);
35  }
36 
37 
38 
39 template<typename T1>
40 inline
41 void
42 log_det
43  (
44  typename T1::elem_type& out_val,
45  typename T1::pod_type& out_sign,
46  const Op<T1,op_diagmat>& X,
48  )
49  {
52 
53  typedef typename T1::elem_type eT;
54  typedef typename T1::pod_type T;
55 
56  const diagmat_proxy<T1> A(X.m);
57 
58  const uword N = A.n_elem;
59 
60  if(N == 0)
61  {
62  out_val = eT(0);
63  out_sign = T(1);
64 
65  return;
66  }
67 
68  const eT x = A[0];
69 
70  T sign = (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1;
71  eT val = (is_complex<eT>::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
72 
73  for(uword i=1; i<N; ++i)
74  {
75  const eT x = A[i];
76 
77  sign *= (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1;
78  val += (is_complex<eT>::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
79  }
80 
81  out_val = val;
82  out_sign = sign;
83  }
84 
85 
86 
static arma_inline const eT & tmp_real(const eT &X)
internal function to obtain the real part of either a plain number or a complex number ...
Definition: access.hpp:26
const uword n_elem
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
#define arma_ignore(variable)
bool log_det(typename T1::elem_type &out_val, typename T1::pod_type &out_sign, const Base< typename T1::elem_type, T1 > &X, const typename arma_blas_type_only< typename T1::elem_type >::result *junk=0)
log determinant of mat
Definition: fn_log_det.hpp:24
#define arma_extra_debug_sigprint
Definition: debug.hpp:1116
static bool log_det(eT &out_val, typename get_pod_type< eT >::result &out_sign, const Base< eT, T1 > &X)
immediate log determinant of a matrix using ATLAS or LAPACK
arma_inline const eOp< T1, eop_log > log(const Base< typename T1::elem_type, T1 > &A)
Definition: fn_elem.hpp:156


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