25#include <experimental/mdspan>
36 template<
class T,
int m,
int n>
44 return std::mdspan<T, std::extents<size_t, m, n>>(
data.data());
49 return std::mdspan<const T, std::extents<size_t, m, n>>(
data.data());
62 inline mat &operator+=(
const mat &other) {
64 for (
size_t i = 0; i < m * n; i++) {
73 for (
auto i = 0; i < m; i++) {
74 for (
auto j = 0; j < n; j++) {
75 if (sham::abs(
data[i * n + j] - other.
data[i * n + j]) >= precision) {
85 template<
class T,
int n>
97 template<
class T,
int n>
105 return std::mdspan<T, std::extents<size_t, n>>(
data.data());
110 return std::mdspan<T, std::extents<size_t, n, 1>>(
data.data());
115 return std::mdspan<T, std::extents<size_t, 1, n>>(
data.data());
144 return std::mdspan<T, std::dextents<size_t, 2>>(
data.data(),
rows,
columns);
149 return std::mdspan<const T, std::dextents<size_t, 2>>(
data.data(),
rows,
columns);
172 for (
auto i = 0; i <
rows; i++) {
173 for (
auto j = 0; j <
columns; j++) {
202 return std::mdspan<T, std::dextents<size_t, 1>>(
data.data(),
size);
207 return std::mdspan<T, std::dextents<size_t, 2>>(
data.data(),
size, 1);
212 return std::mdspan<T, std::dextents<size_t, 2>>(
data.data(), 1,
size);
223template<
class T,
int m,
int n>
225 using component_type = T;
226 static constexpr u32 dimension = m * n;
228 static constexpr bool is_float_based
229 = std::is_same<T, f16>::value || std::is_same<T, f32>::value || std::is_same<T, f64>::value;
230 static constexpr bool is_uint_based = std::is_same<T, u8>::value || std::is_same<T, u16>::value
231 || std::is_same<T, u32>::value
232 || std::is_same<T, u64>::value;
233 static constexpr bool is_int_based = std::is_same<T, i8>::value || std::is_same<T, i16>::value
234 || std::is_same<T, i32>::value
235 || std::is_same<T, i64>::value;
236 static constexpr bool has_info = is_float_based || is_int_based || is_uint_based;
239 constexpr T min = shambase::get_min<T>();
243 constexpr T max = shambase::get_max<T>();
247 constexpr T zero = 0;
std::uint32_t u32
32 bit unsigned integer
Shamrock assertion utility.
mat_d & operator+=(const mat_d &other)
Addition operator for matrices.
constexpr auto get_mdspan() const
const overload
std::vector< T > data
The matrix data.
bool operator==(const mat_d< T > &other) const
Check if this matrix is equal to another one.
mat_d(int rows, int columns)
Constructor.
int columns
Number of columns.
bool equal_at_precision(const mat_d< T > &other, const T precision) const
check if this matrix is equal to another one at a given precison
constexpr const T & operator()(int i, int j) const
const overload
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.
Matrix class based on std::array storage and mdspan.
constexpr auto get_mdspan() const
const overload
std::array< f32, m *n > 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.
constexpr auto get_mdspan()
Get the vector data as a mdspan.
std::vector< T > data
The vector data.
constexpr auto get_mdspan_mat_row()
Get the vector data as a mdspan of a matrix with one row.
bool operator==(const vec_d< T > &other) const
Check if this vector is equal to another one.
constexpr auto get_mdspan_mat_col()
Get the vector data as a mdspan of a matrix with one column.
vec_d(int size)
Constructor.
constexpr T & operator[](int i)
Access the vector entry at position i.
Vector class based on std::array storage and mdspan.
constexpr auto get_mdspan()
Get the vector data as a mdspan.
bool operator==(const vec< T, n > &other) const
Check if this vector is equal to another one.
constexpr auto get_mdspan_mat_col()
Get the vector data as a mdspan of a matrix with one column.
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.
shammath::mat< f64, 3, 3 > f64_3x3
Alias for 3x3 double matrix.
shammath::mat< f32, 4, 4 > f32_4x4
Alias for 4x4 float matrix.
shammath::mat< f64, 4, 4 > f64_4x4
Alias for 4x4 double matrix.
shammath::mat< f32, 3, 3 > f32_3x3
Alias for 3x3 float matrix.
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.