"Fossies" - the Fresh Open Source Software Archive

Member "armadillo-9.800.3/include/armadillo_bits/fn_mvnrnd.hpp" (16 Jun 2016, 2729 Bytes) of package /linux/misc/armadillo-9.800.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fn_mvnrnd.hpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
    2 // Copyright 2008-2016 National ICT Australia (NICTA)
    3 // 
    4 // Licensed under the Apache License, Version 2.0 (the "License");
    5 // you may not use this file except in compliance with the License.
    6 // You may obtain a copy of the License at
    7 // http://www.apache.org/licenses/LICENSE-2.0
    8 // 
    9 // Unless required by applicable law or agreed to in writing, software
   10 // distributed under the License is distributed on an "AS IS" BASIS,
   11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 // See the License for the specific language governing permissions and
   13 // limitations under the License.
   14 // ------------------------------------------------------------------------
   15 
   16 
   17 //! \addtogroup fn_mvnrnd
   18 //! @{
   19 
   20 
   21 
   22 template<typename T1, typename T2>
   23 arma_warn_unused
   24 inline
   25 typename
   26 enable_if2
   27   <
   28   is_real<typename T1::elem_type>::value,
   29   const Glue<T1, T2, glue_mvnrnd_vec>
   30   >::result
   31 mvnrnd(const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C)
   32   {
   33   arma_extra_debug_sigprint();
   34   
   35   return Glue<T1, T2, glue_mvnrnd_vec>(M.get_ref(), C.get_ref());
   36   }
   37 
   38 
   39 
   40 template<typename T1, typename T2>
   41 arma_warn_unused
   42 inline
   43 typename
   44 enable_if2
   45   <
   46   is_real<typename T1::elem_type>::value,
   47   const Glue<T1, T2, glue_mvnrnd>
   48   >::result
   49 mvnrnd(const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C, const uword N)
   50   {
   51   arma_extra_debug_sigprint();
   52   
   53   return Glue<T1, T2, glue_mvnrnd>(M.get_ref(), C.get_ref(), N);
   54   }
   55 
   56 
   57 
   58 template<typename T1, typename T2>
   59 arma_warn_unused
   60 inline
   61 typename
   62 enable_if2
   63   <
   64   is_real<typename T1::elem_type>::value,
   65   bool
   66   >::result
   67 mvnrnd(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C)
   68   {
   69   arma_extra_debug_sigprint();
   70   
   71   const bool status = glue_mvnrnd::apply_direct(out, M.get_ref(), C.get_ref(), uword(1));
   72   
   73   if(status == false)
   74     {
   75     arma_debug_warn("mvnrnd(): given covariance matrix is not symmetric positive semi-definite");
   76     return false;
   77     }
   78   
   79   return true;
   80   }
   81 
   82 
   83 
   84 template<typename T1, typename T2>
   85 arma_warn_unused
   86 inline
   87 typename
   88 enable_if2
   89   <
   90   is_real<typename T1::elem_type>::value,
   91   bool
   92   >::result
   93 mvnrnd(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type, T1>& M, const Base<typename T1::elem_type, T2>& C, const uword N)
   94   {
   95   arma_extra_debug_sigprint();
   96   
   97   const bool status = glue_mvnrnd::apply_direct(out, M.get_ref(), C.get_ref(), N);
   98   
   99   if(status == false)
  100     {
  101     arma_debug_warn("mvnrnd(): given covariance matrix is not symmetric positive semi-definite");
  102     return false;
  103     }
  104   
  105   return true;
  106   }
  107 
  108 
  109 
  110 //! @}