Skip to content

Commit

Permalink
add static function dim() to alpaka::Vec
Browse files Browse the repository at this point in the history
- Easy way to get the dim of a alpaka::Vec.
  • Loading branch information
SimeonEhrig authored and psychocoderHPC committed Nov 7, 2024
1 parent 8fefd70 commit 6140bce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/alpaka/vec/Vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ namespace alpaka
return (*this)[I];
}

//! \return The number of dimensions of the vector.
[[nodiscard]] ALPAKA_FN_HOST_ACC static consteval auto dim() noexcept -> TVal
{
return TDim::value;
}

//! \return The element-wise sum of two vectors.
ALPAKA_NO_HOST_ACC_WARNING
ALPAKA_FN_HOST_ACC friend constexpr auto operator+(Vec const& p, Vec const& q) -> Vec
Expand Down
9 changes: 8 additions & 1 deletion test/unit/vec/src/VecTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ TEST_CASE("basicVecTraits", "[vec]")
}

{
constexpr alpaka::Vec<Dim, Idx> vec3(static_cast<Idx>(47u), static_cast<Idx>(8u), static_cast<Idx>(3u));
using Vec3 = alpaka::Vec<Dim, Idx>;
constexpr Vec3 vec3(static_cast<Idx>(47u), static_cast<Idx>(8u), static_cast<Idx>(3u));

// alpaka::Vec::dim
{
STATIC_REQUIRE(vec3.dim() == 3);
STATIC_REQUIRE(Vec3::dim() == 3);
}

// alpaka::Vec operator +
{
Expand Down

0 comments on commit 6140bce

Please sign in to comment.