a set of C++ library classes
for neural networks development



class matrix

Class for manipulating matrices of real numbers

Public Methods

[more] matrix (int n=0, int m=0, double val=0.0)
Constructor.
[more] matrix (const matrix&)
Copy Constructor
[more] matrix (const vect& vec)
Constructor.
[more] matrix (int n, int m, double** p)
Constructor.
[more]matrix& operator= (const matrix&)
Assignment operator
[more] ~matrix ()
Destructor
[more]int dim1 () const
Returns the number of rows of the matrix
[more]int dim2 () const
Returns the number of columns of the matrix
[more]vect& row (int i) const
Returns the i-th row of the matrix
[more]vect col (int i) const
Returns the i-th column of the matrix
[more]matrix transpose () const
Returns the transpose of the matrix
[more] operator vect () const
Matrix to vect type conversion
[more]vect& operator[] (int i) const
Returns a row i of the matrix
[more]double& operator() (int i, int j)
Returns the element (i,j) of the matrix
[more]double operator() (int, int) const
Returns the element (i,j) of the matrix
[more]int operator== (const matrix&) const
Boolean equality test
[more]int operator!= (const matrix& x) const
Boolean inequality test
[more]matrix operator+ (const matrix& M1)
Addition of matrices
Preconditions: Mdim1() == M1dim1() and Mdim2() == M1dim2()
[more]matrix operator- (const matrix& M1)
Subtraction of matrices
Preconditions: Mdim1() == M1dim1() and Mdim2() == M1dim2()
[more]matrix operator- ()
Unary minus
[more]matrix& operator-= (const matrix&)
Overloading -= operator
[more]matrix& operator+= (const matrix&)
Overloading += operator
[more]matrix operator* (const matrix& M1)
Multiplication of matrices
Preconditions: Mdim2() == M1dim1()
[more]vect operator* (const vect& vec)
Multiplication with vector
Preconditions: Mdim2() == vecdim()
[more]matrix operator* (double x)
Multiplication with a scalar
Preconditions: Mdim2() == vecdim()
[more]void print (ostream& O)
Prints the matrix row by row to ostream O
[more]void print ()
Prints the matrix row by row to cout
[more]void read (istream& I)
Reads a matrix from the stream I
Reads Mdim1 times Mdim2() numbers from input stream I and writes them row by row into the matrix
[more]void read ()
Reads a matrix from standard input
Reads Mdim1 times Mdim2() numbers from cin and writes them row by row into the matrix
[more]void initialize (double val = 0.0)
Initialize the matrix
All the elements of the matrix are initialized to value


Documentation

Class for manipulating matrices of real numbers
o matrix(int n=0, int m=0, double val=0.0)
Constructor. The matrix is initialized to a m * n matrix.
Parameters:
- n number of rows
- m number of columns
val - initialization value

o matrix(const matrix&)
Copy Constructor

o matrix(const vect& vec)
Constructor. The matrix is initialized to a vec.dim() * 1 matrix, using the values of the vector vec.
Parameters:
vec - vector

o matrix(int n, int m, double** p)
Constructor. The matrix is initialized to a n * m matrix, using the values of the matrix of double pp.
Parameters:
- n number of rows
- m number of columns
- p matrix of double

omatrix& operator=(const matrix&)
Assignment operator

o ~matrix()
Destructor

oint dim1() const
Returns the number of rows of the matrix

oint dim2() const
Returns the number of columns of the matrix

ovect& row(int i) const
Returns the i-th row of the matrix
Parameters:
i - row of the matrix
Returns:
vector corresponding to the row i of the matrix

ovect col(int i) const
Returns the i-th column of the matrix
Parameters:
i - column of the matrix
Returns:
vector corresponding to the column i of the matrix

omatrix transpose() const
Returns the transpose of the matrix
Returns:
transpose of the matrix

o operator vect() const
Matrix to vect type conversion

ovect& operator[](int i) const
Returns a row i of the matrix
Parameters:
i - row index of the matrix @retrun row of the matrix

odouble& operator()(int i, int j)
Returns the element (i,j) of the matrix
Parameters:
i - row
j - column @retrun element (i,j) of the matrix

odouble operator()(int, int) const
Returns the element (i,j) of the matrix
Parameters:
i - row
j - column @retrun element (i,j) of the matrix

oint operator==(const matrix&) const
Boolean equality test

oint operator!=(const matrix& x) const
Boolean inequality test

omatrix operator+(const matrix& M1)
Addition of matrices
Preconditions: Mdim1() == M1dim1() and Mdim2() == M1dim2()

omatrix operator-(const matrix& M1)
Subtraction of matrices
Preconditions: Mdim1() == M1dim1() and Mdim2() == M1dim2()

omatrix operator-()
Unary minus

omatrix& operator-=(const matrix&)
Overloading -= operator

omatrix& operator+=(const matrix&)
Overloading += operator

omatrix operator*(const matrix& M1)
Multiplication of matrices
Preconditions: Mdim2() == M1dim1()

ovect operator*(const vect& vec)
Multiplication with vector
Preconditions: Mdim2() == vecdim()

omatrix operator*(double x)
Multiplication with a scalar
Preconditions: Mdim2() == vecdim()

ovoid print(ostream& O)
Prints the matrix row by row to ostream O

ovoid print()
Prints the matrix row by row to cout

ovoid read(istream& I)
Reads a matrix from the stream I
Reads Mdim1 times Mdim2() numbers from input stream I and writes them row by row into the matrix

ovoid read()
Reads a matrix from standard input
Reads Mdim1 times Mdim2() numbers from cin and writes them row by row into the matrix

ovoid initialize(double val = 0.0)
Initialize the matrix
All the elements of the matrix are initialized to value
Parameters:
val - initialization value


This class has no child classes.
Friends:
ostream& operator<<(ostream& O, const matrix& M)
istream& operator>>(istream& I, matrix& M)

Alphabetic index HTML hierarchy of classes or Java


Last Updated February 2001
For comments and suggestions mail to Giorgio Valentini