Class Matrix

Class Documentation

class Matrix

This is a simple Matrix class for quadratic \( N \times N \) matrices. The Matrix is implemented with a 1d (column major) std::vector. There are also some linear algebra functions available.

Public Functions

inline Matrix(Matrix const &other, unsigned int N_sub)

Copies the upper left N_sub x N_sub matrix from other into the new object. Caller has to make sure that N_sub <= other.size()

Parameters
  • &other – The matrix from which we want to copy entries

  • N_sub – The size of the sub matrix. Caller has to make sure that N_sub <= other.size()

Returns A

newly constructed N_sub x N_sub Matrix object.

inline Matrix(unsigned int _size)

Creates a new _size x _size matrix. The matrix elements are initialized with zeros.

Parameters

_size – The number of rows / columns of the matrix.

inline ~Matrix()

Destroys the current matrix object.

inline unsigned int size() const

Returns the number of row / columns of the matrix.

inline void replace_row(unsigned int row, data_t const *const x)

Replaces the row at position row with the given vector. Caller has to make sure that row < N and that x has at-least N elements.

Note

There are no safety checks performed.

Parameters
  • row – The row which should be replaced.

  • x – The vector which the row should be replaced with

inline void replace_column(unsigned int col, data_t const *const x)

Replaces the column at position col with the given vector. Caller has to make sure that col < N and that x has at-least N elements.

Note

There are no safety checks performed.

Parameters
  • col – The column which should be replaced.

  • x – The vector which the row should be replaced with

inline void rank_one_update(unsigned int j, data_t const *const x)

Adds the given vector x to the j-th row and column of the the matrix. Caller has to make sure that j < N and that x has at-least N elements.

Note

There are no safety checks performed.

Parameters
  • j – The column / row to manipulate

  • x – The vector to be added to the row and column

Returns None

inline data_t &operator[](int i)

Access the i-th row of the matrix. Caller has to make sure that i < N.

Note

There are no safety checks performed.

Parameters

i – The row to be accessed

Returns A

reference to the i-th row

inline data_t operator[](int i) const

Access the i-th row of the matrix. Caller has to make sure that i < N.

Note

There are no safety checks performed.

Parameters

i – The row to be accessed

Returns A

reference to the i-th row

inline data_t &operator()(int i, int j)

Access the i-th row and j-th column of the matrix. Caller has to make sure that i, j < N.

Note

There are no safety checks performed.

Parameters
  • i – The row to be accessed

  • j – The column to be accessed

Returns A

reference to the (i,j) entry of the matrix

inline data_t operator()(int i, int j) const

Access the i-th row and j-th column of the matrix. Caller has to make sure that i, j < N.

Note

There are no safety checks performed.

Parameters
  • i – The row to be accessed

  • j – The column to be accessed

Returns A

reference to the (i,j) entry of the matrix