SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
matrix_concept.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <concepts>
16#include <cstddef>
17#include <limits>
18
20
21namespace seqan3::detail
22{
23
26template <typename score_type>
28
35template <typename matrix_t>
36concept matrix = requires (std::remove_cvref_t<matrix_t> m) {
38
40
42
43 {
44 m.cols()
45 } -> std::same_as<typename std::remove_cvref_t<matrix_t>::size_type>;
46
47 {
48 m.rows()
49 } -> std::same_as<typename std::remove_cvref_t<matrix_t>::size_type>;
50
51 {
52 m.at(matrix_coordinate{})
53 } -> std::same_as<typename std::remove_cvref_t<matrix_t>::reference>;
54 };
56
57// Workaround for https://github.com/doxygen/doxygen/issues/9379
58#if SEQAN3_DOXYGEN_ONLY(1) 0
59template <typename matrix_t>
60class matrix
61{};
62#endif
63
90
102template <matrix matrix1_t, matrix matrix2_t>
103 requires std::equality_comparable_with<typename matrix1_t::reference, typename matrix2_t::reference>
104inline bool operator==(matrix1_t const & lhs, matrix2_t const & rhs) noexcept
105{
106 if (lhs.rows() != rhs.rows())
107 return false;
108
109 if (lhs.cols() != rhs.cols())
110 return false;
111
112 for (size_t row = 0u; row < lhs.rows(); ++row)
113 for (size_t col = 0u; col < lhs.cols(); ++col)
114 if (matrix_coordinate co{row_index_type{row}, column_index_type{col}}; lhs.at(co) != rhs.at(co))
115 return false;
116
117 return true;
118}
119
126template <matrix matrix1_t, matrix matrix2_t>
127 requires std::equality_comparable_with<typename matrix1_t::reference, typename matrix2_t::reference>
128inline bool operator!=(matrix1_t const & lhs, matrix2_t const & rhs) noexcept
129{
130 return !(lhs == rhs);
131}
133
134} // namespace seqan3::detail
Defines the requirements of a matrix (e.g. score matrices, trace matrices).
Definition: matrix_concept.hpp:61
bool operator!=(matrix1_t const &lhs, matrix2_t const &rhs) noexcept
Whether two alignment matrices are equal.
Definition: matrix_concept.hpp:128
bool operator==(matrix1_t const &lhs, matrix2_t const &rhs) noexcept
Whether two alignment matrices are equal.
Definition: matrix_concept.hpp:104
@ score_type
ID for the score_type option.
constexpr score_type matrix_inf
A special score which represents infinity.
Definition: matrix_concept.hpp:27
@ row
The corresponding alignment coordinate will be incrementable/decrementable in the row index.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
T max(T... args)
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
A strong type for designated initialisation of the column index of a matrix.
Definition: matrix_coordinate.hpp:32
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:61