Dense matrix¶
The Matrix
class for dense matices. Its purpose is to provide convenient mechanisms for performing basic matrix
operations, such as constructing the matrix, retrieving the size, setting the value at \((i, j)\). The matrix is stored in row row major and The precision of the entries are double.
An example of generating a \(m x n\) matrix of real double-precision numbers with value 3.14 is the following
Matrix x(m, n, 3.14);
The underlying data storage for Matrix
is std::vector
.
-
class
Matrix
¶ Constructors and destructors
-
Matrix
()¶ This creates a default empty matrix.
-
Matrix
(int m, int n)¶ A matrix of size \(m x n\) is created. It allocates memory, and initializes the value to 0.
-
Matrix
(int m, int n, double val)¶ A matrix of size \(m x n\) is created. It allocates memory, and initializes the value to
val
.
Member functions
-
size_t
rows
() const¶ Return the number of rows of the matrix.
-
size_t
cols
() const¶ Return the number of cols of the matrix.
-
size_t
nnz
() const¶ Return the number of nonzeros in the matrix.
-
void
resize
(size_t m_, size_t n_)¶ Resize the matrix to size \(m_ x n_\).
-
double &
operator()
(size_t i, size_t j)¶ Retrieve the \((i, j)\) th entry of the matrix.
-
const double &
operator()
(size_t i, size_t j) const¶ Retrieve the \((i, j)\) th entry of the matrix.
Member functions for file I/O
-
void
read
(std::istream &in)¶ Read data from input stream and save the data as a Matrix.
-
void
write
(std::ostream &out)¶ Write a Matrix to a out stream with matrix market format.
-