42#include <boost/qvm/mat_operations.hpp>
43#include <boost/qvm/vec_mat_operations.hpp>
44#include <boost/qvm/vec_operations.hpp>
47#include <boost/qvm/deduce_mat.hpp>
48#include <boost/qvm/deduce_scalar.hpp>
49#include <boost/qvm/deduce_vec.hpp>
50#include <boost/qvm/map_mat_mat.hpp>
51#include <boost/qvm/map_mat_vec.hpp>
52#include <boost/qvm/map_vec_mat.hpp>
53#include <boost/qvm/mat.hpp>
54#include <boost/qvm/mat_access.hpp>
55#include <boost/qvm/mat_traits.hpp>
65template <
typename T, std::
size_t Rows, std::
size_t Cols>
struct Matrix {
79 template <
class Archive>
void serialize(Archive &ar,
const unsigned int) {
85 Matrix(std::initializer_list<T> init_list) {
86 assert(init_list.size() == Rows * Cols);
87 std::ranges::copy(init_list,
begin());
89 Matrix(std::initializer_list<std::initializer_list<T>> init_list) {
90 assert(init_list.size() == Rows);
155 static_assert(R < Rows,
"Invalid row index.");
156 return boost::qvm::row<R>(*
this);
164 static_assert(C < Cols,
"Invalid column index.");
165 return boost::qvm::col<C>(*
this);
172 static_assert(Rows == Cols,
173 "Diagonal can only be retrieved from square matrices.");
174 return boost::qvm::diag(*
this);
182 return std::accumulate(d.begin(), d.end(), T{}, std::plus<T>{});
190 return boost::qvm::transposed(*
this);
198 static_assert(Rows == Cols,
199 "Inversion of a non-square matrix not implemented.");
200 return boost::qvm::inverse(*
this);
206 constexpr std::pair<std::size_t, std::size_t>
shape() const noexcept {
215using boost::qvm::operator+;
216using boost::qvm::operator+=;
217using boost::qvm::operator-;
218using boost::qvm::operator-=;
219using boost::qvm::operator*;
220using boost::qvm::operator*=;
221using boost::qvm::operator==;
223template <
typename T, std::
size_t M, std::
size_t N>
228template <
typename T, std::
size_t Rows, std::
size_t Cols>
230 static_assert(Rows == Cols,
"Diagonal matrix has to be a square matrix.");
231 return boost::qvm::diag_mat(v);
234template <
typename T, std::
size_t Rows, std::
size_t Cols>
236 static_assert(Rows == Cols,
237 "Identity matrix only defined for square matrices.");
238 return boost::qvm::identity_mat<T, Rows>();
245template <
typename T, std::
size_t Rows, std::
size_t Cols>
246struct mat_traits<
Utils::Matrix<T, Rows, Cols>> {
248 static int const rows = Rows;
249 static int const cols = Cols;
252 template <std::
size_t R, std::
size_t C>
254 static_assert(R < Rows,
"Invalid row index.");
255 static_assert(C < Cols,
"Invalid column index.");
259 template <std::
size_t R, std::
size_t C>
261 static_assert(R < Rows,
"Invalid row index.");
262 static_assert(C < Cols,
"Invalid column index.");
280template <
typename T,
typename U>
285template <
typename T,
typename U>
290template <
typename T,
typename U>
295template <
typename T,
typename U>
300template <
typename T,
typename U>
Array implementation with CUDA support.
Vector implementation and trait types for boost qvm interoperability.
void flatten(Range const &v, OutputIterator out)
Flatten a range of ranges.
Matrix< T, Rows, Cols > identity_mat()
Matrix< T, Rows, Cols > diagonal_mat(Utils::Vector< T, Rows > const &v)
DEVICE_QUALIFIER constexpr pointer data() noexcept
DEVICE_QUALIFIER constexpr iterator begin() noexcept
const value_type & const_reference
const value_type * const_pointer
DEVICE_QUALIFIER constexpr iterator end() noexcept
const value_type * const_iterator
Matrix representation with static size.
constexpr iterator begin() noexcept
Iterator access (non const).
Matrix< T, Cols, Rows > transposed() const
Retrieve a transposed copy of the matrix.
container::value_type value_type
constexpr const_pointer data() const noexcept
Access to the underlying data pointer (non const).
container::const_reference const_reference
Vector< T, Cols > diagonal() const
Retrieve the diagonal.
Matrix(std::initializer_list< std::initializer_list< T > > init_list)
container::reference reference
container::pointer pointer
constexpr const_iterator end() const noexcept
Iterator access (non const).
T trace() const
Retrieve the trace.
Vector< T, Cols > row() const
Retrieve an entire matrix row.
Matrix< T, Rows, Cols > inversed() const
Retrieve an inverted copy of the matrix.
Vector< T, Rows > col() const
Retrieve an entire matrix column.
constexpr std::pair< std::size_t, std::size_t > shape() const noexcept
Retrieve the shape of the matrix.
container::const_iterator const_iterator
container::const_pointer const_pointer
auto flatten() const noexcept
friend class boost::serialization::access
constexpr iterator end() noexcept
Iterator access (non const).
container::iterator iterator
constexpr pointer data()
Access to the underlying data pointer (non const).
constexpr value_type operator()(std::size_t row, std::size_t col) const
Element access (const).
constexpr const_iterator begin() const noexcept
Iterator access (const).
constexpr reference operator()(std::size_t row, std::size_t col)
Element access (non const).
Matrix(std::initializer_list< T > init_list)
static scalar_type read_element_idx(std::size_t r, std::size_t c, mat_type const &m)
static scalar_type & write_element_idx(std::size_t r, std::size_t c, mat_type &m)
static scalar_type read_element(mat_type const &m)
static scalar_type & write_element(mat_type &m)