Class for matrices. More...
#include <Matrix.h>
Public Member Functions | |
Matrix (T x=T(0)) | |
Constructor. More... | |
Matrix (Complex< T > z) | |
Constructor. More... | |
Matrix (size_t size, T x) | |
Constructor. More... | |
Matrix (size_t size, Complex< T > z) | |
Constructor. More... | |
Matrix (size_t nrows, size_t ncols, T x) | |
Constructor. More... | |
Matrix (size_t nrows, size_t ncols, Complex< T > z) | |
Constructor. More... | |
Matrix (std::initializer_list< T > list) | |
Constructor. More... | |
Matrix (std::initializer_list< Complex< T >> list) | |
Constructor. More... | |
Matrix (std::initializer_list< std::initializer_list< T >> list) | |
Constructor. More... | |
Matrix (std::initializer_list< std::initializer_list< Complex< T >>> list) | |
Constructor. More... | |
Matrix (const Matrix< T, M, N, Flags > ©) | |
Constructor. More... | |
template<typename U , size_t P, size_t Q, unsigned int Flags2> | |
Matrix (const Matrix< U, P, Q, Flags2 > &other) | |
Constructor. More... | |
void | Resize (size_t newSize) |
Resizes a dynamic matrix. More... | |
void | Resize (size_t newM, size_t newN) |
Resizes a dynamic matrix. More... | |
size_t | NumRows () const |
size_t | NumColumns () const |
size_t | NumEntries () const |
Matrix< T, 1, 2 > | Size () const |
size_t | Length () const |
For vectors, this returns the length of the vector. More... | |
Complex< T > * | Data () |
Matrix< T, 1, N > | GetRow (size_t r) const |
Takes row r of the matrix and returns it. More... | |
Matrix< T, M, 1 > | GetColumn (size_t c) const |
Takes column c of the matrix and returns it. More... | |
template<size_t P, size_t Q> | |
std::enable_if<(P==1||P==Dynamic)&&(Q==N||Q==Dynamic||N==Dynamic), void >::type | SetRow (size_t r, const Matrix< T, P, Q > &row) |
Sets row r of the matrix to row. More... | |
template<size_t P, size_t Q> | |
std::enable_if<(P==M||P==Dynamic||M==Dynamic)&&(Q==1||Q==Dynamic), void >::type | SetColumn (size_t c, const Matrix< T, P, Q > &column) |
Sets column c of the matrix to row. More... | |
void | SwapRows (size_t r1, size_t r2) |
Swaps rows r1 and r2. More... | |
void | ScaleRow (size_t r, Complex< T > s) |
Scales row r by s, i.e., \(a_{ri}=sa_{ri}\) for \(0\le i<N\). More... | |
void | AddRows (size_t r1, size_t r2, Complex< T > s) |
Scales row r2 by s then adds it to r1, i.e., \(a_{r1,i}=a_{r1,i}+sa_{r2,i}\) for \(0\le i<N\). More... | |
Complex< T > | operator[] (size_t i) const |
Operators. More... | |
Complex< T > & | operator[] (size_t i) |
Complex< T > | operator() (size_t r, size_t c) const |
Returns the the data located in row r and column c. More... | |
Complex< T > & | operator() (size_t r, size_t c) |
template<typename U , typename std::enable_if< std::is_convertible< T, U >::value >::type * = nullptr> | |
operator Matrix< U, M, N, Flags > () | |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > & | operator= (const Matrix< T, P, Q, Flags2 > &other) |
Set the matrix to other. More... | |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > & | operator+= (const Matrix< T, P, Q, Flags2 > &other) |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > & | operator-= (const Matrix< T, P, Q, Flags2 > &other) |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > & | operator*= (const Matrix< T, P, Q, Flags2 > &other) |
Matrix< T, M, N, Flags > & | operator*= (Complex< T > other) |
Matrix< T, M, N, Flags > & | operator/= (Complex< T > other) |
Matrix< T, M, N, Flags > | operator- () |
Friends | |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > | operator+ (Matrix< T, M, N, Flags > A, const Matrix< T, P, Q, Flags2 > &B) |
Computes the MxN matrix \(C=A+B\) defined by \(c_{ij}=a_{ij}+b_{ij}\). More... | |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, N, Flags > | operator- (Matrix< T, M, N, Flags > A, const Matrix< T, P, Q, Flags2 > &B) |
Computes the MxN matrix \(C=A-B\) defined by \(c_{ij}=a_{ij}-b_{ij}\). More... | |
Matrix< T, M, N, Flags > | operator* (Matrix< T, M, N, Flags > A, const Complex< T > &s) |
Computes the MxN matrix \(B=sA\) defined by \(b_{ij}=sa_{ij}\). More... | |
Matrix< T, M, N, Flags > | operator* (const Complex< T > &s, Matrix< T, M, N, Flags > A) |
Computes the MxN matrix \(B=sA\) defined by \(b_{ij}=sa_{ij}\). More... | |
Matrix< T, M, N, Flags > | operator/ (Matrix< T, M, N, Flags > A, const Complex< T > &s) |
Computes the MxN matrix \(B=A/s\) defined by \(b_{ij}=a_{ij}/s\). More... | |
template<size_t P, size_t Q, unsigned int Flags2> | |
Matrix< T, M, Q, Flags > | operator* (const Matrix< T, M, N, Flags > &A, const Matrix< T, P, Q, Flags2 > &B) |
Computes the MxQ matrix \(C=AB\) defined by \(c_{ij}=\sum_{k=0}^{N-1}a_{ik}b_{kj}\). More... | |
std::ostream & | operator<< (std::ostream &out, const Matrix< T, M, N, Flags > &m) |
Takes a matrix and writes to out in a formatted manner. More... | |
template<size_t P, size_t Q, unsigned int Flags2> | |
bool | operator== (const Matrix< T, M, N, Flags > &a, const Matrix< T, P, Q, Flags2 > &b) |
Compares two matrices entrywise. More... | |
template<size_t P, size_t Q, unsigned int Flags2> | |
bool | operator!= (const Matrix< T, M, N, Flags > &a, const Matrix< T, P, Q, Flags2 > &b) |
Compares two matrices entrywise. More... | |
Class for matrices.
T | Type to store the real and imaginary part of each entry as. |
M | Number of rows. Use Dynamic to allow this value to change over time. |
N | Number of column. Use Dynamic to allow this value to change over time. |
Flags | Whether to use row major storage or column major storage. (default = row major). |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=x\) for all \(i,j\). If M or N are set to Dynamic, a 0x0 matrix will be created.
x | Real number (default = 0) |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=z\) for all \(i,j\). If M or N are set to Dynamic, a 0x0 matrix will be created.
val | Complex number |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=x\) for all \(i,j\). If M or N are set to Dynamic, they will be set to size. Otherwise, the size parameter is ignored.
size | Size to set M or N if they are set to Dynamic. |
x | Real number (default = 0) |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=z\) for all \(i,j\). If M or N are set to Dynamic, they will be set to size. Otherwise, the size parameter is ignored.
size | Size to set M or N if they are set to Dynamic. |
z | Complex number |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=x\) for all \(i,j\). If M is set to Dynamic, it will be set to nrows. If N is set to Dynamic, it will be set to ncols. Otherwise, the nrows and ncols parameters are ignored.
nrows | Size to set M if it is set to Dynamic. |
ncols | Size to set N if it is set to Dynamic. |
x | Real number (default = 0) |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) where \(a_{ij}=z\) for all \(i,j\). If M is set to Dynamic, it will be set to nrows. If N is set to Dynamic, it will be set to ncols. Otherwise, the nrows and ncols parameters are ignored.
nrows | Size to set M if it is set to Dynamic. |
ncols | Size to set N if it is set to Dynamic. |
z | Complex number |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) by filling in entries from list. The order they are filled in depend on Flags. If the list is longer than M*N, then the remaining entries are ignored. If the list is shorter than M*N, then the remaining entries are set to zero.
If both M and N is set to Dynamic, it will set M to the list's size and N to 1. If just M is Dynamic or just N is Dynamic, it will set the Dynamic size to the list's size divided the non-Dynamic size. However, if the list's size is less than the non-Dynamic size, it will set the Dynamic size to 1.
list | Initializer list of real numbers |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) by filling in entries from list. The order they are filled in depend on Flags. If the list is longer than M*N, then the remaining entries are ignored. If the list is shorter than M*N, then the remaining entries are set to zero.
If both M and N is set to Dynamic, it will set M to the list's size and N to 1. If just M is Dynamic or just N is Dynamic, it will set the Dynamic size to the list's size divided the non-Dynamic size. However, if the list's size is less than the non-Dynamic size, it will set the Dynamic size to 1.
list | Initializer list of Complex numbers |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) by filling in entries from list. Each initializer list in list represents a row of A. If that row is longer than N, than the remaining elements of that row are ignored. If that row is shorter than N, the remaining elements are zero to zero.
If M is set to Dynamic, it will set M to the number of rows in the list. If N is set to Dynamic, it will set N to the longest row on the list.
list | Initializer list of initializer lists of real numbers. |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) by filling in entries from list. Each initializer list in list represents a row of A. If that row is longer than N, than the remaining elements of that row are ignored. If that row is shorter than N, the remaining elements are zero to zero.
If M is set to Dynamic, it will set M to the number of rows in the list. If N is set to Dynamic, it will set N to the longest row on the list.
list | Initializer list of initializer lists of complex numbers. |
|
inline |
|
inline |
Constructor.
Creates the M-by-N matrix \(A\) by copying the matrix given by other. If Q < N, the remaining N-Q elements of each row will be set to zero. If Q > N, the remaining Q-N elements of other is ignored. If P < M, the remaining M-P rows will be set to zero. If P > M, the remaining P-M rows of other is ignored.
If M is set to Dynamic, it will set M to P. If N is set to Dynamic, it will set N to Q.
other | PxQ Matrix |
|
inline |
Scales row r2 by s then adds it to r1, i.e., \(a_{r1,i}=a_{r1,i}+sa_{r2,i}\) for \(0\le i<N\).
If \(r1\ge M\) or \(r2\ge M\) an exception is thrown.
r1 | Row 1 index |
r2 | Row 2 index |
s | Complex number |
|
inline |
|
inline |
Takes column c of the matrix and returns it.
If \(c\ge N\), an exception is thrown.
c | Column index |
|
inline |
Takes row r of the matrix and returns it.
If \(r\ge M\), an exception is thrown.
r | Row index |
|
inline |
For vectors, this returns the length of the vector.
For matrices, returns either M or N depending on what's larger. If empty, 0 is returned.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns the the data located in row r and column c.
If the matrix is column major, r still represents the row and c still represents the column.
r | Row index |
c | Column index |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Operators.
Returns the ith entry of the data. This accesses the data directly, the result will depend on if the matrix is row major or column major.
i | Index |
|
inline |
Resizes a dynamic matrix.
If M or N are dynamic, this function becomes available. If both M and N are dynamic, it resizes the matrix to newMxnewN. Otherwise it resizes the matrix to newMxN or MxnewN depending if M or N is dynamic. If neither M nor N are dynamic, this function throws an exception.
newM | New number of rows. Ignored if M is not dynamic |
newN | New number of columns. Ignored if N is not dynamic |
|
inline |
Resizes a dynamic matrix.
If M or N is dynamic, this function becomes available. It resizes the matrix to newSizexN or MxnewSize depending on if N or M is dynamic. If both M and N are dynamic, it becomes an newSizexnewSize matrix. If neither M nor N are dynamic, this function throws an exception.
newSize | New number of rows/columns |
|
inline |
Scales row r by s, i.e., \(a_{ri}=sa_{ri}\) for \(0\le i<N\).
If \(r\ge M\) an exception is thrown.
r | Row index |
s | Complex number |
|
inline |
Sets column c of the matrix to row.
If \(c\ge N\), an exception is thrown. If \(P\ne M\) or \(Q\ne 1\), an exception is thrown.
c | Column index |
column | PxQ Matrix |
|
inline |
Sets row r of the matrix to row.
If \(r\ge M\), an exception is thrown. If \(P\ne 1\) or \(Q\ne N\), an exception is thrown.
r | Row index |
row | PxQ Matrix |
|
inline |
|
inline |
Swaps rows r1 and r2.
If \(r1\ge M\) or \(r2\ge M\) an exception is thrown.
r1 | Row 1 index |
r2 | Row 2 index |
|
friend |
Takes a matrix and writes to out in a formatted manner.
out | Reference to std::ostream. |
m | MxN Matrix. |