alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Vec.hpp
Go to the documentation of this file.
1/* Copyright 2025 Axel Huebl, Benjamin Worpitz, Erik Zenker, Matthias Werner, René Widera, Andrea Bocci, Jan Stephan,
2 * Bernhard Manfred Gruber
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
14#include "alpaka/dim/Traits.hpp"
15#include "alpaka/idx/Traits.hpp"
16#include "alpaka/meta/Fold.hpp"
19#include "alpaka/vec/Traits.hpp"
20
21#include <algorithm>
22#include <cstdint>
23#include <functional>
24#include <limits>
25#include <ostream>
26#include <tuple>
27#include <type_traits>
28#include <utility>
29
30namespace alpaka
31{
32 template<typename TDim, typename TVal>
33 class Vec;
34
35 //! A n-dimensional vector.
36 template<typename TDim, typename TVal>
37 class Vec final
38 {
39 public:
40 static_assert(TDim::value >= 0u, "Invalid dimensionality");
41
42 using Dim = TDim;
43 using Val = TVal;
44 using value_type = Val; //!< STL-like value_type.
45
46 private:
47 //! A sequence of integers from 0 to dim-1.
48 //! This can be used to write compile time indexing algorithms.
49 using IdxSequence = std::make_integer_sequence<std::size_t, TDim::value>;
50
51 public:
52 ALPAKA_FN_HOST_ACC constexpr Vec() : m_data{}
53 {
54 }
55
56 //! Value constructor.
57 //! This constructor is only available if the number of parameters matches the vector idx.
59 template<
60 typename... TArgs,
61 typename = std::enable_if_t<
62 sizeof...(TArgs) == TDim::value && (std::is_convertible_v<std::decay_t<TArgs>, TVal> && ...)>>
63 ALPAKA_FN_HOST_ACC constexpr Vec(TArgs&&... args) : m_data{static_cast<TVal>(std::forward<TArgs>(args))...}
64 {
65 }
66
67 //! Generator constructor.
68 //! Initializes the vector with the values returned from generator(IC) in order, where IC::value runs from 0 to
69 //! TDim - 1 (inclusive).
70 template<typename F, std::enable_if_t<std::is_invocable_v<F, std::integral_constant<std::size_t, 0>>, int> = 0>
71 ALPAKA_FN_HOST_ACC constexpr explicit Vec(F&& generator)
72 : Vec(std::forward<F>(generator), std::make_index_sequence<TDim::value>{})
73 {
74 }
75
76 private:
77 template<typename F, std::size_t... Is>
78 ALPAKA_FN_HOST_ACC constexpr explicit Vec(F&& generator, std::index_sequence<Is...>)
79 : m_data{generator(std::integral_constant<std::size_t, Is>{})...}
80 {
81 }
82
83 public:
84 //! \brief Single value constructor.
85 //!
86 //! Creates a vector with all values set to val.
87 //! \param val The initial value.
89 ALPAKA_FN_HOST_ACC static constexpr auto all(TVal const& val) -> Vec<TDim, TVal>
90 {
92 for(auto& e : v)
93 e = val;
94 return v;
95 }
96
97 //! Zero value constructor.
99 ALPAKA_FN_HOST_ACC static constexpr auto zeros() -> Vec<TDim, TVal>
100 {
101 return all(static_cast<TVal>(0));
102 }
103
104 //! One value constructor.
106 ALPAKA_FN_HOST_ACC static constexpr auto ones() -> Vec<TDim, TVal>
107 {
108 return all(static_cast<TVal>(1));
109 }
110
111 ALPAKA_FN_HOST_ACC constexpr auto begin() -> TVal*
112 {
113 return m_data;
114 }
115
116 ALPAKA_FN_HOST_ACC constexpr auto begin() const -> TVal const*
117 {
118 return m_data;
119 }
120
121 ALPAKA_FN_HOST_ACC constexpr auto end() -> TVal*
122 {
123 return m_data + TDim::value;
124 }
125
126 ALPAKA_FN_HOST_ACC constexpr auto end() const -> TVal const*
127 {
128 return m_data + TDim::value;
129 }
130
131 ALPAKA_FN_HOST_ACC constexpr auto front() -> TVal&
132 {
133 return m_data[0];
134 }
135
136 ALPAKA_FN_HOST_ACC constexpr auto front() const -> TVal const&
137 {
138 return m_data[0];
139 }
140
141 ALPAKA_FN_HOST_ACC constexpr auto back() -> TVal&
142 {
143 return m_data[Dim::value - 1];
144 }
145
146 ALPAKA_FN_HOST_ACC constexpr auto back() const -> TVal const&
147 {
148 return m_data[Dim::value - 1];
149 }
150
151 //! access elements by name
152 //!
153 //! names: x,y,z,w
154 //! @{
155 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1, int> = 0>
156 ALPAKA_FN_HOST_ACC constexpr decltype(auto) x() const
157 {
158 return m_data[Dim::value - 1];
159 }
160
161 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 1, int> = 0>
162 ALPAKA_FN_HOST_ACC constexpr decltype(auto) x()
163 {
164 return m_data[Dim::value - 1];
165 }
166
167 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2, int> = 0>
168 ALPAKA_FN_HOST_ACC constexpr decltype(auto) y() const
169 {
170 return m_data[Dim::value - 2];
171 }
172
173 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 2, int> = 0>
174 ALPAKA_FN_HOST_ACC constexpr decltype(auto) y()
175 {
176 return m_data[Dim::value - 2];
177 }
178
179 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3, int> = 0>
180 ALPAKA_FN_HOST_ACC constexpr decltype(auto) z() const
181 {
182 return m_data[Dim::value - 3];
183 }
184
185 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 3, int> = 0>
186 ALPAKA_FN_HOST_ACC constexpr decltype(auto) z()
187 {
188 return m_data[Dim::value - 3];
189 }
190
191 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4, int> = 0>
192 ALPAKA_FN_HOST_ACC constexpr decltype(auto) w() const
193 {
194 return m_data[Dim::value - 4];
195 }
196
197 template<typename TDefer = Dim, std::enable_if_t<std::is_same_v<TDefer, Dim> && Dim::value >= 4, int> = 0>
198 ALPAKA_FN_HOST_ACC constexpr decltype(auto) w()
199 {
200 return m_data[Dim::value - 4];
201 }
202
203 //! @}
204
205 //! Value reference accessor at the given non-unsigned integer index.
206 //! \return A reference to the value at the given index.
208 template<typename TIdx, typename = std::enable_if_t<std::is_integral_v<TIdx>>>
209 ALPAKA_FN_HOST_ACC constexpr auto operator[](TIdx const iIdx) -> TVal&
210 {
212 auto const idx = static_cast<typename TDim::value_type>(iIdx);
214 return m_data[idx];
215 }
216
217 //! Value accessor at the given non-unsigned integer index.
218 //! \return The value at the given index.
220 template<typename TIdx, typename = std::enable_if_t<std::is_integral_v<TIdx>>>
221 ALPAKA_FN_HOST_ACC constexpr auto operator[](TIdx const iIdx) const -> TVal
222 {
224 auto const idx = static_cast<typename TDim::value_type>(iIdx);
226 return m_data[idx];
227 }
228
230 template<typename TFnObj, std::size_t... TIndices>
231 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto foldrByIndices(
232 TFnObj const& f,
233 std::integer_sequence<std::size_t, TIndices...>) const
234 {
235 return meta::foldr(f, (*this)[TIndices]...);
236 }
237
239 template<typename TFnObj, std::size_t... TIndices>
240 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto foldrByIndices(
241 TFnObj const& f,
242 std::integer_sequence<std::size_t, TIndices...>,
243 TVal initial) const
244 {
245 return meta::foldr(f, (*this)[TIndices]..., initial);
246 }
247
249 template<typename TFnObj>
250 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto foldrAll(TFnObj const& f) const
251 {
252 return foldrByIndices(f, IdxSequence());
253 }
254
256 template<typename TFnObj>
257 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto foldrAll(TFnObj const& f, TVal initial) const
258 {
259 return foldrByIndices(f, IdxSequence(), initial);
260 }
261
262// suppress strange warning produced by nvcc+MSVC in release mode
263#if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
264# pragma warning(push)
265# pragma warning(disable : 4702) // unreachable code
266#endif
267 //! \return The product of all values.
269 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto prod() const -> TVal
270 {
271 return foldrAll(std::multiplies<TVal>{}, TVal{1});
272 }
273#if BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
274# pragma warning(pop)
275#endif
276 //! \return The sum of all values.
278 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto sum() const -> TVal
279 {
280 return foldrAll(std::plus<TVal>{}, TVal{0});
281 }
282
283 //! \return The min of all values.
285 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto min() const -> TVal
286 {
287 return foldrAll(meta::min<TVal>{}, std::numeric_limits<TVal>::max());
288 }
289
290 //! \return The max of all values.
292 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto max() const -> TVal
293 {
294 return foldrAll(meta::max<TVal>{}, std::numeric_limits<TVal>::min());
295 }
296
297 //! \return True if all values are true, i.e., the "logical and" of all values.
299 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto all() const -> bool
300 {
301 return foldrAll(std::logical_and<TVal>{}, true);
302 }
303
304 //! \return True if any value is true, i.e., the "logical or" of all values.
306 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto any() const -> bool
307 {
308 return foldrAll(std::logical_or<TVal>{}, false);
309 }
310
311 //! \return True if none of the values are true
313 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto none() const -> bool
314 {
315 return !foldrAll(std::logical_or<TVal>{}, false);
316 }
317
318 //! \return The index of the minimal element.
319 [[nodiscard]] ALPAKA_FN_HOST constexpr auto minElem() const -> typename TDim::value_type
320 {
321 return static_cast<typename TDim::value_type>(
322 std::distance(std::begin(m_data), std::min_element(std::begin(m_data), std::end(m_data))));
323 }
324
325 //! \return The index of the maximal element.
326 [[nodiscard]] ALPAKA_FN_HOST constexpr auto maxElem() const -> typename TDim::value_type
327 {
328 return static_cast<typename TDim::value_type>(
329 std::distance(std::begin(m_data), std::max_element(std::begin(m_data), std::end(m_data))));
330 }
331
332 template<size_t I>
333 ALPAKA_FN_HOST_ACC constexpr auto get() -> TVal&
334 {
335 return (*this)[I];
336 }
337
338 template<size_t I>
339 [[nodiscard]] ALPAKA_FN_HOST_ACC constexpr auto get() const -> TVal
340 {
341 return (*this)[I];
342 }
343
344 //! \return The number of dimensions of the vector.
345 [[nodiscard]] ALPAKA_FN_HOST_ACC static consteval auto dim() noexcept -> TVal
346 {
347 return TDim::value;
348 }
349
350 //! \return The element-wise sum of two vectors.
352 ALPAKA_FN_HOST_ACC friend constexpr auto operator+(Vec const& p, Vec const& q) -> Vec
353 {
354 Vec r;
355 if constexpr(TDim::value > 0)
356 {
357 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
358 r[i] = p[i] + q[i];
359 }
360 return r;
361 }
362
363 //! \return The element-wise difference of two vectors.
365 ALPAKA_FN_HOST_ACC friend constexpr auto operator-(Vec const& p, Vec const& q) -> Vec
366 {
367 Vec r;
368 if constexpr(TDim::value > 0)
369 {
370 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
371 r[i] = p[i] - q[i];
372 }
373 return r;
374 }
375
376 //! \return The element-wise product of two vectors.
378 ALPAKA_FN_HOST_ACC friend constexpr auto operator*(Vec const& p, Vec const& q) -> Vec
379 {
380 Vec r;
381 if constexpr(TDim::value > 0)
382 {
383 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
384 r[i] = p[i] * q[i];
385 }
386 return r;
387 }
388
390 ALPAKA_FN_HOST_ACC friend constexpr auto operator==(Vec const& a, Vec const& b) -> bool
391 {
392 if constexpr(TDim::value > 0)
393 {
394 for(typename TDim::value_type i(0); i < TDim::value; ++i)
395 {
396 if(a[i] != b[i])
397 return false;
398 }
399 }
400 return true;
401 }
402
404 ALPAKA_FN_HOST_ACC friend constexpr auto operator!=(Vec const& a, Vec const& b) -> bool
405 {
406 return !(a == b);
407 }
408
409 //! \return The element-wise less than relation of two vectors.
411 ALPAKA_FN_HOST_ACC friend constexpr auto operator<(Vec const& p, Vec const& q) -> Vec<TDim, bool>
412 {
413 Vec<TDim, bool> r;
414 if constexpr(TDim::value > 0)
415 {
416 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
417 r[i] = p[i] < q[i];
418 }
419 return r;
420 }
421
422 //! \return The element-wise less than relation of two vectors.
424 ALPAKA_FN_HOST_ACC friend constexpr auto operator<=(Vec const& p, Vec const& q) -> Vec<TDim, bool>
425 {
426 Vec<TDim, bool> r;
427 if constexpr(TDim::value > 0)
428 {
429 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
430 r[i] = p[i] <= q[i];
431 }
432 return r;
433 }
434
435 //! \return The element-wise greater than relation of two vectors.
437 ALPAKA_FN_HOST_ACC friend constexpr auto operator>(Vec const& p, Vec const& q) -> Vec<TDim, bool>
438 {
439 Vec<TDim, bool> r;
440 if constexpr(TDim::value > 0)
441 {
442 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
443 r[i] = p[i] > q[i];
444 }
445 return r;
446 }
447
448 //! \return The element-wise greater equal than relation of two vectors.
450 ALPAKA_FN_HOST_ACC friend constexpr auto operator>=(Vec const& p, Vec const& q) -> Vec<TDim, bool>
451 {
452 Vec<TDim, bool> r;
453 if constexpr(TDim::value > 0)
454 {
455 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
456 r[i] = p[i] >= q[i];
457 }
458 return r;
459 }
460
461 //! \return The element-wise logical and relation of two vectors.
463 ALPAKA_FN_HOST_ACC friend constexpr auto operator&&(Vec const& p, Vec const& q) -> Vec<TDim, bool>
464 {
465 Vec<TDim, bool> r;
466 if constexpr(TDim::value > 0)
467 {
468 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
469 r[i] = p[i] && q[i];
470 }
471 return r;
472 }
473
474 //! \return The element-wise logical or relation of two vectors.
476 ALPAKA_FN_HOST_ACC friend constexpr auto operator||(Vec const& p, Vec const& q) -> Vec<TDim, bool>
477 {
478 Vec<TDim, bool> r;
479 if constexpr(TDim::value > 0)
480 {
481 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
482 r[i] = p[i] || q[i];
483 }
484 return r;
485 }
486
487 ALPAKA_FN_HOST friend constexpr auto operator<<(std::ostream& os, Vec const& v) -> std::ostream&
488 {
489 os << "(";
490 if constexpr(TDim::value > 0)
491 {
492 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
493 {
494 os << v[i];
495 if(i != TDim::value - 1)
496 os << ", ";
497 }
498 }
499 else
500 os << ".";
501 os << ")";
502
503 return os;
504 }
505
506 private:
507 // Zero sized arrays are not allowed, therefore zero-dimensional vectors have one member.
508 TVal m_data[TDim::value == 0u ? 1u : TDim::value];
509 };
510
511 template<typename TFirstIndex, typename... TRestIndices>
512 ALPAKA_FN_HOST_ACC Vec(TFirstIndex&&, TRestIndices&&...)
513 -> Vec<DimInt<1 + sizeof...(TRestIndices)>, std::decay_t<TFirstIndex>>;
514
515 template<typename T>
516 inline constexpr bool isVec = false;
517
518 template<typename TDim, typename TVal>
519 inline constexpr bool isVec<Vec<TDim, TVal>> = true;
520
521 //! Converts a Vec to a std::array
522 template<typename TDim, typename TVal>
523 ALPAKA_FN_HOST_ACC constexpr auto toArray(Vec<TDim, TVal> const& v) -> std::array<TVal, TDim::value>
524 {
525 std::array<TVal, TDim::value> a{};
526 if constexpr(TDim::value > 0)
527 {
528 for(unsigned i = 0; i < TDim::value; i++)
529 a[i] = v[i];
530 }
531 return a;
532 }
533
534 //! \return The element-wise minimum of one or more vectors.
536 template<
537 typename TDim,
538 typename TVal,
539 typename... Vecs,
540 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
541 ALPAKA_FN_HOST_ACC constexpr auto elementwise_min(Vec<TDim, TVal> const& p, Vecs const&... qs) -> Vec<TDim, TVal>
542 {
544 if constexpr(TDim::value > 0)
545 {
546 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
547 r[i] = std::min({p[i], qs[i]...});
548 }
549 return r;
550 }
551
552 //! \return The element-wise maximum of one or more vectors.
554 template<
555 typename TDim,
556 typename TVal,
557 typename... Vecs,
558 typename = std::enable_if_t<(std::is_same_v<Vec<TDim, TVal>, Vecs> && ...)>>
559 ALPAKA_FN_HOST_ACC constexpr auto elementwise_max(Vec<TDim, TVal> const& p, Vecs const&... qs) -> Vec<TDim, TVal>
560 {
562 if constexpr(TDim::value > 0)
563 {
564 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
565 r[i] = std::max({p[i], qs[i]...});
566 }
567 return r;
568 }
569
570 namespace trait
571 {
572 //! The Vec dimension get trait specialization.
573 template<typename TDim, typename TVal>
574 struct DimType<Vec<TDim, TVal>>
575 {
576 using type = TDim;
577 };
578
579 //! The Vec idx type trait specialization.
580 template<typename TDim, typename TVal>
581 struct IdxType<Vec<TDim, TVal>>
582 {
583 using type = TVal;
584 };
585
586 //! Specialization for selecting a sub-vector.
587 template<typename TDim, typename TVal, std::size_t... TIndices>
588 struct SubVecFromIndices<Vec<TDim, TVal>, std::index_sequence<TIndices...>>
589 {
591 Vec<TDim, TVal> const& vec) -> Vec<DimInt<sizeof...(TIndices)>, TVal>
592 {
593 if constexpr(std::is_same_v<std::index_sequence<TIndices...>, std::make_index_sequence<TDim::value>>)
594 {
595 return vec; // Return whole vector.
596 }
597 else
598 {
599 static_assert(
600 sizeof...(TIndices) <= TDim::value,
601 "The sub-vector's dimensionality must be smaller than or equal to the original "
602 "dimensionality.");
603 return {vec[TIndices]...}; // Return sub-vector.
604 }
606 }
607 };
608
609 template<typename TValNew, typename TDim, typename TVal>
610 struct CastVec<TValNew, Vec<TDim, TVal>>
611 {
614 {
615 if constexpr(std::is_same_v<TValNew, TVal>)
616 {
617 return vec;
618 }
619 else
620 {
622 if constexpr(TDim::value > 0)
623 {
624 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
625 r[i] = static_cast<TValNew>(vec[i]);
626 }
627 return r;
628 }
630 }
631 };
632
633 //! ReverseVec specialization for Vec.
634 template<typename TDim, typename TVal>
635 struct ReverseVec<Vec<TDim, TVal>>
636 {
639 {
640 if constexpr(TDim::value <= 1)
641 {
642 return vec;
643 }
644 else
645 {
647 for(typename TDim::value_type i = 0; i < TDim::value; ++i)
648 r[i] = vec[TDim::value - 1u - i];
649 return r;
650 }
652 }
653 };
654
655 //! Concatenation specialization for Vec.
656 template<typename TDimL, typename TDimR, typename TVal>
657 struct ConcatVec<Vec<TDimL, TVal>, Vec<TDimR, TVal>>
658 {
660 ALPAKA_FN_HOST_ACC static constexpr auto concatVec(
661 Vec<TDimL, TVal> const& vecL,
663 {
665 if constexpr(TDimL::value > 0)
666 {
667 for(typename TDimL::value_type i = 0; i < TDimL::value; ++i)
668 r[i] = vecL[i];
669 }
670 if constexpr(TDimR::value > 0)
671 {
672 for(typename TDimR::value_type i = 0; i < TDimR::value; ++i)
673 r[TDimL::value + i] = vecR[i];
674 }
675 return r;
676 }
677 };
678 } // namespace trait
679} // namespace alpaka
680
681#if defined(__clang__)
682# pragma GCC diagnostic push
683# pragma GCC diagnostic ignored "-Wmismatched-tags"
684#endif
685namespace std
686{
687 template<typename TDim, typename TVal>
688 struct tuple_size<alpaka::Vec<TDim, TVal>> : integral_constant<size_t, TDim::value>
689 {
690 };
691
692 template<size_t I, typename TDim, typename TVal>
693 struct tuple_element<I, alpaka::Vec<TDim, TVal>>
694 {
695 using type = TVal;
696 };
697} // namespace std
698#if defined(__clang__)
699# pragma GCC diagnostic pop
700#endif
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
A n-dimensional vector.
Definition Vec.hpp:38
ALPAKA_FN_HOST_ACC constexpr auto begin() -> TVal *
Definition Vec.hpp:111
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto ones() -> Vec< TDim, TVal >
One value constructor.
Definition Vec.hpp:106
ALPAKA_FN_HOST_ACC constexpr auto begin() const -> TVal const *
Definition Vec.hpp:116
ALPAKA_FN_HOST_ACC constexpr auto front() -> TVal &
Definition Vec.hpp:131
ALPAKA_FN_HOST_ACC constexpr Vec()
Definition Vec.hpp:52
Val value_type
STL-like value_type.
Definition Vec.hpp:44
TDim Dim
Definition Vec.hpp:42
ALPAKA_FN_HOST_ACC constexpr Vec(F &&generator)
Generator constructor. Initializes the vector with the values returned from generator(IC) in order,...
Definition Vec.hpp:71
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto zeros() -> Vec< TDim, TVal >
Zero value constructor.
Definition Vec.hpp:99
TVal Val
Definition Vec.hpp:43
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr Vec(TArgs &&... args)
Value constructor. This constructor is only available if the number of parameters matches the vector ...
Definition Vec.hpp:63
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto all(TVal const &val) -> Vec< TDim, TVal >
Single value constructor.
Definition Vec.hpp:89
ALPAKA_FN_HOST_ACC constexpr auto front() const -> TVal const &
Definition Vec.hpp:136
ALPAKA_FN_HOST_ACC constexpr auto end() const -> TVal const *
Definition Vec.hpp:126
ALPAKA_FN_HOST_ACC constexpr auto end() -> TVal *
Definition Vec.hpp:121
ALPAKA_FN_HOST_ACC constexpr auto back() -> TVal &
Definition Vec.hpp:141
ALPAKA_FN_HOST_ACC constexpr auto back() const -> TVal const &
Definition Vec.hpp:146
#define ALPAKA_FN_HOST
Definition Common.hpp:40
#define ALPAKA_FN_HOST_ACC
Definition Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition Common.hpp:82
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto assertValueUnsigned(TArg const &arg) -> void
This method checks integral values if they are greater or equal zero. The implementation prevents war...
Definition Assert.hpp:77
auto clipCast(V const &val) -> T
Definition ClipCast.hpp:16
ALPAKA_FN_HOST_ACC Complex< T > operator+(Complex< T > const &val)
Host-device arithmetic operations matching std::complex<T>.
Definition Complex.hpp:188
ALPAKA_FN_HOST_ACC Complex< T > operator-(Complex< T > const &val)
Unary minus.
Definition Complex.hpp:195
constexpr ALPAKA_FN_HOST_ACC bool operator==(Complex< T > const &lhs, Complex< T > const &rhs)
Equality of two complex numbers.
Definition Complex.hpp:294
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &os, Complex< T > const &x)
Host-only output of a complex number.
Definition Complex.hpp:345
ALPAKA_FN_HOST_ACC Complex< T > operator*(Complex< T > const &lhs, Complex< T > const &rhs)
Muptiplication of two complex numbers.
Definition Complex.hpp:244
constexpr ALPAKA_FN_HOST_ACC bool operator!=(Complex< T > const &lhs, Complex< T > const &rhs)
Inequality of two complex numbers.
Definition Complex.hpp:320
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
Definition Traits.hpp:1263
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
Definition Traits.hpp:1280
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto foldr(TFnObj const &, T const &t) -> T
Definition Fold.hpp:13
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto all(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
Definition Traits.hpp:114
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto any(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
Definition Traits.hpp:137
The alpaka accelerator library.
ALPAKA_FN_HOST_ACC constexpr auto toArray(Vec< TDim, TVal > const &v) -> std::array< TVal, TDim::value >
Converts a Vec to a std::array.
Definition Vec.hpp:523
constexpr bool isVec
Definition Vec.hpp:516
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_min(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
Definition Vec.hpp:541
std::integral_constant< std::size_t, N > DimInt
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC constexpr auto elementwise_max(Vec< TDim, TVal > const &p, Vecs const &... qs) -> Vec< TDim, TVal >
Definition Vec.hpp:559
ALPAKA_FN_HOST_ACC Vec(TFirstIndex &&, TRestIndices &&...) -> Vec< DimInt< 1+sizeof...(TRestIndices)>, std::decay_t< TFirstIndex > >
STL namespace.
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto castVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TValNew >
Definition Vec.hpp:613
Trait for casting a vector.
Definition Traits.hpp:26
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto concatVec(Vec< TDimL, TVal > const &vecL, Vec< TDimR, TVal > const &vecR) -> Vec< DimInt< TDimL::value+TDimR::value >, TVal >
Definition Vec.hpp:660
Trait for concatenating two vectors.
Definition Traits.hpp:34
The dimension getter type trait.
Definition Traits.hpp:14
The idx type trait.
Definition Traits.hpp:25
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto reverseVec(Vec< TDim, TVal > const &vec) -> Vec< TDim, TVal >
Definition Vec.hpp:638
Trait for reversing a vector.
Definition Traits.hpp:30
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC constexpr auto subVecFromIndices(Vec< TDim, TVal > const &vec) -> Vec< DimInt< sizeof...(TIndices)>, TVal >
Definition Vec.hpp:590
Trait for selecting a sub-vector.
Definition Traits.hpp:22