Loading...
Searching...
No Matches
matrix_coordinate.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <concepts>
#include <type_traits>
#include <seqan3/core/detail/strong_type.hpp>
#include <seqan3/utility/concept.hpp>
#include <seqan3/utility/simd/algorithm.hpp>
#include <seqan3/utility/simd/concept.hpp>
namespace seqan3::detail
{
template <typename index_type>
requires (std::integral<index_type> || simd_index<index_type>)
struct column_index_type : detail::strong_type<index_type, column_index_type<index_type>>
{
using detail::strong_type<index_type, column_index_type<index_type>>::strong_type;
};
template <std::signed_integral index_type>
column_index_type(index_type) -> column_index_type<std::ptrdiff_t>;
template <std::unsigned_integral index_type>
column_index_type(index_type) -> column_index_type<size_t>;
template <simd_index index_type>
column_index_type(index_type) -> column_index_type<index_type>;
template <typename index_type>
requires (std::integral<index_type> || simd_index<index_type>)
struct row_index_type : detail::strong_type<index_type, row_index_type<index_type>>
{
using detail::strong_type<index_type, row_index_type<index_type>>::strong_type;
};
template <std::signed_integral index_type>
row_index_type(index_type) -> row_index_type<std::ptrdiff_t>;
template <std::unsigned_integral index_type>
row_index_type(index_type) -> row_index_type<size_t>;
template <simd_index index_type>
row_index_type(index_type) -> row_index_type<index_type>;
template <typename index_t>
requires (std::integral<index_t> || simd_index<index_t>)
struct matrix_index
{
constexpr matrix_index() = default;
constexpr matrix_index(matrix_index const &) = default;
constexpr matrix_index(matrix_index &&) = default;
constexpr matrix_index & operator=(matrix_index const &) = default;
constexpr matrix_index & operator=(matrix_index &&) = default;
~matrix_index() = default;
constexpr matrix_index(row_index_type<index_t> const row_idx, column_index_type<index_t> const col_idx) noexcept :
row{row_idx.get()},
col{col_idx.get()}
{}
template <seqan3::arithmetic scalar_index_t>
constexpr matrix_index(row_index_type<scalar_index_t> const row_idx,
column_index_type<scalar_index_t> const col_idx) noexcept
requires simd_index<index_t>
// Note the explicit type conversion is necessary since the scalar type might be of smaller bit size.
:
row{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(row_idx.get()))},
col{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(col_idx.get()))}
{}
template <std::integral other_index_t>
requires (!std::same_as<other_index_t, index_t>)
explicit constexpr matrix_index(matrix_index<other_index_t> other) noexcept :
row{static_cast<index_t>(other.row)},
col{static_cast<index_t>(other.col)}
{}
template <std::integral first_index_t, std::integral second_index_t>
constexpr explicit operator std::pair<first_index_t, second_index_t>() const noexcept
{
return std::pair{static_cast<first_index_t>(col), static_cast<second_index_t>(row)};
}
index_t row{};
index_t col{};
};
matrix_index() -> matrix_index<std::ptrdiff_t>;
template <std::integral row_index_t, std::integral col_index_t>
requires std::common_with<row_index_t, col_index_t>
matrix_index(row_index_type<row_index_t>,
column_index_type<col_index_t>) -> matrix_index<std::common_type_t<row_index_t, col_index_t>>;
template <simd_index index_t>
matrix_index(row_index_type<index_t>, column_index_type<index_t>) -> matrix_index<index_t>;
using matrix_coordinate = matrix_index<size_t>;
template <simd_index index_t>
using simd_matrix_coordinate = matrix_index<index_t>;
using matrix_offset = matrix_index<std::ptrdiff_t>;
} // namespace seqan3::detail
strong_type.hpp
Provides basic data structure for strong types.
type_traits
concept.hpp
Provides concepts that do not have equivalents in C++20.
Hide me