From f081cb81704fdcb7cc9881815cf69ed653cc2f47 Mon Sep 17 00:00:00 2001 From: Simeon Ehrig Date: Wed, 23 Oct 2024 16:11:47 +0200 Subject: [PATCH] add static function dim() to alpaka::Vec - Easy way to get the dim of a alpaka::Vec. --- include/alpaka/vec/Vec.hpp | 6 ++++++ test/unit/vec/src/VecTest.cpp | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/alpaka/vec/Vec.hpp b/include/alpaka/vec/Vec.hpp index d327f60ff45..b0e2dba5f10 100644 --- a/include/alpaka/vec/Vec.hpp +++ b/include/alpaka/vec/Vec.hpp @@ -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 diff --git a/test/unit/vec/src/VecTest.cpp b/test/unit/vec/src/VecTest.cpp index d559b47a5d3..837d4acc27c 100644 --- a/test/unit/vec/src/VecTest.cpp +++ b/test/unit/vec/src/VecTest.cpp @@ -177,7 +177,14 @@ TEST_CASE("basicVecTraits", "[vec]") } { - constexpr alpaka::Vec vec3(static_cast(47u), static_cast(8u), static_cast(3u)); + using Vec3 = alpaka::Vec; + constexpr Vec3 vec3(static_cast(47u), static_cast(8u), static_cast(3u)); + + // alpaka::Vec::dim + { + STATIC_REQUIRE(vec3.dim() == 3); + STATIC_REQUIRE(Vec3::dim() == 3); + } // alpaka::Vec operator + {