From e8dadc37fe4be8e8579374c129e2e84872587860 Mon Sep 17 00:00:00 2001 From: Atell Krasnopolski Date: Tue, 23 Jul 2024 19:57:10 +0200 Subject: [PATCH] Address the reviewers' suggestions --- include/clad/Differentiator/KokkosBuiltins.h | 30 +++++++------ unittests/Kokkos/ViewBasics.cpp | 44 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/include/clad/Differentiator/KokkosBuiltins.h b/include/clad/Differentiator/KokkosBuiltins.h index 181f85b48..b0e81a9b1 100644 --- a/include/clad/Differentiator/KokkosBuiltins.h +++ b/include/clad/Differentiator/KokkosBuiltins.h @@ -40,24 +40,28 @@ inline void deep_copy_pushforward(const View1& dst, const View2& src, T param, } template -inline void -resize_pushforward(View& v, const size_t n0, const size_t n1, const size_t n2, - const size_t n3, const size_t n4, const size_t n5, - const size_t n6, const size_t n7, View& d_v, - const size_t d_n0, const size_t d_n1, const size_t d_n2, - const size_t d_n3, const size_t d_n4, const size_t d_n5, - const size_t d_n6, const size_t d_n7) { +inline void resize_pushforward(View& v, const size_t n0, const size_t n1, + const size_t n2, const size_t n3, + const size_t n4, const size_t n5, + const size_t n6, const size_t n7, View& d_v, + const size_t /*d_n0*/, const size_t /*d_n1*/, + const size_t /*d_n2*/, const size_t /*d_n3*/, + const size_t /*d_n4*/, const size_t /*d_n5*/, + const size_t /*d_n6*/, const size_t /*d_n7*/) { ::Kokkos::resize(v, n0, n1, n2, n3, n4, n5, n6, n7); ::Kokkos::resize(d_v, n0, n1, n2, n3, n4, n5, n6, n7); } template -inline void resize_pushforward( - const I& arg, View& v, const size_t n0, const size_t n1, const size_t n2, - const size_t n3, const size_t n4, const size_t n5, const size_t n6, - const size_t n7, const dI& d_arg, View& d_v, const size_t d_n0, - const size_t d_n1, const size_t d_n2, const size_t d_n3, const size_t d_n4, - const size_t d_n5, const size_t d_n6, const size_t d_n7) { +inline void resize_pushforward(const I& arg, View& v, const size_t n0, + const size_t n1, const size_t n2, + const size_t n3, const size_t n4, + const size_t n5, const size_t n6, + const size_t n7, const dI& d_arg, View& d_v, + const size_t /*d_n0*/, const size_t /*d_n1*/, + const size_t /*d_n2*/, const size_t /*d_n3*/, + const size_t /*d_n4*/, const size_t /*d_n5*/, + const size_t /*d_n6*/, const size_t /*d_n7*/) { ::Kokkos::resize(arg, v, n0, n1, n2, n3, n4, n5, n6, n7); ::Kokkos::resize(arg, d_v, n0, n1, n2, n3, n4, n5, n6, n7); } diff --git a/unittests/Kokkos/ViewBasics.cpp b/unittests/Kokkos/ViewBasics.cpp index 4a78078db..b16e59f90 100644 --- a/unittests/Kokkos/ViewBasics.cpp +++ b/unittests/Kokkos/ViewBasics.cpp @@ -204,4 +204,48 @@ TEST(ViewBasics, TestResize2) { for (double x = 3; x <= 5; x += 1) for (double y = 3; y <= 5; y += 1) EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps); +} + +double f_basics_resize_3(double x, double y) { + Kokkos::View a("a", 3, + 2); + Kokkos::deep_copy(a, 3 * x + y); + + Kokkos::resize(Kokkos::WithoutInitializing, a, 5, 5); + + a(4, 4, 0) = x * y; + + return a(4, 4, 0); +} + +TEST(ViewBasics, TestResize3) { + const double eps = 1e-8; + + auto df = clad::differentiate(f_basics_resize_3, 0); + auto df_true = [](double x, double y) { return y; }; + for (double x = 3; x <= 5; x += 1) + for (double y = 3; y <= 5; y += 1) + EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps); +} + +double f_basics_resize_4(double x, double y) { + Kokkos::View a("a", 3, + 2); + Kokkos::deep_copy(a, 3 * x + y); + + Kokkos::resize(a, 5, 5); + + a(4, 4, 0) = x * y; + + return a(4, 4, 0); +} + +TEST(ViewBasics, TestResize4) { + const double eps = 1e-8; + + auto df = clad::differentiate(f_basics_resize_4, 0); + auto df_true = [](double x, double y) { return y; }; + for (double x = 3; x <= 5; x += 1) + for (double y = 3; y <= 5; y += 1) + EXPECT_NEAR(df.execute(x, y), df_true(x, y), eps); } \ No newline at end of file