Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/array/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -1941,29 +1941,29 @@ class copy_shape_traits {
* or `sizeof...(LoopOrder)` `index_t` objects in the case of
* `for_all_indices<>`. */
template <size_t... LoopOrder, class Shape, class Fn,
class = internal::enable_if_callable<Fn, typename Shape::index_type>,
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0>
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0,
class = internal::enable_if_callable<Fn, typename Shape::index_type>>
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_each_index(const Shape& s, Fn&& fn) {
shape_traits<Shape>::for_each_index(s, fn);
}
template <size_t... LoopOrder, class Shape, class Fn,
class = internal::enable_if_applicable<Fn, typename Shape::index_type>,
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0>
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0,
class = internal::enable_if_applicable<Fn, typename Shape::index_type>>
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_all_indices(const Shape& s, Fn&& fn) {
using index_type = typename Shape::index_type;
for_each_index(s, [fn = std::move(fn)](const index_type& i) { internal::apply(fn, i); });
}
template <size_t... LoopOrder, class Shape, class Fn,
class = internal::enable_if_callable<Fn, index_of_rank<sizeof...(LoopOrder)>>,
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0>
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0,
class = internal::enable_if_callable<Fn, index_of_rank<sizeof...(LoopOrder)>>>
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_each_index(const Shape& s, Fn&& fn) {
using index_type = index_of_rank<sizeof...(LoopOrder)>;
for_each_index_in_order(reorder<LoopOrder...>(s),
[fn = std::move(fn)](const index_type& i) { fn(internal::unshuffle<LoopOrder...>(i)); });
}
template <size_t... LoopOrder, class Shape, class Fn,
class = internal::enable_if_callable<Fn, decltype(LoopOrder)...>,
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0>
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0,
class = internal::enable_if_callable<Fn, decltype(LoopOrder)...>>
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_all_indices(const Shape& s, Fn&& fn) {
using index_type = index_of_rank<sizeof...(LoopOrder)>;
for_each_index_in_order(reorder<LoopOrder...>(s), [fn = std::move(fn)](const index_type& i) {
Expand Down
4 changes: 2 additions & 2 deletions test/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ TEST(for_each_index_scalar) {
TEST(for_each_index_1d) {
dense_shape<1> s(20);
int expected_flat_offset = 0;
for_each_index(s, [&](std::tuple<int> i) {
for_each_index(s, [&](auto i) {
ASSERT_EQ(s[i], expected_flat_offset);
expected_flat_offset++;
});
Expand All @@ -362,7 +362,7 @@ TEST(for_each_index_3d) {
s.resolve();
int expected_flat_offset = 0;
move_only token;
for_each_index(s, [&, token = std::move(token)](std::tuple<int, int, int> i) {
for_each_index(s, [&, token = std::move(token)](auto i) {
ASSERT_EQ(s[i], expected_flat_offset);
expected_flat_offset++;
assert_used(token);
Expand Down