-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalised for_each_indexed for all ranks
- Loading branch information
1 parent
303a18c
commit 6589471
Showing
4 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "rank.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace jada { | ||
|
||
namespace detail { | ||
|
||
template <size_t... Is> | ||
static constexpr auto | ||
elementwise_add(auto tuple1, auto& tuple2, std::index_sequence<Is...>) { | ||
return std::make_tuple((std::get<Is>(tuple1) + std::get<Is>(tuple2))...); | ||
} | ||
} // namespace detail | ||
|
||
/// | ||
///@brief Elementwise addition of two generic types which have std::get implemented. | ||
/// | ||
///@param lhs Left-hand side operand. | ||
///@param rhs Right-hand side operand. | ||
///@return A tuple of elementwise added values. | ||
/// | ||
static constexpr auto elementwise_add(auto lhs, auto rhs) { | ||
static_assert(rank(lhs) == rank(rhs), "Rank mismatch in elemenwise_add"); | ||
constexpr size_t N = rank(lhs); | ||
return detail::elementwise_add(lhs, rhs, std::make_index_sequence<N>{}); | ||
} | ||
|
||
} // namespace jada |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters