Regina Calculation Engine
Public Types | Public Member Functions | Static Public Member Functions | Static 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>

Inheritance diagram for regina::Matrix< T, ring >:
regina::Output< Matrix< T > > regina::MatrixRingIdentities< T, ring >

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...
 
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...
 
void divRowExact (unsigned long row, const T &divBy)
 Divides all elements of the given row by the given integer. More...
 
void divColExact (unsigned long col, const T &divBy)
 Divides all elements of the given column by the given integer. More...
 
gcdRow (unsigned long row)
 Computes the greatest common divisor of all elements of the given row. More...
 
gcdCol (unsigned long col)
 Computes the greatest common divisor of all elements of the given column. More...
 
void reduceRow (unsigned long row)
 Reduces the given row by dividing all its elements by their greatest common divisor. More...
 
void reduceCol (unsigned long col)
 Reduces the given column by dividing all its elements by their greatest common divisor. 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 Member Functions

static Matrix identity (unsigned long size)
 Returns an identity matrix of the given size. More...
 

Static Public Attributes

static const T zero
 The additive identity in the underlying ring. More...
 
static const T one
 The multiplicative identity in the underlying ring. More...
 

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
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 Typedef Documentation

◆ Coefficient

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)>
typedef T regina::Matrix< T, ring >::Coefficient

The type of each entry in the matrix.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

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 >::Matrix ( unsigned long  rows,
unsigned long  cols 
)
inline

Creates a new matrix of the given size.

All entries will be initialised using their default constructors.

In particular, this means that for Regina's own integer classes (Integer, LargeInteger and NativeInteger), all entries will be initialised to zero.

Warning
If T is a native C++ integer type (such as int or long), then the matrix elements will not be initialised to any particular value.
Precondition
The given number of rows and columns are both strictly positive.
Parameters
rowsthe number of rows in the new matrix.
colsthe number of columns in the new matrix.

◆ Matrix() [2/3]

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 >::Matrix ( const Matrix< T, ring > &  src)
inline

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

This constructor induces a deep copy of src.

Parameters
srcthe matrix to clone.

◆ Matrix() [3/3]

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 >::Matrix ( Matrix< T, ring > &&  src)
inlinenoexcept

Moves the given matrix into this new matrix.

This is a fast (constant time) operation.

The matrix that is passed (src) will no longer be usable.

Parameters
srcthe matrix to move.

◆ ~Matrix()

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 >::~Matrix ( )
inline

Destroys this matrix.

Member Function Documentation

◆ addCol() [1/2]

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)>
void regina::Matrix< T, ring >::addCol ( unsigned long  source,
unsigned long  dest 
)
inline

Adds the given source column to the given destination column.

This routine is only available when the template argument ring is true.

Precondition
The two given columns are distinct and between 0 and columns()-1 inclusive.
Parameters
sourcethe columns to add.
destthe column that will be added to.

◆ addCol() [2/2]

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)>
void regina::Matrix< T, ring >::addCol ( unsigned long  source,
unsigned long  dest,
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.

This routine is only available when the template argument ring is true.

Precondition
The two given columns are distinct and between 0 and columns()-1 inclusive.
Parameters
sourcethe columns to add.
destthe column that will be added to.
copiesthe number of copies of source to add to dest.

◆ addRow() [1/2]

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)>
void regina::Matrix< T, ring >::addRow ( unsigned long  source,
unsigned long  dest 
)
inline

Adds the given source row to the given destination row.

This routine is only available when the template argument ring is true.

Precondition
The two given rows are distinct and between 0 and rows()-1 inclusive.
Parameters
sourcethe row to add.
destthe row that will be added to.

◆ addRow() [2/2]

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)>
void regina::Matrix< T, ring >::addRow ( unsigned long  source,
unsigned long  dest,
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.

This routine is only available when the template argument ring is true.

Precondition
The two given rows are distinct and between 0 and rows()-1 inclusive.
Parameters
sourcethe row to add.
destthe row that will be added to.
copiesthe number of copies of source to add to dest.

◆ columns()

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)>
unsigned long regina::Matrix< T, ring >::columns ( ) const
inline

