57 for (
int i=0;
i<
n;
i++) {
60 a_ls.fastAccessDx(
i) = 1;
64 b_ls.fastAccessDx(
i) = 1;
76 ASSERT_TRUE(x_dfad.hasFastAccess() == x_ls.hasFastAccess());
81 for (
int i=0;
i<x_ls.size();
i++) {
87 compareDx(x_dfad.fastAccessDx(
i), x_ls.fastAccessDx(
i));
106 template <
typename ScalarT>
108 ScalarT t1 = 3. * a +
sin(b) /
log(
fabs(a - b * 7.));
114 t1 /=
cosh(b - 0.7) + 7.*
sinh(t1 + 0.8)*
tanh(9./a) - 9.;
122 #define BINARY_OP_TEST(TESTNAME,OP) \
123 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
124 c_dfad = a_dfad OP b_dfad; \
125 c_ls = a_ls OP b_ls; \
126 compareFads(c_dfad, c_ls); \
128 double val = urand.number(); \
129 c_dfad = a_dfad OP val; \
130 c_ls = a_ls OP val; \
131 compareFads(c_dfad, c_ls); \
133 c_dfad = val OP b_dfad; \
134 c_ls = val OP b_ls; \
135 compareFads(c_dfad, c_ls); \
138 #define RELOP_TEST(TESTNAME,OP) \
139 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
140 bool r1 = a_dfad OP b_dfad; \
141 bool r2 = a_ls OP b_ls; \
142 ASSERT_TRUE(r1 == r2); \
144 double val = urand.number(); \
145 r1 = a_dfad OP val; \
147 ASSERT_TRUE(r1 == r2); \
149 r1 = val OP b_dfad; \
151 ASSERT_TRUE(r1 == r2); \
154 #define BINARY_FUNC_TEST(TESTNAME,FUNC) \
155 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
156 c_dfad = FUNC (a_dfad,b_dfad); \
157 c_ls = FUNC (a_ls,b_ls); \
158 compareFads(c_dfad, c_ls); \
160 double val = urand.number(); \
161 c_dfad = FUNC (a_dfad,val); \
162 c_ls = FUNC (a_ls,val); \
163 compareFads(c_dfad, c_ls); \
165 c_dfad = FUNC (val,b_dfad); \
166 c_ls = FUNC (val,b_ls); \
167 compareFads(c_dfad, c_ls); \
170 #define UNARY_OP_TEST(TESTNAME,OP) \
171 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
172 c_dfad = OP a_dfad; \
174 compareFads(c_dfad, c_ls); \
177 #define UNARY_FUNC_TEST(TESTNAME,FUNC) \
178 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
179 c_dfad = FUNC (a_dfad); \
180 c_ls = FUNC (a_ls); \
181 compareFads(c_dfad, c_ls); \
184 #define UNARY_ASSIGNOP_TEST(TESTNAME,OP) \
185 TEST_F(LogicalSparseOpsUnitTest, TESTNAME) { \
188 compareFads(c_dfad, c_ls); \
190 double val = urand.number(); \
193 compareFads(c_dfad, c_ls); \
235 c_dfad = composite1(a_dfad, b_dfad);
236 c_ls = composite1(a_ls, b_ls);
237 compareFads(c_dfad, c_ls);
245 aa_dfad = aa_dfad + b_dfad;
246 aa_ls = aa_ls + b_ls;
247 compareFads(aa_dfad, aa_ls);
255 aa_dfad = aa_dfad - b_dfad;
256 aa_ls = aa_ls - b_ls;
257 compareFads(aa_dfad, aa_ls);
265 aa_dfad = aa_dfad * b_dfad;
266 aa_ls = aa_ls * b_ls;
267 compareFads(aa_dfad, aa_ls);
275 aa_dfad = aa_dfad / b_dfad;
276 aa_ls = aa_ls / b_ls;
277 compareFads(aa_dfad, aa_ls);
284 LSType aa_ls = a_ls + 1.0;
285 c_ls =
max(aa_ls, a_ls);
286 compareDoubles(c_ls.val(), aa_ls.val());
287 for (
int i=0;
i<
n;
i++) {
288 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
289 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
291 c_ls =
max(a_ls, aa_ls);
292 compareDoubles(c_ls.val(), aa_ls.val());
293 for (
int i=0;
i<n;
i++) {
294 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
295 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
299 c_ls =
max(a_ls+1.0, a_ls);
300 compareDoubles(c_ls.val(), aa_ls.val());
301 for (
int i=0;
i<n;
i++) {
302 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
303 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
305 c_ls =
max(a_ls, a_ls+1.0);
306 compareDoubles(c_ls.val(), aa_ls.val());
307 for (
int i=0;
i<n;
i++) {
308 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
309 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
313 c_ls =
max(a_ls+1.0, a_ls+1.0);
314 compareDoubles(c_ls.val(), aa_ls.val());
315 for (
int i=0;
i<n;
i++) {
316 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
317 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
321 c_ls =
max(a_ls+1.0, a_ls-1.0);
322 compareDoubles(c_ls.val(), aa_ls.val());
323 for (
int i=0;
i<n;
i++) {
324 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
325 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
327 c_ls =
max(a_ls-1.0, a_ls+1.0);
328 compareDoubles(c_ls.val(), aa_ls.val());
329 for (
int i=0;
i<n;
i++) {
330 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
331 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
335 val = a_ls.val() + 1;
336 c_ls =
max(a_ls, val);
337 compareDoubles(c_ls.val(),
val);
338 for (
int i=0;
i<n;
i++)
339 compareBools(c_ls.dx(
i), 0);
340 val = a_ls.val() - 1;
341 c_ls =
max(a_ls, val);
342 compareDoubles(c_ls.val(), a_ls.val());
343 for (
int i=0;
i<n;
i++) {
344 compareBools(c_ls.dx(
i), a_ls.dx(
i));
345 compareBools(c_ls.fastAccessDx(
i), a_ls.fastAccessDx(
i));
347 val = b_ls.val() + 1;
348 c_ls =
max(val, b_ls);
349 compareDoubles(c_ls.val(),
val);
350 for (
int i=0;
i<n;
i++)
351 compareBools(c_ls.dx(
i), 0);
352 val = b_ls.val() - 1;
353 c_ls =
max(val, b_ls);
354 compareDoubles(c_ls.val(), b_ls.val());
355 for (
int i=0;
i<n;
i++) {
356 compareBools(c_ls.dx(
i), b_ls.dx(
i));
357 compareBools(c_ls.fastAccessDx(
i), b_ls.fastAccessDx(
i));
362 c_ls =
max(a_ls+1.0, val);
363 compareDoubles(c_ls.val(), aa_ls.val());
364 for (
int i=0;
i<n;
i++) {
365 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
366 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
368 c_ls =
max(val, a_ls+1.0);
369 compareDoubles(c_ls.val(), aa_ls.val());
370 for (
int i=0;
i<n;
i++) {
371 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
372 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
380 LSType aa_ls = a_ls - 1.0;
381 c_ls =
min(aa_ls, a_ls);
382 compareDoubles(c_ls.val(), aa_ls.val());
383 for (
int i=0;
i<
n;
i++) {
384 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
385 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
387 c_ls =
min(a_ls, aa_ls);
388 compareDoubles(c_ls.val(), aa_ls.val());
389 for (
int i=0;
i<n;
i++) {
390 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
391 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
395 c_ls =
min(a_ls-1.0, a_ls);
396 compareDoubles(c_ls.val(), aa_ls.val());
397 for (
int i=0;
i<n;
i++) {
398 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
399 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
401 c_ls =
min(a_ls, a_ls-1.0);
402 compareDoubles(c_ls.val(), aa_ls.val());
403 for (
int i=0;
i<n;
i++) {
404 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
405 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
409 c_ls =
min(a_ls-1.0, a_ls-1.0);
410 compareDoubles(c_ls.val(), aa_ls.val());
411 for (
int i=0;
i<n;
i++) {
412 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
413 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
417 c_ls =
min(a_ls+1.0, a_ls-1.0);
418 compareDoubles(c_ls.val(), aa_ls.val());
419 for (
int i=0;
i<n;
i++) {
420 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
421 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
423 c_ls =
min(a_ls-1.0, a_ls+1.0);
424 compareDoubles(c_ls.val(), aa_ls.val());
425 for (
int i=0;
i<n;
i++) {
426 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
427 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
431 val = a_ls.val() - 1;
432 c_ls =
min(a_ls, val);
433 compareDoubles(c_ls.val(),
val);
434 for (
int i=0;
i<n;
i++)
435 compareBools(c_ls.dx(
i), 0);
436 val = a_ls.val() + 1;
437 c_ls =
min(a_ls, val);
438 compareDoubles(c_ls.val(), a_ls.val());
439 for (
int i=0;
i<n;
i++) {
440 compareBools(c_ls.dx(
i), a_ls.dx(
i));
441 compareBools(c_ls.fastAccessDx(
i), a_ls.fastAccessDx(
i));
443 val = b_ls.val() - 1;
444 c_ls =
min(val, b_ls);
445 compareDoubles(c_ls.val(),
val);
446 for (
int i=0;
i<n;
i++)
447 compareBools(c_ls.dx(
i), 0);
448 val = b_ls.val() + 1;
449 c_ls =
min(val, b_ls);
450 compareDoubles(c_ls.val(), b_ls.val());
451 for (
int i=0;
i<n;
i++) {
452 compareBools(c_ls.dx(
i), b_ls.dx(
i));
453 compareBools(c_ls.fastAccessDx(
i), b_ls.fastAccessDx(
i));
458 c_ls =
min(a_ls-1.0, val);
459 compareDoubles(c_ls.val(), aa_ls.val());
460 for (
int i=0;
i<n;
i++) {
461 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
462 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
464 c_ls =
min(val, a_ls-1.0);
465 compareDoubles(c_ls.val(), aa_ls.val());
466 for (
int i=0;
i<n;
i++) {
467 compareBools(c_ls.dx(
i), aa_ls.dx(
i));
468 compareBools(c_ls.fastAccessDx(
i), aa_ls.fastAccessDx(
i));
void compareDoubles(double a, double b)
void compareDx(double a, bool b)
#define UNARY_OP_TEST(TESTNAME, OP)
#define BINARY_FUNC_TEST(TESTNAME, FUNC)
LogicalSparseOpsUnitTest()
#define TEST_F(test_fixture, test_name)
Sacado::LFad::LogicalSparse< double, bool > LSType
void compareBools(bool a, bool b)
#define UNARY_FUNC_TEST(TESTNAME, FUNC)
ScalarT number()
Get random number.
ScalarT composite1(const ScalarT &a, const ScalarT &b)
#define ASSERT_TRUE(condition)
#define RELOP_TEST(TESTNAME, OP)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
#define BINARY_OP_TEST(TESTNAME, OP)
Sacado::Fad::DFad< double > DFadType
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SACADO_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
#define UNARY_ASSIGNOP_TEST(TESTNAME, OP)
Sacado::Random< double > urand
void compareFads(const DFadType &x_dfad, const LSType &x_ls)