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
Product.h
1#ifndef PBAT_MATH_LINALG_MINI_PRODUCT_H
2#define PBAT_MATH_LINALG_MINI_PRODUCT_H
3
4#include "Api.h"
5#include "Concepts.h"
6#include "pbat/HostDevice.h"
7
8#include <type_traits>
9#include <utility>
10
11namespace pbat {
12namespace math {
13namespace linalg {
14namespace mini {
15
16template <class /*CMatrix*/ TLhsMatrix, class /*CMatrix*/ TRhsMatrix>
17class Product
18{
19 public:
20 using LhsNestedType = TLhsMatrix;
21 using RhsNestedType = TRhsMatrix;
22
23 using ScalarType = typename LhsNestedType::ScalarType;
24 using SelfType = Product<LhsNestedType, RhsNestedType>;
25
26 static auto constexpr kRows = LhsNestedType::kRows;
27 static auto constexpr kCols = RhsNestedType::kCols;
28 static bool constexpr bRowMajor = false;
29
30 PBAT_HOST_DEVICE Product(LhsNestedType const& _A, RhsNestedType const& _B) : A(_A), B(_B) {}
31
32 PBAT_HOST_DEVICE ScalarType operator()(auto i, auto j) const
33 {
34 using IntegerType = std::remove_const_t<decltype(LhsNestedType::kRows)>;
35 auto contract = [this, i, j]<IntegerType... K>(std::integer_sequence<IntegerType, K...>) {
36 return ((A(i, K) * B(K, j)) + ...);
37 };
38 return contract(std::make_integer_sequence<IntegerType, LhsNestedType::kCols>());
39 }
40
41 // Vector(ized) access
42 PBAT_HOST_DEVICE ScalarType operator()(auto i) const { return (*this)(i % kRows, i / kRows); }
43 PBAT_HOST_DEVICE ScalarType operator[](auto i) const { return (*this)(i); }
44
45 PBAT_MINI_READ_API(SelfType)
46
47 private:
48 LhsNestedType const& A;
49 RhsNestedType const& B;
50};
51
52template <CMatrix TLhsMatrix, CMatrix TRhsMatrix>
53PBAT_HOST_DEVICE auto operator*(TLhsMatrix const& A, TRhsMatrix const& B)
54{
56}
57
58} // namespace mini
59} // namespace linalg
60} // namespace math
61} // namespace pbat
62
63#endif // PBAT_MATH_LINALG_MINI_PRODUCT_H
Definition Product.h:18
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