CH_Matrix_Classes::Indexmatrix Class Reference
[Indexmatrix (dense, integer, m by n)]

Matrix class for integral values of type Integer More...

#include <indexmat.hxx>

Inheritance diagram for CH_Matrix_Classes::Indexmatrix:

CH_Matrix_Classes::Memarrayuser

List of all members.

Public Member Functions

Constructors, Destructor, and Initialization (Members)
 Indexmatrix ()
 empty matrix
 Indexmatrix (const Indexmatrix &A, Integer d=1)
 copy constructor, *this=d*A
 Indexmatrix (const Range &)
 generate a column vector holding the indices of this Range
 Indexmatrix (Integer nr, Integer nc)
 generate a matrix of size nr x nc but WITHOUT initializing the memory
 Indexmatrix (Integer nr, Integer nc, Integer d)
 generate a matrix of size nr x nc initializing all elements to the value d
 Indexmatrix (Integer nr, Integer nc, const Integer *dp, Integer incr=1)
 generate a matrix of size nr x nc initializing the elements from the (one dimensional) array dp with increment incr
 Indexmatrix (const std::vector< Integer > &vec)
 copy a std::vector<Integer> to a column vector of the same size and content
 ~Indexmatrix ()
void set_init (bool)
 after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefined)
bool get_init () const
 returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefined)
Indexmatrixinit (const Indexmatrix &A, Integer d=1)
 initialize to *this=A*d
Indexmatrixinit (const Range &)
 initialize *this to a column vector holding the indices of Range
Indexmatrixinit (Integer nr, Integer nc, Integer d)
 intialize *this to a matrix of size nr x nc initializing all elements to the value d
Indexmatrixinit (Integer nr, Integer nc, const Integer *dp, Integer incr=1)
 generate a matrix of size nr x nc initializing the elements from the (one dimensional) array dp with increment incr
Indexmatrixinit (const std::vector< Integer > &vec)
 use std::vector<Integer> to initialize this to a column vector of the same size and content
void newsize (Integer nr, Integer nc)
 resize the matrix to nr x nc elements but WITHOUT initializing the memory
Conversions from other Matrix Classes (Members)
 Indexmatrix (const Matrix &)
 copy with rounding
 Indexmatrix (const Symmatrix &)
 copy with rounding
 Indexmatrix (const Sparsemat &)
 copy with rounding
 Indexmatrix (const Sparsesym &)
 copy with rounding
Size and Type Information (Members)
void dim (Integer &_nr, Integer &_nc) const
 returns the number of rows in _nr and the number of columns in _nc
Integer dim () const
 returns the dimension rows * columns when the matrix is regarded as a vector
Integer rowdim () const
 returns the row dimension
Integer coldim () const
 returns the column dimension
Mtype get_mtype () const
 returns the type of the matrix, MTindexmatrix
Indexing and Submatrices (Members)
Integeroperator() (Integer i, Integer j)
 returns reference to element (i,j) of the matrix (rowindex i, columnindex j)
Integeroperator() (Integer i)
 returns reference to element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
Integer operator() (Integer i, Integer j) const
 returns value of element (i,j) of the matrix (rowindex i, columnindex j)
Integer operator() (Integer i) const
 returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
Indexmatrix operator() (const Indexmatrix &vecrow, const Indexmatrix &veccol) const
 returns a new submatrix as indexed by vecrow and veccol, A(i,j)=(*this)(vecrow(i),veccol(j)) for 0<=i<vecrow.dim(), 0<=j<veccol.dim()
Indexmatrix operator() (const Indexmatrix &A) const
 returns a new matrix B of the same shape as A with B(i,j)=(*this)(A(i),A(j)) for 0<=i<A.rowdim(), 0<=j<A.coldim()
Integeroperator[] (Integer i)
 returns reference to element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
Integer operator[] (Integer i) const
 returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
Indexmatrix col (Integer i) const
 returns column i copied to a new matrix
Indexmatrix row (Integer i) const
 returns row i copied to a new matrix
Indexmatrix 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
Indexmatrix rows (const Indexmatrix &vec) const
 returns a matrix of size vec.dim() x this->rowdim(), with row i a copy of row vec(i) of *this
