cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrSVDRSSolver.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 
6  Author(s): Ankur Kapoor
7  Created on: 2004-10-30
8 
9  (C) Copyright 2004-2013 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
27 #ifndef _nmrSVDRSSolver_h
28 #define _nmrSVDRSSolver_h
29 
30 
33 
34 
119 
120 protected:
121  CISSTNETLIB_INTEGER M; /* No. of rows of A, B, G */
122  CISSTNETLIB_INTEGER N; /* No. of cols of A, No of rows and cols of V */
123  CISSTNETLIB_INTEGER Lda; /* >= max(m, n) */
124  CISSTNETLIB_INTEGER Ldb; /* >= m */
125  CISSTNETLIB_INTEGER Nb; /* No. of cols of B and G */
126  vctDynamicMatrix<CISSTNETLIB_DOUBLE> S; /* Singular values, Dim(S)>n */
128 
129 public:
130 
135  nmrSVDRSSolver(void): M(0), N(0)
136  { Allocate(M, N); }
137 
138 
148  nmrSVDRSSolver( CISSTNETLIB_INTEGER m,
149  CISSTNETLIB_INTEGER n,
150  CISSTNETLIB_INTEGER nb = 1) {
151  Allocate(m, n, nb);
152  }
153 
154 
162  { Allocate(A, B); }
163 
164 
173  inline void Allocate( CISSTNETLIB_INTEGER m,
174  CISSTNETLIB_INTEGER n,
175  CISSTNETLIB_INTEGER nb = 1) {
176  M = m;
177  N = n;
178  Lda = std::max(M, N);
179  Ldb = M;
180  Nb = nb;
181  S.SetSize(N, 1, VCT_COL_MAJOR);
182  Work.SetSize(2 * N, 1, VCT_COL_MAJOR);
183  }
184 
185 
192  { Allocate(A.rows(), A.cols(), B.cols()); }
193 
194 
213  throw (std::runtime_error)
214  {
215  /* check that the size matches with Allocate() */
216  if ((M != static_cast<CISSTNETLIB_INTEGER>(A.rows())) ||
217  (N != static_cast<CISSTNETLIB_INTEGER>(A.cols())) ||
218  (Nb != static_cast<CISSTNETLIB_INTEGER>(B.cols()))) {
219  cmnThrow(std::runtime_error("nmrSVDRSSolver Solve: Sizes used for Allocate were different"));
220  }
221 
222  /* check other dimensions */
223  if (M != static_cast<CISSTNETLIB_INTEGER>(B.rows())) {
224  cmnThrow(std::runtime_error("nmrSVDRSSolver Solve: Sizes of parameters are incompatible"));
225  }
226 
227  /* check that the matrices are Fortran like */
228  if (! (A.IsFortran() && B.IsFortran())) {
229  cmnThrow(std::runtime_error("nmrSVDRSSolver Solve: All parameters must be Fortran compatible"));
230  }
231 
232 #if defined(CISSTNETLIB_VERSION_MAJOR)
233 #if (CISSTNETLIB_VERSION_MAJOR >= 3)
234  cisstNetlib_svdrs_(A.Pointer(), &Lda, &M, &N, B.Pointer(),
235  &Ldb, &Nb, S.Pointer(), Work.Pointer());
236 #endif
237 #else // no major version
238  svdrs_(A.Pointer(), &Lda, &M, &N, B.Pointer(),
239  &Ldb, &Nb, S.Pointer(), Work.Pointer());
240 #endif // CISSTNETLIB_VERSION
241  }
242 
243 
244  inline const vctDynamicMatrix<CISSTNETLIB_DOUBLE> & GetS(void) const
245  { return S; }
246 
247 };
248 
249 
250 #endif // _nmrSVDRSSolver_h
251 
Declaration of vctDynamicMatrix.
void Allocate(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &A, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &B)
Definition: nmrSVDRSSolver.h:190
CISSTNETLIB_INTEGER N
Definition: nmrSVDRSSolver.h:122
vctDynamicMatrix< CISSTNETLIB_DOUBLE > S
Definition: nmrSVDRSSolver.h:126
nmrSVDRSSolver(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &A, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &B)
Definition: nmrSVDRSSolver.h:160
nmrSVDRSSolver(void)
Definition: nmrSVDRSSolver.h:135
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctDynamicMatrixBase.h:143
CISSTNETLIB_INTEGER Lda
Definition: nmrSVDRSSolver.h:123
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
void SetSize(size_type rows, size_type cols, bool storageOrder)
Definition: vctDynamicMatrix.h:364
Definition: nmrSVDRSSolver.h:118
#define cmnThrow(a)
Definition: MinimalCmn.h:4
nmrSVDRSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nb=1)
Definition: nmrSVDRSSolver.h:148
void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n, CISSTNETLIB_INTEGER nb=1)
Definition: nmrSVDRSSolver.h:173
CISSTNETLIB_INTEGER Nb
Definition: nmrSVDRSSolver.h:125
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetS(void) const
Definition: nmrSVDRSSolver.h:244
CISSTNETLIB_INTEGER Ldb
Definition: nmrSVDRSSolver.h:124
void Solve(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &A, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &B)
Definition: nmrSVDRSSolver.h:211
const bool VCT_COL_MAJOR
Definition: vctForwardDeclarations.h:46
CISSTNETLIB_INTEGER M
Definition: nmrSVDRSSolver.h:121
vctDynamicMatrix< CISSTNETLIB_DOUBLE > Work
Definition: nmrSVDRSSolver.h:127