56 #ifndef SPARSE_VECTOR_OP_DEF_H
57 #define SPARSE_VECTOR_OP_DEF_H
69 T my_my_max(
const T& v1,
const T& v2 ) {
return v1 > v2 ? v1 : v2; }
72 T my_my_min(
const T& v1,
const T& v2 ) {
return v1 < v2 ? v1 : v2; }
75 namespace AbstractLinAlgPack {
84 namespace SparseVectorUtilityPack {
85 template<
class T_SpVec>
90 template<
class T_SpVec>
94 typename T_SpVec::difference_type offset = sv_rhs2.offset();
95 for(
typename T_SpVec::const_iterator iter = sv_rhs2.begin(); iter != sv_rhs2.end(); ++iter)
96 result += vs_rhs1(iter->index()+offset) * iter->value();
101 template<
class T_SpVec>
107 template<
class T_SpVec>
110 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
111 result += ::fabs(iter->value());
116 template<
class T_SpVec>
119 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
120 result += (iter->value()) * (iter->value());
125 template<
class T_SpVec>
128 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
129 result = my_my_max(result,std::fabs(iter->value()));
134 template<
class T_SpVec>
137 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
138 result = my_my_max(iter->value(),result);
143 template<
class T_SpVec>
146 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
147 result = my_my_min(result,iter->value());
152 template<
class T_SpVec>
155 if( alpha == 1.0 )
return;
156 for(
typename T_SpVec::iterator iter = sv_lhs->begin(); iter != sv_lhs->end(); ++iter)
157 iter->value() *= alpha;
161 template<
class T_SpVec>
165 typename T_SpVec::difference_type offset = sv_rhs.offset();
166 for(
typename T_SpVec::const_iterator iter = sv_rhs.begin(); iter != sv_rhs.end(); ++iter)
167 (*vs_lhs)(iter->index() + offset) += alpha * iter->value();
171 template<
class T_SpVec>
190 typename T_SpVec::difference_type offset = sv_rhs2.offset();
192 for(
typename T_SpVec::const_iterator sv_rhs2_itr = sv_rhs2.begin(); sv_rhs2_itr != sv_rhs2.end(); ++sv_rhs2_itr)
194 ,
col( gms_rhs1, trans_rhs1, sv_rhs2_itr->index() + offset ) );
198 template<
class T_SpVec>
222 typename T_SpVec::difference_type offset = sv_rhs2.offset();
223 for(
typename T_SpVec::const_iterator sv_itr = sv_rhs2.begin(); sv_itr != sv_rhs2.end(); ++sv_itr)
251 switch(effective_uplo) {
257 vs_lhs(j) += alpha * sv_itr->value();
263 ,
col(tri_rhs1.
gms(),trans_rhs1,j)(j_adjusted,n) );
272 vs_lhs(j) += alpha * sv_itr->value();
278 ,
col(tri_rhs1.
gms(),trans_rhs1,j)(1,j_adjusted) );
287 template<
class T_SpVec>
297 switch(sym_rhs1.
uplo()) {
300 for(vs_lhs_itr = vs_lhs.
begin(), i = 1; i <= size; ++i)
306 sym_rhs1.
gms().
row(i)(1,i)
307 ,sym_rhs1.
gms().
col(i)(i+1,size)
311 *vs_lhs_itr++ += alpha *
318 for(vs_lhs_itr = vs_lhs.
begin(), i = 1; i <= size; ++i)
324 sym_rhs1.
gms().
col(i)(1,i-1)
325 ,sym_rhs1.
gms().
row(i)(i,size)
336 namespace SparseVectorUtilityPack {
345 template<
class T_SpVec>
350 typename T_SpVec::difference_type offset = sv.offset();
351 for(
typename T_SpVec::const_iterator sv_itr = sv.begin(); sv_itr != sv.end(); ++sv_itr) {
352 typename T_SpVec::element_type::indice_type curr_indice = sv_itr->index()+offset;
353 if(curr_indice <= split)
354 result += vs1(curr_indice) * sv_itr->value();
356 result += vs2(curr_indice - split) * sv_itr->value();
365 #endif // SPARSE_VECTOR_OP_DEF_H
DVectorSlice row(DMatrixSlice &gms, BLAS_Cpp::Transp trans, size_type i)
void Vp_StSV(DVectorSlice *vs_lhs, value_type alpha, const T_SpVec &sv_rhs)
vs_lhs += alpha * sv_rhs (BLAS xAXPY)
void Vp_StV(DVectorSlice *vs_lhs, value_type alpha, const DVectorSlice &vs_rhs)
vs_lhs += alpha * vs_rhs (BLAS xAXPY)
size_type dim() const
Returns the number of elements of the VectorSliceTmpl.
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
BLAS_Cpp::Uplo uplo() const
size_type cols() const
Return the number of columns.
RTOp_value_type value_type
value_type min_SV(const T_SpVec &sv_rhs)
result = min(sv_rhs)
void Vp_StMtSV(DVectorSlice *vs_lhs, value_type alpha, const DMatrixSlice &gms_rhs1, BLAS_Cpp::Transp trans_rhs1, const T_SpVec &sv_rhs2)
vs_lhs += alpha * op(gms_rhs1) * sv_rhs2 (BLAS xGEMV)
value_type norm_1_SV(const T_SpVec &sv_rhs)
result = ||sv_rhs||1 (BLAS xASUM)
C++ Standard Library compatable iterator class for accesing nonunit stride arrays of data...
BLAS_Cpp::Uplo uplo() const
std::vector< std::string > split(const std::string &str, const std::string &delimiters, const size_t start=0)
value_type norm_inf_SV(const T_SpVec &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
value_type norm_2_SV(const T_SpVec &sv_rhs)
result = ||sv_rhs||2 (BLAS xNRM2)
void Vp_V_assert_sizes(size_type v_lhs_size, size_type v_rhs_size)
v_lhs += op v_rhs
RTOp_index_type size_type
value_type imp_dot2_V_V_SV(const DVectorSlice &vs1, const DVectorSlice &vs2, const T_SpVec &sv)
DVectorSlice col(DMatrixSlice &gms, BLAS_Cpp::Transp trans, size_type j)
void VopV_assert_sizes(size_type v_rhs1_size, size_type v_rhs2_size)
v_rhs1 op v_rhs2
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
size_type rows() const
Return the number of rows.
value_type max_SV(const T_SpVec &sv_rhs)
result = max(sv_rhs)
BLAS_Cpp::Diag diag() const
AbstractLinAlgPack::value_type value_type
void Vp_MtV_assert_sizes(size_type v_lhs_size, size_type m_rhs1_rows, size_type m_rhs1_cols, BLAS_Cpp::Transp trans_rhs1, size_type v_rhs2_size)
v_lhs += op(m_rhs1) * v_rhs2
value_type dot_SV_V(const T_SpVec &sv_rhs1, const DVectorSlice &vs_rhs2)
result = dot(sv_rhs1,vs_rhs2) (BLAS xDOT)
value_type dot_V_SV(const DVectorSlice &vs_rhs1, const T_SpVec &sv_rhs2)
result = dot(vs_rhs1,sv_rhs2) (BLAS xDOT)
DVectorSlice col(size_type j)
Return DVectorSlice object representing the jth column (1-based; 1,2,..,#this->cols()#, or throw std::out_of_range)
DVectorSlice row(size_type i)
Return DVectorSlice object representing the ith row (1-based; 1,2,..,#this->rows()#, or throw std::out_of_range)