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);
887template <
size_t R,
size_t C,
typename E>
916 m_elements.resize(m_rows * m_cols);
946 for (
size_t i = 0; i <
rows; ++i)
948 for (
size_t j = 0; j <
cols; ++j)
950 (*this)(i, j) =
ptr[
cnt++];
957 : m_elements(
other.m_elements), m_rows(
other.m_rows), m_cols(
other.m_cols)
965 : m_elements(std::move(
other.m_elements)),
966 m_rows(
other.m_rows),
977 m_elements =
other.m_elements;
978 m_rows =
other.m_rows;
979 m_cols =
other.m_cols;
988 m_elements = std::move(
other.m_elements);
989 m_rows =
other.m_rows;
990 m_cols =
other.m_cols;
999 std::fill(m_elements.begin(), m_elements.end(),
val);
1002template <
typename T>
1004 const std::function<
T(
size_t i)>&
func)
1006 for (
size_t i = 0; i < m_elements.size(); ++i)
1008 m_elements[i] =
func(i);
1012template <
typename T>
1014 const std::function<
T(
size_t i,
size_t j)>&
func)
1016 for (
size_t i = 0; i <
GetRows(); ++i)
1018 for (
size_t j = 0; j <
GetCols(); ++j)
1020 (*this)(i, j) =
func(i, j);
1025template <
typename T>
1028 m_elements.swap(
other.m_elements);
1030 std::swap(m_rows,
other.m_rows);
1031 std::swap(m_cols,
other.m_cols);
1034template <
typename T>
1042 for (
size_t i = 0; i <
minRows; ++i)
1044 for (
size_t j = 0; j <
minCols; ++j)
1053template <
typename T>
1062template <
typename T>
1068template <
typename T>
1074template <
typename T>
1078 return &m_elements[0];
1081template <
typename T>
1085 return &m_elements[0];
1088template <
typename T>
1092 return begin() + m_rows * m_cols;
1095template <
typename T>
1099 return begin() + m_rows * m_cols;
1102template <
typename T>
1106 return &m_elements[0];
1109template <
typename T>
1113 return &m_elements[0];
1116template <
typename T>
1120 assert(i < m_rows * m_cols);
1122 return m_elements[i];
1125template <
typename T>
1129 assert(i < m_rows * m_cols);
1131 return m_elements[i];
1134template <
typename T>
1140template <
typename T>
1143 m_elements.resize(
rows, value);
1146template <
typename T>
1147template <
size_t R,
size_t C,
typename E>
1155template <
typename T>
1158 size_t sz =
lst.size();
1159 m_elements.resize(
sz);
1165 m_elements[i] =
static_cast<T>(
row);
1170template <
typename T>
1176 for (
size_t i = 0; i <
rows; ++i)
1182template <
typename T>
1184 : m_elements(
other.m_elements)
1189template <
typename T>
1191 : m_elements(std::move(
other.m_elements))
1196template <
typename T>
1200 m_elements =
other.m_elements;
1204template <
typename T>
1208 m_elements = std::move(
other.m_elements);
1212template <
typename T>
1215 std::fill(m_elements.begin(), m_elements.end(),
val);
1218template <
typename T>
1220 const std::function<
T(
size_t i)>&
func)
1222 for (
size_t i = 0; i < m_elements.size(); ++i)
1224 m_elements[i] =
func(i);
1228template <
typename T>
1230 const std::function<
T(
size_t i,
size_t j)>&
func)
1232 for (
size_t i = 0; i <
GetRows(); ++i)
1234 m_elements[i] =
func(i, 0);
1238template <
typename T>
1241 m_elements.swap(
other.m_elements);
1244template <
typename T>
1250template <
typename T>
1253 m_elements.push_back(
newElem);
1256template <
typename T>
1259 m_elements.insert(m_elements.end(),
newElems.m_elements.begin(),
1263template <
typename T>
1269template <
typename T>
1272 return m_elements.size();
1275template <
typename T>
1281template <
typename T>
1285 return &m_elements[0];
1288template <
typename T>
1292 return &m_elements[0];
1295template <
typename T>
1299 return begin() + m_elements.size();
1302template <
typename T>
1306 return begin() + m_elements.size();
1309template <
typename T>
1313 return &m_elements[0];
1316template <
typename T>
1320 return &m_elements[0];
1323template <
typename T>
1327 assert(i < m_elements.size());
1329 return m_elements[i];
1332template <
typename T>
1336 assert(i < m_elements.size());
1338 return m_elements[i];
1341template <
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>
1353template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1359template <
typename T,
size_t Rows,
size_t Cols>
1365template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1374template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1384template <
typename T,
size_t Rows,
size_t Cols>
1392template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M2>
1399template <
typename T,
size_t Rows,
size_t Cols>
1407template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2>
1408constexpr std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(),
bool>
operator==(
1414 std::equal_to<T>());
1417template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1427 for (
size_t i = 0; i <
a.
GetRows(); ++i)
1429 for (
size_t j = 0; j <
a.
GetCols(); ++j)
1441template <
typename T,
size_t R1,
size_t C1,
size_t R2,
size_t C2,
typename M1,
1449template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1451constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1459template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1460constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1468template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1469constexpr std::enable_if_t<TraitIsMatrixSizeStatic<Rows, Cols>::value,
T>
1473 Rows *
Cols - 1>::Call(
a, std::plus<T>(),
1477template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
1479constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1486template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1487constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1490 return std::accumulate(
a.
begin(),
a.
end(),
init, std::plus<T>());
1493template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1494constexpr std::enable_if_t<TraitIsMatrixSizeDynamic<Rows, Cols>::value,
T>
1497 return std::accumulate(
a.
begin(),
a.
end(),
T{}, std::plus<T>());
1502template <
typename T,
size_t Rows,
size_t Cols,
typename M1>
1509template <
typename T,
size_t Rows,
size_t Cols,
typename M1,
typename M2,
1510 typename M3,
typename M4>
1519 for (
size_t i = 0; i <
f0.
GetRows(); ++i)
1521 for (
size_t j = 0; j <
f0.
GetCols(); ++j)
const T & ConstReference
Definition Matrix.hpp:620
const T * ConstPointer
Definition Matrix.hpp:622
const T & ConstReference
Definition Matrix.hpp:542
const T * ConstPointer
Definition Matrix.hpp:544
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:509
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:21
void ElemIDiv(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1393
void ElemIMul(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1375
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
constexpr T Product(const MatrixExpression< T, Rows, Cols, M1 > &a, const T &init)
Definition Matrix-Impl.hpp:1503
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:738
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:1342
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
void operator*=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1366
void operator/=(Matrix< T, Rows, Cols > &a, const T &b)
Definition Matrix-Impl.hpp:1400
void operator-=(Matrix< T, R1, C1 > &a, const MatrixExpression< T, R2, C2, M2 > &b)
Definition Matrix-Impl.hpp:1354
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