Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add static function dim() to alpaka::Vec #2415

Merged
merged 1 commit into from
Nov 7, 2024
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
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
j-stephan marked this conversation as resolved.
Show resolved Hide resolved
{
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
Loading