127 for ( vector<Index>::iterator j =
mcolptr.begin() + c + 1;
137 return *(
mdata.insert(
mdata.begin()+i, 0 ) );
153 {
return this->
ro(r, c); }
189 for (
Index i=begin; i<end; ++i )
286 vector<Index> mrowind_ref(
mrowind.size());
289 vector<Numeric> mdata_ref(
mdata.size());
292 mrowind.resize(mrowind_ref.size()+rnnz);
293 mdata.resize(mdata_ref.size()+rnnz);
297 vector<Index>::iterator mrowind_it =
mrowind.begin();
298 vector<Numeric>::iterator mdata_it =
mdata.begin();
301 Index colptr_mod = 0;
308 vector<Numeric>::iterator dstart = mdata_ref.begin()+
mcolptr[i];
309 vector<Numeric>::iterator dend = mdata_ref.begin()+
mcolptr[i+1];
310 vector<Index>::iterator rstart = mrowind_ref.begin()+
mcolptr[i];
311 vector<Index>::iterator rend = mrowind_ref.begin()+
mcolptr[i+1];
321 vector<Index>::iterator rpos = find(rstart,rend,r);
322 vector<Numeric>::iterator dpos = dstart+(rpos-rstart);
330 copy(rstart,rend,mrowind_it);
331 copy(dstart,dend,mdata_it);
334 mrowind_it += rend-rstart;
335 mdata_it += dend-dstart;
338 colptr_mod =
mcolptr[i]+(rend-rstart);
344 rpos = find_if(rstart,rend,bind2nd(std::greater<Index>(),r));
345 dpos = dstart+(rpos-rstart);
348 copy(rstart,rpos,mrowind_it);
349 copy(dstart,dpos,mdata_it);
353 mrowind_it += rpos-rstart;
354 mdata_it += dpos-dstart;
367 copy(rpos,rend,mrowind_it);
368 copy(dpos,dend,mdata_it);
371 mrowind_it += rend-rpos;
372 mdata_it += dend-dpos;
375 colptr_mod =
mcolptr[i]+(rend-rstart+1);
382 vector<Index>::iterator rpos = find(rstart,rend,r);
383 vector<Numeric>::iterator dpos = dstart+(rpos-rstart);
388 remove_copy(rstart,rend,mrowind_it, *rpos);
389 remove_copy(dstart,dend,mdata_it, *dpos);
392 mrowind_it += rend-rstart-1;
393 mdata_it += dend-dstart-1;
396 colptr_mod =
mcolptr[i]+(rend-rstart-1);
402 copy(rstart,rend,mrowind_it);
403 copy(dstart,dend,mdata_it);
406 mrowind_it += rend-rstart;
407 mdata_it += dend-dstart;
410 colptr_mod =
mcolptr[i]+(rend-rstart);
415 *(
mcolptr.end()-1) = colptr_mod;
439 mcolptr = vector<Index>( c+1, n);
441 mdata = vector<Numeric>(n,1.0);
445 vector<Index>::iterator rit = mrowind.begin();
446 vector<Index>::iterator cit =
mcolptr.begin();
447 for(
Index i=0; i<n; i++ ) {
477 mcolptr = vector<Index>(c+1,0);
497 for (
size_t c=0; c<v.
mcolptr.size()-1; ++c)
508 for (
Index i=begin; i<end; ++i )
514 os << setw(3) << r <<
" " 515 << setw(3) << c <<
" " 516 << setw(3) << v.
mdata[i] <<
"\n";
548 for (
Index i=0; i<end; i++)
592 for (
size_t c=0; c<M.
mcolptr.size()-1; ++c)
603 for (
Index i=begin; i<end; ++i )
609 y[r] += M.
mdata[i] * x[c];
646 for (
size_t c=0; c<B.
mcolptr.size()-1; ++c)
657 for (
Index i=begin; i<end; ++i )
670 A(r,j) += B.
mdata[i] *
C(c,j);
695 if ( B.
mdata.size() == 0)
return;
707 vector<Index>::const_iterator startrow, stoprow;
715 for (
Index i=*startrow; i<=*stoprow; i++)
728 vector<Numeric>::iterator dataA_it = A.
mdata.begin();
729 vector<Index>::iterator rowindA_it = A.
mrowind.begin();
733 for (
size_t c=0; c<A.
mcolptr.size(); ++c)
737 for (
size_t i=0; i<B.
mcolptr.size()-1; i++)
741 vector<Index>::const_iterator elem_it =
755 vector<Numeric>::const_iterator elemdata_it=B.
mdata.begin() + diff;
756 *dataA_it = *elemdata_it;
803 for (
size_t c=0; c<C.
mcolptr.size()-1; ++c)
809 for (
size_t b=0; b<Bt.mcolptr.size()-1; ++b)
813 std::set<Index> colintersec;
816 Bt.mrowind.begin()+*(Bt.mcolptr.begin()+b),
817 Bt.mrowind.begin()+*(Bt.mcolptr.begin()+b+1),
818 inserter(colintersec, colintersec.begin()));
822 if (!colintersec.empty())
825 for (std::set<Index>::iterator i=colintersec.begin();
826 i!=colintersec.end(); ++i)
835 vector<Index>::const_iterator rowindBt_it =
836 find(Bt.mrowind.begin()+*(Bt.mcolptr.begin()+b),
837 Bt.mrowind.begin()+*(Bt.mcolptr.begin()+b+1), *i);
838 vector<Index>::const_iterator rowindC_it =
842 vector<Numeric>::const_iterator dataBt_it =
843 Bt.mdata.begin()+(rowindBt_it-Bt.mrowind.begin());
844 vector<Numeric>::const_iterator dataC_it =
847 tempA += *dataBt_it * *dataC_it;
883 if (B.
data().size() < C.
data().size())
894 for (
size_t c = 0; c < D->mcolptr.size()-1; ++c)
899 A.
rw(D->mrowind[i], c) += D->mdata[i];
930 for (
size_t c = 0; c < C.
mcolptr.size()-1; ++c)
INDEX Index
The type to use for all integer numbers and indices.
Index nnz() const
Returns the number of nonzero elements.
Numeric operator()(Index r, Index c) const
Plain index operator.
Index mrr
Number of rows in the sparse matrix.
void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Copy data between begin and end to target.
const std::vector< Numeric > & data() const
Index mcr
Number of rows in the sparse matrix.
Index ncols() const
Returns the number of columns.
Numeric & rw(Index r, Index c)
Read and write index operator.
void make_I(Index r, Index c)
Make Identity matrix.
Index nelem() const
Returns the number of elements.
Index ncols() const
Returns the number of columns.
Sparse()
Default constructor.
Header file for sparse matrices.
friend void transpose(Sparse &A, const Sparse &B)
Transpose of sparse matrix.
friend void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
Index nrows() const
Returns the number of rows.
friend void mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
std::vector< Index > mcolptr
Pointers to first data element for each column.
NUMERIC Numeric
The type to use for all floating point numbers.
friend void sub(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse subtraction.
friend std::ostream & operator<<(std::ostream &os, const Sparse &v)
Output operator for Sparse.
std::vector< Index > mrowind
Row indices.
Numeric ro(Index r, Index c) const
Read only index operator.
A constant view of a Vector.
A constant view of a Matrix.
void resize(Index r, Index c)
Resize function.
std::vector< Numeric > mdata
The actual data values.
friend void add(Sparse &A, const Sparse &B, const Sparse &C)
Sparse - Sparse addition.
void insert_row(Index r, Vector v)
Insert row function.
Index nrows() const
Returns the number of rows.