26 #ifndef _nmrPInverseEconomy_h
27 #define _nmrPInverseEconomy_h
197 if (allocateOutput) {
207 if (allocateWorkspace) {
222 template <
class _vectorOwnerTypeWorkspace>
231 current += (MMember * minmn);
236 current += (NMember *
NMember);
254 template <
typename _matrixOwnerTypePInverse>
256 throw(std::runtime_error)
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>
277 throw(std::runtime_error)
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>
383 template <
class _matrixOwnerTypeA>
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>
486 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
508 template <
class _matrixOwnerTypePInverse,
509 class _vectorOwnerTypeWorkspace>
537 template <
class _matrixOwnerTypePInverse>
589 template <
class _matrixOwnerType>
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();
606 const size_type minmn = (rows < cols) ? rows : 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;
645 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse,
class _vectorOwnerTypeWorkspace>
668 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypePInverse>
void SetDimension(size_type m, size_type n, bool storageOrder)
Definition: nmrPInverseEconomy.h:174
const vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void) const
Definition: nmrPInverseEconomy.h:557
Declaration of vctDynamicMatrix.
Definition: vctDynamicMatrixBase.h:42
Definition: nmrPInverseEconomy.h:325
nmrPInverseEconomyDynamicData()
Definition: nmrPInverseEconomy.h:366
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > UReference
Definition: nmrPInverseEconomy.h:156
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
size_type MMember
Definition: nmrPInverseEconomy.h:165
static Type Tolerance(void)
Definition: cmnTypeTraits.h:170
Declaration of vctFixedSizeMatrix.
void ThrowUnlessWorkspaceSizeIsCorrect(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace) const
Definition: nmrPInverseEconomy.h:276
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void) const
Definition: nmrPInverseEconomy.h:560
size_t size_type
Definition: vctContainerTraits.h:35
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition: nmrPInverseEconomy.h:442
void ThrowUnlessOutputSizeIsCorrect(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse) const
Definition: nmrPInverseEconomy.h:255
bool StorageOrder(void) const
Definition: vctDynamicConstMatrixBase.h:656
unsigned int size_type
Definition: nmrPInverseEconomy.h:136
static size_type WorkspaceSize(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrPInverseEconomy.h:312
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition: vctDynamicVectorRef.h:156
bool StorageOrder(void)
Definition: nmrPInverseEconomy.h:352
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &CMN_UNUSED(A), vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition: nmrPInverseEconomy.h:421
void SetRefSVD(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition: nmrPInverseEconomy.h:223
vctDynamicVector< CISSTNETLIB_DOUBLE > OutputMemory
Definition: nmrPInverseEconomy.h:150
static size_type WorkspaceSize(size_type m, size_type n)
Definition: nmrSVDEconomy.h:282
void SetSize(size_type size)
Definition: vctDynamicVector.h:315
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > PInverseReference
Definition: nmrPInverseEconomy.h:155
CISSTNETLIB_INTEGER nmrPInverseEconomy(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrPInverseEconomyDynamicData &data)
Definition: nmrPInverseEconomy.h:590
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrPInverseEconomy.h:384
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > SReference
Definition: nmrPInverseEconomy.h:158
static size_type WorkspaceSize(size_type m, size_type n)
Definition: nmrPInverseEconomy.h:295
size_type NMember
Definition: nmrPInverseEconomy.h:166
void SetRef(size_type rows, size_type cols, stride_type rowStride, stride_type colStride, pointer dataPointer)
Definition: vctDynamicMatrixRef.h:217
bool StorageOrderMember
Definition: nmrPInverseEconomy.h:167
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void)
Definition: nmrPInverseEconomy.h:331
reference at(index_type index)
Definition: vctDynamicVectorBase.h:170
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void) const
Definition: nmrPInverseEconomy.h:563
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void)
Definition: nmrPInverseEconomy.h:334
size_type N(void)
Definition: nmrPInverseEconomy.h:349
value_type SetAll(const value_type value)
Definition: vctDynamicMatrixBase.h:452
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
void Allocate(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrPInverseEconomy.h:461
reference at(size_type index)
Definition: vctDynamicMatrixBase.h:171
vctDynamicVector< CISSTNETLIB_DOUBLE > WorkspaceMemory
Definition: nmrPInverseEconomy.h:146
size_type M(void)
Definition: nmrPInverseEconomy.h:346
#define cmnThrow(a)
Definition: MinimalCmn.h:4
void SetRefOutput(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse)
Definition: nmrPInverseEconomy.h:538
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
void SetRefWorkspace(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition: nmrPInverseEconomy.h:487
CISSTNETLIB_INTEGER nmrSVDEconomy(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrSVDEconomyDynamicData &data)
Definition: nmrSVDEconomy.h:801
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & Workspace(void)
Definition: nmrPInverseEconomy.h:343
Declaration of nmrSVDEconomy.
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > WorkspaceReference
Definition: nmrPInverseEconomy.h:159
Declaration of the template function cmnThrow.
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > VtReference
Definition: nmrPInverseEconomy.h:157
Definition: nmrPInverseEconomy.h:128
void AllocateOutputWorkspace(bool allocateOutput, bool allocateWorkspace)
Definition: nmrPInverseEconomy.h:194
const bool VCT_COL_MAJOR
Definition: vctForwardDeclarations.h:46
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void)
Definition: nmrPInverseEconomy.h:340
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & PInverse(void) const
Definition: nmrPInverseEconomy.h:566
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void)
Definition: nmrPInverseEconomy.h:337
Definition: vctDynamicVectorBase.h:61
Friend(nmrPInverseEconomyDynamicData &data)
Definition: nmrPInverseEconomy.h:329
nmrPInverseEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition: nmrPInverseEconomy.h:401
void SetRef(vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &pInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &workspace)
Definition: nmrPInverseEconomy.h:510