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);
624 std::swap(y,
other.y);
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++];
970 m_elements = std::move(
other.m_elements);
971 m_rows =
other.m_rows;
972 m_cols =
other.m_cols;
981 std::fill(m_elements.begin(), m_elements.end(),
val);
986 const std::function<
T(
size_t i)>&
func)
988 for (
size_t i = 0; i < m_elements.size(); ++i)
990 m_elements[i] =
func(i);
996 const std::function<
T(
size_t i,
size_t j)>&
func)
998 for (
size_t i = 0; i <
GetRows(); ++i)
1000 for (
size_t j = 0; j <
GetCols(); ++j)
1002 (*this)(i, j) =
func(i, j);
1007template <
typename T>
1010 m_elements.swap(
other.m_elements);
1012 std::swap(m_rows,
other.m_rows);
1013 std::swap(m_cols,
other.m_cols);
1016template <
typename T>
1024 for (
size_t i = 0; i <
minRows; ++i)
1026 for (
size_t j = 0; j <
minCols; ++j)
1035template <
typename T>
1044template <
typename T>
1050template <
typename T>
1056template <
typename T>
1060 return &m_elements[0];
1063template <
typename T>
1067 return &m_elements[0];
1070template <
typename T>
1074 return begin() + m_rows * m_cols;
1077template <
typename T>
1081 return begin() + m_rows * m_cols;
1084template <
typename T>
1088 return &m_elements[0];
1091template <
typename T>
1095 return &m_elements[0];
1098template <
typename T>
1102 assert(i < m_rows * m_cols);
1104 return m_elements[i];
1107template <
typename T>
1111 assert(i < m_rows * m_cols);
1113 return m_elements[i];
1116template <
typename T>
1119template <
typename T>
1122 m_elements.resize(
rows, value);
1125template <
typename T>
1126template <
size_t R,
size_t C,
typename E>
1134template <
typename T>
1137 size_t sz =
lst.size();
1138 m_elements.resize(
sz);
1144 m_elements[i] =
static_cast<T>(
row);
1149template <
typename T>
1155 for (
size_t i = 0; i <
rows; ++i)
1161template <
typename T>
1164template <
typename T>
1167template <
typename T>
1171template <
typename T>
1175template <
typename T>
1178 std::fill(m_elements.begin(), m_elements.end(),
val);
1181template <
typename T>
1183 const std::function<
T(
size_t i)>&
func)
1185 for (
size_t i = 0; i < m_elements.size(); ++i)
1187 m_elements[i] =
func(i);
1191template <
typename T>
1193 const std::function<
T(
size_t i,
size_t j)>&
func)
1195 for (
size_t i = 0; i <
GetRows(); ++i)
1197 m_elements[i] =
func(i, 0);
1201template <
typename T>
1204 m_elements.swap(
other.m_elements);
1207template <
typename T>
1213template <
typename T>
1216 m_elements.push_back(
newElem);
1219template <
typename T>
1222 m_elements.insert(m_elements.end(),
newElems.m_elements.begin(),
1226template <
typename T>
1232template <
typename T>
1235 return m_elements.size();
1238template <
typename T>
1244template <
typename T>
1248 return &m_elements[0];
1251template <
typename T>
1255 return &m_elements[0];
1258template <
typename T>
1262 return begin() + m_elements.size();
1265template <
typename T>
1269 return begin() + m_elements.size();
1272template <
typename T>
1276 return &m_elements[0];
1279template <
typename T>
1283 return &m_elements[0];
1286template <
typename T>
1290 assert(i < m_elements.size());
1292 return m_elements[i];
1295template <
typename T>
1299 assert(i < m_elements.size());
1301 return m_elements[i];
1304template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1310template <
typename T,
size_t Rows,
size_t Cols>
1316template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1322template <
typename T,
size_t Rows,
size_t Cols>
1328template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1337template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1347template <
typename T,
size_t Rows,
size_t Cols>
1355template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1362template <
typename T,
size_t Rows,
size_t Cols>
1370template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
1371constexpr std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(),
bool>
operator==(
1377 std::equal_to<T>());
1380template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1390 for (
size_t i = 0; i <
a.
GetRows(); ++i)
1392 for (
size_t j = 0; j <
a.
GetCols(); ++j)
1404template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1412template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1414constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1423template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1424constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1429 init, std::plus<T>(),
1433template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1434constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1442template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1444constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1451template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1452constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1455 return std::accumulate(
a.
begin(),
a.
end(),
init, std::plus<T>());
1458template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1459constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1462 return std::accumulate(
a.
begin(),
a.
end(),
T{}, std::plus<T>());
1467template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1474template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
1475 typename M3,
typename M4>
1484 for (
size_t i = 0; i <
f0.
GetRows(); ++i)
1486 for (
size_t j = 0; j <
f0.
GetCols(); ++j)
const T & ConstReference
Definition Matrix.hpp:530
const T * ConstPointer
Definition Matrix.hpp:532
const T & ConstReference
Definition Matrix.hpp:452
const T * ConstPointer
Definition Matrix.hpp:454
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 &)=default
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:1356
void ElemIMul(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1338
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:1371
constexpr T Product(const MatrixExpression< T, Rows, Cols, M1 > &a, const T &init)
Definition Matrix-Impl.hpp:1468
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:648
bool operator!=(const MatrixExpression< T, R1, C1, M1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1406
void operator+=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1305
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:1415
void operator*=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1329
void operator/=(Matrix< T, Rows, Cols > &a, const T &b)
Definition Matrix-Impl.hpp:1363
void operator-=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1317
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
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:105
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