fn_diagmat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup fn_diagmat
00017 //! @{
00018 
00019 
00020 //! interpret a mat as a diagonal matrix (i.e. off-diagonal entries are zero)
00021 template<typename eT, typename T1>
00022 inline
00023 const Op<T1, op_diagmat>
00024 diagmat(const Base<eT,T1>& X)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   return Op<T1, op_diagmat>(X.get_ref());
00029   }
00030 
00031 
00032 
00033 //! interpret a colvec as a diagonal matrix
00034 template<typename eT>
00035 inline
00036 const Op<Mat<eT>, op_diagmat_vec>
00037 diagmat(const Col<eT>& X)
00038   {
00039   arma_extra_debug_sigprint();
00040   
00041   return Op<Mat<eT>, op_diagmat_vec>(X);
00042   }
00043 
00044 
00045 
00046 //! interpret a rowvec as a diagonal matrix
00047 template<typename eT>
00048 inline
00049 const Op<Mat<eT>, op_diagmat_vec>
00050 diagmat(const Row<eT>& X)
00051   {
00052   arma_extra_debug_sigprint();
00053   
00054   return Op<Mat<eT>, op_diagmat_vec>(X);
00055   }
00056 
00057 
00058 
00059 //! create a diagonal matrix out of subview_col
00060 template<typename eT>
00061 inline
00062 Mat<eT>
00063 diagmat(const subview_col<eT>& X)
00064   {
00065   arma_extra_debug_sigprint();
00066   
00067   Mat<eT> out;
00068   out.zeros(X.n_elem, X.n_elem);
00069   
00070   for(u32 i=0; i<X.n_elem; ++i)
00071     {
00072     out.at(i,i) = X[i];
00073     }
00074   
00075   return out;
00076   }
00077 
00078 
00079 
00080 //! create a diagonal matrix out of subview_row
00081 template<typename eT>
00082 inline
00083 Mat<eT>
00084 diagmat(const subview_row<eT>& X)
00085   {
00086   arma_extra_debug_sigprint();
00087   
00088   Mat<eT> out;
00089   out.zeros(X.n_elem, X.n_elem);
00090   
00091   for(u32 i=0; i<X.n_elem; ++i)
00092     {
00093     out.at(i,i) = X[i];
00094     }
00095   
00096   return out;
00097   }
00098 
00099 
00100 
00101 //! create a diagonal matrix out of diagview
00102 template<typename eT>
00103 inline
00104 Mat<eT>
00105 diagmat(const diagview<eT>& X)
00106   {
00107   arma_extra_debug_sigprint();
00108   
00109   Mat<eT> out;
00110   out.zeros(X.n_elem, X.n_elem);
00111   
00112   for(u32 i=0; i<X.n_elem; ++i)
00113     {
00114     out.at(i,i) = X[i];
00115     }
00116   
00117   return out;
00118   }
00119 
00120 
00121 
00122 //! two consecutive diagmat operations are equivalent to one diagmat operation
00123 template<typename T1>
00124 inline
00125 const Op<T1, op_diagmat>&
00126 diagmat(const Op<T1, op_diagmat>& X)
00127   {
00128   arma_extra_debug_sigprint();
00129   arma_extra_debug_print("diagmat(): two consecutive diagmat() operations detected");
00130   
00131   return X;
00132   }
00133 
00134 
00135 
00136 //! @}