Regina Calculation Engine
Public Types | Public Member Functions | Public Attributes | List of all members
regina::Matrix< T, ring > Class Template Reference

Represents a matrix of elements of the given type T. More...

#include <maths/matrix.h>

Public Types

typedef T Coefficient
 The type of each entry in the matrix. More...
 

Public Member Functions

 Matrix (unsigned long rows, unsigned long cols)
 Creates a new matrix of the given size. More...
 
 Matrix (const Matrix &src)
 Creates a new matrix that is a clone of the given matrix. More...
 
 Matrix (Matrix &&src) noexcept
 Moves the given matrix into this new matrix. More...
 
 ~Matrix ()
 Destroys this matrix. More...
 
Matrixoperator= (const Matrix &src)
 Copies the given matrix into this matrix. More...
 
Matrixoperator= (Matrix &&src) noexcept
 Moves the given matrix into this 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 &other) const
 Determines whether this and the given matrix are identical. More...
 
bool operator!= (const Matrix &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...
 
 REGINA_ENABLE_FOR_RING_STATIC (Matrix) identity(unsigned long size)
 Returns an identity matrix of the given size. 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...
 
Matrix operator* (const Matrix &other) const
 Multiplies this by the given matrix, and returns the result. More...
 
Matrix multiplyAs (const Matrix &other) const
 Deprecated alias for the multiplication operator. More...
 
det () const
 Evaluates the determinant of the matrix. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (void) divRowExact(unsigned long row
 Divides all elements of the given row by the given integer. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (void) divColExact(unsigned long col
 Divides all elements of the given column by the given integer. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (T) gcdRow(unsigned long row)
 Computes the greatest common divisor of all elements of the given row. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (T) gcdCol(unsigned long col)
 Computes the greatest common divisor of all elements of the given column. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (void) reduceRow(unsigned long row)
 Reduces the given row by dividing all its elements by their greatest common divisor. More...
 
 REGINA_ENABLE_FOR_REGINA_INTEGER (void) reduceCol(unsigned long col)
 Reduces the given column by dividing all its elements by their greatest common divisor. More...
 

Public Attributes

const T & divBy
 

Detailed Description

template<class T, bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
class regina::Matrix< T, ring >

Represents a matrix of elements of the given type T.

As of Regina 5.3, the old subclasses of Matrix have now been merged into a single Matrix class. The additional member functions that the old subclasses MatrixRing and MatrixIntDomain used to provide are now part of Matrix, and are enabled or disabled according to the Matrix template parameters.

It is generally safe to just use the type Matrix<T>, since the ring argument has a sensible default. At present, ring defaults to true (thereby enabling member functions designed for matrices over rings) when T is one of the following types:

Other types may be added to this list in future versions of Regina.

There are several requirements for the underlying type T. For all matrix types:

If ring is true, then in addition to this:

In particular, all of Regina's integer and rational types (Integer, LargeInteger, NativeInteger<...> and Rational) satisfy all of these requirements, and will set ring to true by default.

The header maths/matrixops.h contains several other algorithms that work with the specific class Matrix<Integer>.

This class is designed to avoid deep copies wherever possible. In particular, it supports C++11 move constructors and move assignment. Functions that take or return objects by value are designed to be just as efficient as working with references or pointers, and long chains of operators such as a = b * c * d do not make unwanted deep copies.

Python:\n Not present in general, although the specific type
Matrix<Integer> is available under the name MatrixInt.
Template Parameters
Tthe type of each individual matrix element.
ringtrue if we should enable member functions that only work when T represents an element of a ring. This has a sensible default; see above in the class documentation for details.

Member Function Documentation

◆ REGINA_ENABLE_FOR_REGINA_INTEGER() [1/4]

template<class T , bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
regina::Matrix< T, ring >::REGINA_ENABLE_FOR_REGINA_INTEGER ( )
inline

Computes the greatest common divisor of all elements of the given column.

The value returned is guaranteed to be non-negative.

This routine is only available when T is one of Regina's own integer classes (Integer, LargeInteger, or NativeIntgeger).

Precondition
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column whose gcd should be computed.
Returns
the greatest common divisor of all elements of this column.

◆ REGINA_ENABLE_FOR_REGINA_INTEGER() [2/4]

template<class T , bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
regina::Matrix< T, ring >::REGINA_ENABLE_FOR_REGINA_INTEGER ( void  )

Divides all elements of the given column by the given integer.

This can only be used when the given integer divides into all column elements exactly (with no remainder). For the Integer class, this may be much faster than ordinary division.

This routine is only available when T is one of Regina's own integer classes (Integer, LargeInteger, or NativeIntgeger).

Precondition
The argument divBy is neither zero nor infinity, and none of the elements of the given column are infinity.
The argument divBy divides exactly into every element of the given column (i.e., it leaves no remainder).
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column whose elements should be divided by divBy.
divBythe integer to divide each column element by.

◆ REGINA_ENABLE_FOR_REGINA_INTEGER() [3/4]

template<class T , bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
regina::Matrix< T, ring >::REGINA_ENABLE_FOR_REGINA_INTEGER ( void  )
inline

Reduces the given column by dividing all its elements by their greatest common divisor.

It is guaranteed that, if the column is changed at all, it will be divided by a positive integer.

This routine is only available when T is one of Regina's own integer classes (Integer, LargeInteger, or NativeIntgeger).

Precondition
The given column number is between 0 and columns()-1 inclusive.
Parameters
colthe index of the column to reduce.

◆ REGINA_ENABLE_FOR_REGINA_INTEGER() [4/4]

template<class T , bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
regina::Matrix< T, ring >::REGINA_ENABLE_FOR_REGINA_INTEGER ( void  )
inline

Reduces the given row by dividing all its elements by their greatest common divisor.

It is guaranteed that, if the row is changed at all, it will be divided by a positive integer.

This routine is only available when T is one of Regina's own integer classes (Integer, LargeInteger, or NativeIntgeger).

Precondition
The given row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row to reduce.

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

Copyright © 1999-2020, 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).