summaryrefslogtreecommitdiffstats
path: root/pstl/test/test_transform_unary.cpp
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2018-12-19 17:45:32 +0000
committerJF Bastien <jfbastien@apple.com>2018-12-19 17:45:32 +0000
commite637637ae46a5b2fa1e9d10c16ae5b0922289f82 (patch)
tree1bd45f3e03d8bbb85a9dca6b46015769d521b186 /pstl/test/test_transform_unary.cpp
parent5d409b22781f5854f1bac3fd60c8499af0c865bf (diff)
downloadbcm5719-llvm-e637637ae46a5b2fa1e9d10c16ae5b0922289f82.tar.gz
bcm5719-llvm-e637637ae46a5b2fa1e9d10c16ae5b0922289f82.zip
Initial PSTL commit
The initial commit of the Parallel STL upstream (under LLVM umbrella) based on Parallel STL 20181204 open source release, which is available by https://github.com/intel/parallelstl Author: Mikhail Dvorskiy <mikhail.dvorskiy@intel.com> Differential Revision: https://reviews.llvm.org/D55889 llvm-svn: 349653
Diffstat (limited to 'pstl/test/test_transform_unary.cpp')
-rw-r--r--pstl/test/test_transform_unary.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/pstl/test/test_transform_unary.cpp b/pstl/test/test_transform_unary.cpp
new file mode 100644
index 00000000000..8932fe6a96b
--- /dev/null
+++ b/pstl/test/test_transform_unary.cpp
@@ -0,0 +1,87 @@
+// -*- C++ -*-
+//===-- test_transform_unary.cpp ------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#include "utils.h"
+
+using namespace TestUtils;
+
+template <typename InputIterator, typename OutputIterator>
+void
+check_and_reset(InputIterator first, InputIterator last, OutputIterator out_first)
+{
+ typedef typename std::iterator_traits<OutputIterator>::value_type Out;
+ typename std::iterator_traits<OutputIterator>::difference_type k = 0;
+ for (; first != last; ++first, ++out_first, ++k)
+ {
+ // check
+ Out expected = 1 - *first;
+ Out actual = *out_first;
+ EXPECT_EQ(expected, actual, "wrong value in output sequence");
+ // reset
+ *out_first = k % 7 != 4 ? 7 * k - 5 : 0;
+ }
+}
+
+struct test_one_policy
+{
+ template <typename Policy, typename InputIterator, typename OutputIterator, typename UnaryOp>
+ void
+ operator()(Policy&& exec, InputIterator first, InputIterator last, OutputIterator out_first,
+ OutputIterator out_last, UnaryOp op)
+ {
+ auto orr = std::transform(exec, first, last, out_first, op);
+ EXPECT_TRUE(out_last == orr, "transform returned wrong iterator");
+ check_and_reset(first, last, out_first);
+ }
+};
+
+template <typename Tin, typename Tout>
+void
+test()
+{
+ for (size_t n = 0; n <= 100000; n = n <= 16 ? n + 1 : size_t(3.1415 * n))
+ {
+ Sequence<Tin> in(n, [](int32_t k) { return k % 5 != 1 ? 3 * k - 7 : 0; });
+
+ Sequence<Tout> out(n);
+
+ const auto flip = Complement<Tin, Tout>(1);
+ invoke_on_all_policies(test_one_policy(), in.begin(), in.end(), out.begin(), out.end(), flip);
+ invoke_on_all_policies(test_one_policy(), in.cbegin(), in.cend(), out.begin(), out.end(), flip);
+ }
+}
+
+template <typename T>
+struct test_non_const
+{
+ template <typename Policy, typename InputIterator, typename OutputInterator>
+ void
+ operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
+ {
+ invoke_if(exec, [&]() { transform(exec, input_iter, input_iter, out_iter, non_const(std::negate<T>())); });
+ }
+};
+
+int32_t
+main()
+{
+ test<int32_t, int32_t>();
+ test<int32_t, float32_t>();
+ test<uint16_t, float32_t>();
+ test<float32_t, float64_t>();
+ test<float64_t, float64_t>();
+
+ test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
+
+ std::cout << done() << std::endl;
+ return 0;
+}
OpenPOWER on IntegriCloud