Defined in matrix.hpp.
This is a class for matrices where both the arithmetic operations in the underlying semiring and the dimensions of the matrix can be set at run time.
| Semiring | the type of a semiring object which defines the semiring arithmetic (see requirements below). |
| Scalar | the type of the entries in the matrices (the type of elements in the underlying semiring). |
The template parameter Semiring must have the following member functions:
scalar_type scalar_zero() that returns the multiplicative zero scalar in the semiringscalar_type scalar_one() that returns the multiplicative identity scalar in the semiringscalar_type plus_no_checks(scalar_type x, scalar_type y) that returns the sum in the semiring of the scalars x and y.scalar_type product_no_checks(scalar_type x, scalar_type y) that returns the product in the semiring of the scalars x and y.See, for example, MaxPlusTruncSemiring.
Public Types | |
| using | Row = DynamicMatrix |
| Alias for the type of the rows of a DynamicMatrix. | |
| using | RowView = DynamicRowView<Semiring, Scalar> |
| Alias for the type of row views of a DynamicMatrix. | |
| using | scalar_const_reference = typename MatrixCommon::scalar_const_reference |
Alias for const references to the template parameter Scalar. | |
| using | scalar_reference = typename MatrixCommon::scalar_reference |
Alias for references to the template parameter Scalar. | |
| using | scalar_type = typename MatrixCommon::scalar_type |
Alias for the template parameter Scalar. | |
| using | semiring_type = Semiring |
| Alias for the template parameter Semiring. | |
Public Member Functions | |
| DynamicMatrix ()=delete | |
| Deleted. | |
| DynamicMatrix (DynamicMatrix &&)=default | |
| Default move constructor. | |
| DynamicMatrix (DynamicMatrix const &)=default | |
| Default copy constructor. | |
| DynamicMatrix (RowView const &rv) | |
| Construct a row over a given semiring (RowView). | |
| DynamicMatrix (Semiring const *sr, size_t r, size_t c) | |
| Construct a matrix over a given semiring with given dimensions. | |
| DynamicMatrix (Semiring const *sr, std::initializer_list< scalar_type > const &rw) | |
| Construct a row over a given semiring (std::initializer_list). | |
| DynamicMatrix (Semiring const *sr, std::initializer_list< std::initializer_list< scalar_type > > const &rws) | |
| Construct a matrix over a given semiring (std::initializer_list of std::initializer_list). | |
| DynamicMatrix (Semiring const *sr, std::vector< std::vector< scalar_type > > const &rws) | |
| Construct a matrix over a given semiring (std::vector of std::vector). | |
| scalar_reference | at (size_t r, size_t c) |
| Returns a reference to the specified entry of the matrix. | |
| scalar_reference | at (size_t r, size_t c) const |
| Returns a const reference to the specified entry of the matrix. | |
| iterator | begin () noexcept |
| Returns an iterator pointing at the first entry. | |
| const_iterator | cbegin () noexcept |
| Returns a const iterator pointing at the first entry. | |
| const_iterator | cend () noexcept |
| Returns a const iterator pointing one beyond the last entry in the matrix. | |
| std::pair< scalar_type, scalar_type > | coords (const_iterator it) const |
| Get the coordinates of an iterator. | |
| iterator | end () noexcept |
| Returns an iterator pointing one beyond the last entry in the matrix. | |
| size_t | hash_value () const |
| Return a hash value of a matrix. | |
| size_t | number_of_cols () const noexcept |
| Returns the number of columns of the matrix. | |
| size_t | number_of_rows () const noexcept |
| Returns the number of rows of the matrix. | |
| bool | operator!= (DynamicMatrix const &that) const |
| Inequality operator. | |
| bool | operator!= (RowView const &that) const |
| Inequality operator. | |
| scalar_reference | operator() (size_t r, size_t c) |
| Returns a reference to the specified entry of the matrix. | |
| scalar_const_reference | operator() (size_t r, size_t c) const |
| Returns a const reference to the specified entry of the matrix. | |
| DynamicMatrix | operator* (DynamicMatrix const &that) |
| Returns the product of two matrices. | |
| DynamicMatrix | operator* (scalar_type a) |
| Multiplies every entry of a matrix by a scalar in-place. | |
| void | operator*= (scalar_type a) |
| Multiplies every entry of a matrix by a scalar in-place. | |
| DynamicMatrix | operator+ (DynamicMatrix const &that) |
| Returns the sum of two matrices. | |
| void | operator+= (DynamicMatrix const &that) |
| Add a matrix to another matrix in-place. | |
| void | operator+= (RowView const &that) |
| Add a matrix to another matrix in-place. | |
| void | operator+= (scalar_type a) |
| Adds a scalar to every entry of the matrix in-place. | |
| bool | operator< (DynamicMatrix const &that) const |
| Less than operator. | |
| bool | operator< (RowView const &that) const |
| Less than operator. | |
| template<typename T> | |
| bool | operator<= (T const &that) const |
| Less than or equal operator. | |
| DynamicMatrix & | operator= (DynamicMatrix &&)=default |
| Default move assignment operator. | |
| DynamicMatrix & | operator= (DynamicMatrix const &)=default |
| Default copy assignment operator. | |
| bool | operator== (DynamicMatrix const &that) const |
| Equality operator. | |
| bool | operator== (RowView const &that) const |
| Equality operator. | |
| bool | operator> (DynamicMatrix const &that) const |
| Greater than operator. | |
| template<typename T> | |
| bool | operator>= (T const &that) const |
| Greater than or equal operator. | |
| void | product_inplace_no_checks (DynamicMatrix const &x, DynamicMatrix const &y) |
Multiplies x and y and stores the result in this. | |
| RowView | row (size_t i) const |
| Returns a view into a row. | |
| RowView | row_no_checks (size_t i) const |
| Returns a view into a row. | |
| template<typename T> | |
| void | rows (T &x) const |
| Add row views for every row in the matrix to a container. | |
| scalar_type | scalar_one () const noexcept |
| Returns the multiplicative identity of the underlying semiring. | |
| scalar_type | scalar_zero () const noexcept |
| Returns the additive identity of the underlying semiring. | |
| semiring_type const * | semiring () const noexcept |
| Returns the underlying semiring. | |
| void | swap (DynamicMatrix &that) noexcept |
Swaps the contents of *this with the contents of that. | |
| void | transpose () |
| Transpose a matrix in-place. | |
| void | transpose_no_checks () |
| Transpose a matrix in-place. | |
Static Public Member Functions | |
| static DynamicMatrix | one (Semiring const *semiring, size_t n) |
| Construct the \(n \times n\) identity matrix. | |
|
delete |
The default constructor for this variant of DynamicMatrix is deleted because a valid semiring object is required to define the arithmetic at run-time.
|
default |
Default copy constructor.
|
default |
Default move constructor.
|
inline |
Construct a matrix over the semiring semiring with the given dimensions.
| sr | a pointer to const semiring object. |
| r | the number of rows in the matrix being constructed. |
| c | the number of columns in the matrix being constructed. |
|
inlineexplicit |
This function constructs a matrix over a given semiring from an std::initializer_list of the rows (std::initializer_list).
| sr | a pointer to const semiring object. |
| rws | the values to be copied into the matrix. |
|
inlineexplicit |
This function constructs a matrix over a given semiring from an std::vector of the rows (std::vector).
| sr | a pointer to const semiring object. |
| rws | the values to be copied into the matrix. |
|
inlineexplicit |
Construct a row over a given semiring from a std::initializer_list of the entries.
| sr | a pointer to const Semiring object. |
| rw | the values to be copied into the row. |
|
inlineexplicit |
Construct a row over a given semiring from a RowView.
| rv | the row view. |
| scalar_reference at | ( | size_t | r, |
| size_t | c ) |
Returns a reference to the specified entry of the matrix.
| r | the index of the row of the entry. |
| c | the index of the column of the entry. |
| LibsemigroupsException | if r or c is out of bounds. |
| scalar_reference at | ( | size_t | r, |
| size_t | c ) const |
Returns a const reference to the specified entry of the matrix.
| r | the index of the row of the entry. |
| c | the index of the column of the entry. |
| LibsemigroupsException | if r or c is out of bounds. |
|
noexcept |
This function returns a random access iterator point at the first entry of the matrix.
noexcept and is guaranteed never to throw.
|
noexcept |
This function returns a const (random access) iterator pointing at the first entry in the matrix.
noexcept and is guaranteed never to throw.
|
noexcept |
This function returns a const (random access) iterator pointing one passed the last entry of the matrix.
noexcept and is guaranteed never to throw.| std::pair< scalar_type, scalar_type > coords | ( | const_iterator | it | ) | const |
This function returns a pair containing the row and columns corresponding to a const_iterator pointing into a matrix.
| it | the const_iterator. |
std::pair<scalar_type, scalar_type>.
|
noexcept |
noexcept and is guaranteed never to throw.| size_t hash_value | ( | ) | const |
This function returns a hash value for a matrix. The return value is recomputed every time this function is called.
this.noexcept and is guaranteed never to throw.
|
noexcept |
This function returns the number of columns of the matrix.
size_t.noexcept and is guaranteed never to throw.
|
noexcept |
This function returns the number of rows of the matrix.
size_t.noexcept and is guaranteed never to throw.
|
inlinestatic |
Construct the \(n \times n\) identity matrix.
| semiring | the semiring. |
| n | the dimension. |
semiring.| bool operator!= | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) | const |
This function returns true if *this is not equal to that; and false otherwise.
| that | the matrix or row view for comparison. |
operator==(that).| bool operator!= | ( | RowView const & | that | ) | const |
This function returns true if *this is not equal to that; and false otherwise.
| that | the matrix or row view for comparison. |
operator==(that).| scalar_reference operator() | ( | size_t | r, |
| size_t | c ) |
Returns a reference to the specified entry of the matrix.
| r | the index of the row of the entry. |
| c | the index of the column of the entry. |
r and c are performed. | scalar_const_reference operator() | ( | size_t | r, |
| size_t | c ) const |
Returns a const reference to the specified entry of the matrix.
| r | the index of the row of the entry. |
| c | the index of the column of the entry. |
r and c are performed. | DynamicMatrix operator* | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) |
This function returns the product of two matrices.
| that | the matrix to multiply by this. |
| DynamicMatrix operator* | ( | scalar_type | a | ) |
This function multiplies every entry of a matrix by a scalar in-place.
| a | the scalar to multiply every entry by. |
| void operator*= | ( | scalar_type | a | ) |
This function multiplies every entry of a matrix by a scalar in-place.
| a | the scalar to multiply every entry by. |
| DynamicMatrix operator+ | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) |
This function returns the sum of two matrices.
| that | the matrix to add to this. |
| void operator+= | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) |
This function adds a matrix (or the row represented by a RowView) to another matrix of the same shape in-place.
| that | the matrix or row view to add. |
| void operator+= | ( | RowView const & | that | ) |
This function adds a matrix (or the row represented by a RowView) to another matrix of the same shape in-place.
| that | the matrix or row view to add. |
| void operator+= | ( | scalar_type | a | ) |
This function adds a scalar to every entry of the matrix in-place.
| a | the scalar_type to add to a DynamicMatrix. |
| bool operator< | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) | const |
This operator defines a total order on the set of matrices of the same type.
| that | the matrix or row view for comparison. |
true if *this is less than that and false if it is not.| bool operator< | ( | RowView const & | that | ) | const |
This operator defines a total order on the set of matrices of the same type.
| that | the matrix or row view for comparison. |
true if *this is less than that and false if it is not.| bool operator<= | ( | T const & | that | ) | const |
This operator defines a total order on the set of matrices of the same type.
| U | the type of the argument that. |
| that | the matrix or row view for comparison. |
true if *this is less than or equal to that and false if it is not.
|
default |
Default move assignment operator.
|
default |
Default copy assignment operator.
| bool operator== | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) | const |
This function returns true if *this is equal to that; and false otherwise.
| that | matrix or row view for comparison. |
true if *this and that are equal and false if they are not.| bool operator== | ( | RowView const & | that | ) | const |
This function returns true if *this is equal to that; and false otherwise.
| that | matrix or row view for comparison. |
true if *this and that are equal and false if they are not.| bool operator> | ( | DynamicMatrix< Semiring, Scalar > const & | that | ) | const |
This operator defines a total order on the set of matrices of the same type.
| that | the matrix for comparison. |
true if *this is less than that and false if it is not.| bool operator>= | ( | T const & | that | ) | const |
This operator defines a total order on the set of matrices of the same type.
| U | the type of the argument that. |
| that | the matrix or row view for comparison. |
true if *this is greater than or equal to that and false if it is not.| void product_inplace_no_checks | ( | DynamicMatrix< Semiring, Scalar > const & | x, |
| DynamicMatrix< Semiring, Scalar > const & | y ) |
This function redefines this to be the product of x and y. This is in-place multiplication to avoid allocation of memory for products which do not need to be stored for future use.
| x | the first matrix to multiply. |
| y | the second matrix to multiply. |
| RowView row | ( | size_t | i | ) | const |
This function returns a RowView into the row with index i.
| i | the index of the row. |
| LibsemigroupsException | if i is greater than or equal to number_of_rows. |
| RowView row_no_checks | ( | size_t | i | ) | const |
This function returns a RowView into the row with index i.
| i | the index of the row. |
i. | void rows | ( | T & | x | ) | const |
This function adds a RowView for each row in the matrix to the container x.
| T | the type of the container. |
| x | a container. |
R.
|
noexcept |
This function returns the multiplicative identity of the underlying semiring of a matrix.
noexcept and is guaranteed never to throw.
|
noexcept |
This function returns the additive identity of the underlying semiring of a matrix.
noexcept and is guaranteed never to throw.
|
noexcept |
Returns a const pointer to the underlying semiring (if any).
Semiring const*.noexcept and is guaranteed never to throw.
|
inlinenoexcept |
This function swaps the contents of *this with the contents of that.
| that | the matrix to swap contents with. |
noexcept and is guaranteed never to throw.| void transpose | ( | ) |
This function transpose a matrix object in-place.
| LibsemigroupsException | if the matrix isn't square. |
| void transpose_no_checks | ( | ) |
This function transpose a matrix object in-place.