47 for(; iter != iter_end; ++iter, ++i) {
50 nnz += iter->second->size();
66 for(; iter != iter_end; ++iter) {
67 const CSVec* v = iter->second;
68 const std::vector<int>& v_ind = v->
indices();
69 const std::vector<double>& v_coef = v->
coefs();
70 for(
size_t i=0; i<v_ind.size(); ++i) {
71 colind_ptr[offset] = v_ind[i];
72 coef_ptr[offset++] = v_coef[i];
99 return !(*
this == rhs);
111 const std::vector<int>& xind = x.
indices();
112 const std::vector<double>& xcoef = x.
coefs();
114 const double* xcoef_ptr = xcoef.empty() ? NULL : &xcoef[0];
115 const int* xind_ptr = xind.empty() ? NULL : &xind[0];
116 int xlen = xcoef.size();
118 std::vector<int>& yind = y.
indices();
119 std::vector<double>& ycoef = y.
coefs();
126 int* yind_ptr = yind.size() > 0 ? &yind[0] : NULL;
127 double* ycoef_ptr = ycoef.size() > 0 ? &ycoef[0] : NULL;
129 int jbeg = *rowoffs++;
130 for(
unsigned i=0; i<nrows; ++i) {
131 int jend = *rowoffs++;
138 sum += Acoef[jbeg]*xcoef_ptr[xoff];
143 yind_ptr[i] = rows[i];
155 const std::vector<int>& xind = x.
indices();
156 const std::vector<double>& xcoef = x.
coefs();
158 const double* xcoef_ptr = xcoef.empty() ? NULL : &xcoef[0];
162 std::vector<int> offsets;
164 const int* offsetsptr = &offsets[0];
168 int jbeg = *rowoffs++;
169 for(
unsigned i=0; i<nrows; ++i) {
170 int jend = *rowoffs++;
172 int xoff = offsetsptr[i];
178 double xcoeff = xcoef_ptr[xoff];
181 add_entry(fy, colinds[jbeg],Acoef[jbeg]*xcoeff);
190 bool storeResultZeros)
198 if (Arows.size() < 1 || Brows.size() < 1) {
210 static double fei_min = std::numeric_limits<double>::min();
212 int jbeg = *Arowoffs++;
213 for(
size_t i=0; i<Arows.size(); ++i) {
215 int jend = *Arowoffs++;
218 if (storeResultZeros) {
228 double Acoef = *Acoefs++;
232 if (Brow_offset < 0) {
236 if (!storeResultZeros) {
237 if (std::abs(Acoef) < fei_min) {
242 const int* Brow_cols = Bcols.empty() ? NULL : &(Bcols[Browoffs[Brow_offset]]);
243 const double* Brow_coefs = Bcoefs==NULL ? NULL : &(Bcoefs[Browoffs[Brow_offset]]);
244 int Brow_len = Browoffs[Brow_offset+1]-Browoffs[Brow_offset];
246 for(
int k=0; k<Brow_len; ++k) {
247 double resultCoef = Acoef*Brow_coefs[k];
248 int resultCol = Brow_cols[k];
250 if (!storeResultZeros) {
251 if (std::abs(resultCoef) < fei_min) {
256 if (fc_row == NULL) {
260 add_entry(*fc_row, resultCol, resultCoef);
269 bool storeResultZeros)
277 if (Arows.size() < 1 || Brows.size() < 1) {
282 const size_t numArows = Arows.size();
291 std::vector<double> row_coefs;
293 static double fei_min = std::numeric_limits<double>::min();
295 std::vector<int> offsets;
298 int jbeg = *Arowoffs++;
299 for(
size_t i=0; i<numArows; ++i) {
300 int jend = *Arowoffs++;
302 int Brow_offset = offsets[i];
303 if (Brow_offset < 0) {
308 const int* Brow_cols = Bcols.empty() ? NULL : &(Bcols[Browoffs[Brow_offset]]);
309 const double* Brow_coefs = Bcoefs==NULL ? NULL : &(Bcoefs[Browoffs[Brow_offset]]);
310 int Brow_len = Browoffs[Brow_offset+1]-Browoffs[Brow_offset];
312 if ((
int)row_coefs.size() < Brow_len) row_coefs.resize(Brow_len*2);
313 double* row_coefs_ptr = &row_coefs[0];
316 int Acol = Acols[jbeg];
317 double Acoef = Acoefs[jbeg++];
319 if (std::abs(Acoef) < fei_min && !storeResultZeros) {
323 for(
int k=0; k<Brow_len; ++k) {
324 row_coefs_ptr[k] = Acoef*Brow_coefs[k];
327 fc.
sumInRow(Acol, Brow_cols, row_coefs_ptr, Brow_len);
341 for(
size_t i=0; i<rows.size(); ++i) {
344 for(
int j=rowoffs[i]; j<rowoffs[i+1]; ++j) {
CSRMat & operator+=(const CSRMat &src)
void multiply_CSRMat_CSRMat(const CSRMat &A, const CSRMat &B, CSRMat &C, bool storeResultZeros)
unsigned getNumRows() const
CSVec * create_or_getRow(int row)
std::vector< int > & indices()
bool hasRow(int row) const
std::vector< int > rowNumbers
void multiply_trans_CSRMat_CSVec(const CSRMat &A, const CSVec &x, CSVec &y)
void add_CSRMat_to_FillableMat(const CSRMat &csrm, FillableMat &fm)
std::vector< int > packedColumnIndices
std::vector< int > rowOffsets
void find_offsets(const std::vector< int > &sources, const std::vector< int > &targets, std::vector< int > &offsets)
std::vector< double > packedcoefs_
bool operator!=(const CSRMat &rhs) const
int binarySearch(const T &item, const T *list, int len)
feipoolmat::const_iterator const_iterator
void sumInRow(int row, const int *cols, const double *coefs, unsigned len)
bool operator==(const CSRMat &rhs) const
SparseRowGraph & getGraph()
void multiply_trans_CSRMat_CSRMat(const CSRMat &A, const CSRMat &B, CSRMat &C, bool storeResultZeros)
void sumInCoef(int row, int col, double coef)
void add_entry(CSVec &vec, int eqn, double coef)
CSRMat & operator=(const FillableMat &src)
void multiply_CSRMat_CSVec(const CSRMat &A, const CSVec &x, CSVec &y)
unsigned getNumRows() const
std::vector< double > & getPackedCoefs()
std::vector< double > & coefs()