From aae8c3f54cfc99a270127faa4510f946f804f63d Mon Sep 17 00:00:00 2001 From: Yuuichi Asahi Date: Thu, 26 Sep 2024 02:09:06 +0900 Subject: [PATCH] Recover fftn tests with given axes --- fft/unit_test/Test_Transform.cpp | 71 ++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/fft/unit_test/Test_Transform.cpp b/fft/unit_test/Test_Transform.cpp index c34da843..cdaaedd5 100644 --- a/fft/unit_test/Test_Transform.cpp +++ b/fft/unit_test/Test_Transform.cpp @@ -2304,7 +2304,7 @@ void test_fftn_2dfft_2dview() { ComplexView2DType x("x", n0, n1); ComplexView2DType out("out", n0, n1), out1("out1", n0, n1), - out2("out2", n0, n1); + out2("out2", n0, n1), out_no_axes("out_no_axes", n0, n1); ComplexView2DType out_b("out_b", n0, n1), out_o("out_o", n0, n1), out_f("out_f", n0, n1); @@ -2323,7 +2323,9 @@ void test_fftn_2dfft_2dview() { using axes_type = KokkosFFT::axis_type<2>; axes_type axes = {-2, -1}; KokkosFFT::fftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + KokkosFFT::fftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward KokkosFFT::fftn(execution_space(), x, out_b, axes, KokkosFFT::Normalization::backward); KokkosFFT::fftn(execution_space(), x, out_o, axes, @@ -2335,6 +2337,7 @@ void test_fftn_2dfft_2dview() { multiply(out_f, static_cast(n0 * n1)); EXPECT_TRUE(allclose(out, out2, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out2, 1.e-5, 1.e-6)); @@ -2368,7 +2371,7 @@ void test_ifftn_2dfft_2dview() { ComplexView2DType x("x", n0, n1); ComplexView2DType out("out", n0, n1), out1("out1", n0, n1), - out2("out2", n0, n1); + out2("out2", n0, n1), out_no_axes("out_no_axes", n0, n1); ComplexView2DType out_b("out_b", n0, n1), out_o("out_o", n0, n1), out_f("out_f", n0, n1); @@ -2388,7 +2391,9 @@ void test_ifftn_2dfft_2dview() { KokkosFFT::Normalization::backward, /*axis=*/0); KokkosFFT::ifftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + KokkosFFT::ifftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward KokkosFFT::ifftn(execution_space(), x, out_b, axes, KokkosFFT::Normalization::backward); KokkosFFT::ifftn(execution_space(), x, out_o, axes, @@ -2400,6 +2405,7 @@ void test_ifftn_2dfft_2dview() { multiply(out_f, 1.0 / static_cast(n0 * n1)); EXPECT_TRUE(allclose(out, out2, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out2, 1.e-5, 1.e-6)); @@ -2434,7 +2440,7 @@ void test_rfftn_2dfft_2dview() { RealView2DType x("x", n0, n1), x_ref("x_ref", n0, n1); ComplexView2DType out("out", n0, n1 / 2 + 1), out1("out1", n0, n1 / 2 + 1), - out2("out2", n0, n1 / 2 + 1); + out2("out2", n0, n1 / 2 + 1), out_no_axes("out_no_axes", n0, n1 / 2 + 1); ComplexView2DType out_b("out_b", n0, n1 / 2 + 1), out_o("out_o", n0, n1 / 2 + 1), out_f("out_f", n0, n1 / 2 + 1); @@ -2453,7 +2459,11 @@ void test_rfftn_2dfft_2dview() { Kokkos::deep_copy(x, x_ref); KokkosFFT::rfftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + + Kokkos::deep_copy(x, x_ref); + KokkosFFT::rfftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward Kokkos::deep_copy(x, x_ref); KokkosFFT::rfftn(execution_space(), x, out_b, axes, @@ -2471,6 +2481,7 @@ void test_rfftn_2dfft_2dview() { multiply(out_f, static_cast(n0 * n1)); EXPECT_TRUE(allclose(out, out2, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out2, 1.e-5, 1.e-6)); @@ -2514,7 +2525,7 @@ void test_irfftn_2dfft_2dview() { ComplexView2DType out1("out1", n0, n1 / 2 + 1); RealView2DType out2("out2", n0, n1), out("out", n0, n1); RealView2DType out_b("out_b", n0, n1), out_o("out_o", n0, n1), - out_f("out_f", n0, n1); + out_f("out_f", n0, n1), out_no_axes("out_no_axes", n0, n1); const Kokkos::complex I(1.0, 1.0); Kokkos::Random_XorShift64_Pool<> random_pool(12345); @@ -2531,8 +2542,13 @@ void test_irfftn_2dfft_2dview() { KokkosFFT::Normalization::backward, /*axis=*/1); Kokkos::deep_copy(x, x_ref); - KokkosFFT::irfftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + KokkosFFT::irfftn( + execution_space(), x, + out_no_axes); // default: KokkosFFT::Normalization::backward + + Kokkos::deep_copy(x, x_ref); + KokkosFFT::irfftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward Kokkos::deep_copy(x, x_ref); KokkosFFT::irfftn(execution_space(), x, out_b, axes, @@ -2550,6 +2566,7 @@ void test_irfftn_2dfft_2dview() { multiply(out_f, 1.0 / static_cast(n0 * n1)); EXPECT_TRUE(allclose(out, out2, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out2, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out2, 1.e-5, 1.e-6)); @@ -2678,7 +2695,7 @@ void test_fftn_3dfft_3dview(T atol = 1.0e-6) { ComplexView3DType out("out", n0, n1, n2), out1("out1", n0, n1, n2), out2("out2", n0, n1, n2), out3("out3", n0, n1, n2); ComplexView3DType out_b("out_b", n0, n1, n2), out_o("out_o", n0, n1, n2), - out_f("out_f", n0, n1, n2); + out_f("out_f", n0, n1, n2), out_no_axes("out_no_axes", n0, n1, n2); const Kokkos::complex I(1.0, 1.0); Kokkos::Random_XorShift64_Pool<> random_pool(12345); @@ -2699,7 +2716,9 @@ void test_fftn_3dfft_3dview(T atol = 1.0e-6) { KokkosFFT::Normalization::backward, /*axis=*/0); KokkosFFT::fftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + KokkosFFT::fftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward KokkosFFT::fftn(execution_space(), x, out_b, axes, KokkosFFT::Normalization::backward); KokkosFFT::fftn(execution_space(), x, out_o, axes, @@ -2711,6 +2730,7 @@ void test_fftn_3dfft_3dview(T atol = 1.0e-6) { multiply(out_f, static_cast(n0 * n1 * n2)); EXPECT_TRUE(allclose(out, out3, 1.e-5, atol)); + EXPECT_TRUE(allclose(out_no_axes, out3, 1.e-5, atol)); EXPECT_TRUE(allclose(out_b, out3, 1.e-5, atol)); EXPECT_TRUE(allclose(out_o, out3, 1.e-5, atol)); EXPECT_TRUE(allclose(out_f, out3, 1.e-5, atol)); @@ -2726,7 +2746,7 @@ void test_ifftn_3dfft_3dview() { ComplexView3DType out("out", n0, n1, n2), out1("out1", n0, n1, n2), out2("out2", n0, n1, n2), out3("out3", n0, n1, n2); ComplexView3DType out_b("out_b", n0, n1, n2), out_o("out_o", n0, n1, n2), - out_f("out_f", n0, n1, n2); + out_f("out_f", n0, n1, n2), out_no_axes("out_no_axes", n0, n1, n2); const Kokkos::complex I(1.0, 1.0); Kokkos::Random_XorShift64_Pool<> random_pool(12345); @@ -2747,7 +2767,9 @@ void test_ifftn_3dfft_3dview() { KokkosFFT::Normalization::backward, /*axis=*/0); KokkosFFT::ifftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + KokkosFFT::ifftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward KokkosFFT::ifftn(execution_space(), x, out_b, axes, KokkosFFT::Normalization::backward); KokkosFFT::ifftn(execution_space(), x, out_o, axes, @@ -2759,6 +2781,7 @@ void test_ifftn_3dfft_3dview() { multiply(out_f, 1.0 / static_cast(n0 * n1 * n2)); EXPECT_TRUE(allclose(out, out3, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out3, 1.e-5, 1.e-6)); @@ -2776,7 +2799,8 @@ void test_rfftn_3dfft_3dview() { out1("out1", n0, n1, n2 / 2 + 1), out2("out2", n0, n1, n2 / 2 + 1), out3("out3", n0, n1, n2 / 2 + 1); ComplexView3DType out_b("out_b", n0, n1, n2 / 2 + 1), - out_o("out_o", n0, n1, n2 / 2 + 1), out_f("out_f", n0, n1, n2 / 2 + 1); + out_o("out_o", n0, n1, n2 / 2 + 1), out_f("out_f", n0, n1, n2 / 2 + 1), + out_no_axes("out_no_axes", n0, n1, n2 / 2 + 1); Kokkos::Random_XorShift64_Pool<> random_pool(12345); Kokkos::fill_random(x, random_pool, 1); @@ -2797,7 +2821,11 @@ void test_rfftn_3dfft_3dview() { Kokkos::deep_copy(x, x_ref); KokkosFFT::rfftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + out_no_axes); // default: KokkosFFT::Normalization::backward + + Kokkos::deep_copy(x, x_ref); + KokkosFFT::rfftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward Kokkos::deep_copy(x, x_ref); KokkosFFT::rfftn(execution_space(), x, out_b, axes, @@ -2815,6 +2843,7 @@ void test_rfftn_3dfft_3dview() { multiply(out_f, static_cast(n0 * n1 * n2)); EXPECT_TRUE(allclose(out, out3, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out3, 1.e-5, 1.e-6)); @@ -2833,7 +2862,7 @@ void test_irfftn_3dfft_3dview() { out2("out2", n0, n1, n2 / 2 + 1); RealView3DType out("out", n0, n1, n2), out3("out3", n0, n1, n2); RealView3DType out_b("out_b", n0, n1, n2), out_o("out_o", n0, n1, n2), - out_f("out_f", n0, n1, n2); + out_f("out_f", n0, n1, n2), out_no_axes("out_no_axes", n0, n1, n2); const Kokkos::complex I(1.0, 1.0); Kokkos::Random_XorShift64_Pool<> random_pool(12345); @@ -2853,8 +2882,13 @@ void test_irfftn_3dfft_3dview() { KokkosFFT::Normalization::backward, /*axis=*/2); Kokkos::deep_copy(x, x_ref); - KokkosFFT::irfftn(execution_space(), x, - out); // default: KokkosFFT::Normalization::backward + KokkosFFT::irfftn( + execution_space(), x, + out_no_axes); // default: KokkosFFT::Normalization::backward + + Kokkos::deep_copy(x, x_ref); + KokkosFFT::irfftn(execution_space(), x, out, + axes); // default: KokkosFFT::Normalization::backward Kokkos::deep_copy(x, x_ref); KokkosFFT::irfftn(execution_space(), x, out_b, axes, @@ -2872,6 +2906,7 @@ void test_irfftn_3dfft_3dview() { multiply(out_f, 1.0 / static_cast(n0 * n1 * n2)); EXPECT_TRUE(allclose(out, out3, 1.e-5, 1.e-6)); + EXPECT_TRUE(allclose(out_no_axes, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_b, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_o, out3, 1.e-5, 1.e-6)); EXPECT_TRUE(allclose(out_f, out3, 1.e-5, 1.e-6));