11 #ifndef CUBBYFLOW_MATRIX_EXPRESSION_HPP 12 #define CUBBYFLOW_MATRIX_EXPRESSION_HPP 20 static constexpr
size_t MATRIX_SIZE_DYNAMIC = 0;
22 template <
size_t Rows,
size_t Cols>
25 return (Rows == MATRIX_SIZE_DYNAMIC) || (Cols == MATRIX_SIZE_DYNAMIC);
28 template <
size_t Rows,
size_t Cols>
31 return !IsMatrixSizeDynamic<Rows, Cols>();
34 template <
size_t Rows,
size_t Cols>
37 return IsMatrixSizeStatic<Rows, Cols>() && (Rows == Cols);
40 template <
size_t Rows,
size_t Cols>
43 static const bool value = IsMatrixSizeDynamic<Rows, Cols>();
46 template <
size_t Rows,
size_t Cols>
49 static const bool value = IsMatrixSizeStatic<Rows, Cols>();
52 template <
size_t Rows,
size_t Cols>
55 static const bool value = IsMatrixStaticSquare<Rows, Cols>();
58 template <
typename T,
size_t Rows,
size_t Cols>
61 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
64 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
67 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
70 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
73 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
74 typename UnaryOperation>
77 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
78 typename BinaryOperation>
92 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
99 [[nodiscard]] constexpr
size_t GetRows()
const;
102 [[nodiscard]] constexpr
size_t GetCols()
const;
105 [[nodiscard]] T Eval(
size_t i,
size_t j)
const;
111 template <
size_t R,
size_t C,
typename E>
112 [[nodiscard]]
bool IsSimilar(
114 double tol = std::numeric_limits<double>::epsilon())
const;
117 [[nodiscard]] constexpr
bool IsSquare()
const;
133 [[nodiscard]]
ValueType Determinant()
const;
135 [[nodiscard]]
size_t DominantAxis()
const;
137 [[nodiscard]]
size_t SubdominantAxis()
const;
141 [[nodiscard]]
ValueType NormSquared()
const;
143 [[nodiscard]]
ValueType FrobeniusNorm()
const;
147 [[nodiscard]]
ValueType LengthSquared()
const;
150 template <
size_t R,
size_t C,
typename E>
155 template <
size_t R,
size_t C,
typename E>
156 [[nodiscard]]
ValueType DistanceSquaredTo(
191 template <
typename U>
194 template <
size_t R,
size_t C,
typename E,
typename U = ValueType>
195 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() || Cols == 1) &&
196 (IsMatrixSizeDynamic<R, C>() || C == 1),
200 template <
size_t R,
size_t C,
typename E,
typename U = ValueType>
201 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
202 (Rows == 2 && Cols == 1)) &&
203 (IsMatrixSizeDynamic<R, C>() || (R == 2 && C == 1)),
207 template <
size_t R,
size_t C,
typename E,
typename U = ValueType>
208 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
209 (Rows == 3 && Cols == 1)) &&
210 (IsMatrixSizeDynamic<R, C>() || (R == 3 && C == 1)),
215 template <
size_t R,
size_t C,
typename E,
typename U = ValueType>
216 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
217 ((Rows == 2 || Rows == 3) && Cols == 1)) &&
218 (IsMatrixSizeDynamic<R, C>() ||
219 ((R == 2 || R == 3) && C == 1)),
224 template <
size_t R,
size_t C,
typename E,
typename U = ValueType>
225 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
226 ((Rows == 2 || Rows == 3) && Cols == 1)) &&
227 (IsMatrixSizeDynamic<R, C>() ||
228 ((R == 2 || R == 3) && C == 1)),
233 template <
typename U = ValueType>
234 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
235 (Rows == 2 && Cols == 1)),
240 template <
typename U = ValueType>
241 std::enable_if_t<(IsMatrixSizeDynamic<Rows, Cols>() ||
242 (Rows == 3 && Cols == 1)),
247 [[nodiscard]] Derived& GetDerived();
250 [[nodiscard]]
const Derived& GetDerived()
const;
264 template <
typename U = ValueType>
265 static std::enable_if_t<
266 (Rows > 4 && Cols > 4) || IsMatrixSizeDynamic<Rows, Cols>(), U>
281 template <
typename M = Matrix<T, Rows, Cols>>
283 std::enable_if_t<(Rows > 4 && Cols > 4) ||
284 IsMatrixSizeDynamic<Rows, Cols>(),
288 template <
typename T,
size_t Rows,
size_t Cols>
294 : m_rows(r), m_cols(c), m_val(val)
299 [[nodiscard]] constexpr
size_t GetRows()
const;
301 [[nodiscard]] constexpr
size_t GetCols()
const;
303 constexpr T operator()(
size_t,
size_t)
const;
311 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
321 [[nodiscard]] constexpr
size_t GetRows()
const;
323 [[nodiscard]] constexpr
size_t GetCols()
const;
325 T operator()(
size_t i,
size_t j)
const;
331 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
334 MatrixOffDiagonal<T, Rows, Cols, M1>>
342 [[nodiscard]] constexpr
size_t GetRows()
const;
344 [[nodiscard]] constexpr
size_t GetCols()
const;
346 T operator()(
size_t i,
size_t j)
const;
352 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
357 constexpr
MatrixTri(
const M1& mat1,
bool isUpper,
bool isStrict)
358 : m_mat1(mat1), m_isUpper(isUpper), m_isStrict(isStrict)
363 [[nodiscard]] constexpr
size_t GetRows()
const;
365 [[nodiscard]] constexpr
size_t GetCols()
const;
367 T operator()(
size_t i,
size_t j)
const;
375 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
377 :
public MatrixExpression<T, Rows, Cols, MatrixTranspose<T, Rows, Cols, M1>>
385 [[nodiscard]] constexpr
size_t GetRows()
const;
387 [[nodiscard]] constexpr
size_t GetCols()
const;
389 constexpr T operator()(
size_t i,
size_t j)
const;
395 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
396 typename UnaryOperation>
399 MatrixUnaryOp<T, Rows, Cols, M1, UnaryOperation>>
407 [[nodiscard]] constexpr
size_t GetRows()
const;
409 [[nodiscard]] constexpr
size_t GetCols()
const;
411 constexpr T operator()(
size_t i,
size_t j)
const;
418 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
421 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
424 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
427 template <
typename T,
size_t Rows,
size_t Cols,
typename U,
typename M1>
430 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
433 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
436 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
450 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2,
451 typename BinaryOperation>
455 MatrixElemWiseBinaryOp<T, Rows, Cols, E1, E2, BinaryOperation>>
459 : m_mat1(mat1), m_mat2(mat2)
464 [[nodiscard]] constexpr
size_t GetRows()
const;
466 [[nodiscard]] constexpr
size_t GetCols()
const;
468 constexpr T operator()(
size_t i,
size_t j)
const;
473 BinaryOperation m_op;
477 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
482 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
487 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
492 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
497 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
502 template <
typename T,
size_t Rows,
size_t Cols,
typename E1,
typename E2>
506 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
510 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
514 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
518 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
522 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
526 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
530 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
531 typename BinaryOperation>
535 MatrixScalarElemWiseBinaryOp<T, Rows, Cols, M1, BinaryOperation>>
539 : m_mat1(mat1), m_scalar2(scalar2)
544 [[nodiscard]] constexpr
size_t GetRows()
const;
546 [[nodiscard]] constexpr
size_t GetCols()
const;
548 constexpr T operator()(
size_t i,
size_t j)
const;
553 BinaryOperation m_op;
556 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
560 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
564 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
568 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
572 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
576 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
580 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
584 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
588 template <
typename T,
size_t Rows,
size_t Cols,
typename M2,
589 typename BinaryOperation>
593 ScalarMatrixElemWiseBinaryOp<T, Rows, Cols, M2, BinaryOperation>>
597 : m_scalar1(s1), m_mat2(m2)
602 [[nodiscard]] constexpr
size_t GetRows()
const;
604 [[nodiscard]] constexpr
size_t GetCols()
const;
606 constexpr T operator()(
size_t i,
size_t j)
const;
611 BinaryOperation m_op;
614 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
618 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
622 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
626 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
630 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
634 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
638 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
642 template <
typename T,
size_t Rows,
size_t Cols,
typename M2>
646 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
647 typename M3,
typename TernaryOperation>
651 MatrixTernaryOp<T, Rows, Cols, M1, M2, M3, TernaryOperation>>
655 : m_mat1(mat1), m_mat2(mat2), m_mat3(mat3)
660 [[nodiscard]] constexpr
size_t GetRows()
const;
662 [[nodiscard]] constexpr
size_t GetCols()
const;
664 constexpr T operator()(
size_t i,
size_t j)
const;
670 TernaryOperation m_op;
673 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
677 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
683 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
689 : m_mat1(mat1), m_mat2(mat2)
694 [[nodiscard]] constexpr
size_t GetRows()
const;
696 [[nodiscard]] constexpr
size_t GetCols()
const;
698 T operator()(
size_t i,
size_t j)
const;
705 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
Matrix expression for element-wise binary operation.
Definition: MatrixExpression.hpp:452
MatrixCSR< T > operator-(const MatrixCSR< T > &a)
Definition: MatrixCSR-Impl.hpp:1029
constexpr auto Ceil(const MatrixExpression< T, Rows, Cols, M1 > &a)
Definition: MatrixExpression-Impl.hpp:1025
std::enable_if_t< std::is_arithmetic< T >::value, T > Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.hpp:166
constexpr auto ElemDiv(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1094
Definition: MatrixExpression.hpp:648
constexpr MatrixElemWiseBinaryOp(const E1 &mat1, const E2 &mat2)
Definition: MatrixExpression.hpp:458
Definition: MatrixExpression.hpp:75
constexpr auto Floor(const MatrixExpression< T, Rows, Cols, M1 > &a)
Definition: MatrixExpression-Impl.hpp:1031
T ValueType
Definition: MatrixExpression.hpp:96
constexpr auto Max(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1112
MatrixCSR< T > operator/(const MatrixCSR< T > &a, T b)
Definition: MatrixCSR-Impl.hpp:1090
Definition: Matrix.hpp:27
constexpr bool IsMatrixStaticSquare()
Definition: MatrixExpression.hpp:35
static const bool value
Definition: MatrixExpression.hpp:43
Definition: pybind11Utils.hpp:20
constexpr bool IsMatrixSizeStatic()
Definition: MatrixExpression.hpp:29
constexpr MatrixMul(const M1 &mat1, const M2 &mat2)
Definition: MatrixExpression.hpp:688
constexpr auto ElemMul(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1085
Definition: MatrixExpression.hpp:71
constexpr auto Min(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1103
Definition: MatrixExpression.hpp:590
constexpr MatrixOffDiagonal(const M1 &mat1)
Definition: MatrixExpression.hpp:337
MatrixCSR< T > operator+(const MatrixCSR< T > &a, const MatrixCSR< T > &b)
Definition: MatrixCSR-Impl.hpp:1035
constexpr MatrixConstant(size_t r, size_t c, const T &val)
Definition: MatrixExpression.hpp:293
Definition: MatrixExpression.hpp:47
constexpr MatrixTri(const M1 &mat1, bool isUpper, bool isStrict)
Definition: MatrixExpression.hpp:357
Definition: MatrixExpression.hpp:53
Definition: MatrixExpression.hpp:68
Definition: MatrixExpression.hpp:65
Base class for matrix expression.
Definition: MatrixExpression.hpp:93
std::enable_if_t< std::is_arithmetic< T >::value, T > AbsMax(T x, T y)
Returns the absolute maximum value among the two inputs.
Definition: MathUtils-Impl.hpp:84
constexpr MatrixDiagonal(const M1 &mat1)
Definition: MatrixExpression.hpp:316
std::enable_if_t< std::is_arithmetic< T >::value, T > AbsMin(T x, T y)
Returns the absolute minimum value among the two inputs.
Definition: MathUtils-Impl.hpp:78
Definition: MatrixExpression.hpp:62
constexpr ScalarMatrixElemWiseBinaryOp(const T &s1, const M2 &m2)
Definition: MatrixExpression.hpp:596
Definition: MatrixExpression.hpp:289
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.hpp:543
constexpr bool IsMatrixSizeDynamic()
Definition: MatrixExpression.hpp:23
constexpr MatrixUnaryOp(const M1 &mat1)
Definition: MatrixExpression.hpp:402
Definition: MatrixExpression.hpp:79
Definition: MatrixExpression.hpp:41
constexpr MatrixTernaryOp(const M1 &mat1, const M2 &mat2, const M3 &mat3)
Definition: MatrixExpression.hpp:654
constexpr MatrixScalarElemWiseBinaryOp(const M1 &mat1, const T &scalar2)
Definition: MatrixExpression.hpp:538
constexpr MatrixTranspose(const M1 &m_mat1)
Definition: MatrixExpression.hpp:380
Definition: MatrixExpression.hpp:684