Skip to content

Commit

Permalink
Add new deduction guides and test
Browse files Browse the repository at this point in the history
  • Loading branch information
kboyarinov committed Dec 20, 2024
1 parent fe56f9f commit 54b0137
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 32 deletions.
40 changes: 33 additions & 7 deletions include/oneapi/tbb/blocked_nd_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ namespace d1 {
*/

template<typename Value, unsigned int N, typename = detail::make_index_sequence<N>>
<<<<<<< HEAD:include/oneapi/tbb/blocked_rangeNd.h
class blocked_rangeNd_impl;

template<typename Value, unsigned int N, std::size_t... Is>
class blocked_rangeNd_impl<Value, N, detail::index_sequence<Is...>> {
=======
class blocked_nd_range_impl;

template<typename Value, unsigned int N, std::size_t... Is>
class blocked_nd_range_impl<Value, N, detail::index_sequence<Is...>> {
>>>>>>> origin/rarutyun/blocked_range_nd_class:include/oneapi/tbb/blocked_nd_range.h
public:
//! Type of a value.
using value_type = Value;
Expand Down Expand Up @@ -154,6 +147,39 @@ class blocked_nd_range : public blocked_nd_range_impl<Value, N> {
using base::base;
};

#if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
template <typename Value, unsigned int N0,
typename... Values, unsigned int... Ns,
typename = std::enable_if_t<(sizeof...(Values) > 0)>,
typename = std::enable_if_t<(... && std::is_same_v<Value, Values>)>,
typename = std::enable_if_t<(N0 == 2 || N0 == 3) && (... && (Ns == 2 || Ns == 3))>>
blocked_nd_range(const Value (&)[N0], const Values (&... dim)[Ns])
-> blocked_nd_range<Value, 1 + sizeof...(Values)>;

template <typename Value, typename... Values,
typename = std::enable_if_t<(... && std::is_same_v<Value, Values>)>>
blocked_nd_range(blocked_range<Value>, blocked_range<Values>...)
-> blocked_nd_range<Value, 1 + sizeof...(Values)>;

template <typename Value, unsigned int N,
typename = std::enable_if_t<(N != 2 && N != 3)>>
blocked_nd_range(const Value (&)[N])
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(const Value (&)[N], typename blocked_nd_range<Value, N>::size_type)
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(blocked_nd_range<Value, N>, oneapi::tbb::split)
-> blocked_nd_range<Value, N>;

template <typename Value, unsigned int N>
blocked_nd_range(blocked_nd_range<Value, N>, oneapi::tbb::proportional_split)
-> blocked_nd_range<Value, N>;

#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

} // namespace d1
} // namespace detail

Expand Down
81 changes: 56 additions & 25 deletions test/conformance/conformance_blocked_nd_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,35 +296,66 @@ TEST_CASE("blocked_nd_range proportional splitting") {
//! Testing blocked_rangeNd deduction guides
//! \brief \ref interface
TEST_CASE("blocked_rangeNd deduction guides") {
using oneapi::tbb::blocked_nd_range;

std::vector<const unsigned long*> v;
using iterator = typename decltype(v)::iterator;

oneapi::tbb::blocked_range<int> br(0, 100);

oneapi::tbb::blocked_rangeNd r1({v.begin(), v.end()});
static_assert(std::is_same<decltype(r1),
oneapi::tbb::blocked_rangeNd<iterator, 1>>::value);

oneapi::tbb::blocked_rangeNd r2({v.begin(), v.end()}, {v.begin(), v.end()});
static_assert(std::is_same<decltype(r2),
oneapi::tbb::blocked_rangeNd<iterator, 2>>::value);

oneapi::tbb::blocked_rangeNd r3({0, 100}, {0, 100}, {0, 100}, {0, 100});
static_assert(std::is_same<decltype(r3),
oneapi::tbb::blocked_rangeNd<int, 4>>::value);

oneapi::tbb::blocked_rangeNd r4(br);
static_assert(std::is_same<decltype(r4),
oneapi::tbb::blocked_rangeNd<int, 1>>::value);
oneapi::tbb::blocked_range<int> dim_range(0, 100);

oneapi::tbb::blocked_rangeNd r5(br, br, br);
static_assert(std::is_same<decltype(r5),
oneapi::tbb::blocked_rangeNd<int, 3>>::value);
blocked_nd_range<int, 2> source_range(dim_range, dim_range);

oneapi::tbb::blocked_rangeNd rc(r1);
static_assert(std::is_same<decltype(rc), decltype(r1)>::value);

oneapi::tbb::blocked_rangeNd rm(std::move(r2));
static_assert(std::is_same<decltype(rm), decltype(r2)>::value);
{
blocked_nd_range range(dim_range, dim_range, dim_range);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 3>>);
}
{
blocked_nd_range range({v.begin(), v.end()}, {v.begin(), v.end()});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<iterator, 2>>);
}
{
blocked_nd_range range({0, 100}, {0, 100, 5}, {0, 100}, {0, 100, 5});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range({100});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 1>>);
}
{
blocked_nd_range range({100}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 1>>);
}
{
blocked_nd_range range({100, 200}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 2>>);
}
{
blocked_nd_range range({100, 200, 300}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 3>>);
}
{
blocked_nd_range range({100, 200, 300, 400});
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range({100, 200, 300, 400}, 5);
static_assert(std::is_same_v<decltype(range), blocked_nd_range<int, 4>>);
}
{
blocked_nd_range range(source_range, oneapi::tbb::split{});
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(source_range, oneapi::tbb::proportional_split{1, 3});
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(source_range);
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
{
blocked_nd_range range(std::move(source_range));
static_assert(std::is_same_v<decltype(range), decltype(source_range)>);
}
}
#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

0 comments on commit 54b0137

Please sign in to comment.