Glue_schur


Classes

class  glue_schur
 Class which implements the immediate Schur product (element-wise multiplication) of two or more matrices. More...
class  glue_schur_diag

Functions

template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B, const Mat< eT > &C)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Glue< Mat< eT >, Mat< eT >, glue_schur > &X)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Glue< Glue< Mat< eT >, Mat< eT >, glue_schur >, Mat< eT >, glue_schur > &X)
template<typename T1 , typename T2 >
static void glue_schur::apply (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_schur > &X)
template<typename eT >
static void glue_schur::apply_inplace (Mat< eT > &out, const Mat< eT > &B)
template<typename T1 , typename op_type >
static void glue_schur::apply_inplace (Mat< typename T1::elem_type > &out, const Op< T1, op_type > &X)
template<typename T1 , typename T2 , typename glue_type >
static void glue_schur::apply_inplace (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_type > &X)
template<typename eT1 , typename eT2 >
static void glue_schur::apply_mixed (Mat< typename promote_type< eT1, eT2 >::result > &out, const Mat< eT1 > &X, const Mat< eT2 > &Y)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const T1 &A, const Op< T2, op_diagmat > &B)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_diagmat > &A, const Op< T2, op_diagmat > &B)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< T1, Op< T2, op_diagmat >, glue_schur_diag > &X)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, T2, glue_schur_diag > &X)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, Op< T2, op_diagmat >, glue_schur_diag > &X)

Function Documentation

template<typename eT >
void glue_schur::apply ( Mat< eT > &  out,
const Mat< eT > &  A,
const Mat< eT > &  B 
) [inline, static, inherited]

Definition at line 22 of file glue_schur_meat.hpp.

References Mat< eT >::mem, Mat< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().

Referenced by apply(), apply_inplace(), and apply_mixed().

00023   {
00024   arma_extra_debug_sigprint();
00025   
00026   arma_debug_assert_same_size(A, B, "matrix schur product");
00027     
00028   // no aliasing problem
00029   out.set_size(A.n_rows, A.n_cols);
00030     
00031         eT* out_mem = out.memptr();
00032   const eT* A_mem   = A.mem;
00033   const eT* B_mem   = B.mem;
00034   
00035   const u32 n_elem  = A.n_elem;
00036     
00037   for(u32 i=0; i<n_elem; ++i)
00038     {
00039     out_mem[i] = A_mem[i] * B_mem[i];
00040     }
00041   
00042   }

template<typename eT >
void glue_schur::apply ( Mat< eT > &  out,
const Mat< eT > &  A,
const Mat< eT > &  B,
const Mat< eT > &  C 
) [inline, static, inherited]

Definition at line 49 of file glue_schur_meat.hpp.

References Mat< eT >::mem, Mat< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and Mat< eT >::set_size().

00050   {
00051   arma_extra_debug_sigprint();
00052   
00053   arma_debug_assert_same_size(A, B, "matrix schur product");
00054   arma_debug_assert_same_size(A, C, "matrix schur product");
00055   
00056   // no aliasing problem
00057   out.set_size(A.n_rows, A.n_cols);
00058     
00059         eT* out_mem = out.memptr();
00060   const eT* A_mem   = A.mem;
00061   const eT* B_mem   = B.mem;
00062   const eT* C_mem   = C.mem;
00063   
00064   const u32 n_elem  = A.n_elem;
00065   
00066   for(u32 i=0; i<n_elem; ++i)
00067     {
00068     out_mem[i] = A_mem[i] * B_mem[i] * C_mem[i];
00069     }
00070   
00071   }

template<typename eT >
void glue_schur::apply ( Mat< eT > &  out,
const Glue< Mat< eT >, Mat< eT >, glue_schur > &  X 
) [inline, static, inherited]

Definition at line 78 of file glue_schur_meat.hpp.

References apply().

00079   {
00080   glue_schur::apply(out, X.A, X.B);
00081   }

template<typename eT >
void glue_schur::apply ( Mat< eT > &  out,
const Glue< Glue< Mat< eT >, Mat< eT >, glue_schur >, Mat< eT >, glue_schur > &  X 
) [inline, static, inherited]

Definition at line 88 of file glue_schur_meat.hpp.

References apply().

00089   {
00090   glue_schur::apply(out, X.A.A, X.A.B, X.B);
00091   }

template<typename T1 , typename T2 >
void glue_schur::apply ( Mat< typename T1::elem_type > &  out,
const Glue< T1, T2, glue_schur > &  X 
) [inline, static, inherited]

Definition at line 97 of file glue_schur_meat.hpp.

References Glue< T1, T2, glue_type >::A, apply(), Glue< T1, T2, glue_type >::B, and Mat< eT >::set_size().

