cisst-saw
Loading...
Searching...
No Matches
nmrInverse.h File Reference

Declaration of nmrInverse. More...

Go to the source code of this file.

Classes

class  nmrInverseDynamicData
 Data for Inverse problem (Dynamic). More...
class  nmrInverseDynamicData::Friend
class  nmrInverseFixedSizeData< _size, _storageOrder >
 Data for Inverse problem (Fixed size). More...
class  nmrInverseFixedSizeData< _size, _storageOrder >::Friend

Functions

Algorithm Inverse: Compute the inverse of a square matrix

using Lower Upper Decomposition

These functions are different wrappers for the LAPACK function dgetrf and dgetri. They compute the inverse factorization of a square matrix A.

These functions are wrappers around the LAPACK routine dgetrf and dgetri, therefore they share some features with the LAPACK routine:

  1. On exit, the content of A is altered.
  2. The vectors and matrices must be compact, i.e. use a contiguous block of memory.

The nmrInverse functions add the following features:

  1. A simplified interface to the cisstVector matrices, either vctDynamicMatrix or vctFixedSizeMatrix.
  2. Input validation checks are performed, i.e. an std::runtime_error exception will be thrown if the sizes or storage order don't match or if the containers are not compact.
  3. Helper classes to allocate memory for the output and workspace: nmrInverseFixedSizeData and nmrInverseDynamicData.

