libsemigroups  v3.6.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
matrix-exceptions.hpp
1//
2// libsemigroups - C++ library for semigroups and monoids
3// Copyright (C) 2026 James D. Mitchell
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17//
18
19// This file contains declarations of exception throwing functions for use
20// in matrix.hpp.
21
22#ifndef LIBSEMIGROUPS_DETAIL_MATRIX_EXCEPTIONS_HPP_
23#define LIBSEMIGROUPS_DETAIL_MATRIX_EXCEPTIONS_HPP_
24
25#include <algorithm> // for find_if_not
26#include <initializer_list> // for initializer_list
27#include <iterator> // for distance, empty
28#include <stddef.h> // for size_t
29#include <stdint.h> // for uint64_t
30#include <string_view> // for basic_string_view, string_view
31#include <type_traits> // for enable_if_t
32
33#include "libsemigroups/exception.hpp" // for LIBSEMIGROUPS_EXCEPTION
34#include "libsemigroups/is-matrix.hpp" // for IsStaticMatrix, IsDynamicMatrix
35
36namespace libsemigroups {
37 namespace matrix {
38
52 // TODO deprecate + move to detail
53 template <typename Mat>
54 void throw_if_not_square(Mat const& x,
55 std::string_view arg_desc = "the argument");
56
74 // TODO deprecate
75 template <typename Mat>
76 void throw_if_bad_dim(Mat const& x,
77 Mat const& y,
78 std::string_view arg_desc_x = "the 1st argument",
79 std::string_view arg_desc_y = "the 2nd argument");
80
95 // TODO deprecate -> detail
96 template <typename Mat>
97 void throw_if_bad_coords(Mat const& x, size_t r, size_t c);
98 } // namespace matrix
99
100 namespace detail {
101 template <typename Mat>
102 void throw_if_semiring_nullptr(Mat const& m);
103
104 template <typename Mat, typename Container>
105 auto throw_if_bad_dim(Container const& m)
106 -> std::enable_if_t<IsStaticMatrix<Mat>>;
107
108 // Not checking dynamic matrices, no compile-time dimensions.
109 template <typename Mat, typename Container>
110 auto throw_if_bad_dim(Container const&)
111 -> std::enable_if_t<IsDynamicMatrix<Mat>> {}
112
113 template <typename Mat, typename Container>
114 auto throw_if_bad_row_dim(Container const& row)
115 -> std::enable_if_t<IsStaticMatrix<Mat>>;
116
117 template <typename Mat, typename Container>
118 auto throw_if_bad_row_dim(Container const&)
119 -> std::enable_if_t<IsDynamicMatrix<Mat>> {}
120
121 template <typename Container>
122 void throw_if_any_row_wrong_size(Container const& m);
123
124 template <typename Scalar>
125 void throw_if_any_row_wrong_size(
126 std::initializer_list<std::initializer_list<Scalar>> m) {
127 throw_if_any_row_wrong_size<
128 std::initializer_list<std::initializer_list<Scalar>>>(m);
129 }
130 } // namespace detail
131} // namespace libsemigroups
132
133#include "matrix-exceptions.tpp"
134#endif // LIBSEMIGROUPS_DETAIL_MATRIX_EXCEPTIONS_HPP_
Namespace for helper functions for matrices.
Definition matrix-exceptions.hpp:37
void throw_if_not_square(Mat const &x, std::string_view arg_desc="the argument")
Throws if a matrix is not square.
void throw_if_bad_coords(Mat const &x, size_t r, size_t c)
Throws the arguments do not index an entry of a matrix.
void throw_if_bad_dim(Mat const &x, Mat const &y, std::string_view arg_desc_x="the 1st argument", std::string_view arg_desc_y="the 2nd argument")
Throws if two matrices do not have the same dimensions.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44