Regina Calculation Engine
Public Member Functions | Protected Attributes | List of all members
regina::NMatrix< T > Class Template Reference

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

#include <maths/nmatrix.h>

Inheritance diagram for regina::NMatrix< T >:
regina::NMatrixRing< T >

Public Member Functions

 NMatrix (unsigned long rows, unsigned long cols)
 Creates a new matrix of the given size. More...
 
 NMatrix (const NMatrix &cloneMe)
 Creates a new matrix that is a clone of the given matrix. More...
 
virtual ~NMatrix ()
 Destroys 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 NMatrix< T > &other) const
 Determines whether this and the given matrix are identical. More...
 
bool operator!= (const NMatrix< T > &other) const
 Determines whether this and the given matrix are different. More...
 
virtual 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...
 

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::NMatrix< T >

Represents a matrix of elements of the given type T.

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.
Python:
Not present, although the subclass NMatrixInt is.

Constructor & Destructor Documentation

template<class T>
regina::NMatrix< T >::NMatrix ( 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
rowsthe number of rows in the new matrix.
colsthe number of columns in the new matrix.
template<class T>
regina::NMatrix< T >::NMatrix ( const NMatrix< T > &  cloneMe)
inline

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

Parameters
cloneMethe matrix to clone.
template<class T>
virtual regina::NMatrix< T >::~NMatrix ( )
inlinevirtual

Destroys this matrix.

Member Function Documentation

template<class T>
unsigned long regina::NMatrix< T >::columns ( ) const
inline

Returns the number of columns in this matrix.

Returns
the number of columns.
template<class T>
T& regina::NMatrix< T >::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.
template<class T>
const T& regina::NMatrix< T >::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.
template<class T>
void regina::NMatrix< T >::initialise ( const T &  value)
inline

Sets every entry in the matrix to the given value.

Parameters
valuethe value to assign to each entry.
template<class T>
void regina::NMatrix< T >::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.
template<class T>
bool regina::NMatrix< T >::operator!= ( const NMatrix< T > &  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.
template<class T>
bool regina::NMatrix< T >::operator== ( const NMatrix< T > &  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.
template<class T>
unsigned long regina::NMatrix< T >::rows ( ) const
inline

Returns the number of rows in this matrix.

Returns
the number of rows.
template<class T>
void regina::NMatrix< T >::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.
template<class T>
void regina::NMatrix< T >::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.
template<class T>
virtual void regina::NMatrix< T >::writeMatrix ( std::ostream &  out) const
inlinevirtual

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 NMatrix is mirrored and its inherited routines are mirrored also.
Parameters
outthe output stream to which to write.

Member Data Documentation

template<class T>
T** regina::NMatrix< T >::data
protected

The actual entries in the matrix.

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

template<class T>
unsigned long regina::NMatrix< T >::nCols
protected

The number of columns in the matrix.

template<class T>
unsigned long regina::NMatrix< T >::nRows
protected

The number of rows in the matrix.


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

Copyright © 1999-2014, 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@debian.org).