26#ifndef _nmrPInverseEconomy_h
27#define _nmrPInverseEconomy_h
197 if (allocateOutput) {
207 if (allocateWorkspace) {
211 this->WorkspaceMemory.SetSize(0);
222 template <
class _vectorOwnerTypeWorkspace>
254 template <
typename _matrixOwnerTypePInverse>
259 if ((
MMember != pInverse.cols()) || (
NMember != pInverse.rows())) {
260 cmnThrow(std::runtime_error(
"nmrPInverseEconomyDynamicData: Size of matrix pInverse is incorrect."));
263 cmnThrow(std::runtime_error(
"nmrPInverseEconomyDynamicData: Storage order of pInverse is incorrect."));
274 template <
typename _vectorOwnerTypeWorkspace>
280 if (lwork > workspace.size()) {
281 cmnThrow(std::runtime_error(
"nmrPInverseEconomyDynamicData: Workspace is too small."));
283 if (!workspace.IsCompact()) {
284 cmnThrow(std::runtime_error(
"nmrPInverseEconomyDynamicData: Workspace must be compact."));
299 const size_type lwork_1 = 3 * minmn + maxmn;
301 const size_type lwork = (lwork_1 > lwork_2) ? lwork_1 : lwork_2;
303 return m * minmn + n * n + minmn + lwork;
311 template <
class _matrixOwnerTypeA>
332 return Data.SReference;
335 return Data.PInverseReference;
338 return Data.UReference;
341 return Data.VtReference;
344 return Data.WorkspaceReference;
353 return Data.StorageOrderMember;
383 template <
class _matrixOwnerTypeA>
386 this->
Allocate(A.rows(), A.cols(), A.StorageOrder());
400 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
418 template <
class _matrixOwnerTypeA,
419 class _matrixOwnerTypePInverse,
420 class _vectorOwnerTypeWorkspace>
425 this->
SetRef(pInverse, workspace);
441 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse>
460 template <
class _matrixOwnerTypeA>
463 this->
SetDimension(A.rows(), A.cols(), A.StorageOrder());
486 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
490 this->
SetDimension(A.rows(), A.cols(), A.StorageOrder());
508 template <
class _matrixOwnerTypePInverse,
509 class _vectorOwnerTypeWorkspace>
513 this->
SetDimension(pInverse.cols(), pInverse.rows(), pInverse.StorageOrder());
517 this->PInverseReference.
SetRef(pInverse);
537 template <
class _matrixOwnerTypePInverse>
540 this->
SetDimension(pInverse.cols(), pInverse.rows(), pInverse.StorageOrder());
543 this->PInverseReference.
SetRef(pInverse);
589template <
class _matrixOwnerType>
593 typedef unsigned int size_type;
596 CISSTNETLIB_INTEGER ret_value;
599 cmnThrow(std::runtime_error(
"nmrPInverseEconomy Solve: Storage order used for Allocate was different"));
601 if ((A.rows() != dataFriend.
M()) || (A.cols() != dataFriend.
N())) {
602 cmnThrow(std::runtime_error(
"nmrPInverseEconomy Solve: Size used for Allocate was different"));
604 const size_type
rows = A.rows();
605 const size_type
cols = A.cols();
613 CISSTNETLIB_DOUBLE singularValue;
614 size_type irank, i, j;
615 for (irank = 0; irank < minmn; irank++) {
616 if ((singularValue = dataFriend.
S().
at(irank)) > eps) {
617 for (j = 0; j <
rows; j++) {
618 for (i = 0; i <
cols; i++) {
620 + dataFriend.
Vt().
at(irank, i) * dataFriend.
U().
at(j, irank) / singularValue;
645template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse,
class _vectorOwnerTypeWorkspace>
668template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse>
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Definition nmrPInverseEconomy.h:325
size_type M(void)
Definition nmrPInverseEconomy.h:346
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void)
Definition nmrPInverseEconomy.h:331
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void)
Definition nmrPInverseEconomy.h:340
Friend(nmrPInverseEconomyDynamicData &data)
Definition nmrPInverseEconomy.h:329
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & Workspace(void)
Definition nmrPInverseEconomy.h:343
bool StorageOrder(void)
Definition nmrPInverseEconomy.h:352
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void)
Definition nmrPInverseEconomy.h:337
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void)
Definition nmrPInverseEconomy.h:334
size_type N(void)
Definition nmrPInverseEconomy.h:349
Definition nmrPInverseEconomy.h:128
static size_type WorkspaceSize(size_type m, size_type n)
Definition nmrPInverseEconomy.h:295
void AllocateOutputWorkspace(bool allocateOutput, bool allocateWorkspace)
Definition nmrPInverseEconomy.h:194
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > WorkspaceReference
Definition nmrPInverseEconomy.h:159
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition nmrPInverseEconomy.h:442
unsigned int size_type
Definition nmrPInverseEconomy.h:136
void SetRefWorkspace(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverseEconomy.h:487
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > PInverseReference
Definition nmrPInverseEconomy.h:155
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > VtReference
Definition nmrPInverseEconomy.h:157
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > SReference
Definition nmrPInverseEconomy.h:158
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverseEconomy.h:421
const vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void) const
Definition nmrPInverseEconomy.h:557
size_type MMember
Definition nmrPInverseEconomy.h:165
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverseEconomy.h:401
vctDynamicVector< CISSTNETLIB_DOUBLE > WorkspaceMemory
Definition nmrPInverseEconomy.h:146
nmrPInverseEconomyDynamicData()
Definition nmrPInverseEconomy.h:366
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void) const
Definition nmrPInverseEconomy.h:566
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void) const
Definition nmrPInverseEconomy.h:563
size_type NMember
Definition nmrPInverseEconomy.h:166
void SetDimension(size_type m, size_type n, bool storageOrder)
Definition nmrPInverseEconomy.h:174
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverseEconomy.h:384
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > UReference
Definition nmrPInverseEconomy.h:156
void Allocate(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverseEconomy.h:461
vctDynamicVector< CISSTNETLIB_DOUBLE > OutputMemory
Definition nmrPInverseEconomy.h:150
void ThrowUnlessWorkspaceSizeIsCorrect(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace) const CISST_THROW(std
Definition nmrPInverseEconomy.h:276
void SetRef(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverseEconomy.h:510
bool StorageOrderMember
Definition nmrPInverseEconomy.h:167
void SetRefSVD(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition nmrPInverseEconomy.h:223
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void) const
Definition nmrPInverseEconomy.h:560
static size_type WorkspaceSize(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrPInverseEconomy.h:312
void ThrowUnlessOutputSizeIsCorrect(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse) const CISST_THROW(std
Definition nmrPInverseEconomy.h:255
void SetRefOutput(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition nmrPInverseEconomy.h:538
static size_type WorkspaceSize(size_type m, size_type n)
Definition nmrSVDEconomy.h:281
Definition vctDynamicMatrixBase.h:43
reference at(size_type index) CISST_THROW(std
Definition vctDynamicMatrixBase.h:171
value_type SetAll(const value_type value)
Definition vctDynamicMatrixBase.h:452
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
#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
CISSTNETLIB_INTEGER nmrPInverseEconomy(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrPInverseEconomyDynamicData &data) CISST_THROW(std
Definition nmrPInverseEconomy.h:590
Declaration of nmrSVDEconomy.
CISSTNETLIB_INTEGER nmrSVDEconomy(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrSVDEconomyDynamicData &data) CISST_THROW(std
Definition nmrSVDEconomy.h:800
size_type cols() const
Definition vctDynamicConstMatrixBase.h:243
size_type rows() const
Definition vctDynamicConstMatrixBase.h:238
Declaration of vctDynamicMatrix.
Declaration of vctFixedSizeMatrix.
const bool VCT_COL_MAJOR
Definition vctForwardDeclarations.h:44