11#ifndef CUBBYFLOW_MATRIX_IMPL_HPP
12#define CUBBYFLOW_MATRIX_IMPL_HPP
23template <
typename M1,
typename M2,
size_t J>
26 constexpr static auto call(
const M1&
a,
const M2& b,
size_t i,
size_t j)
32template <
typename M1,
typename M2>
35 constexpr static auto call(
const M1&
a,
const M2& b,
size_t i,
size_t j)
37 return a(i, 0) * b(0, j);
47 template <
typename U = T>
48 constexpr static std::enable_if_t<(
Cols == 1), U>
Call(
59 template <
typename U = T>
60 constexpr static std::enable_if_t<(
Cols == 1), U>
Call(
104 template <
typename U = T>
105 constexpr static std::enable_if_t<(
Cols > 1), U>
Call(
113 template <
typename U = T>
114 constexpr static std::enable_if_t<(
Cols == 1), U>
Call(
160template <
typename T,
size_t Rows,
size_t Cols,
typename BinaryOperation>
167 return op(
a[0], b[0]);
173template <
typename T,
size_t Rows,
size_t Cols>
179template <
typename T,
size_t Rows,
size_t Cols>
180template <
size_t R,
size_t C,
typename E>
188template <
typename T,
size_t Rows,
size_t Cols>
211template <
typename T,
size_t Rows,
size_t Cols>
216 for (
size_t i = 0; i <
Rows; ++i)
218 for (
size_t j = 0; j <
Cols; ++j)
220 (*this)(i, j) =
ptr[
cnt++];
225template <
typename T,
size_t Rows,
size_t Cols>
228 m_elements.fill(
val);
231template <
typename T,
size_t Rows,
size_t Cols>
234 for (
size_t i = 0; i <
Rows *
Cols; ++i)
236 m_elements[i] =
func(i);
240template <
typename T,
size_t Rows,
size_t Cols>
242 const std::function<
T(
size_t i,
size_t j)>&
func)
244 for (
size_t i = 0; i <
Rows; ++i)
246 for (
size_t j = 0; j <
Cols; ++j)
248 (*this)(i, j) =
func(i, j);
253template <
typename T,
size_t Rows,
size_t Cols>
256 m_elements.swap(
other.m_elements);
259template <
typename T,
size_t Rows,
size_t Cols>
265template <
typename T,
size_t Rows,
size_t Cols>
271template <
typename T,
size_t Rows,
size_t Cols>
274 return &m_elements[0];
277template <
typename T,
size_t Rows,
size_t Cols>
281 return &m_elements[0];
284template <
typename T,
size_t Rows,
size_t Cols>
290template <
typename T,
size_t Rows,
size_t Cols>
297template <
typename T,
size_t Rows,
size_t Cols>
300 return &m_elements[0];
303template <
typename T,
size_t Rows,
size_t Cols>
307 return &m_elements[0];
310template <
typename T,
size_t Rows,
size_t Cols>
316 return m_elements[i];
319template <
typename T,
size_t Rows,
size_t Cols>
325 return m_elements[i];
329template <
size_t R,
size_t C,
typename E>
366 std::swap(x,
other.x);
447template <
size_t R,
size_t C,
typename E>
489 std::swap(x,
other.x);
490 std::swap(y,
other.y);
577template <
size_t R,
size_t C,
typename E>
623 std::swap(x,
other.x);
625 std::swap(z,
other.z);
718template <
size_t R,
size_t C,
typename E>
768 std::swap(x,
other.x);
769 std::swap(y,
other.y);
770 std::swap(z,
other.z);
771 std::swap(w,
other.w);
884template <
size_t R,
size_t C,
typename E>
913 m_elements.resize(m_rows * m_cols);
943 for (
size_t i = 0; i <
rows; ++i)
945 for (
size_t j = 0; j <
cols; ++j)
947 (*this)(i, j) =
ptr[
cnt++];
954 : m_elements(
other.m_elements), m_rows(
other.m_rows), m_cols(
other.m_cols)
962 : m_elements(std::move(
other.m_elements)),
963 m_rows(
other.m_rows),
974 m_elements =
other.m_elements;
975 m_rows =
other.m_rows;
976 m_cols =
other.m_cols;
985 m_elements = std::move(
other.m_elements);
986 m_rows =
other.m_rows;
987 m_cols =
other.m_cols;
996 std::fill(m_elements.begin(), m_elements.end(),
val);
1001 const std::function<
T(
size_t i)>&
func)
1003 for (
size_t i = 0; i < m_elements.size(); ++i)
1005 m_elements[i] =
func(i);
1009template <
typename T>
1011 const std::function<
T(
size_t i,
size_t j)>&
func)
1013 for (
size_t i = 0; i <
GetRows(); ++i)
1015 for (
size_t j = 0; j <
GetCols(); ++j)
1017 (*this)(i, j) =
func(i, j);
1022template <
typename T>
1025 m_elements.swap(
other.m_elements);
1027 std::swap(m_rows,
other.m_rows);
1028 std::swap(m_cols,
other.m_cols);
1031template <
typename T>
1039 for (
size_t i = 0; i <
minRows; ++i)
1041 for (
size_t j = 0; j <
minCols; ++j)
1050template <
typename T>
1059template <
typename T>
1065template <
typename T>
1071template <
typename T>
1075 return &m_elements[0];
1078template <
typename T>
1082 return &m_elements[0];
1085template <
typename T>
1089 return begin() + m_rows * m_cols;
1092template <
typename T>
1096 return begin() + m_rows * m_cols;
1099template <
typename T>
1103 return &m_elements[0];
1106template <
typename T>
1110 return &m_elements[0];
1113template <
typename T>
1117 assert(i < m_rows * m_cols);
1119 return m_elements[i];
1122template <
typename T>
1126 assert(i < m_rows * m_cols);
1128 return m_elements[i];
1131template <
typename T>
1134template <
typename T>
1137 m_elements.resize(
rows, value);
1140template <
typename T>
1141template <
size_t R,
size_t C,
typename E>
1149template <
typename T>
1152 size_t sz =
lst.size();
1153 m_elements.resize(
sz);
1159 m_elements[i] =
static_cast<T>(
row);
1164template <
typename T>
1170 for (
size_t i = 0; i <
rows; ++i)
1176template <
typename T>
1178 : m_elements(
other.m_elements)
1183template <
typename T>
1185 : m_elements(std::move(
other.m_elements))
1190template <
typename T>
1194 m_elements =
other.m_elements;
1198template <
typename T>
1202 m_elements = std::move(
other.m_elements);
1206template <
typename T>
1209 std::fill(m_elements.begin(), m_elements.end(),
val);
1212template <
typename T>
1214 const std::function<
T(
size_t i)>&
func)
1216 for (
size_t i = 0; i < m_elements.size(); ++i)
1218 m_elements[i] =
func(i);
1222template <
typename T>
1224 const std::function<
T(
size_t i,
size_t j)>&
func)
1226 for (
size_t i = 0; i <
GetRows(); ++i)
1228 m_elements[i] =
func(i, 0);
1232template <
typename T>
1235 m_elements.swap(
other.m_elements);
1238template <
typename T>
1244template <
typename T>
1247 m_elements.push_back(
newElem);
1250template <
typename T>
1253 m_elements.insert(m_elements.end(),
newElems.m_elements.begin(),
1257template <
typename T>
1263template <
typename T>
1266 return m_elements.size();
1269template <
typename T>
1275template <
typename T>
1279 return &m_elements[0];
1282template <
typename T>
1286 return &m_elements[0];
1289template <
typename T>
1293 return begin() + m_elements.size();
1296template <
typename T>
1300 return begin() + m_elements.size();
1303template <
typename T>
1307 return &m_elements[0];
1310template <
typename T>
1314 return &m_elements[0];
1317template <
typename T>
1321 assert(i < m_elements.size());
1323 return m_elements[i];
1326template <
typename T>
1330 assert(i < m_elements.size());
1332 return m_elements[i];
1335template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1341template <
typename T,
size_t Rows,
size_t Cols>
1347template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1353template <
typename T,
size_t Rows,
size_t Cols>
1359template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1368template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1378template <
typename T,
size_t Rows,
size_t Cols>
1386template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1393template <
typename T,
size_t Rows,
size_t Cols>
1401template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
1402constexpr std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(),
bool>
operator==(
1408 std::equal_to<T>());
1411template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1421 for (
size_t i = 0; i <
a.
GetRows(); ++i)
1423 for (
size_t j = 0; j <
a.
GetCols(); ++j)
1435template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1443template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1445constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1454template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1455constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1460 init, std::plus<T>(),
1464template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1465constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1473template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1475constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1482template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1483constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1486 return std::accumulate(
a.
begin(),
a.
end(),
init, std::plus<T>());
1489template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1490constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1493 return std::accumulate(
a.
begin(),
a.
end(),
T{}, std::plus<T>());
1498template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1505template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
1506 typename M3,
typename M4>
1515 for (
size_t i = 0; i <
f0.
GetRows(); ++i)
1517 for (
size_t j = 0; j <
f0.
GetCols(); ++j)
const T & ConstReference
Definition Matrix.hpp:601
const T * ConstPointer
Definition Matrix.hpp:603
const T & ConstReference
Definition Matrix.hpp:523
const T * ConstPointer
Definition Matrix.hpp:525
void CopyFrom(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
Definition MatrixDenseBase-Impl.hpp:21
T Eval(size_t i, size_t j) const
Returns the evaluated value for (i, j).
Definition MatrixExpression-Impl.hpp:33
Derived & GetDerived()
Returns actual implementation (the subclass).
Definition MatrixExpression-Impl.hpp:508
T & Reference
Definition Matrix.hpp:40
ConstPointer ConstIterator
Definition Matrix.hpp:45
void Fill(const T &val)
Definition Matrix-Impl.hpp:226
Matrix & operator=(const Matrix &other)
Definition Matrix.hpp:81
const T * ConstPointer
Definition Matrix.hpp:43
constexpr size_t GetCols() const
Definition Matrix-Impl.hpp:266
Iterator begin()
Definition Matrix-Impl.hpp:272
void Swap(Matrix &other)
Definition Matrix-Impl.hpp:254
T * Pointer
Definition Matrix.hpp:42
Pointer Iterator
Definition Matrix.hpp:44
constexpr size_t GetRows() const
Definition Matrix-Impl.hpp:260
Pointer data()
Definition Matrix-Impl.hpp:298
constexpr Matrix()
Definition Matrix.hpp:47
Iterator end()
Definition Matrix-Impl.hpp:285
Reference operator[](size_t i)
Definition Matrix-Impl.hpp:311
const T & ConstReference
Definition Matrix.hpp:41
Definition pybind11Utils.hpp:22
void ElemIDiv(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1387
void ElemIMul(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1369
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:1402
constexpr T Product(const MatrixExpression< T, Rows, Cols, M1 > &a, const T &init)
Definition Matrix-Impl.hpp:1499
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
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:719
bool operator!=(const MatrixExpression< T, R1, C1, M1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1437
void operator+=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1336
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:1446
void operator*=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1360
void operator/=(Matrix< T, Rows, Cols > &a, const T &b)
Definition Matrix-Impl.hpp:1394
void operator-=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1348
static constexpr auto call(const M1 &a, const M2 &b, size_t i, size_t j)
Definition Matrix-Impl.hpp:35
Definition Matrix-Impl.hpp:25
static constexpr auto call(const M1 &a, const M2 &b, size_t i, size_t j)
Definition Matrix-Impl.hpp:26
static constexpr bool Call(const Matrix< T, Rows, Cols > &a, const Matrix< T, Rows, Cols > &b, BinaryOperation op)
Definition Matrix-Impl.hpp:163
Definition Matrix-Impl.hpp:149
static constexpr bool Call(const Matrix< T, Rows, Cols > &a, const Matrix< T, Rows, Cols > &b, BinaryOperation op)
Definition Matrix-Impl.hpp:150
static constexpr T CallDiag(const Matrix< T, Rows, Cols > &a, const T &init, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:135
static constexpr T Call(const Matrix< T, Rows, Cols > &a, const T &init, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:121
static constexpr std::enable_if_t<(Cols==1), U > Call(const Matrix< T, Rows, 1 > &a, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:114
static constexpr T Call(const Matrix< T, Rows, Cols > &a, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:128
Definition Matrix-Impl.hpp:45
static constexpr T Call(const Matrix< T, Rows, Cols > &a, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:80
static constexpr std::enable_if_t<(Cols==1), U > Call(const Matrix< T, Rows, 1 > &a, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:60
static constexpr T Call(const Matrix< T, Rows, Cols > &a, const T &init, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:70
static constexpr std::enable_if_t<(Cols==1), U > Call(const Matrix< T, Rows, 1 > &a, const T &init, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:48
static constexpr T CallDiag(const Matrix< T, Rows, Cols > &a, const T &init, ReduceOperation op, UnaryOperation uop)
Definition Matrix-Impl.hpp:90