00098   {
00099   arma_extra_debug_sigprint();
00100 
00101   typedef typename T1::elem_type eT;
00102 
00103   const u32 N_mat = 1 + depth_lhs< glue_schur, Glue<T1,T2,glue_schur> >::num;
00104   arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat );
00105 
00106   if(N_mat == 2)
00107     {
00108     const unwrap<T1> tmp1(X.A);
00109     const unwrap<T2> tmp2(X.B);
00110     
00111     glue_schur::apply(out, tmp1.M, tmp2.M);
00112     }
00113   else
00114     {
00115     const Mat<eT>* ptrs[N_mat];
00116     bool            del[N_mat];
00117 
00118     mat_ptrs<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X);
00119     //mat_ptrs_outcheck<glue_schur, Glue<T1,T2,glue_schur> >::get_ptrs(ptrs, del, X, &out);
00120 
00121     for(u32 i=0; i<N_mat; ++i)  arma_extra_debug_print( arma_boost::format("ptrs[%d] = %x") % i % ptrs[i] );
00122     for(u32 i=0; i<N_mat; ++i)  arma_extra_debug_print( arma_boost::format(" del[%d] = %d") % i %  del[i] );
00123 
00124     const Mat<eT>& tmp_mat = *(ptrs[0]);
00125 
00126     for(u32 i=1; i<N_mat; ++i)
00127       {
00128       arma_debug_assert_same_size(tmp_mat, *(ptrs[i]), "matrix schur product");
00129       }
00130   
00131     
00132     const u32 n_rows = ptrs[0]->n_rows;
00133     const u32 n_cols = ptrs[0]->n_cols;
00134 
00135     // no aliasing problem
00136     out.set_size(n_rows,n_cols);
00137     
00138     const u32 n_elem = ptrs[0]->n_elem;
00139     
00140     for(u32 j=0; j<n_elem; ++j)
00141       {
00142       eT acc = ptrs[0]->mem[j];
00143       
00144       for(u32 i=1; i<N_mat; ++i)
00145         {
00146         acc *= ptrs[i]->mem[j];
00147         }
00148       
00149       out[j] = acc;
00150       }
00151     
00152     
00153     for(u32 i=0; i<N_mat; ++i)
00154       {
00155       if(del[i] == true)
00156         {
00157         arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i );
00158         delete ptrs[i];
00159         }
00160       }
00161 
00162     }
00163   }

template<typename eT >
void glue_schur::apply_inplace ( Mat< eT > &  out,
const Mat< eT > &  B 
) [inline, static, inherited]

Definition at line 170 of file glue_schur_meat.hpp.

References Mat< eT >::mem, and Mat< eT >::n_elem.

Referenced by Mat< eT >::operator%=().

00171   {
00172   arma_extra_debug_sigprint();
00173   
00174   arma_debug_assert_same_size(out, B, "matrix schur product");
00175   
00176   const u32 n_elem = out.n_elem;
00177   
00178   for(u32 i=0; i<n_elem; ++i)
00179     {
00180     out[i] *= B.mem[i];
00181     }
00182   
00183   }

template<typename T1 , typename op_type >
void glue_schur::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_type > &  X 
) [inline, static, inherited]

Definition at line 190 of file glue_schur_meat.hpp.

References apply().

00191   {
00192   arma_extra_debug_sigprint();
00193   
00194   typedef typename T1::elem_type eT;
00195   
00196   const Mat<eT> tmp(X);
00197   glue_schur::apply(out, out, tmp);
00198   }

template<typename T1 , typename T2 , typename glue_type >
void glue_schur::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Glue< T1, T2, glue_type > &  X 
) [inline, static, inherited]

Definition at line 205 of file glue_schur_meat.hpp.

References apply().

00206   {
00207   arma_extra_debug_sigprint();
00208   
00209   // out = X % out;
00210   
00211   typedef typename T1::elem_type eT;
00212   
00213   const Mat<eT> tmp(X);
00214   glue_schur::apply(out, out, tmp);
00215   }

template<typename eT1 , typename eT2 >
void glue_schur::apply_mixed ( Mat< typename promote_type< eT1, eT2 >::result > &  out,
const Mat< eT1 > &  X,
const Mat< eT2 > &  Y 
) [inline, static, inherited]

Definition at line 225 of file glue_schur_meat.hpp.

References apply(), Mat< eT >::mem, Mat< eT >::n_cols, and Mat< eT >::n_rows.

Referenced by operator%().

00226   {
00227   arma_extra_debug_sigprint();
00228   
00229   typedef typename promote_type<eT1,eT2>::result out_eT;
00230   
00231   arma_debug_assert_same_size(X,Y, "matrix schur product");  
00232   
00233   out.set_size(X.n_rows, X.n_cols);
00234   
00235         out_eT* out_mem = out.memptr();
00236   const eT1*    X_mem   = X.mem;
00237   const eT2*    Y_mem   = Y.mem;
00238   
00239   const u32 n_elem = out.n_elem;
00240   
00241   for(u32 i=0; i<n_elem; ++i)
00242     {
00243     out_mem[i] = upgrade_val<eT1,eT2>::apply(X_mem[i]) * upgrade_val<eT1,eT2>::apply(Y_mem[i]);
00244     }
00245   }

