11 #ifndef CUBBYFLOW_MATRIX_HPP 12 #define CUBBYFLOW_MATRIX_HPP 26 template <
typename T,
size_t Rows,
size_t Cols>
32 static_assert(IsMatrixSizeStatic<Rows, Cols>(),
33 "This class should be a static-sized matrix.");
37 using Base::operator();
54 template <
typename... Args>
56 : m_elements{ { first,
static_cast<ValueType>(rest)... } }
61 template <
size_t R,
size_t C,
typename E>
70 constexpr
Matrix(
const Matrix& other) : m_elements(other.m_elements)
75 constexpr
Matrix(Matrix&& other) noexcept
76 : m_elements(std::move(other.m_elements))
83 m_elements = other.m_elements;
89 m_elements = std::move(other.m_elements);
93 void Fill(
const T& val);
95 void Fill(
const std::function<T(
size_t i)>& func);
97 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
99 void Swap(Matrix& other);
101 [[nodiscard]] constexpr
size_t GetRows()
const;
103 [[nodiscard]] constexpr
size_t GetCols()
const;
122 std::array<T, Rows * Cols> m_elements;
125 template <
typename T>
131 using Base::operator();
151 template <
size_t R,
size_t C,
typename E>
154 Matrix(
const std::initializer_list<T>& lst);
158 constexpr
Matrix(
const Matrix& other) : x(other.x)
163 constexpr
Matrix(Matrix&& other) noexcept : x(std::move(other.x))
176 x = std::move(other.x);
180 void Fill(
const T& val);
182 void Fill(
const std::function<T(
size_t i)>& func);
184 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
186 void Swap(Matrix& other);
188 [[nodiscard]] constexpr
size_t GetRows()
const;
190 [[nodiscard]] constexpr
size_t GetCols()
const;
208 constexpr
static Matrix MakeUnitX();
210 constexpr
static Matrix MakeUnit(
size_t i);
215 template <
typename T>
221 using Base::operator();
236 constexpr
Matrix(
const T& _x,
const T& _y) : x(_x), y(_y)
241 template <
size_t R,
size_t C,
typename E>
244 Matrix(
const std::initializer_list<T>& lst);
248 constexpr
Matrix(
const Matrix& other) : x(other.x), y(other.y)
253 constexpr
Matrix(Matrix&& other) noexcept
254 : x(std::move(other.x)), y(std::move(other.y))
268 x = std::move(other.x);
269 y = std::move(other.y);
273 void Fill(
const T& val);
275 void Fill(
const std::function<T(
size_t i)>& func);
277 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
279 void Swap(Matrix& other);
281 [[nodiscard]] constexpr
size_t GetRows()
const;
283 [[nodiscard]] constexpr
size_t GetCols()
const;
301 constexpr
static Matrix MakeUnitX();
303 constexpr
static Matrix MakeUnitY();
305 constexpr
static Matrix MakeUnit(
size_t i);
311 template <
typename T>
317 using Base::operator();
327 constexpr
Matrix() : x(T{}), y(T{}), z(T{})
333 : x(_xy.x), y(_xy.y), z(_z)
338 constexpr
Matrix(
const T& _x,
const T& _y,
const T& _z)
339 : x(_x), y(_y), z(_z)
344 template <
size_t R,
size_t C,
typename E>
347 Matrix(
const std::initializer_list<T>& lst);
351 constexpr
Matrix(
const Matrix& other) : x(other.x), y(other.y), z(other.z)
356 constexpr
Matrix(Matrix&& other) noexcept
357 : x(std::move(other.x)), y(std::move(other.y)), z(std::move(other.z))
372 x = std::move(other.x);
373 y = std::move(other.y);
374 z = std::move(other.z);
378 void Fill(
const T& val);
380 void Fill(
const std::function<T(
size_t i)>& func);
382 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
384 void Swap(Matrix& other);
386 [[nodiscard]] constexpr
size_t GetRows()
const;
388 [[nodiscard]] constexpr
size_t GetCols()
const;
406 constexpr
static Matrix MakeUnitX();
408 constexpr
static Matrix MakeUnitY();
410 constexpr
static Matrix MakeUnitZ();
412 constexpr
static Matrix MakeUnit(
size_t i);
419 template <
typename T>
425 using Base::operator();
435 constexpr
Matrix() : x(T{}), y(T{}), z(T{}), w(T{})
440 constexpr
Matrix(
const T& _x,
const T& _y,
const T& _z,
const T& _w)
441 : x(_x), y(_y), z(_z), w(_w)
446 template <
size_t R,
size_t C,
typename E>
449 Matrix(
const std::initializer_list<T>& lst);
454 : x(other.x), y(other.y), z(other.z), w(other.w)
459 constexpr
Matrix(Matrix&& other) noexcept
460 : x(std::move(other.x)),
461 y(std::move(other.y)),
462 z(std::move(other.z)),
463 w(std::move(other.w))
479 x = std::move(other.x);
480 y = std::move(other.y);
481 z = std::move(other.z);
482 w = std::move(other.w);
486 void Fill(
const T& val);
488 void Fill(
const std::function<T(
size_t i)>& func);
490 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
492 void Swap(Matrix& other);
494 [[nodiscard]] constexpr
size_t GetRows()
const;
496 [[nodiscard]] constexpr
size_t GetCols()
const;
514 constexpr
static Matrix MakeUnitX();
516 constexpr
static Matrix MakeUnitY();
518 constexpr
static Matrix MakeUnitZ();
520 constexpr
static Matrix MakeUnitW();
522 constexpr
static Matrix MakeUnit(
size_t i);
530 template <
typename T>
531 class Matrix<T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC> final
533 T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC,
534 Matrix<T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC>>,
536 T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC,
537 Matrix<T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC>>
548 T, MATRIX_SIZE_DYNAMIC, MATRIX_SIZE_DYNAMIC,
555 template <
size_t R,
size_t C,
typename E>
564 Matrix(
const Matrix& other);
566 Matrix(Matrix&& other) noexcept;
570 Matrix&
operator=(Matrix&& other) noexcept;
572 void Fill(
const T& val);
574 void Fill(
const std::function<T(
size_t i)>& func);
576 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
578 void Swap(Matrix& other);
584 [[nodiscard]]
size_t GetRows()
const;
586 [[nodiscard]]
size_t GetCols()
const;
605 std::vector<T> m_elements;
610 template <
typename T>
611 class Matrix<T, MATRIX_SIZE_DYNAMIC, 1> final
613 Matrix<T, MATRIX_SIZE_DYNAMIC, 1>>,
615 Matrix<T, MATRIX_SIZE_DYNAMIC, 1>>
632 template <
size_t R,
size_t C,
typename E>
635 Matrix(
const std::initializer_list<T>& lst);
641 Matrix(
const Matrix& other);
643 Matrix(Matrix&& other) noexcept;
647 Matrix&
operator=(Matrix&& other) noexcept;
649 void Fill(
const T& val);
651 void Fill(
const std::function<T(
size_t i)>& func);
653 void Fill(
const std::function<T(
size_t i,
size_t j)>& func);
655 void Swap(Matrix& other);
661 void AddElement(
const Matrix& newElems);
665 [[nodiscard]]
size_t GetRows()
const;
667 [[nodiscard]] constexpr
size_t GetCols()
const;
686 std::vector<T> m_elements;
689 template <
typename T>
692 template <
typename T>
695 template <
typename T>
737 template <
typename T,
size_t Rows>
740 template <
typename T>
743 template <
typename T>
746 template <
typename T>
749 template <
typename T>
804 template <
typename T>
820 template <
typename T>
836 template <
typename T,
size_t Rows,
size_t Cols>
842 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
845 template <
typename T,
size_t Rows,
size_t Cols>
848 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
851 template <
typename T,
size_t Rows,
size_t Cols>
854 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
857 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
860 template <
typename T,
size_t Rows,
size_t Cols>
863 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
866 template <
typename T,
size_t Rows,
size_t Cols>
869 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
870 constexpr std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(),
bool>
operator==(
874 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
879 template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
884 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
885 typename BinaryOperation>
886 constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value, T>
890 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
891 constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value, T>
894 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
895 constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value, T>
898 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
899 typename BinaryOperation>
900 constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value, T>
904 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
905 constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value, T>
908 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
909 constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value, T>
912 template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
916 template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
917 typename M3,
typename M4>
constexpr Matrix()
Definition: Matrix.hpp:47
constexpr Matrix(Matrix &&other) noexcept
Definition: Matrix.hpp:356
constexpr Matrix(const Matrix< T, 2, 1 > &_xy, const T &_z)
Definition: Matrix.hpp:332
Matrix & operator=(Matrix &&other) noexcept
Definition: Matrix.hpp:87
const T * ConstPointer
Definition: Matrix.hpp:323
Matrix & operator=(const Matrix &other)
Definition: Matrix.hpp:468
T & Reference
Definition: Matrix.hpp:320
Matrix & operator=(Matrix &&other) noexcept
Definition: Matrix.hpp:477
T * Pointer
Definition: Matrix.hpp:226
ConstPointer ConstIterator
Definition: Matrix.hpp:546
const T * ConstPointer
Definition: Matrix.hpp:622
constexpr Matrix(Matrix &&other) noexcept
Definition: Matrix.hpp:459
Definition: MatrixDenseBase.hpp:20
Matrix & operator=(Matrix &&other) noexcept
Definition: Matrix.hpp:370
Pointer Iterator
Definition: Matrix.hpp:432
ConstPointer ConstIterator
Definition: Matrix.hpp:624
const double & ConstReference
Definition: Matrix.hpp:41
ValueType y
Definition: Matrix.hpp:415
const T & ConstReference
Definition: Matrix.hpp:321
Matrix & operator=(const Matrix &other)
Definition: Matrix.hpp:259
T & Reference
Definition: Matrix.hpp:134
constexpr Matrix(const Matrix &other)
Definition: Matrix.hpp:70
double * Pointer
Definition: Matrix.hpp:42
constexpr std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), bool > operator==(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: Matrix-Impl.hpp:1408
Returns the type of the value itself.
Definition: TypeHelpers.hpp:18
T * Pointer
Definition: Matrix.hpp:430
T ValueType
Definition: Matrix.hpp:319
void CopyFrom(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
Definition: MatrixDenseBase-Impl.hpp:21
const T * ConstPointer
Definition: Matrix.hpp:544
T ValueType
Definition: Matrix.hpp:223
Pointer Iterator
Definition: Matrix.hpp:324
Pointer Iterator
Definition: Matrix.hpp:545
const T * ConstPointer
Definition: Matrix.hpp:137
ValueType w
Definition: Matrix.hpp:527
constexpr Matrix(const T &_x)
Definition: Matrix.hpp:146
const double * ConstPointer
Definition: Matrix.hpp:43
ValueType x
Definition: Matrix.hpp:307
double ValueType
Definition: Matrix.hpp:39
T ValueType
Definition: Matrix.hpp:540
Matrix & operator=(Matrix &&other) noexcept
Definition: Matrix.hpp:174
Matrix & operator=(const Matrix &other)
Definition: Matrix.hpp:168
ValueType y
Definition: Matrix.hpp:308
constexpr Matrix()
Definition: Matrix.hpp:231
constexpr Matrix(Matrix &&other) noexcept
Definition: Matrix.hpp:163
void ElemIDiv(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1393
Matrix & operator=(Matrix &&other) noexcept
Definition: Matrix.hpp:266
ValueType y
Definition: Matrix.hpp:525
Pointer data()
Definition: Matrix-Impl.hpp:298
void Fill(const T &val)
Definition: Matrix-Impl.hpp:226
Pointer Iterator
Definition: Matrix.hpp:138
Pointer Iterator
Definition: Matrix.hpp:228
Iterator end()
Definition: Matrix-Impl.hpp:285
const T & ConstReference
Definition: Matrix.hpp:135
Definition: Matrix.hpp:27
constexpr Matrix(Matrix &&other) noexcept
Definition: Matrix.hpp:253
constexpr Matrix()
Definition: Matrix.hpp:435
constexpr T Product(const MatrixExpression< T, Rows, Cols, M1 > &a, const T &init)
Definition: Matrix-Impl.hpp:1503
constexpr Matrix(const Matrix &other)
Definition: Matrix.hpp:158
double & Reference
Definition: Matrix.hpp:40
Matrix & operator=(const Matrix &other)
Definition: Matrix.hpp:81
constexpr Matrix(ConstReference first, Args... rest)
Definition: Matrix.hpp:55
const T & ConstReference
Definition: Matrix.hpp:620
constexpr Matrix(const T &_x, const T &_y, const T &_z, const T &_w)
Definition: Matrix.hpp:440
void operator+=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1342
ValueType z
Definition: Matrix.hpp:416
Definition: pybind11Utils.hpp:20
T ValueType
Definition: Matrix.hpp:427
ValueType x
Definition: Matrix.hpp:414
ConstPointer ConstIterator
Definition: Matrix.hpp:139
const T & ConstReference
Definition: Matrix.hpp:542
const T * ConstPointer
Definition: Matrix.hpp:431
Definition: Matrix.hpp:531
constexpr Matrix(const Matrix &other)
Definition: Matrix.hpp:453
T * Pointer
Definition: Matrix.hpp:136
Pointer Iterator
Definition: Matrix.hpp:44
const T & ConstReference
Definition: Matrix.hpp:429
Definition: Matrix.hpp:216
void operator/=(Matrix< T, Rows, Cols > &a, const T &b)
Definition: Matrix-Impl.hpp:1400
ConstPointer ConstIterator
Definition: Matrix.hpp:45
constexpr Matrix()
Definition: Matrix.hpp:141
T ValueType
Definition: Matrix.hpp:618
constexpr Matrix(const T &_x, const T &_y, const T &_z)
Definition: Matrix.hpp:338
ConstPointer ConstIterator
Definition: Matrix.hpp:229
T * Pointer
Definition: Matrix.hpp:543
constexpr Matrix(const T &_x, const T &_y)
Definition: Matrix.hpp:236
constexpr size_t GetCols() const
Definition: Matrix-Impl.hpp:266
void operator*=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1366
Base class for matrix expression.
Definition: MatrixExpression.hpp:93
T * Pointer
Definition: Matrix.hpp:621
constexpr Matrix(const Matrix &other)
Definition: Matrix.hpp:351
Definition: Matrix.hpp:611
const T & ConstReference
Definition: Matrix.hpp:225
constexpr std::enable_if_t< TraitIsMatrixSizeStatic< Rows, Cols >::value, T > Accumulate(const MatrixExpression< T, Rows, Cols, M1 > &a, const T &init, BinaryOperation op)
Definition: Matrix-Impl.hpp:1452
bool operator!=(const MatrixExpression< T, R1, C1, M1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1443
void operator-=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1354
Reference operator[](size_t i)
Definition: Matrix-Impl.hpp:311
constexpr Matrix()
Definition: Matrix.hpp:327
typename NestedInitializerLists< T, N >::Type NestedInitializerListsT
Definition: NestedInitializerList.hpp:57
Iterator begin()
Definition: Matrix-Impl.hpp:272
std::enable_if_t< std::is_arithmetic< T >::value, T > MonotonicCatmullRom(const T &f0, const T &f1, const T &f2, const T &f3, T t)
Computes monotonic Catmull-Rom interpolation.
Definition: MathUtils-Impl.hpp:336
constexpr size_t GetRows() const
Definition: Matrix-Impl.hpp:260
ConstPointer ConstIterator
Definition: Matrix.hpp:325
T & Reference
Definition: Matrix.hpp:428
constexpr Matrix(Matrix &&other) noexcept
Definition: Matrix.hpp:75
Pointer Iterator
Definition: Matrix.hpp:623
T ValueType
Definition: Matrix.hpp:133
void Swap(Matrix &other)
Definition: Matrix-Impl.hpp:254
T & Reference
Definition: Matrix.hpp:619
constexpr Matrix(const Matrix &other)
Definition: Matrix.hpp:248
ValueType x
Definition: Matrix.hpp:524
Matrix & operator=(const Matrix &other)
Definition: Matrix.hpp:362
ValueType z
Definition: Matrix.hpp:526
void ElemIMul(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition: Matrix-Impl.hpp:1375
ValueType x
Definition: Matrix.hpp:212
const T * ConstPointer
Definition: Matrix.hpp:227
ConstPointer ConstIterator
Definition: Matrix.hpp:433
T & Reference
Definition: Matrix.hpp:224
T & Reference
Definition: Matrix.hpp:541
T * Pointer
Definition: Matrix.hpp:322