Sacado Package Browser (Single Doxygen Collection)
Version of the Day
test
TestSuite
FadLAPACKUnitTests.hpp
Go to the documentation of this file.
1
// $Id$
2
// $Source$
3
// @HEADER
4
// ***********************************************************************
5
//
6
// Sacado Package
7
// Copyright (2006) Sandia Corporation
8
//
9
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10
// the U.S. Government retains certain rights in this software.
11
//
12
// This library is free software; you can redistribute it and/or modify
13
// it under the terms of the GNU Lesser General Public License as
14
// published by the Free Software Foundation; either version 2.1 of the
15
// License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful, but
18
// WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25
// USA
26
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27
// (etphipp@sandia.gov).
28
//
29
// ***********************************************************************
30
// @HEADER
31
32
#ifndef FADLAPACKUNITTESTS_HPP
33
#define FADLAPACKUNITTESTS_HPP
34
35
// Sacado includes
36
#include "
Sacado_No_Kokkos.hpp
"
37
#include "
Sacado_Fad_LAPACK.hpp
"
38
#include "
Sacado_Random.hpp
"
39
40
// Cppunit includes
41
#include <cppunit/extensions/HelperMacros.h>
42
43
#define COMPARE_VALUES(a, b) \
44
CPPUNIT_ASSERT( std::abs(a-b) < this->tol_a + this->tol_r*std::abs(a) );
45
46
#define COMPARE_FADS(a, b) \
47
CPPUNIT_ASSERT(a.size() == b.size()); \
48
CPPUNIT_ASSERT(a.hasFastAccess() == b.hasFastAccess()); \
49
COMPARE_VALUES(a.val(), b.val()); \
50
for (int k=0; k<a.size(); k++) { \
51
COMPARE_VALUES(a.dx(k), b.dx(k)); \
52
COMPARE_VALUES(a.fastAccessDx(k), b.fastAccessDx(k)); \
53
} \
54
;
55
56
#define COMPARE_FAD_VECTORS(X1, X2, n) \
57
CPPUNIT_ASSERT(X1.size() == std::size_t(n)); \
58
CPPUNIT_ASSERT(X2.size() == std::size_t(n)); \
59
for (unsigned int i=0; i<n; i++) { \
60
COMPARE_FADS(X1[i], X2[i]); \
61
} \
62
;
63
64
// A class for testing differentiated LAPACK operations for general Fad types
65
template
<
class
FadType,
class
ScalarType>
66
class
FadLAPACKUnitTests
:
public
CppUnit::TestFixture {
67
68
typedef
Sacado::Fad::Vector<unsigned int,FadType>
VectorType
;
69
70
CPPUNIT_TEST_SUITE
(
FadLAPACKUnitTests
);
71
72
CPPUNIT_TEST
(
testGESV
);
73
74
CPPUNIT_TEST_SUITE_END
();
75
76
public
:
77
78
FadLAPACKUnitTests
();
79
80
FadLAPACKUnitTests
(
int
m
,
int
n
,
int
l
,
int
ndot
,
81
double
absolute_tolerance,
double
relative_tolerance);
82
83
void
setUp
();
84
void
tearDown
();
85
86
void
testGESV
();
87
88
protected
:
89
90
// Random number generator
91
Sacado::Random<ScalarType>
urand
;
92
93
// Real random number generator for derivative components
94
Sacado::Random<double>
real_urand
;
95
96
// Number of matrix rows
97
unsigned
int
m
;
98
99
// Number of matrix columns
100
unsigned
int
n
;
101
102
// Number of matrix columns for level 3 blas
103
unsigned
int
l
;
104
105
// Number of derivative components
106
unsigned
int
ndot
;
107
108
// Tolerances to which fad objects should be the same
109
double
tol_a
,
tol_r
;
110
111
};
// class FadLAPACKUnitTests
112
113
template
<
class
FadType,
class
ScalarType>
114
FadLAPACKUnitTests<FadType,ScalarType>::
115
FadLAPACKUnitTests
() :
116
urand(), real_urand(), m(5),
n
(6), l(4), ndot(7), tol_a(1.0e-11), tol_r(1.0e-11) {}
117
118
template
<
class
FadType,
class
ScalarType>
119
FadLAPACKUnitTests<FadType,ScalarType>::
120
FadLAPACKUnitTests
(
int
m_,
int
n_,
int
l_,
int
ndot_,
double
absolute_tolerance,
121
double
relative_tolerance) :
122
urand(),
123
real_urand(),
124
m(m_),
125
n
(n_),
126
l(l_),
127
ndot(ndot_),
128
tol_a(absolute_tolerance),
129
tol_r(relative_tolerance) {}
130
131
template
<
class
FadType,
class
ScalarType>
132
void
FadLAPACKUnitTests<FadType,ScalarType>::
133
setUp
() {}
134
135
template
<
class
FadType,
class
ScalarType>
136
void
FadLAPACKUnitTests<FadType,ScalarType>::
137
tearDown
() {}
138
139
// Tests all arguments
140
template
<
class
FadType,
class
ScalarType>
141
void
142
FadLAPACKUnitTests<FadType,ScalarType>::
143
testGESV
() {
144
145
const
int
n
= 2;
146
const
int
nrhs = 1;
147
double
A
[] = { 1.1, 0.1, .01, 0.9 };
148
const
int
lda = 2;
149
int
IPIV[] = {0, 0};
150
double
B
[] = { 0.1, 0.2 };
151
const
int
ldb = 2;
152
int
info(0);
153
154
const
double
refX[] = {0.088978766430738, 0.212335692618807};
155
156
Teuchos::LAPACK<int,double>
teuchos_lapack;
157
teuchos_lapack.
GESV
(
n
, nrhs, &
A
[0], lda, &IPIV[0], &
B
[0], ldb, &info);
158
159
COMPARE_VALUES
(
B
[0],refX[0]);
160
COMPARE_VALUES
(
B
[1],refX[1]);
161
162
//Teuchos::LAPACK<int,FadType> sacado_lapack(false);
163
//sacado_blas.SCAL(m, alpha, &x2[0], 1);
164
//COMPARE_VALUES(1,0);
165
}
166
167
#undef COMPARE_VALUES
168
#undef COMPARE_FADS
169
#undef COMPARE_FAD_VECTORS
170
171
#endif // FADLAPACKUNITTESTS_HPP
FadLAPACKUnitTests::FadLAPACKUnitTests
FadLAPACKUnitTests()
Definition:
FadLAPACKUnitTests.hpp:115
FadLAPACKUnitTests::tol_a
double tol_a
Definition:
FadLAPACKUnitTests.hpp:109
Sacado::Random< ScalarType >
FadLAPACKUnitTests::CPPUNIT_TEST_SUITE_END
CPPUNIT_TEST_SUITE_END()
FadLAPACKUnitTests::setUp
void setUp()
Definition:
FadLAPACKUnitTests.hpp:133
FadLAPACKUnitTests
Definition:
FadLAPACKUnitTests.hpp:66
FadLAPACKUnitTests::CPPUNIT_TEST
CPPUNIT_TEST(testGESV)
FadLAPACKUnitTests::ndot
unsigned int ndot
Definition:
FadLAPACKUnitTests.hpp:106
Teuchos::LAPACK::GESV
void GESV(const OrdinalType &n, const OrdinalType &nrhs, ScalarType *A, const OrdinalType &lda, OrdinalType *IPIV, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
FadLAPACKUnitTests::VectorType
Sacado::Fad::Vector< unsigned int, FadType > VectorType
Definition:
FadLAPACKUnitTests.hpp:68
Sacado_Fad_LAPACK.hpp
FadLAPACKUnitTests::urand
Sacado::Random< ScalarType > urand
Definition:
FadLAPACKUnitTests.hpp:91
FadLAPACKUnitTests::real_urand
Sacado::Random< double > real_urand
Definition:
FadLAPACKUnitTests.hpp:94
FadLAPACKUnitTests::testGESV
void testGESV()
Definition:
FadLAPACKUnitTests.hpp:143
Sacado_No_Kokkos.hpp
FadLAPACKUnitTests::CPPUNIT_TEST_SUITE
CPPUNIT_TEST_SUITE(FadLAPACKUnitTests)
FadLAPACKUnitTests::tol_r
double tol_r
Definition:
FadLAPACKUnitTests.hpp:109
FadLAPACKUnitTests::n
unsigned int n
Definition:
FadLAPACKUnitTests.hpp:100
COMPARE_VALUES
#define COMPARE_VALUES(a, b)
Definition:
FadLAPACKUnitTests.hpp:43
A
Definition:
ConversionTests.cpp:42
FadLAPACKUnitTests::m
unsigned int m
Definition:
FadLAPACKUnitTests.hpp:97
Sacado::Fad::Vector
A class for storing a contiguously allocated array of Fad objects. This is a general definition that ...
Definition:
Sacado_Fad_Vector.hpp:55
FadLAPACKUnitTests::tearDown
void tearDown()
Definition:
FadLAPACKUnitTests.hpp:137
FadLAPACKUnitTests::l
unsigned int l
Definition:
FadLAPACKUnitTests.hpp:103
Sacado_Random.hpp
Teuchos::LAPACK
n
int n
B
Definition:
ConversionTests.cpp:43
Generated by
1.8.16