11 #ifndef CUBBYFLOW_MATRIX_DENSE_BASE_IMPL_HPP 12 #define CUBBYFLOW_MATRIX_DENSE_BASE_IMPL_HPP 19 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
20 template <
size_t R,
size_t C,
typename E>
24 for (
size_t i = 0; i < GetRows(); ++i)
26 for (
size_t j = 0; j < GetCols(); ++j)
28 (*this)(i, j) = expression.
Eval(i, j);
33 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
36 const size_t n = std::min(GetRows(), GetCols());
38 for (
size_t i = 0; i < n; ++i)
44 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
47 for (
size_t i = 0; i < GetRows(); ++i)
49 for (
size_t j = 0; j < GetCols(); ++j)
59 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
60 template <
size_t R,
size_t C,
typename E>
66 for (
size_t j = 0; j < GetCols(); ++j)
68 (*this)(i, j) = row.
Eval(j, 0);
72 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
73 template <
size_t R,
size_t C,
typename E>
79 for (
size_t i = 0; i < GetRows(); ++i)
81 (*this)(i, j) = col.
Eval(i, 0);
85 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
88 GetDerived() /= GetDerived().Norm();
91 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
94 D tmp = GetDerived().Transposed();
99 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
102 CopyFrom(GetDerived().Inverse());
105 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
109 assert(i < GetRows() && j < GetCols());
111 return GetDerived()[j + i * GetCols()];
114 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
118 assert(i < GetRows() && j < GetCols());
120 return GetDerived()[j + i * GetCols()];
123 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
124 template <
size_t R,
size_t C,
typename E>
128 CopyFrom(expression);
133 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
134 template <
typename D>
135 std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(), D>
141 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
142 template <
typename D>
143 std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D>
149 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
150 template <
typename D>
151 std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(), D>
157 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
158 template <
typename D>
159 std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D>
166 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
167 template <
typename D>
168 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
177 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
178 template <
typename D>
179 std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D>
188 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
189 template <
typename... Args,
typename D>
190 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
194 static_assert(
sizeof...(rest) == Rows - 1,
195 "Number of parameters should match the size of diagonal.");
198 std::array<T, Rows> diag{ { first, rest... } };
200 for (
size_t i = 0; i < Rows; ++i)
208 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
209 template <
size_t R,
size_t C,
typename E,
typename D>
210 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
214 assert(expression.
GetCols() == 1);
218 for (
size_t i = 0; i < Rows; ++i)
220 m(i, i) = expression.
Eval(i, 0);
226 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
227 template <
typename D>
228 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>() && (Rows == 2), D>
231 return D{ std::cos(rad), -std::sin(rad), std::sin(rad), std::cos(rad) };
234 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
235 template <
size_t R,
size_t C,
typename E,
typename D>
236 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>() && (Rows == 3 || Rows == 4),
243 D result = MakeIdentity();
246 1 + (1 - std::cos(rad)) * (axis.
Eval(0, 0) * axis.
Eval(0, 0) - 1);
247 result(0, 1) = -axis.
Eval(2, 0) * std::sin(rad) +
248 (1 - std::cos(rad)) * axis.
Eval(0, 0) * axis.
Eval(1, 0);
249 result(0, 2) = axis.
Eval(1, 0) * std::sin(rad) +
250 (1 - std::cos(rad)) * axis.
Eval(0, 0) * axis.
Eval(2, 0);
252 result(1, 0) = axis.
Eval(2, 0) * std::sin(rad) +
253 (1 - std::cos(rad)) * axis.
Eval(0, 0) * axis.
Eval(1, 0);
255 1 + (1 - std::cos(rad)) * (axis.
Eval(1, 0) * axis.
Eval(1, 0) - 1);
256 result(1, 2) = -axis.
Eval(0, 0) * std::sin(rad) +
257 (1 - std::cos(rad)) * axis.
Eval(1, 0) * axis.
Eval(2, 0);
259 result(2, 0) = -axis.
Eval(1, 0) * std::sin(rad) +
260 (1 - std::cos(rad)) * axis.
Eval(0, 0) * axis.
Eval(2, 0);
261 result(2, 1) = axis.
Eval(0, 0) * std::sin(rad) +
262 (1 - std::cos(rad)) * axis.
Eval(1, 0) * axis.
Eval(2, 0);
264 1 + (1 - std::cos(rad)) * (axis.
Eval(2, 0) * axis.
Eval(2, 0) - 1);
269 template <
typename T,
size_t Rows,
size_t Cols,
typename Derived>
270 template <
size_t R,
size_t C,
typename E,
typename D>
271 std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>() && (Rows == 4), D>
277 D result = MakeIdentity();
279 result(0, 3) = t.
Eval(0, 0);
280 result(1, 3) = t.
Eval(1, 0);
281 result(2, 3) = t.
Eval(2, 0);
286 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
289 return static_cast<const D&
>(*this).GetRows();
292 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
295 return static_cast<const D&
>(*this).GetCols();
298 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
301 return GetDerived().begin();
304 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
307 return GetDerived().begin();
310 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
313 return GetDerived().end();
316 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
319 return GetDerived().end();
322 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
326 assert(i < GetRows() * GetCols());
328 return GetDerived()[i];
331 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
335 assert(i < GetRows() * GetCols());
337 return GetDerived()[i];
340 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
343 return static_cast<D&
>(*this);
346 template <
typename T,
size_t Rows,
size_t Cols,
typename D>
349 return static_cast<const D&
>(*this);
const T & ConstReference
Definition: MatrixDenseBase.hpp:25
constexpr size_t GetCols() const
Returns the number of columns.
Definition: MatrixExpression-Impl.hpp:27
Definition: MatrixDenseBase.hpp:20
constexpr size_t GetRows() const
Returns the number of rows.
Definition: MatrixExpression-Impl.hpp:21
void SetDiagonal(ConstReference val)
Sets diagonal elements with input scalar.
Definition: MatrixDenseBase-Impl.hpp:34
void CopyFrom(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
Definition: MatrixDenseBase-Impl.hpp:21
MatrixDenseBase & operator=(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
T Eval(size_t i, size_t j) const
Returns the evaluated value for (i, j).
Definition: MatrixExpression-Impl.hpp:33
T ValueType
Definition: MatrixDenseBase.hpp:23
void SetColumn(size_t j, const MatrixExpression< T, R, C, E > &col)
Sets j-th column with input vector.
Definition: MatrixDenseBase-Impl.hpp:74
Definition: pybind11Utils.hpp:20
void Transpose()
Transposes this matrix.
Definition: MatrixDenseBase-Impl.hpp:92
void SetRow(size_t i, const MatrixExpression< T, R, C, E > &row)
Sets i-th row with input column vector.
Definition: MatrixDenseBase-Impl.hpp:61
T & Reference
Definition: MatrixDenseBase.hpp:24
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >) &&(Rows==2), D > MakeRotationMatrix(T rad)
Definition: MatrixDenseBase-Impl.hpp:229
void Normalize()
Definition: MatrixDenseBase-Impl.hpp:86
Base class for matrix expression.
Definition: MatrixExpression.hpp:93
Definition: MatrixExpression.hpp:62
void SetOffDiagonal(ConstReference val)
Sets off-diagonal elements with input scalar.
Definition: MatrixDenseBase-Impl.hpp:45
Definition: MatrixExpression.hpp:289
void Invert()
Inverts this matrix.
Definition: MatrixDenseBase-Impl.hpp:100
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >) &&(Rows==4), D > MakeTranslationMatrix(const MatrixExpression< T, R, C, E > &t)
Makes translation matrix.
Definition: MatrixDenseBase-Impl.hpp:272
Reference operator()(size_t i, size_t j)
Definition: MatrixDenseBase-Impl.hpp:107