Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-2.4.4/include/armadillo_bits/fn_log_det.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) 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 | |
14 //! \addtogroup fn_log_det | |
15 //! @{ | |
16 | |
17 | |
18 | |
19 //! log determinant of mat | |
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, | |
27 const Base<typename T1::elem_type,T1>& X, | |
28 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
29 ) | |
30 { | |
31 arma_extra_debug_sigprint(); | |
32 arma_ignore(junk); | |
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, | |
47 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0 | |
48 ) | |
49 { | |
50 arma_extra_debug_sigprint(); | |
51 arma_ignore(junk); | |
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 | |
87 //! @} |