SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
coordinate_matrix.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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 <seqan3/std/concepts>
16#include <seqan3/std/ranges>
17
26
27namespace seqan3::detail
28{
29
30//------------------------------------------------------------------------------
31// coordinate_matrix
32//------------------------------------------------------------------------------
33
62template <typename index_t>
64 requires (std::integral<index_t> || simd_index<index_t>)
67{
68private:
77 {
79 index_t column_index{};
80
87 auto operator()(index_t const row_index) noexcept
88 {
89 return matrix_index<index_t>{row_index_type{row_index}, column_index_type{column_index}};
90 }
91 };
92
94 template <typename simd_index_t>
96
98 using size_type = lazy_conditional_t<simd_concept<index_t>, lazy<lazy_scalar_type_t, index_t>, index_t>;
99
100 // The coordinate matrix iterator.
101 class iterator;
102
104 size_type column_count{};
106 size_type row_count{};
107
108public:
112 coordinate_matrix() = default;
117 ~coordinate_matrix() = default;
118
137 template <std::integral column_index_t, std::integral row_index_t>
139 row_index_type<row_index_t> const row_count) noexcept
140 {
141 this->column_count = column_count.get();
142 this->row_count = row_count.get();
143 }
145
150 iterator begin() const noexcept
151 {
152 return iterator{size_type{}, row_count};
153 }
154
156 iterator end() const noexcept
157 {
158 return iterator{column_count, row_count};
159 }
161};
162
163//------------------------------------------------------------------------------
164// iterator
165//------------------------------------------------------------------------------
166
176template <typename index_t>
178 requires (std::integral<index_t> || simd_index<index_t>)
181{
182private:
184 using iota_view_t = lazy_conditional_t<simd_index<index_t>,
186 decltype(std::views::iota(size_type{}, size_type{}))>;
188 index_t column_id{0};
190 size_type row_count{0};
191
192public:
197 using value_type = decltype(std::declval<iota_view_t>()
198 | std::views::transform(convert_to_matrix_coordinate{index_t{}/*column_id*/}));
202 using pointer = void;
208
212 iterator() = default;
213 iterator(iterator const &) = default;
214 iterator(iterator &&) = default;
215 iterator & operator=(iterator const &) = default;
216 iterator & operator=(iterator &&) = default;
217 ~iterator() = default;
218
225 explicit iterator(size_type column_id, size_type row_count) noexcept :
226 row_count{std::move(row_count)}
227 {
228 if constexpr (simd_index<index_t>)
229 this->column_id = simd::fill<index_t>(std::move(column_id));
230 else
231 this->column_id = std::move(column_id);
232 }
234
240 auto operator*() const
241 {
242 if constexpr (simd_index<index_t>)
243 {
244 return views::iota_simd<index_t>(size_type{}, row_count)
246 }
247 else
248 {
249 return std::views::iota(size_type{}, row_count)
251 }
252 }
254
261 {
262 // clang: pre-increment of a SIMD vector does not work
263 if constexpr (simd_index<index_t>)
264 column_id = column_id + simd::fill<index_t>(1);
265 else
266 ++column_id;
267
268 return *this;
269 }
270
273 {
274 iterator tmp{*this};
275 ++(*this);
276 return tmp;
277 }
279
285 friend bool operator==(iterator const & lhs, iterator const & rhs)
286 {
287 if constexpr (simd_index<index_t>)
288 return lhs.column_id[0] == rhs.column_id[0];
289 else
290 return lhs.column_id == rhs.column_id;
291 }
292
294 friend bool operator!=(iterator const & lhs, iterator const & rhs)
295 {
296 return !(lhs == rhs);
297 }
299};
300} // namespace seqan3::detail
Provides algorithms to modify seqan3::simd::simd_type.
Provides seqan3::aligned_allocator.
The iterator for the seqan3::detail::coordinate_matrix.
Definition: coordinate_matrix.hpp:181
friend bool operator!=(iterator const &lhs, iterator const &rhs)
Tests whether lhs != rhs.
Definition: coordinate_matrix.hpp:294
auto operator*() const
Access the pointed-to matrix coordinate column.
Definition: coordinate_matrix.hpp:240
lazy_conditional_t< simd_index< index_t >, lazy< iota_simd_view, index_t >, decltype(std::views::iota(size_type{}, size_type{}))> iota_view_t
The iota view type which depends on the index type.
Definition: coordinate_matrix.hpp:186
value_type reference
The reference type.
Definition: coordinate_matrix.hpp:200
iterator(iterator const &)=default
Defaulted.
iterator & operator=(iterator const &)=default
Defaulted.
decltype(std::declval< iota_view_t >()|std::views::transform(convert_to_matrix_coordinate{index_t{}})) value_type
The value type.
Definition: coordinate_matrix.hpp:198
iterator(iterator &&)=default
Defaulted.
index_t column_id
The currently represented column index.
Definition: coordinate_matrix.hpp:188
iterator(size_type column_id, size_type row_count) noexcept
Constructs and initialises the iterator with the current column index and the row index marking the e...
Definition: coordinate_matrix.hpp:225
iterator & operator++()
Increments the iterator to the next column.
Definition: coordinate_matrix.hpp:260
iterator & operator=(iterator &&)=default
Defaulted.
void pointer
The pointer type.
Definition: coordinate_matrix.hpp:202
iterator operator++(int)
Increments the iterator to the next column and returns the iterator pointing to the previous column.
Definition: coordinate_matrix.hpp:272
friend bool operator==(iterator const &lhs, iterator const &rhs)
Tests whether lhs == rhs.
Definition: coordinate_matrix.hpp:285
A matrix over coordinates.
Definition: coordinate_matrix.hpp:67
void resize(column_index_type< column_index_t > const column_count, row_index_type< row_index_t > const row_count) noexcept
Resets the coordinate matrix with the given end column index and end row index representing the new d...
Definition: coordinate_matrix.hpp:138
lazy_conditional_t< simd_concept< index_t >, lazy< lazy_scalar_type_t, index_t >, index_t > size_type
The internal size type which depends on index_t being a simd vector or a scalar type.
Definition: coordinate_matrix.hpp:98
coordinate_matrix(coordinate_matrix const &)=default
Defaulted.
iterator end() const noexcept
Returns the iterator pointing to the end column of the matrix.
Definition: coordinate_matrix.hpp:156
coordinate_matrix(coordinate_matrix &&)=default
Defaulted.
coordinate_matrix()=default
Defaulted.
~coordinate_matrix()=default
Defaulted.
coordinate_matrix & operator=(coordinate_matrix &&)=default
Defaulted.
typename simd_traits< simd_index_t >::scalar_type lazy_scalar_type_t
Type alias for the scalar type defined by the seqan3::simd::simd_traits type.
Definition: coordinate_matrix.hpp:95
coordinate_matrix & operator=(coordinate_matrix const &)=default
Defaulted.
iterator begin() const noexcept
Returns the iterator pointing to the first column of the matrix.
Definition: coordinate_matrix.hpp:150
The <concepts> header from C++20's standard library.
constexpr simd_t iota(typename simd_traits< simd_t >::scalar_type const offset)
Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2,...
Definition: algorithm.hpp:299
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: traits.hpp:495
Refines the seqan3::simd::simd_concept requiring the underlying scalar type to model std::integral.
Provides seqan3::detail::counted_simd_iterator and seqan3::views::iota_simd.
Provides lazy template instantiation traits.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The <ranges> header from C++20's standard library.
Provides seqan3::simd::simd_traits.
A strong type for designated initialisation of the column index of a matrix.
Definition: matrix_coordinate.hpp:34
A function object that converts a column index and a row index to a seqan3::detail::matrix_coordinate...
Definition: coordinate_matrix.hpp:77
auto operator()(index_t const row_index) noexcept
The conversion operator.
Definition: coordinate_matrix.hpp:87
An empty type whose only purpose is to hold an uninstantiated template plus its arguments.
Definition: lazy_conditional.hpp:33
A representation of a location or offset within a two-dimensional matrix.
Definition: matrix_coordinate.hpp:96
A strong type for designated initialisation of the row index of a matrix.
Definition: matrix_coordinate.hpp:65
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition: simd_traits.hpp:41
Provides type traits for working with templates.
Provides seqan3::simd::simd_concept.