cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Ankur Kapoor
6 Created on: 2004-10-30
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#ifndef _nmrNNLSSolver_h
26#define _nmrNNLSSolver_h
27
30
70
71protected:
72 CISSTNETLIB_INTEGER M;
73 CISSTNETLIB_INTEGER N;
74 CISSTNETLIB_INTEGER Mda;
75 CISSTNETLIB_INTEGER Mode;
76 CISSTNETLIB_DOUBLE RNorm;
81
82public:
88 M(0),
89 N(0)
90 {
91 Allocate(M, N);
92 }
93
94
103 nmrNNLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n) {
104 Allocate(m, n);
105 }
106
107
116
117
125 inline void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n) {
126 M = m;
127 N = n;
128 Mda = M;
129 X.SetSize(N, 1, VCT_COL_MAJOR);
130 W.SetSize(N,1, VCT_COL_MAJOR);
131 Zz.SetSize(M,1, VCT_COL_MAJOR);
132 Index.SetSize(N, 1, VCT_COL_MAJOR);
133 }
134
135
143
144
158 CISST_THROW(std::runtime_error)
159 {
160 /* check that the size matches with Allocate() */
161 if ((M != static_cast<CISSTNETLIB_INTEGER>(C.rows()))
162 || (N != static_cast<CISSTNETLIB_INTEGER>(C.cols()))) {
163 cmnThrow(std::runtime_error("nmrNNLSSolver Solve: Sizes used for Allocate were different"));
164 }
165
166 /* check other dimensions */
167 if (C.rows() != d.rows()) {
168 cmnThrow(std::runtime_error("nmrNNLSSolver Solve: Sizes of parameters are incompatible"));
169 }
170
171 /* check that the matrices are Fortran like */
172 if (! (C.IsFortran()
173 && d.IsFortran())) {
174 cmnThrow(std::runtime_error("nmrNNLSSolver Solve: All parameters must be Fortran compatible"));
175 }
176
177#if defined(CISSTNETLIB_VERSION_MAJOR)
178#if (CISSTNETLIB_VERSION_MAJOR >= 3)
179 cisstNetlib_nnls_(C.Pointer(), &Mda, &M, &N, d.Pointer(), X.Pointer(), &RNorm,
180 W.Pointer(), Zz.Pointer(), Index.Pointer(), &Mode);
181#endif
182#else // no major version
183 nnls_(C.Pointer(), &Mda, &M, &N, d.Pointer(), X.Pointer(), &RNorm,
184 W.Pointer(), Zz.Pointer(), Index.Pointer(), &Mode);
185#endif // CISSTNETLIB_VERSION
186
187 //error handling??
188 }
189
190
192 inline const vctDynamicMatrix<CISSTNETLIB_DOUBLE> &GetX(void) const {
193 return X;
194 }
195
196
197 /* Get W. This method must be used after Solve(). */
199 return W;
200 }
201
202
203 /* Get RNorm. This method must be used after Solve(). */
204 inline CISSTNETLIB_DOUBLE GetRNorm(void) const {
205 return RNorm;
206 }
207};
208
209
210#endif // _nmrNNLSSolver_h
CISSTNETLIB_INTEGER Mda
Definition nmrNNLSSolver.h:74
CISSTNETLIB_INTEGER M
Definition nmrNNLSSolver.h:72
nmrNNLSSolver(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &d)
Definition nmrNNLSSolver.h:113
CISSTNETLIB_INTEGER N
Definition nmrNNLSSolver.h:73
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetX(void) const
Definition nmrNNLSSolver.h:192
void Solve(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > d) CISST_THROW(std
Definition nmrNNLSSolver.h:157
void Allocate(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition nmrNNLSSolver.h:125
CISSTNETLIB_DOUBLE RNorm
Definition nmrNNLSSolver.h:76
CISSTNETLIB_DOUBLE GetRNorm(void) const
Definition nmrNNLSSolver.h:204
CISSTNETLIB_INTEGER Mode
Definition nmrNNLSSolver.h:75
vctDynamicMatrix< CISSTNETLIB_INTEGER > Index
Definition nmrNNLSSolver.h:80
nmrNNLSSolver(CISSTNETLIB_INTEGER m, CISSTNETLIB_INTEGER n)
Definition nmrNNLSSolver.h:103
void Allocate(vctDynamicMatrix< CISSTNETLIB_DOUBLE > &C, vctDynamicMatrix< CISSTNETLIB_DOUBLE > &CMN_UNUSED(d))
Definition nmrNNLSSolver.h:140
vctDynamicMatrix< CISSTNETLIB_DOUBLE > W
Definition nmrNNLSSolver.h:78
const vctDynamicMatrix< CISSTNETLIB_DOUBLE > & GetDual(void) const
Definition nmrNNLSSolver.h:198
vctDynamicMatrix< CISSTNETLIB_DOUBLE > Zz
Definition nmrNNLSSolver.h:79
nmrNNLSSolver(void)
Definition nmrNNLSSolver.h:87
vctDynamicMatrix< CISSTNETLIB_DOUBLE > X
Definition nmrNNLSSolver.h:77
Definition vctForwardDeclarations.h:157
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#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