3 #ifndef CH_MATRIX_CLASSES__SYMMAT_HXX 4 #define CH_MATRIX_CLASSES__SYMMAT_HXX 14 #ifndef CH_MATRIX_CLASSES__MATRIX_HXX 95 #if (CONICBUNDLE_DEBUG>=1) 595 void display(std::ostream& out,
641 Real alpha=1.,
Real beta=0.,
int trans=0);
645 Real alpha=1.,
Real beta=0.,
int trans=0);
649 Real alpha=1.,
Real beta=0.,
int trans=0);
653 Real alpha=1.,
Real beta=0.,
int btrans=0);
657 Real alpha=1.,
Real beta=0.,
int atrans=0);
661 Real alpha=1.,
Real beta=0.,
int btrans=0);
665 Real alpha=1.,
Real beta=0.,
int atrans=0);
669 Real alpha=1.,
Real beta=0.,
int trans=0);
673 Real alpha=1.,
Real beta=0.,
int trans=0);
677 Real alpha=1.,
Real beta=0.,
int trans=0);
748 #if (CONICBUNDLE_DEBUG>=1) 754 {
return xeya(A,d); }
757 {
return xeya(A,d); }
760 {
return xeya(A,d); }
799 inline Symmatrix::~Symmatrix()
808 if (
unsigned(j)>=
unsigned(i))
return m[((unsigned(i)*((unsigned(
nr)<<1)-(
unsigned(i)+1)))>>1)+unsigned(j)];
809 return m[((unsigned(j)*((unsigned(
nr)<<1)-(
unsigned(j)+1)))>>1)+unsigned(i)];
815 if (
unsigned(j)>=
unsigned(i))
return m[((unsigned(i)*((unsigned(
nr)<<1)-(
unsigned(i)+1)))>>1)+unsigned(j)];
816 return m[((unsigned(j)*((unsigned(
nr)<<1)-(
unsigned(j)+1)))>>1)+unsigned(i)];
826 const unsigned long uj=unsigned(i/nr);
827 const unsigned long ui=unsigned(i%nr);
828 if (uj>=ui)
return m[((ui*((unsigned(nr)<<1)-(ui+1)))>>1)+uj];
829 return m[((uj*((unsigned(nr)<<1)-(uj+1)))>>1)+ui];
835 const unsigned long uj=unsigned(i/nr);
836 const unsigned long ui=unsigned(i%nr);
837 if (uj>=ui)
return m[((ui*((unsigned(nr)<<1)-(ui+1)))>>1)+uj];
838 return m[((uj*((unsigned(nr)<<1)-(uj+1)))>>1)+ui];
854 #if (CONICBUNDLE_DEBUG>=1) 893 {
return xpeya(A,-1.);}
1000 {
return xeya(A,d); }
1012 {
return xpeya(A); }
1016 {
return xpeya(A,-1.); }
1021 #ifndef CH_MATRIX_CLASSES__SPARSMAT_HXX #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
Integer tred2(Integer nm, Integer n, Real *a, Real *d, Real *e, Real *z) const
a subroutine needed internally for eigenvalue computations (eigval.cxx)
static const Mtype mtype
used for MatrixError templates (runtime type information was not yet existing)
Definition: symmat.hxx:51
friend Matrix diag(const Symmatrix &A)
returns a column vector v consisting of the elements v(i)=(*this)(i,i), 0<=i<row dimension ...
friend Real trace(const Symmatrix &A)
returns the sum of the diagonal elements A(i,i) over all i
void set_init(bool)
after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefin...
Definition: symmat.hxx:102
Header declaring the classes CH_Matrix_Classes::Realrange and CH_Matrix_Classes::Matrix having Real e...
void mat_xmultea(Integer len, Val *x, const Val a)
Set x[i]*=a for len elements of the array x.
Definition: matop.hxx:734
Real * m
lower triangle stored columnwise (a11,a21,...,anr1,a22,.....)
Definition: symmat.hxx:54
friend Real norm2(const Symmatrix &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: symmat.hxx:986
friend Real min(const Symmatrix &A)
returns the minimum value over all elements of the matrix
Matrix & xpeya(const Matrix &A, Real d=1.)
sets *this+=d*A and returns *this
friend Real sum(const Symmatrix &A)
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
int Aasen_factor(Indexmatrix &piv)
computes Aasen factorization LTL^T with pivoting, where L is unit lower triangular with first colum e...
friend Matrix sumrows(const Symmatrix &A)
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
friend Symmatrix abs(const Symmatrix &A)
returns a Symmatrix with elements abs(A(i,j))
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
Symmatrix & xpetriu_yza(const Matrix &A, const Matrix &B, Real d=1.)
adds to *this(i,j), i<=j the upper triangle of the matrix product d*transpose(A)*B ...
int Chol_solve(Matrix &x) const
computes, after Chol_factor was executed succesfully, the solution to (*old_this)x=rhs; rhs is overwr...
Integer imtql2(Integer nm, Integer n, Real *d, Real *e, Real *z) const
a subroutine needed internally for eigenvalue computations (eigval.cxx)
friend std::istream & operator>>(std::istream &i, Symmatrix &A)
input format (nr and nc are Integer values, all others Real values): nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n
Real * get_store()
returns the current address of the internal value array; use cautiously, do not use delete! ...
Definition: symmat.hxx:224
int Chol_Ltsolve(Matrix &rhs) const
computes, after Chol_factor into LL^T was executed succesfully, the solution to L^Tx=rhs; rhs is over...
int Chol_factor(Real tol=1e-10)
computes the Cholesky factorization, for positive definite matrices only, (*this) is overwritten by t...
Matrix row(Integer i) const
returns row i copied to a new Matrix
friend Symmatrix operator%(const Symmatrix &A, const Symmatrix &B)
ATTENTION: this is redefined as the Hadamard product and sets (i,j)=A(i,j)*B(i,j) for all i<=j...
Definition: symmat.hxx:913
void mat_xea(Integer len, Val *x, const Val a)
Set x[i]=a for len elements of the array x.
Definition: matop.hxx:77
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Symmatrix & init(const Symmatrix &A, double d=1.)
initialize to *this=A*d
Definition: symmat.hxx:753
Symmatrix & operator%=(const Symmatrix &A)
ATTENTION: this is redefined as the Hadamard product, (*this)(i,j)=(*this)(i,j)*A(i,j) for all i<=j.
Definition: symmat.hxx:894
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
Mtype
serves for specifying the source (matrix class or function) of the error
Definition: matop.hxx:1585
Matrix col(Integer i) const
returns column i copied to a new Matrix
friend Real ip(const Symmatrix &A, const Symmatrix &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Symmatrix & operator/=(Real d)
ATTENTION: d is NOT checked for 0.
Definition: symmat.hxx:901
int Chol_Lmult(Matrix &rhs) const
computes, after Chol_factor into LL^T was executed succesfully, L*rhs, overwriting rhs by the result;...
void init_to_zero()
initialize the matrix to a 0x0 matrix without storage
Definition: symmat.hxx:745
friend Symmatrix & xeyapzb(Symmatrix &x, const Symmatrix &y, const Symmatrix &z, Real alpha, Real beta)
returns x= alpha*y+beta*z; x is initialized to the correct size
Definition: symmat.hxx:877
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...
Integer eig(Matrix &P, Matrix &d, bool sort_non_decreasingly=true) const
computes an eigenvalue decomposition P*Diag(d)*tranpose(P)=(*this) by symmetric QR; returns 0 on succ...
friend Matrix sumcols(const Symmatrix &A)
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Symmatrix operator-(Real d, const Symmatrix &A)
returns a Symmatrix that equals d-A (each element subtracted from d)
Definition: symmat.hxx:973
Integer mem_dim
amount of memory currently allocated
Definition: symmat.hxx:52
friend void swap(Symmatrix &A, Symmatrix &B)
swap the content of the two matrices A and B (involves no copying)
Definition: symmat.hxx:849
Symmatrix & xetriu_yza(const Matrix &A, const Matrix &B, Real d=1.)
sets *this(i,j), i<=j to the upper triangle of the matrix product d*transpose(A)*B ...
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and _nc
Definition: symmat.hxx:153
Matrix rows(const Indexmatrix &vec) const
returns a matrix of size vec.dim() x this->coldim(), with row i a copy of row vec(i) of *this ...
friend void symscale(const Symmatrix &A, const Matrix &B, Symmatrix &S, Real a, Real b, int btrans)
sets S=beta*S+alpha*B'*A*B for symmatrix A and matrix B
void mat_xhadey(Integer len, Val *x, const Val *y)
Set x[i]*=y[i] for len elements of the arrays x and y.
Definition: matop.hxx:470
int Chol_inverse(Symmatrix &S) const
computes, after Chol_factor was executed succesfully, the inverse to (*old_this) and stores it in S (...
Symmatrix & pivot_permute(const Indexmatrix &piv, bool inverse=false)
for i=0 to rowdim row (and column) i of this matrix is swapped with row piv(j); for inverse=true the ...
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
Integer rowdim() const
returns the row dimension
Definition: symmat.hxx:159
friend Matrix maxrows(const Symmatrix &A)
returns a row vector holding in each column the maximum over all rows in this column ...
Symmatrix & swapij(Integer i, Integer j)
swaps rows (and columns) i and j
Symmatrix & principal_submatrix(const Indexmatrix &ind, Symmatrix &S) const
returns S and in S the principal submatrix indexed by ind (multiple indices are allowed) ...
const Real * get_store() const
returns the current address of the internal value array; use cautiously!
Definition: symmat.hxx:226
static Memarray * memarray
pointer to common memory manager for all Memarrayusers, instantiated in memarray.cxx ...
Definition: memarray.hxx:121
friend Matrix minrows(const Symmatrix &A)
returns a row vector holding in each column the minimum over all rows in this column ...
int free(void *addr)
free the array pointed to by addr (addr must be an address returned by get)
int LDLfactor(Real tol=1e-10)
computes LDLfactorization (implemented only for positive definite matrices so far, no pivoting), (*this) is overwritten by the factorization; returns 1 if diagonal elements go below tol
friend Symmatrix & rankadd(const Matrix &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 initiliazed to the co...
Symmatrix()
empty matrix
Definition: symmat.hxx:778
friend Symmatrix & scaledrankadd(const Matrix &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...
Mtype get_mtype() const
returns the type of the matrix, MTsymmetric
Definition: symmat.hxx:165
Symmatrix & xeya(const Symmatrix &A, Real d=1.)
sets *this=d*A and returns *this
friend void svec(const Symmatrix &A, Matrix &v, Real a, bool add, Integer startindex_vec, Integer startindex_A, Integer blockdim)
the symmetric vec operator stacks the lower triangle of A to a n*(n+1)/2 vector with the same norm2 a...
friend Symmatrix Diag(const Matrix &A)
returns a symmetric diagonal matrix S of order A.dim() with vec(A) on the diagonal, i.e., S(i,i)=A(i) for all i and S(i,j)=0 for i!=j
friend Matrix maxcols(const Symmatrix &A)
returns a column vector holding in each row the maximum over all columns in this row ...
int LDLinverse(Symmatrix &S) const
computes, after LDLfactor was executed succesfully, the inverse to (*old_this) and stores it in S (nu...
friend Matrix & genmult(const Symmatrix &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int btrans)
returns C=beta*C+alpha*A*B, where B may be transposed; C must not be equal to B; if beta==0...
int LDLsolve(Matrix &x) const
computes, after LDLfactor was executed succesfully, the solution to (*old_this)x=rhs; rhs is overwrit...
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
friend Symmatrix & rank2add(const Matrix &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.
friend void sveci(const Matrix &v, Symmatrix &A, Real a, bool add, Integer startindex_vec, Integer startindex_A, Integer blockdim)
the inverse operator to svec, extracts from v at startindex_vec (>=0) the symmetric matrix of blockdi...
Integer nr
number of rows = number of columns
Definition: symmat.hxx:53
#define chk_add(x, y)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1763
int Chol_Ltmult(Matrix &rhs) const
computes, after Chol_factor into LL^T was executed succesfully, L^Trhs, overwriting rhs by the result...
Symmatrix & enlarge_below(Integer addn)
increases the order of the matrix by appending storage for further addn rows and columns (marked as n...
void mat_xey(Integer len, Val *x, const Val *y)
Copy an array of length len to destination x from source y.
Definition: matop.hxx:117
int Chol_scaleLi(Symmatrix &S) const
computes, after Chol_factor into LL^T was executed succesfully, L^{-1}SL^{-T} overwriting S ...
Real & operator()(Integer i, Integer j)
returns reference to element (i,j) of the matrix (rowindex i, columnindex j)
Definition: symmat.hxx:802
int Aasen_tridiagsolve(Matrix &x) const
computes, after Aasen_factor into LTL^T was executed, the solution to Tx=rhs; rhs is overwritten by t...
Matrix class for real values of type Real
Definition: matrix.hxx:74
int Chol_Lsolve(Matrix &rhs) const
computes, after Chol_factor into LL^T was executed succesfully, the solution to Lx=rhs; rhs is overwr...
friend Real max(const Symmatrix &A)
returns the maximum value over all elements of the matrix
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
friend Symmatrix operator/(const Symmatrix &A, Real d)
returns a Symmatrix that equals A/d; ATTENTION: no check against division by zero ...
Definition: symmat.hxx:957
bool get_init() const
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefine...
Definition: symmat.hxx:104
friend std::ostream & operator<<(std::ostream &o, const Symmatrix &A)
output format (nr and nc are Integer values, all others Real values): nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
void mat_xbpeya(Integer len, Val *x, const Val *y, const Val a, const Val b)
Set x[i]=a*y[i]+b*x[i] for len elements of the arrays x and y.
Definition: matop.hxx:628
friend Symmatrix & xbpeya(Symmatrix &x, const Symmatrix &y, Real alpha, Real beta)
returns x= alpha*y+beta*x; if beta==0. then x is initialized to the correct size
Definition: symmat.hxx:860
#define chk_range(i, j, ubi, ubj)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1772
Symmatrix & transpose()
transposes itself (at almost no cost)
Definition: symmat.hxx:322
friend Symmatrix skron(const Symmatrix &A, const Symmatrix &B, Real alpha, bool add, Integer startindex_S)
the symmetric Kronecker product, defined via (A skron B)svec(C)=(BCA'+ACB')/2; sets or adds (if add==...
Definition: symmat.hxx:982
Symmatrix & shift_diag(Real s)
shifts the diagonal by s, i.e., (*this)(i,i)+=s for all i
#define chk_init(x)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1761
void mat_xeyapzb(Integer len, Val *x, const Val *y, const Val *z, const Val a, const Val b)
Set x[i]=a*y[i]+b*z[i] for len elements of the arrays x, y and z.
Definition: matop.hxx:1024
void mat_xpea(Integer len, Val *x, const Val a)
Set x[i]+=a for len elements of the array x.
Definition: matop.hxx:690
int Aasen_solve(Matrix &x, const Indexmatrix &piv) const
computes, after Aasen_factor into LTL^T was executed, the solution to (*old_this)x=rhs; rhs is overwr...
int Aasen_Ltsolve(Matrix &x) const
computes, after Aasen_factor into LTL^T was executed, the solution to L^Tx=rhs; rhs is overwritten by...
void newsize(Integer n)
resize the matrix to nr x nr elements but WITHOUT initializing the memory
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121
Matrix()
empty matrix
Definition: matrix.hxx:1082
friend Symmatrix operator+(const Symmatrix &A, const Symmatrix &B)
returns a Matrix that equals A+B
Definition: symmat.hxx:917
friend Matrix operator*(const Symmatrix &A, const Symmatrix &B)
returns a Matrix that equals A*B
Definition: symmat.hxx:909
int Chol_scaleLt(Symmatrix &S) const
computes, after Chol_factor into LL^T was executed succesfully, L^TSL overwriting S ...
Symmatrix & delete_principal_submatrix(const Indexmatrix &ind, bool sorted_increasingly=false)
returns this afte deleting the principal submatrix indexed by ind (no repetitions!); ...
Header declaring the class CH_Matrix_Classes::Sparsemat for sparse matrices with Real elements...
bool is_init
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined ...
Definition: symmat.hxx:56
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: symmat.hxx:156
int Aasen_Lsolve(Matrix &x) const
computes, after Aasen_factor into LTL^T was executed, the solution to Lx=rhs; rhs is overwritten by t...
friend Matrix mincols(const Symmatrix &A)
returns a column vector holding in each row the minimum over all columns in this row ...
Symmatrix & xpeya(const Symmatrix &A, Real d=1.)
sets *this+=d*A and returns *this
Matrix cols(const Indexmatrix &vec) const
returns a matrix of size this->rowdim() x vec.dim(), with column i a copy of column vec(i) of *this ...
void mfile_output(std::ostream &out, int precision=16, int width=0) const
outputs a matrix A in the format "[ A(0,1) ... A(0,nc-1)\n ... A(nr-1,nc-1)];\n" so that it can be re...
Integer coldim() const
returns the column dimension
Definition: symmat.hxx:162