casacore
|
#include <SquareMatrix.h>
Public Types | |
enum | { General , Diagonal , ScalarId } |
Enum used internally to optimize operations. More... | |
Public Member Functions | |
~SquareMatrix () | |
Destructor. | |
SquareMatrix () | |
Default constructor - creates a unity matrix at present, this may not be what we want (non-intuitive?) | |
SquareMatrix (int itype) | |
Create a matrix of a given type, no initialization. | |
SquareMatrix (const SquareMatrix< T, n > &m) | |
Copy construct a SquareMatrix, a true copy is made. | |
SquareMatrix (const T a[n][n]) | |
Construct from c-style matrix (by copying elements). | |
SquareMatrix (const Matrix< T > &mat) | |
Construct from Matrix. | |
SquareMatrix (const T vec[n]) | |
Construct from c-style vector, creates a diagonal matrix. | |
SquareMatrix (const Vector< T > &vec) | |
Construct from Vector, creates a diagonal matrix. | |
SquareMatrix (const T &scalar) | |
Construct from scalar, creates a scalar-identity matrix. | |
SquareMatrix< T, n > & | operator= (const SquareMatrix< T, n > &m) |
Assignment, uses copy semantics. | |
SquareMatrix< T, n > & | operator= (const T a[n][n]) |
Assign a c-style matrix, creates a general matrix. | |
SquareMatrix< T, n > & | operator= (const Matrix< T > &m) |
Assign a Matrix, creates a general matrix. | |
SquareMatrix< T, n > & | operator= (const T vec[n]) |
Assign a c-style vector, creates a diagonal matrix. | |
SquareMatrix< T, n > & | operator= (const Vector< T > &v) |
Assign a Vector, creates a diagonal matrix. | |
SquareMatrix< T, n > & | operator= (T val) |
Assign a scalar, creates a scalar-identity matrix. | |
SquareMatrix< T, n > & | operator+= (const SquareMatrix< T, n > &other) |
Add two SquareMatrices, element by element. | |
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 > & | operator*= (Float f) |
Scalar multiplication. | |
T | operator() (Int i, Int j) const |
Indexing, only const indexing is allowed. | |
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. | |
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). | |
SquareMatrix< T, n > & | adjoint () |
Tranpose and conjugate the matrix in place(!). | |
SquareMatrix< T, n > & | conj (SquareMatrix< T, n > &result) |
Conjugate the matrix, return it in result (and by ref) | |
SquareMatrix< T, n > & | adjoint (SquareMatrix< T, n > &result) |
Tranpose and conjugate the matrix, return it in result (and by ref) | |
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). | |
SquareMatrix< T, n > | inverse () const |
Return the inverse of the matrix by value. | |
Matrix< T > & | matrix (Matrix< T > &result) const |
Assign 'this' to the Matrix result, also return result by reference. | |
Matrix< T > | matrix () const |
Convert the SquareMatrix to a Matrix. | |
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. | |
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 | |
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. | |
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 104 of file SquareMatrix.h.
anonymous enum |
Enum used internally to optimize operations.
Enumerator | |
---|---|
General | |
Diagonal | |
ScalarId |
Definition at line 120 of file SquareMatrix.h.
|
inline |
Destructor.
Definition at line 122 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 125 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::a_p.
|
inline |
Create a matrix of a given type, no initialization.
Definition at line 127 of file SquareMatrix.h.
|
inline |
Copy construct a SquareMatrix, a true copy is made.
Definition at line 129 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from c-style matrix (by copying elements).
Definition at line 131 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from Matrix.
Definition at line 133 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from c-style vector, creates a diagonal matrix.
Definition at line 135 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from Vector, creates a diagonal matrix.
Definition at line 137 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::operator=().
|
inline |
Construct from scalar, creates a scalar-identity matrix.
Definition at line 139 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 223 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::inverse().
Referenced by casacore::SquareMatrix< T, n >::inverse().
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 228 of file SquareMatrix.h.
References casacore::SquareMatrix< T, n >::matrix().
Referenced by casacore::SquareMatrix< T, n >::matrix().
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 184 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 173 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(), casacore::SquareMatrix< T, n >::SquareMatrix(), casacore::SquareMatrix< T, n >::SquareMatrix(), casacore::SquareMatrix< T, n >::SquareMatrix(), and casacore::SquareMatrix< T, n >::SquareMatrix().
|
inline |
Assign a c-style matrix, creates a general matrix.
Definition at line 143 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 153 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 161 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 233 of file SquareMatrix.h.
Referenced by casacore::SquareMatrix< T, n >::operator()(), casacore::SquareMatrix< T, n >::operator()(), casacore::SquareMatrix< T, n >::operator=(), casacore::SquareMatrix< T, n >::operator=(), casacore::SquareMatrix< T, n >::operator=(), casacore::SquareMatrix< T, n >::SquareMatrix(), and casacore::SquareMatrix< T, n >::SquareMatrix().
|
private |