fn_log_det.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2010-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2010-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 
00020 template<typename T1>
00021 inline
00022 bool
00023 log_det
00024   (
00025         typename T1::elem_type&          out_val,
00026         typename T1::pod_type&           out_sign,
00027   const Base<typename T1::elem_type,T1>& X,
00028   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00029   )
00030   {
00031   arma_extra_debug_sigprint();
00032   arma_ignore(junk);
00033   
00034   return auxlib::log_det(out_val, out_sign, X);
00035   }
00036 
00037 
00038 
00039 template<typename T1>
00040 inline
00041 void
00042 log_det
00043   (
00044         typename T1::elem_type& out_val,
00045         typename T1::pod_type&  out_sign,
00046   const Op<T1,op_diagmat>&      X,
00047   const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
00048   )
00049   {
00050   arma_extra_debug_sigprint();
00051   arma_ignore(junk);
00052   
00053   typedef typename T1::elem_type eT;
00054   typedef typename T1::pod_type   T;
00055   
00056   const diagmat_proxy<T1> A(X.m);
00057   
00058   const uword N = A.n_elem;
00059   
00060   if(N == 0)
00061     {
00062     out_val  = eT(0);
00063     out_sign =  T(1);
00064     
00065     return;
00066     }
00067   
00068   const eT x = A[0];
00069   
00070   T  sign = (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1;
00071   eT val  = (is_complex<eT>::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
00072   
00073   for(uword i=1; i<N; ++i)
00074     {
00075     const eT x = A[i];
00076     
00077     sign *= (is_complex<eT>::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1;
00078     val  += (is_complex<eT>::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x);
00079     }
00080   
00081   out_val  = val;
00082   out_sign = sign;
00083   }
00084 
00085 
00086 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:04