Skip to content

Commit

Permalink
Replace some assertions with concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Dec 12, 2023
1 parent bbe4dc1 commit db282df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 3 additions & 9 deletions include/etl/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ constexpr size_t fast_index(size_t i) noexcept(assert_nothrow) {
* \param j The index of the second dimension to access
* \return The flat position of (i,j)
*/
template <typename T>
template <etl_2d T>
constexpr size_t fast_index(size_t i, size_t j) noexcept(assert_nothrow) {
static_assert(is_2d<T>, "Invalid number of dimensions for fast_index");

if constexpr (decay_traits<T>::storage_order == order::RowMajor) {
cpp_assert(i < decay_traits<T>::template dim<0>(), "Out of bounds");
cpp_assert(j < decay_traits<T>::template dim<1>(), "Out of bounds");
Expand All @@ -117,10 +115,8 @@ constexpr size_t fast_index(size_t i, size_t j) noexcept(assert_nothrow) {
* \param k The index of the third dimension to access
* \return The flat position of (i,j,k)
*/
template <typename T>
template <etl_3d T>
constexpr size_t fast_index(size_t i, size_t j, size_t k) noexcept(assert_nothrow) {
static_assert(is_3d<T>, "Invalid number of dimensions for fast_index");

if constexpr (decay_traits<T>::storage_order == order::RowMajor) {
cpp_assert(i < decay_traits<T>::template dim<0>(), "Out of bounds");
cpp_assert(j < decay_traits<T>::template dim<1>(), "Out of bounds");
Expand All @@ -144,10 +140,8 @@ constexpr size_t fast_index(size_t i, size_t j, size_t k) noexcept(assert_nothro
* \param l The index of the fourth dimension to access
* \return The flat position of (i,j,k,l)
*/
template <typename T>
template <etl_4d T>
constexpr size_t fast_index(size_t i, size_t j, size_t k, size_t l) noexcept(assert_nothrow) {
static_assert(is_4d<T>, "Invalid number of dimensions for fast_index");

if constexpr (decay_traits<T>::storage_order == order::RowMajor) {
cpp_assert(i < decay_traits<T>::template dim<0>(), "Out of bounds");
cpp_assert(j < decay_traits<T>::template dim<1>(), "Out of bounds");
Expand Down
4 changes: 1 addition & 3 deletions include/etl/op/flip_transformers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ namespace etl {
*
* \tparam T The type on which the transformer is applied
*/
template <typename T>
template <etl_2d T>
struct one_if_max_sub_transformer {
using sub_type = T; ///< The type on which the expression works
using value_type = value_t<T>; ///< The type of valuie

friend etl_traits<one_if_max_sub_transformer>;

static_assert(is_2d<sub_type>, "one_if_max_sub is only defined for 2D Matrix");

static constexpr bool gpu_computable = impl::egblas::has_sone_if_max_sub && all_row_major<T> && all_floating<T>;

private:
Expand Down

0 comments on commit db282df

Please sign in to comment.