Indexmatrixtriu (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
Indexmatrixtril (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
Indexmatrixsubassign (const Indexmatrix &vecrow, const Indexmatrix &veccol, const Indexmatrix &A)
 assigns A to a submatrix of *this, (*this)(vecrow(i),veccol(j))=A(i,j) for 0<=i<vecrow.dim(), 0<=j<veccol.dim()
Indexmatrixsubassign (const Indexmatrix &vec, const Indexmatrix &A)
 assigns vector A to a subvector of *this, (*this)(vec(i))=A(i) for 0<=i<vec.dim(), *this, vec, and A may be rectangular matrices, their dimesions are not changed, returns *this
Indexmatrixdelete_rows (const Indexmatrix &ind)
 all rows indexed by vector ind are deleted, no row should appear twice in ind, remaining rows are moved up keeping their order, returns *this
Indexmatrixdelete_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
Indexmatrixinsert_row (Integer i, const Indexmatrix &v)
 insert the row vector v before row i, 0<=i<= row dimension, for i==row dimension the row is appended below; appending to a 0x0 matrix is allowed, returns *this
Indexmatrixinsert_col (Integer i, const Indexmatrix &v)
 insert a column before column i, 0<=i<= column dimension, for i==column dimension the column is appended at the right; appending to a 0x0 matrix is allowed, returns *this
Indexmatrixreduce_length (Integer n)
 (*this) is set to a column vector of length min{max{0,n},dim()}; usually used to truncate a vector, returns *this
Indexmatrixconcat_right (const Indexmatrix &A)
 concats matrix A to the right of *this, A or *this may be the 0x0 matrix initally, returns *this
Indexmatrixconcat_below (const Indexmatrix &A)
 concats matrix A to the bottom of *this, A or *this may be the 0x0 matrix initally, returns *this
Indexmatrixconcat_below (Integer d)
 concat value d at the bottom of *this, *this must be a column vector or the 0x0 matrix, returns *this
Indexmatrixconcat_right (Integer d)
 concat value d at the right of *this, *this must be a row vector or the 0x0 matrix, returns *this
Integerget_store ()
 returns the current address of the internal value array; use cautiously, do not use delete!
const Integerget_store () const
 returns the current address of the internal value array; use cautiously!
BLAS-like Routines (Members)
Indexmatrixxeya (const Indexmatrix &A, Integer d=1)
 sets *this=d*A and returns *this
Indexmatrixxpeya (const Indexmatrix &A, Integer d=1)
 sets *this+=d*A and returns *this
Usual Arithmetic Operators (Members)
Indexmatrixoperator= (const Indexmatrix &A)
Indexmatrixoperator*= (const Indexmatrix &s)
Indexmatrixoperator+= (const Indexmatrix &v)
Indexmatrixoperator-= (const Indexmatrix &v)
Indexmatrixoperator%= (const Indexmatrix &A)
 ATTENTION: this is redefined as the Hadamard product, (*this)(i,j)=(*this)(i,j)*A(i,j) for all i,j.
Indexmatrix operator- () const
Indexmatrixoperator*= (Integer d)
Indexmatrixoperator/= (Integer d)
 ATTENTION: d is NOT checked for 0.
Indexmatrixoperator%= (Integer d)
 sets (*this)(i,j)%=d for all i,j in the modulo meaning of %, ATTENTION: d is NOT checked for 0
Indexmatrixoperator+= (Integer d)
 sets (*this)(i,j)+=d for all i,j
Indexmatrixoperator-= (Integer d)
 sets (*this)(i,j)-=d for all i,j
Indexmatrixtranspose ()
 transposes itself (cheap for vectors, expensive for matrices)
Elementwise Operations (Members)
Indexmatrixrand (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,upperb] for all i,j
Indexmatrixshuffle (CH_Tools::GB_rand *random_generator=0)
 shuffle the elements randomly (does not change dimensions)
Indexmatrixsign (void)
 using sign assign (*this)(i,j)=sign((*this)(i,j)) for all i,j
Indexmatrixabs (void)
 using abs assign (*this)(i,j)=abs((*this)(i,j)) for all i,j
Numerical Methods (Members)
Indexmatrixscale_rows (const Indexmatrix &vec)
 scales each row i of (*this) by vec(i), i.e., (*this)=diag(vec)*(*this), and returns (*this)
Indexmatrixscale_cols (const Indexmatrix &vec)
 scales each column i of (*this) by vec(i), i.e., (*this)=(*this)*diag(vec), and returns (*this)
Find (Members)
Indexmatrix find () const
 returns an Indexmatrix ind so that (*this)(ind(i)) 0<=i<ind.dim() runs through all nonzero elements
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 value num
Input, Output (Members)
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 values are used.

Private Member Functions

void init_to_zero ()
 initialize the matrix to a 0x0 matrix without storage

Private Attributes

Integer mem_dim
 amount of memory currently allocated
Integer nr
 number of rows
Integer nc
 number of columns
Integerm
 pointer to store, order is columnwise (a11,a21,...,anr1,a12,a22,.....)
bool is_init
 flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined

Static Private Attributes

static const Mtype mtype
 used for MatrixError templates (runtime type information was not yet existing)

Friends

class Matrix
class Symmatrix
class Sparsemat
class Sparsesym
Indexing and Submatrices (Friends)
Indexmatrix diag (const Indexmatrix &A)
 returns a column vector v consisting of the elements v(i)=(*this)(i,i), 0<=i<min(row dimension,column dimension)
Indexmatrix triu (const Indexmatrix &A, Integer d=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
Indexmatrix tril (const Indexmatrix &A, Integer d=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
Indexmatrix concat_right (const Indexmatrix &A, const Indexmatrix &B)
 returns a new matrix [A, B], i.e., it concats matrices A and B rowwise; A or B may be a 0x0 matrix
Indexmatrix concat_below (const Indexmatrix &A, const Indexmatrix &B)
 returns the matrix [A; B], i.e., it concats matrices A and B columnwise; A or B may be a 0x0 matrix
void swap (Indexmatrix &A, Indexmatrix &B)
 swap the content of the two matrices A and B (involves no copying)
BLAS-like Routines (Friends)
Indexmatrixxbpeya (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 the correct size
Indexmatrixxeyapzb (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
Indexmatrixgenmult (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==0 then C is initialized to the correct size
Usual Arithmetic Operators (Friends)
Indexmatrix operator* (const Indexmatrix &A, const Indexmatrix &B)
Indexmatrix operator+ (const Indexmatrix &A, const Indexmatrix &B)
Indexmatrix operator- (const Indexmatrix &A, const Indexmatrix &B)
Indexmatrix operator% (const Indexmatrix &A, const Indexmatrix &B)
 ATTENTION: this is redefined as the Hadamard product, (*this)(i,j)=(*this)(i,j)*A(i,j) for all i,j.
Indexmatrix operator* (const Indexmatrix &A, Integer d)
Indexmatrix operator* (Integer d, const Indexmatrix &A)
Indexmatrix operator/ (const Indexmatrix &A, Integer d)
 ATTENTION: d is NOT checked for 0.
Indexmatrix operator% (const Indexmatrix &A, Integer d)
 sets (i,j)=A(i,j)%d for all i,j in the modulo meaning of %, ATTENTION: d is NOT checked for 0
Indexmatrix operator+ (const Indexmatrix &A, Integer d)
 returns (i,j)=A(i,j)+d for all i,j
Indexmatrix operator+ (Integer d, const Indexmatrix &A)
 returns (i,j)=A(i,j)+d for all i,j
Indexmatrix operator- (const Indexmatrix &A, Integer d)
 returns (i,j)=A(i,j)-d for all i,j
Indexmatrix operator- (Integer d, const Indexmatrix &A)
 returns (i,j)=d-A(i,j) for all i,j
Indexmatrix transpose (const Indexmatrix &A)
Connections to other Classes (Friends)
std::vector< int > & assign (std::vector< int > &vec, const Indexmatrix &A)
 interpret A as a vector and copy it to a std::vector<int> which is also returned
std::vector< long > & assign (std::vector< long > &vec, const Indexmatrix &A)
 interpret A as a vector and copy it to a std::vector<long> which is also returned
Elementwise Operations (Friends)
Indexmatrix rand (Integer nr, Integer nc, Integer lb, Integer ub, CH_Tools::GB_rand *random_generator=0)
 return a nr x nc matrix with (i,j) assigned a random number uniformly from [lowerb,upperb] for all i,j
Indexmatrix sign (const Indexmatrix &A)
 return a matrix of the same size as A with (i,j)=sign(A(i,j)) for all i,j, see also CH_Matrix_Classes::sign()
Indexmatrix abs (const Indexmatrix &A)
Numerical Methods (Friends)
Integer trace (const Indexmatrix &A)
 returns the sum of the diagonal elements A(i,i) over all i
Integer ip (const Indexmatrix &A, const Indexmatrix &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Real norm2 (const Indexmatrix &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,j
Indexmatrix sumrows (const Indexmatrix &A)
 returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
Indexmatrix sumcols (const Indexmatrix &A)
 returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Integer sum (const Indexmatrix &A)
 returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Comparisons, Max, Min, Sort, Find (Friends)
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, 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, 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, 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, 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, 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, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)<d) for all i,j
Indexmatrix operator> (const Indexmatrix &A, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)>d) for all i,j
Indexmatrix operator<= (const Indexmatrix &A, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)<=d) for all i,j
Indexmatrix operator>= (const Indexmatrix &A, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)>=d) for all i,j
Indexmatrix operator== (const Indexmatrix &A, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)==d) for all i,j
Indexmatrix operator!= (const Indexmatrix &A, Integer d)
 returns a matrix having elements (i,j)=Integer(A(i,j)!=d) for all i,j
Indexmatrix operator< (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d<A(i,j)) for all i,j
Indexmatrix operator> (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d>A(i,j)) for all i,j
Indexmatrix operator<= (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d<=A(i,j)) for all i,j
Indexmatrix operator>= (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d>=A(i,j)) for all i,j
Indexmatrix operator== (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d==A(i,j)) for all i,j
Indexmatrix operator!= (Integer d, const Indexmatrix &A)
 returns a matrix having elements (i,j)=Integer(d!=A(i,j)) for all i,j
Indexmatrix minrows (const Indexmatrix &A)
 returns a row vector holding in each column the minimum over all rows in this column
Indexmatrix mincols (const Indexmatrix &A)
 returns a column vector holding in each row the minimum over all columns in this row
Integer min (const Indexmatrix &A, Integer *iindex=0, Integer *jindex=0)
 returns the minimum value over all elements of the matrix
Indexmatrix maxrows (const Indexmatrix &A)
 returns a row vector holding in each column the maximum over all rows in this column
Indexmatrix maxcols (const Indexmatrix &A)
 returns a column vector holding in each row the maximum over all columns in this row
Integer max (const Indexmatrix &A, Integer *iindex=0, Integer *jindex=0)
 returns the maximum value over all elements of the matrix
Indexmatrix sortindex (const Indexmatrix &vec)
 returns an Indexmatrix ind so that vec(ind(0))<=vec(ind(1))<=...<=vec(ind(vec.dim()-1)) (vec may be rectangular)
void sortindex (const Indexmatrix &vec, Indexmatrix &ind)
 sets ind so that vec(ind(0))<=vec(ind(1))<=...<=vec(ind(vec.dim()-1)) (vec may be rectangular)
Indexmatrix find (const Indexmatrix &A)
 returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all nonzero elements of A
Indexmatrix find_number (const Indexmatrix &A, Integer num=0)
 returns an Indexmatrix ind so that A(ind(i)) 0<=i<ind.dim() runs through all elements of A having value num
Input, Output (Friends)
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
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


Detailed Description

Matrix class for integral values of type Integer

Internally a matrix of size nr x nc is stored in a one dimensional array of Integer variables, the elements are arranged in columnwise order (a11,a21,...,anr1,a12,a22,...).

Any matrix element can be indexed by (i,j), which internally refers to m[i+j*nr], or directly by the one dimensional index (i+j*nr). The latter view directly correspond to the vec() operator often used in the linear algebra literature, i.e., the matrix is transformed to a vector by stacking the columns on top of each other.


Constructor & Destructor Documentation

CH_Matrix_Classes::Indexmatrix::Indexmatrix ( Integer  nr,
Integer  nc 
) [inline]

generate a matrix of size nr x nc but WITHOUT initializing the memory

If initializing the memory externally and CONICBUNDLE_DEBUG is defined, please use set_init() via matrix.set_init(true) in order to avoid warnings concerning improper initialization

References init_to_zero(), and newsize().


Member Function Documentation

void CH_Matrix_Classes::Indexmatrix::newsize ( Integer  nr,
Integer  nc 
)

resize the matrix to nr x nc elements but WITHOUT initializing the memory

If initializing the memory externally and CONICBUNDLE_DEBUG is defined, please use set_init() via matrix.set_init(true) in order to avoid warnings concerning improper initialization

Referenced by Indexmatrix(), and init().

void CH_Matrix_Classes::Indexmatrix::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 values are used.

Parameters:
out  output stream
precision  not needed here, used for consistency with real valued matrices
width  field width, default = precision+6
screenwidth  maximum number of characters in one output line, default = 80


The documentation for this class was generated from the following file:

Generated on Tue May 3 16:52:54 2011 for ConicBundle by  doxygen 1.5.6