casacore
|
#include <SquareMatrix.h>
Public Types | |
enum | { General , Diagonal , ScalarId } |
Enum used internally to optimize operations. More... | |
Public Member Functions | |
~SquareMatrix () | |
Destructor. More... | |
SquareMatrix () | |
Default constructor - creates a unity matrix at present, this may not be what we want (non-intuitive?) More... | |
SquareMatrix (int itype) | |
Create a matrix of a given type, no initialization. More... | |
SquareMatrix (const SquareMatrix< T, n > &m) | |
Copy construct a SquareMatrix, a true copy is made. More... | |
SquareMatrix (const T a[n][n]) | |
Construct from c-style matrix (by copying elements). More... | |
SquareMatrix (const Matrix< T > &mat) | |
Construct from Matrix. More... | |
SquareMatrix (const T vec[n]) | |
Construct from c-style vector, creates a diagonal matrix. More... | |
SquareMatrix (const Vector< T > &vec) | |
Construct from Vector, creates a diagonal matrix. More... | |
SquareMatrix (const T &scalar) | |
Construct from scalar, creates a scalar-identity matrix. More... | |
SquareMatrix< T, n > & | operator= (const SquareMatrix< T, n > &m) |
Assignment, uses copy semantics. More... | |
SquareMatrix< T, n > & | operator= (const T a[n][n]) |
Assign a c-style matrix, creates a general matrix. More... | |
SquareMatrix< T, n > & | operator= (const Matrix< T > &m) |
Assign a Matrix, creates a general matrix. More... | |
SquareMatrix< T, n > & | operator= (const T vec[n]) |
Assign a c-style vector, creates a diagonal matrix. More... | |
SquareMatrix< T, n > & | operator= (const Vector< T > &v) |
Assign a Vector, creates a diagonal matrix. More... | |
SquareMatrix< T, n > & | operator= (T val) |
Assign a scalar, creates a scalar-identity matrix. More... | |
SquareMatrix< T, n > & | operator+= (const SquareMatrix< T, n > &other) |
Add two SquareMatrices, element by element. More... | |
SquareMatrix< T, n > & | operator*= (const SquareMatrix< T, n > &other) |
Matrix product of 'this' SquareMatrix with other, i.e., A*=B; is equivalent with A=A*B where '*' is matrix multiplication. More... | |
SquareMatrix< T, n > & | operator*= (Float f) |
Scalar multiplication. More... | |
T | operator() (Int i, Int j) const |
Indexing, only const indexing is allowed. More... | |
T & | operator() (Int i, Int j) |
Non const indexing, throws exception if you try to change an element which would require a type change of the matrix. More... | |
SquareMatrix< T, n > & | conj () |
For a SquareMatrix<Complex,n> : set the argument result to the real part of the matrix (and return result by reference to allow use in expressions without creating temporary). More... | |
SquareMatrix< T, n > & | adjoint () |
Tranpose and conjugate the matrix in place(!). More... | |
SquareMatrix< T, n > & | conj (SquareMatrix< T, n > &result) |
Conjugate the matrix, return it in result (and by ref) More... | |
SquareMatrix< T, n > & | adjoint (SquareMatrix< T, n > &result) |
Tranpose and conjugate the matrix, return it in result (and by ref) More... | |
SquareMatrix< T, n > & | inverse (SquareMatrix< T, n > &result) const |
Compute the inverse of the matrix and return it in result (also returns result by reference). More... | |
SquareMatrix< T, n > | inverse () const |
Return the inverse of the matrix by value. More... | |
Matrix< T > & | matrix (Matrix< T > &result) const |
Assign 'this' to the Matrix result, also return result by reference. More... | |
Matrix< T > | matrix () const |
Convert the SquareMatrix to a Matrix. More... | |
Private Member Functions | |
T & | throwInvAccess () |
Private Attributes | |
T | a_p [n][n] |
Int | type_p |
Friends | |
class | RigidVector< T, n > |
Friends currently need to be explicit (non templated) type to work. More... | |
RigidVector< Complex, 4 > | operator* (const SquareMatrix< Complex, 4 > &m, const RigidVector< Float, 4 > &v) |
friend class SquareMatrix<T,n*n>;// Sun native does not accept this friend class SquareMatrix<Complex,4>; // for directProduct of 2x2 Global friend function for product of Complex matrix and Float 4-vector More... | |
SquareMatrix< Complex, 4 > & | directProduct (SquareMatrix< Complex, 4 > &result, const SquareMatrix< Complex, 2 > &left, const SquareMatrix< Complex, 2 > &right) |
Global friend function to calculate direct product. More... | |
Fast Square Matrix class with fixed (templated) size
Public interface
SquareMatrix is a specialized class for small (<5x5) square matrices.
SquareMatrix provides operations similar to the Matrix class, but it is much faster for small arrays. One important difference is that operators *= and * do matrix products for SquareMatrices instead of element by element multiplication. SquareMatrices also optimize operations internally for scalar identity matrices (diagonal matrix with all elements equal) and diagonal matrices. The different types of SquareMatrix are created by constructors and operator= taking either a scalar, a vector or a full matrix.
The basic Matrix classes are rather inefficient for small sizes, new and delete tend to dominate the execution time for computationally intensive code. The SquareMatrix classes circumvent this by having a compile-time fixed size c-array internally. The SquareMatrix class have fixed zero origin and no increments, this allows fast indexing, copying and math operations. As mentioned in the synopsis, the SquareMatrix classes also avoid unnecessary operations for simple matrices (scalar-identity and diagonal).
Definition at line 107 of file SquareMatrix.h.
anonymous enum |
Enum used internally to optimize operations.
Enumerator | |
---|---|
General | |
Diagonal | |
ScalarId |
Definition at line 123 of file SquareMatrix.h.
|
inline |
Destructor.
Definition at line 125 of file SquareMatrix.h.
|
inline |
Default constructor - creates a unity matrix at present, this may not be what we want (non-intuitive?)
Definition at line 128 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p.
|
inline |
Create a matrix of a given type, no initialization.
Definition at line 130 of file SquareMatrix.h.
|
inline |
Copy construct a SquareMatrix, a true copy is made.
Definition at line 132 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from c-style matrix (by copying elements).
Definition at line 134 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from Matrix.
Definition at line 136 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from c-style vector, creates a diagonal matrix.
Definition at line 138 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from Vector, creates a diagonal matrix.
Definition at line 140 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from scalar, creates a scalar-identity matrix.
Definition at line 142 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::adjoint | ( | ) |
Tranpose and conjugate the matrix in place(!).
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::adjoint | ( | SquareMatrix< T, n > & | result | ) |
Tranpose and conjugate the matrix, return it in result (and by ref)
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::conj | ( | ) |
For a SquareMatrix<Complex,n>
: set the argument result to the real part of the matrix (and return result by reference to allow use in expressions without creating temporary).
For a SquareMatrix<Complex,n>
: return the real part of the matrix.
Conjugate the matrix in place(!).
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::conj | ( | SquareMatrix< T, n > & | result | ) |
Conjugate the matrix, return it in result (and by ref)
|
inline |
Return the inverse of the matrix by value.
Definition at line 226 of file SquareMatrix.h.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::inverse | ( | SquareMatrix< T, n > & | result | ) | const |
Compute the inverse of the matrix and return it in result (also returns result by reference).
|
inline |
Convert the SquareMatrix to a Matrix.
Definition at line 231 of file SquareMatrix.h.
Matrix<T>& casacore::SquareMatrix< T, n >::matrix | ( | Matrix< T > & | result | ) | const |
Assign 'this' to the Matrix result, also return result by reference.
|
inline |
Non const indexing, throws exception if you try to change an element which would require a type change of the matrix.
Definition at line 187 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p, casacore::SquareMatrix< T, n >::Diagonal, casacore::SquareMatrix< T, n >::ScalarId, casacore::SquareMatrix< T, n >::throwInvAccess(), and casacore::SquareMatrix< T, n >::type_p.
|
inline |
Indexing, only const indexing is allowed.
You cannot change the matrix via indexing. No bounds checking.
Definition at line 176 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p, casacore::SquareMatrix< T, n >::Diagonal, casacore::SquareMatrix< T, n >::ScalarId, and casacore::SquareMatrix< T, n >::type_p.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator*= | ( | const SquareMatrix< T, n > & | other | ) |
Matrix product of 'this' SquareMatrix with other, i.e., A*=B; is equivalent with A=A*B where '*' is matrix multiplication.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator*= | ( | Float | f | ) |
Scalar multiplication.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator+= | ( | const SquareMatrix< T, n > & | other | ) |
Add two SquareMatrices, element by element.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator= | ( | const Matrix< T > & | m | ) |
Assign a Matrix, creates a general matrix.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator= | ( | const SquareMatrix< T, n > & | m | ) |
Assignment, uses copy semantics.
Referenced by casacore::SquareMatrix< T, n >::SquareMatrix().
|
inline |
Assign a c-style matrix, creates a general matrix.
Definition at line 146 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p, casacore::SquareMatrix< T, n >::General, casacore::pa(), and casacore::SquareMatrix< T, n >::type_p.
|
inline |
Assign a c-style vector, creates a diagonal matrix.
Definition at line 156 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p, casacore::SquareMatrix< T, n >::Diagonal, and casacore::SquareMatrix< T, n >::type_p.
SquareMatrix<T,n>& casacore::SquareMatrix< T, n >::operator= | ( | const Vector< T > & | v | ) |
Assign a Vector, creates a diagonal matrix.
|
inline |
Assign a scalar, creates a scalar-identity matrix.
Definition at line 164 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p, casacore::SquareMatrix< T, n >::ScalarId, and casacore::SquareMatrix< T, n >::type_p.
|
private |
Referenced by casacore::SquareMatrix< T, n >::operator()().
|
friend |
Global friend function to calculate direct product.
|
friend |
friend class SquareMatrix<T,n*n>;// Sun native does not accept this friend class SquareMatrix<Complex,4>; // for directProduct of 2x2 Global friend function for product of Complex matrix and Float 4-vector
|
friend |
Friends currently need to be explicit (non templated) type to work.
Definition at line 1 of file SquareMatrix.h.
|
private |
Definition at line 236 of file SquareMatrix.h.
Referenced by casacore::SquareMatrix< T, n >::operator()(), casacore::SquareMatrix< T, n >::operator=(), and casacore::SquareMatrix< T, n >::SquareMatrix().
|
private |
Definition at line 237 of file SquareMatrix.h.
Referenced by casacore::SquareMatrix< T, n >::operator()(), and casacore::SquareMatrix< T, n >::operator=().