Returns the number of columns in this matrix.

Returns
the number of columns.

◆ det()

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)>
T regina::Matrix< T, ring >::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.

This routine is only available when the template argument ring is true.

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.

◆ divColExact()

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)>
void regina::Matrix< T, ring >::divColExact ( unsigned long  col,
const T &  divBy 
)
inline

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.

◆ divRowExact()

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)>
void regina::Matrix< T, ring >::divRowExact ( unsigned long  row,
const T &  divBy 
)
inline

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

This can only be used when the given integer divides into all row 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 row are infinity.
The argument divBy divides exactly into every element of the given row (i.e., it leaves no remainder).
The given row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row whose elements should be divided by divBy.
divBythe integer to divide each row element by.

◆ entry() [1/2]

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)>
T& regina::Matrix< T, ring >::entry ( unsigned long  row,
unsigned long  column 
)
inline


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
rowthe row of the desired entry.
columnthe column of the desired entry.
Returns
a reference to the entry in the given row and column.

◆ entry() [2/2]

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)>
const T& regina::Matrix< T, ring >::entry ( unsigned long  row,
unsigned long  column 
) const
inline


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
rowthe row of the desired entry.
columnthe column of the desired entry.
Returns
a reference to the entry in the given row and column.

◆ gcdCol()

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)>
T regina::Matrix< T, ring >::gcdCol ( unsigned long  col)
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.

◆ gcdRow()

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)>
T regina::Matrix< T, ring >::gcdRow ( unsigned long  row)
inline

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

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 row number is between 0 and rows()-1 inclusive.
Parameters
rowthe index of the row whose gcd should be computed.
Returns
the greatest common divisor of all elements of this row.

◆ identity()

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)>
static Matrix regina::Matrix< T, ring >::identity ( unsigned long  size)
inlinestatic

Returns an identity matrix of the given size.

The matrix returned will have size rows and size columns.

This routine is only available when the template argument ring is true.

Parameters
sizethe number of rows and columns of the matrix to build.
Returns
an identity matrix of the given size.

◆ initialise() [1/2]

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)>
void regina::Matrix< T, ring >::initialise ( const T &  value)
inline

Sets every entry in the matrix to the given value.

Parameters
valuethe value to assign to each entry.

◆ initialise() [2/2]

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)>
void regina::Matrix< T, ring >::initialise ( List  allValues)


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
allValuesthe individual elements to place into the matrix.

◆ isIdentity()

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)>
bool regina::Matrix< T, ring >::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).

This routine is only available when the template argument ring is true.

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

◆ isZero()

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)>
bool regina::Matrix< T, ring >::isZero ( ) const
inline

Determines whether this is the zero matrix.

This routine is only available when the template argument ring is true.

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

◆ makeIdentity()

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)>
void regina::Matrix< T, ring >::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 1 if r == c and 0 otherwise.

This routine is only available when the template argument ring is true.

◆ multCol()

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)>
void regina::Matrix< T, ring >::multCol ( unsigned long  column,
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.

This routine is only available when the template argument ring is true.

Precondition
The given column is between 0 and columns()-1 inclusive.
Parameters
columnthe column to work with.
factorthe factor by which to multiply the given column.

◆ multiplyAs()

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)>
Matrix regina::Matrix< T, ring >::multiplyAs ( const Matrix< T, ring > &  other) const
inline


Deprecated alias for the multiplication operator.

Multiplies this by the given matrix, and returns a new matrix (of this same class) as a result. This matrix is not changed.

As of Regina 5.3, the template parameter MatrixClass has been removed, since Regina's old matrix class hierarchy has been replaced with a single Matrix class. It is harmless if you still pass a template parameter, but your parameter will be ignored.

This routine is only available when the template argument ring is true.

Precondition
The number of columns in this matrix equals the number of rows in the given matrix.
Deprecated:
Simply use the multiplication operator (which is now identical to this routine). This routine multiplyAs() dated back to when Matrix had a hierarchy of subclasses that offered different capabilities according to the underlying type T. Now that there is just a single class Matrix, this routine is no longer required.
      \par Python

