SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
policy_optimum_tracker_simd.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <limits>
13#include <ranges>
14
21
22namespace seqan3::detail
23{
24
42{
43
60 template <typename score_t, typename coordinate_t>
61 requires (std::assignable_from<score_t &, score_t const &> &&
62 requires (coordinate_t coordinate)
63 {
64 requires simd_concept<decltype(coordinate.col)>;
65 requires simd_concept<decltype(coordinate.row)>;
66 })
67 void operator()(score_t & optimal_score,
68 coordinate_t const & optimal_coordinate,
69 score_t current_score,
70 coordinate_t const & current_coordinate) const noexcept
71 {
72 auto mask =
73 (optimal_coordinate.col == current_coordinate.col) && (optimal_coordinate.row == current_coordinate.row);
74 optimal_score = (mask) ? std::move(current_score) : optimal_score;
75 }
76};
77
82template <typename alignment_configuration_t, std::semiregular optimum_updater_t>
83 requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
84 && std::invocable<
85 optimum_updater_t,
90class policy_optimum_tracker_simd : protected policy_optimum_tracker<alignment_configuration_t, optimum_updater_t>
91{
92protected:
95
96 // Import the configured score type.
97 using typename base_policy_t::score_type;
98 using typename base_policy_t::traits_type;
99
104
105 static_assert(simd_concept<score_type>, "Must be a simd type!");
106
107 // Import base variables into class scope.
113
123
132 policy_optimum_tracker_simd(alignment_configuration_t const & config) : base_policy_t{config}
133 {
136 }
138
141 {
143 }
144
191 template <std::ranges::input_range sequence1_collection_t, std::ranges::input_range sequence2_collection_t>
192 void initialise_tracker(sequence1_collection_t & sequence1_collection,
193 sequence2_collection_t & sequence2_collection)
194 {
195 using index_t = typename traits_type::matrix_index_type;
196 using scalar_index_t = typename simd_traits<index_t>::scalar_type;
197
198 scalar_index_t largest_sequence1_size{};
199 scalar_index_t largest_sequence2_size{};
200 alignas(alignof(index_t)) std::array<scalar_index_t, traits_type::alignments_per_vector> sequence1_sizes{};
201 alignas(alignof(index_t)) std::array<scalar_index_t, traits_type::alignments_per_vector> sequence2_sizes{};
202
203 // First, get all dimensions from the sequences and keep track of the maximal size in either dimension.
204 size_t sequence_count{};
205 for (auto && [sequence1, sequence2] : views::zip(sequence1_collection, sequence2_collection))
206 {
207 sequence1_sizes[sequence_count] = std::ranges::distance(sequence1);
208 sequence2_sizes[sequence_count] = std::ranges::distance(sequence2);
209 largest_sequence1_size = std::max(largest_sequence1_size, sequence1_sizes[sequence_count]);
210 largest_sequence2_size = std::max(largest_sequence2_size, sequence2_sizes[sequence_count]);
211 ++sequence_count;
212 }
213
214 // Second, determine the offset for each individual end-coordinate which is used to project the cell to the
215 // last row or column of the global alignment matrix. Choose the smallest distance as the correct offset
216 // to the projected cell.
217 for (size_t index = 0; index != sequence_count; ++index)
218 {
219 assert(sequence1_sizes[index] <= largest_sequence1_size);
220 assert(sequence2_sizes[index] <= largest_sequence2_size);
221
222 padding_offsets[index] = std::min(largest_sequence1_size - sequence1_sizes[index],
223 largest_sequence2_size - sequence2_sizes[index]);
224 sequence1_sizes[index] += padding_offsets[index];
225 sequence2_sizes[index] += padding_offsets[index];
226 }
227
228 // Load the target coordinate indices from the respective arrays.
229 optimal_coordinate.col = simd::load<index_t>(sequence1_sizes.data());
230 optimal_coordinate.row = simd::load<index_t>(sequence2_sizes.data());
231 }
232};
233} // namespace seqan3::detail
Provides algorithms to modify seqan3::simd::simd_type.
Implements the tracker to store the global optimum for a particular alignment computation.
Definition policy_optimum_tracker_simd.hpp:91
policy_optimum_tracker_simd(alignment_configuration_t const &config)
Construction and initialisation using the alignment configuration.
Definition policy_optimum_tracker_simd.hpp:132
void reset_optimum()
Resets the optimum such that a new alignment can be computed.
Definition policy_optimum_tracker_simd.hpp:140
typename simd::simd_traits< score_type >::scalar_type scalar_type
The scalar type of the simd vector.
Definition policy_optimum_tracker_simd.hpp:101
typename traits_type::original_score_type original_score_type
The original non-simd score type.
Definition policy_optimum_tracker_simd.hpp:103
policy_optimum_tracker_simd & operator=(policy_optimum_tracker_simd &&)=default
Defaulted.
std::array< original_score_type, simd_traits< score_type >::length > padding_offsets
The individual offsets used for padding the sequences.
Definition policy_optimum_tracker_simd.hpp:112
policy_optimum_tracker_simd(policy_optimum_tracker_simd const &)=default
Defaulted.
score_type optimal_score
The tracked score of the global optimum.
Definition policy_optimum_tracker.hpp:196
policy_optimum_tracker_simd & operator=(policy_optimum_tracker_simd const &)=default
Defaulted.
matrix_coordinate_type optimal_coordinate
The matrix coordinate of the tracked optimum.
Definition policy_optimum_tracker.hpp:198
void initialise_tracker(sequence1_collection_t &sequence1_collection, sequence2_collection_t &sequence2_collection)
Initialises the tracker and possibly the binary update operation.
Definition policy_optimum_tracker_simd.hpp:192
policy_optimum_tracker_simd(policy_optimum_tracker_simd &&)=default
Defaulted.
Implements the tracker to store the global optimum for a particular alignment computation.
Definition policy_optimum_tracker.hpp:186
bool test_last_row_cell
Whether cells of the last row shall be tracked.
Definition policy_optimum_tracker.hpp:205
alignment_configuration_traits< alignment_configuration_t > traits_type
The configuration traits type.
Definition policy_optimum_tracker.hpp:189
typename traits_type::score_type score_type
The configured score type.
Definition policy_optimum_tracker.hpp:191
score_type optimal_score
The tracked score of the global optimum.
Definition policy_optimum_tracker.hpp:196
optimum_updater_t compare_and_set_optimum
The function object to compare and exchange the optimum.
Definition policy_optimum_tracker.hpp:200
matrix_coordinate_type optimal_coordinate
The matrix coordinate of the tracked optimum.
Definition policy_optimum_tracker.hpp:198
bool test_last_column_cell
Whether cells of the last column shall be tracked.
Definition policy_optimum_tracker.hpp:207
Implementation of a masked alphabet to be used for tuple composites.
Definition mask.hpp:35
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
The generic simd concept.
Provides lazy template instantiation traits.
T max(T... args)
T min(T... args)
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
Provides seqan3::detail::policy_optimum_tracker.
Provides seqan3::simd::simd_type.
Provides seqan3::simd::simd_traits.
std::conditional_t< is_vectorised, simd_type_t< original_score_type >, original_score_type > score_type
The score type for the alignment algorithm.
Definition alignment/pairwise/detail/type_traits.hpp:133
std::conditional_t< is_vectorised, simd_type_t< select_scalar_index_t< original_score_type > >, size_t > matrix_index_type
The type of the matrix index.
Definition alignment/pairwise/detail/type_traits.hpp:140
lazy_conditional_t< is_vectorised, lazy< simd_matrix_coordinate, matrix_index_type >, matrix_coordinate > matrix_coordinate_type
The type of the matrix coordinate.
Definition alignment/pairwise/detail/type_traits.hpp:143
typename std::remove_reference_t< decltype(std::declval< configuration_t >().get_or(align_cfg::score_type< int32_t >{}))>::type original_score_type
The original score type selected by the user.
Definition alignment/pairwise/detail/type_traits.hpp:131
Function object that compares and updates the alignment optimum for the vectorised global alignment a...
Definition policy_optimum_tracker_simd.hpp:42
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38
IMPLEMENTATION_DEFINED scalar_type
The underlying type of a simd vector (is not defined if simd_t does not model seqan3::simd::simd)
Definition simd_traits.hpp:42
Provides seqan3::views::zip.
Hide me