syslib_proto.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 syslib
00018 //! @{
00019 
00020 
00021 class syslib
00022   {
00023   public:
00024   
00025   template<typename eT>
00026   arma_hot
00027   inline
00028   static
00029   void
00030   copy_elem(eT* dest, const eT* src, const u32 n_elem)
00031     {
00032     #if !defined(__OPTIMIZE__)
00033       {
00034       std::memcpy(dest, src, n_elem*sizeof(eT));
00035       }
00036     #else
00037       {
00038       switch(n_elem)
00039         {
00040         case 0:
00041           break;
00042         
00043         case 1:
00044           *dest = *src;
00045           break;
00046           
00047         case 2:
00048           dest[0] = src[0];
00049           dest[1] = src[1];
00050           break;
00051         
00052         case 3:
00053           dest[0] = src[0];
00054           dest[1] = src[1];
00055           dest[2] = src[2];
00056           break;
00057         
00058         case 4:
00059           dest[0] = src[0];
00060           dest[1] = src[1];
00061           dest[2] = src[2];
00062           dest[3] = src[3];
00063           break;
00064         
00065         default:
00066           if( n_elem <= (128/sizeof(eT)) )
00067             {
00068             u32 i,j;
00069             
00070             for(i=0, j=1; j<n_elem; i+=2, j+=2)
00071               {
00072               dest[i] = src[i];
00073               dest[j] = src[j];
00074               }
00075             
00076             if(i < n_elem)
00077               {
00078               dest[i] = src[i];
00079               }
00080             }
00081           else
00082             {
00083             std::memcpy(dest, src, n_elem*sizeof(eT));
00084             }
00085         }
00086       }
00087     #endif
00088     }
00089   
00090   
00091   
00092   template<typename out_eT, typename in_eT>
00093   arma_hot
00094   inline
00095   static
00096   void
00097   copy_and_convert_elem(out_eT* dest, const in_eT* src, const u32 n_elem)
00098     {
00099     u32 i,j;
00100     
00101     for(i=0, j=1; j<n_elem; i+=2, j+=2)
00102       {
00103       dest[i] = out_eT( src[i] );
00104       dest[j] = out_eT( src[j] );
00105       }
00106     
00107     if(i < n_elem)
00108       {
00109       dest[i] = out_eT( src[i] );
00110       }
00111     }
00112   
00113   
00114   
00115   //
00116   // TODO: the functions below will need more work
00117   
00118   
00119   template<typename out_eT, typename in_eT>
00120   arma_hot
00121   arma_inline
00122   static
00123   void
00124   convert_cx_scalar(out_eT& out, const in_eT& in)
00125     {
00126     out = out_eT(in);
00127     }
00128   
00129   
00130   
00131   template<typename out_eT, typename in_T>
00132   arma_hot
00133   arma_inline
00134   static
00135   void
00136   convert_cx_scalar(out_eT& out, const std::complex<in_T>& in)
00137     {
00138     out = out_eT( in.real() );
00139     }
00140   
00141   
00142   
00143   template<typename out_T, typename in_T>
00144   arma_hot
00145   arma_inline
00146   static
00147   void
00148   convert_cx_scalar(std::complex<out_T>& out, const std::complex<in_T>& in)
00149     {
00150     typedef std::complex<out_T> out_eT;
00151     
00152     out = out_eT(in);
00153     }
00154   
00155   
00156   
00157   template<typename out_eT, typename in_eT>
00158   arma_hot
00159   inline
00160   static
00161   void
00162   copy_and_convert_cx_elem(out_eT* dest, const in_eT* src, const u32 n_elem)
00163     {
00164     u32 i,j;
00165     
00166     for(i=0, j=1; j<n_elem; i+=2, j+=2)
00167       {
00168       convert_cx_scalar( dest[i], src[i] );
00169       convert_cx_scalar( dest[j], src[j] );
00170       }
00171     
00172     if(i < n_elem)
00173       {
00174       convert_cx_scalar( dest[i], src[i] );
00175       }
00176     }
00177   
00178   
00179   
00180   };
00181 
00182 
00183 
00184 //! @}