libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
Matrices

This page contains links to the documentation of the functionality in libsemigroups for matrices.

There are several different classes in libsemigroups for representing matrices over various semirings. There are up to three different representations for every type of matrix:

  1. those whose dimension and arithmetic operations can be defined at compile time: StaticMatrix;
  2. those whose arithmetic operation can be defined at compile time but whose dimensions can be set at run time: DynamicMatrix (with compile-time arithmetic);
  3. those whose arithmetic operations and dimensions can be set at run time: DynamicMatrix (with run-time arithmetic).

It's unlikely that you will want to use the classes described on this page directly, but rather through the aliases described on the other matrix pages (such as, for example, BMat).

Warning
All of the matrices in libsemigroups have entries that are integer types, and the code does not currently attempt to detect overflows.

Over specific semirings

The following matrix classes are provided which define matrices over some specific semirings:

Over arbitrary semirings

The following general matrix classes are provided which can be used to define matrices over arbitrary semirings:

Row views

A row view is a lightweight representation of a row of a matrix. The following row view classes are provided:

Adapters

There are various specialisations of the adapters described on this page for the matrices described on this page:

Topics

 make<Matrix>
 Safely construct a Matrix instance.
 

Namespaces

namespace  libsemigroups::matrix
 Namespace for helper functions for matrices.
 

Functions

template<typename Mat>
auto operator* (typename Mat::scalar_type a, Mat const &x) -> std::enable_if_t< IsMatrix< Mat >, Mat >
 Multiply a matrix by a scalar.
 
template<typename Mat>
auto operator+ (typename Mat::scalar_type a, Mat const &x) -> std::enable_if_t< IsMatrix< Mat >, Mat >
 Add a scalar to a matrix.
 
template<typename S, typename T>
std::ostringstreamoperator<< (std::ostringstream &os, detail::RowViewCommon< S, T > const &x)
 Insertion operator for row views.
 
template<typename Mat>
auto operator<< (std::ostringstream &os, Mat const &x) -> std::enable_if_t< IsMatrix< Mat >, std::ostringstream & >
 Insertion operator for matrices.
 
template<typename Mat>
auto to_human_readable_repr (Mat const &x, std::string const &prefix, std::string const &short_name="", std::string const &braces="{}", size_t max_width=72) -> std::enable_if_t< IsMatrix< Mat >, std::string >
 Returns a human readable representation of a matrix.
 

Variables

template<typename T>
constexpr bool IsDynamicMatrix = IsMatrix<T> && !IsStaticMatrix<T>
 Helper variable template.
 
template<typename T>
static constexpr bool IsIntMat = detail::IsIntMatHelper<T>::value
 Helper variable template.
 
template<typename T>
constexpr bool IsMatrix = detail::IsMatrixHelper<T>::value
 Helper variable template.
 
template<typename T>
static constexpr bool IsMatWithSemiring = detail::IsMatWithSemiringHelper<T>::value
 Helper variable template.
 
template<typename T>
static constexpr bool IsMaxPlusMat = detail::IsMaxPlusMatHelper<T>::value
 Helper variable template.
 
template<typename T>
static constexpr bool IsMinPlusMat = detail::IsMinPlusMatHelper<T>::value
 Helper variable template.
 
template<typename T>
constexpr bool IsStaticMatrix = detail::IsStaticMatrixHelper<T>::value
 Helper variable template.
 

Function Documentation

◆ operator*()

template<typename Mat>
auto operator* ( typename Mat::scalar_type a,
Mat const & x ) -> std::enable_if_t<IsMatrix<Mat>, Mat>

This function returns the product of the matrix x and the scalar a.

Template Parameters
Matthe type of the 2nd argument, must satisfy IsMatrix<Mat>.
Parameters
athe scalar to multiply.
xthe matrix.
Returns
The product of a and x.
Exceptions
This function guarantees not to throw a LibsemigroupsException.
Warning
This function does not detect overflows of Mat::scalar_type.

◆ operator+()

template<typename Mat>
auto operator+ ( typename Mat::scalar_type a,
Mat const & x ) -> std::enable_if_t<IsMatrix<Mat>, Mat>

This function returns the sum of the matrix x and the scalar a.

Template Parameters
Matthe type of the 2nd argument, must satisfy IsMatrix<Mat>.
Parameters
athe scalar to add.
xthe matrix.
Returns
The sum of a and x.
Exceptions
This function guarantees not to throw a LibsemigroupsException.
Warning
This function does not detect overflows of Mat::scalar_type.

◆ operator<<() [1/2]

template<typename S, typename T>
std::ostringstream & operator<< ( std::ostringstream & os,
detail::RowViewCommon< S, T > const & x )

This function inserts a human readable representation of a row view into the string stream os.

Parameters
osthe string stream.
xthe row view.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ operator<<() [2/2]

template<typename Mat>
auto operator<< ( std::ostringstream & os,
Mat const & x ) -> std::enable_if_t<IsMatrix<Mat>, std::ostringstream&>

This function inserts a human readable representation of a matrix into the string stream os.

Template Parameters
Matthe type of the argument x, must satisfy IsMatrix<Mat>.
Parameters
osthe string stream.
xthe matrix.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ to_human_readable_repr()

template<typename Mat>
auto to_human_readable_repr ( Mat const & x,
std::string const & prefix,
std::string const & short_name = "",
std::string const & braces = "{}",
size_t max_width = 72 ) -> std::enable_if_t<IsMatrix<Mat>, std::string>

This function returns a human readable representation of a matrix.

Template Parameters
Matthe type of the matrix, must satisfy IsMatrix<Mat>.
Parameters
xthe matrix.
prefixthe prefix for the returned string.
short_namethe short name of the type of matrix (default: "").
bracesthe braces to use to delineate rows (default: "{}").
max_widththe maximum width of the returned representation (default: 72).
Exceptions
LibsemigroupsExceptionif braces does not have size 2.

Variable Documentation

◆ IsDynamicMatrix

template<typename T>
bool IsDynamicMatrix = IsMatrix<T> && !IsStaticMatrix<T>
constexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is DynamicMatrix; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsIntMat

template<typename T>
bool IsIntMat = detail::IsIntMatHelper<T>::value
staticconstexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is IntMat; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsMatrix

template<typename T>
bool IsMatrix = detail::IsMatrixHelper<T>::value
constexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is derived from any of DynamicMatrix (with compile-time arithmetic), DynamicMatrix (with run-time arithmetic), or StaticMatrix; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsMatWithSemiring

template<typename T>
bool IsMatWithSemiring = detail::IsMatWithSemiringHelper<T>::value
staticconstexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is DynamicMatrix<Semiring, Scalar>; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsMaxPlusMat

template<typename T>
bool IsMaxPlusMat = detail::IsMaxPlusMatHelper<T>::value
staticconstexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is MaxPlusMat; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsMinPlusMat

template<typename T>
bool IsMinPlusMat = detail::IsMinPlusMatHelper<T>::value
staticconstexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is MinPlusMat; and false otherwise.

Template Parameters
Tthe type to check.

◆ IsStaticMatrix

template<typename T>
bool IsStaticMatrix = detail::IsStaticMatrixHelper<T>::value
constexpr

Defined in matrix.hpp.

This variable has value true if the template parameter T is StaticMatrix; and false otherwise.

Template Parameters
Tthe type to check.