All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions
QGpCoreTools::DoubleMatrix Class Reference

Brief description of class still missing. More...

#include <DoubleMatrix.h>

Inheritance diagram for QGpCoreTools::DoubleMatrix:
QGpCoreTools::Matrix< double > QGpCoreTools::Matrix2x2 QGpCoreTools::Matrix3x3 QGpCoreTools::Matrix4x4

List of all members.

Public Member Functions

 DoubleMatrix ()
 DoubleMatrix (int ndim)
 DoubleMatrix (int nrow, int ncol)
 DoubleMatrix (const Matrix< double > m)
 DoubleMatrix (const DoubleMatrix &m)
DoubleMatrix eigenVectors (QVector< double > &eigenValues) const
bool invert ()
void random (double min=0.0, double max=1.0)
void rotation (AxisType ax, const Angle &angle)

Detailed Description

Brief description of class still missing.

NxM matrix with double values stored in the same way as LAPACK: iCol*nRows+iRow


Constructor & Destructor Documentation

: Matrix<double>() {}
: Matrix<double>(ndim) {}
QGpCoreTools::DoubleMatrix::DoubleMatrix ( int  nrow,
int  ncol 
) [inline]
: Matrix<double>(nrow, ncol) {}
QGpCoreTools::DoubleMatrix::DoubleMatrix ( const Matrix< double >  m) [inline]
: Matrix<double>(m) {}
: Matrix<double>(m) {}

Member Function Documentation

Computes eigen vectors and values

References QGpCoreTools::Matrix< T >::at(), QGpCoreTools::Matrix< double >::columnCount(), QGpCoreTools::Matrix< double >::data(), QGpCoreTools::dgesvd_(), and QGpCoreTools::Matrix< double >::rowCount().

Referenced by QGpCoreTools::Covariance::stddev2D().

  {
    int m=rowCount();
    int n=columnCount();
    int minDim=m;
    if(n<minDim) {
      minDim=n;
    }
    eigenValues.resize(minDim);

    double * a=new double[m*n];           // A copy of matrix values
    double * u=new double[m*n];           // nullspace vectors
    double * vt=new double[m*n];          // eigenvectors
    double * s=eigenValues.data();        // eigenvalues
    double * work=new double[10*minDim];  // work space

    /*
       Copy matrix to a because  its content will be destroyed
    */
    const double * aValues=data();
    for(register int i=m*n-1; i>=0; i--) {
      a[i]=aValues[i];
    }
    char jobu='A';            // flags to tell what to do in dgesvd_
    char jobvt='A';
    int lda=m;
    int ldu=m;
    int ldvt=n;
    int lwork=10*minDim;
    int info=0;
    // LAPACK is probalby not thread safe... lock it
    static QMutex mutex;
    mutex.lock();
    dgesvd_(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, &info);
    mutex.unlock();
    // Output is A=U * SIGMA * VT
    DoubleMatrix um(m,m);
    double * uValues=&um.at(0,0);
    for(register int i=m*m-1; i>=0; i--) {
      uValues[i]=u[i];
    }
    delete [] work;
    delete [] vt;
    delete [] u;
    delete [] a;
    return um;
  }

Based on LAPACK LU decomposition, for general matrix type.

Reimplemented from QGpCoreTools::Matrix< double >.

References QGpCoreTools::Matrix< double >::_d, QGpCoreTools::Matrix< double >::columnCount(), QGpCoreTools::dgetrf_(), QGpCoreTools::dgetri_(), and QGpCoreTools::Matrix< double >::rowCount().

  {
    ASSERT(rowCount()==columnCount());
    double * values=_d->values();
    int m=rowCount();
    if(m==1) {  // Not accepted by dgetrf
      values[0]=1.0/values[0];
      return true;
    }
    int n=columnCount();            // The order of matrix A
    int lda=m;                      // The leading dimension of A
    int * ipiv=new int[n];          // Pivot indices
    int lwork=5*n;                      // Dimension of workspace
    double * work=new double[lwork];   // work space
    int info;  // dimension of workspaces
    // LAPACK is probalby not thread safe... lock it
    static QMutex mutex;
    mutex.lock();
    dgetrf_(&m, &n, values, &lda, ipiv, &info);
    if(info!=0) { // singular matrix
      mutex.unlock();
      delete [] ipiv;
      delete [] work;
      return false;
    }
    dgetri_(&n, values, &lda, ipiv, work, &lwork, &info);
    if(info!=0) {
      mutex.unlock();
      delete [] ipiv;
      delete [] work;
      return false;
    }
    mutex.unlock();
    delete [] ipiv;
    delete [] work;
    _d->swapRowColumn();
    return true;
  }
void QGpCoreTools::DoubleMatrix::random ( double  min = 0.0,
double  max = 1.0 
)

Fills the matrix with random values between min and max

References QGpCoreTools::Matrix< double >::_d, QGpCoreTools::Matrix< double >::columnCount(), QGpCoreTools::Matrix< double >::rowCount(), and QGpCoreTools::Random::uniform().

  {
    Random r;
    double * values=_d->values();
    for(int i=columnCount()*rowCount()-1; i>=0;i--) {
      values[i]=r.uniform(min, max);
    }
  }
void QGpCoreTools::DoubleMatrix::rotation ( AxisType  ax,
const Angle angle 
)

Sets matrix as a rotation matrix around axis ax. The angle is counted using the right hand convention. Angle is in radians. The matrix must be set to identity before. Transformation matrix (4x4) can be constructed with the same function.

Reimplemented in QGpCoreTools::Matrix4x4, and QGpCoreTools::Matrix3x3.

References QGpCoreTools::Matrix< double >::at(), QGpCoreTools::Angle::cos(), QGpCoreTools::Angle::sin(), TRACE, QGpCoreTools::XAxis, QGpCoreTools::YAxis, and QGpCoreTools::ZAxis.

  {
    TRACE;
    switch (ax) {
    case XAxis:
      at(1, 1)=angle.cos();
      at(1, 2)=-angle.sin();
      at(2, 1)=angle.sin();
      at(2, 2)=angle.cos();
      break;
    case YAxis:
      at(0, 0)=angle.cos();
      at(0, 2)=angle.sin();
      at(2, 0)=-angle.sin();
      at(2, 2)=angle.cos();
      break;
    case ZAxis:
      at(0, 0)=angle.cos();
      at(0, 1)=-angle.sin();
      at(1, 0)=angle.sin();
      at(1, 1)=angle.cos();
      break;
    }
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines