Skip to content

Commit

Permalink
Merge pull request #1237 from rrahn/misc/refactor_aligned_sequence_bu…
Browse files Browse the repository at this point in the history
…ilder

Misc/refactor aligned sequence builder
  • Loading branch information
rrahn authored Oct 8, 2019
2 parents ebd0790 + 5205342 commit f11bd64
Show file tree
Hide file tree
Showing 17 changed files with 920 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ inline void assign_unaligned(aligned_seq_t & aligned_seq, unaligned_sequence_typ
using std::swap;
aligned_seq_t tmp;
tmp.resize(std::ranges::distance(unaligned_seq));
std::copy(std::ranges::begin(unaligned_seq), std::ranges::end(unaligned_seq), std::ranges::begin(tmp));
std::ranges::copy(unaligned_seq, std::ranges::begin(tmp));
swap(aligned_seq, tmp);
}
//!\}
Expand Down
214 changes: 86 additions & 128 deletions include/seqan3/alignment/matrix/detail/aligned_sequence_builder.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class alignment_trace_matrix_full_banded :
if (trace_begin.row >= static_cast<size_t>(band_size) || trace_begin.col >= matrix_base_t::num_cols)
throw std::invalid_argument{"The given coordinate exceeds the trace matrix size."};

return path_t{trace_iterator_t{matrix_base_t::data.begin() + matrix_offset{trace_begin}},
return path_t{trace_iterator_t{matrix_base_t::data.begin() + matrix_offset{trace_begin},
column_index_type{band_col_index}},
std::ranges::default_sentinel};
}

Expand Down
7 changes: 7 additions & 0 deletions include/seqan3/alignment/matrix/detail/matrix_coordinate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ struct matrix_index
{}
//!\}

//!\brief Explicit conversion to the a std::pair.
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{}; //!< The row index.
index_t col{}; //!< The column index.
};
Expand Down
8 changes: 0 additions & 8 deletions include/seqan3/alignment/matrix/detail/trace_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,4 @@ class trace_iterator : public trace_iterator_base<trace_iterator<matrix_iter_t>,
//!\}
};

/*!\name Type deduction guides
* \{
*/
//!\brief Deduces the template argument from the passed iterator.
template <two_dimensional_matrix_iterator matrix_iter_t>
trace_iterator(matrix_iter_t const) -> trace_iterator<matrix_iter_t>;
//!\}

} // namespace seqan3::detail
26 changes: 17 additions & 9 deletions include/seqan3/alignment/matrix/detail/trace_iterator_banded.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ class trace_iterator_banded : public trace_iterator_base<trace_iterator_banded<m

/*!\brief Constructs from the underlying trace matrix iterator indicating the start of the trace path.
* \param[in] matrix_iter The underlying matrix iterator.
* \param[in] pivot_column The last column index which is still inside of the band in the first row of the
* banded matrix.
*/
constexpr trace_iterator_banded(matrix_iter_t const matrix_iter) noexcept : base_t{matrix_iter}
template <typename index_t>
constexpr trace_iterator_banded(matrix_iter_t const matrix_iter, column_index_type<index_t> const & pivot_column)
noexcept :
base_t{matrix_iter},
pivot_column{static_cast<size_t>(pivot_column.get())}
{}

/*!\brief Constructs from the underlying trace matrix iterator indicating the start of the trace path.
Expand All @@ -75,6 +81,14 @@ class trace_iterator_banded : public trace_iterator_base<trace_iterator_banded<m
{}
//!\}

//!\copydoc seqan3::detail::trace_iterator_base::coordinate()
[[nodiscard]] constexpr matrix_coordinate coordinate() const noexcept
{
auto coord = base_t::coordinate();
coord.row += static_cast<int32_t>(coord.col - pivot_column);
return coord;
}

private:
//!\copydoc seqan3::detail::trace_iterator_base::go_left
constexpr void go_left(matrix_iter_t & iter) const noexcept
Expand All @@ -91,14 +105,8 @@ class trace_iterator_banded : public trace_iterator_base<trace_iterator_banded<m
// So going diagonal means go to the previous column and stay in the same row.
iter -= matrix_offset{row_index_type{0}, column_index_type{1}};
}
};

/*!\name Type deduction guides
* \{
*/
//!\brief Deduces the template argument from the passed iterator.
template <two_dimensional_matrix_iterator matrix_iter_t>
trace_iterator_banded(matrix_iter_t const) -> trace_iterator_banded<matrix_iter_t>;
//!\}
size_t pivot_column{}; //!< The largest column index which is inside of the band in the first row of the matrix.
};

} // namespace seqan3::detail
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class trace_iterator_base
}

//!\brief Returns the current coordinate in two-dimensional space.
constexpr matrix_coordinate coordinate() const noexcept
[[nodiscard]] constexpr matrix_coordinate coordinate() const noexcept
{
return matrix_iter.coordinate();
}
Expand Down
43 changes: 41 additions & 2 deletions include/seqan3/core/type_traits/lazy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct instantiate<lazy<template_t, spec_t...>>

/*!\brief A transformation trait that instantiates seqan3::lazy types. Transformation trait shortcut.
* \tparam t The type to operate on.
* \relates seqan3::instantiate
* \relates seqan3::detail::instantiate
*/
template <typename t>
//!\cond
Expand Down Expand Up @@ -95,13 +95,52 @@ struct lazy_conditional : instantiate<std::conditional_t<decision, on_true_t, on
* \tparam decision Whether to resolve to the first type or the second.
* \tparam on_true_t The return type in case `decision` is true.
* \tparam on_false_t The return type in case `decision` is false.
* \relates seqan3::lazy_conditional
* \relates seqan3::detail::lazy_conditional
*/
template <bool decision, typename on_true_t, typename on_false_t>
//!\cond
requires requires { typename instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>; }
//!\endcond
using lazy_conditional_t = instantiate_t<std::conditional_t<decision, on_true_t, on_false_t>>;

/*!\brief An unary type trait that tests whether a template class can be declared with the given template type
* parameters.
* \implements seqan3::unary_type_trait
* \tparam query_t The type of the template class to test.
* \tparam args_t The template parameter pack to instantiate the template class with.
*
* \details
*
* Note, this unary type trait can be used in a seqan3::detail::lazy_conditional expression to check if instantiating
* a template class with specific template arguments would result in a valid template declaration. Thus, the template
* parameters of the checked class must be constrained accordingly. It is, however, not possible to test if the
* the resulting type is incomplete or not, such that it can not be tested if an instance of the class template with
* the given template arguments can be actually created.
*
* ### Example
*
* \include test/snippet/core/type_traits/is_class_template_declarable_with.cpp
*/
template <template <typename ...> typename query_t, typename ...args_t>
struct is_class_template_declarable_with :
//!\cond
public std::false_type
//!\endcond
{};

//!\cond
template <template <typename ...> typename query_t, typename ...args_t>
requires requires { typename std::type_identity<query_t<args_t...>>::type; }
struct is_class_template_declarable_with<query_t, args_t...> : public std::true_type
{};
//!\endcond

/*!\brief Helper variable template for seqan3::detail::is_class_template_declarable_with.
* \tparam query_t The type of the template class to test.
* \tparam args_t The template parameter pack to instantiate the template class with.
* \relates seqan3::detail::is_class_template_declarable_with
*/
template <template <typename ...> typename query_t, typename ...args_t>
inline constexpr bool is_class_template_declarable_with_v = is_class_template_declarable_with<query_t, args_t...>::value;
//!\}
} // namespace seqan3::detail
4 changes: 2 additions & 2 deletions include/seqan3/range/concept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ SEQAN3_CONCEPT const_iterable_range =
std::ranges::input_range<type const> &&
(std::ranges::forward_range<std::remove_const_t<type>> == std::ranges::forward_range<type const>) &&
(std::ranges::bidirectional_range<std::remove_const_t<type>> == std::ranges::bidirectional_range<type const>) &&
(std::ranges::random_access_range<std::remove_const_t<type>> == std::ranges::random_access_range<type const>);
(std::ranges::random_access_range<std::remove_const_t<type>> == std::ranges::random_access_range<type const>);
//!\endcond

/*!\interface seqan3::forwarding_range<>
* \extends std::Range
* \extends std::ranges::range
* \brief Specifies a range whose iterators may outlive the range and remain valid.
* \see https://eel.is/c++draft/range.req
*/
Expand Down
Loading

0 comments on commit f11bd64

Please sign in to comment.