SeqAn3 3.3.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// -----------------------------------------------------------------------------------------------------
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 <limits>
16#include <ranges>
17
24
25namespace seqan3::detail
26{
27
45{
46
63 template <typename score_t, typename coordinate_t>
64 requires (std::assignable_from<score_t &, score_t const &> &&
65 requires (coordinate_t coordinate)
66 {
67 requires simd_concept<decltype(coordinate.col)>;
68 requires simd_concept<decltype(coordinate.row)>;
69 })
70 void operator()(score_t & optimal_score,
71 coordinate_t const & optimal_coordinate,
72 score_t current_score,
73 coordinate_t const & current_coordinate) const noexcept
74 {
75 auto mask =
76 (optimal_coordinate.col == current_coordinate.col) && (optimal_coordinate.row == current_coordinate.row);
77 optimal_score = (mask) ? std::move(current_score) : optimal_score;
78 }
79};
80
85template <typename alignment_configuration_t, std::semiregular optimum_updater_t>
86 requires is_type_specialisation_of_v<alignment_configuration_t, configuration>
87 && std::invocable<
88 optimum_updater_t,
93class policy_optimum_tracker_simd : protected policy_optimum_tracker<alignment_configuration_t, optimum_updater_t>
94{
95protected:
98
99 // Import the configured score type.
100 using typename base_policy_t::score_type;
101 using typename base_policy_t::traits_type;
102
107
108 static_assert(simd_concept<score_type>, "Must be a simd type!");
109
110 // Import base variables into class scope.
116
126
135 policy_optimum_tracker_simd(alignment_configuration_t const & config) : base_policy_t{config}
136 {
139 }
141
144 {
146 }
147
194 template <std::ranges::input_range sequence1_collection_t, std::ranges::input_range sequence2_collection_t>
195 void initialise_tracker(sequence1_collection_t & sequence1_collection,
196 sequence2_collection_t & sequence2_collection)
197 {
198 using index_t = typename traits_type::matrix_index_type;
199 using scalar_index_t = typename simd_traits<index_t>::scalar_type;
200
201 scalar_index_t largest_sequence1_size{};
202 scalar_index_t largest_sequence2_size{};
203 alignas(alignof(index_t)) std::array<scalar_index_t, traits_type::alignments_per_vector> sequence1_sizes{};
204 alignas(alignof(index_t)) std::array<scalar_index_t, traits_type::alignments_per_vector> sequence2_sizes{};
205
206 // First, get all dimensions from the sequences and keep track of the maximal size in either dimension.
207 size_t sequence_count{};
208 for (auto && [sequence1, sequence2] : views::zip(sequence1_collection, sequence2_collection))
209 {
210 sequence1_sizes[sequence_count] = std::ranges::distance(sequence1);
211 sequence2_sizes[sequence_count] = std::ranges::distance(sequence2);
212 largest_sequence1_size = std::max(largest_sequence1_size, sequence1_sizes[sequence_count]);
213 largest_sequence2_size = std::max(largest_sequence2_size, sequence2_sizes[sequence_count]);
214 ++sequence_count;
215 }
216
217 // Second, determine the offset for each individual end-coordinate which is used to project the cell to the
218 // last row or column of the global alignment matrix. Choose the smallest distance as the correct offset
219 // to the projected cell.
220 for (size_t index = 0; index != sequence_count; ++index)
221 {
222 assert(sequence1_sizes[index] <= largest_sequence1_size);
223 assert(sequence2_sizes[index] <= largest_sequence2_size);
224
225 padding_offsets[index] = std::min(largest_sequence1_size - sequence1_sizes[index],
226 largest_sequence2_size - sequence2_sizes[index]);
227 sequence1_sizes[index] += padding_offsets[index];
228 sequence2_sizes[index] += padding_offsets[index];
229 }
230
231 // Load the target coordinate indices from the respective arrays.
232 optimal_coordinate.col = simd::load<index_t>(sequence1_sizes.data());
233 optimal_coordinate.row = simd::load<index_t>(sequence2_sizes.data());
234 }
235};
236} // 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:94
policy_optimum_tracker_simd(alignment_configuration_t const &config)
Construction and initialisation using the alignment configuration.
Definition: policy_optimum_tracker_simd.hpp:135
void reset_optimum()
Resets the optimum such that a new alignment can be computed.
Definition: policy_optimum_tracker_simd.hpp:143
typename simd::simd_traits< score_type >::scalar_type scalar_type
The scalar type of the simd vector.
Definition: policy_optimum_tracker_simd.hpp:104
typename traits_type::original_score_type original_score_type
The original non-simd score type.
Definition: policy_optimum_tracker_simd.hpp:106
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:115
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:199
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:201
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:195
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:189
bool test_last_row_cell
Whether cells of the last row shall be tracked.
Definition: policy_optimum_tracker.hpp:208
alignment_configuration_traits< alignment_configuration_t > traits_type
The configuration traits type.
Definition: policy_optimum_tracker.hpp:192
typename traits_type::score_type score_type
The configured score type.
Definition: policy_optimum_tracker.hpp:194
score_type optimal_score
The tracked score of the global optimum.
Definition: policy_optimum_tracker.hpp:199
optimum_updater_t compare_and_set_optimum
The function object to compare and exchange the optimum.
Definition: policy_optimum_tracker.hpp:203
matrix_coordinate_type optimal_coordinate
The matrix coordinate of the tracked optimum.
Definition: policy_optimum_tracker.hpp:201
bool test_last_column_cell
Whether cells of the last column shall be tracked.
Definition: policy_optimum_tracker.hpp:210
Implementation of a masked alphabet to be used for tuple composites..
Definition: mask.hpp:38
constexpr auto zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition: zip.hpp:573
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:29
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:136
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:143
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:146
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:134
Function object that compares and updates the alignment optimum for the vectorised global alignment a...
Definition: policy_optimum_tracker_simd.hpp:45
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition: simd_traits.hpp:41
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:45
Provides seqan3::views::zip.