14#include <libcamera/base/span.h>
25template<
typename T,
unsigned int Rows,
unsigned int Cols,
26 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
28template<
typename T,
unsigned int Rows,
unsigned int Cols>
35 data_.fill(
static_cast<T
>(0));
40 std::copy(data.begin(), data.end(), data_.begin());
46 for (
size_t i = 0; i < std::min(Rows, Cols); i++)
47 ret[i][i] =
static_cast<T
>(1);
55 std::stringstream out;
58 for (
unsigned int i = 0; i < Rows; i++) {
60 for (
unsigned int j = 0; j < Cols; j++) {
62 out << ((j + 1 < Cols) ?
", " :
" ");
64 out << ((i + 1 < Rows) ?
"], " :
"]");
73 return Span<const T, Cols>{ &data_.data()[i * Cols], Cols };
78 return Span<T, Cols>{ &data_.data()[i * Cols], Cols };
82 template<
typename U, std::enable_if_t<std::is_arithmetic_v<U>>>
88 for (
unsigned int i = 0; i < Rows * Cols; i++)
94 std::array<T, Rows * Cols> data_;
98template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols,
99 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
101template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols>
107 for (
unsigned int i = 0; i < Rows; i++) {
108 for (
unsigned int j = 0; j < Cols; j++)
109 result[i][j] = d * m[i][j];
116template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols,
117 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
119template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols>
128 unsigned int R1,
unsigned int C1,
129 unsigned int R2,
unsigned int C2,
130 std::enable_if_t<C1 == R2> * =
nullptr>
132template<
typename T,
unsigned int R1,
unsigned int C1,
unsigned int R2,
unsigned in C2>
138 for (
unsigned int i = 0; i < R1; i++) {
139 for (
unsigned int j = 0; j < C2; j++) {
142 for (
unsigned int k = 0; k < C1; k++)
143 sum += m1[i][k] * m2[k][j];
152template<
typename T,
unsigned int Rows,
unsigned int Cols>
157 for (
unsigned int i = 0; i < Rows; i++) {
158 for (
unsigned int j = 0; j < Cols; j++)
159 result[i][j] = m1[i][j] + m2[i][j];
166bool matrixValidateYaml(
const YamlObject &obj,
unsigned int size);
172template<
typename T,
unsigned int Rows,
unsigned int Cols>
173std::ostream &
operator<<(std::ostream &out,
const ipa::Matrix<T, Rows, Cols> &m)
179template<
typename T,
unsigned int Rows,
unsigned int Cols>
180struct YamlObject::Getter<ipa::Matrix<T, Rows, Cols>> {
181 std::optional<ipa::Matrix<T, Rows, Cols>>
get(
const YamlObject &obj)
const
183 if (!ipa::matrixValidateYaml(obj, Rows * Cols))
186 ipa::Matrix<T, Rows, Cols> matrix;
187 T *data = &matrix[0][0];
190 for (
const YamlObject &entry : obj.asList()) {
191 const auto value = entry.get<T>();
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:27
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:174
Matrix class.
Definition matrix.h:31
Matrix< T, Rows, Cols > & operator*=(U d)
Multiply the matrix by a scalar in-place.
Definition matrix.h:86
const std::string toString() const
Assemble and return a string describing the matrix.
Definition matrix.h:53
Matrix(const std::vector< T > &data)
Construct a matrix from supplied data.
Definition matrix.h:38
static Matrix identity()
Construct an identity matrix.
Definition matrix.h:43
Matrix()
Construct a zero matrix.
Definition matrix.h:33
Span< T, Cols > operator[](size_t i)
Index to a row in the matrix.
Definition matrix.h:76
Span< const T, Cols > operator[](size_t i) const
Index to a row in the matrix.
Definition matrix.h:71
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:46
Matrix< U, Rows, Cols > operator*(T d, const Matrix< U, Rows, Cols > &m)
Multiply the matrix by a scalar.
Definition matrix.h:103
Matrix< T, Rows, Cols > operator+(const Matrix< T, Rows, Cols > &m1, const Matrix< T, Rows, Cols > &m2)
Matrix addition.
Definition matrix.h:153
Top-level libcamera namespace.
Definition backtrace.h:17
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91