19#ifndef LIBSEMIGROUPS_MATRIX_HELPERS_HPP_
20#define LIBSEMIGROUPS_MATRIX_HELPERS_HPP_
26#include <unordered_map>
27#include <unordered_set>
32#include "constants.hpp"
34#include "exception.hpp"
35#include "is-matrix.hpp"
36#include "matrix-class.hpp"
38#include "detail/containers.hpp"
39#include "detail/matrix-exceptions.hpp"
44 struct IsStdBitSetHelper : std::false_type {};
47 struct IsStdBitSetHelper<std::bitset<N>> : std::true_type {};
50 static constexpr bool IsStdBitSet = IsStdBitSetHelper<T>::value;
53 struct BitSetCapacity {
54 static constexpr size_t value = BitSet<1>::max_size();
57 template <
size_t R,
size_t C>
59 static_assert(R == C,
"the number of rows and columns must be equal");
60 static constexpr size_t value = R;
88 template <
typename Mat>
89 [[nodiscard]]
constexpr auto threshold(Mat
const&)
noexcept
90 -> std::enable_if_t<!detail::IsTruncMat<Mat>,
91 typename Mat::scalar_type> {
108 template <
typename Mat>
109 [[nodiscard]]
constexpr auto threshold(Mat
const&)
noexcept
111 typename Mat::scalar_type> {
112 return detail::IsTruncMatHelper<Mat>::threshold;
130 template <
typename Mat>
133 typename Mat::scalar_type> {
134 return x.semiring()->threshold();
158 template <
size_t T,
size_t P,
size_t R,
size_t C,
typename Scalar>
159 [[nodiscard]]
constexpr Scalar
181 template <
size_t T,
size_t P,
typename Scalar>
182 [[nodiscard]]
constexpr Scalar
202 template <
typename Scalar>
205 return x.semiring()->period();
248 template <
typename Mat>
249 [[nodiscard]] Mat
pow(Mat
const& x,
typename Mat::scalar_type e);
274 template <
typename Mat,
typename = std::enable_if_t<IsDynamicMatrix<Mat>>>
301 template <
typename Mat,
typename = std::enable_if_t<IsStaticMatrix<Mat>>>
302 [[nodiscard]] detail::StaticVector1<typename Mat::RowView, Mat::nr_rows>
304 detail::StaticVector1<typename Mat::RowView, Mat::nr_rows> container;
344 template <
typename Mat,
size_t R,
size_t C,
typename Container>
346 detail::StaticVector1<BitSet<C>, R>& result);
380 template <
typename Mat,
size_t R,
size_t C,
typename Container>
411 template <
typename Mat,
size_t R,
size_t C>
412 void bitset_rows(Mat
const& x, detail::StaticVector1<BitSet<C>, R>& result);
432 template <
typename Mat>
463 template <
typename Mat,
typename Container>
489 template <
typename Mat,
typename Container>
519 template <typename Mat, size_t M = detail::BitSetCapacity<Mat>::value>
520 [[nodiscard]] detail::StaticVector1<BitSet<M>, M>
546 template <
typename Mat,
typename Container>
580 template <
typename Mat,
typename Container>
581 std::enable_if_t<IsMaxPlusTruncMat<Mat>>
582 row_basis(Container&& views, std::decay_t<Container>& result);
614 template <
typename Mat,
typename Container>
615 std::enable_if_t<IsBMat<Mat>>
row_basis(Container&& views,
616 std::decay_t<Container>& result);
644 template <
typename Mat,
646 typename = std::enable_if_t<IsMatrix<Mat>>>
671 template <
typename Mat,
typename = std::enable_if_t<IsDynamicMatrix<Mat>>>
697 template <
typename Mat,
typename = std::enable_if_t<IsStaticMatrix<Mat>>>
698 [[nodiscard]] detail::StaticVector1<typename Mat::RowView, Mat::nr_rows>
700 detail::StaticVector1<typename Mat::RowView, Mat::nr_rows> container;
724 template <
typename Mat,
726 typename = std::enable_if_t<!IsMatrix<std::decay_t<Container>>>>
730 template <
typename T>
732 void operator()(T& res, T
const& pt, T
const& x)
const {
739 template <
typename Mat,
741 typename = std::enable_if_t<IsMatrix<Mat>>>
742 void row_basis_rows(Mat
const& x, Container& result);
745 template <
typename Mat,
747 typename = std::enable_if_t<IsStaticMatrix<Mat>>>
748 [[nodiscard]] detail::StaticVector1<typename Mat::Row, Mat::nr_rows>
749 row_basis_rows(Mat
const& x);
752 template <
typename Mat,
754 typename = std::enable_if_t<IsDynamicMatrix<Mat>>>
757 row_basis_rows(x, container);
762 template <
typename Mat,
764 typename = std::enable_if_t<IsStaticMatrix<Mat>>>
765 [[nodiscard]] detail::StaticVector1<typename Mat::Row, Mat::nr_rows>
766 row_basis_rows(Container&&
rows);
802 template <
typename Mat,
typename = std::enable_if_t<IsBMat<Mat>>>
807#include "matrix-helpers.tpp"
StaticMatrix< BooleanPlus, BooleanProd, BooleanZero, BooleanOne, R, C, int > StaticBMat
Alias for static boolean matrices.
Definition matrix-class.hpp:2144
Undefined const UNDEFINED
Value for something undefined.
static constexpr bool IsMatWithSemiring
Helper variable template.
Definition is-matrix.hpp:127
DynamicMatrix< NTPPlus< T, P, Scalar >, NTPProd< T, P, Scalar >, IntegerZero< Scalar >, IntegerOne< Scalar >, Scalar > DynamicNTPMatWithoutSemiring
Alias for ntp matrices with static threshold and period.
Definition matrix-class.hpp:3881
DynamicMatrix< NTPSemiring< Scalar >, Scalar > DynamicNTPMatWithSemiring
Alias for ntp matrices with dynamic threshold and period.
Definition matrix-class.hpp:3865
StaticMatrix< NTPPlus< T, P, Scalar >, NTPProd< T, P, Scalar >, IntegerZero< Scalar >, IntegerOne< Scalar >, R, C, Scalar > StaticNTPMat
Alias for ntp matrices with static threshold and period, and dimensions.
Definition matrix-class.hpp:3907
Namespace for helper functions for matrices.
Definition matrix-exceptions.hpp:37
void bitset_row_basis(Container &&rows, std::decay_t< Container > &result)
Appends a basis for the space spanned by some bitsets to a container.
void bitset_rows(Container &&views, detail::StaticVector1< BitSet< C >, R > &result)
Converts a container of row views of a boolean matrix to bit sets, and append them to another contain...
constexpr Scalar period(StaticNTPMat< T, P, R, C, Scalar > const &) noexcept
Returns the period of a static ntp matrix.
Definition matrix-helpers.hpp:160
constexpr auto threshold(Mat const &) noexcept -> std::enable_if_t<!detail::IsTruncMat< Mat >, typename Mat::scalar_type >
Returns the threshold of a matrix.
Definition matrix-helpers.hpp:89
size_t row_space_size(Mat const &x)
Returns the size of the row space of a boolean matrix.
std::vector< typename Mat::RowView > rows(Mat const &x)
Returns a std::vector of row views into the rows of a dynamic matrix.
Definition matrix-helpers.hpp:275
Mat pow(Mat const &x, typename Mat::scalar_type e)
Returns a power of a matrix.
std::enable_if_t< IsMaxPlusTruncMat< Mat > > row_basis(Container &&views, std::decay_t< Container > &result)
Appends a basis for a space spanned by row views or bit sets to a container.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44