casacore
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
casacore::SquareMatrix< T, n > Class Template Reference

More...

#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.
 
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

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.
 

Detailed Description

template<class T, Int n>
class casacore::SquareMatrix< T, n >

Fast Square Matrix class with fixed (templated) size

Intended use:

Public interface

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Etymology

SquareMatrix is a specialized class for small (<5x5) square matrices.

Synopsis

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.

Example

// create two SquareMatrices
SquareMatrix<Float,2> sm1(3.0); // a scalar identity matrix
Vector<Float> vec(2); vec(0)=2.0; vec(1)=3.0;
SquareMatrix<Float,2> sm2(vec); // a diagonal matrix
// multiply the matrices
// Note: A*=B is equivalent to A=A*B where '*' is matrix multiplication
sm1*=sm2; // sm1 now diagonal

Motivation

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).

Template Type Argument Requirements (T)

Thrown Exceptions

To Do

Definition at line 104 of file SquareMatrix.h.

Member Enumeration Documentation

◆ anonymous enum

template<class T , Int n>
anonymous enum

Enum used internally to optimize operations.

Enumerator
General 
Diagonal 
ScalarId 

Definition at line 120 of file SquareMatrix.h.

Constructor & Destructor Documentation

◆ ~SquareMatrix()

template<class T , Int n>
casacore::SquareMatrix< T, n >::~SquareMatrix ( )
inline

Destructor.

Definition at line 122 of file SquareMatrix.h.

◆ SquareMatrix() [1/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( )
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.

◆ SquareMatrix() [2/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( int  itype)
inline

Create a matrix of a given type, no initialization.

Definition at line 127 of file SquareMatrix.h.

◆ SquareMatrix() [3/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const SquareMatrix< T, n > &  m)
inline

Copy construct a SquareMatrix, a true copy is made.

Definition at line 129 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::operator=().

◆ SquareMatrix() [4/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const T  a[n][n])
inline

Construct from c-style matrix (by copying elements).

Definition at line 131 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::operator=().

◆ SquareMatrix() [5/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const Matrix< T > &  mat)
inline

Construct from Matrix.

Definition at line 133 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::operator=().

◆ SquareMatrix() [6/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const T  vec[n])
inline

Construct from c-style vector, creates a diagonal matrix.

Definition at line 135 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::operator=().

◆ SquareMatrix() [7/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const Vector< T > &  vec)
inline

Construct from Vector, creates a diagonal matrix.

Definition at line 137 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::operator=().

◆ SquareMatrix() [8/8]

template<class T , Int n>
casacore::SquareMatrix< T, n >::SquareMatrix ( const T &  scalar)
inline

Construct from scalar, creates a scalar-identity matrix.

Definition at line 139 of file SquareMatrix.h.

References casacore::SquareMatrix< T, n >::a_p.

Member Function Documentation

◆ adjoint() [1/2]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::adjoint ( )

Tranpose and conjugate the matrix in place(!).

◆ adjoint() [2/2]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::adjoint ( SquareMatrix< T, n > &  result)

Tranpose and conjugate the matrix, return it in result (and by ref)

◆ conj() [1/2]

template<class T , Int n>
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(!).

◆ conj() [2/2]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::conj ( SquareMatrix< T, n > &  result)

Conjugate the matrix, return it in result (and by ref)

◆ inverse() [1/2]

template<class T , Int n>
SquareMatrix< T, n > casacore::SquareMatrix< T, n >::inverse ( ) const
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().

◆ inverse() [2/2]

template<class T , Int n>
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).

◆ matrix() [1/2]

template<class T , Int n>
Matrix< T > casacore::SquareMatrix< T, n >::matrix ( ) const
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() [2/2]

template<class T , Int n>
Matrix< T > & casacore::SquareMatrix< T, n >::matrix ( Matrix< T > &  result) const

Assign 'this' to the Matrix result, also return result by reference.

◆ operator()() [1/2]

template<class T , Int n>
T & casacore::SquareMatrix< T, n >::operator() ( Int  i,
Int  j 
)
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.

◆ operator()() [2/2]

template<class T , Int n>
T casacore::SquareMatrix< T, n >::operator() ( Int  i,
Int  j 
) const
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.

◆ operator*=() [1/2]

template<class T , Int n>
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.

◆ operator*=() [2/2]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator*= ( Float  f)

Scalar multiplication.

◆ operator+=()

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator+= ( const SquareMatrix< T, n > &  other)

Add two SquareMatrices, element by element.

◆ operator=() [1/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( const Matrix< T > &  m)

Assign a Matrix, creates a general matrix.

◆ operator=() [2/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( const SquareMatrix< T, n > &  m)

◆ operator=() [3/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( const T  a[n][n])
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.

◆ operator=() [4/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( const T  vec[n])
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.

◆ operator=() [5/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( const Vector< T > &  v)

Assign a Vector, creates a diagonal matrix.

◆ operator=() [6/6]

template<class T , Int n>
SquareMatrix< T, n > & casacore::SquareMatrix< T, n >::operator= ( val)
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.

◆ throwInvAccess()

template<class T , Int n>
T & casacore::SquareMatrix< T, n >::throwInvAccess ( )
private

Friends And Related Symbol Documentation

◆ directProduct

template<class T , Int n>
SquareMatrix< Complex, 4 > & directProduct ( SquareMatrix< Complex, 4 > &  result,
const SquareMatrix< Complex, 2 > &  left,
const SquareMatrix< Complex, 2 > &  right 
)
friend

Global friend function to calculate direct product.

◆ operator*

template<class T , Int n>
RigidVector< Complex, 4 > operator* ( const SquareMatrix< Complex, 4 > &  m,
const RigidVector< Float, 4 > &  v 
)
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

◆ RigidVector< T, n >

template<class T , Int n>
friend class RigidVector< T, n >
friend

Friends currently need to be explicit (non templated) type to work.

Definition at line 1 of file SquareMatrix.h.

Member Data Documentation

◆ a_p

template<class T , Int n>
T casacore::SquareMatrix< T, n >::a_p[n][n]
private

◆ type_p

template<class T , Int n>
Int casacore::SquareMatrix< T, n >::type_p
private

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