24#include <experimental/mdspan>
35 template<
class T,
int m,
int n>
43 return std::mdspan<T, std::extents<size_t, m, n>>(
data.data());
48 return std::mdspan<const T, std::extents<size_t, m, n>>(
data.data());
60 inline mat &operator+=(
const mat &other) {
62 for (
size_t i = 0; i < m * n; i++) {
71 for (
auto i = 0; i < m; i++) {
72 for (
auto j = 0; j < n; j++) {
73 if (sham::abs(
data[i * n + j] - other.
data[i * n + j]) >= precision) {
83 template<
class T,
int n>
95 template<
class T,
int n>
103 return std::mdspan<T, std::extents<size_t, n>>(
data.data());
108 return std::mdspan<T, std::extents<size_t, n, 1>>(
data.data());
113 return std::mdspan<T, std::extents<size_t, 1, n>>(
data.data());
125template<
class T,
int m,
int n>
127 using component_type = T;
128 static constexpr u32 dimension = m * n;
130 static constexpr bool is_float_based
131 = std::is_same<T, f16>::value || std::is_same<T, f32>::value || std::is_same<T, f64>::value;
132 static constexpr bool is_uint_based = std::is_same<T, u8>::value || std::is_same<T, u16>::value
133 || std::is_same<T, u32>::value
134 || std::is_same<T, u64>::value;
135 static constexpr bool is_int_based = std::is_same<T, i8>::value || std::is_same<T, i16>::value
136 || std::is_same<T, i32>::value
137 || std::is_same<T, i64>::value;
138 static constexpr bool has_info = is_float_based || is_int_based || is_uint_based;
149 constexpr T zero = 0;
std::uint32_t u32
32 bit unsigned integer
Shamrock assertion utility.
Matrix class based on std::array storage and mdspan.
constexpr auto get_mdspan() const
const overload
std::array< T, m *n > data
The matrix data.
constexpr T & operator()(int i, int j)
Access the matrix entry at position (i, j)
constexpr auto get_mdspan()
Get the matrix data as a mdspan.
constexpr const T & operator()(int i, int j) const
const overload
bool equal_at_precision(const mat< T, m, n > &other, const T precision) const
check if this matrix is equal to another one at a given precison
bool operator==(const mat< T, m, n > &other) const
Check if this matrix is equal to another one.
Vector class based on std::array storage and mdspan.
constexpr auto get_mdspan()
Get the vector data as a mdspan.
constexpr auto get_mdspan_mat_col()
Get the vector data as a mdspan of a matrix with one column.
bool operator==(const vec< T, n > &other)
Check if this vector is equal to another one.
std::array< T, n > data
The vector data.
constexpr T & operator[](int i)
Access the vector entry at position i.
constexpr auto get_mdspan_mat_row()
Get the vector data as a mdspan of a matrix with one row.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for math utility
constexpr mat< T, n, n > mat_identity()
Returns the identity matrix of size n.
void mat_set_identity(const std::mdspan< T, Extents, Layout, Accessor > &input1)
Set the content of a matrix to the identity matrix.