34 template <
typename FadType1,
typename FadType2>
35 bool checkFads(
const FadType1& x,
const FadType2& x2,
47 for (
int i=0; i<x.size(); ++i)
53 template <
typename FadType1,
typename FadType2>
63 success = success &&
checkFads(x.val(), x2.val(), out,
tol);
66 for (
int i=0; i<x.size(); ++i)
67 success = success &&
checkFads(x.dx(i), x2.dx(i), out,
tol);
72 template <
typename fadfadtype,
typename ordinal>
75 const ordinal num_cols,
76 const ordinal outer_fad_size,
77 const ordinal inner_fad_size,
81 typedef typename fadfadtype::value_type fadtype;
82 typedef typename fadtype::value_type scalar;
83 fadfadtype x(outer_fad_size, scalar(0.0));
84 fadtype y(inner_fad_size, scalar(0.0));
86 const scalar x_row = 1000.0 + scalar(num_rows) / scalar(row+1);
87 const scalar x_col = 100.0 + scalar(num_cols) / scalar(col+1);
88 y.val() = x_row + x_col;
89 for (ordinal j=0; j<inner_fad_size; ++j) {
90 const scalar y_fad = 1.0 + scalar(inner_fad_size) / scalar(j+1);
91 y.fastAccessDx(j) = x_row + x_col + y_fad;
94 for (ordinal i=0; i<outer_fad_size; ++i) {
95 const scalar x_fad = 10.0 + scalar(outer_fad_size) / scalar(i+1);
97 for (ordinal j=0; j<inner_fad_size; ++j) {
98 const scalar y_fad = 1.0 + scalar(inner_fad_size) / scalar(j+1);
99 y.fastAccessDx(j) = x_row + x_col + x_fad + y_fad;
101 x.fastAccessDx(i) = y;
112 Kokkos_View_FadFad, DeepCopy, FadFadType, Layout, Device )
114 typedef Kokkos::View<FadFadType**,Layout,Device> ViewType;
115 typedef typename ViewType::size_type size_type;
116 typedef typename ViewType::HostMirror host_view_type;
124 ViewType v1(
"view1", num_rows, num_cols, outer_fad_size+1);
125 host_view_type h_v1 = Kokkos::create_mirror_view(v1);
126 for (size_type i=0; i<num_rows; ++i)
127 for (size_type j=0; j<num_cols; ++j)
128 h_v1(i,j) = generate_nested_fad<FadFadType>(num_rows,
133 Kokkos::deep_copy(v1, h_v1);
136 ViewType v2(
"view2", num_rows, num_cols, outer_fad_size+1);
137 Kokkos::deep_copy(v2, v1);
140 host_view_type h_v2 = Kokkos::create_mirror_view(v2);
141 Kokkos::deep_copy(h_v2, v2);
145 for (size_type i=0; i<num_rows; ++i) {
146 for (size_type j=0; j<num_cols; ++j) {
147 FadFadType
f = generate_nested_fad<FadFadType>(num_rows,
157 #ifdef HAVE_SACADO_KOKKOSCONTAINERS
160 Kokkos_DynRankView_FadFad, DeepCopy, FadFadType, Layout, Device )
162 typedef Kokkos::DynRankView<FadFadType,Layout,Device> ViewType;
163 typedef typename ViewType::size_type size_type;
164 typedef typename ViewType::HostMirror host_view_type;
172 ViewType v1(
"view1", num_rows, num_cols, outer_fad_size+1);
173 host_view_type h_v1 = Kokkos::create_mirror_view(v1);
174 for (size_type i=0; i<num_rows; ++i)
175 for (size_type j=0; j<num_cols; ++j)
176 h_v1(i,j) = generate_nested_fad<FadFadType>(num_rows,
181 Kokkos::deep_copy(v1, h_v1);
184 ViewType v2(
"view2", num_rows, num_cols, outer_fad_size+1);
185 Kokkos::deep_copy(v2, v1);
188 host_view_type h_v2 = Kokkos::create_mirror_view(v2);
189 Kokkos::deep_copy(h_v2, v2);
193 for (size_type i=0; i<num_rows; ++i) {
194 for (size_type j=0; j<num_cols; ++j) {
195 FadFadType
f = generate_nested_fad<FadFadType>(num_rows,
209 Kokkos_DynRankView_FadFad, Interop, FadFadType, Layout, Device )
211 typedef Kokkos::DynRankView<FadFadType,Layout,Device> DRViewType;
212 typedef typename DRViewType::size_type size_type;
213 typedef typename DRViewType::HostMirror host_view_type;
215 typedef Kokkos::View<FadFadType**,Layout,Device> NoDynViewType;
216 typedef typename NoDynViewType::HostMirror host_nondynrankview_type;
224 DRViewType v1(
"drview1", num_rows, num_cols, outer_fad_size+1);
225 host_view_type h_v1 = Kokkos::create_mirror_view(v1);
227 NoDynViewType ndv2(
"nodview2", num_rows, num_cols, outer_fad_size+1);
228 host_nondynrankview_type h_ndv2 = Kokkos::create_mirror_view(ndv2);
230 for (size_type i=0; i<num_rows; ++i)
231 for (size_type j=0; j<num_cols; ++j)
232 h_v1(i,j) = generate_nested_fad<FadFadType>(num_rows,
237 Kokkos::deep_copy(v1, h_v1);
240 Kokkos::deep_copy(ndv2, h_v1);
242 DRViewType v2(
"drview2", num_rows, num_cols, outer_fad_size+1);
246 host_view_type h_v2 = Kokkos::create_mirror_view(v2);
247 Kokkos::deep_copy(h_v2, v2);
251 for (size_type i=0; i<num_rows; ++i) {
252 for (size_type j=0; j<num_cols; ++j) {
253 FadFadType
f = generate_nested_fad<FadFadType>(num_rows,
267 Kokkos_DynRankView_FadFad, Interop2, FadFadType, Layout, Device )
269 typedef Kokkos::DynRankView<FadFadType,Layout,Device> DRViewType;
270 typedef typename DRViewType::size_type size_type;
271 typedef typename DRViewType::HostMirror host_view_type;
273 typedef Kokkos::View<FadFadType**,Layout,Device> NoDynViewType;
274 typedef typename NoDynViewType::HostMirror host_nondynrankview_type;
282 DRViewType v1(
"drview1", num_rows, num_cols, outer_fad_size+1);
283 host_view_type h_v1 = Kokkos::create_mirror_view(v1);
285 NoDynViewType ndv2(
"nodview2", num_rows, num_cols, outer_fad_size+1);
286 host_nondynrankview_type h_ndv2 = Kokkos::create_mirror_view(ndv2);
288 for (size_type i=0; i<num_rows; ++i)
289 for (size_type j=0; j<num_cols; ++j)
290 h_v1(i,j) = generate_nested_fad<FadFadType>(num_rows,
295 Kokkos::deep_copy(v1, h_v1);
298 Kokkos::deep_copy(ndv2, h_v1);
300 DRViewType v2(ndv2) ;
303 host_view_type h_v2 = Kokkos::create_mirror_view(v2);
304 Kokkos::deep_copy(h_v2, v2);
308 for (size_type i=0; i<num_rows; ++i) {
309 for (size_type j=0; j<num_cols; ++j) {
310 FadFadType
f = generate_nested_fad<FadFadType>(num_rows,
325 Kokkos_DynRankView_FadFad, DeepCopy, FadFadType, Layout, Device ) {}
327 Kokkos_DynRankView_FadFad, Interop, FadFadType, Layout, Device ) {}
329 Kokkos_DynRankView_FadFad, Interop2, FadFadType, Layout, Device ) {}
333 #define VIEW_FAD_TESTS_FLD( F, L, D ) \
334 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_View_FadFad, DeepCopy, F, L, D ) \
335 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_DynRankView_FadFad, DeepCopy, F, L, D ) \
336 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_DynRankView_FadFad, Interop, F, L, D ) \
337 TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT( Kokkos_DynRankView_FadFad, Interop2, F, L, D )
339 #define VIEW_FAD_TESTS_FD( F, D ) \
340 using Kokkos::LayoutLeft; \
341 using Kokkos::LayoutRight; \
342 VIEW_FAD_TESTS_FLD( F, LayoutLeft, D) \
343 VIEW_FAD_TESTS_FLD( F, LayoutRight, D)
354 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
356 #define VIEW_FAD_TESTS_D( D ) \
357 VIEW_FAD_TESTS_FD( SFadType, D ) \
358 VIEW_FAD_TESTS_FD( SLFadType, D ) \
359 VIEW_FAD_TESTS_FD( DFadType, D )
361 #define VIEW_FAD_TESTS_D( D ) \
362 VIEW_FAD_TESTS_FD( SFadType, D ) \
363 VIEW_FAD_TESTS_FD( SLFadType, D )
366 #define VIEW_FAD_TESTS_D( D )
Sacado::Fad::SFad< InnerFadType, global_outer_fad_size > SFadType
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
Sacado::Fad::DFad< double > DFadType
bool checkFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
const int global_num_rows
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(Kokkos_View_FadFad, DeepCopy, FadFadType, Layout, Device)
const int global_num_cols
Sacado::Fad::SLFad< InnerFadType, 2 *global_outer_fad_size > SLFadType
const int global_inner_fad_size
#define TEUCHOS_TEST_EQUALITY(v1, v2, out, success)
Sacado::Fad::SFad< double, global_inner_fad_size > InnerFadType
bool checkNestedFads(const FadType1 &x, const FadType2 &x2, Teuchos::FancyOStream &out, double tol=1.0e-15)
const int global_outer_fad_size
fadfadtype generate_nested_fad(const ordinal num_rows, const ordinal num_cols, const ordinal outer_fad_size, const ordinal inner_fad_size, const ordinal row, const ordinal col)