15#include <libcamera/base/span.h>
26template<
typename T,
unsigned int Rows,
unsigned int Cols,
27 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
29template<
typename T,
unsigned int Rows,
unsigned int Cols>
36 data_.fill(
static_cast<T
>(0));
41 std::copy(data.begin(), data.end(), data_.begin());
47 for (
size_t i = 0; i < std::min(Rows, Cols); i++)
48 ret[i][i] =
static_cast<T
>(1);
56 std::stringstream out;
59 for (
unsigned int i = 0; i < Rows; i++) {
61 for (
unsigned int j = 0; j < Cols; j++) {
63 out << ((j + 1 < Cols) ?
", " :
" ");
65 out << ((i + 1 < Rows) ?
"], " :
"]");
74 return Span<const T, Cols>{ &data_.data()[i * Cols], Cols };
79 return Span<T, Cols>{ &data_.data()[i * Cols], Cols };
83 template<
typename U, std::enable_if_t<std::is_arithmetic_v<U>>>
89 for (
unsigned int i = 0; i < Rows * Cols; i++)
95 std::array<T, Rows * Cols> data_;
99template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols,
100 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
102template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols>
108 for (
unsigned int i = 0; i < Rows; i++) {
109 for (
unsigned int j = 0; j < Cols; j++)
110 result[i][j] = d * m[i][j];
117template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols,
118 std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
120template<
typename T,
typename U,
unsigned int Rows,
unsigned int Cols>
129 unsigned int R1,
unsigned int C1,
130 unsigned int R2,
unsigned int C2,
131 std::enable_if_t<C1 == R2> * =
nullptr>
133template<
typename T,
unsigned int R1,
unsigned int C1,
unsigned int R2,
unsigned in C2>
139 for (
unsigned int i = 0; i < R1; i++) {
140 for (
unsigned int j = 0; j < C2; j++) {
143 for (
unsigned int k = 0; k < C1; k++)
144 sum += m1[i][k] * m2[k][j];
153template<
typename T,
unsigned int Rows,
unsigned int Cols>
158 for (
unsigned int i = 0; i < Rows; i++) {
159 for (
unsigned int j = 0; j < Cols; j++)
160 result[i][j] = m1[i][j] + m2[i][j];
167bool matrixValidateYaml(
const YamlObject &obj,
unsigned int size);
173template<
typename T,
unsigned int Rows,
unsigned int Cols>
174std::ostream &
operator<<(std::ostream &out,
const ipa::Matrix<T, Rows, Cols> &m)
180template<
typename T,
unsigned int Rows,
unsigned int Cols>
181struct YamlObject::Getter<ipa::Matrix<T, Rows, Cols>> {
182 std::optional<ipa::Matrix<T, Rows, Cols>>
get(
const YamlObject &obj)
const
184 if (!ipa::matrixValidateYaml(obj, Rows * Cols))
187 ipa::Matrix<T, Rows, Cols> matrix;
188 T *data = &matrix[0][0];
191 for (
const YamlObject &entry : obj.
asList()) {
192 const auto value = entry.get<T>();
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:26
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:165
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition yaml_parser.h:196
Matrix class.
Definition matrix.h:32
Matrix< T, Rows, Cols > & operator*=(U d)
Multiply the matrix by a scalar in-place.
Definition matrix.h:87
const std::string toString() const
Assemble and return a string describing the matrix.
Definition matrix.h:54
Matrix(const std::vector< T > &data)
Construct a matrix from supplied data.
Definition matrix.h:39
static Matrix identity()
Construct an identity matrix.
Definition matrix.h:44
Matrix()
Construct a zero matrix.
Definition matrix.h:34
Span< T, Cols > operator[](size_t i)
Index to a row in the matrix.
Definition matrix.h:77
Span< const T, Cols > operator[](size_t i) const
Index to a row in the matrix.
Definition matrix.h:72
#define LOG_DECLARE_CATEGORY(name)
Declare a category of log messages.
Definition log.h:47
Matrix< U, Rows, Cols > operator*(T d, const Matrix< U, Rows, Cols > &m)
Multiply the matrix by a scalar.
Definition matrix.h:104
Matrix< T, Rows, Cols > operator+(const Matrix< T, Rows, Cols > &m1, const Matrix< T, Rows, Cols > &m2)
Matrix addition.
Definition matrix.h:154
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