137 if (allocateOutput) {
153 template <
class _vectorOwnerTypePivotIndices>
155 throw(std::runtime_error)
159 if (minmn != pivotIndices.size()) {
160 cmnThrow(std::runtime_error(
"nmrLUDynamicData: Size of vector pivotIndices is incorrect."));
162 if (!pivotIndices.IsCompact()) {
163 cmnThrow(std::runtime_error(
"nmrLUDynamicData: Vector pivotIndices must be compact."));
177 template <
class _matrixOwnerTypeA>
192 template <
class _matrixOwnerTypeA>
208 template <
class _matrixOwnerTypeA>
226 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypePivotIndices,
class _matrixOwnerTypeP>
232 throw(std::runtime_error)
234 const size_type minmn = (A.rows() < A.cols()) ? A.rows() : A.cols();
236 if (pivotIndices.size() != minmn) {
237 cmnThrow(std::runtime_error(
"nmrLUDynamicData::UpdateMatrixP: Size of vector pivotIndices is incorrect."));
239 if (! P.IsSquare(A.rows())) {
240 cmnThrow(std::runtime_error(
"nmrLUDynamicData::UpdateMatrixP: Size of matrix P is incorrect."));
244 P.Diagonal().SetAll(1.0);
246 for (rowIndex = 0; rowIndex < minmn; ++rowIndex) {
247 colIndex = pivotIndices[rowIndex] - 1;
248 P.ExchangeColumns(rowIndex, colIndex);
267 template <
class _matrixOwnerTypeA,
class _matrixOwnerTypeL,
class _matrixOwnerTypeU>
272 throw(std::runtime_error)
278 L.Diagonal().SetAll(1.0);
280 for (rowIndex = 0; rowIndex < rows; ++rowIndex) {
281 for (colIndex = 0; colIndex < cols; ++colIndex) {
282 if (rowIndex > colIndex) {
283 L.Element(rowIndex, colIndex) = A.Element(rowIndex, colIndex);
285 U.Element(rowIndex, colIndex) = A.Element(rowIndex, colIndex);
358 template <
class _matrixOwnerTypeA>
375 template <
class _matrixOwnerTypeA,
376 class _vectorOwnerTypePivotIndices>
380 this->
SetRef(A, pivotIndices);
392 template <
class _matrixOwnerTypeA>
422 template <
class _matrixOwnerTypeA,
423 class _vectorOwnerTypePivotIndices>
426 throw(std::runtime_error)
469 template <vct::
size_type _rows, vct::
size_type _cols>
475 enum {
MIN_MN = (_rows < _cols) ? _rows : _cols};
511 return Data.PivotIndicesMember;
537 inline static MatrixTypeP &
540 throw(std::runtime_error)
544 P.Diagonal().SetAll(1.0);
546 for (rowIndex = 0; rowIndex <
MIN_MN; ++rowIndex) {
547 colIndex = pivotIndices[rowIndex] - 1;
548 P.ExchangeColumns(rowIndex, colIndex);
572 throw(std::runtime_error)
576 L.Diagonal().SetAll(1.0);
578 for (rowIndex = 0; rowIndex < _rows; ++rowIndex) {
579 for (colIndex = 0; colIndex < _cols; ++colIndex) {
580 if (rowIndex > colIndex) {
581 L.Element(rowIndex, colIndex) = A.Element(rowIndex, colIndex);
583 U.Element(rowIndex, colIndex) = A.Element(rowIndex, colIndex);
719 template <
class _matrixOwnerType>
722 throw (std::runtime_error)
725 CISSTNETLIB_INTEGER info;
728 if (!A.IsColMajor()) {
729 cmnThrow(std::runtime_error(
"nmrLU: Input must use VCT_COL_MAJOR storage order."));
732 if ((dataFriend.
M() != A.rows()) || (dataFriend.
N() != A.cols())) {
733 cmnThrow(std::runtime_error(
"nmrLU: Size used for Allocate was different."));
736 if (! A.IsCompact()) {
737 cmnThrow(std::runtime_error(
"nmrLU: Requires a compact matrix."));
740 CISSTNETLIB_INTEGER m = dataFriend.
M();
741 CISSTNETLIB_INTEGER n = dataFriend.
N();
742 CISSTNETLIB_INTEGER lda = (m > 1) ? m : 1;
745 #if defined(CISSTNETLIB_VERSION_MAJOR)
746 #if (CISSTNETLIB_VERSION_MAJOR >= 3)
747 cisstNetlib_dgetrf_(&m, &n,
751 #else // no major version
755 #endif // CISSTNETLIB_VERSION
774 template <
class _matrixOwnerTypeA,
class _vectorOwnerTypePivotIndices>
779 return nmrLU(A, data);
783 #ifndef SWIG // don't have fixed size containers in Python
810 template <vct::
size_type _rows, vct::
size_type _cols, vct::
size_type _minmn>
816 CMN_ASSERT(minmn == static_cast<CISSTNETLIB_INTEGER>(_minmn));
818 CISSTNETLIB_INTEGER info;
819 CISSTNETLIB_INTEGER lda = (_rows> 1) ? _rows : 1;
820 CISSTNETLIB_INTEGER m = _rows;
821 CISSTNETLIB_INTEGER n = _cols;
824 #if defined(CISSTNETLIB_VERSION_MAJOR)
825 #if (CISSTNETLIB_VERSION_MAJOR >= 3)
826 cisstNetlib_dgetrf_(&m, &n,
828 pivotIndices.
Pointer(), &info);
830 #else // no major version
833 pivotIndices.
Pointer(), &info);
834 #endif // CISSTNETLIB_VERSION
860 template <vct::
size_type _rows, vct::
size_type _cols>
size_type N(void)
Definition: nmrLU.h:313
static MatrixTypeP & UpdateMatrixP(const VectorTypePivotIndices &pivotIndices, MatrixTypeP &P)
Definition: nmrLU.h:538
static void UpdateMatrixLU(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicMatrixBase< _matrixOwnerTypeL, CISSTNETLIB_DOUBLE > &L, vctDynamicMatrixBase< _matrixOwnerTypeU, CISSTNETLIB_DOUBLE > &U)
Definition: nmrLU.h:269
VectorTypePivotIndices PivotIndicesMember
Definition: nmrLU.h:494
vctDynamicVector< CISSTNETLIB_INTEGER > OutputMemory
Definition: nmrLU.h:98
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, MIN_MN, _cols, VCT_COL_MAJOR > MatrixTypeU
Definition: nmrLU.h:491
vct::size_type size_type
Definition: nmrLU.h:474
Declaration of vctDynamicMatrix.
#define CMN_ASSERT(expr)
Definition: cmnAssert.h:90
void SetDimension(size_type m, size_type n)
Definition: nmrLU.h:116
static nsize_type MatrixLSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrLU.h:194
Definition: vctDynamicMatrixBase.h:42
void SetRef(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > &pivotIndices)
Definition: nmrLU.h:424
Data of LU problem (Dynamic).
Definition: nmrLU.h:84
Friend(nmrLUDynamicData &data)
Definition: nmrLU.h:305
nmrLUDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > &pivotIndices)
Definition: nmrLU.h:377
Declaration of vctFixedSizeMatrix.
size_type NMember
Definition: nmrLU.h:109
value_type SetAll(const value_type value)
Definition: vctFixedSizeMatrixBase.h:421
size_t size_type
Definition: vctContainerTraits.h:35
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, MIN_MN, VCT_COL_MAJOR > MatrixTypeL
Definition: nmrLU.h:488
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition: vctDynamicVectorRef.h:156
VectorTypePivotIndices & PivotIndices(void)
Definition: nmrLU.h:510
static void UpdateMatrixLU(const MatrixTypeA &A, MatrixTypeL &L, MatrixTypeU &U)
Definition: nmrLU.h:569
void SetSize(size_type size)
Definition: vctDynamicVector.h:315
Definition: vctDynamicConstMatrixBase.h:77
Implementation of a fixed-size vector using template metaprogramming.
Definition: vctFixedSizeVector.h:52
vctFixedSizeVector< CISSTNETLIB_INTEGER, MIN_MN > VectorTypePivotIndices
Definition: nmrLU.h:482
nmrLUFixedSizeData()
Definition: nmrLU.h:519
vctFixedSizeVector< size_type, 2 > nsize_type
Definition: nmrLU.h:94
void ThrowUnlessOutputSizeIsCorrect(vctDynamicVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > &pivotIndices)
Definition: nmrLU.h:154
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, VCT_COL_MAJOR > MatrixTypeA
Definition: nmrLU.h:479
vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _rows, VCT_COL_MAJOR > MatrixTypeP
Definition: nmrLU.h:485
#define cmnThrow(a)
Definition: MinimalCmn.h:4
Implementation of a fixed-size matrix using template metaprogramming.
Definition: vctFixedSizeMatrix.h:52
Friend(nmrLUFixedSizeData< _rows, _cols > &data)
Definition: nmrLU.h:508
nmrLUDynamicData(size_type m, size_type n)
Definition: nmrLU.h:344
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
void Allocate(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrLU.h:393
size_type M(void)
Definition: nmrLU.h:310
vct::size_type size_type
Definition: nmrLU.h:92
static nsize_type MatrixPSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrLU.h:179
vctDynamicVectorRef< CISSTNETLIB_INTEGER > & PivotIndices(void)
Definition: nmrLU.h:307
Definition: vctDynamicConstVectorBase.h:77
Data of LU problem (Fixed size).
Definition: nmrLU.h:470
void Allocate(size_type m, size_type n)
Definition: nmrLU.h:405
CISSTNETLIB_INTEGER nmrLU(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrLUDynamicData &data)
Definition: nmrLU.h:720
nmrLUDynamicData()
Definition: nmrLU.h:328
pointer Pointer(size_type index=0)
Definition: vctFixedSizeVectorBase.h:226
static nsize_type MatrixUSize(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrLU.h:210
Declaration of the template function cmnThrow.
size_type MMember
Definition: nmrLU.h:108
void AllocateOutput(bool allocateOutput)
Definition: nmrLU.h:134
nmrLUDynamicData(vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A)
Definition: nmrLU.h:359
static vctDynamicMatrixBase< _matrixOwnerTypeP, CISSTNETLIB_DOUBLE > & UpdateMatrixP(const vctDynamicConstMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, const vctDynamicConstVectorBase< _vectorOwnerTypePivotIndices, CISSTNETLIB_INTEGER > &pivotIndices, vctDynamicMatrixBase< _matrixOwnerTypeP, CISSTNETLIB_DOUBLE > &P)
Definition: nmrLU.h:229
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctFixedSizeMatrixBase.h:161
vctDynamicVectorRef< CISSTNETLIB_INTEGER > PivotIndicesReference
Definition: nmrLU.h:103
Definition: vctDynamicVectorBase.h:61
const VectorTypePivotIndices & PivotIndices(void) const
Definition: nmrLU.h:524
const vctDynamicVectorRef< CISSTNETLIB_INTEGER > & PivotIndices(void) const
Definition: nmrLU.h:437