There are different ways to call this function to compute the Inverse of the matrix A. These correspond to different overloaded nmrInverse functions:

  1. Using a preallocated data object.

    The user creates the input matrix A:

    vctRandom(A, -10.0, 10.0);
    Definition vctForwardDeclarations.h:157
    void vctRandom(vctDynamicMatrixBase< _matrixOwnerType, _elementType > &matrix, const typename vctDynamicMatrixBase< _matrixOwnerType, _elementType >::value_type min, const typename vctDynamicMatrixBase< _matrixOwnerType, _elementType >::value_type max)
    Definition vctRandomDynamicMatrix.h:47
    const bool VCT_COL_MAJOR
    Definition vctForwardDeclarations.h:44

    The user allocates a data object which could be of type nmrInverseFixedSizeData or nmrInverseDynamicData. corresponding to fixed size or dynamic matrix A:

    Data for Inverse problem (Dynamic).
    Definition nmrInverse.h:80

    Call the nmrInverse function:

    nmrInverse(A, data);
    CISSTNETLIB_INTEGER nmrInverse(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrInverseDynamicData &data) CISST_THROW(std
    Definition nmrInverse.h:572

    The content of input matrix A is modified by this routine.

  2. The user provides the vector pivotIndices and workspace.

    The User allocates memory for this vector:

    vctRandom(A, -10.0, 10.0);
    static size_type PivotIndicesSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
    Definition nmrInverse.h:211
    static size_type WorkspaceSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
    Definition nmrInverse.h:224
    Definition vctForwardDeclarations.h:131

    Call the Inverse routine:

    nmrInverse(A, pivotIndices, workspace);

    The Inverse function verifies that the size of the data objects matches the input.

  3. Using a data for fixed size containers.

    vctRandom(A, -10.0, 10.0);
    DataType data;
    nmrInverse(A, data);
    Data for Inverse problem (Fixed size).
    Definition nmrInverse.h:415
    Implementation of a fixed-size matrix using template metaprogramming.
    Definition vctFixedSizeMatrix.h:54

Note
The Inverse functions make use of LAPACK routines. To activate this code, set the CISST_HAS_CISSTNETLIB flag to ON during the configuration of cisst with CMake.
template<class _matrixOwnerType>
CISSTNETLIB_INTEGER nmrInverse (vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrInverseDynamicData &data) CISST_THROW(std
template<class _matrixOwnerTypeA, class _vectorOwnerTypePivotIndices, class _vectorOwnerTypeWorkspace>
CISSTNETLIB_INTEGER nmrInverse (vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > &pivotIndices, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
template<class _matrixOwnerTypeA>
CISSTNETLIB_INTEGER nmrInverse (vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
template<vct::size_type _size, vct::size_type _maxSize1, vct::size_type _lWork, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > &A, vctFixedSizeVector< CISSTNETLIB_INTEGER, _maxSize1 > &pivotIndices, vctFixedSizeVector< CISSTNETLIB_DOUBLE, _lWork > &workspace)
template<vct::size_type _size, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > &A, nmrInverseFixedSizeData< _size, _storageOrder > &data)
template<vct::size_type _size, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > &A)

Detailed Description

Declaration of nmrInverse.

Function Documentation

◆ nmrInverse() [1/6]

template<class _matrixOwnerType>
CISSTNETLIB_INTEGER nmrInverse ( vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > & A,
nmrInverseDynamicData & data )
inline

This function solves the Inverse problem for a dynamic matrix using an nmrInverseDynamicData.

This function checks for valid input (size and compact) and calls the LAPACK function. If the input doesn't match the data, an exception is thrown (std::runtime_error).

This function modifies the input matrix A and stores the results in the data.

Parameters
AA square matrix, either vctDynamicMatrix or vctDynamicMatrixRef.
dataA data object corresponding to the input matrix.
Test
nmrInverseTest::TestDynamicColumnMajor nmrInverseTest::TestDynamicRowMajor

◆ nmrInverse() [2/6]

template<class _matrixOwnerTypeA>
CISSTNETLIB_INTEGER nmrInverse ( vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & A)
inline

This function solves the Inverse problem for a dynamic matrix.

Internally, a data object is created. This forces the dynamic allocation of the pivot indices vector as well as the workspace vector. Then, the nmrInverse(A, data) function can be used safely.

Parameters
Ais a reference to a dynamic square matrix

◆ nmrInverse() [3/6]

template<class _matrixOwnerTypeA, class _vectorOwnerTypePivotIndices, class _vectorOwnerTypeWorkspace>
CISSTNETLIB_INTEGER nmrInverse ( vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & A,
vctDynamicVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > & pivotIndices,
vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & workspace )
inline

This function solves the Inverse problem for a dynamic matrix using the storage provided by the user (pivotIndices and workspace).

Internally, a data is created using the storage provided by the user (see nmrInverseDynamicData::SetRef). While the data is being build, the consistency of the output is checked. Then, the nmrInverse(A, data) function can be used safely.

Parameters
Ais a reference to a dynamic square matrix
pivotIndicesVector created by the user to store the pivot indices.
workspaceVector created by the user for the workspace.
Test
nmrInverseTest::TestDynamicColumnMajorUserAlloc nmrInverseTest::TestDynamicRowMajorUserAlloc

◆ nmrInverse() [4/6]

template<vct::size_type _size, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse ( vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > & A)
inline

This function solves the Inverse problem for a fixed size matrix.

Internally, a data object is created. This forces the allocation (stack) of the pivot indices vector as well as the workspace vector. Then, the nmrInverse(A, data) function can be used safely.

Parameters
AA fixed size square matrix.

◆ nmrInverse() [5/6]

template<vct::size_type _size, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse ( vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > & A,
nmrInverseFixedSizeData< _size, _storageOrder > & data )
inline

This function solves the Inverse problem for a fixed size matrix using nmrInverseFixedSizeData to allocate the memory required for the pivot indices and the workspace:

This method calls nmrInverse(A, pivotIndices, workspace).

Parameters
AA fixed size square matrix.
dataA data object.
Test
TestFixedSizeColumnMajor TestFixedSizeRowMajor

◆ nmrInverse() [6/6]

template<vct::size_type _size, vct::size_type _maxSize1, vct::size_type _lWork, bool _storageOrder>
CISSTNETLIB_INTEGER nmrInverse ( vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _size, _size, _storageOrder > & A,
vctFixedSizeVector< CISSTNETLIB_INTEGER, _maxSize1 > & pivotIndices,
vctFixedSizeVector< CISSTNETLIB_DOUBLE, _lWork > & workspace )
inline

This function solves the Inverse problem for a fixed size matrix using the storage provided by the user for the pivot indices vector as well as the workspace vector.

The sizes of the matrices must match at compilation time. This is enforced by the template parameters and matching problems will lead to compilation errors. Since there is no easy way to enforce the size of the vector pivotIndices with template parameters, a runtime check is performed. The test uses CMN_ASSERT to determine what to do if the sizes don't match. By default CMN_ASSERT calls abort() but it can be configured to be ignored or to throw an exception (see CMN_ASSERT for details).

This function modifies the input matrix A.

Parameters
Ais a fixed size square matrix.
pivotIndicesVector created by the caller for the pivot indices.
workspaceVector created by the caller for the workspace.
Test
TestFixedSizeColumnMajorUserAlloc TestFixedSizeRowMajorUserAlloc