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
Concepts.h
1
#ifndef PBAT_MATH_LINALG_MINI_CONCEPTS_H
2
#define PBAT_MATH_LINALG_MINI_CONCEPTS_H
3
4
#include <concepts>
5
#include <type_traits>
6
#include <utility>
7
8
namespace
pbat
{
9
namespace
math
{
10
namespace
linalg
{
11
namespace
mini
{
12
13
template
<
class
TMatrix>
14
concept
CMatrix
=
requires
(TMatrix M)
15
{
16
typename
TMatrix::ScalarType;
17
{
18
TMatrix::kRows
19
} -> std::convertible_to<int>;
20
{
21
TMatrix::kCols
22
} -> std::convertible_to<int>;
23
{
24
TMatrix::bRowMajor
25
} -> std::convertible_to<bool>;
26
// WARNING: It seems that in our math/linalg/mini library, any concept constraint that uses
27
// member functions with the . notation fails. This probably has something to do with M not
28
// being a concrete type at the time when we are evaluating the concept constraint.
29
//{
30
// M.Rows()
31
//} -> std::convertible_to<int>;
32
//{
33
// M.Cols()
34
//} -> std::convertible_to<int>;
35
// WARNING: This constraint causes compile errors with nvcc, I don't know why!
36
#if not defined(__CUDACC__)
37
{
38
M(std::declval<int>(), std::declval<int>())
39
} -> std::convertible_to<typename TMatrix::ScalarType>;
40
#endif
41
};
42
43
// WARNING: These constraints don't compile with nvcc, unfortunately. Only use CMatrix concept in
44
// CUDA code.
45
#if not defined(__CUDACC__)
46
47
template
<
class
TMatrix>
48
concept
CReadableMatrix
=
CMatrix<TMatrix>
and
requires
(TMatrix M)
49
{
50
true
;
51
// WARNING:
52
// Unfortunately, these constraints cause compilation error, due to ambiguity between the const
53
// and non-const versions of these member function calls (tested with MSVC).
54
//{M.Transpose()};
55
//{M.Slice(std::declval<int>(), std::declval<int>())};
56
//{M.Col(std::declval<int>())};
57
//{M.Row(std::declval<int>())};
58
};
59
60
template
<
class
TMatrix>
61
concept
CWriteableMatrix
=
CMatrix<TMatrix>
and
requires
(TMatrix M)
62
{
63
{M(std::declval<int>(), std::declval<int>()) = std::declval<typename TMatrix::ScalarType>()};
64
{M = std::declval<TMatrix>()};
65
};
66
67
template
<
class
TMatrix>
68
concept
CReadableVectorizedMatrix
=
CMatrix<TMatrix>
and
requires
(TMatrix M)
69
{
70
{
71
M(std::declval<int>())
72
} -> std::convertible_to<typename TMatrix::ScalarType>;
73
{
74
M[std::declval<int>()]
75
} -> std::convertible_to<typename TMatrix::ScalarType>;
76
};
77
78
template
<
class
TMatrix>
79
concept
CWriteableVectorizedMatrix
=
CMatrix<TMatrix>
and
requires
(TMatrix M)
80
{
81
{M(std::declval<int>()) = std::declval<typename TMatrix::ScalarType>()};
82
{M[std::declval<int>()] = std::declval<typename TMatrix::ScalarType>()};
83
};
84
85
#else
86
87
template
<
class
TMatrix>
88
concept
CReadableMatrix
=
CMatrix<TMatrix>
;
89
90
template
<
class
TMatrix>
91
concept
CWriteableMatrix
=
CMatrix<TMatrix>
;
92
93
template
<
class
TMatrix>
94
concept
CReadableVectorizedMatrix
=
CMatrix<TMatrix>
;
95
96
template
<
class
TMatrix>
97
concept
CWriteableVectorizedMatrix
=
CMatrix<TMatrix>
;
98
99
#endif
// not defined(__CUDACC__)
100
101
}
// namespace mini
102
}
// namespace linalg
103
}
// namespace math
104
}
// namespace pbat
105
106
#define PBAT_MINI_CHECK_CMATRIX(TMatrix) static_assert(CMatrix<TMatrix>, "CMatrix not satisfied");
107
#define PBAT_MINI_CHECK_CREADABLEMATRIX(TMatrix) \
108
static_assert(CReadableMatrix<TMatrix>, "CReadableMatrix not satisfied");
109
#define PBAT_MINI_CHECK_CWRITEABLEMATRIX(TMatrix) \
110
static_assert(CWriteableMatrix<TMatrix>, "CWriteableMatrix not satisfied");
111
#define PBAT_MINI_CHECK_CREADABLEVECTORIZEDMATRIX(TMatrix) \
112
static_assert(CReadableVectorizedMatrix<TMatrix>, "CReadableVectorizedMatrix not satisfied");
113
#define PBAT_MINI_CHECK_CWRITEABLEVECTORIZEDMATRIX(TMatrix) \
114
static_assert(CWriteableVectorizedMatrix<TMatrix>, "CWriteableVectorizedMatrix not satisfied");
115
116
#define PBAT_MINI_CHECK_READABLE_CONCEPTS(TMatrix) \
117
PBAT_MINI_CHECK_CREADABLEMATRIX(TMatrix); \
118
PBAT_MINI_CHECK_CREADABLEVECTORIZEDMATRIX(TMatrix);
119
120
#define PBAT_MINI_CHECK_WRITEABLE_CONCEPTS(TMatrix) \
121
PBAT_MINI_CHECK_CWRITEABLEMATRIX(TMatrix); \
122
PBAT_MINI_CHECK_CWRITEABLEVECTORIZEDMATRIX(TMatrix);
123
124
#define PBAT_MINI_DIMENSIONS_API \
125
PBAT_HOST_DEVICE constexpr auto Rows() const \
126
{ \
127
return kRows; \
128
} \
129
PBAT_HOST_DEVICE constexpr auto Cols() const \
130
{ \
131
return kCols; \
132
}
133
134
#endif
// PBAT_MATH_LINALG_MINI_CONCEPTS_H
pbat::math::linalg::mini::CMatrix
Definition
Concepts.h:14
pbat::math::linalg::mini::CReadableMatrix
Definition
Concepts.h:48
pbat::math::linalg::mini::CReadableVectorizedMatrix
Definition
Concepts.h:68
pbat::math::linalg::mini::CWriteableMatrix
Definition
Concepts.h:61
pbat::math::linalg::mini::CWriteableVectorizedMatrix
Definition
Concepts.h:79
pbat::math::linalg::mini
Mini linear algebra related functionality.
Definition
Assign.h:12
pbat::math::linalg
Linear Algebra related functionality.
Definition
FilterEigenvalues.h:7
pbat::math
Math related functionality.
Definition
Concepts.h:19
pbat
The main namespace of the library.
Definition
Aliases.h:15
source
pbat
math
linalg
mini
Concepts.h
Generated by
1.13.2