PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
Repeat.h
1#ifndef PBAT_MATH_LINALG_MINI_REPEAT_H
2#define PBAT_MATH_LINALG_MINI_REPEAT_H
3
4#include "Api.h"
5#include "Concepts.h"
6#include "pbat/HostDevice.h"
7
8#include <type_traits>
9
10namespace pbat {
11namespace math {
12namespace linalg {
13namespace mini {
14
15template <class /*CMatrix*/ TMatrix, int RepeatRows, int RepeatCols>
16class TiledView
17{
18 public:
19 using NestedType = TMatrix;
20 using ScalarType = typename NestedType::ScalarType;
21 using SelfType = TiledView<NestedType, RepeatRows, RepeatCols>;
22
23 static auto constexpr kRows = RepeatRows * NestedType::kRows;
24 static auto constexpr kCols = RepeatCols * NestedType::kCols;
25 static bool constexpr bRowMajor = NestedType::bRowMajor;
26
27 PBAT_HOST_DEVICE TiledView(NestedType const& _A) : A(_A) {}
28
29 PBAT_HOST_DEVICE ScalarType operator()(auto i, auto j) const
30 {
31 return A(i % NestedType::kRows, j % NestedType::kCols);
32 }
33
34 // Vector(ized) access
35 PBAT_HOST_DEVICE ScalarType operator()(auto i) const { return (*this)(i % kRows, i / kRows); }
36 PBAT_HOST_DEVICE ScalarType operator[](auto i) const { return (*this)(i); }
37
38 PBAT_MINI_READ_API(SelfType)
39
40 private:
41 NestedType const& A;
42};
43
44template <auto RepeatRows, auto RepeatCols, class /*CMatrix*/ TMatrix>
45PBAT_HOST_DEVICE auto Repeat(TMatrix&& A)
46{
47 using MatrixType = std::remove_cvref_t<TMatrix>;
48 return TiledView<MatrixType, RepeatRows, RepeatCols>(std::forward<TMatrix>(A));
49}
50
51} // namespace mini
52} // namespace linalg
53} // namespace math
54} // namespace pbat
55
56#endif // PBAT_MATH_LINALG_MINI_REPEAT_H
Mini linear algebra related functionality.
Definition Assign.h:12
Linear Algebra related functionality.
Definition FilterEigenvalues.h:7
Math related functionality.
Definition Concepts.h:19
The main namespace of the library.
Definition Aliases.h:15