26#ifndef _nmrSVDEconomy_h
27#define _nmrSVDEconomy_h
181 if (allocateOutput) {
184 this->OutputMemory.SetSize(outputLength);
188 this->OutputMemory.Pointer(0));
192 this->OutputMemory.Pointer(
MMember * minmn));
193 this->SReference.
SetRef(minmn,
196 this->OutputMemory.SetSize(0);
199 if (allocateWorkspace) {
201 this->WorkspaceReference.
SetRef(this->WorkspaceMemory);
203 this->WorkspaceMemory.SetSize(0);
215 template <
typename _matrixOwnerTypeU,
216 typename _vectorOwnerTypeS,
217 typename _matrixOwnerTypeVt>
225 if ((inU.rows() !=
MMember ) || (inU.cols() != minmn)) {
226 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Size of matrix U is incorrect."));
229 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Storage order of U is incorrect."));
231 if (!inU.IsCompact()) {
232 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Matrix U must be compact."));
234 if (! inVt.IsSquare(
NMember)) {
235 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Size of matrix Vt is incorrect."));
238 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Storage order of Vt is incorrect."));
240 if (!inVt.IsCompact()) {
241 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Matrix Vt must be compact."));
243 if (minmn != inS.size()) {
244 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Size of vector S is incorrect."));
246 if (!inS.IsCompact()) {
247 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Vector S must be compact."));
259 template <
typename _vectorOwnerTypeWorkspace>
265 if (lwork > inWorkspace.size()) {
266 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Workspace is too small."));
268 if (!inWorkspace.IsCompact()) {
269 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData: Workspace must be compact."));
285 const size_type lwork_1 = 3 * minmn + maxmn;
287 return (lwork_1 > lwork_2) ? lwork_1 : lwork_2;
295 template <
class _matrixOwnerTypeA>
309 template <
class _matrixOwnerTypeA>
313 nsize_type matrixSize(A.rows(), (A.rows() < A.cols()) ? A.row() : A.cols());
326 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypeS,
class _vectorOwnerTypeS>
334 const size_type minmn = (A.rows() < A.cols()) ? A.rows() : A.cols();
335 if ((minmn != matrixS.rows()) || (minmn != matrixS.cols())) {
336 cmnThrow(std::runtime_error(
"nmrSVDEconomyDynamicData::UpdateMatrixS: Size of matrix S is incorrect."));
339 matrixS.Diagonal().Assign(vectorS);
358 return Data.SReference;
361 return Data.UReference;
364 return Data.VtReference;
367 return Data.WorkspaceReference;
376 return Data.StorageOrderMember;
429 template <
class _matrixOwnerTypeA>
449 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
470 template <
typename _matrixOwnerTypeU,
471 typename _vectorOwnerTypeS,
472 typename _matrixOwnerTypeVt,
473 typename _vectorOwnerTypeWorkspace>
479 this->
SetRef(inU, inS, inVt, inWorkspace);
492 template <
typename _matrixOwnerTypeU,
493 typename _vectorOwnerTypeS,
494 typename _matrixOwnerTypeVt>
513 template <
class _matrixOwnerTypeA>
516 this->
Allocate(A.rows(), A.cols(), A.StorageOrder());
530 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypeWorkspace>
534 this->
SetDimension(A.rows(), A.cols(), A.StorageOrder());
541 this->WorkspaceReference.
SetRef(inWorkspace);
572 template <
typename _matrixOwnerTypeU,
573 typename _vectorOwnerTypeS,
574 typename _matrixOwnerTypeVt,
575 typename _vectorOwnerTypeWorkspace>
582 this->
SetDimension(inU.rows(), inVt.rows(), inU.StorageOrder());
587 this->SReference.
SetRef(inS);
588 this->UReference.
SetRef(inU);
589 this->VtReference.
SetRef(inVt);
590 this->WorkspaceReference.
SetRef(inWorkspace);
602 template <
typename _matrixOwnerTypeU,
603 typename _vectorOwnerTypeS,
typename _matrixOwnerTypeVt>
609 this->
SetDimension(inU.rows(), inVt.rows(), inU.StorageOrder());
612 this->SReference.
SetRef(inS);
613 this->UReference.
SetRef(inU);
614 this->VtReference.
SetRef(inVt);
799template <
class _matrixOwnerType>
805 CISSTNETLIB_INTEGER Info;
812 cmnThrow(std::runtime_error(
"nmrSVDEconomy: Storage order used for Allocate was different"));
815 if ((dataFriend.
M() != A.rows()) || (dataFriend.
N() != A.cols())) {
816 cmnThrow(std::runtime_error(
"nmrSVDEconomy: Size used for Allocate was different"));
819 if (! A.IsCompact()) {
820 cmnThrow(std::runtime_error(
"nmrSVDEconomy: Requires a compact matrix"));
824 CISSTNETLIB_DOUBLE *UPtr, *VtPtr;
825 CISSTNETLIB_INTEGER m_Lda, m_Ldu, m_Ldvt;
827 if (A.IsColMajor()) {
828 m_Lda = (1 > dataFriend.
M()) ? 1 : dataFriend.
M();
829 m_Ldu = dataFriend.
M();
830 m_Ldvt = dataFriend.
N();
834 m_Lda = (1 > dataFriend.
N()) ? 1 : dataFriend.
N();
835 m_Ldu = dataFriend.
N();
836 m_Ldvt = dataFriend.
M();
843#if defined(CISSTNETLIB_VERSION)
844#if defined(CISSTNETLIB_VERSION_MAJOR)
845#if (CISSTNETLIB_VERSION_MAJOR >= 3)
846 cisstNetlib_dgesvd_(&m_Jobu, &m_Jobvt, &m_Ldu, &m_Ldvt,
847 A.Pointer(), &m_Lda, dataFriend.
S().
Pointer(),
853 dgesvd_(&m_Jobu, &m_Jobvt, &m_Ldu, &m_Ldvt,
854 A.Pointer(), &m_Lda, dataFriend.
S().
Pointer(),
860 ftnlen jobu_len = (ftnlen)1, jobvt_len = (ftnlen)1;
861 la_dzlapack_MP_sgesvd_nat(&m_Jobu, &m_Jobvt, &m_Ldu, &m_Ldvt,
862 A.Pointer(), &m_Lda, dataFriend.
S().
Pointer(),
866 jobu_len, jobvt_len);
887template <
class _matrixOwnerTypeA,
class _matrixOwnerTypeU,
888 class _vectorOwnerTypeS,
class _matrixOwnerTypeVt,
889 class _vectorOwnerTypeWorkspace>
921template <
class _matrixOwnerTypeA,
class _matrixOwnerTypeU,
922 class _vectorOwnerTypeS,
class _matrixOwnerTypeVt>
Definition nmrSVDEconomy.h:351
size_type M(void)
Definition nmrSVDEconomy.h:369
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void)
Definition nmrSVDEconomy.h:357
bool StorageOrder(void)
Definition nmrSVDEconomy.h:375
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & Workspace(void)
Definition nmrSVDEconomy.h:366
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void)
Definition nmrSVDEconomy.h:363
Friend(nmrSVDEconomyDynamicData &inData)
Definition nmrSVDEconomy.h:355
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void)
Definition nmrSVDEconomy.h:360
size_type N(void)
Definition nmrSVDEconomy.h:372
Data for SVD problem (Dynamic).
Definition nmrSVDEconomy.h:104
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > WorkspaceReference
Definition nmrSVDEconomy.h:136
nmrSVDEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &inU, vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &inS, vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > &inVt)
Definition nmrSVDEconomy.h:495
void SetRefOutput(vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &inU, vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &inS, vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > &inVt) CISST_THROW(std
Definition nmrSVDEconomy.h:604
vctFixedSizeVector< size_type, 2 > nsize_type
Definition nmrSVDEconomy.h:116
void SetDimension(size_type m, size_type n, bool storageOrder)
Definition nmrSVDEconomy.h:152
static size_type WorkspaceSize(size_type m, size_type n)
Definition nmrSVDEconomy.h:281
nmrSVDEconomyDynamicData()
Definition nmrSVDEconomy.h:392
void SetRefWorkspace(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &inWorkspace)
Definition nmrSVDEconomy.h:531
nmrSVDEconomyDynamicData(size_type m, size_type n, bool storageOrder)
Definition nmrSVDEconomy.h:412
static size_type WorkspaceSize(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &inA)
Definition nmrSVDEconomy.h:296
static nsize_type MatrixSSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrSVDEconomy.h:311
void Allocate(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrSVDEconomy.h:514
vctDynamicVectorRef< CISSTNETLIB_DOUBLE > SReference
Definition nmrSVDEconomy.h:135
void AllocateOutputWorkspace(bool allocateOutput, bool allocateWorkspace)
Definition nmrSVDEconomy.h:178
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & Vt(void) const
Definition nmrSVDEconomy.h:635
nmrSVDEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &inU, vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &inS, vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > &inVt, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &inWorkspace)
Definition nmrSVDEconomy.h:474
vctDynamicVector< CISSTNETLIB_DOUBLE > WorkspaceMemory
Definition nmrSVDEconomy.h:120
size_type MMember
Definition nmrSVDEconomy.h:143
static vctDynamicMatrixBase< _matrixOwnerTypeS, CISSTNETLIB_DOUBLE > & UpdateMatrixS(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, const vctDynamicConstVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &vectorS, vctDynamicMatrixBase< _matrixOwnerTypeS, CISSTNETLIB_DOUBLE > &matrixS) CISST_THROW(std
Definition nmrSVDEconomy.h:329
void SetRef(vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &inU, vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &inS, vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > &inVt, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &inWorkspace) CISST_THROW(std
Definition nmrSVDEconomy.h:576
const vctDynamicVectorRef< CISSTNETLIB_DOUBLE > & S(void) const
Definition nmrSVDEconomy.h:622
void ThrowUnlessOutputSizeIsCorrect(vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &inU, vctDynamicVectorBase< _vectorOwnerTypeS, CISSTNETLIB_DOUBLE > &inS, vctDynamicMatrixBase< _matrixOwnerTypeVt, CISSTNETLIB_DOUBLE > &inVt) const CISST_THROW(std
Definition nmrSVDEconomy.h:218
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > UReference
Definition nmrSVDEconomy.h:133
nmrSVDEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition nmrSVDEconomy.h:430
void Allocate(size_type m, size_type n, bool storageOrder)
Definition nmrSVDEconomy.h:554
void ThrowUnlessWorkspaceSizeIsCorrect(vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &inWorkspace) const CISST_THROW(std
Definition nmrSVDEconomy.h:261
vctDynamicVector< CISSTNETLIB_DOUBLE > OutputMemory
Definition nmrSVDEconomy.h:127
vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > VtReference
Definition nmrSVDEconomy.h:134
size_type NMember
Definition nmrSVDEconomy.h:144
const vctDynamicMatrixRef< CISSTNETLIB_DOUBLE > & U(void) const
Definition nmrSVDEconomy.h:629
unsigned int size_type
Definition nmrSVDEconomy.h:112
nmrSVDEconomyDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &inWorkspace)
Definition nmrSVDEconomy.h:450
bool StorageOrderMember
Definition nmrSVDEconomy.h:145
Definition vctForwardDeclarations.h:145
Definition vctForwardDeclarations.h:119
Definition vctDynamicMatrixBase.h:43
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition vctDynamicMatrixBase.h:143
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
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 vector using template metaprogramming.
Definition vctFixedSizeVector.h:54
#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 nmrSVDEconomy(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrSVDEconomyDynamicData &data) CISST_THROW(std
Definition nmrSVDEconomy.h:800
Declaration of vctDynamicMatrix.
Declaration of vctFixedSizeMatrix.
const bool VCT_COL_MAJOR
Definition vctForwardDeclarations.h:44