Matrix multplication where the matrices have different element types. //! Simple version (no caching). //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes). More...
#include <gemm_mixed.hpp>
Static Public Member Functions | |
template<typename out_eT , typename in_eT1 , typename in_eT2 > | |
static arma_hot void | apply (Mat< out_eT > &C, const Mat< in_eT1 > &A, const Mat< in_eT2 > &B, const out_eT alpha=out_eT(1), const out_eT beta=out_eT(0)) |
Matrix multplication where the matrices have different element types. //! Simple version (no caching). //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes).
Definition at line 213 of file gemm_mixed.hpp.
static arma_hot void gemm_mixed_simple< do_trans_A, do_trans_B, use_alpha, use_beta >::apply | ( | Mat< out_eT > & | C, | |
const Mat< in_eT1 > & | A, | |||
const Mat< in_eT2 > & | B, | |||
const out_eT | alpha = out_eT(1) , |
|||
const out_eT | beta = out_eT(0) | |||
) | [inline, static] |
Definition at line 223 of file gemm_mixed.hpp.
References Mat< eT >::at(), Mat< eT >::colptr(), Mat< eT >::n_cols, and Mat< eT >::n_rows.
{ arma_extra_debug_sigprint(); const u32 A_n_rows = A.n_rows; const u32 A_n_cols = A.n_cols; const u32 B_n_rows = B.n_rows; const u32 B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { for(u32 row_A = 0; row_A < A_n_rows; ++row_A) { for(u32 col_B = 0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(u32 i = 0; i < B_n_rows; ++i) { const out_eT val1 = upgrade_val<in_eT1,in_eT2>::apply(A.at(row_A,i)); const out_eT val2 = upgrade_val<in_eT1,in_eT2>::apply(B_coldata[i]); acc += val1 * val2; //acc += upgrade_val<in_eT1,in_eT2>::apply(A.at(row_A,i)) * upgrade_val<in_eT1,in_eT2>::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true) && (use_beta == false) ) { C.at(row_A,col_B) = alpha * acc; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true) && (use_beta == true) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(u32 col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const in_eT1* A_coldata = A.colptr(col_A); for(u32 col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(u32 i=0; i < B_n_rows; ++i) { acc += upgrade_val<in_eT1,in_eT2>::apply(A_coldata[i]) * upgrade_val<in_eT1,in_eT2>::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true) && (use_beta == false) ) { C.at(col_A,col_B) = alpha * acc; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true) && (use_beta == true) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { for(u32 row_A = 0; row_A < A_n_rows; ++row_A) { for(u32 row_B = 0; row_B < B_n_rows; ++row_B) { out_eT acc = out_eT(0); for(u32 i = 0; i < B_n_cols; ++i) { acc += upgrade_val<in_eT1,in_eT2>::apply(A.at(row_A,i)) * upgrade_val<in_eT1,in_eT2>::apply(B.at(row_B,i)); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,row_B) = acc; } else if( (use_alpha == true) && (use_beta == false) ) { C.at(row_A,row_B) = alpha * acc; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(row_A,row_B) = acc + beta*C.at(row_A,row_B); } else if( (use_alpha == true) && (use_beta == true) ) { C.at(row_A,row_B) = alpha*acc + beta*C.at(row_A,row_B); } } } } else if( (do_trans_A == true) && (do_trans_B == true) ) { for(u32 row_B=0; row_B < B_n_rows; ++row_B) { for(u32 col_A=0; col_A < A_n_cols; ++col_A) { const in_eT1* A_coldata = A.colptr(col_A); out_eT acc = out_eT(0); for(u32 i=0; i < A_n_rows; ++i) { acc += upgrade_val<in_eT1,in_eT2>::apply(B.at(row_B,i)) * upgrade_val<in_eT1,in_eT2>::apply(A_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true) && (use_beta == false) ) { C.at(col_A,row_B) = alpha * acc; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true) && (use_beta == true) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } }