regina::MatrixRing< T > Class Template Reference
Mathematical Support

Represents a matrix of elements from a given ring T. More...

`#include <maths/matrix.h>`

Inheritance diagram for regina::MatrixRing< T >:

## Public Member Functions

| MatrixRing (unsigned long rows, unsigned long cols)
| Creates a new matrix of the given size. More...
| MatrixRing (const Matrix< T > &cloneMe)
| Creates a new matrix that is a clone of the given matrix. More...
void | makeIdentity ()
| Turns this matrix into an identity matrix. More...
bool | isIdentity () const
| Determines whether this matrix is a square identity matrix. More...
bool | isZero () const
| Determines whether this is the zero matrix. More...
void | addRow (unsigned long source, unsigned long dest)
| Adds the given source row to the given destination row. More...
void | addRow (unsigned long source, unsigned long dest, T copies)
| Adds the given number of copies of the given source row to the given destination row. More...
void | addCol (unsigned long source, unsigned long dest)
| Adds the given source column to the given destination column. More...
void | addCol (unsigned long source, unsigned long dest, T copies)
| Adds the given number of copies of the given source column to the given destination column. More...
void | multRow (unsigned long row, T factor)
| Multiplies the given row by the given factor. More...
void | multCol (unsigned long column, T factor)
| Multiplies the given column by the given factor. More...
std::unique_ptr< MatrixRing< T > > | operator* (const MatrixRing< T > &other) const
| Multiplies this by the given matrix, and returns the result. More...
template<class MatrixClass >
std::unique_ptr< MatrixClass > | multiplyAs (const MatrixRing< T > &other) const
| Multiplies this by the given matrix, and returns a new matrix of subclass MatrixClass. More...
T | det () const
| Evaluates the determinant of the matrix. More...
void | initialise (const T &value)
| Sets every entry in the matrix to the given value. More...
void | initialise (List allValues)
| A Python-only routine that fills the matrix with the given set of elements. More...
unsigned long | rows () const
| Returns the number of rows in this matrix. More...
unsigned long | columns () const
| Returns the number of columns in this matrix. More...
T & | entry (unsigned long row, unsigned long column)
| Returns the entry at the given row and column. More...
const T & | entry (unsigned long row, unsigned long column) const
| Returns the entry at the given row and column. More...
bool | operator== (const Matrix< T > &other) const
| Determines whether this and the given matrix are identical. More...
bool | operator!= (const Matrix< T > &other) const
| Determines whether this and the given matrix are different. More...
void | writeMatrix (std::ostream &out) const
| Writes a complete representation of the matrix to the given output stream. More...
void | swapRows (unsigned long first, unsigned long second)
| Swaps the elements of the two given rows in the matrix. More...
void | swapColumns (unsigned long first, unsigned long second)
| Swaps the elements of the two given columns in the matrix. More...
void | writeTextShort (std::ostream &out) const
| Writes a short text representation of this object to the given output stream. More...
void | writeTextLong (std::ostream &out) const
| Writes a detailed text representation of this object to the given output stream. More...
std::string | str () const
| Returns a short text representation of this object. More...
std::string | utf8 () const
| Returns a short text representation of this object using unicode characters. More...
std::string | detail () const
| Returns a detailed text representation of this object. More...

## Static Public Attributes

static const T | zero
| Zero in the underlying ring. More...
static const T | one
| One (the multiplicative identity) in the underlying ring. More...

## Protected Attributes

unsigned long | nRows
| The number of rows in the matrix. More...
unsigned long | nCols
| The number of columns in the matrix. More...
T ** | data
| The actual entries in the matrix. More...

## Detailed Description

### template<class T>
class regina::MatrixRing< T >

Represents a matrix of elements from a given ring T.

Note that many important functions (such as entry()) are inherited from the parent class Matrix, and are not documented again here.

Precondition
  Type T has a default constructor and overloads the assignment (`=`) operator.
  An element t of type T can be written to an output stream out using the standard expression `out << t`.
  Type T provides binary operators `+`, `-` and `*` and unary operators `+=`, `-=` and `*=`.
  Type T has a long integer constructor. That is, if `a` is of type T, then `a` can be initialised to a long integer `l` using `a(l)`. Here the value 1 refers to the multiplicative identity in the ring T.

Python:
  Not present, although the typedef MatrixInt is.

## Constructor & Destructor Documentation

## MatrixRing() [1/2]

template<class T >

regina::MatrixRing< T >::MatrixRing | ( | unsigned long | rows,
|  | unsigned long | cols
| ) |  |

inline

Creates a new matrix of the given size.

All entries will be initialised using their default constructors.

Precondition
  The given number of rows and columns are both strictly positive.

Parameters

  rows | the number of rows in the new matrix.
  cols | the number of columns in the new matrix.

## MatrixRing() [2/2]

template<class T >

regina::MatrixRing< T >::MatrixRing | ( | const Matrix< T > & | cloneMe | ) |

inline

Creates a new matrix that is a clone of the given matrix.

Parameters

  cloneMe | the matrix to clone.

## Member Function Documentation

## addCol() [1/2]

template<class T >

void regina::MatrixRing< T >::addCol | ( | unsigned long | source,
|  | unsigned long | dest
| ) |  |

inline

Adds the given source column to the given destination column.

Precondition
  The two given columns are distinct and between 0 and columns()-1 inclusive.

Parameters

  source | the columns to add.
  dest | the column that will be added to.

## addCol() [2/2]

template<class T >

void regina::MatrixRing< T >::addCol | ( | unsigned long | source,
|  | unsigned long | dest,
|  | T | copies
| ) |  |

inline

Adds the given number of copies of the given source column to the given destination column.

Note that copies is passed by value in case it is an element of the row to be changed.

Precondition
  The two given columns are distinct and between 0 and columns()-1 inclusive.

Parameters

  source | the columns to add.
  dest | the column that will be added to.
  copies | the number of copies of source to add to dest.

## addRow() [1/2]

template<class T >

void regina::MatrixRing< T >::addRow | ( | unsigned long | source,
|  | unsigned long | dest
| ) |  |

inline

Adds the given source row to the given destination row.

Precondition
  The two given rows are distinct and between 0 and rows()-1 inclusive.

Parameters

  source | the row to add.
  dest | the row that will be added to.

## addRow() [2/2]

template<class T >

void regina::MatrixRing< T >::addRow | ( | unsigned long | source,
|  | unsigned long | dest,
|  | T | copies
| ) |  |

inline

Adds the given number of copies of the given source row to the given destination row.

Note that copies is passed by value in case it is an element of the row to be changed.

Precondition
  The two given rows are distinct and between 0 and rows()-1 inclusive.

Parameters

  source | the row to add.
  dest | the row that will be added to.
  copies | the number of copies of source to add to dest.

## columns()

template<class T >

unsigned long regina::Matrix< T >::columns | ( |  | ) | const

inline inherited

Returns the number of columns in this matrix.

Returns
  the number of columns.

## det()

template<class T >

T regina::MatrixRing< T >::det | ( |  | ) | const

inline

Evaluates the determinant of the matrix.

This algorithm has quartic complexity, and uses the dynamic programming approach of Mahajan and Vinay. For further details, see Meena Mahajan and V. Vinay, "Determinant: Combinatorics, algorithms, and complexity", Chicago J. Theor. Comput. Sci., Vol. 1997, Article 5.

Precondition
  This is a square matrix.

Returns
  the determinant of this matrix.

## detail()

std::string regina::Output< Matrix< T > , false >::detail | ( |  | ) | const

inherited

Returns a detailed text representation of this object.

This text may span many lines, and should provide the user with all the information they could want. It should be human-readable, should not contain extremely long lines (which cause problems for users reading the output in a terminal), and should end with a final newline. There are no restrictions on the underlying character set.

Returns
  a detailed text representation of this object.

## entry() [1/2]

template<class T >

T& regina::Matrix< T >::entry | ( | unsigned long | row,
|  | unsigned long | column
| ) |  |

inline inherited

Returns the entry at the given row and column.

Rows and columns are numbered beginning at zero.

Precondition
  row is between 0 and rows()-1 inclusive.
  column is between 0 and columns()-1 inclusive.

Python:
  Although the entry() routine gives direct read-write access to matrix elements, the syntax `matrix.entry(row, column) = value` still cannot be used in python to set a matrix element directly. For this, you can use the syntax `matrix.set(row, column, value)`. This set() routine returns nothing, and is provided for python only (i.e., it is not part of the C++ calculation engine).

Parameters

  row | the row of the desired entry.
  column | the column of the desired entry.

Returns
  a reference to the entry in the given row and column.

## entry() [2/2]

template<class T >

const T& regina::Matrix< T >::entry | ( | unsigned long | row,
|  | unsigned long | column
| ) |  | const

inline inherited

Returns the entry at the given row and column.

Rows and columns are numbered beginning at zero.

Precondition
  row is between 0 and rows()-1 inclusive.
  column is between 0 and columns()-1 inclusive.

Python:
  Not present, although the non-const form of this routine is.

Parameters

  row | the row of the desired entry.
  column | the column of the desired entry.

Returns
  a reference to the entry in the given row and column.

## initialise() [1/2]

template<class T >

void regina::Matrix< T >::initialise | ( | const T & | value | ) |

inline inherited

Sets every entry in the matrix to the given value.

Parameters

  value | the value to assign to each entry.

## initialise() [2/2]

template<class T >

void regina::Matrix< T >::initialise | ( | List | allValues | ) |

inherited

A Python-only routine that fills the matrix with the given set of elements.

The argument allValues must be a Python list of length rows() * columns(). Its values will be inserted into the matrix row by row (i.e., the first row will be filled, then the second row, and so on).

C++:
  Not available; this routine is for Python only.

Parameters

  allValues | the individual elements to place into the matrix.

## isIdentity()

template<class T >

bool regina::MatrixRing< T >::isIdentity | ( |  | ) | const

inline

Determines whether this matrix is a square identity matrix.

If this matrix is square, isIdentity() will return `true` if and only if the matrix has ones in the main diagonal and zeroes everywhere else.

If this matrix is not square, isIdentity() will always return `false` (even if makeIdentity() was called earlier).

Returns
  `true` if and only if this is a square identity matrix.

## isZero()

template<class T >

bool regina::MatrixRing< T >::isZero | ( |  | ) | const

inline

Determines whether this is the zero matrix.

Returns
  `true` if and only if all entries in the matrix are zero.

## makeIdentity()

template<class T >

void regina::MatrixRing< T >::makeIdentity | ( |  | ) |

inline

Turns this matrix into an identity matrix.

This matrix need not be square; after this routine it will have `entry(r,c)` equal to `one` if `r == c` and `zero` otherwise.

## multCol()

template<class T >

void regina::MatrixRing< T >::multCol | ( | unsigned long | column,
|  | T | factor
| ) |  |

inline

Multiplies the given column by the given factor.

Note that factor is passed by value in case it is an element of the row to be changed.

Precondition
  The given column is between 0 and columns()-1 inclusive.

Parameters

  column | the column to work with.
  factor | the factor by which to multiply the given column.

## multiplyAs()

template<class T >
template<class MatrixClass >

std::unique_ptr<MatrixClass> regina::MatrixRing< T >::multiplyAs | ( | const MatrixRing< T > & | other | ) | const

inline

Multiplies this by the given matrix, and returns a new matrix of subclass MatrixClass.

This matrix is not changed.

Precondition
  The number of columns in this matrix equals the number of rows in the given matrix.
  The class MatrixClass is a subclass of MatrixRing<T>, and can be fully initialised by calling the two-argument constructor (passing the row and column counts) and then settng individual elements via data[r][c]. In particular, there should not be any new data members that need explicit initialisation.

Python:
  Not present, but the python multiplication operator performs the same task (see the python notes for operator *).

Parameters

  other | the matrix by which to multiply this matrix.

Returns
  a newly allocated matrix representing `this * other`.

## multRow()

template<class T >

void regina::MatrixRing< T >::multRow | ( | unsigned long | row,
|  | T | factor
| ) |  |

inline

Multiplies the given row by the given factor.

Note that factor is passed by value in case it is an element of the row to be changed.

Precondition
  The given row is between 0 and rows()-1 inclusive.

Parameters

  row | the row to work with.
  factor | the factor by which to multiply the given row.

## operator!=()

template<class T >

bool regina::Matrix< T >::operator!= | ( | const Matrix< T > & | other | ) | const

inline inherited

Determines whether this and the given matrix are different.

Two matrices are different if either (i) their dimensions differ, or (ii) the corresponding elements of each matrix differ in at least one location.

Note that this routine can happily deal with two matrices of different dimensions (in which case it will always return `true`).

This routine returns `true` if and only if the equality operator (==) returns `false`.

Precondition
  The type T provides an equality operator (==).

Parameters

  other | the matrix to compare with this.

Returns
  `true` if the matrices are different as described above, or `false` otherwise.

## operator*()

template<class T >

std::unique_ptr<MatrixRing<T> > regina::MatrixRing< T >::operator* | ( | const MatrixRing< T > & | other | ) | const

inline

Multiplies this by the given matrix, and returns the result.

This matrix is not changed.

Precondition
  The number of columns in this matrix equals the number of rows in the given matrix.

