operator_times.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 
00018 //! \addtogroup operator_times
00019 //! @{
00020 
00021 
00022 
00023 //! Base * scalar
00024 template<typename T1>
00025 arma_inline
00026 const eOp<T1, eop_scalar_times>
00027 operator*
00028 (const Base<typename T1::elem_type,T1>& X, const typename T1::elem_type k)
00029   {
00030   arma_extra_debug_sigprint();
00031   
00032   return eOp<T1, eop_scalar_times>(X.get_ref(),k);
00033   }
00034 
00035 
00036 
00037 //! scalar * Base
00038 template<typename T1>
00039 arma_inline
00040 const eOp<T1, eop_scalar_times>
00041 operator*
00042 (const typename T1::elem_type k, const Base<typename T1::elem_type,T1>& X)
00043   {
00044   arma_extra_debug_sigprint();
00045   
00046   return eOp<T1, eop_scalar_times>(X.get_ref(),k);  // NOTE: order is swapped
00047   }
00048 
00049 
00050 
00051 //! non-complex Base * complex scalar (experimental)
00052 template<typename T1>
00053 arma_inline
00054 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>
00055 operator*
00056   (
00057   const Base<typename T1::pod_type, T1>&     X,
00058   const std::complex<typename T1::pod_type>& k
00059   )
00060   {
00061   arma_extra_debug_sigprint();
00062   
00063   return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>('j', X.get_ref(), k);
00064   }
00065 
00066 
00067 
00068 //! complex scalar * non-complex Base (experimental)
00069 template<typename T1>
00070 arma_inline
00071 const mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>
00072 operator*
00073   (
00074   const std::complex<typename T1::pod_type>& k,
00075   const Base<typename T1::pod_type, T1>&     X
00076   )
00077   {
00078   arma_extra_debug_sigprint();
00079   
00080   return mtOp<typename std::complex<typename T1::pod_type>, T1, op_cx_scalar_times>('j', X.get_ref(), k);
00081   }
00082 
00083 
00084 
00085 //! scalar * trans(T1)
00086 template<typename T1>
00087 arma_inline
00088 const Op<T1, op_trans2>
00089 operator*
00090 (const typename T1::elem_type k, const Op<T1, op_trans>& X)
00091   {
00092   arma_extra_debug_sigprint();
00093   
00094   return Op<T1, op_trans2>(X.m, k);
00095   }
00096 
00097 
00098 
00099 //! trans(T1) * scalar
00100 template<typename T1>
00101 arma_inline
00102 const Op<T1, op_trans2>
00103 operator*
00104 (const Op<T1, op_trans>& X, const typename T1::elem_type k)
00105   {
00106   arma_extra_debug_sigprint();
00107   
00108   return Op<T1, op_trans2>(X.m, k);
00109   }
00110 
00111 
00112 
00113 //! Base * diagmat
00114 template<typename T1, typename T2>
00115 arma_inline
00116 const Glue<T1, Op<T2, op_diagmat>, glue_times_diag>
00117 operator*
00118 (const Base<typename T2::elem_type,T1>& X, const Op<T2, op_diagmat>& Y)
00119   {
00120   arma_extra_debug_sigprint();
00121   
00122   return Glue<T1, Op<T2, op_diagmat>, glue_times_diag>(X.get_ref(), Y);
00123   }
00124 
00125 
00126 
00127 //! diagmat * Base
00128 template<typename T1, typename T2>
00129 arma_inline
00130 const Glue<Op<T1, op_diagmat>, T2, glue_times_diag>
00131 operator*
00132 (const Op<T1, op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y)
00133   {
00134   arma_extra_debug_sigprint();
00135   
00136   return Glue<Op<T1, op_diagmat>, T2, glue_times_diag>(X, Y.get_ref());
00137   }
00138 
00139 
00140 
00141 //! diagmat * diagmat
00142 template<typename T1, typename T2>
00143 arma_inline
00144 Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>::result >
00145 operator*
00146 (const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
00147   {
00148   arma_extra_debug_sigprint();
00149   
00150   typedef typename T1::elem_type eT1;
00151   typedef typename T2::elem_type eT2;
00152   
00153   typedef typename promote_type<eT1,eT2>::result out_eT;
00154   
00155   promote_type<eT1,eT2>::check();
00156   
00157   const diagmat_proxy<T1> A(X.m);
00158   const diagmat_proxy<T2> B(Y.m);
00159   
00160   arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "matrix multiply");
00161   
00162   const u32 N = A.n_elem;
00163   
00164   Mat<out_eT> out(N,N);
00165   
00166   out.zeros();
00167   
00168   for(u32 i=0; i<N; ++i)
00169     {
00170     out.at(i,i) = upgrade_val<eT1,eT2>::apply( A[i] ) * upgrade_val<eT1,eT2>::apply( B[i] );
00171     }
00172   
00173   return out;
00174   }
00175 
00176 
00177 
00178 //! multiplication of Base objects with same element type
00179 template<typename T1, typename T2>
00180 arma_inline
00181 const Glue<T1, T2, glue_times>
00182 operator*
00183 (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y)
00184   {
00185   arma_extra_debug_sigprint();
00186   
00187   return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
00188   }
00189 
00190 
00191 
00192 //! multiplication of Base objects with different element types
00193 template<typename T1, typename T2>
00194 inline
00195 const mtGlue< typename promote_type<typename T1::elem_type, typename T2::elem_type>::result, T1, T2, glue_mixed_times >
00196 operator*
00197   (
00198   const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T1_result, T1>& X,
00199   const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T2_result, T2>& Y
00200   )
00201   {
00202   arma_extra_debug_sigprint();
00203   
00204   typedef typename T1::elem_type eT1;
00205   typedef typename T2::elem_type eT2;
00206   
00207   typedef typename promote_type<eT1,eT2>::result out_eT;
00208   
00209   promote_type<eT1,eT2>::check();
00210   
00211   return mtGlue<out_eT, T1, T2, glue_mixed_times>( X.get_ref(), Y.get_ref() );
00212   }
00213 
00214 
00215 
00216 //! @}