00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MATRIX_VECTOR_TEMPLATE_OP_DEF_H
00032 #define MATRIX_VECTOR_TEMPLATE_OP_DEF_H
00033
00034 #include "AbstractLinAlgPack_MatrixVectorTemplateOp.hpp"
00035 #include "DenseLinAlgPack_DMatrixClass.hpp"
00036
00037
00038
00039
00040 namespace {
00041
00042 typedef AbstractLinAlgPack::DVectorSlice (AbstractLinAlgPack::DMatrixSlice::*Pvec_func)
00043 (AbstractLinAlgPack::DMatrixSlice::size_type);
00044
00045 template<class T_Matrix>
00046 void imp_assign(AbstractLinAlgPack::DMatrixSlice& gms_lhs, const T_Matrix& gm_rhs
00047 , BLAS_Cpp::Transp trans_rhs)
00048 {
00049
00050 Pvec_func vec_func;
00051 if(trans_rhs == BLAS_Cpp::no_trans) vec_func = &AbstractLinAlgPack::DMatrixSlice::col;
00052 else vec_func = &AbstractLinAlgPack::DMatrixSlice::row;
00053 for(int k = 1; k <= gm_rhs.cols(); ++k)
00054 AbstractLinAlgPack::assign((gms_lhs.*vec_func)(k), gm_rhs.col(k));
00055 }
00056 }
00057
00058
00059
00061 template<class T_Matrix>
00062 void AbstractLinAlgPack::assign(DMatrix& gm_lhs, const T_Matrix& gm_rhs
00063 , BLAS_Cpp::Transp trans_rhs)
00064 {
00065 DenseLinAlgPack::resize_gm_lhs(gm_lhs,gm_rhs.rows(),gm_rhs.cols(),trans_rhs);
00066 DMatrixSlice gms_lhs = gm_lhs;
00067 imp_assign(gms_lhs,gm_rhs,trans_rhs);
00068 }
00069
00071 template<class T_Matrix>
00072 void AbstractLinAlgPack::assign(DMatrixSlice& gms_lhs, const T_Matrix& gm_rhs
00073 , BLAS_Cpp::Transp trans_rhs)
00074 {
00075 DenseLinAlgPack::assert_gms_lhs(gms_lhs,gm_rhs.rows(),gm_rhs.cols(),trans_rhs);
00076 imp_assign(gms_lhs,gm_rhs,trans_rhs);
00077 }
00078
00079
00080
00081
00082 namespace {
00083
00084 template<class T_Matrix>
00085 void imp_assert_V_MtV_rhs_sizes(const T_Matrix& gm_rhs1, BLAS_Cpp::Transp trans_rhs1
00086 , const AbstractLinAlgPack::DVectorSlice& vs_rhs2)
00087 {
00088 typename T_Matrix::size_type
00089 cols = (trans_rhs1 == BLAS_Cpp::no_trans) ? gm_rhs1.cols() : gm_rhs1.rows();
00090
00091 if(cols != vs_rhs2.size())
00092 throw std::length_error("V_MtV: The sizes of the rhs expression do not match");
00093 }
00094
00095
00096 template<class T_Matrix>
00097 void imp_V_MtV_no_trans(AbstractLinAlgPack::DVectorSlice& vs_lhs, const T_Matrix& gm_rhs1
00098 , const AbstractLinAlgPack::DVectorSlice& vs_rhs2)
00099 {
00100 typedef typename T_Matrix::size_type size_type;
00101 size_type rows = gm_rhs1.rows();
00102 AbstractLinAlgPack::DVectorSlice::iterator itr_v_lhs = vs_lhs.begin();
00103 for(size_type i = 1; i <= rows; ++i)
00104 *itr_v_lhs++ = AbstractLinAlgPack::dot(vs_rhs2,gm_rhs1.row(i));
00105 }
00106
00107 template<class T_Matrix>
00108 void imp_V_MtV_trans(AbstractLinAlgPack::DVectorSlice& vs_lhs, const T_Matrix& gm_rhs1
00109 , const AbstractLinAlgPack::DVectorSlice& vs_rhs2)
00110 {
00111 typedef typename T_Matrix::size_type size_type;
00112 size_type cols = gm_rhs1.cols();
00113 AbstractLinAlgPack::DVectorSlice::iterator itr_v_lhs = vs_lhs.begin();
00114 for(size_type j = 1; j <= cols; ++j)
00115 *itr_v_lhs++ = AbstractLinAlgPack::dot(vs_rhs2,gm_rhs1.col(j));
00116 }
00117
00118 }
00119
00120
00121
00122 template<class T_Matrix>
00123 void AbstractLinAlgPack::V_MtV(DVector& v_lhs, const T_Matrix& gm_rhs1, BLAS_Cpp::Transp trans_rhs1
00124 , const DVectorSlice& vs_rhs2)
00125 {
00126 imp_assert_V_MtV_rhs_sizes(gm_rhs1,trans_rhs1,vs_rhs2);
00127 v_lhs.resize( (trans_rhs1==BLAS_Cpp::no_trans) ? gm_rhs1.rows() : gm_rhs1.cols() );
00128 DVectorSlice vs_lhs = v_lhs;
00129 if(trans_rhs1 == BLAS_Cpp::no_trans)
00130 imp_V_MtV_no_trans(vs_lhs,gm_rhs1,vs_rhs2);
00131 else
00132 imp_V_MtV_trans(vs_lhs,gm_rhs1,vs_rhs2);
00133 }
00134
00135 template<class T_Matrix>
00136 void AbstractLinAlgPack::V_MtV(DVectorSlice& v_lhs, const T_Matrix& gm_rhs1, BLAS_Cpp::Transp trans_rhs1
00137 , const DVectorSlice& vs_rhs2)
00138 {
00139 imp_assert_V_MtV_rhs_sizes(gm_rhs1,trans_rhs1,vs_rhs2);
00140 DenseLinAlgPack::assert_resize_vs_lhs(v_lhs, (trans_rhs1==BLAS_Cpp::no_trans) ? gm_rhs1.rows() : gm_rhs1.cols());
00141 if(trans_rhs1 == BLAS_Cpp::no_trans)
00142 imp_V_MtV_no_trans(v_lhs,gm_rhs1,vs_rhs2);
00143 else
00144 imp_V_MtV_trans(v_lhs,gm_rhs1,vs_rhs2);
00145 }
00146
00147 #endif // MATRIX_VECTOR_TEMPLATE_OP_DEF_H