op_htrans_meat.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 op_htrans
00017 //! @{
00018 
00019 
00020 //! Immediate transpose of a complex matrix
00021 template<typename T>
00022 inline
00023 void
00024 op_htrans::apply_noalias(Mat< std::complex<T> >& out, const Mat< std::complex<T> >& A)
00025   {
00026   arma_extra_debug_sigprint();
00027   
00028   out.set_size(A.n_cols, A.n_rows);
00029   
00030   for(u32 in_row = 0; in_row<A.n_rows; ++in_row)
00031     {
00032     const u32 out_col = in_row;
00033   
00034     for(u32 in_col = 0; in_col<A.n_cols; ++in_col)
00035       {
00036       const u32 out_row = in_col;
00037       out.at(out_row, out_col) = std::conj( A.at(in_row, in_col) );
00038       }
00039     }
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         for(u32 row=(col+1); row<n_rows; ++row)
00075           {
00076           eT val1 = std::conj(coldata[row]);
00077           eT val2 = std::conj(out.at(col,row));
00078           
00079           out.at(col,row) = val1;
00080           coldata[row]    = val2;
00081           }
00082         }
00083       }
00084     else
00085       {
00086       const Mat<eT> A_copy = A;
00087       op_trans::apply_noalias(out, A_copy);
00088       }
00089     }
00090   
00091   }
00092 
00093 
00094 
00095 template<typename T, typename T1>
00096 inline
00097 void
00098 op_htrans::apply(Mat< std::complex<T> >& out, const Op<T1,op_htrans>& in)
00099   {
00100   arma_extra_debug_sigprint();
00101   
00102   typedef typename std::complex<T> eT;
00103 
00104   isnt_same_type<eT,typename T1::elem_type>::check();
00105 
00106   const unwrap<T1> tmp(in.m);
00107   const Mat<eT>& A = tmp.M;
00108   
00109   if(&out != &A)
00110     {
00111     op_htrans::apply_noalias(out, A);
00112     }
00113   else
00114     {
00115     if(out.n_rows == out.n_cols)
00116       {
00117       arma_extra_debug_print("doing in-place hermitian transpose of a square matrix");
00118       
00119       const u32 n_rows = out.n_rows;
00120       const u32 n_cols = out.n_cols;
00121       
00122       for(u32 col=0; col<n_cols; ++col)
00123         {
00124         eT* coldata = out.colptr(col);
00125         
00126         for(u32 row=(col+1); row<n_rows; ++row)
00127           {
00128           eT val1 = std::conj(coldata[row]);
00129           eT val2 = std::conj(out.at(col,row));
00130           
00131           out.at(col,row) = val1;
00132           coldata[row]    = val2;
00133           }
00134         }
00135       }
00136     else
00137       {
00138       const Mat<eT> A_copy = A;
00139       op_trans::apply_noalias(out, A_copy);
00140       }
00141     }
00142   
00143   
00144   }
00145 
00146 
00147 
00148 //! @}