ConicBundle
sparssym.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CH_MATRIX_CLASSES__SPARSSYM_HXX
4 #define CH_MATRIX_CLASSES__SPARSSYM_HXX
5 
14 #ifndef CH_MATRIX_CLASSES__SPARSMAT_HXX
15 #include "sparsmat.hxx"
16 #endif
17 
18 namespace CH_Matrix_Classes {
19 
20 // **************************************************************************
21 // class definition
22 // **************************************************************************
23 
27 
89 class Sparsesym: protected Memarrayuser
90 {
91  friend class Indexmatrix;
92  friend class Matrix;
93  friend class Symmatrix;
94  friend class Sparsemat;
95 
96 private:
97 
100 
101  //column by column representation of lower triangle
107 
109 
110  bool is_init;
111 
113  inline void init_to_zero();
114 
116  void update_support();
117 
118 public:
119 
120  //----------------------------------------------------
121  //---- constructors, destructor, and initialization
122  //----------------------------------------------------
123 
127 
129  inline Sparsesym();
131  inline Sparsesym(const Sparsesym& A,Real d=1.);
133  inline Sparsesym(Integer nr);
135  inline Sparsesym(Integer nr,Integer nz,
136  const Integer *ini,const Integer *inj,const Real* va);
138  inline Sparsesym(Integer nr,Integer nz,
139  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va);
140 
141 #if (CONICBUNDLE_DEBUG>=1)
142  void set_init(bool i){is_init=i;}
145  int get_init() const {return is_init;}
146 #else
147  void set_init(bool /* i */){}
150  bool get_init() const {return true;}
151 #endif
152 
154  inline Sparsesym& init(const Sparsesym&,Real d=1.);
156  inline Sparsesym& init(const Matrix&,Real d=1.);
158  inline Sparsesym& init(const Indexmatrix&,Real d=1.);
160  inline Sparsesym& init(const Symmatrix&,Real d=1.);
162  inline Sparsesym& init(const Sparsemat&,Real d=1.);
164  inline Sparsesym& init(Integer nr);
166  Sparsesym& init(Integer nr,Integer nz,
167  const Integer *ini,const Integer *inj,const Real* va);
169  Sparsesym& init(Integer nr,Integer nz,
170  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va);
171 
172  //initialize to the same support as A but with constant value d; the same support will be generated even for d=0.
173  Sparsesym& init_support(const Sparsesym& A,Real d=0.);
174 
176  void set_tol(Real t){tol=t;}
177 
178 
180 
184 
186  inline Sparsesym(const Matrix&,Real d=1.);
188  inline Sparsesym(const Indexmatrix&,Real d=1.);
190  inline Sparsesym(const Symmatrix&,Real d=1.);
192  inline Sparsesym(const Sparsemat&,Real d=1.);
193 
195 
196 
197  //----------------------------------------------------
198  //---- size and type information
199  //----------------------------------------------------
200 
204 
206  void dim(Integer& r, Integer& c) const {r=nr; c=nr;}
207 
209  Integer dim() const {return nr*nr;}
210 
212  Integer rowdim() const {return nr;}
213 
215  Integer coldim() const {return nr;}
216 
218  Integer nonzeros() const {return colval.dim();}
219 
221  Mtype get_mtype() const {return mtype;}
222 
224 
225 
226  //--------------------------------
227  //---- Indexing and Submatrices
228  //--------------------------------
229 
233 
235  Real operator()(Integer i,Integer j) const;
237  Real operator()(Integer i) const; //vector of stacked columns
238 
240  Real operator[](Integer i) const; //vector of stacked columns
241 
243  const Indexmatrix& get_colinfo() const {return colinfo;}
244 
246  const Indexmatrix& get_colindex() const {return colindex;}
248  const Matrix& get_colval() const {return colval;}
250  const Indexmatrix& get_suppind() const {return suppind;}
252  const Indexmatrix& get_suppcol() const {return suppcol;}
253 
255  void get_edge_rep(Indexmatrix& I, Indexmatrix& J, Matrix& val) const;
256 
258  int contains_support(const Sparsesym& A) const;
259 
261  int check_support(Integer i,Integer j) const;
262 
263 
265 
266 
270 
271 
272 
274  friend Matrix diag(const Sparsesym& A); //=(A(1,1),A(2,2),...)^t
276  friend Sparsesym sparseDiag(const Matrix& A,Real tol);
277 
279  friend void swap(Sparsesym& A, Sparsesym& B);
280 
282 
283 
284  //------------------------------
285  //---- BLAS-like Routines
286  //------------------------------
287 
291 
293  Sparsesym& xeya(const Sparsesym& A,Real d=1.);
295  Sparsesym& xeya(const Matrix& A,Real d=1.);
297  Sparsesym& xeya(const Indexmatrix& A,Real d=1.);
298 
300  Sparsesym& support_xbpeya(const Sparsesym& y,Real alpha=1.,Real beta=0.);
301 
303 
307 
309  friend Sparsesym& xbpeya(Sparsesym& x,const Sparsesym& y,Real alpha,Real beta);
310 
312  friend Sparsesym& xeyapzb(Sparsesym& x,const Sparsesym& y,const Sparsesym& z,Real alpha,Real beta);
313 
315  friend Sparsesym& support_rankadd(const Matrix& A,Sparsesym& C,
316  Real alpha,Real beta,int trans);
317 
319  friend Matrix& genmult(const Sparsesym& A,const Matrix& B,Matrix &C,
320  Real alpha,Real beta, int btrans);
321 
323  friend Matrix& genmult(const Matrix& A,const Sparsesym& B,Matrix &C,
324  Real alpha,Real beta, int atrans);
325 
327 
328 
329  //------------------------------
330  //---- usual operators
331  //------------------------------
332 
336 
338  inline Sparsesym& operator=(const Sparsesym &A);
340  inline Sparsesym& operator+=(const Sparsesym &v);
342  inline Sparsesym& operator-=(const Sparsesym &v);
344  inline Sparsesym operator-() const;
345 
347  inline Sparsesym& operator*=(Real d);
349  inline Sparsesym& operator/=(Real d);
350 
352  inline Sparsesym& operator=(const Matrix &A);
354  inline Sparsesym& operator=(const Indexmatrix &A);
355 
357  Sparsesym& transpose(){return *this;}
358 
359 
361 
365 
367  friend inline Sparsesym operator+(const Sparsesym &A,const Sparsesym& B);
369  friend inline Sparsesym operator-(const Sparsesym &A,const Sparsesym& B);
371  friend inline Sparsesym operator*(const Sparsesym& A,Real d);
373  friend inline Sparsesym operator*(Real d,const Sparsesym &A);
375  friend inline Sparsesym operator/(const Sparsesym& A,Real d);
376 
377 
379  friend inline Matrix operator*(const Matrix& A,const Sparsesym& B);
381  friend inline Matrix operator*(const Sparsesym& A,const Matrix& B);
383  friend inline Matrix operator+(const Matrix& A,const Sparsesym& B);
385  friend inline Matrix operator+(const Sparsesym& A,const Matrix& B);
387  friend inline Matrix operator-(const Matrix& A,const Sparsesym& B);
389  friend inline Matrix operator-(const Sparsesym& A,const Matrix& B);
390 
391 
393  friend inline Sparsesym transpose(const Sparsesym& A);
394 
396 
397  //------------------------------------------
398  //---- Connections to other Matrix Classes
399  //------------------------------------------
400 
404 
406  Sparsesym& xeya(const Symmatrix& A,Real d=1.);
408  Sparsesym& xeya(const Sparsemat& A,Real d=1.);
409 
411  inline Sparsesym& operator=(const Symmatrix &A);
413  inline Symmatrix operator+(const Symmatrix &A) const;
415  inline Symmatrix operator-(const Symmatrix &A) const;
416 
418  inline Sparsesym& operator=(const Sparsemat &A);
420  Sparsemat sparsemult(const Matrix& A) const;
421 
423 
427 
429  friend inline Symmatrix operator+(const Sparsesym &A,const Symmatrix &B);
431  friend inline Symmatrix operator+(const Symmatrix &A,const Sparsesym &B);
433  friend inline Symmatrix operator-(const Sparsesym& A,const Symmatrix &B);
435  friend inline Symmatrix operator-(const Symmatrix &A,const Sparsesym &B);
437  friend Real ip(const Symmatrix& A, const Sparsesym& B); //=trace(B^t*A)
439  friend inline Real ip(const Sparsesym& A, const Symmatrix& B);
440 
442  friend Matrix& genmult(const Sparsesym& A,const Sparsemat& B,Matrix &C,
443  Real alpha,Real beta,int btrans);
445  friend Matrix& genmult(const Sparsemat& A,const Sparsesym& B,Matrix &C,
446  Real alpha,Real beta,int atrans);
448  friend inline Matrix operator*(const Sparsesym& A,const Sparsemat& B);
450  friend inline Matrix operator*(const Sparsemat& A,const Sparsesym& B);
451 
453 
454  //------------------------------
455  //---- Elementwise Operations
456  //------------------------------
457 
461 
463  friend Sparsesym abs(const Sparsesym& A);
464 
466 
467  //----------------------------
468  //---- Numerical Methods
469  //----------------------------
470 
474 
476  friend Real trace(const Sparsesym& A); //=sum(diag(A))
478  friend Real ip(const Sparsesym& A, const Sparsesym& B); //=trace(B^t*A)
480  friend Real ip(const Matrix& A, const Sparsesym& B); //=trace(B^t*A)
482  friend inline Real ip(const Sparsesym& A, const Matrix& B);
484  friend Real norm2(const Sparsesym& A); //=sqrt(ip(A,A))
485 
487  friend Matrix sumrows(const Sparsesym& A); //=(1 1 1 ... 1)*A
489  friend inline Matrix sumcols(const Sparsesym& A); //=A*(1 1 1 ... 1)^t
491  friend Real sum(const Sparsesym& A); //=(1 1 ... 1)*A*(1 1 ... 1)^t
492 
494 
495 
496  //---------------------------------------------
497  //---- Comparisons / Max / Min / sort / find
498  //---------------------------------------------
499 
503 
505  friend int equal(const Sparsesym& A, const Sparsesym& B,Real eqtol);
506 
508 
509 
510  //--------------------------------
511  //---- Input / Output
512  //--------------------------------
513 
517 
520  void display(std::ostream& out,
521  int precision=0,
522  int width=0,
523  int screenwidth=0
524  ) const;
525 
527 
531 
533  friend std::ostream& operator<<(std::ostream& o,const Sparsesym &v);
535  friend std::istream& operator>>(std::istream& i,Sparsesym &v);
536 
538 
539 };
540 
542 
543 // **************************************************************************
544 // make non inline friends available outside
545 // **************************************************************************
546 
547 
549  Matrix diag(const Sparsesym& A); //=(A(1,1),A(2,2),...)^t
550 
553 
555  void swap(Sparsesym& A, Sparsesym& B);
556 
557 
559  Sparsesym& xeyapzb(Sparsesym& x,const Sparsesym& y,
560  const Sparsesym& z,Real alpha=1.,Real beta=1.);
561 
564  Real alpha=1.,Real beta=0.,int trans=0);
565 
566 
568  Real ip(const Symmatrix& A, const Sparsesym& B); //=trace(B^t*A)
569 
571  Sparsesym abs(const Sparsesym& A);
572 
574  Real trace(const Sparsesym& A); //=sum(diag(A))
575 
577  Real ip(const Sparsesym& A, const Sparsesym& B); //=trace(B^t*A)
578 
580  Real ip(const Matrix& A, const Sparsesym& B); //=trace(B^t*A)
581 
583  Real norm2(const Sparsesym& A); //=sqrt(ip(A,A))
584 
586  Matrix sumrows(const Sparsesym& A); //=(1 1 1 ... 1)*A
587 
589  Real sum(const Sparsesym& A); //=(1 1 ... 1)*A*(1 1 ... 1)^t
590 
592  std::ostream& operator<<(std::ostream& o,const Sparsesym &v);
593 
595  std::istream& operator>>(std::istream& i,Sparsesym &v);
596 
597 // **************************************************************************
598 // implementation of inline functions
599 // **************************************************************************
600 
602 {
603  mtype=MTsparse;
604  nr=0;
606 #if (CONICBUNDLE_DEBUG>=1)
607  is_init=1;
608 #endif
609 }
610 
612 { return xeya(A,d); }
613 
615 { return xeya(A,d);}
616 
618 { return xeya(A,d);}
619 
621 {
622 nr=r;
623 colinfo.init(0,0,Integer(0)); colindex.init(0,0,Integer(0)); colval.init(0,0,0.);
624 chk_set_init(*this,1);
625 return *this;
626 }
627 
629 { init_to_zero(); chk_set_init(*this,1);}
631 { init_to_zero(); init(r);}
633 { init_to_zero(); xeya(A,d);}
634 inline Sparsesym::Sparsesym(const Matrix& A,Real d)
635 { init_to_zero(); xeya(A,d);}
637 { init_to_zero(); xeya(A,d);}
638 
640  const Integer *ini,const Integer *inj,const Real* va)
641 { init_to_zero(); init(in_nr,nz,ini,inj,va);}
642 
644  const Indexmatrix& ini,const Indexmatrix& inj, const Matrix& va)
645 { init_to_zero(); init(in_nr,nz,ini,inj,va);}
646 
648 { return (*this)(i%nr,i/nr); }
650 { return (*this)(i%nr,i/nr); }
651 
652 
654 inline Sparsesym& xbpeya(Sparsesym& x,const Sparsesym& y,Real alpha=1.,Real beta=0.)
655 {
656  if (beta==0.) return x.init(y,alpha);
657  Sparsesym B; xeyapzb(B,x,y,beta,alpha); swap(x,B); return x;
658 }
659 
660 inline Sparsesym& Sparsesym::operator=(const Sparsesym &A)
661 { return xeya(A);}
662 inline Sparsesym& Sparsesym::operator+=(const Sparsesym &A)
663 { Sparsesym B; xeyapzb(B,*this,A); swap(*this,B); return *this;}
664 inline Sparsesym& Sparsesym::operator-=(const Sparsesym &A)
665 { Sparsesym B; xeyapzb(B,*this,A,1.,-1.); swap(*this,B); return *this;}
666 inline Sparsesym& Sparsesym::operator*=(Real d)
667 {chk_init(*this); colval*=d; return *this;}
669 {chk_init(*this);colval/=d;return *this;}
670 inline Sparsesym Sparsesym::operator-() const
671 { return Sparsesym(*this,-1.); }
672 
673 
674 inline Sparsesym& Sparsesym::operator=(const Matrix &A)
675 { return xeya(A);}
676 inline Sparsesym& Sparsesym::operator=(const Indexmatrix &A)
677 { return xeya(A);}
678 
679 
681 inline Sparsesym operator+(const Sparsesym& A,const Sparsesym& B)
682 {Sparsesym C; return xeyapzb(C,A,B);}
683 
685 inline Sparsesym operator-(const Sparsesym& A,const Sparsesym& B)
686 {Sparsesym C; return xeyapzb(C,A,B,1.,-1.);}
687 
689 inline Sparsesym operator*(const Sparsesym &A,Real d)
690  { return Sparsesym(A,d);}
691 
693 inline Sparsesym operator*(Real d,const Sparsesym &A)
694  { return Sparsesym(A,d);}
695 
697 inline Sparsesym operator/(const Sparsesym &A,Real d)
698  { return Sparsesym(A,1/d);}
699 
701 inline Matrix operator*(const Sparsesym& A,const Matrix& B)
702 { Matrix C; return genmult(A,B,C,1.,0.,0); }
703 
705 inline Matrix operator*(const Matrix& A,const Sparsesym& B)
706 { Matrix C; return genmult(A,B,C,1.,0.,0); }
707 
709 inline Matrix operator+(const Matrix& A,const Sparsesym& B)
710 { Matrix C(A); return C.xpeya(B);}
711 
713 inline Matrix operator+(const Sparsesym& A,const Matrix& B)
714 { Matrix C(B); return C.xpeya(A);}
715 
717 inline Matrix operator-(const Matrix& A,const Sparsesym& B)
718 { Matrix C(A); return C.xpeya(B,-1.);}
719 
721 inline Matrix operator-(const Sparsesym& A,const Matrix& B)
722 { Matrix C(B,-1.); return C.xpeya(A);}
723 
725 inline Real ip(const Sparsesym& A, const Matrix& B)
726 {return ip(B,A);}
727 
729 inline Sparsesym transpose(const Sparsesym& A)
730 {return Sparsesym(A);}
731 
733 inline Matrix sumcols(const Sparsesym& A) //=A*(1 1 1 ... 1)^t
734 {Matrix s(sumrows(A)); return s.transpose();}
735 
736 
737 inline Matrix::Matrix(const Sparsesym& A,Real d)
738 
739 {init_to_zero(); xeya(A,d); }
740 
741 inline Matrix& Matrix::init(const Sparsesym& A,Real d)
742 
743 {return xeya(A,d); }
744 
745 inline Matrix& Matrix::operator=(const Sparsesym& A)
746 
747 {return xeya(A); }
748 
749 inline Matrix& Matrix::operator*=(const Sparsesym& A)
750 
751 { Matrix C; return *this=genmult(*this,A,C,1.,0.,0);}
752 
753 inline Matrix& Matrix::operator+=(const Sparsesym& A)
754 
755 {return xpeya(A); }
756 
757 inline Matrix& Matrix::operator-=(const Sparsesym& A)
758 
759 {return xpeya(A,-1.); }
760 
761 
763 { init_to_zero(); xeya(A,d);}
765 { return xeya(A,d);}
766 inline Sparsesym& Sparsesym::operator=(const Symmatrix& A)
767 { return xeya(A);}
768 inline Symmatrix Sparsesym::operator+(const Symmatrix &A) const
769 {Symmatrix B(A); B+=*this; return B;}
770 inline Symmatrix Sparsesym::operator-(const Symmatrix &A) const
771 {Symmatrix B(A); B-=*this; return B;}
772 
774 inline Symmatrix operator+(const Sparsesym &A,const Symmatrix &B)
775 {Symmatrix C(B);return C.xpeya(A);}
776 
778 inline Symmatrix operator+(const Symmatrix &A,const Sparsesym &B)
779 {Symmatrix C(A);return C.xpeya(B);}
780 
782 inline Symmatrix operator-(const Sparsesym& A,const Symmatrix &B)
783 {Symmatrix C(B,-1.);return C.xpeya(A);}
784 
786 inline Symmatrix operator-(const Symmatrix &A,const Sparsesym &B)
787 {Symmatrix C(A);return C.xpeya(B,-1);}
788 
790 inline Real ip(const Sparsesym& A, const Symmatrix& B)
791 { return ip(B,A);}
793  { init_to_zero(); xeya(A,d);}
795  { return xeya(A,d);}
796 inline Sparsesym& Sparsesym::operator=(const Sparsemat& A)
797  { return xeya(A);}
798 
800 inline Matrix operator*(const Sparsesym& A,const Sparsemat& B)
801  { Matrix C; return genmult(A,B,C);}
802 
804 inline Matrix operator*(const Sparsemat& A,const Sparsesym& B)
805  { Matrix C; return genmult(A,B,C);}
806 
808 { init_to_zero(); xeya(A,d);}
810 { return xeya(A,d);}
811 inline Sparsemat& Sparsemat::operator=(const Sparsesym &A)
812 { return xeya(A);}
813 
815 inline Matrix operator*(const Symmatrix& A,const Sparsemat& B)
816 { Matrix C; return genmult(A,B,C,1.,0.,0);}
817 
819 inline Matrix operator*(const Sparsemat& A,const Symmatrix& B)
820 { Matrix C; return genmult(A,B,C,1.,0.,0);}
821 
823  { init_to_zero(); xeya(A,d);}
825  { return xeya(A,d);}
826 inline Symmatrix& Symmatrix::operator=(const Sparsesym& A)
827  { return xeya(A); }
828 inline Symmatrix& Symmatrix::operator+=(const Sparsesym& A)
829  { return xpeya(A);}
830 inline Symmatrix& Symmatrix::operator-=(const Sparsesym& A)
831  { return xpeya(A,-1.);}
832 
836 
838 int equal(const Sparsesym& A, const Sparsesym& B,Real eqtol=1e-10);
839 
840 
842 
843 }
844 
845 
846 #endif
847 
bool is_init
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined ...
Definition: sparssym.hxx:110
#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
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
friend Sparsesym operator*(const Sparsesym &A, Real d)
returns a Sparsesym that equals A*d
Definition: sparssym.hxx:689
const Indexmatrix & get_colindex() const
returns the index vector of the column representation holding the row index for each element ...
Definition: sparssym.hxx:246
Matrix & xpeya(const Matrix &A, Real d=1.)
sets *this+=d*A and returns *this
Indexmatrix colinfo
k by 4 matrix, for nonzero columns: index (<0 for diagonal), # nonzeros, first index in colindex/colv...
Definition: sparssym.hxx:102
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
friend Sparsesym & xeyapzb(Sparsesym &x, const Sparsesym &y, const Sparsesym &z, Real alpha, Real beta)
returns x= alpha*y+beta*z; x is initialized to the correct size
Sparsemat sparsemult(const Matrix &A) const
compute (*this)*A and return the result in a Sparsemat
#define SPARSE_ZERO_TOL
if the absolute value of an element is below this value, it is considered zero
Definition: sparsmat.hxx:24
friend Matrix sumrows(const Sparsesym &A)
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
Indexmatrix suppind
index of an element with respect to the principal submatrix spanned by the entire support ...
Definition: sparssym.hxx:105
friend Sparsesym & support_rankadd(const Matrix &A, Sparsesym &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha*AA^T (or A^TA), but only on the current support of C
const Indexmatrix & get_colinfo() const
returns information on nozero diagonal/columns, k by 4, listing: index (<0 for diagonal), # nonzeros, first index in colindex/colval, index in suppport submatrix
Definition: sparssym.hxx:243
Symmatrix & init(const Symmatrix &A, double d=1.)
initialize to *this=A*d
Definition: symmat.hxx:753
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
friend Sparsesym operator+(const Sparsesym &A, const Sparsesym &B)
returns a Sparsesym that equals A+B
Definition: sparssym.hxx:681
int contains_support(const Sparsesym &A) const
returns 1 if A is of the same dimension and the support of A is contained in the support of *this...
void init_to_zero()
initialize the matrix to a 0x0 matrix without storage
Definition: sparssym.hxx:601
friend void swap(Sparsesym &A, Sparsesym &B)
swap the content of the two sparse matrices A and B (involves no copying)
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
friend Real sum(const Sparsesym &A)
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Sparsesym & support_xbpeya(const Sparsesym &y, Real alpha=1., Real beta=0.)
returns this= alpha*y+beta(*this) restricted to the curent support of *this; if beta==0, then *this is initialized to 0 on its support first
Integer rowdim() const
returns the row dimension
Definition: sparssym.hxx:212
Sparsesym & init(const Sparsesym &, Real d=1.)
initialize to *this=A*d
Definition: sparssym.hxx:611
Sparsemat()
empty matrix
Definition: sparsmat.hxx:692
void set_init(bool)
after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefin...
Definition: sparssym.hxx:148
friend Matrix diag(const Sparsesym &A)
returns the diagonal of A as a dense Matrix vector
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
Indexmatrix colindex
gives the rowindex of the element at position i, (sorted increasingly per column) ...
Definition: sparssym.hxx:103
friend std::ostream & operator<<(std::ostream &o, const Sparsesym &v)
output format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n ...
void dim(Integer &r, Integer &c) const
returns the number of rows in _nr and the number of columns in _nc
Definition: sparssym.hxx:206
friend int equal(const Sparsesym &A, const Sparsesym &B, Real eqtol)
returns 1 if both matrices are identical, 0 otherwise
int check_support(Integer i, Integer j) const
returns 0 if (i,j) is not in the support, 1 otherwise
friend Sparsesym sparseDiag(const Matrix &A, Real tol)
forms a sparse symmetrix matrix having vector A on its diagonal
Symmatrix()
empty matrix
Definition: symmat.hxx:778
Sparsesym & operator/=(Real d)
ATTENTION: d is NOT checked for 0.
Definition: sparssym.hxx:668
error arises in a message of CH_Matrix_Classes::Sparsemat
Definition: matop.hxx:1590
Sparsemat & init(const Sparsemat &A, Real d=1.)
initialize to *this=A*d
Definition: sparsmat.hxx:674
friend Real trace(const Sparsesym &A)
returns the sum of the diagonal elements A(i,i) over all i
Mtype get_mtype() const
returns the type of the matrix, MTmatrix
Definition: sparssym.hxx:221
Integer nr
number rows = number columns
Definition: sparssym.hxx:99
Matrix colval
gives the value of the element at position i
Definition: sparssym.hxx:104
Real tol
>0, if abs(value)<tol, then value is taken to be zero
Definition: sparssym.hxx:108
Sparsesym & xeya(const Sparsesym &A, Real d=1.)
sets *this=d*A and returns *this
Mtype mtype
used for MatrixError templates (runtime type information was not yet existing)
Definition: sparssym.hxx:98
const Indexmatrix & get_suppind() const
returns the index vector of the column representation holding the row index w.r.t. the principal support submatrix for each element
Definition: sparssym.hxx:250
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: sparssym.hxx:209
Indexmatrix & init(const Indexmatrix &A, Integer d=1)
initialize to *this=A*d
friend std::istream & operator>>(std::istream &i, Sparsesym &v)
input format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n ...
Integer coldim() const
returns the column dimension
Definition: sparssym.hxx:215
Integer nonzeros() const
returns the number of nonzeros in the lower triangle (including diagonal)
Definition: sparssym.hxx:218
void get_edge_rep(Indexmatrix &I, Indexmatrix &J, Matrix &val) const
stores the nz nonzero values of the lower triangle of *this in I,J,val so that this(I(i),J(i))=val(i) for i=0,...,nz-1 and dim(I)=dim(J)=dim(val)=nz (ordered as in row representation)
Matrix class for real values of type Real
Definition: matrix.hxx:74
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...
const Matrix & get_colval() const
returns the value vector of the column representation holding the value for each element ...
Definition: sparssym.hxx:248
Matrix & transpose()
transposes itself (cheap for vectors, expensive for matrices)
friend Matrix & genmult(const Sparsesym &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int btrans)
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to B; if beta==0...
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
const Indexmatrix & get_suppcol() const
returns the vector listing in ascending order the original column indices of the principal support su...
Definition: sparssym.hxx:252
Symmatrix operator-(const Symmatrix &A, const Sparsesym &B)
returns a Symmatrix that equals A-B
Definition: sparssym.hxx:786
friend Sparsesym & xbpeya(Sparsesym &x, const Sparsesym &y, Real alpha, Real beta)
returns x= alpha*y+beta*x; if beta==0. then x is initialized to the correct size
Definition: sparssym.hxx:654
friend Sparsesym operator/(const Sparsesym &A, Real d)
ATTENTION: d is NOT checked for 0.
Definition: sparssym.hxx:697
bool get_init() const
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefine...
Definition: sparssym.hxx:150
friend Real norm2(const Sparsesym &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...
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
friend Sparsesym abs(const Sparsesym &A)
returns a Sparsesym with elements abs((*this)(i,j)) for all i,j
Real operator[](Integer i) const
returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim...
Definition: sparssym.hxx:649
Sparsesym & transpose()
transposes itself (at almost no cost)
Definition: sparssym.hxx:357
#define chk_init(x)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1761
Sparsesym()
empty matrix
Definition: sparssym.hxx:628
void set_tol(Real t)
set tolerance for recognizing zero values to t
Definition: sparssym.hxx:176
Matrix()
empty matrix
Definition: matrix.hxx:1082
friend Matrix sumcols(const Sparsesym &A)
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Definition: sparssym.hxx:733
friend Real ip(const Symmatrix &A, const Sparsesym &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Real operator()(Integer i, Integer j) const
returns value of element (i,j) of the matrix (rowindex i, columnindex j)
Header declaring the class CH_Matrix_Classes::Sparsemat for sparse matrices with Real elements...
Indexmatrix suppcol
the index of the support column in the original matrix
Definition: sparssym.hxx:106
Symmatrix & xpeya(const Symmatrix &A, Real d=1.)
sets *this+=d*A and returns *this
void update_support()
removes zeros and updates suppind and suppcol