From bacf477a3e52d37e38cbbe7672e947d4a02f61cc Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Wed, 30 Oct 2024 13:43:28 +0900 Subject: [PATCH] update unit tests for padding --- common/unit_test/Test_Padding.cpp | 280 ++++++++++++++---------------- common/unit_test/Test_Utils.cpp | 53 ++++++ fft/unit_test/Test_Transform.cpp | 98 ++++++----- 3 files changed, 243 insertions(+), 188 deletions(-) diff --git a/common/unit_test/Test_Padding.cpp b/common/unit_test/Test_Padding.cpp index d9823e3..cc2c58f 100644 --- a/common/unit_test/Test_Padding.cpp +++ b/common/unit_test/Test_Padding.cpp @@ -913,7 +913,8 @@ TEST(CropOrPad1D, 1DView) { const int len = 30, len_pad = 32, len_crop = 28; View1D x("x", len); - View1D x_out, x_out_pad, x_out_crop; + View1D x_out("x_out", len), x_out_pad("x_out_pad", len_pad), + x_out_crop("x_out_crop", len_crop); View1D ref_x("ref_x", len), ref_x_pad("ref_x_pad", len_pad), ref_x_crop("ref_x_crop", len_crop); @@ -932,11 +933,9 @@ TEST(CropOrPad1D, 1DView) { auto sub_x = Kokkos::subview(x, range1); Kokkos::deep_copy(ref_x_crop, sub_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_type<1>{len}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad, - shape_type<1>{len_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop, - shape_type<1>{len_crop}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); EXPECT_TRUE(allclose(x_out_pad, ref_x_pad, 1.e-5, 1.e-12)); @@ -948,8 +947,11 @@ TEST(CropOrPad1D, 2DView) { const int n1 = 5, n1_pad = 7, n1_crop = 3; View2D x("x", n0, n1); - View2D x_out, x_out_pad_axis0, x_out_pad_axis1, x_out_crop_axis0, - x_out_crop_axis1; + View2D x_out("x_out", n0, n1), + x_out_pad_axis0("x_out_pad_axis0", n0_pad, n1), + x_out_pad_axis1("x_out_pad_axis1", n0, n1_pad), + x_out_crop_axis0("x_out_crop_axis0", n0_crop, n1), + x_out_crop_axis1("x_out_crop_axis1", n0, n1_crop); View2D ref_x("ref_x", n0, n1), ref_x_pad_axis0("ref_x_pad_axis0", n0_pad, n1), ref_x_crop_axis0("ref_x_crop_axis0", n0_crop, n1); @@ -1002,17 +1004,12 @@ TEST(CropOrPad1D, 2DView) { Kokkos::deep_copy(ref_x_pad_axis1, h_ref_x_pad_axis1); Kokkos::deep_copy(ref_x_crop_axis1, h_ref_x_crop_axis1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, - shape_type<2>{n0, n1}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis0, - shape_type<2>{n0_pad, n1}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis0, - shape_type<2>{n0_crop, n1}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis0); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis0); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis1, - shape_type<2>{n0, n1_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis1, - shape_type<2>{n0, n1_crop}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis1); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); EXPECT_TRUE(allclose(x_out_pad_axis0, ref_x_pad_axis0, 1.e-5, 1.e-12)); @@ -1027,8 +1024,13 @@ TEST(CropOrPad1D, 3DView) { const int n2 = 8, n2_pad = 10, n2_crop = 6; View3D x("x", n0, n1, n2); - View3D x_out, x_out_pad_axis0, x_out_crop_axis0, x_out_pad_axis1, - x_out_crop_axis1, x_out_pad_axis2, x_out_crop_axis2; + View3D x_out("x_out", n0, n1, n2), + x_out_pad_axis0("x_out_pad_axis0", n0_pad, n1, n2), + x_out_crop_axis0("x_out_crop_axis0", n0_crop, n1, n2), + x_out_pad_axis1("x_out_pad_axis1", n0, n1_pad, n2), + x_out_crop_axis1("x_out_crop_axis1", n0, n1_crop, n2), + x_out_pad_axis2("x_out_pad_axis2", n0, n1, n2_pad), + x_out_crop_axis2("x_out_crop_axis2", n0, n1, n2_crop); View3D ref_x("ref_x", n0, n1, n2), ref_x_pad_axis0("ref_x_pad_axis0", n0_pad, n1, n2), ref_x_crop_axis0("ref_x_crop_axis0", n0_crop, n1, n2); @@ -1109,22 +1111,15 @@ TEST(CropOrPad1D, 3DView) { Kokkos::deep_copy(ref_x_pad_axis2, h_ref_x_pad_axis2); Kokkos::deep_copy(ref_x_crop_axis2, h_ref_x_crop_axis2); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, - shape_type<3>{n0, n1, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis0, - shape_type<3>{n0_pad, n1, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis0, - shape_type<3>{n0_crop, n1, n2}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis0); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis0); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis1, - shape_type<3>{n0, n1_pad, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis1, - shape_type<3>{n0, n1_crop, n2}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis2, - shape_type<3>{n0, n1, n2_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis2, - shape_type<3>{n0, n1, n2_crop}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_pad_axis2); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_crop_axis2); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); EXPECT_TRUE(allclose(x_out_pad_axis0, ref_x_pad_axis0, 1.e-5, 1.e-12)); @@ -1140,8 +1135,14 @@ TEST(CropOrPad2D, 2DView) { const int n1 = 5, n1_pad = 7, n1_crop = 3; View2D x("x", n0, n1); - View2D x_out, x_out_0_1p, x_out_0_1c, x_out_0p_1, x_out_0p_1p, - x_out_0p_1c, x_out_0c_1, x_out_0c_1p, x_out_0c_1c; + View2D x_out("x_out", n0, n1), x_out_0_1p("x_out_0_1p", n0, n1_pad), + x_out_0_1c("x_out_0_1c", n0, n1_crop), + x_out_0p_1("x_out_0p_1", n0_pad, n1), + x_out_0p_1p("x_out_0p_1p", n0_pad, n1_pad), + x_out_0p_1c("x_out_0p_1c", n0_pad, n1_crop), + x_out_0c_1("x_out_0c_1", n0_crop, n1), + x_out_0c_1p("x_out_0c_1p", n0_crop, n1_pad), + x_out_0c_1c("x_out_0c_1c", n0_crop, n1_crop); View2D ref_x("ref_x", n0, n1), ref_x_0_1p("ref_x_0_1p", n0, n1_pad), ref_x_0_1c("ref_x_0_1c", n0, n1_crop); View2D ref_x_0p_1("ref_x_0p_1", n0_pad, n1), @@ -1215,24 +1216,15 @@ TEST(CropOrPad2D, 2DView) { Kokkos::deep_copy(ref_x_0c_1p, h_ref_x_0c_1p); Kokkos::deep_copy(ref_x_0c_1c, h_ref_x_0c_1c); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, - shape_type<2>{n0, n1}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1p, - shape_type<2>{n0, n1_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1c, - shape_type<2>{n0, n1_crop}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1, - shape_type<2>{n0_pad, n1}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1p, - shape_type<2>{n0_pad, n1_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1c, - shape_type<2>{n0_pad, n1_crop}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1, - shape_type<2>{n0_crop, n1}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1p, - shape_type<2>{n0_crop, n1_pad}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1c, - shape_type<2>{n0_crop, n1_crop}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1c); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1c); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1c); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); EXPECT_TRUE(allclose(x_out_0_1p, ref_x_0_1p, 1.e-5, 1.e-12)); @@ -1251,8 +1243,15 @@ TEST(CropOrPad2D, 3DView) { const int n2 = 8; View3D x("x", n0, n1, n2); - View3D x_out, x_out_0_1p, x_out_0_1c, x_out_0p_1, x_out_0p_1p, - x_out_0p_1c, x_out_0c_1, x_out_0c_1p, x_out_0c_1c; + View3D x_out("x_out", n0, n1, n2), + x_out_0_1p("x_out_0_1p", n0, n1_pad, n2), + x_out_0_1c("x_out_0_1c", n0, n1_crop, n2), + x_out_0p_1("x_out_0p_1", n0_pad, n1, n2), + x_out_0p_1p("x_out_0p_1p", n0_pad, n1_pad, n2), + x_out_0p_1c("x_out_0p_1c", n0_pad, n1_crop, n2), + x_out_0c_1("x_out_0c_1", n0_crop, n1, n2), + x_out_0c_1p("x_out_0c_1p", n0_crop, n1_pad, n2), + x_out_0c_1c("x_out_0c_1c", n0_crop, n1_crop, n2); View3D ref_x("ref_x", n0, n1, n2), ref_x_0_1p("ref_x_0_1p", n0, n1_pad, n2), ref_x_0_1c("ref_x_0_1c", n0, n1_crop, n2); @@ -1329,24 +1328,15 @@ TEST(CropOrPad2D, 3DView) { Kokkos::deep_copy(ref_x_0c_1p, h_ref_x_0c_1p); Kokkos::deep_copy(ref_x_0c_1c, h_ref_x_0c_1c); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, - shape_type<3>{n0, n1, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1p, - shape_type<3>{n0, n1_pad, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1c, - shape_type<3>{n0, n1_crop, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1, - shape_type<3>{n0_pad, n1, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1p, - shape_type<3>{n0_pad, n1_pad, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1c, - shape_type<3>{n0_pad, n1_crop, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1, - shape_type<3>{n0_crop, n1, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1p, - shape_type<3>{n0_crop, n1_pad, n2}); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1c, - shape_type<3>{n0_crop, n1_crop, n2}); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0_1c); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0p_1c); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1p); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out_0c_1c); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); EXPECT_TRUE(allclose(x_out_0_1p, ref_x_0_1p, 1.e-5, 1.e-12)); @@ -1371,12 +1361,11 @@ TEST(CropOrPad3D, 3DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - shape_type<3> shape_new = {n0_new, n1_new, n2_new}; + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); - View3D x_out; + View3D x_out("x_out", n0_new, n1_new, n2_new); View3D ref_x("ref_x", n0_new, n1_new, n2_new); auto h_ref_x = Kokkos::create_mirror_view(ref_x); @@ -1393,7 +1382,7 @@ TEST(CropOrPad3D, 3DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } @@ -1415,14 +1404,13 @@ TEST(CropOrPad4D, 4DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - int d3 = rand_dist(rand_engine); - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - std::size_t n3_new = static_cast(n3 + d3); - shape_type<4> shape_new = {n0_new, n1_new, n2_new, n3_new}; - - View4D x_out; + int d3 = rand_dist(rand_engine); + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); + std::size_t n3_new = static_cast(n3 + d3); + + View4D x_out("x_out", n0_new, n1_new, n2_new, n3_new); View4D ref_x("ref_x", n0_new, n1_new, n2_new, n3_new); auto h_ref_x = Kokkos::create_mirror_view(ref_x); @@ -1443,7 +1431,7 @@ TEST(CropOrPad4D, 4DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } @@ -1465,16 +1453,15 @@ TEST(CropOrPad5D, 5DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - int d3 = rand_dist(rand_engine); - int d4 = rand_dist(rand_engine); - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - std::size_t n3_new = static_cast(n3 + d3); - std::size_t n4_new = static_cast(n4 + d4); - shape_type<5> shape_new = {n0_new, n1_new, n2_new, n3_new, n4_new}; - - View5D x_out; + int d3 = rand_dist(rand_engine); + int d4 = rand_dist(rand_engine); + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); + std::size_t n3_new = static_cast(n3 + d3); + std::size_t n4_new = static_cast(n4 + d4); + + View5D x_out("x_out", n0_new, n1_new, n2_new, n3_new, n4_new); View5D ref_x("ref_x", n0_new, n1_new, n2_new, n3_new, n4_new); auto h_ref_x = Kokkos::create_mirror_view(ref_x); @@ -1497,7 +1484,7 @@ TEST(CropOrPad5D, 5DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } @@ -1519,19 +1506,18 @@ TEST(CropOrPad6D, 6DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - int d3 = rand_dist(rand_engine); - int d4 = rand_dist(rand_engine); - int d5 = rand_dist(rand_engine); - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - std::size_t n3_new = static_cast(n3 + d3); - std::size_t n4_new = static_cast(n4 + d4); - std::size_t n5_new = static_cast(n5 + d5); - shape_type<6> shape_new = {n0_new, n1_new, n2_new, - n3_new, n4_new, n5_new}; - - View6D x_out; + int d3 = rand_dist(rand_engine); + int d4 = rand_dist(rand_engine); + int d5 = rand_dist(rand_engine); + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); + std::size_t n3_new = static_cast(n3 + d3); + std::size_t n4_new = static_cast(n4 + d4); + std::size_t n5_new = static_cast(n5 + d5); + + View6D x_out("x_out", n0_new, n1_new, n2_new, n3_new, n4_new, + n5_new); View6D ref_x("ref_x", n0_new, n1_new, n2_new, n3_new, n4_new, n5_new); @@ -1559,7 +1545,7 @@ TEST(CropOrPad6D, 6DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } @@ -1581,21 +1567,20 @@ TEST(CropOrPad7D, 7DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - int d3 = rand_dist(rand_engine); - int d4 = rand_dist(rand_engine); - int d5 = rand_dist(rand_engine); - int d6 = rand_dist(rand_engine); - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - std::size_t n3_new = static_cast(n3 + d3); - std::size_t n4_new = static_cast(n4 + d4); - std::size_t n5_new = static_cast(n5 + d5); - std::size_t n6_new = static_cast(n6 + d6); - shape_type<7> shape_new = {n0_new, n1_new, n2_new, n3_new, - n4_new, n5_new, n6_new}; - - View7D x_out; + int d3 = rand_dist(rand_engine); + int d4 = rand_dist(rand_engine); + int d5 = rand_dist(rand_engine); + int d6 = rand_dist(rand_engine); + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); + std::size_t n3_new = static_cast(n3 + d3); + std::size_t n4_new = static_cast(n4 + d4); + std::size_t n5_new = static_cast(n5 + d5); + std::size_t n6_new = static_cast(n6 + d6); + + View7D x_out("x_out", n0_new, n1_new, n2_new, n3_new, n4_new, + n5_new, n6_new); View7D ref_x("ref_x", n0_new, n1_new, n2_new, n3_new, n4_new, n5_new, n6_new); @@ -1626,7 +1611,7 @@ TEST(CropOrPad7D, 7DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } @@ -1648,23 +1633,22 @@ TEST(CropOrPad8D, 8DView) { for (int d0 = -1; d0 <= 1; d0++) { for (int d1 = -1; d1 <= 1; d1++) { for (int d2 = -1; d2 <= 1; d2++) { - int d3 = rand_dist(rand_engine); - int d4 = rand_dist(rand_engine); - int d5 = rand_dist(rand_engine); - int d6 = rand_dist(rand_engine); - int d7 = rand_dist(rand_engine); - std::size_t n0_new = static_cast(n0 + d0); - std::size_t n1_new = static_cast(n1 + d1); - std::size_t n2_new = static_cast(n2 + d2); - std::size_t n3_new = static_cast(n3 + d3); - std::size_t n4_new = static_cast(n4 + d4); - std::size_t n5_new = static_cast(n5 + d5); - std::size_t n6_new = static_cast(n6 + d6); - std::size_t n7_new = static_cast(n7 + d7); - shape_type<8> shape_new = {n0_new, n1_new, n2_new, n3_new, - n4_new, n5_new, n6_new, n7_new}; - - View8D x_out; + int d3 = rand_dist(rand_engine); + int d4 = rand_dist(rand_engine); + int d5 = rand_dist(rand_engine); + int d6 = rand_dist(rand_engine); + int d7 = rand_dist(rand_engine); + std::size_t n0_new = static_cast(n0 + d0); + std::size_t n1_new = static_cast(n1 + d1); + std::size_t n2_new = static_cast(n2 + d2); + std::size_t n3_new = static_cast(n3 + d3); + std::size_t n4_new = static_cast(n4 + d4); + std::size_t n5_new = static_cast(n5 + d5); + std::size_t n6_new = static_cast(n6 + d6); + std::size_t n7_new = static_cast(n7 + d7); + + View8D x_out("x_out", n0_new, n1_new, n2_new, n3_new, n4_new, + n5_new, n6_new, n7_new); View8D ref_x("ref_x", n0_new, n1_new, n2_new, n3_new, n4_new, n5_new, n6_new, n7_new); @@ -1698,7 +1682,7 @@ TEST(CropOrPad8D, 8DView) { } Kokkos::deep_copy(ref_x, h_ref_x); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out, shape_new); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, x_out); EXPECT_TRUE(allclose(x_out, ref_x, 1.e-5, 1.e-12)); } } diff --git a/common/unit_test/Test_Utils.cpp b/common/unit_test/Test_Utils.cpp index 48dbcff..b768adb 100644 --- a/common/unit_test/Test_Utils.cpp +++ b/common/unit_test/Test_Utils.cpp @@ -526,6 +526,59 @@ TEST(ExtractExtents, 1Dto8D) { EXPECT_EQ(KokkosFFT::Impl::extract_extents(view8D), ref_extents8D); } +TEST(ShrankExtents, 1Dto8D) { + using View1Dtype = Kokkos::View; + using View2Dtype = Kokkos::View; + using View3Dtype = Kokkos::View; + using View4Dtype = Kokkos::View; + using View5Dtype = Kokkos::View; + using View6Dtype = Kokkos::View; + using View7Dtype = Kokkos::View; + using View8Dtype = Kokkos::View; + + std::size_t n1 = 1, n2 = 1, n3 = 2, n4 = 3, n5 = 5, n6 = 8, n7 = 13, n8 = 21; + std::size_t s1 = 21, s2 = 13, s3 = 8, s4 = 5, s5 = 3, s6 = 2, s7 = 1, s8 = 1; + + View1Dtype in1D("in1D", n1), out1D("out1D", s1); + View2Dtype in2D("in2D", n1, n2), out2D("out2D", s1, s2); + View3Dtype in3D("in3D", n1, n2, n3), out3D("out3D", s1, s2, s3); + View4Dtype in4D("in4D", n1, n2, n3, n4), out4D("out4D", s1, s2, s3, s4); + View5Dtype in5D("in5D", n1, n2, n3, n4, n5), + out5D("out5D", s1, s2, s3, s4, s5); + View6Dtype in6D("in6D", n1, n2, n3, n4, n5, n6), + out6D("out6D", s1, s2, s3, s4, s5, s6); + View7Dtype in7D("in7D", n1, n2, n3, n4, n5, n6, n7), + out7D("out7D", s1, s2, s3, s4, s5, s6, s7); + View8Dtype in8D("in8D", n1, n2, n3, n4, n5, n6, n7, n8), + out8D("out8D", s1, s2, s3, s4, s5, s6, s7, s8); + + std::array ref_extents1D = {n1}; + std::array ref_extents2D = {n1, n2}; + std::array ref_extents3D = {n1, n2, n3}; + std::array ref_extents4D = {n1, n2, n3, n4}; + std::array ref_extents5D = {n1, n2, n3, n4, s5}; + std::array ref_extents6D = {n1, n2, n3, n4, s5, s6}; + std::array ref_extents7D = {n1, n2, n3, n4, s5, s6, s7}; + std::array ref_extents8D = {n1, n2, n3, n4, s5, s6, s7, s8}; + + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in1D, out1D), + ref_extents1D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in2D, out2D), + ref_extents2D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in3D, out3D), + ref_extents3D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in4D, out4D), + ref_extents4D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in5D, out5D), + ref_extents5D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in6D, out6D), + ref_extents6D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in7D, out7D), + ref_extents7D); + EXPECT_EQ(KokkosFFT::Impl::shrank_extents(in8D, out8D), + ref_extents8D); +} + TEST(IndexSequence, 3Dto5D) { using View3Dtype = Kokkos::View; using View4Dtype = Kokkos::View; diff --git a/fft/unit_test/Test_Transform.cpp b/fft/unit_test/Test_Transform.cpp index e95539c..1a79353 100644 --- a/fft/unit_test/Test_Transform.cpp +++ b/fft/unit_test/Test_Transform.cpp @@ -920,9 +920,11 @@ void test_fft1_1dfft_5dview(T atol = 1.e-12) { auto [s0, s1, s2, s3, s4] = shape; auto [sr0, sr1, sr2, sr3, sr4] = shape_c2r; ComplexView5DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4), - x_hat("x_hat", s0, s1, s2, s3, s4), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4), + ref_x("ref_x", s0, s1, s2, s3, s4); RealView5DType xr("xr", s0, s1, s2, s3, s4), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4), + ref_xr("ref_xr", s0, s1, s2, s3, s4); ComplexView5DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4); const Kokkos::complex z(1.0, 1.0); @@ -930,8 +932,8 @@ void test_fft1_1dfft_5dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -975,9 +977,11 @@ void test_fft1_1dfft_6dview(T atol = 1.e-12) { auto [s0, s1, s2, s3, s4, s5] = shape; auto [sr0, sr1, sr2, sr3, sr4, sr5] = shape_c2r; ComplexView6DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5), - x_hat("x_hat", s0, s1, s2, s3, s4, s5), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5), + ref_x("ref_x", s0, s1, s2, s3, s4, s5); RealView6DType xr("xr", s0, s1, s2, s3, s4, s5), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5); ComplexView6DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5); const Kokkos::complex z(1.0, 1.0); @@ -985,8 +989,8 @@ void test_fft1_1dfft_6dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -1030,9 +1034,11 @@ void test_fft1_1dfft_7dview(T atol = 1.e-12) { auto [s0, s1, s2, s3, s4, s5, s6] = shape; auto [sr0, sr1, sr2, sr3, sr4, sr5, sr6] = shape_c2r; ComplexView7DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5, s6), - x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6), + ref_x("ref_x", s0, s1, s2, s3, s4, s5, s6); RealView7DType xr("xr", s0, s1, s2, s3, s4, s5, s6), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5, s6); ComplexView7DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5, sr6); const Kokkos::complex z(1.0, 1.0); @@ -1040,8 +1046,8 @@ void test_fft1_1dfft_7dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -1085,9 +1091,11 @@ void test_fft1_1dfft_8dview(T atol = 1.e-12) { auto [s0, s1, s2, s3, s4, s5, s6, s7] = shape; auto [sr0, sr1, sr2, sr3, sr4, sr5, sr6, sr7] = shape_c2r; ComplexView8DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5, s6, s7), - x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6, s7), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6, s7), + ref_x("ref_x", s0, s1, s2, s3, s4, s5, s6, s7); RealView8DType xr("xr", s0, s1, s2, s3, s4, s5, s6, s7), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6, s7), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6, s7), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5, s6, s7); ComplexView8DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5, sr6, sr7); @@ -1096,8 +1104,8 @@ void test_fft1_1dfft_8dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -1814,9 +1822,10 @@ void test_fft2_2dfft_3dview(T atol = 1.e-12) { auto [sr0, sr1, sr2] = shape_c2r; ComplexView3DType inv_x_hat("inv_x_hat", s0, s1, s2), - x_hat("x_hat", s0, s1, s2), ref_x; + x_hat("x_hat", s0, s1, s2), ref_x("ref_x", s0, s1, s2); RealView3DType xr("xr", s0, s1, s2), - inv_xr_hat("inv_xr_hat", s0, s1, s2), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2), + ref_xr("ref_xr", s0, s1, s2); ComplexView3DType xr_hat("xr_hat", sr0, sr1, sr2); const Kokkos::complex z(1.0, 1.0); @@ -1824,8 +1833,8 @@ void test_fft2_2dfft_3dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -1893,9 +1902,10 @@ void test_fft2_2dfft_4dview(T atol = 1.e-12) { auto [sr0, sr1, sr2, sr3] = shape_c2r; ComplexView4DType inv_x_hat("inv_x_hat", s0, s1, s2, s3), - x_hat("x_hat", s0, s1, s2, s3), ref_x; + x_hat("x_hat", s0, s1, s2, s3), ref_x("ref_x", s0, s1, s2, s3); RealView4DType xr("xr", s0, s1, s2, s3), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3), + ref_xr("ref_xr", s0, s1, s2, s3); ComplexView4DType xr_hat("xr_hat", sr0, sr1, sr2, sr3); const Kokkos::complex z(1.0, 1.0); @@ -1903,8 +1913,8 @@ void test_fft2_2dfft_4dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -1972,9 +1982,11 @@ void test_fft2_2dfft_5dview(T atol = 1.e-12) { auto [sr0, sr1, sr2, sr3, sr4] = shape_c2r; ComplexView5DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4), - x_hat("x_hat", s0, s1, s2, s3, s4), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4), + ref_x("ref_x", s0, s1, s2, s3, s4); RealView5DType xr("xr", s0, s1, s2, s3, s4), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4), + ref_xr("ref_xr", s0, s1, s2, s3, s4); ComplexView5DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4); const Kokkos::complex z(1.0, 1.0); @@ -1982,8 +1994,8 @@ void test_fft2_2dfft_5dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -2051,9 +2063,11 @@ void test_fft2_2dfft_6dview(T atol = 1.e-12) { auto [sr0, sr1, sr2, sr3, sr4, sr5] = shape_c2r; ComplexView6DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5), - x_hat("x_hat", s0, s1, s2, s3, s4, s5), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5), + ref_x("ref_x", s0, s1, s2, s3, s4, s5); RealView6DType xr("xr", s0, s1, s2, s3, s4, s5), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5); ComplexView6DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5); const Kokkos::complex z(1.0, 1.0); @@ -2061,8 +2075,8 @@ void test_fft2_2dfft_6dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -2129,10 +2143,12 @@ void test_fft2_2dfft_7dview(T atol = 1.e-12) { auto [sr0, sr1, sr2, sr3, sr4, sr5, sr6] = shape_c2r; ComplexView7DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5, s6), - x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6), + ref_x("ref_x", s0, s1, s2, s3, s4, s5, s6); RealView7DType xr("xr", s0, s1, s2, s3, s4, s5, s6), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5, s6); ComplexView7DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5, sr6); @@ -2141,8 +2157,8 @@ void test_fft2_2dfft_7dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence(); @@ -2210,10 +2226,12 @@ void test_fft2_2dfft_8dview(T atol = 1.e-12) { ComplexView8DType inv_x_hat("inv_x_hat", s0, s1, s2, s3, s4, s5, s6, s7), - x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6, s7), ref_x; + x_hat("x_hat", s0, s1, s2, s3, s4, s5, s6, s7), + ref_x("ref_x", s0, s1, s2, s3, s4, s5, s6, s7); RealView8DType xr("xr", s0, s1, s2, s3, s4, s5, s6, s7), - inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6, s7), ref_xr; + inv_xr_hat("inv_xr_hat", s0, s1, s2, s3, s4, s5, s6, s7), + ref_xr("ref_xr", s0, s1, s2, s3, s4, s5, s6, s7); ComplexView8DType xr_hat("xr_hat", sr0, sr1, sr2, sr3, sr4, sr5, sr6, sr7); @@ -2223,8 +2241,8 @@ void test_fft2_2dfft_8dview(T atol = 1.e-12) { Kokkos::fill_random(x, random_pool, z); Kokkos::fill_random(xr, random_pool, 1); - KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x, shape); - KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr, shape); + KokkosFFT::Impl::crop_or_pad(execution_space(), x, ref_x); + KokkosFFT::Impl::crop_or_pad(execution_space(), xr, ref_xr); Kokkos::fence();