115 if (allocateOutput) {
125 if (allocateWorkspace) {
129 this->WorkspaceMemory.SetSize(0);
140 template <
class _vectorOwnerTypeWorkspace>
172 template <
typename _matrixOwnerTypePInverse>
177 if ((
MMember != pInverse.cols()) || (
NMember != pInverse.rows())) {
178 cmnThrow(std::runtime_error(
"nmrPInverseDynamicData: Size of matrix pInverse is incorrect."));
181 cmnThrow(std::runtime_error(
"nmrPInverseDynamicData: Storage order of pInverse is incorrect."));
192 template <
typename _vectorOwnerTypeWorkspace>
198 if (lwork > workspace.size()) {
199 cmnThrow(std::runtime_error(
"nmrPInverseDynamicData: Workspace is too small."));
201 if (!workspace.IsCompact()) {
202 cmnThrow(std::runtime_error(
"nmrPInverseDynamicData: Workspace must be compact."));
217 const size_type lwork_1 = 3 * minmn + maxmn;
219 const size_type lwork = (lwork_1 > lwork_2) ? lwork_1 : lwork_2;
221 return m * m + n * n + minmn + lwork + n * m;
229 template <
class _matrixOwnerTypeA>
250 return Data.SReference;
253 return Data.PInverseReference;
256 return Data.UReference;
259 return Data.VtReference;
262 return Data.WorkspaceReference;
271 return Data.StorageOrderMember;
300 template <
class _matrixOwnerTypeA>
303 this->
Allocate(A.rows(), A.cols(), A.StorageOrder());
315 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
331 template <
class _matrixOwnerTypeA,
332 class _matrixOwnerTypePInverse,
333 class _vectorOwnerTypeWorkspace>
338 this->
SetRef(pInverse, workspace);
352 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse>
371 template <
class _matrixOwnerTypeA>
374 this->
SetDimension(A.rows(), A.cols(), A.StorageOrder());
397 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
401 this->
SetDimension(A.rows(), A.cols(), A.StorageOrder());
418 template <
class _matrixOwnerTypePInverse,
419 class _vectorOwnerTypeWorkspace>
423 this->
SetDimension(pInverse.cols(), pInverse.rows(), pInverse.StorageOrder());
427 this->PInverseReference.
SetRef(pInverse);
447 template <
class _matrixOwnerTypePInverse>
450 this->
SetDimension(pInverse.cols(), pInverse.rows(), pInverse.StorageOrder());
453 this->PInverseReference.
SetRef(pInverse);
496template <vct::
size_type _rows, vct::
size_type _cols,
bool _storageOrder>
502 enum {
MIN_MN = (_rows < _cols) ? _rows : _cols};
568 return Data.PInverseMember;
571 return Data.SReference;
574 return Data.UReference;
577 return Data.VtReference;
580 return Data.WorkspaceMember;
583 return Data.PReference;
594 UReference(WorkspaceMember.
Pointer(0)),
595 VtReference(WorkspaceMember.
Pointer(_rows * _rows)),
596 SReference(WorkspaceMember.
Pointer(_rows * _rows + _cols * _cols)),
597 SVDWorkspaceReference(WorkspaceMember.
Pointer(_rows * _rows + _cols * _cols +
MIN_MN)),
610 return PInverseMember;
783template <
class _matrixOwnerType>
789 CISSTNETLIB_INTEGER ret_value;
792 cmnThrow(std::runtime_error(
"nmrPInverse Solve: Storage order used for Allocate was different"));
794 if ((A.rows() != dataFriend.
M()) || (A.cols() != dataFriend.
N())) {
795 cmnThrow(std::runtime_error(
"nmrPInverse Solve: Size used for Allocate was different"));
797 const size_type
rows = A.rows();
798 const size_type
cols = A.cols();
802 ret_value =
nmrSVD(A, dataFriend.
U(), dataFriend.
S(),
807 CISSTNETLIB_DOUBLE singularValue;
808 size_type irank, i, j;
809 for (irank = 0; irank < minmn; irank++) {
810 if ((singularValue = dataFriend.
S().
at(irank)) > eps) {
811 for (j = 0; j <
rows; j++) {
812 for (i = 0; i <
cols; i++) {
814 + dataFriend.
Vt().
at(irank, i) * dataFriend.
U().
at(j, irank) / singularValue;
839template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse,
class _vectorOwnerTypeWorkspace>
844 CISSTNETLIB_INTEGER ret_value =
nmrPInverse(A, svdData);
863template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse>
868 CISSTNETLIB_INTEGER ret_value =
nmrPInverse(A, svdData);
891template <vct::
size_type _rows, vct::
size_type _cols, vct::
size_type _work,
bool _storageOrder,
class _dataPtrType>
897#if CMN_ASSERT_IS_DEFINED
902 const size_type maxmn = (_rows > _cols) ? _rows : _cols;
910 (_storageOrder) ? _rows : 1,
911 (_storageOrder) ? 1 : _rows,
914 (_storageOrder) ? _cols : 1,
915 (_storageOrder) ? 1 : _cols,
916 workspace.
Pointer(_rows*_rows));
918 workspace.
Pointer(_rows * _rows + _cols * _cols));
920 workspace.
Pointer(_rows * _rows + _cols * _cols + minmn));
922 workspace.
Pointer(_rows * _rows + _cols * _cols + minmn + lwork_3));
924 CISSTNETLIB_INTEGER ret_value;
925 ret_value =
nmrSVD(ARef, URef, SRef, VtRef, SVDWorkspaceRef);
939 for (irank = 0; irank < minmn; irank++) {
940 if (SRef(irank) > eps) {
941 PRef.
Row(irank).ProductOf(URef.Transpose().
Row(irank), 1.0/SRef(irank));
943 PRef.
Row(irank).SetAll(0.);
946 pInverseRef.
ProductOf(VtRef.Transpose(), PRef);
966template <vct::
size_type _rows, vct::
size_type _cols,
bool _storageOrder>
971 CISSTNETLIB_INTEGER ret_value =
nmrPInverse(A, pInverse, workspace);
995template <vct::
size_type _rows, vct::
size_type _cols,
bool _storageOrder>
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Definition nmrPInverse.h:243
size_type N(void)
Definition nmrPInverse.h:267
size_type M(void)
Definition nmrPInverse.h:264
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void)
Definition nmrPInverse.h:255
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void)
Definition nmrPInverse.h:252
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void)
Definition nmrPInverse.h:258
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & Workspace(void)
Definition nmrPInverse.h:261
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void)
Definition nmrPInverse.h:249
bool StorageOrder(void)
Definition nmrPInverse.h:270
Friend(nmrPInverseDynamicData &data)
Definition nmrPInverse.h:247
Definition nmrPInverse.h:46
void SetRef(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverse.h:420
vct::size_type size_type
Definition nmrPInverse.h:54
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > PInverseReference
Definition nmrPInverse.h:73
const vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void) const
Definition nmrPInverse.h:467
size_type NMember
Definition nmrPInverse.h:84
void SetRefWorkspace(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverse.h:398
nmrPInverseDynamicData()
Definition nmrPInverse.h:284
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void) const
Definition nmrPInverse.h:473
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > UReference
Definition nmrPInverse.h:74
void AllocateOutputWorkspace(bool allocateOutput, bool allocateWorkspace)
Definition nmrPInverse.h:112
void ThrowUnlessWorkspaceSizeIsCorrect(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace) const CISST_THROW(std
Definition nmrPInverse.h:194
void SetDimension(size_type m, size_type n, bool storageOrder)
Definition nmrPInverse.h:92
size_type MMember
Definition nmrPInverse.h:83
vctDynamicVector< CISSTNETLIB_DOUBLE > WorkspaceMemory
Definition nmrPInverse.h:64
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > SReference
Definition nmrPInverse.h:76
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > VtReference
Definition nmrPInverse.h:75
void SetRefOutput(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition nmrPInverse.h:448
nmrPInverseDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverse.h:334
static size_type WorkspaceSize(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverse.h:230
void Allocate(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverse.h:372
bool StorageOrderMember
Definition nmrPInverse.h:85
void SetRefSVD(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverse.h:141
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void) const
Definition nmrPInverse.h:476
nmrPInverseDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition nmrPInverse.h:353
void ThrowUnlessOutputSizeIsCorrect(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse) const CISST_THROW(std
Definition nmrPInverse.h:173
nmrPInverseDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverse.h:301
vctDynamicVector< CISSTNETLIB_DOUBLE > OutputMemory
Definition nmrPInverse.h:68
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void) const
Definition nmrPInverse.h:470
nmrPInverseDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverse.h:316
static size_type WorkspaceSize(size_type m, size_type n)
Definition nmrPInverse.h:213
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > WorkspaceReference
Definition nmrPInverse.h:77
Definition nmrPInverse.h:561
MatrixTypePInverse & PInverse(void)
Definition nmrPInverse.h:567
MatrixTypeP & P(void)
Definition nmrPInverse.h:582
VectorTypeS & S(void)
Definition nmrPInverse.h:570
MatrixTypeU & U(void)
Definition nmrPInverse.h:573
MatrixTypeVt & Vt(void)
Definition nmrPInverse.h:576
Friend(nmrPInverseFixedSizeData< _rows, _cols, _storageOrder > &data)
Definition nmrPInverse.h:565
VectorTypeWorkspace & Workspace(void)
Definition nmrPInverse.h:579
Definition nmrPInverse.h:498
vct::size_type size_type
Definition nmrPInverse.h:500
@ LWORK_1
Definition nmrPInverse.h:503
@ LWORK_3
Definition nmrPInverse.h:505
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, _storageOrder > MatrixTypeA
Definition nmrPInverse.h:515
const MatrixTypeU & U(void) const
Definition nmrPInverse.h:615
nmrPInverseFixedSizeData()
Definition nmrPInverse.h:593
const VectorTypeS & S(void) const
Definition nmrPInverse.h:612
vctFixedSizeVectorRef< CISSTNETLIB_DOUBLE, MIN_MN, 1 > VectorTypeS
Definition nmrPInverse.h:525
vctFixedSizeMatrixRef< CISSTNETLIB_DOUBLE, _cols, _cols, _storageOrder ? _cols :1, _storageOrder ? 1 :_cols > MatrixTypeVt
Definition nmrPInverse.h:523
@ LWORK
Definition nmrPInverse.h:511
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _cols, _rows, _storageOrder > MatrixTypePInverse
Definition nmrPInverse.h:517
const MatrixTypePInverse & PInverse(void) const
Definition nmrPInverse.h:609
vctFixedSizeVector< CISSTNETLIB_DOUBLE, LWORK > VectorTypeWorkspace
Definition nmrPInverse.h:519
const MatrixTypeP & P(void) const
Definition nmrPInverse.h:621
@ MIN_MN
Definition nmrPInverse.h:502
vctFixedSizeMatrixRef< CISSTNETLIB_DOUBLE, _cols, _rows, _storageOrder? _cols :1, _storageOrder ? 1 :_rows > MatrixTypeP
Definition nmrPInverse.h:528
const MatrixTypeVt & Vt(void) const
Definition nmrPInverse.h:618
@ LWORK_2
Definition nmrPInverse.h:504
vctFixedSizeVectorRef< CISSTNETLIB_DOUBLE, LWORK_3, 1 > VectorTypeSVDWorkspace
Definition nmrPInverse.h:527
vctFixedSizeMatrixRef< CISSTNETLIB_DOUBLE, _rows, _rows, _storageOrder ? _rows :1, _storageOrder ? 1 :_rows > MatrixTypeU
Definition nmrPInverse.h:521
static size_type WorkspaceSize(size_type m, size_type n)
Definition nmrSVD.h:296
Definition vctDynamicMatrixBase.h:43
RowRefType Row(size_type index) CISST_THROW(std
Definition vctDynamicMatrixBase.h:227
reference at(size_type index) CISST_THROW(std
Definition vctDynamicMatrixBase.h:171
value_type SetAll(const value_type value)
Definition vctDynamicMatrixBase.h:452
ThisType & ProductOf(const vctDynamicConstMatrixBase< __matrixOwnerType, _elementType > &matrix, const value_type scalar)
Definition vctDynamicMatrixBase.h:971
Dynamic matrix referencing existing memory.
Definition vctDynamicMatrixRef.h:75
void SetRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition vctDynamicMatrixRef.h:217
Definition vctDynamicVectorBase.h:62
pointer Pointer(index_type index=0)
Definition vctDynamicVectorBase.h:155
reference at(index_type index) CISST_THROW(std
Definition vctDynamicVectorBase.h:170
Definition vctForwardDeclarations.h:131
Dynamic vector referencing existing memory.
Definition vctDynamicVectorRef.h:78
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition vctDynamicVectorRef.h:156
Implementation of a fixed-size matrix using template metaprogramming.
Definition vctFixedSizeMatrix.h:54
Definition vctForwardDeclarations.h:110
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
pointer Pointer(size_type index=0)
Definition vctFixedSizeVectorBase.h:226
Implementation of a fixed-size vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
Definition vctForwardDeclarations.h:89
#define CMN_ASSERT(expr)
Definition cmnAssert.h:97
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of the template function cmnThrow.
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
size_t size_type
Definition vctContainerTraits.h:35
CISSTNETLIB_INTEGER nmrPInverse(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrPInverseDynamicData &data) CISST_THROW(std
Definition nmrPInverse.h:784
CISSTNETLIB_INTEGER nmrSVD(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrSVDDynamicData &data) CISST_THROW(std
Definition nmrSVD.h:998
size_type cols() const
Definition vctDynamicConstMatrixBase.h:243
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition vctDynamicConstMatrixBase.h:306
size_type rows() const
Definition vctDynamicConstMatrixBase.h:238
Declaration of vctDynamicMatrix.
Declaration of vctFixedSizeMatrix.
const bool VCT_COL_MAJOR
Definition vctForwardDeclarations.h:44