public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Rodgers <rodgertq@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-2328] libstdc++: Split up pstl/set.cc testcase Date: Wed, 5 Jul 2023 22:04:56 +0000 (GMT) [thread overview] Message-ID: <20230705220456.E72E23856944@sourceware.org> (raw) https://gcc.gnu.org/g:acfe8fa8dc4907e8fe7b878654112c397d6d59c3 commit r14-2328-gacfe8fa8dc4907e8fe7b878654112c397d6d59c3 Author: Thomas Rodgers <trodgers@redhat.com> Date: Wed Jul 5 14:13:02 2023 -0700 libstdc++: Split up pstl/set.cc testcase This testcase is causing some timeout issues. This patch splits the testcase up by individual set algorithm. libstdc++-v3:/ChangeLog: * testsuite/25_algorithms/pstl/alg_sorting/set.cc: Delete file. * testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc: New file. * testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_union.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set_util.h: Likewise. Diff: --- .../25_algorithms/pstl/alg_sorting/set.cc | 289 --------------------- .../pstl/alg_sorting/set_difference.cc | 93 +++++++ .../pstl/alg_sorting/set_intersection.cc | 94 +++++++ .../pstl/alg_sorting/set_symmetric_difference.cc | 95 +++++++ .../25_algorithms/pstl/alg_sorting/set_union.cc | 93 +++++++ .../25_algorithms/pstl/alg_sorting/set_util.h | 76 ++++++ 6 files changed, 451 insertions(+), 289 deletions(-) diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc deleted file mode 100644 index 0343739dfd1..00000000000 --- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc +++ /dev/null @@ -1,289 +0,0 @@ -// -*- C++ -*- -// { dg-options "-ltbb" } -// { dg-do run { target c++17 } } -// { dg-timeout-factor 3 } -// { dg-require-effective-target tbb_backend } - -//===-- set.pass.cpp ------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "pstl/pstl_test_config.h" - -#ifdef PSTL_STANDALONE_TESTS - -#include <cmath> -#include <chrono> - -#include "pstl/execution" -#include "pstl/algorithm" -#else -#include <execution> -#include <algorithm> -#endif // PSTL_STANDALONE_TESTS - -#include "pstl/test_utils.h" - -using namespace TestUtils; - -template <typename T> -struct Num -{ - T val; - - Num() : val{} {} - Num(const T& v) : val(v) {} - - //for "includes" checks - template <typename T1> - bool - operator<(const Num<T1>& v1) const - { - return val < v1.val; - } - - //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them - template <typename T1> - operator Num<T1>() const - { - return Num<T1>((T1)val); - } - - friend bool - operator==(const Num& v1, const Num& v2) - { - return v1.val == v2.val; - } -}; - -template <typename Type> -struct test_set_union -{ - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits<InputIterator1>::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence<T1> expect(n); - Sequence<T1> out(n); - - auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); - } - - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template <typename Type> -struct test_set_intersection -{ - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits<InputIterator1>::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence<T1> expect(n); - Sequence<T1> out(n); - - auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); - } - - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template <typename Type> -struct test_set_difference -{ - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits<InputIterator1>::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence<T1> expect(n); - Sequence<T1> out(n); - - auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); - } - - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template <typename Type> -struct test_set_symmetric_difference -{ - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, - Compare comp) - { - using T1 = typename std::iterator_traits<InputIterator1>::value_type; - - auto n1 = std::distance(first1, last1); - auto n2 = std::distance(first2, last2); - auto n = n1 + n2; - Sequence<T1> expect(n); - Sequence<T1> out(n); - - auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); - auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); - - EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); - EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), - "wrong set_symmetric_difference effect"); - } - - template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> - typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) - { - } -}; - -template <typename T1, typename T2, typename Compare> -void -test_set(Compare compare) -{ - - const std::size_t n_max = 100000; - - // The rand()%(2*n+1) encourages generation of some duplicates. - std::srand(4200); - - for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) - { - for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) - { - //prepare the input ranges - Sequence<T1> in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); - Sequence<T2> in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); - - std::sort(in1.begin(), in1.end(), compare); - std::sort(in2.begin(), in2.end(), compare); - - invoke_on_all_policies(test_set_union<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_intersection<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_difference<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), - compare); - - invoke_on_all_policies(test_set_symmetric_difference<T1>(), in1.begin(), in1.end(), in2.cbegin(), - in2.cend(), compare); - } - } -} - -template <typename T> -struct test_non_const_set_difference -{ - template <typename Policy, typename InputIterator, typename OutputInterator> - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); - } -}; - -template <typename T> -struct test_non_const_set_intersection -{ - template <typename Policy, typename InputIterator, typename OutputInterator> - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); - } -}; - -template <typename T> -struct test_non_const_set_symmetric_difference -{ - template <typename Policy, typename InputIterator, typename OutputInterator> - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, - non_const(std::less<T>())); - } -}; - -template <typename T> -struct test_non_const_set_union -{ - template <typename Policy, typename InputIterator, typename OutputInterator> - void - operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) - { - set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); - } -}; - -int -main() -{ - - test_set<float64_t, float64_t>(std::less<>()); - test_set<Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; }); - - test_set<MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { - return val1.value() < val2.value(); - }); - EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); - EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); - - test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_difference<int32_t>>()); - - test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_intersection<int32_t>>()); - - test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_symmetric_difference<int32_t>>()); - - test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_union<int32_t>>()); - - std::cout << done() << std::endl; - - return 0; -} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc new file mode 100644 index 00000000000..a05fad8c47e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc @@ -0,0 +1,93 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include <cmath> +#include <chrono> + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include <execution> +#include <algorithm> +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template <typename Type> +struct test_set_difference +{ + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits<InputIterator1>::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence<T1> expect(n); + Sequence<T1> out(n); + + auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect"); + } + + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template <typename T> +struct test_non_const_set_difference +{ + template <typename Policy, typename InputIterator, typename OutputInterator> + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); + } +}; + +int +main() +{ + test_set_op<test_set_difference<float64_t>, float64_t, float64_t>(std::less<>()); + test_set_op<test_set_difference<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; }); + test_set_op<test_set_difference<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_difference<int32_t>>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc new file mode 100644 index 00000000000..4d63fa14da6 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc @@ -0,0 +1,94 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include <cmath> +#include <chrono> + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include <execution> +#include <algorithm> +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template <typename Type> +struct test_set_intersection +{ + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits<InputIterator1>::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence<T1> expect(n); + Sequence<T1> out(n); + + auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect"); + } + + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template <typename T> +struct test_non_const_set_intersection +{ + template <typename Policy, typename InputIterator, typename OutputInterator> + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); + } +}; + +int +main() +{ + test_set_op<test_set_intersection<float64_t>, float64_t, float64_t>(std::less<>()); + test_set_op<test_set_intersection<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; }); + + test_set_op<test_set_intersection<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + std::cout << done() << std::endl; + + test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_intersection<int32_t>>()); +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc new file mode 100644 index 00000000000..aaa52f8089d --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc @@ -0,0 +1,95 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include <cmath> +#include <chrono> + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include <execution> +#include <algorithm> +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template <typename Type> +struct test_set_symmetric_difference +{ + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits<InputIterator1>::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence<T1> expect(n); + Sequence<T1> out(n); + + auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), + "wrong set_symmetric_difference effect"); + } + + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template <typename T> +struct test_non_const_set_symmetric_difference +{ + template <typename Policy, typename InputIterator, typename OutputInterator> + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, + non_const(std::less<T>())); + } +}; + +int +main() +{ + test_set_op<test_set_symmetric_difference<float64_t>, float64_t, float64_t>(std::less<>()); + test_set_op<test_set_symmetric_difference<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; }); + test_set_op<test_set_symmetric_difference<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_symmetric_difference<int32_t>>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc new file mode 100644 index 00000000000..85cde6b0b41 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc @@ -0,0 +1,93 @@ +// -*- C++ -*- +// { dg-options "-ltbb" } +// { dg-do run { target c++17 } } +// { dg-timeout-factor 3 } +// { dg-require-effective-target tbb_backend } + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#include "pstl/pstl_test_config.h" + +#ifdef PSTL_STANDALONE_TESTS + +#include <cmath> +#include <chrono> + +#include "pstl/execution" +#include "pstl/algorithm" +#else +#include <execution> +#include <algorithm> +#endif // PSTL_STANDALONE_TESTS + +#include "pstl/test_utils.h" + +#include "set_util.h" + +using namespace TestUtils; + +template <typename Type> +struct test_set_union +{ + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, + Compare comp) + { + using T1 = typename std::iterator_traits<InputIterator1>::value_type; + + auto n1 = std::distance(first1, last1); + auto n2 = std::distance(first2, last2); + auto n = n1 + n2; + Sequence<T1> expect(n); + Sequence<T1> out(n); + + auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp); + auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp); + + EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union"); + EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect"); + } + + template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare> + typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) + { + } +}; + +template <typename T> +struct test_non_const_set_union +{ + template <typename Policy, typename InputIterator, typename OutputInterator> + void + operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter) + { + set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>())); + } +}; + +int +main() +{ + test_set_op<test_set_union<float64_t>, float64_t, float64_t>(std::less<>()); + test_set_op<test_set_union<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; }); + test_set_op<test_set_union<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool { + return val1.value() < val2.value(); + }); + EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls"); + EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls"); + + test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_union<int32_t>>()); + + std::cout << done() << std::endl; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h new file mode 100644 index 00000000000..cd54fc7a6a3 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h @@ -0,0 +1,76 @@ +// -*- C++ -*- + +//===-- set.pass.cpp ------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Note: This file was derived from set.pass.cc which is part of the upstream +// source. + +#ifndef __PSTL_TEST_SET_UTIL_H +#define __PSTL_TEST_SET_UTIL_H + +namespace TestUtils +{ + template <typename T> + struct Num + { + T val; + + Num() : val{} {} + Num(const T& v) : val(v) {} + + //for "includes" checks + template <typename T1> + bool + operator<(const Num<T1>& v1) const + { + return val < v1.val; + } + + //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them + template <typename T1> + operator Num<T1>() const + { + return Num<T1>((T1)val); + } + + friend bool + operator==(const Num& v1, const Num& v2) + { + return v1.val == v2.val; + } + }; + + template <typename Operation, + typename T1, typename T2, typename Compare> + void + test_set_op(Compare compare) + { + const std::size_t n_max = 100000; + + // The rand()%(2*n+1) encourages generation of some duplicates. + std::srand(4200); + + for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n)) + { + for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m)) + { + //prepare the input ranges + Sequence<T1> in1(n, [](std::size_t k) { return rand() % (2 * k + 1); }); + Sequence<T2> in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); }); + + std::sort(in1.begin(), in1.end(), compare); + std::sort(in2.begin(), in2.end(), compare); + + invoke_on_all_policies(Operation(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(), + compare); + } + } + } +} // namespace TestUtils +#endif // __PSTL_TEST_SET_UTIL_H
reply other threads:[~2023-07-05 22:04 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230705220456.E72E23856944@sourceware.org \ --to=rodgertq@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).