cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrNNLSSolver.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 _nmrNNLSSolver_h
28 #define _nmrNNLSSolver_h
29 
32 
72 
73 protected:
74  CISSTNETLIB_INTEGER M;
75  CISSTNETLIB_INTEGER N;
76  CISSTNETLIB_INTEGER Mda;
77  CISSTNETLIB_INTEGER Mode;
78  CISSTNETLIB_DOUBLE RNorm;
83 
84 public:
90  M(0),
91  N(0)
92  {
93  Allocate(M, N);
94  }
95 
96 
105  nmrNNLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n) {
106  Allocate(m, n);
107  }
108 
109 
116  Allocate(C, d);
117  }
118 
119 
127  inline void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n) {
128  M = m;
129  N = n;
130  Mda = M;
131  X.SetSize(N, 1, VCT_COL_MAJOR);
132  W.SetSize(N,1, VCT_COL_MAJOR);
135  }
136 
137 
143  Allocate(C.rows(), C.cols());
144  }
145 
146 
160  throw (std::runtime_error)
161  {
162  /* check that the size matches with Allocate() */
163  if ((M != static_cast<CISSTNETLIB_INTEGER>(C.rows()))
164  || (N != static_cast<CISSTNETLIB_INTEGER>(C.cols()))) {
165  cmnThrow(std::runtime_error("nmrNNLSSolver Solve: Sizes used for Allocate were different"));
166  }
167 
168  /* check other dimensions */
169  if (C.rows() != d.rows()) {
170  cmnThrow(std::runtime_error("nmrNNLSSolver Solve: Sizes of parameters are incompatible"));
171  }
172 
173  /* check that the matrices are Fortran like */
174  if (! (C.IsFortran()
175  && d.IsFortran())) {
176  cmnThrow(std::runtime_error("nmrNNLSSolver Solve: All parameters must be Fortran compatible"));
177  }
178 
179 #if defined(CISSTNETLIB_VERSION_MAJOR)
180 #if (CISSTNETLIB_VERSION_MAJOR >= 3)
181  cisstNetlib_nnls_(C.Pointer(), &Mda, &M, &N, d.Pointer(), X.Pointer(), &RNorm,
182  W.Pointer(), Zz.Pointer(), Index.Pointer(), &Mode);
183 #endif
184 #else // no major version
185  nnls_(C.Pointer(), &Mda, &M, &N, d.Pointer(), X.Pointer(), &RNorm,
186  W.Pointer(), Zz.Pointer(), Index.Pointer(), &Mode);
187 #endif // CISSTNETLIB_VERSION
188 
189  //error handling??
190  }
191 
192 
194  inline const vctDynamicMatrix<CISSTNETLIB_DOUBLE> &GetX(void) const {
195  return X;
196  }
197 
198 
199  /* Get W. This method must be used after Solve(). */
200  inline const vctDynamicMatrix<CISSTNETLIB_DOUBLE> &GetDual(void) const {
201  return W;
202  }
203 
204 
205  /* Get RNorm. This method must be used after Solve(). */
206  inline CISSTNETLIB_DOUBLE GetRNorm(void) const {
207  return RNorm;
208  }
209 };
210 
211 
212 #endif // _nmrNNLSSolver_h
213 
Declaration of vctDynamicMatrix.
vctDynamicMatrix< CISSTNETLIB_INTEGER > Index
Definition: nmrNNLSSolver.h:82
vctDynamicMatrix< CISSTNETLIB_DOUBLE > Zz
Definition: nmrNNLSSolver.h:81
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
bool IsFortran(void) const
Definition: vctDynamicConstMatrixBase.h:650
vctDynamicMatrix< CISSTNETLIB_DOUBLE > X
Definition: nmrNNLSSolver.h:79
void Solve(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > d)
Definition: nmrNNLSSolver.h:159
nmrNNLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition: nmrNNLSSolver.h:105
void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition: nmrNNLSSolver.h:127
vctDynamicMatrix< CISSTNETLIB_DOUBLE > W
Definition: nmrNNLSSolver.h:80
nmrNNLSSolver(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &d)
Definition: nmrNNLSSolver.h:115
CISSTNETLIB_DOUBLE GetRNorm(void) const
Definition: nmrNNLSSolver.h:206
pointer Pointer(size_type rowIndex, size_type colIndex)
Definition: vctDynamicMatrixBase.h:143
nmrNNLSSolver(void)
Definition: nmrNNLSSolver.h:89
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetDual(void) const
Definition: nmrNNLSSolver.h:200
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
void SetSize(size_type rows, size_type cols, bool storageOrder)
Definition: vctDynamicMatrix.h:364
Definition: nmrNNLSSolver.h:71
#define cmnThrow(a)
Definition: MinimalCmn.h:4
CISSTNETLIB_INTEGER N
Definition: nmrNNLSSolver.h:75
void Allocate(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &CMN_UNUSED(d))
Definition: nmrNNLSSolver.h:142
CISSTNETLIB_INTEGER Mode
Definition: nmrNNLSSolver.h:77
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetX(void) const
Definition: nmrNNLSSolver.h:194
const bool VCT_COL_MAJOR
Definition: vctForwardDeclarations.h:46
CISSTNETLIB_DOUBLE RNorm
Definition: nmrNNLSSolver.h:78
CISSTNETLIB_INTEGER Mda
Definition: nmrNNLSSolver.h:76
CISSTNETLIB_INTEGER M
Definition: nmrNNLSSolver.h:74