op_htrans_meat.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup op_htrans
00018 //! @{
00019 
00020 
00021 
00022 //! Immediate transpose of a complex matrix
00023 template<typename T>
00024 inline
00025 void
00026 op_htrans::apply_noalias(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   out.set_size(A.n_cols, A.n_rows);
00031   
00032   for(u32 in_row = 0; in_row<A.n_rows; ++in_row)
00033     {
00034     const u32 out_col = in_row;
00035   
00036     for(u32 in_col = 0; in_col<A.n_cols; ++in_col)
00037       {
00038       const u32 out_row = in_col;
00039       out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) );
00040       }
00041     }
00042   
00043   }
00044 
00045 
00046 
00047 //! Immediate transpose of a complex matrix
00048 template<typename T>
00049 inline
00050 void
00051 op_htrans::apply(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A)
00052   {
00053   arma_extra_debug_sigprint();
00054   
00055   typedef typename std::complex<T> eT;
00056 
00057   if(&out != &A)
00058     {
00059     op_htrans::apply_noalias(out, A);
00060     }
00061   else
00062     {
00063     if(out.n_rows == out.n_cols)
00064       {
00065       arma_extra_debug_print("doing in-place hermitian transpose of a square matrix");
00066       
00067       const u32 n_rows = out.n_rows;
00068       const u32 n_cols = out.n_cols;
00069       
00070       for(u32 col=0; col<n_cols; ++col)
00071         {
00072         eT* coldata = out.colptr(col);
00073         
00074         out.at(col,col) = std::conj( out.at(col,col) );
00075         
00076         for(u32 row=(col+1); row<n_rows; ++row)
00077           {
00078           const eT val1 = std::conj(coldata[row]);
00079           const eT val2 = std::conj(out.at(col,row));
00080           
00081           out.at(col,row) = val1;
00082           coldata[row]    = val2;
00083           }
00084         }
00085       }
00086     else
00087       {
00088       const Mat<eT> A_copy = A;
00089       op_htrans::apply_noalias(out, A_copy);
00090       }
00091     }
00092   
00093   }
00094 
00095 
00096 
00097 template<typename T, typename T1>
00098 inline
00099 void
00100 op_htrans::apply(Mat< std::complex<T> >& out, const Op<T1,op_htrans>& in)
00101   {
00102   arma_extra_debug_sigprint();
00103   
00104   typedef typename std::complex<T> eT;
00105   
00106   isnt_same_type<eT,typename T1::elem_type>::check();
00107   
00108   const unwrap<T1> tmp(in.m);
00109   const Mat<eT>& A = tmp.M;
00110   
00111   op_htrans::apply(out, A);
00112   }
00113 
00114 
00115 
00116 //! @}