template<typename T1 , typename T2 >
void glue_schur_diag::apply ( Mat< typename T1::elem_type > &  out,
const T1 &  A,
const Op< T2, op_diagmat > &  B 
) [inline, static, inherited]

Definition at line 256 of file glue_schur_meat.hpp.

References Mat< eT >::at(), Mat< eT >::is_square(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_rows, and Mat< eT >::zeros().

Referenced by glue_schur_diag::apply().

00257   {
00258   arma_extra_debug_sigprint();
00259   
00260   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00261   
00262   const unwrap<T1> tmp1(A_orig);
00263   const unwrap<T2> tmp2(B_orig.m);
00264   
00265   typedef typename T1::elem_type eT;
00266   
00267   const Mat<eT>& A = tmp1.M;
00268   const Mat<eT>& B = tmp2.M;
00269   
00270   arma_debug_check( (B.is_square() == false), "glue_schur_diag::apply(): matrices must be square" );
00271   arma_debug_assert_same_size(A, B, "matrix schur product");
00272 
00273   if( (&out != &A) && (&out != &B) )
00274     {
00275     out.zeros(A.n_rows, A.n_cols);
00276     
00277     for(u32 i=0; i<A.n_rows; ++i)
00278       {
00279       out.at(i,i) = A.at(i,i) * B.at(i,i);
00280       }
00281     }
00282   else
00283     {
00284     for(u32 col=0; col<A.n_cols; ++col)
00285       {
00286       for(u32 row=0; row<A.n_rows; ++row)
00287         {
00288         if(col != row)
00289           {
00290           out.at(row,col) = eT(0);
00291           }
00292         else
00293           {
00294           out.at(row,col) = A.at(row,col) * B.at(row,col);
00295           }
00296         }
00297       }
00298     }
00299   
00300   }

template<typename T1 , typename T2 >
void glue_schur_diag::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_diagmat > &  A,
const Op< T2, op_diagmat > &  B 
) [inline, static, inherited]

Definition at line 307 of file glue_schur_meat.hpp.

References Mat< eT >::at(), Mat< eT >::is_square(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_rows, and Mat< eT >::zeros().

00308   {
00309   arma_extra_debug_sigprint();
00310   
00311   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00312   
00313   const unwrap<T1> tmp1(A_orig.m);
00314   const unwrap<T2> tmp2(B_orig.m);
00315   
00316   typedef typename T1::elem_type eT;
00317   
00318   const Mat<eT>& A = tmp1.M;
00319   const Mat<eT>& B = tmp2.M;
00320   
00321   arma_debug_check( (A.is_square() == false), "glue_schur_diag::apply(): matrices must be square" );
00322   arma_debug_assert_same_size(A, B, "matrix schur product");
00323   
00324   if( (&out != &A) && (&out != &B) )
00325     {
00326     out.zeros(A.n_rows, A.n_cols);
00327     
00328     for(u32 i=0; i<A.n_rows; ++i)
00329       {
00330       out.at(i,i) = A.at(i,i) * B.at(i,i);
00331       }
00332     }
00333   else
00334     {
00335     for(u32 col=0; col<A.n_cols; ++col)
00336       {
00337       for(u32 row=0; row<A.n_rows; ++row)
00338         {
00339         if(col != row)
00340           {
00341           out.at(row,col) = eT(0);
00342           }
00343         else
00344           {
00345           out.at(row,col) = A.at(row,col) * B.at(row,col);
00346           }
00347         }
00348       }
00349     }
00350   
00351   }

template<typename T1 , typename T2 >
void glue_schur_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< T1, Op< T2, op_diagmat >, glue_schur_diag > &  X 
) [inline, static, inherited]

Definition at line 358 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00359   {
00360   glue_schur_diag::apply(out, X.A, X.B);
00361   }

template<typename T1 , typename T2 >
void glue_schur_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< Op< T1, op_diagmat >, T2, glue_schur_diag > &  X 
) [inline, static, inherited]

Definition at line 368 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00369   {
00370   glue_schur_diag::apply(out, X.B, X.A);  // NOTE: arguments are swapped
00371   }

template<typename T1 , typename T2 >
void glue_schur_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< Op< T1, op_diagmat >, Op< T2, op_diagmat >, glue_schur_diag > &  X 
) [inline, static, inherited]

Definition at line 378 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00379   {
00380   glue_schur_diag::apply(out, X.A, X.B);
00381   }