Skip to content

Commit

Permalink
add size function to alpaka::Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetyusufoglu committed Oct 23, 2024
1 parent 8fefd70 commit 74cb39c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/alpaka/vec/Vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ namespace alpaka
return m_data[Dim::value - 4];
}

//! Function returns the size of the static array
//! \return The size
ALPAKA_FN_HOST_ACC static constexpr decltype(auto) size()
{
return Dim::value;
}

//! @}

//! Value reference accessor at the given non-unsigned integer index.
Expand Down
23 changes: 23 additions & 0 deletions test/unit/vec/src/VecTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,29 @@ TEST_CASE("basicVecTraits", "[vec]")
STATIC_REQUIRE(Vec{1, 2, 3}.front() == 1); // non-const overload
STATIC_REQUIRE(Vec{1, 2, 3}.back() == 3); // non-const overload
}
{
constexpr alpaka::Vec<Dim, Idx> vec4(static_cast<Idx>(47u), static_cast<Idx>(8u), static_cast<Idx>(3u));
// compile time tests
STATIC_REQUIRE(vec4.size() == 3);
STATIC_REQUIRE((alpaka::Vec{4, 8, 3}).size() == 3);
STATIC_REQUIRE((alpaka::Vec{4, 8}).size() == 2);
STATIC_REQUIRE((alpaka::Vec{4}).size() == 1);
STATIC_REQUIRE(decltype(vec4)::size() == 3);
STATIC_REQUIRE(decltype(alpaka::Vec{4, 8, 3})::size() == 3);

using Vec3DType = alpaka::Vec<Dim, Idx>;
STATIC_REQUIRE(Vec3DType::size() == 3);

constexpr alpaka::Vec vec5{8, 3};
STATIC_REQUIRE(vec5.size() == 2);

// runtime tests
REQUIRE(vec4.size() == 3);
REQUIRE((alpaka::Vec{4, 8, 3}).size() == 3);
REQUIRE((alpaka::Vec{4, 8}).size() == 2);
REQUIRE((alpaka::Vec{4}).size() == 1);
REQUIRE(vec5.size() == 2);
}
}

template<typename TDim, typename TIdx>
Expand Down

0 comments on commit 74cb39c

Please sign in to comment.