diff --git a/sparsesmat.cc b/sparsesmat.cc index 5932ef2..7af5eae 100644 --- a/sparsesmat.cc +++ b/sparsesmat.cc @@ -58,7 +58,7 @@ for(SPMatindex k=0; k prod=av.otimes(bv,false,alpha); - //scatter the results + //scatter the results -- probably the computational bottleneck for(i=0; i +void SparseSMat::axpy(const T alpha, const SparseSMat &x, const bool transp) +{ +if(nn!=x.nn) laerror("incompatible matrix dimensions in SparseSMat::axpy"); +if(alpha==(T)0) return; +copyonwrite(); +for(SPMatindex i=0; i; + typename std::map::iterator p; + for(p=x.v[i]->begin(); p!=x.v[i]->end(); ++p) (*v[i])[p->first] = p->second * alpha; + } +} + + +template +void SparseSMat::gemv(const T beta, NRVec &r, const char trans, const T alpha, const NRVec &x) const +{ +if(nn!=r.size() || nn!= x.size()) laerror("incompatible matrix vector dimensions in SparseSMat::gemv"); +r *= beta; +if(alpha == (T)0) return; +r.copyonwrite(); +for(SPMatindex i=0; i::iterator p; + for(p=v[i]->begin(); p!=v[i]->end(); ++p) r[i] += x[p->first] * p->second * alpha ; + } +} + #define INSTANTIZE(T) \ template void SparseSMat::gemm(const T beta, const SparseSMat &a, const char transa, const SparseSMat &b, const char transb, const T alpha); \ template SparseSMat & SparseSMat::operator*=(const T &a); \ +template void SparseSMat::gemv(const T beta, NRVec &r, const char trans, const T alpha, const NRVec &x) const; \ +template void SparseSMat::axpy(const T alpha, const SparseSMat &x, const bool transp); \ + INSTANTIZE(double)