3 #ifndef CH_MATRIX_CLASSES__INDEXMAT_HXX 4 #define CH_MATRIX_CLASSES__INDEXMAT_HXX 19 #ifndef CH_MATRIX_CLASSES__MEMARRAY_HXX 22 #ifndef CH_MATRIX_CLASSES__MYMATH_HXX 213 inline void init_to_zero();
249 inline Indexmatrix(
const std::vector<Integer>& vec);
254 #if (CONICBUNDLE_DEBUG>=1) 255 void set_init(
bool i){is_init=i;}
258 bool get_init()
const {
return is_init;}
260 void set_init(
bool ){}
279 inline Indexmatrix& init(
const std::vector<Integer>& vec);
572 friend inline std::vector<int>&
assign(std::vector<int>& vec,
575 friend inline std::vector<long>&
assign(std::vector<long>& vec,
744 void display(std::ostream& out,
752 void mfile_output(std::ostream& out,
785 nr=nc=0;mem_dim=0;m=0;
800 if (incr==1)
mat_xey(nr*nc,m,d);
814 for(
Integer i=0;i<nr;i++) m[i]=vec[(
unsigned long)(i)];
850 init(inr,inc,d,incr);
915 {
return xpeya(A,-1); }
980 #if (CONICBUNDLE_DEBUG>=1) 1021 vec.resize((
unsigned long)(A.
dim()));
1022 for(
Integer i=0;i<A.
dim();i++) vec[(
unsigned long)(i)]=
int(A(i));
1029 vec.resize((
unsigned long)(A.
dim()));
1030 for(
Integer i=0;i<A.
dim();i++) vec[(
unsigned long)(i)]=
long(A(i));
1039 #ifndef CH_MATRIX_CLASSES__MATRIX_HXX Integer coldim() const
returns the column dimension
Definition: indexmat.hxx:324
#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
bool get_init() const
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefine...
Definition: indexmat.hxx:263
Indexmatrix mincols(const Indexmatrix &A)
returns a column vector holding in each row the minimum over all columns in this row ...
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
Matrix operator-(const Matrix &A, const Matrix &B)
returns Matrix equal to A-B
Definition: matrix.hxx:1283
Integer nr
number of rows
Definition: indexmat.hxx:206
Indexmatrix find() const
returns an Indexmatrix ind so that (*this)(ind(i)) 0<=i<ind.dim() runs through all nonzero elements ...
Indexmatrix maxrows(const Indexmatrix &A)
returns a row vector holding in each column the maximum over all rows in this column ...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
Matrix tril(const Matrix &A, Integer i=0)
retuns a matrix that keeps the lower triangle of A starting with diagonal d, i.e., (i,j)=A(i,j) for 0<=i<row dimension, 0<=j<min(i+d+1,column dimension), and sets (i,j)=0 otherwise
Definition: matrix.hxx:1342
void swap(double &a, double &b)
swaps two double variables
Definition: mymath.hxx:79
Indexmatrix maxcols(const Indexmatrix &A)
returns a column vector holding in each row the maximum over all columns in this row ...
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
Indexmatrix sortindex(const Indexmatrix &vec, bool nondecreasing=true)
returns an Indexmatrix ind so that vec(ind(0))<=vec(ind(1))<=...<=vec(ind(vec.dim()-1)) (vec may be r...
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Mtype
serves for specifying the source (matrix class or function) of the error
Definition: matop.hxx:1585
Header defining simple functions like max, min, abs.
Indexmatrix & sign(void)
using sign assign (*this)(i,j)=sign((*this)(i,j)) for all i,j
Real norm2(const Matrix &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: matrix.hxx:1235
Matrix concat_below(const Matrix &A, const Matrix &B)
returns a bew matrix [A; B], i.e., it concats matrices A and B columnwise; A or B may be a 0x0 matrix...
Definition: matrix.hxx:1350
Matrix triu(const Matrix &A, Integer i=0)
retuns a matrix that keeps the upper triangle of A starting with diagonal d, i.e., (i,j)=A(i,j) for 0<=i<row dimension, max(0,i+d)<=j<column dimension, and sets (i,j)=0 otherwise
Definition: matrix.hxx:1338
Matrix operator*(const Matrix &A, const Matrix &B)
returns Matrix equal to A*B
Definition: matrix.hxx:1275
Indexmatrix & tril(Integer d=0)
keeps lower triangle starting with diagonal d; set (*this)(i,j)=0 for 0<=i<row dimension, max(0,i+d)<=j<column dimension, returns *this
Indexmatrix & concat_below(const Indexmatrix &A)
concats matrix A to the bottom of *this, A or *this may be the 0x0 matrix initally, returns *this
Integer from
value of starting element
Definition: indexmat.hxx:51
Indexmatrix operator<=(const Indexmatrix &A, const Indexmatrix &B)
returns a matrix having elements (i,j)=Integer(A(i,j)<=B(i,j)) for all i,j
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
Indexmatrix & rand(Integer nr, Integer nc, Integer lowerb, Integer upperb, CH_Tools::GB_rand *random_generator=0)
resize *this to an nr x nc matrix and assign to (i,j) a random number uniformly from [lowerb...
Indexmatrix & reduce_length(Integer n)
(*this) is set to a column vector of length min{max{0,n},dim()}; usually used to truncate a vector...
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
Indexmatrix find_number(const Matrix &A, Real num=0., Real tol=1e-10)
returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all elements of A having val...
Definition: matrix.hxx:1444
void init_to_zero()
initialize the matrix to a 0x0 matrix without storage
Indexmatrix sumcols(const Indexmatrix &A)
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Indexmatrix operator==(const Indexmatrix &A, const Indexmatrix &B)
returns a matrix having elements (i,j)=Integer(A(i,j)==B(i,j)) for all i,j
Indexmatrix & operator%=(const Indexmatrix &A)
ATTENTION: this is redefined as the Hadamard product, (*this)(i,j)=(*this)(i,j)*A(i,j) for all i,j.
Range(Integer _from, Integer _to, Integer _step=1)
constructor for {i: i=from+k*step for some k in N_0 and i<=to}
Definition: indexmat.hxx:58
Indexmatrix & operator/=(Integer d)
ATTENTION: d is NOT checked for 0.
Integer nc
number of columns
Definition: indexmat.hxx:206
Indexmatrix & concat_right(const Indexmatrix &A)
concats matrix A to the right of *this, A or *this may be the 0x0 matrix initally, returns *this
Integer & operator[](Integer i)
returns reference to element (i) of the matrix if regarded as vector of stacked columns [element (iro...
Integer trace(const Indexmatrix &A)
returns the sum of the diagonal elements A(i,i) over all i
bool mat_equal(Integer len, const Val *x, const Val *y)
returns true if the elements of the arrays x and y are exactly equal.
Definition: matop.hxx:1415
Integer step
step distance between successive elements starting with from
Definition: indexmat.hxx:55
Integer & operator()(Integer i, Integer j)
returns reference to element (i,j) of the matrix (rowindex i, columnindex j)
Indexmatrix operator<(const Indexmatrix &A, const Indexmatrix &B)
returns a matrix having elements (i,j)=Integer(A(i,j)<B(i,j)) for all i,j
int sign(int a)
return the signum of an int a (1 for a>0,-1 for a<0,0 for a==0)
Definition: mymath.hxx:133
Indexmatrix diag(const Indexmatrix &A)
returns a column vector v consisting of the elements v(i)=A(i,i), 0<=i<min(row dimension,column dimension)
Matrix operator/(const Matrix &A, const Matrix &B)
ATTENTION: this is redefined to act componentwise without checking for zeros, C(i,j)=A(i,j)/B(i,j) for all i,j.
Definition: matrix.hxx:1291
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
Integer mem_dim
amount of memory currently allocated
Definition: indexmat.hxx:205
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
std::ostream & operator<<(std::ostream &o, const Indexmatrix &A)
output format (all Integer values): nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n
Indexmatrix & init(const Indexmatrix &A, Integer d=1)
initialize to *this=A*d
#define chk_add(x, y)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1763
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
Indexmatrix operator>=(const Indexmatrix &A, Integer d)
returns a matrix having elements (i,j)=Integer(A(i,j)>=d) for all i,j
Integer to
upper bound on element values
Definition: indexmat.hxx:53
void mat_xmodea(Integer len, Val *x, const Val a)
Set x[i]%=a for len elements of the array x.
Definition: matop.hxx:836
Indexmatrix()
empty matrix
Matrix class for real values of type Real
Definition: matrix.hxx:74
Indexmatrix transpose(const Indexmatrix &A)
returns an Indexmatrix that is the transpose of A
Indexmatrix & triu(Integer d=0)
keeps upper triangle starting with diagonal d; set (*this)(i,j)=0 for 0<=i<row dimension, 0<=j<min(i+d,column dimension), returns *this
Val mat_ip(Integer len, const Val *x, const Val *y, const Val *d=0)
return sum(x[i]*y[i]) summing over len elements of the arrays x and y.
Definition: matop.hxx:1096
~Range()
destructor, nothing to do
Definition: indexmat.hxx:60
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: indexmat.hxx:318
const Integer * get_store() const
returns the current address of the internal value array; use cautiously!
Definition: indexmat.hxx:429
allows to specify a range of integral values via (from, to, step) meaning {j=from+i*step:j in[from...
Definition: indexmat.hxx:47
Indexmatrix operator>(const Indexmatrix &A, Integer d)
returns a matrix having elements (i,j)=Integer(A(i,j)>d) for all i,j
std::vector< double > & assign(std::vector< double > &vec, const Matrix &A)
interpret A as a vector and copy it to a std::vector<double> which is also returned ...
Definition: matrix.hxx:1447
double max(double a, double b)
maximum value of two double variables
Definition: mymath.hxx:43
Indexmatrix sumrows(const Indexmatrix &A)
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
static const Mtype mtype
used for MatrixError templates (runtime type information was not yet existing)
Definition: indexmat.hxx:204
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
Integer rowdim() const
returns the row dimension
Definition: indexmat.hxx:321
#define chk_range(i, j, ubi, ubj)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1772
Indexmatrix minrows(const Indexmatrix &A)
returns a row vector holding in each column the minimum over all rows in this column ...
Integer * get_store()
returns the current address of the internal value array; use cautiously, do not use delete! ...
Definition: indexmat.hxx:427
double min(double a, double b)
minimum value of two double variables
Definition: mymath.hxx:49
Indexmatrix & genmult(const Indexmatrix &A, const Indexmatrix &B, Indexmatrix &C, Integer alpha=1, Integer beta=0, int atrans=0, int btrans=0)
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=...
bool is_init
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined ...
Definition: indexmat.hxx:210
Matrix concat_right(const Matrix &A, const Matrix &B)
returns a new matrix [A, B], i.e., it concats matrices A and B rowwise; A or B may be a 0x0 matrix ...
Definition: matrix.hxx:1346
double abs(double d)
absolute value of a double
Definition: mymath.hxx:25
Mtype get_mtype() const
returns the type of the matrix, MTindexmatrix
Definition: indexmat.hxx:327
Header for simple memory management tools that support frequent allocation and deallocation of arrays...
Integer * m
pointer to store, order is columnwise (a11,a21,...,anr1,a12,a22,.....)
Definition: indexmat.hxx:208
Indexmatrix & xbpeya(Indexmatrix &x, const Indexmatrix &y, Integer alpha=1, Integer beta=0, int ytrans=0)
returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to...
Integer sum(const Indexmatrix &A)
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Matrix operator+(const Matrix &A, const Matrix &B)
returns Matrix equal to A+B
Definition: matrix.hxx:1279
#define chk_init(x)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1761
Matrix rand(Integer rows, Integer cols, CH_Tools::GB_rand *random_generator=0)
return a nr x nc matrix with (i,j) assigned a random number uniformly from [0,1] for all i...
Definition: matrix.hxx:1366
Matrix operator%(const Matrix &A, const Matrix &B)
ATTENTION: this is redefined as the Hadamard product, C(i,j)=A(i,j)*B(i,j) for all i...
Definition: matrix.hxx:1287
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
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: indexmat.hxx:315
bool equal(const Matrix &A, const Matrix &B)
returns true if both matrices have the same size and the same elements
Definition: matrix.hxx:1433
Indexmatrix & xeyapzb(Indexmatrix &x, const Indexmatrix &y, const Indexmatrix &z, Integer alpha=1, Integer beta=1)
returns x= alpha*y+beta*z; x is initialized to the correct size; alpha and beta have default value 1 ...
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121
Real ip(const Matrix &A, const Matrix &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Definition: matrix.hxx:1165
void mat_xdivea(Integer len, Val *x, const Val a)
Set x[i]/=a for len elements of the array x.
Definition: matop.hxx:791
Indexmatrix operator!=(const Indexmatrix &A, const Indexmatrix &B)
returns a matrix having elements (i,j)=Integer(A(i,j)!=B(i,j)) for all i,j
Indexmatrix find_number(Integer num=0) const
returns an Indexmatrix ind so that (*this)(ind(i)) 0<=i<ind.dim() runs through all elements having va...
Indexmatrix find(const Matrix &A, Real tol=1e-10)
returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all nonzero elements with ab...
Definition: matrix.hxx:1441
std::istream & operator>>(std::istream &i, Indexmatrix &A)
input format (all Integer values): nr nc \n A(1,1) A(1,2) ... A(1,nc) \n A(2,1) ... A(nr,nc) \n