#include <nmrSVDEconomy.h>
Collaboration diagram for nmrSVDEconomyDynamicData:

The result of an SVD decomposition is composed of three different containers, the matrices U and V and the vector S defined by
. The sizes of these components must match exactly the input matrix A. To ease the use of the SVD routine, the user can rely on the nmrSVDEconomyDynamicData class to perform the required memory allocation. Furthermore, the underlying Fortran routine from LAPACK requires a workspace (aka a scratch space). This workspace can also be allocated by the nmrSVDEconomyDynamicData.
Another good reason to use a "data" object is that the memory allocation can be performed once during an initialization phase while the function nmrSVDEconomy can be called numerous times later on without any new dynamic memory allocation. This is crucial for such things as real time tasks.
The SVD routine is somewhat specific in the sens that is can be used on either storage order, row major or column major, without any copy or transpose. Nevertheless, the current implementation requires all the matrices to use the same storage order, i.e. if A is row major, both U and Vt must be stored row first. Matrices and vectors must also be compact, i.e. use a contiguous block of memory.
Any size or storage order mismatch will lead to an exception thrown (std::runtime_error). Since we are using cmnThrow, it is possible to configure cisst (at compilation time) to abort the program instead of throwing an exception.
The nmrSVDEconomyDynamicData class allows 4 different configurations:
Definition at line 107 of file nmrSVDEconomy.h.
| typedef unsigned int nmrSVDEconomyDynamicData::size_type |
Type used for sizes within nmrSVDEconomyDynamicData. This type is compatible with the cisstVector containers such as vctDynamicMatrix and vctDynamicVector (unsigned int). To call the Fortran based routines, these values must be cast to CISSTNETLIB_INTEGER.
Definition at line 115 of file nmrSVDEconomy.h.
Matrix size type, i.e. vector of two elements: number of rows and columns.
Definition at line 119 of file nmrSVDEconomy.h.
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | ) | [inline] |
The default constuctor. For dynamic size, there are assigned default values, i.e. sets all the dimensions to zero. These MUST be changed by calling the appropriate method.
Definition at line 395 of file nmrSVDEconomy.h.
References AllocateOutputWorkspace().
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | size_type | m, | |
| size_type | n, | |||
| bool | storageOrder | |||
| ) | [inline] |
Constructor where the user specifies the size and storage order. Memory allocation is performed for the output matrices and vectors as well as Workspace used by LAPACK. This should be used when the user doesn't care much about where the output should be stored and doesn't need to share the workspace between different algorithms.
| m,n | Dimension of the matrix to be decomposed. | |
| storageOrder | Storage order used for all matrices. |
Definition at line 415 of file nmrSVDEconomy.h.
References Allocate().
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A | ) | [inline] |
Constructor where the user provides the input matrix to specify the size and storage order. Memory allocation is performed for the output matrices and vectors as well as Workspace used by LAPACK. This should be used when the user doesn't care much about where the output should be stored and doesn't need to share the workspace between different algorithms.
| A | input matrix |
Definition at line 433 of file nmrSVDEconomy.h.
References Allocate().
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A, | |
| vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & | inWorkspace | |||
| ) | [inline] |
Constructor where the user provides the input matrix to specify the size and storage order. Memory allocation is performed for the output matrices and vectors only. This constructor should be used when the user cares wants to avoid allocating different workspaces for different numerical routines. Please note that since multiple routines can share the workspace, these routines must be called in a thread safe manner.
| A | input matrix | |
| inWorkspace | workspace |
Definition at line 453 of file nmrSVDEconomy.h.
References SetRefWorkspace().
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > & | inU, | |
| vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | inS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > & | inVt, | |||
| vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & | inWorkspace | |||
| ) | [inline] |
Constructor where the user provides the matrices U, Vt and vectors S as well as the workspace. The data object now acts as a composite container to hold, pass and manipulate a convenient storage for SVD algorithm. Checks are made on the validity of the input and its consitency in terms of size ans storage order. Please note that since the workspace and the input are now created by the user, special attention must be given to thread safety issues.
| inU,inS,inVt | The output matrices and vector | |
| inWorkspace | The workspace for LAPACK. |
Definition at line 477 of file nmrSVDEconomy.h.
References SetRef().
| nmrSVDEconomyDynamicData::nmrSVDEconomyDynamicData | ( | vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > & | inU, | |
| vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | inS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > & | inVt | |||
| ) | [inline] |
Constructor where the user provides the matrices U, Vt and vectors S. The workspace will be allocated and managed by the "data". This constructor should be used when the user already has a storage for the data but doesn't care much about the workspace.
| inU,inS,inVt | The output matrices and vector |
Definition at line 498 of file nmrSVDEconomy.h.
References SetRefOutput().
| void nmrSVDEconomyDynamicData::SetDimension | ( | size_type | m, | |
| size_type | n, | |||
| bool | storageOrder | |||
| ) | [inline, protected] |
Private method to set the data members MMember, NMember and StorageOrder. This method must be called before AllocateOutputWorkspace, ThrowUnlessOutputSizeIsCorrect or ThrowUnlessWorkspaceSizeIsCorrect.
Definition at line 155 of file nmrSVDEconomy.h.
References MMember, NMember, and StorageOrderMember.
Referenced by Allocate(), SetRef(), SetRefOutput(), and SetRefWorkspace().
| void nmrSVDEconomyDynamicData::AllocateOutputWorkspace | ( | bool | allocateOutput, | |
| bool | allocateWorkspace | |||
| ) | [inline, protected] |
Private method to allocate memory for the output and the workspace if needed. This method assumes that the dimension m and n as well as the storage order are already set. It is important to use this method in all the methods provided in the user API, even if all the memory is provided by the user since this method will ensure that the "data" (nmrSVDEconomyDynamicData) does not keep any memory allocated. This is for the case where a single "data" is used first to allocate everything and, later on, used with user allocated memory (for either the workspace or the output). For example:
vctDynamicMatrix<CISSTNETLIB_DOUBLE> A(20, 20); vctRandom(A, 10, 10); nmrSVDEconomyDynamicData data(A); // allocate output AND workspace vctDynamicVector<CISSTNETLIB_DOUBLE> workspace(nmrSVDEconomyDynamicData::WorkspaceSize(A)); data.SetRefWorkspace(workspace); // after all, use my own workspace
Definition at line 181 of file nmrSVDEconomy.h.
References MMember, NMember, OutputMemory, vctDynamicMatrixRef< _elementType >::SetRef(), vctDynamicVectorRef< _elementType >::SetRef(), vctDynamicVector< _elementType >::SetSize(), SReference, StorageOrderMember, UReference, VtReference, WorkspaceMemory, WorkspaceReference, and WorkspaceSize().
Referenced by Allocate(), nmrSVDEconomyDynamicData(), SetRef(), SetRefOutput(), and SetRefWorkspace().
| void nmrSVDEconomyDynamicData::ThrowUnlessOutputSizeIsCorrect | ( | vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > & | inU, | |
| vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | inS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > & | inVt | |||
| ) | const throw (std::runtime_error) [inline, protected] |
Verifies that the user provided references for the output match the size of the "data" as set by SetDimension. This method also checks that the storage orders are consistent across the provided matrices and that all containers are compact.
Definition at line 221 of file nmrSVDEconomy.h.
References cmnThrow(), MMember, NMember, and StorageOrderMember.
Referenced by SetRef(), and SetRefOutput().
| void nmrSVDEconomyDynamicData::ThrowUnlessWorkspaceSizeIsCorrect | ( | vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & | inWorkspace | ) | const throw (std::runtime_error) [inline, protected] |
Verifies that the user provided references for the workspace match (or is greated than) the size of the "data" as set by SetDimension. This method also checks that the workspace is compact.
Definition at line 264 of file nmrSVDEconomy.h.
References cmnThrow(), MMember, NMember, and WorkspaceSize().
Referenced by SetRef(), and SetRefWorkspace().
| static size_type nmrSVDEconomyDynamicData::WorkspaceSize | ( | size_type | m, | |
| size_type | n | |||
| ) | [inline, static] |
Helper methods for user to set minimum working space required by LAPACK SVD routine.
| m,n | The size of matrix whose SVD needs to be computed. |
Definition at line 284 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), nmrSVDEconomy(), nmrPInverseEconomyDynamicData::SetRefSVD(), nmrPInverseEconomyDynamicData::ThrowUnlessWorkspaceSizeIsCorrect(), ThrowUnlessWorkspaceSizeIsCorrect(), and WorkspaceSize().
| static size_type nmrSVDEconomyDynamicData::WorkspaceSize | ( | vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | inA | ) | [inline, static] |
Helper method to determine the minimum working space required by LAPACK SVD routine.
| inA | The matrix whose SVD needs to be computed |
Definition at line 299 of file nmrSVDEconomy.h.
References vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::cols(), vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::rows(), and WorkspaceSize().
| static nsize_type nmrSVDEconomyDynamicData::MatrixSSize | ( | const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A | ) | [inline, static] |
Helper method to compute the size of the matrix S. This method can be used before UpdateMatrixS to make sure that the size of S is correct.
| A | The matrix to be decomposed using nmrSVDEconomy (it is used only to determine the sizes). |
Definition at line 314 of file nmrSVDEconomy.h.
References vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::cols(), and vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::rows().
| static vctDynamicMatrixBase<_matrixOwnerTypeS, CISSTNETLIB_DOUBLE>& nmrSVDEconomyDynamicData::UpdateMatrixS | ( | const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A, | |
| const vctDynamicConstVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | vectorS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeS, CISSTNETLIB_DOUBLE > & | matrixS | |||
| ) | throw (std::runtime_error) [inline, static] |
Fill a matrix from the singular values. Sets all the elements to zero and then replace the diagonal by the singular values (provided by vectorS).
| A | Matrix decomposed using nmrSVDEconomy. This is required to check the dimension of matrixS. | |
| vectorS | Vector of singular values as computed by nmrSVDEconomy. | |
| matrixS | Matrix with storage provided by the user. It must have the same size as A. |
Definition at line 332 of file nmrSVDEconomy.h.
References cmnThrow().
| void nmrSVDEconomyDynamicData::Allocate | ( | vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A | ) | [inline] |
This method allocates memory for the output matrices and vector as well as the workspace. The input matrix is used only to determine the size of the problem as well as the storage order (i.e. VCT_ROW_MAJOR or VCT_COL_MAJOR).
This method should be called before the nmrSVDEconomyDynamicData object is passed on to nmrSVDEconomy function.
| A | The matrix for which SVD needs to be computed, size MxN |
Definition at line 517 of file nmrSVDEconomy.h.
References vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::cols(), vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::rows(), and vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::StorageOrder().
Referenced by nmrSVDEconomyDynamicData().
| void nmrSVDEconomyDynamicData::SetRefWorkspace | ( | vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > & | A, | |
| vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & | inWorkspace | |||
| ) | [inline] |
This method allocates the memory for the output matrices and vector and uses the memory provided by user for workspace. The input matrix A is used to determine the size of the problem as well as the storage order.
This method verifies that the workspace provided by the user is large enough and is compact.
| A | The matrix for which SVD needs to be computed, size MxN. | |
| inWorkspace | The vector used for workspace by LAPACK. |
Definition at line 534 of file nmrSVDEconomy.h.
References AllocateOutputWorkspace(), vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::cols(), vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::rows(), SetDimension(), vctDynamicVectorRef< _elementType >::SetRef(), vctDynamicConstMatrixBase< _matrixOwnerType, _elementType >::StorageOrder(), ThrowUnlessWorkspaceSizeIsCorrect(), and WorkspaceReference.
Referenced by nmrSVDEconomyDynamicData().
This method allocates the memory for the output matrices and vector as well as the workspace. This method is not meant to be a top-level user API, but is used by other overloaded Allocate methods.
| m | Number of rows of input matrix A. | |
| n | Number of cols of input matrix A. | |
| storageOrder | Storage order of input matrix. One of VCT_COL_MAJOR or VCT_ROW_MAJOR. |
Definition at line 557 of file nmrSVDEconomy.h.
References AllocateOutputWorkspace(), and SetDimension().
| void nmrSVDEconomyDynamicData::SetRef | ( | vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > & | inU, | |
| vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | inS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > & | inVt, | |||
| vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > & | inWorkspace | |||
| ) | throw (std::runtime_error) [inline] |
This method doesn't allocate any memory as it relies on user provided matrices and vectors for the output as well as the workspace.
The data object now acts as a composite container to hold, pass and manipulate a convenient storage for SVD algorithm. The method tests that all the containers provided by the user have the correct size, storage order and are compact.
| inU,inS,inVt | The output matrices and vector. | |
| inWorkspace | The workspace. |
Definition at line 579 of file nmrSVDEconomy.h.
References AllocateOutputWorkspace(), SetDimension(), vctDynamicMatrixRef< _elementType >::SetRef(), vctDynamicVectorRef< _elementType >::SetRef(), SReference, ThrowUnlessOutputSizeIsCorrect(), ThrowUnlessWorkspaceSizeIsCorrect(), UReference, VtReference, and WorkspaceReference.
Referenced by nmrSVDEconomyDynamicData().
| void nmrSVDEconomyDynamicData::SetRefOutput | ( | vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > & | inU, | |
| vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > & | inS, | |||
| vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > & | inVt | |||
| ) | throw (std::runtime_error) [inline] |
This method allocates the memory for the workspace. The output memory is provided by the user. The method computes the size of the problem based on the user provided output and verifies that the output components (inU, inS, and inVt) are consistent with respect to their size and storage order.
| inU,inS,inVt | The output matrices and vector. |
Definition at line 607 of file nmrSVDEconomy.h.
References AllocateOutputWorkspace(), SetDimension(), vctDynamicMatrixRef< _elementType >::SetRef(), vctDynamicVectorRef< _elementType >::SetRef(), SReference, ThrowUnlessOutputSizeIsCorrect(), UReference, and VtReference.
Referenced by nmrSVDEconomyDynamicData().
| const vctDynamicVectorRef<CISSTNETLIB_DOUBLE>& nmrSVDEconomyDynamicData::S | ( | void | ) | const [inline] |
Const reference to the result vector S. This method must be called after the data has been computed by the nmrSVDEconomy function.
Definition at line 625 of file nmrSVDEconomy.h.
References SReference.
| const vctDynamicMatrixRef<CISSTNETLIB_DOUBLE>& nmrSVDEconomyDynamicData::U | ( | void | ) | const [inline] |
Const reference to the result matrix U. This method must be called after the data has been computed by the nmrSVDEconomy function.
Definition at line 632 of file nmrSVDEconomy.h.
References UReference.
| const vctDynamicMatrixRef<CISSTNETLIB_DOUBLE>& nmrSVDEconomyDynamicData::Vt | ( | void | ) | const [inline] |
Const reference to the result matrix Vt (V transposed). This method must be called after the data has been computed by the nmrSVDEconomy function.
Definition at line 638 of file nmrSVDEconomy.h.
References VtReference.
vctDynamicVector<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::WorkspaceMemory [protected] |
Memory allocated for Workspace matrices if needed.
Definition at line 123 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace().
vctDynamicVector<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::OutputMemory [protected] |
Memory allocated for U, Vt Matrices and Vector S if needed. This method allocates a single block of memory for these 3 containers; m x m elements of U followed by n x n elements of Vt followed by min (m, n) elements of S.
Definition at line 130 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace().
vctDynamicMatrixRef<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::UReference [protected] |
References to workspace or return types, these point either to user allocated memory or our memory chunks if needed.
Definition at line 136 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetRef(), SetRefOutput(), and U().
vctDynamicMatrixRef<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::VtReference [protected] |
References to workspace or return types, these point either to user allocated memory or our memory chunks if needed.
Definition at line 137 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetRef(), SetRefOutput(), and Vt().
vctDynamicVectorRef<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::SReference [protected] |
References to workspace or return types, these point either to user allocated memory or our memory chunks if needed.
Definition at line 138 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), S(), SetRef(), and SetRefOutput().
vctDynamicVectorRef<CISSTNETLIB_DOUBLE> nmrSVDEconomyDynamicData::WorkspaceReference [protected] |
References to workspace or return types, these point either to user allocated memory or our memory chunks if needed.
Definition at line 139 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetRef(), and SetRefWorkspace().
size_type nmrSVDEconomyDynamicData::MMember [protected] |
Just store M, N, and StorageOrder which are needed to check if A matrix passed to solve method matches the allocated size.
Definition at line 146 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetDimension(), ThrowUnlessOutputSizeIsCorrect(), and ThrowUnlessWorkspaceSizeIsCorrect().
size_type nmrSVDEconomyDynamicData::NMember [protected] |
Just store M, N, and StorageOrder which are needed to check if A matrix passed to solve method matches the allocated size.
Definition at line 147 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetDimension(), ThrowUnlessOutputSizeIsCorrect(), and ThrowUnlessWorkspaceSizeIsCorrect().
bool nmrSVDEconomyDynamicData::StorageOrderMember [protected] |
Just store M, N, and StorageOrder which are needed to check if A matrix passed to solve method matches the allocated size.
Definition at line 148 of file nmrSVDEconomy.h.
Referenced by AllocateOutputWorkspace(), SetDimension(), and ThrowUnlessOutputSizeIsCorrect().