Warning
  The returned matrix will be of the exact class MatrixRing<T>, even if both this and other are of some common subclass of MatrixRing<T>. If you need a subclass to be returned, consider calling multiplyAs() instead.

Python:
  The multiplication operator for a subclass (such as MatrixIntDomain) will return a new matrix of that same subclass. That is, the python multiplication operator really calls multiplyAs(), not this routine.

Parameters

  other | the matrix by which to multiply this matrix.

Returns
  a newly allocated matrix representing `this * other`.

## operator==()

template<class T >

bool regina::Matrix< T >::operator== | ( | const Matrix< T > & | other | ) | const

inline inherited

Determines whether this and the given matrix are identical.

Two matrices are identical if and only if (i) their dimensions are the same, and (ii) the corresponding elements of each matrix are equal.

Note that this routine can happily deal with two matrices of different dimensions (in which case it will always return `false`).

This routine returns `true` if and only if the inequality operator (!=) returns `false`.

Precondition
  The type T provides an equality operator (==).

Parameters

  other | the matrix to compare with this.

Returns
  `true` if the matrices are equal as described above, or `false` otherwise.

## rows()

template<class T >

unsigned long regina::Matrix< T >::rows | ( |  | ) | const

inline inherited

Returns the number of rows in this matrix.

Returns
  the number of rows.

## str()

std::string regina::Output< Matrix< T > , false >::str | ( |  | ) | const

inherited

Returns a short text representation of this object.

This text should be human-readable, should fit on a single line, and should not end with a newline. Where possible, it should use plain ASCII characters.

Python:
  In addition to str(), this is also used as the Python "stringification" function `__str__()`.

Returns
  a short text representation of this object.

## swapColumns()

template<class T >

void regina::Matrix< T >::swapColumns | ( | unsigned long | first,
|  | unsigned long | second
| ) |  |

inline inherited

Swaps the elements of the two given columns in the matrix.

Precondition
  The two given columns are between 0 and columns()-1 inclusive.

Parameters

  first | the first column to swap.
  second | the second column to swap.

## swapRows()

template<class T >

void regina::Matrix< T >::swapRows | ( | unsigned long | first,
|  | unsigned long | second
| ) |  |

inline inherited

Swaps the elements of the two given rows in the matrix.

Precondition
  The two given rows are between 0 and rows()-1 inclusive.

Parameters

  first | the first row to swap.
  second | the second row to swap.

## utf8()

std::string regina::Output< Matrix< T > , false >::utf8 | ( |  | ) | const

inherited

Returns a short text representation of this object using unicode characters.

Like str(), this text should be human-readable, should fit on a single line, and should not end with a newline. In addition, it may use unicode characters to make the output more pleasant to read. This string will be encoded in UTF-8.

Returns
  a short text representation of this object.

## writeMatrix()

template<class T >

void regina::Matrix< T >::writeMatrix | ( | std::ostream & | out | ) | const

inline inherited

Writes a complete representation of the matrix to the given output stream.

Each row will be written on a separate line with elements in each row separated by single spaces.

Python:
  Not present, even if a subclass of Matrix is mirrored and its inherited routines are mirrored also.

Parameters

  out | the output stream to which to write.

## writeTextLong()

template<class T >

void regina::Matrix< T >::writeTextLong | ( | std::ostream & | out | ) | const

inline inherited

Writes a detailed text representation of this object to the given output stream.

Python:
  Not present.

Parameters

  out | the output stream to which to write.

## writeTextShort()

template<class T >

void regina::Matrix< T >::writeTextShort | ( | std::ostream & | out | ) | const

inline inherited

Writes a short text representation of this object to the given output stream.

Python:
  Not present.

Parameters

  out | the output stream to which to write.

## Member Data Documentation

## data

template<class T >

T** regina::Matrix< T >::data

protected inherited

The actual entries in the matrix.

`data[r][c]` is the element in row r, column c.

## nCols

template<class T >

unsigned long regina::Matrix< T >::nCols

protected inherited

The number of columns in the matrix.

## nRows

template<class T >

unsigned long regina::Matrix< T >::nRows

protected inherited

The number of rows in the matrix.

## one

template<class T >

const T regina::MatrixRing< T >::one

static

One (the multiplicative identity) in the underlying ring.

This would be `const` if it weren't for the fact that some compilers don't like this. It should never be modified!

## zero

template<class T >

const T regina::MatrixRing< T >::zero

static

Zero in the underlying ring.

This would be `const` if it weren't for the fact that some compilers don't like this. It should never be modified!

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

- maths/matrix.h

Copyright © 1999-2016, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).