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
Flatten.h
1#ifndef PBAT_MATH_LINALG_MINI_FLATTEN_H
2#define PBAT_MATH_LINALG_MINI_FLATTEN_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>
16class FlatView
17{
18 public:
19 using NestedType = TMatrix;
20 using ScalarType = typename NestedType::ScalarType;
21 using SelfType = FlatView<NestedType>;
22
23 static auto constexpr kRows = NestedType::kRows * NestedType::kCols;
24 static auto constexpr kCols = 1;
25 static bool constexpr bRowMajor = false;
26
27 PBAT_HOST_DEVICE FlatView(NestedType const& A) : mA(A) {}
28
29 PBAT_HOST_DEVICE ScalarType operator()(auto i, [[maybe_unused]] auto j) const { return mA(i); }
30
31 // Vector(ized) access
32 PBAT_HOST_DEVICE ScalarType operator()(auto i) const { return mA(i); }
33 PBAT_HOST_DEVICE ScalarType operator[](auto i) const { return mA(i); }
34
35 PBAT_MINI_READ_WRITE_API(SelfType)
36
37 private:
38 NestedType const& mA;
39};
40
41template <class /*CMatrix*/ TMatrix>
42PBAT_HOST_DEVICE auto Flatten(TMatrix&& A)
43{
44 using MatrixType = std::remove_cvref_t<TMatrix>;
45 return FlatView<MatrixType>(std::forward<TMatrix>(A));
46}
47
48} // namespace mini
49} // namespace linalg
50} // namespace math
51} // namespace pbat
52
53#endif // PBAT_MATH_LINALG_MINI_FLATTEN_H
Definition Flatten.h:17
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