cisst-saw
Loading...
Searching...
No Matches
nmrLSSolver.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Ankur Kapoor
6 Created on: 2004-10-26
7
8 (C) Copyright 2004-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19
24
25
26#ifndef _nmrLSSolver_h
27#define _nmrLSSolver_h
28
29
32
91 // we have this class so that we reserve memory only one would
92 // help if svd of a same size matrix (or a matrix) that doesnt
93 // change much is desired.
94
95protected:
96 CISSTNETLIB_INTEGER M;
97 CISSTNETLIB_INTEGER N;
98 CISSTNETLIB_INTEGER NRHS;
99 CISSTNETLIB_INTEGER Lda;
100 CISSTNETLIB_INTEGER Ldb;
101 CISSTNETLIB_INTEGER Lwork;
102 char Trans;
104 CISSTNETLIB_INTEGER Info;
106
107public:
113 M(0),
114 N(0),
115 NRHS(0),
117 {
119 }
120
121
133 nmrLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nrhs, bool storageOrder) {
134 Allocate(m, n, nrhs, storageOrder);
135 }
136
137
147
148
149
159 inline void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nrhs, bool storageOrder) {
160 const CISSTNETLIB_INTEGER one = 1;
161 StorageOrder = storageOrder;
162 M = m;
163 N = n;
164 NRHS = nrhs;
165 Lda = std::max(one, M);
166 Ldb = std::max(one, std::max(M, N));
167 CISSTNETLIB_INTEGER MN = std::min(M, N);
168 Lwork = std::max (one, MN + std::max (MN, NRHS));
169 Trans = 'N';
170 Work.SetSize(Lwork, 1, StorageOrder);
171 }
172
173
180 Allocate(A.rows(), A.cols(), B.cols(), A.IsRowMajor());
181 }
182
183
184
188
190 template <class _matrixOwnerType>
192 /* check that the size and storage order matches with Allocate() */
193 if (A.IsRowMajor() != StorageOrder) {
194 cmnThrow(std::runtime_error("nmrLSSolver Solve: Storage order used for Allocate was different"));
195 }
196 if (B.IsRowMajor() != StorageOrder) {
197 cmnThrow(std::runtime_error("nmrLSSolver Solve: Storage order used for Allocate was different"));
198 }
199
200 /* check sizes based on storage order, there is a more compact
201 expression for this test but I find this easier to read and
202 debug (Anton) */
203 if (A.IsColMajor()) {
204 if ((M != static_cast<CISSTNETLIB_INTEGER>(A.rows())) || (N != static_cast<CISSTNETLIB_INTEGER>(A.cols()))) {
205 cmnThrow(std::runtime_error("nmrLSSolver Solve: Size used for Allocate was different"));
206 }
207 }
208 if (B.IsColMajor()) {
209 if ((M != static_cast<CISSTNETLIB_INTEGER>(B.rows())) || (NRHS != static_cast<CISSTNETLIB_INTEGER>(B.cols()))) {
210 cmnThrow(std::runtime_error("nmrLSSolver Solve: Size used for Allocate was different"));
211 }
212 }
213
214 /* check that the matrices are Fortran like */
215 if (! A.IsCompact()) {
216 cmnThrow(std::runtime_error("nmrLSSolver Solve: Requires a compact matrix"));
217 }
218 if (! B.IsCompact()) {
219 cmnThrow(std::runtime_error("nmrLSSolver Solve: Requires a compact matrix"));
220 }
221
222 /* call the LAPACK C function */
223#if defined(CISSTNETLIB_VERSION_MAJOR)
224#if (CISSTNETLIB_VERSION_MAJOR >= 3)
225 cisstNetlib_dgels_(&Trans, &M, &N, &NRHS,
226 A.Pointer(), &Lda,
227 B.Pointer(), &Ldb,
228 Work.Pointer(), &Lwork, &Info);
229#endif
230#else // no major version
231 dgels_(&Trans, &M, &N, &NRHS,
232 A.Pointer(), &Lda,
233 B.Pointer(), &Ldb,
234 Work.Pointer(), &Lwork, &Info);
235#endif // CISSTNETLIB_VERSION
236 }
237
238
239};
240
241
242#endif // _nmrLSSolver_h
CISSTNETLIB_INTEGER NRHS
Definition nmrLSSolver.h:98
CISSTNETLIB_INTEGER N
Definition nmrLSSolver.h:97
void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nrhs, bool storageOrder)
Definition nmrLSSolver.h:159
CISSTNETLIB_INTEGER Ldb
Definition nmrLSSolver.h:100
nmrLSSolver(void)
Definition nmrLSSolver.h:112
nmrLSSolver(vctDynamicMatrix< double > &A, vctDynamicMatrix< double > &B)
Definition nmrLSSolver.h:144
void Solve(vctDynamicMatrixBase< _matrixOwnerType, double > &A, vctDynamicMatrixBase< _matrixOwnerType, double > &B) CISST_THROW(std
Definition nmrLSSolver.h:191
CISSTNETLIB_INTEGER Lwork
Definition nmrLSSolver.h:101
vctDynamicMatrix< double > Work
Definition nmrLSSolver.h:103
char Trans
Definition nmrLSSolver.h:102
void Allocate(vctDynamicMatrix< double > &A, vctDynamicMatrix< double > &B)
Definition nmrLSSolver.h:179
CISSTNETLIB_INTEGER Info
Definition nmrLSSolver.h:104
bool StorageOrder
Definition nmrLSSolver.h:105
CISSTNETLIB_INTEGER M
Definition nmrLSSolver.h:96
CISSTNETLIB_INTEGER Lda
Definition nmrLSSolver.h:99
nmrLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nrhs, bool storageOrder)
Definition nmrLSSolver.h:133
Definition vctDynamicMatrixBase.h:43
Definition vctForwardDeclarations.h:157
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
Declaration of vctDynamicMatrix.
const bool VCT_COL_MAJOR
Definition vctForwardDeclarations.h:44