op_flip_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_flip
00018 //! @{
00019 
00020 
00021 
00022 template<typename T1>
00023 inline
00024 void
00025 op_flipud::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_flipud>& in)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   typedef typename T1::elem_type eT;
00030   
00031   const unwrap<T1>  tmp(in.m);
00032   const Mat<eT> X = tmp.M;
00033   
00034   if(&out != &X)
00035     {
00036     out.copy_size(X);
00037     
00038     for(u32 i=0; i<X.n_rows; ++i)
00039       {
00040       out.row(i) = X.row(X.n_rows-1 - i);
00041       }
00042     }
00043   else
00044     {
00045     const u32 N = X.n_rows / 2;
00046     
00047     for(u32 i=0; i<N; ++i)
00048       {
00049       out.swap_rows(i, X.n_rows-1 - i);
00050       }
00051     }
00052   }
00053 
00054 
00055 
00056 template<typename T1>
00057 inline
00058 void
00059 op_fliplr::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_fliplr>& in)
00060   {
00061   arma_extra_debug_sigprint();
00062   
00063   typedef typename T1::elem_type eT;
00064   
00065   const unwrap<T1>  tmp(in.m);
00066   const Mat<eT> X = tmp.M;
00067   
00068   if(&out != &X)
00069     {
00070     out.copy_size(X);
00071     
00072     for(u32 i=0; i<X.n_cols; ++i)
00073       {
00074       out.col(i) = X.col(X.n_cols-1 - i);
00075       }
00076     }
00077   else
00078     {
00079     const u32 N = X.n_cols / 2;
00080     
00081     for(u32 i=0; i<N; ++i)
00082       {
00083       out.swap_cols(i, X.n_cols-1 - i);
00084       }
00085     }
00086   }
00087 
00088 
00089 
00090 //! @}