static bool isnaninf(const FadType& x) { if (Teuchos::ScalarTraits<ValueT>::isnaninf(x.val())) return true; for (int i=0; i<x.size(); i++) if (Teuchos::ScalarTraits<ValueT>::isnaninf(x.dx(i))) return true; return false; }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( Kokkos_View_Fad, UnmanagedConst, FadType, Layout, Device ) { typedef typename FadType::value_type scalar_type; typedef typename ApplyView<scalar_type***,Layout,Device>::type ViewType; typedef typename ApplyView<const scalar_type***,Layout,Device>::type ConstViewType; typedef typename ApplyView<FadType**,Layout,Device,Kokkos::MemoryUnmanaged>::type FadViewType; typedef typename ApplyView<const FadType**,Layout,Device,Kokkos::MemoryUnmanaged>::type ConstFadViewType; typedef typename ViewType::size_type size_type; typedef typename ViewType::HostMirror host_view_type; typedef typename FadViewType::HostMirror fad_host_view_type; const size_type num_rows = global_num_rows; const size_type num_cols = global_num_cols; const size_type fad_size = global_fad_size; // Create and fill view ViewType v("view", num_rows, num_cols, fad_size+1); host_view_type h_v = Kokkos::create_mirror_view(v); for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); for (size_type k=0; k<fad_size; k++) h_v(i,j,k) = f.dx(k); h_v(i,j,fad_size) = f.val(); } } Kokkos::deep_copy(v, h_v); ConstViewType v_const = v; // Create unmanaged view ConstFadViewType v_fad( v_const.ptr_on_device(), num_rows, num_cols, fad_size+1); // Copy back -- can't use create_mirror_view() because v_fad is unmanaged fad_host_view_type h_v_fad("host_view_fad", num_rows, num_cols, fad_size+1); Kokkos::deep_copy(h_v_fad, v_fad); // Check success = true; for (size_type i=0; i<num_rows; ++i) { for (size_type j=0; j<num_cols; ++j) { FadType f = generate_fad<FadType>(num_rows, num_cols, fad_size, i, j); success = success && checkFads(f, h_v_fad(i,j), out); } } }