Not present.

Parameters
otherthe other matrix to multiply this matrix by.
Returns
the product matrix this * other.

◆ multRow()

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)>
void regina::Matrix< T, ring >::multRow ( unsigned long  row,
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.

This routine is only available when the template argument ring is true.

Precondition
The given row is between 0 and rows()-1 inclusive.
Parameters
rowthe row to work with.
factorthe factor by which to multiply the given row.

◆ operator!=()

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)>
bool regina::Matrix< T, ring >::operator!= ( const Matrix< T, ring > &  other) const
inline

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
otherthe matrix to compare with this.
Returns
true if the matrices are different as described above, or false otherwise.

◆ operator*()

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)>
Matrix regina::Matrix< T, ring >::operator* ( const Matrix< T, ring > &  other) const
inline

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

This matrix is not changed.

This routine is only available when the template argument ring is true.

Precondition
The number of columns in this matrix equals the number of rows in the given matrix.
Parameters
otherthe other matrix to multiply this matrix by.
Returns
the product matrix this * other.

◆ operator=() [1/2]

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)>
Matrix& regina::Matrix< T, ring >::operator= ( const Matrix< T, ring > &  src)
inline

Copies the given matrix into this matrix.

It does not matter if this and the given matrix have different sizes; if they do then this matrix will be resized as a result.

This operator induces a deep copy of src.

Parameters
srcthe matrix to copy.
Returns
a reference to this matrix.

◆ operator=() [2/2]

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)>
Matrix& regina::Matrix< T, ring >::operator= ( Matrix< T, ring > &&  src)
inlinenoexcept

Moves the given matrix into this matrix.

This is a fast (constant time) operation.

It does not matter if this and the given matrix have different sizes; if they do then this matrix will be resized as a result.

The matrix that is passed (src) will no longer be usable.

Parameters
srcthe matrix to move.
Returns
a reference to this matrix.

◆ operator==()

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)>
bool regina::Matrix< T, ring >::operator== ( const Matrix< T, ring > &  other) const
inline

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
otherthe matrix to compare with this.
Returns
true if the matrices are equal as described above, or false otherwise.

◆ reduceCol()

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)>
void regina::Matrix< T, ring >::reduceCol ( unsigned long  col)
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.

◆ reduceRow()

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)>
void regina::Matrix< T, ring >::reduceRow ( unsigned long  row)
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.

◆ rows()

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)>
unsigned long regina::Matrix< T, ring >::rows ( ) const
inline

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, bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
void regina::Matrix< T, ring >::swapColumns ( unsigned long  first,
unsigned long  second 
)
inline

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

Precondition
The two given columns are between 0 and columns()-1 inclusive.
Parameters
firstthe first column to swap.
secondthe second column to swap.

◆ swapRows()

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)>
void regina::Matrix< T, ring >::swapRows ( unsigned long  first,
unsigned long  second 
)
inline

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

Precondition
The two given rows are between 0 and rows()-1 inclusive.
Parameters
firstthe first row to swap.
secondthe 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, bool ring = ((std::is_integral<T>::value && ! std::is_same<T, bool>::value) || IsReginaInteger<T>::value || std::is_same<T, Rational>::value)>
void regina::Matrix< T, ring >::writeMatrix ( std::ostream &  out) const
inline


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
outthe output stream to which to write.

◆ writeTextLong()

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)>
void regina::Matrix< T, ring >::writeTextLong ( std::ostream &  out) const
inline


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

Python
Not present.
Parameters
outthe output stream to which to write.

◆ writeTextShort()

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)>
void regina::Matrix< T, ring >::writeTextShort ( std::ostream &  out) const
inline


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

Python
Not present.
Parameters
outthe output stream to which to write.

Member Data Documentation

◆ one

template<typename T , bool ring>
const T regina::MatrixRingIdentities< T, ring >::one
staticinherited

The multiplicative identity in the underlying ring.

◆ zero

template<typename T , bool ring>
const T regina::MatrixRingIdentities< T, ring >::zero
staticinherited

The additive identity in the underlying ring.


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

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