op_neg_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 
00017 //! \addtogroup op_neg
00018 //! @{
00019 
00020 
00021 
00022 //! Negate all elements of a dense matrix
00023 template<typename T1>
00024 inline
00025 void
00026 op_neg::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_neg> &in)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   typedef typename T1::elem_type eT;
00031   
00032   const unwrap_write<T1> tmp(out, in.m);
00033   const Mat<eT>& A     = tmp.M;
00034   
00035         eT* out_mem = out.memptr();
00036   const eT* A_mem   = A.memptr();
00037   const u32 n_elem  = out.n_elem;  
00038   
00039   for(u32 i=0; i<n_elem; ++i)
00040     {
00041     out_mem[i] = -A_mem[i];
00042     }
00043   }
00044 
00045 
00046 
00047 
00048 //! Negate all elements of a dense cube
00049 template<typename T1>
00050 inline
00051 void
00052 op_neg::apply(Cube<typename T1::elem_type>& out, const OpCube<T1,op_neg> &in)
00053   {
00054   arma_extra_debug_sigprint();
00055   
00056   typedef typename T1::elem_type eT;
00057   
00058   const unwrap_cube_write<T1> tmp(out, in.m);
00059   const Cube<eT>& A         = tmp.M;
00060   
00061         eT* out_mem = out.memptr();
00062   const eT* A_mem   = A.memptr();
00063   const u32 n_elem  = out.n_elem;  
00064   
00065   for(u32 i=0; i<n_elem; ++i)
00066     {
00067     out_mem[i] = -A_mem[i];
00068     }
00069   }
00070 
00071 
00072 
00073 //! @}