Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
matrix_op.hpp File Reference
#include "shambase/assert.hpp"
#include "shambase/type_traits.hpp"
#include "shambackends/math.hpp"
#include "shambackends/sycl.hpp"
#include <experimental/mdspan>
#include <array>
Include dependency graph for matrix_op.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  shammath
 namespace for math utility

Functions

template<class T, class Extents, class Layout, class Accessor, class Func>
void shammath::mat_set_vals (const std::mdspan< T, Extents, Layout, Accessor > &input, Func &&func)
 Set the elements of a matrix according to a user-provided function.
template<class T, class Extents, class Layout, class Accessor, class Func>
void shammath::mat_update_vals (const std::mdspan< T, Extents, Layout, Accessor > &input, Func &&func)
 Update the elements of a matrix according to a user-provided function.
template<class T, class Extents, class Layout, class Accessor>
void shammath::mat_set_identity (const std::mdspan< T, Extents, Layout, Accessor > &input1)
 Set the content of a matrix to the identity matrix.
template<class T, class Extents, class Layout, class Accessor>
void shammath::mat_mul_scalar (const std::mdspan< T, Extents, Layout, Accessor > &input, const T &scalar)
 Multiply a matrix by a scalar value.
template<class T, class Extents, class Layout, class Accessor>
void shammath::mat_copy (const std::mdspan< T, Extents, Layout, Accessor > &input, const std::mdspan< T, Extents, Layout, Accessor > &output)
 Copy a matrix to another matrix.
template<class T, class Extents1, class Extents2, class Extents3, class Layout1, class Layout2, class Layout3, class Accessor1, class Accessor2, class Accessor3>
void shammath::mat_plus (const std::mdspan< T, Extents1, Layout1, Accessor1 > &input1, const std::mdspan< T, Extents2, Layout2, Accessor2 > &input2, const std::mdspan< T, Extents3, Layout3, Accessor3 > &output)
 Add two matrices element-wise.
template<class T, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::mat_plus_equal (const std::mdspan< T, Extents1, Layout1, Accessor1 > &inout, const std::mdspan< T, Extents2, Layout2, Accessor2 > &matb)
 Add a matrix to another matrix element-wise and store the result in the first matrix.
template<class T, class Extents1, class Extents2, class Extents3, class Layout1, class Layout2, class Layout3, class Accessor1, class Accessor2, class Accessor3>
void shammath::mat_sub (const std::mdspan< T, Extents1, Layout1, Accessor1 > &input1, const std::mdspan< T, Extents2, Layout2, Accessor2 > &input2, const std::mdspan< T, Extents3, Layout3, Accessor3 > &output)
 Subtract two matrices element-wise.
template<class T, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::mat_sub_equal (const std::mdspan< T, Extents1, Layout1, Accessor1 > &inout, const std::mdspan< T, Extents2, Layout2, Accessor2 > &matb)
 Subtract a matrix from another matrix element-wise and store the result in the first matrix.
template<class Ta, class Tb, class Extents1, class Extents2, class Extents3, class Layout1, class Layout2, class Layout3, class Accessor1, class Accessor2, class Accessor3>
void shammath::mat_prod (const std::mdspan< Ta, Extents1, Layout1, Accessor1 > &input1, const std::mdspan< Ta, Extents2, Layout2, Accessor2 > &input2, const std::mdspan< Tb, Extents3, Layout3, Accessor3 > &output)
 Compute the product of two matrices.
template<class T, class SizeType, class Layout, class Accessor>
void shammath::mat_inv_33 (const std::mdspan< T, std::extents< SizeType, 3, 3 >, Layout, Accessor > &input, const std::mdspan< T, std::extents< SizeType, 3, 3 >, Layout, Accessor > &output)
 Compute the inverse of a 3x3 matrix.
template<class T, class U, class Extents, class Layout, class Accessor>
void shammath::mat_L1_norm (const std::mdspan< T, Extents, Layout, Accessor > &input, U &res)
 compute the L1 norm of a given matrix
template<class T, class Extents, class Layout, class Accessor>
void shammath::mat_set_nul (const std::mdspan< T, Extents, Layout, Accessor > &input)
 Set the content of a matrix to zero.
template<class T, class Extents, class Layout, class Accessor>
void shammath::vec_set_nul (const std::mdspan< T, Extents, Layout, Accessor > &input)
 Set the content of a vector to zero.
template<class T, class Extents, class Layout, class Accessor>
void shammath::vec_copy (const std::mdspan< T, Extents, Layout, Accessor > &input, const std::mdspan< T, Extents, Layout, Accessor > &output)
 Copy the content of one vector in another.
template<class T, class U, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::vec_axpy_beta (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &input, const U beta, const std::mdspan< T, Extents2, Layout2, Accessor2 > &output)
 This function compute y = alpha*x + beta*y with x,y both vectors.
template<class T, class U, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::vec_axpy (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &input, const std::mdspan< T, Extents2, Layout2, Accessor2 > &output)
 This function compute y = alpha*x + y with x,y both vectors.
template<class T, class U, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::mat_axpy_beta (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &input, const U beta, const std::mdspan< T, Extents2, Layout2, Accessor2 > &output)
 This function compute M = alpha*N + beta*M with M,N both matrices.
template<class T, class U, class Extents1, class Extents2, class Layout1, class Layout2, class Accessor1, class Accessor2>
void shammath::mat_axpy (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &input, const std::mdspan< T, Extents2, Layout2, Accessor2 > &output)
 This function compute M = alpha*N + beta*M with M,N both matrices.
template<class T, class U, class Extents1, class Extents2, class Extents3, class Layout1, class Layout2, class Layout3, class Accessor1, class Accessor2, class Accessor3>
void shammath::mat_gemm (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &input1, const std::mdspan< T, Extents2, Layout2, Accessor2 > &input2, const U beta, const std::mdspan< T, Extents3, Layout3, Accessor3 > &output)
 This function compute C = alpha*A*B + beta*C with A,B,C are matrices.
template<class T, class U, class Extents1, class Layout1, class Accessor1>
void shammath::mat_plus_equal_scalar_id (const std::mdspan< T, Extents1, Layout1, Accessor1 > &inout, const U beta)
 This function compute addition of a matrix with mutiple of identity matrix A +=beta * I, where I is an Identity matrix. A is a matrix.
template<class T, class U, class Extents1, class Extents2, class Extents3, class Layout1, class Layout2, class Layout3, class Accessor1, class Accessor2, class Accessor3>
void shammath::mat_gemv (const U alpha, const std::mdspan< T, Extents1, Layout1, Accessor1 > &M, const std::mdspan< T, Extents2, Layout2, Accessor2 > &x, const U beta, const std::mdspan< T, Extents3, Layout3, Accessor3 > &y)
 This function performs matrix-vector multiplication as y = a*Mx + b*y.

Detailed Description