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 //! scalar * trans(T1)
00052 template<typename T1>
00053 arma_inline
00054 const Op<T1, op_trans2>
00055 operator*
00056 (const typename T1::elem_type k, const Op<T1, op_trans>& X)
00057   {
00058   arma_extra_debug_sigprint();
00059   
00060   return Op<T1, op_trans2>(X.m, k);
00061   }
00062 
00063 
00064 
00065 //! trans(T1) * scalar
00066 template<typename T1>
00067 arma_inline
00068 const Op<T1, op_trans2>
00069 operator*
00070 (const Op<T1, op_trans>& X, const typename T1::elem_type k)
00071   {
00072   arma_extra_debug_sigprint();
00073   
00074   return Op<T1, op_trans2>(X.m, k);
00075   }
00076 
00077 
00078 
00079 //! Base * diagmat
00080 template<typename T1, typename T2>
00081 arma_inline
00082 const Glue<T1, Op<T2, op_diagmat>, glue_times_diag>
00083 operator*
00084 (const Base<typename T2::elem_type,T1>& X, const Op<T2, op_diagmat>& Y)
00085   {
00086   arma_extra_debug_sigprint();
00087   
00088   return Glue<T1, Op<T2, op_diagmat>, glue_times_diag>(X.get_ref(), Y);
00089   }
00090 
00091 
00092 
00093 //! diagmat * Base
00094 template<typename T1, typename T2>
00095 arma_inline
00096 const Glue<Op<T1, op_diagmat>, T2, glue_times_diag>
00097 operator*
00098 (const Op<T1, op_diagmat>& X, const Base<typename T1::elem_type,T2>& Y)
00099   {
00100   arma_extra_debug_sigprint();
00101   
00102   return Glue<Op<T1, op_diagmat>, T2, glue_times_diag>(X, Y.get_ref());
00103   }
00104 
00105 
00106 
00107 //! diagmat * diagmat
00108 template<typename T1, typename T2>
00109 arma_inline
00110 Mat< typename promote_type<typename T1::elem_type, typename T2::elem_type>::result >
00111 operator*
00112 (const Op<T1, op_diagmat>& X, const Op<T2, op_diagmat>& Y)
00113   {
00114   arma_extra_debug_sigprint();
00115   
00116   typedef typename T1::elem_type eT1;
00117   typedef typename T2::elem_type eT2;
00118   
00119   typedef typename promote_type<eT1,eT2>::result out_eT;
00120   
00121   promote_type<eT1,eT2>::check();
00122   
00123   const diagmat_proxy<T1> A(X.m);
00124   const diagmat_proxy<T2> B(Y.m);
00125   
00126   arma_debug_assert_mul_size(A.n_elem, A.n_elem, B.n_elem, B.n_elem, "matrix multiply");
00127   
00128   const u32 N = A.n_elem;
00129   
00130   Mat<out_eT> out(N,N);
00131   
00132   out.zeros();
00133   
00134   for(u32 i=0; i<N; ++i)
00135     {
00136     out.at(i,i) = upgrade_val<eT1,eT2>::apply( A[i] ) * upgrade_val<eT1,eT2>::apply( B[i] );
00137     }
00138   
00139   return out;
00140   }
00141 
00142 
00143 
00144 //! multiplication of Base objects with same element type
00145 template<typename T1, typename T2>
00146 arma_inline
00147 const Glue<T1, T2, glue_times>
00148 operator*
00149 (const Base<typename T1::elem_type,T1>& X, const Base<typename T1::elem_type,T2>& Y)
00150   {
00151   arma_extra_debug_sigprint();
00152   
00153   return Glue<T1, T2, glue_times>(X.get_ref(), Y.get_ref());
00154   }
00155 
00156 
00157 
00158 //! multiplication of Base objects with different element types
00159 template<typename T1, typename T2>
00160 arma_inline
00161 Mat<typename promote_type<typename T1::elem_type, typename T2::elem_type>::result>
00162 operator*
00163   (
00164   const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T1_result, T1>& X,
00165   const Base< typename force_different_type<typename T1::elem_type, typename T2::elem_type>::T2_result, T2>& Y
00166   )
00167   {
00168   arma_extra_debug_sigprint();
00169   
00170   typedef typename T1::elem_type eT1;
00171   typedef typename T2::elem_type eT2;
00172   
00173   typedef typename promote_type<eT1,eT2>::result out_eT;
00174   
00175   promote_type<eT1,eT2>::check();
00176   
00177   const unwrap<T1> tmp1(X.get_ref());
00178   const unwrap<T2> tmp2(Y.get_ref());
00179   
00180   const Mat<eT1>& A = tmp1.M;
00181   const Mat<eT2>& B = tmp2.M;
00182   
00183   Mat<out_eT> out;
00184   
00185   glue_times::apply_mixed(out, A, B);
00186   
00187   return out;
00188   }
00189 
00190 
00191 
00192 //! @}