3#include <initializer_list>
6#include <xtensor/containers/xarray.hpp>
7#include <xtensor/core/xmath.hpp>
8#include <xtensor/generators/xrandom.hpp>
9#include <xtensor/io/xio.hpp>
10#include <xtensor/reducers/xreducer.hpp>
11#include <xtensor/views/xview.hpp>
78 Matrix(std::initializer_list<std::initializer_list<T>> list);
112 const T &
operator()(
size_t row,
size_t col)
const;
194 [[nodiscard]]
size_t rows()
const {
return rows_; }
200 [[nodiscard]]
size_t cols()
const {
return cols_; }
206 [[nodiscard]]
size_t size()
const {
return rows_ * cols_; }
212 [[nodiscard]] std::tuple<size_t, size_t>
shape()
const {
return {rows_, cols_}; }
260 xt::xarray<T> &
data() {
return data_; }
266 const xt::xarray<T> &
data()
const {
return data_; }
292 std::ostream &
operator<<(std::ostream &os,
const Matrix<T> &matrix);
301 Matrix<T>
dot(
const Matrix<T> &a,
const Matrix<T> &b);
309 T
sum(
const Matrix<T> &matrix);
317 T
mean(
const Matrix<T> &matrix);
static Matrix zeros(size_t rows, size_t cols)
Create a matrix filled with zeros.
xt::xarray< T > & data()
Get the underlying xtensor array.
size_t cols() const
Get the number of columns.
std::tuple< size_t, size_t > shape() const
Get the shape of the matric in one step.
Matrix()
Default constructor creating an empty matrix.
T determinant() const
Calculate the determinant of the matrix.
Matrix transpose() const
Compute the transpose of the matrix.
size_t size() const
Get the total number of elements.
friend std::ostream & operator<<(std::ostream &os, const Matrix< U > &matrix)
friend U sum(const Matrix< U > &matrix)
Matrix inverse() const
Calculate the inverse of the matrix.
T & operator()(size_t row, size_t col)
Access matrix element at specified position (mutable)
friend Matrix< U > dot(const Matrix< U > &a, const Matrix< U > &b)
Matrix operator+(const Matrix &other) const
Matrix addition operator.
Matrix reshape(size_t new_rows, size_t new_cols) const
Reshape the matrix to new dimensions.
static Matrix random(size_t rows, size_t cols, T min, T max)
Create a matrix with random values.
static Matrix identity(size_t size)
Create an identity matrix.
static Matrix ones(size_t rows, size_t cols)
Create a matrix filled with ones.
Matrix operator-(const Matrix &other) const
Matrix subtraction operator.
friend U mean(const Matrix< U > &matrix)
Matrix operator*(const Matrix &other) const
Matrix multiplication operator.
const xt::xarray< T > & data() const
Get the underlying xtensor array (const)
size_t rows() const
Get the number of rows.
T sum(const Matrix< T > &matrix)
Calculate sum of all matrix elements.
T mean(const Matrix< T > &matrix)
Calculate mean of all matrix elements.
std::ostream & operator<<(std::ostream &os, const Matrix< T > &matrix)
Output stream operator for matrix visualization.
Matrix< T > dot(const Matrix< T > &a, const Matrix< T > &b)
Compute dot product of two matrices.