ConicBundle
sparsmat.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CH_MATRIX_CLASSES__SPARSMAT_HXX
4 #define CH_MATRIX_CLASSES__SPARSMAT_HXX
5 
15 #ifndef CH_MATRIX_CLASSES__SYMMAT_HXX
16 #include "symmat.hxx"
17 #endif
18 
19 namespace CH_Matrix_Classes {
20 
21 //everything involving a "Sparsesym" is implemented in "sparssym.cxx/hxx"
22 
24 #define SPARSE_ZERO_TOL 1e-60
25 
28 
74 class Sparsemat: protected Memarrayuser
75 {
76  friend class Indexmatrix;
77  friend class Matrix;
78  friend class Symmatrix;
79  friend class Sparsesym;
80 
81 private:
82 
85  nc;
86 
87  //column by column representation
91 
92  //row by row representation (see column by column)
96 
97 
99 
100  bool is_init;
101 
103  void init_to_zero();
105  Integer find_column(Integer i) const;
106 
108  Integer find_row(Integer i) const;
109 
110 public:
111 
112  //----------------------------------------------------
113  //---- constructors, destructor, and initialization
114  //----------------------------------------------------
115 
119 
121  inline Sparsemat();
123  inline Sparsemat(const Sparsemat& A,Real d=1.);
125  inline Sparsemat(Integer nr,Integer nc);
127  inline Sparsemat(Integer nr,Integer nc,Integer nz,
128  const Integer *ini,const Integer *inj,const Real* va);
130  inline Sparsemat(Integer nr,Integer nc,Integer nz,
131  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va);
132 
133 #if (CONICBUNDLE_DEBUG>=1)
134  void set_init(bool i){is_init=i;}
137  bool get_init() const {return is_init;}
138 #else
139  void set_init(bool /* i */){}
142  bool get_init() const {return true;}
143 #endif
144 
146  inline Sparsemat& init(const Sparsemat& A,Real d=1.);
148  inline Sparsemat& init(const Matrix& A,Real d=1.);
150  inline Sparsemat& init(const Indexmatrix& A,Real d=1.);
152  inline Sparsemat& init(const Symmatrix&,Real d=1.);
154  inline Sparsemat& init(const Sparsesym&,Real d=1.);
156  inline Sparsemat& init(Integer nr,Integer nc); //zero-matrix of size nr*nc
159  const Integer *ini,const Integer *inj,const Real* va);
162  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va);
163 
165  void set_tol(Real t){tol=t;}
166 
168 
172 
174  inline Sparsemat(const Matrix& A, Real d=1.);
176  inline Sparsemat(const Indexmatrix& A,Real d=1.);
178  inline Sparsemat(const Symmatrix& A,Real d=1.);
180  inline Sparsemat(const Sparsesym& A,Real d=1.);
181 
183 
184  //----------------------------------------------------
185  //---- size and type information
186  //----------------------------------------------------
187 
191 
193  void dim(Integer& in_nr, Integer& in_nc) const {in_nr=nr; in_nc=nc;}
194 
196  Integer dim() const {return nr*nc;}
197 
199  Integer rowdim() const {return nr;}
200 
202  Integer coldim() const {return nc;}
203 
205  Integer nonzeros() const {return colval.dim();}
206 
208  Integer col_nonzeros(Integer i,Integer* startind=0) const;
209 
211  Integer row_nonzeros(Integer i,Integer* startind=0) const;
212 
214  Mtype get_mtype() const {return mtype;}
215 
216 
218 
219 
220 
221  //--------------------------------
222  //---- Indexing and Submatrices
223  //--------------------------------
224 
225 
229 
231  Real operator()(Integer i,Integer j) const;
232 
234  inline Real operator()(Integer i) const;
235 
237  inline Real operator[](Integer i) const;
238 
240  Sparsemat col(Integer i) const;
241 
243  Sparsemat row(Integer i) const;
245  Sparsemat cols(const Indexmatrix& ind) const;
247  Sparsemat rows(const Indexmatrix& ind) const;
248 
250  Sparsemat& delete_rows(const Indexmatrix& ind);
252  Sparsemat& delete_cols(const Indexmatrix& ind);
253 
255  Sparsemat& insert_row(Integer i,const Sparsemat& v);
257  Sparsemat& insert_col(Integer i,const Sparsemat& v);
258 
260  Sparsemat& concat_right(const Sparsemat& A);
262  Sparsemat& concat_below(const Sparsemat& A);
263 
265  const Indexmatrix& get_colinfo() const {return colinfo;}
267  const Indexmatrix& get_colindex() const {return colindex;}
269  const Matrix& get_colval() const {return colval;}
270 
272  const Indexmatrix& get_rowinfo() const {return rowinfo;}
274  const Indexmatrix& get_rowindex() const {return rowindex;}
276  const Matrix& get_rowval() const {return rowval;}
277 
279  void get_edge_rep(Indexmatrix& I, Indexmatrix& J, Matrix& val) const;
281  int get_edge(Integer i,Integer& indi,Integer& indj, Real& val) const;
283  int contains_support(const Sparsemat& A) const;
284 
285 
287 
288 
292 
294  friend inline Sparsemat concat_right(const Sparsemat& A,const Sparsemat& B);
296  friend inline Sparsemat concat_below(const Sparsemat& A,const Sparsemat& B);
297 
299  friend void swap(Sparsemat& A, Sparsemat& B);
300 
302 
303  //------------------------------
304  //---- BLAS-like Routines
305  //------------------------------
306 
310 
312  Sparsemat& xeya(const Sparsemat& A,Real d=1.);
314  Sparsemat& xeya(const Matrix& A,Real d=1.);
316  Sparsemat& xeya(const Indexmatrix& A,Real d=1.);
317 
319 
323 
325  friend Sparsemat& xbpeya(Sparsemat& x,const Sparsemat& y,Real alpha,Real beta,int ytrans);
326 
328  friend Matrix& genmult(const Sparsemat& A,const Matrix& B,Matrix &C,
329  Real alpha,Real beta, int atrans,int btrans);
330  //C=beta*C+alpha A B
331 
333  friend Matrix& genmult(const Sparsemat& A,const Matrix& B,Integer colB,Matrix &C,Integer colC,Real alpha,Real beta, int atrans,int btrans);
334  //C=beta*C+alpha A B
335 
337  friend Matrix& genmult(const Matrix& A,const Sparsemat& B,Matrix &C,
338  Real alpha,Real beta, int atrans,int btrans);
339  //C=beta*C+alpha A B
340 
342  friend Matrix& genmult(const Sparsemat& A,const Sparsemat& B,Matrix &C,
343  Real alpha,Real beta, int atrans,int btrans);
344  //C=beta*C+alpha A B
345 
347 
348  //------------------------------
349  //---- usual operators
350  //------------------------------
351 
355 
357  inline Sparsemat& operator=(const Sparsemat& A);
359  inline Sparsemat& operator+=(const Sparsemat& A);
361  inline Sparsemat& operator-=(const Sparsemat& A);
363  inline Sparsemat operator-() const;
364 
366  inline Sparsemat& operator*=(Real d);
368  inline Sparsemat& operator/=(Real d);
369 
371  Sparsemat& operator=(const Matrix& A);
373  Sparsemat& operator=(const Indexmatrix& A);
374 
376  Sparsemat& transpose();
377 
379 
383 
385  friend Sparsemat operator*(const Sparsemat& A,const Sparsemat& B);
387  friend inline Sparsemat operator+(const Sparsemat &A,const Sparsemat& B);
389  friend inline Sparsemat operator-(const Sparsemat &A,const Sparsemat& B);
390 
392  friend inline Sparsemat operator*(const Sparsemat& A,Real d);
394  friend inline Sparsemat operator*(Real d,const Sparsemat& A);
396  friend inline Sparsemat operator/(const Sparsemat& A,Real d);
397 
399  friend inline Matrix operator*(const Sparsemat& A,const Matrix& B);
401  friend inline Matrix operator*(const Matrix& A,const Sparsemat& B);
403  friend inline Matrix operator+(const Sparsemat& A,const Matrix& B);
405  friend inline Matrix operator+(const Matrix& A,const Sparsemat& B);
407  friend inline Matrix operator-(const Sparsemat& A,const Matrix& B);
409  friend inline Matrix operator-(const Matrix& A,const Sparsemat& B);
410 
412  friend inline Sparsemat transpose(const Sparsemat& A);
413 
415 
416  //------------------------------------------
417  //---- Connections to other Matrix Classes
418  //------------------------------------------
419 
423 
425  Sparsemat& xeya(const Sparsesym& A,Real d=1.);
427  inline Sparsemat& operator=(const Symmatrix& A);
429  inline Sparsemat& operator=(const Sparsesym& A);
430 
432 
436 
438  friend Matrix& genmult(const Symmatrix& A,const Sparsemat& B,Matrix& C,
439  Real alpha,Real beta,int btrans);
440  //returns C=beta*C+alpha*A*B, where A and B may be transposed
441 
443  friend Matrix& genmult(const Sparsemat& A,const Symmatrix& B,Matrix& C,
444  Real alpha,Real beta, int atrans);
445 
447  friend Matrix& genmult(const Sparsesym& A,const Sparsemat& B,Matrix &C,
448  Real alpha,Real beta, int btrans);
449 
451  friend Matrix& genmult(const Sparsemat& A,const Sparsesym& B,Matrix &C,
452  Real alpha,Real beta,int atrans);
453 
455  friend Symmatrix& rankadd(const Sparsemat& A,Symmatrix& C,
456  Real alpha,Real beta,int trans);
457  // returns C=beta*C+alpha* A*A^T, where A may be transposed
458 
460  friend Symmatrix& scaledrankadd(const Sparsemat& A,const Matrix& D,Symmatrix& C,
461  Real alpha,Real beta,int trans);
462  // returns C=beta*C+alpha* A*D*A^T, where A may be transposed
463 
465  friend Symmatrix& rank2add(const Sparsemat& A,const Matrix& B,Symmatrix& C,
466  Real alpha,Real beta,int trans);
467  // returns C=beta*C+alpha* sym(A*B^T) [or sym(A^T*B)]
468 
470  friend inline Matrix operator*(const Symmatrix& A,const Sparsemat& B);
472  friend inline Matrix operator*(const Sparsemat& A,const Symmatrix& B);
473 
475 
476  //------------------------------
477  //---- Elementwise Operations
478  //------------------------------
479 
483 
485  friend Sparsemat abs(const Sparsemat& A);
486 
488 
489  //----------------------------
490  //---- Numerical Methods
491  //----------------------------
492 
496 
498  Sparsemat& scale_rows(const Matrix& vec); //A=diag(vec)*A
500  Sparsemat& scale_cols(const Matrix& vec); //A=A*diag(vec)
501 
502 
504 
508 
510  friend Real trace(const Sparsemat& A); //=sum(diag(A))
512  friend Real ip(const Sparsemat& A, const Sparsemat& B); //=trace(B^t*A)
514  friend Real ip(const Sparsemat& A, const Matrix& B); //=trace(B^t*A)
516  friend inline Real ip(const Matrix& A, const Sparsemat& B);
518  friend Real colip(const Sparsemat& A,Integer j,const Matrix* scaling);
520  friend Real rowip(const Sparsemat& A,Integer i,const Matrix* scaling);
522  friend Sparsemat colsip(const Sparsemat& A,const Matrix* scaling);
524  friend Sparsemat rowsip(const Sparsemat& A,const Matrix* scaling);
526  friend inline Real norm2(const Sparsemat& A); //=sqrt(ip(A,A));
527 
529  friend Matrix sumrows(const Sparsemat& A); //=(1 1 1 ... 1)*A
531  friend Matrix sumcols(const Sparsemat& A); //=A*(1 1 ... 1)^t
533  friend inline Real sum(const Sparsemat& A); //=(1 1 ... 1)*A*(1 1 ... 1)^t
534 
536 
537  //---------------------------------------------
538  //---- Comparisons / Max / Min / sort / find
539  //---------------------------------------------
540 
544 
546  friend int equal(const Sparsemat& A, const Sparsemat& B,Real eqtol);
547 
549 
550 
551  //--------------------------------
552  //---- Input / Output
553  //--------------------------------
554 
558 
561  void display(std::ostream& out,
562  int precision=0,
563  int width=0,
564  int screenwidth=0
565  ) const;
566 
568 
572 
574  friend std::ostream& operator<<(std::ostream& o,const Sparsemat &v);
576  friend std::istream& operator>>(std::istream& i,Sparsemat &v);
577 
579 
580 };
581 
583 
584 
585 // **************************************************************************
586 // make non inline friends available outside
587 // **************************************************************************
588 
590  void swap(Sparsemat& A, Sparsemat& B);
591 
592 
593 
595  Sparsemat& xbpeya(Sparsemat& x,const Sparsemat& y,Real alpha=1.,Real beta=0.,int ytrans=0);
596 
598 Matrix& genmult(const Sparsemat& A,const Matrix& B,Matrix &C,
599  Real alpha=1.,Real beta=0., int atrans=0,int btrans=0);
601  Matrix& genmult(const Matrix& A,const Sparsemat& B,Matrix &C,
602  Real alpha=1.,Real beta=0., int atrans=0,int btrans=0);
604  Matrix& genmult(const Sparsemat& A,const Sparsemat& B,Matrix &C,
605  Real alpha=1.,Real beta=0., int atrans=0,int btrans=0);
606 
608  Sparsemat operator*(const Sparsemat& A,const Sparsemat& B);
609 
610 
612  Matrix& genmult(const Sparsesym& A,const Sparsemat& B,Matrix &C,
613  Real alpha=1.,Real beta=0., int btrans=0);
614 
616  Matrix& genmult(const Sparsemat& A,const Sparsesym& B,Matrix &C,
617  Real alpha=1.,Real beta=0.,int atrans=0);
618 
620  Sparsemat abs(const Sparsemat& A);
621 
623  Real trace(const Sparsemat& A); //=sum(diag(A))
624 
626  Real ip(const Sparsemat& A, const Sparsemat& B); //=trace(B^t*A)
627 
629  Real ip(const Sparsemat& A, const Matrix& B); //=trace(B^t*A)
630 
632  Real colip(const Sparsemat& A,Integer j,const Matrix* scaling=0);
633 
635  Real rowip(const Sparsemat& A,Integer i,const Matrix* scaling=0);
636 
638  Sparsemat colsip(const Sparsemat& A, const Matrix* colscaling=0);
639 
641  Sparsemat rowsip(const Sparsemat& A, const Matrix* rowscaling=0);
642 
644  Matrix sumrows(const Sparsemat& A); //=(1 1 1 ... 1)*A
645 
647  Matrix sumcols(const Sparsemat& A); //=A*(1 1 ... 1)^t
648 
650  std::ostream& operator<<(std::ostream& o,const Sparsemat &v);
651 
653  std::istream& operator>>(std::istream& i,Sparsemat &v);
654 
655 
656 // **************************************************************************
657 // implementation of inline functions
658 // **************************************************************************
659 
661 {
662  mtype=MTsparse;
663  nr=nc=0;
665  colinfo.init(0,3,Integer(0)); colindex.init(0,1,Integer(0)); colval.init(0,1,0.);
666  rowinfo.init(0,3,Integer(0)); rowindex.init(0,1,Integer(0)); rowval.init(0,1,0.);
667 #if (CONICBUNDLE_DEBUG>=1)
668  is_init=true;
669 #endif
670 }
671 
672 //initialize
673 
675 { return xeya(A,d);}
677 { return xeya(A,d);}
679 { return xeya(A,d);}
680 
681 
683 {
684 chk_range(r,c,-1,-1);
685  colinfo.init(0,3,Integer(0)); colindex.init(0,1,Integer(0)); colval.init(0,1,0.);
686  rowinfo.init(0,3,Integer(0)); rowindex.init(0,1,Integer(0)); rowval.init(0,1,0.);
687 nr=r; nc=c;
688 chk_set_init(*this,1);
689 return *this;
690 }
691 
693 { init_to_zero(); chk_set_init(*this,1);}
694 
695  inline Sparsemat::Sparsemat(const Sparsemat& A,double d):Memarrayuser()
696 { init_to_zero(); xeya(A,d);}
697 inline Sparsemat::Sparsemat(const Matrix& A,double d)
698 { init_to_zero(); xeya(A,d);}
699 inline Sparsemat::Sparsemat(const Indexmatrix& A,double d)
700 { init_to_zero(); xeya(A,d);}
701 
703 { init_to_zero(); init(r,c); }
704 
706  const Integer *ini,const Integer *inj,const Real* va)
707 { init_to_zero(); init(in_nr,in_nc,nz,ini,inj,va);}
708 
710  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va)
711 { init_to_zero(); init(in_nr,in_nc,nz,ini,inj,va);}
712 
714 {return (*this)(i%nr,i/nr);}
716 {return (*this)(i%nr,i/nr);}
717 
719 {chk_init(*this);Integer h=nr; nr=nc;nc=h;swap(colinfo,rowinfo);
720  swap(colindex,rowindex);swap(colval,rowval);return *this;}
721 
723 inline Sparsemat concat_right(const Sparsemat& A,const Sparsemat& B)
724 {Sparsemat C(A);C.concat_right(B);return C;}
725 
727 inline Sparsemat concat_below(const Sparsemat& A,const Sparsemat& B)
728 {Sparsemat C(A);C.concat_below(B);return C;}
729 
731 inline Real norm2(const Sparsemat& A)
732 {
733  chk_init(A);
734  return norm2(A.colval);
735 }
736 
737 
738 inline Sparsemat& Sparsemat::operator=(const Sparsemat &A)
739 { return xeya(A); }
740 inline Sparsemat& Sparsemat::operator+=(const Sparsemat &A)
741 { return xbpeya(*this,A,1.,1.); }
742 inline Sparsemat& Sparsemat::operator-=(const Sparsemat &A)
743 { return xbpeya(*this,A,-1.,1.); }
744 inline Sparsemat& Sparsemat::operator*=(Real d)
745 {chk_init(*this); colval*=d; rowval*=d; return *this;}
746 inline Sparsemat& Sparsemat::operator/=(Real d)
747 {chk_init(*this);colval/=d;rowval/=d;return *this;}
748 inline Sparsemat Sparsemat::operator-() const
749 {return Sparsemat(*this,-1.); }
750 
751 
752 
754 inline Sparsemat operator+(const Sparsemat &A,const Sparsemat& B)
755 { Sparsemat C(A); return xbpeya(C,B,1.,1.); }
756 
758 inline Sparsemat operator-(const Sparsemat &A,const Sparsemat& B)
759 { Sparsemat C(A); return xbpeya(C,B,-1.,1.); }
760 
762 inline Sparsemat operator*(const Sparsemat& A,Real d)
763 {return Sparsemat(A,d);}
764 
766 inline Sparsemat operator*(Real d,const Sparsemat& A)
767 {return Sparsemat(A,d);}
768 
770 inline Sparsemat operator/(const Sparsemat& A,Real d)
771 {return Sparsemat(A,1./d);}
772 
773 inline Sparsemat& Sparsemat::operator=(const Matrix &A)
774 {return xeya(A);}
775 inline Sparsemat& Sparsemat::operator=(const Indexmatrix &A)
776 {return xeya(A);}
777 
778 
780 inline Matrix operator*(const Sparsemat& A,const Matrix& B)
781  {Matrix C;return genmult(A,B,C);}
782 
784 inline Matrix operator*(const Matrix& A,const Sparsemat& B)
785  {Matrix C;return genmult(A,B,C);}
786 
788 inline Matrix operator+(const Sparsemat& A,const Matrix& B)
789  {Matrix C(B);return C.xpeya(A);}
790 
792 inline Matrix operator+(const Matrix& A,const Sparsemat& B)
793  {Matrix C(A);return C.xpeya(B);}
794 
796 inline Matrix operator-(const Sparsemat& A,const Matrix& B)
797  {Matrix C(B,-1.);return C.xpeya(A);}
798 
800 inline Matrix operator-(const Matrix& A,const Sparsemat& B)
801  {Matrix C(A);return C.xpeya(B,-1.);}
802 
803 
805 { init_to_zero(); xeya(Matrix(A),d);}
807 {return xeya(Matrix(A),d);}
808 inline Sparsemat& Sparsemat::operator=(const Symmatrix &A)
809 {return xeya(Matrix(A));}
810 
812 inline Real ip(const Matrix& A, const Sparsemat& B)
813 {return ip(B,A);}
814 
816 inline Real sum(const Sparsemat& A)
817 {return sum(A.colval);}
818 
820 inline Sparsemat transpose(const Sparsemat& A)
821 {Sparsemat B(A); B.transpose(); return B;}
822 
823 
824 inline Matrix::Matrix(const Sparsemat& A, Real d)
825 {init_to_zero(); xeya(A,d);}
826 
827 inline Matrix& Matrix::init(const Sparsemat& A, Real d)
828 {return xeya(A,d);}
829 
830 inline Matrix& Matrix::operator=(const Sparsemat & A)
831 {return xeya(A);}
832 
833 inline Matrix& Matrix::operator*=(const Sparsemat &A)
834 { Matrix C; return *this=genmult(*this,A,C);}
835 
836 inline Matrix& Matrix::operator+=(const Sparsemat &A)
837 {return xpeya(A);}
838 
839 inline Matrix& Matrix::operator-=(const Sparsemat &A)
840 {return xpeya(A,-1.);}
841 
842 
846 
848  int equal(const Sparsemat& A, const Sparsemat& B,Real eqtol=1e-10);
849 
851 
852 
853 }
854 
855 //in order to define the inlines associated with the other matrix
856 //classes, the hxx-files of these are included here, as well.
857 
858 #ifndef CH_MATRIX_CLASSES__SPARSSYM_HXX
859 #include "sparssym.hxx"
860 #endif
861 
862 #endif
863 
#define chk_set_init(x, y)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would allow to set ...
Definition: matop.hxx:1774
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: sparsmat.hxx:196
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
friend Real norm2(const Sparsemat &A)
returns the Frobenius norm of A, i.e., the square root of the sum of A(i,j)*A(i,j) over all i...
Definition: sparsmat.hxx:731
friend Symmatrix & rank2add(const Sparsemat &A, const Matrix &B, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha*(A*B^T+B*A^T)/2 [or for transposed (A^T*B+B^T*A)/2]. If beta==0. then C is initiliazed to the correct size.
Sparsemat & delete_rows(const Indexmatrix &ind)
all rows indexed by vector ind are deleted, no row should appear twice in ind, remaining rows are mov...
friend Matrix sumcols(const Sparsemat &A)
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Matrix operator-(const Matrix &A, const Sparsemat &B)
returns a Matrix equal to A-B
Definition: sparsmat.hxx:800
Sparsemat col(Integer i) const
returns column i copied to a new sparse matrix
Matrix & xpeya(const Matrix &A, Real d=1.)
sets *this+=d*A and returns *this
Matrix colval
gives the value of the element at position i
Definition: sparsmat.hxx:90
Integer row_nonzeros(Integer i, Integer *startind=0) const
returns the number of nonzeros in row i; if nonzeros>0 and startind!=0 then the index of the first no...
friend Sparsemat rowsip(const Sparsemat &A, const Matrix *scaling)
returns the row vector of the squared Frobenius norm of all rows i of A, i.e., the sum of A(i...
int contains_support(const Sparsemat &A) const
returns 1 if A is of the same dimension and the support of A is contained in the support of *this...
void get_edge_rep(Indexmatrix &I, Indexmatrix &J, Matrix &val) const
stores the nz nonzero values of *this in I,J,val so that this(I(i),J(i))=val(i) for i=0...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
Sparsemat & delete_cols(const Indexmatrix &ind)
all colmuns indexed by vector ind are deleted, no column should appear twice in ind, remaining columns are moved up keeping their order, returns *this
Integer find_column(Integer i) const
given column index i, find the corresponding rowindex of colinfo or return -1 if the column is empty ...
#define SPARSE_ZERO_TOL
if the absolute value of an element is below this value, it is considered zero
Definition: sparsmat.hxx:24
friend std::istream & operator>>(std::istream &i, Sparsemat &v)
input format: nr nc nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n
bool get_init() const
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefine...
Definition: sparsmat.hxx:142
const Indexmatrix & get_colinfo() const
returns information on nonzero columns, k by 3, listing: index, %nonzeros, first index in colindex/co...
Definition: sparsmat.hxx:265
friend void swap(Sparsemat &A, Sparsemat &B)
swap the content of the two sparse matrices A and B (involves no copying)
void display(std::ostream &out, int precision=0, int width=0, int screenwidth=0) const
displays a matrix in a pretty way for bounded screen widths; for variables of value zero default valu...
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Sparsemat & insert_row(Integer i, const Sparsemat &v)
insert the row vector v before row i, 0<=i<= row dimension, for i==row dimension the row is appended ...
friend Real colip(const Sparsemat &A, Integer j, const Matrix *scaling)
returns the squared Frobenius norm of col i of A, i.e., the sum of A(i,j)*A(i,j) over all i with poss...
Matrix & init(const Matrix &A, Real d=1., int atrans=0)
initialize to *this=A*d where A may be transposed
Definition: matrix.hxx:1035
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: matrix.hxx:209
Mtype
serves for specifying the source (matrix class or function) of the error
Definition: matop.hxx:1585
Integer col_nonzeros(Integer i, Integer *startind=0) const
returns the number of nonzeros in column i; if nonzeros>0 and startind!=0 then the index of the first...
Real tol
>0, if abs(value)<tol, then value is taken to be zero
Definition: sparsmat.hxx:98
void dim(Integer &in_nr, Integer &in_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: sparsmat.hxx:193
friend Matrix & genmult(const Sparsemat &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int atrans, int btrans)
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta=...
friend Symmatrix & scaledrankadd(const Sparsemat &A, const Matrix &D, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha* A*D*A^T, where D is a vector representing a diagonal matrix and A may be tran...
friend Real trace(const Sparsemat &A)
returns the sum of the diagonal elements A(i,i) over all i
const Matrix & get_colval() const
returns the value vector of the column representation holding the value for each element ...
Definition: sparsmat.hxx:269
Sparsemat & xeya(const Sparsemat &A, Real d=1.)
sets *this=d*A and returns *this
Sparsemat()
empty matrix
Definition: sparsmat.hxx:692
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
friend int equal(const Sparsemat &A, const Sparsemat &B, Real eqtol)
returns 1 if both matrices are identical, 0 otherwise
Matrix rowval
gives the value of the element at position i
Definition: sparsmat.hxx:95
Integer nc
number of columns
Definition: sparsmat.hxx:84
Header declaring the class CH_Matrix_Classes::Symmatrix for symmetric matrices with Real elements...
Sparsemat & concat_below(const Sparsemat &A)
concats sparse matrix A to the bottom of *this, A or *this may be the 0x0 matrix initally, returns *this
friend Sparsemat operator+(const Sparsemat &A, const Sparsemat &B)
returns a Sparsemat equal to A+B
Definition: sparsmat.hxx:754
Indexmatrix rowinfo
k by 3, for nonzero rows: index, # nonzeros, first index in colindex/colval
Definition: sparsmat.hxx:93
const Indexmatrix & get_rowindex() const
returns the index vector of the row representation holding the column index for each element ...
Definition: sparsmat.hxx:274
void set_tol(Real t)
set tolerance for recognizing zero values to t
Definition: sparsmat.hxx:165
Integer find_row(Integer i) const
given row index i, find the corresponding rowindex of rowinfo or return -1 if the row is empty ...
Indexmatrix rowindex
gives the column index of the element at position i, (sorted increasingly per row) ...
Definition: sparsmat.hxx:94
friend Sparsemat & xbpeya(Sparsemat &x, const Sparsemat &y, Real alpha, Real beta, int ytrans)
returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to...
error arises in a message of CH_Matrix_Classes::Sparsemat
Definition: matop.hxx:1590
friend Real ip(const Sparsemat &A, const Sparsemat &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Sparsemat & init(const Sparsemat &A, Real d=1.)
initialize to *this=A*d
Definition: sparsmat.hxx:674
friend Symmatrix & rankadd(const Sparsemat &A, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha* A*A^T, where A may be transposed; if beta==0. then C is initialized to the co...
Mtype get_mtype() const
returns the type of the matrix, MTmatrix
Definition: sparsmat.hxx:214
friend Real rowip(const Sparsemat &A, Integer i, const Matrix *scaling)
returns the squared Frobenius norm of row i of A, i.e., the sum of A(i,j)*A(i,j) over all j with poss...
Sparsemat & transpose()
transposes itself (swaps row and column representations, thus cheap)
Definition: sparsmat.hxx:718
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
Real operator[](Integer i) const
returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim...
Definition: sparsmat.hxx:715
void set_init(bool)
after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefin...
Definition: sparsmat.hxx:140
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
Indexmatrix & init(const Indexmatrix &A, Integer d=1)
initialize to *this=A*d
Sparsemat & concat_right(const Sparsemat &A)
concats sparse matrix A to the right of *this, A or *this may be the 0x0 matrix initally, returns *this
Mtype mtype
used for MatrixError templates (runtime type information was not yet existing)
Definition: sparsmat.hxx:83
int get_edge(Integer i, Integer &indi, Integer &indj, Real &val) const
stores element i of the get_edge_rep() function (ordered as in row representation); returns 1 if i is...
friend Sparsemat colsip(const Sparsemat &A, const Matrix *scaling)
returns the column vector of the squared Frobenius norm of all columns j of A, i.e., the sum of A(i,j)*A(i,j) over all i for each j with possibly (if scaling~=0) each term i multiplied by (*scaling)(i)
bool is_init
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined ...
Definition: sparsmat.hxx:100
Sparsemat & insert_col(Integer i, const Sparsemat &v)
insert a column before column i, 0<=i<= column dimension, for i==column dimension the column is appen...
Matrix class for real values of type Real
Definition: matrix.hxx:74
Indexmatrix colindex
gives the rowindex of the element at position i, (sorted increasingly per column) ...
Definition: sparsmat.hxx:89
Sparsemat rows(const Indexmatrix &ind) const
returns a sparse matrix of size vec.dim() x this->rowdim(), with row i a copy of row vec(i) of *this ...
Sparsemat cols(const Indexmatrix &ind) const
returns a sparse matrix of size this->rowdim() x vec.dim(), with column i a copy of column vec(i) of ...
friend Matrix sumrows(const Sparsemat &A)
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
friend Real sum(const Sparsemat &A)
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Definition: sparsmat.hxx:816
const Matrix & get_rowval() const
returns the value vector of the row representation holding the value for each element ...
Definition: sparsmat.hxx:276
const Indexmatrix & get_rowinfo() const
returns information on nonzero rows, k by 3, listing: index, %nonzeros, first index in rowindex/rowva...
Definition: sparsmat.hxx:272
Indexmatrix colinfo
k by 3, for nonzero columns: index, # nonzeros, first index in colindex/colval
Definition: sparsmat.hxx:88
const Indexmatrix & get_colindex() const
returns the index vector of the column representation holding the row index for each element ...
Definition: sparsmat.hxx:267
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
void init_to_zero()
initialize the matrix to a 0x0 matrix without storage
Definition: sparsmat.hxx:660
#define chk_range(i, j, ubi, ubj)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1772
friend Sparsemat operator*(const Sparsemat &A, const Sparsemat &B)
returns a Sparsemat equal to A*B
friend Sparsemat operator/(const Sparsemat &A, Real d)
ATTENTION: d is NOT checked for 0.
Definition: sparsmat.hxx:770
Sparsemat row(Integer i) const
returns row i copied to a new sparse matrix
Integer nr
number of rows
Definition: sparsmat.hxx:84
#define chk_init(x)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1761
friend std::ostream & operator<<(std::ostream &o, const Sparsemat &v)
output format: nr nc nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n
Sparsemat & scale_cols(const Matrix &vec)
scales each column i of (*this) by vec(i), i.e., (*this)=(*this)*diag(vec), and returns (*this) ...
Sparsemat & scale_rows(const Matrix &vec)
scales each row i of (this) by vec(i), i.e., (*this)=diag(vec)(*this), and returns (*this) ...
Integer coldim() const
returns the column dimension
Definition: sparsmat.hxx:202
Integer rowdim() const
returns the row dimension
Definition: sparsmat.hxx:199
Header declaring the class CH_Matrix_Classes::Sparsesym for sparse symmetric matrices with Real eleme...
Matrix()
empty matrix
Definition: matrix.hxx:1082
friend Sparsemat abs(const Sparsemat &A)
returns a Sparsmat with elements abs((*this)(i,j)) for all i,j
Real operator()(Integer i, Integer j) const
returns value of element (i,j) of the matrix (rowindex i, columnindex j)
Integer nonzeros() const
returns the number of nonzeros
Definition: sparsmat.hxx:205