SeqAn3  3.0.3
The Modern C++ library for sequence analysis.

The simd module contains a unified interface to provide simd types and functions used in seqan3. More...

+ Collaboration diagram for Simd:

Classes

struct  seqan3::detail::builtin_simd< scalar_t, length >
 A class that holds the type of a simd implementation called vector extension (formerly known as "seqan simd" in seqan2). More...
 
struct  seqan3::detail::builtin_simd< scalar_t, length >
 A class that holds the type of a simd implementation called vector extension (formerly known as "seqan simd" in seqan2). More...
 
struct  seqan3::detail::builtin_simd_traits_helper< builtin_simd_t >
 Helper struct for seqan3::detail::is_builtin_simd. More...
 
struct  seqan3::detail::builtin_simd_traits_helper< builtin_simd_t >
 Helper struct for seqan3::detail::is_builtin_simd. More...
 
class  seqan3::detail::counted_simd_iterator< index_simd_t >
 Implements a special version of a counted iterator over a simd vector. More...
 
class  seqan3::detail::iota_simd_view< index_simd_t >
 The simd iota view. More...
 
struct  seqan3::detail::iota_simd_view_fn< index_simd_t >
 The view adaptor returning the seqan3::detail::iota_simd_view. More...
 
struct  seqan3::detail::is_builtin_simd< builtin_simd_t >
 This class inherits from std::true_type, iff seqan3::detail::builtin_simd<scalar_t, length>::type is a builtin simd type. More...
 
struct  seqan3::detail::is_native_builtin_simd< builtin_simd_t >
 This class inherits from std::true_type, iff the builtin simd type is supported by the current architecture. More...
 
interface  simd_concept
 The generic simd concept. More...
 
struct  seqan3::simd::simd_traits< simd_t >
 seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of simd_t types. More...
 
struct  seqan3::simd::simd_traits< builtin_simd_t >
 This class specializes seqan3::simd::simd_traits for seqan3::detail::builtin_simd types. More...
 
struct  seqan3::simd::simd_type< scalar_t, length, simd_backend >
 seqan3::simd::simd_type encapsulates simd vector types, which can be manipulated by simd operations. More...
 
struct  seqan3::detail::to_simd_fn< simd_t >
 views::to_simd's range adaptor closure object type. More...
 
class  seqan3::detail::view_to_simd< urng_t, simd_t >
 Transforms a range of ranges into chunks of seqan3::simd vectors. More...
 

Typedefs

template<typename scalar_t , size_t length>
using seqan3::detail::default_simd_backend = builtin_simd< scalar_t, length >
 seqan3::detail::default_simd_backend is the default used implementation of seqan3::simd::simd_type. More...
 
template<typename scalar_t , size_t length = detail::default_simd_length<scalar_t, detail::default_simd_backend>, template< typename scalar_t_, size_t length_ > typename simd_backend = detail::default_simd_backend>
using seqan3::simd::simd_type_t = typename simd_type< scalar_t, length, simd_backend >::type
 Helper type of seqan3::simd::simd_type.
 

Functions

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_eighth (simd_t const &src)
 Extracts one eighth of the given simd vector and stores it in the lower eighth of the target vector. More...
 
template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_half (simd_t const &src)
 Extracts one half of the given simd vector and stores the result in the lower half of the target vector. More...
 
template<size_t divisor, simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_impl (simd_t const &src, uint8_t const mask)
 Helper function to extract a part of the given simd vector. More...
 
template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_quarter (simd_t const &src)
 Extracts one quarter of the given simd vector and stores it in the lower quarter of the target vector. More...
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::fill (typename simd_traits< simd_t >::scalar_type const scalar) noexcept
 Fills a seqan3::simd::simd_type vector with a scalar value. More...
 
template<simd::simd_concept simd_t, size_t... I>
constexpr simd_t seqan3::detail::fill_impl (typename simd_traits< simd_t >::scalar_type const scalar, std::index_sequence< I... >) noexcept
 Helper function for seqan3::simd::fill.
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::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, ... More...
 
template<simd::simd_concept simd_t, typename scalar_t , scalar_t... I>
constexpr simd_t seqan3::detail::iota_impl (scalar_t const offset, std::integer_sequence< scalar_t, I... >)
 Helper function for seqan3::simd::iota.
 
template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::load (void const *mem_addr)
 Load simd_t size bits of integral data from memory. More...
 
template<typename char_t , typename simd_t >
debug_stream_type< char_t > & seqan3::operator<< (debug_stream_type< char_t > &s, simd_t &&simd)
 Overload for debug_stream for simd types. More...
 
template<simd::simd_concept simd_t>
constexpr void seqan3::simd::store (void *mem_addr, simd_t const &simd_vec)
 Store simd_t size bits of integral data into memory. More...
 
template<simd::simd_concept simd_t>
constexpr void seqan3::simd::transpose (std::array< simd_t, simd_traits< simd_t >::length > &matrix)
 Transposes the given simd vector matrix. More...
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::simd::upcast (source_simd_t const &src)
 Upcasts the given vector into the target vector using sign extension of packed values. More...
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_signed (source_simd_t const &src)
 Upcasts the given vector into the target vector using signed extension of packed values. More...
 
template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_unsigned (source_simd_t const &src)
 Upcasts the given vector into the target vector using unsigned extension of packed values. More...
 

Variables

template<typename scalar_t , template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_length
 seqan3::detail::default_simd_length returns the default length depending on the given scalar_t type, which is used in seqan3::simd::simd_type. More...
 
template<template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_max_length = 0u
 seqan3 auto-detects the maximum number of packable [u]int8_t types. More...
 
template<>
constexpr auto seqan3::detail::default_simd_max_length< builtin_simd >
 This function specializes seqan3::detail::default_simd_max_length for seqan3::detail::builtin_simd. More...
 
template<simd_concept index_simd_t>
constexpr detail::iota_simd_view_fn< index_simd_t > seqan3::views::iota_simd
 An iota view over a simd vector. More...
 
template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_builtin_simd_v = is_builtin_simd<builtin_simd_t>::value
 Helper variable to test whether a type is a simd builtin type. More...
 
template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_native_builtin_simd_v = is_native_builtin_simd<builtin_simd_t>::value
 Helper variable to test whether a type is a native simd builtin type. More...
 
template<simd::simd_concept simd_t>
constexpr auto seqan3::views::to_simd
 A view that transforms a range of ranges into chunks of seqan3::simd vectors. More...
 

Detailed Description

The simd module contains a unified interface to provide simd types and functions used in seqan3.

See also
https://en.wikipedia.org/wiki/SIMD
Todo:
Make this public again. We made this documentation internal-documentation only for the 3.0.0 release, because the API was not in shape yet. Remove the cond DEV and todo commands and remove seqan3::simd from SEQAN3_DOXYGEN_EXCLUDE_SYMBOLS in seqan3-doxygen.cmake.

There are different simd implementations (backends), which are auto-selected by seqan3::simd::simd_type_t. Namely seqan3::detail::builtin_simd.

Todo:
Describe more what SIMD is and how to use it.

Typedef Documentation

◆ default_simd_backend

template<typename scalar_t , size_t length>
using seqan3::detail::default_simd_backend = typedef builtin_simd<scalar_t, length>

seqan3::detail::default_simd_backend is the default used implementation of seqan3::simd::simd_type.

Template Parameters
scalar_tThe underlying type of a simd vector
lengthThe number of packed values in a simd vector

Function Documentation

◆ extract_eighth()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_eighth ( simd_t const &  src)
constexpr

Extracts one eighth of the given simd vector and stores it in the lower eighth of the target vector.

Template Parameters
indexAn index value in the range of [0, 1, 2, 3, 4, 5, 6, 7].
simd_tThe simd type.
Parameters
srcThe source to extract the eighth from.
Returns
A simd vector with the lower bits set with the respective eighth from src If the simd vector contains less than 8 elements, the unchanged source will be returned.

Only the first simd length / 8 elements are defined. The value of the remaining elements is implementation defined.

int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}
Provides seqan3::debug_stream and related types.
typename simd_type< scalar_t, length, simd_backend >::type simd_type_t
Helper type of seqan3::simd::simd_type.
Definition: simd.hpp:59
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:42
Meta-header for the simd module.

Example operation for SSE4:

i := index * 16
dst[15:0] := src[i+15:i]

◆ extract_half()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_half ( simd_t const &  src)
constexpr

Extracts one half of the given simd vector and stores the result in the lower half of the target vector.

Template Parameters
indexAn index value in the range of [0, 1].
simd_tThe simd type.
Parameters
srcThe source to extract the half from.
Returns
A simd vector with the lower bits set with the respective half from src If the simd vector contains less than 2 elements, the unchanged source will be returned.

Only the first simd length / 2 elements are defined. The value of the remaining elements is implementation defined.

int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}

Example operation for SSE4:

i := index * 64
dst[63:0] := src[i+63:i]

◆ extract_impl()

template<size_t divisor, simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_impl ( simd_t const &  src,
uint8_t const  mask 
)
constexpr

Helper function to extract a part of the given simd vector.

Template Parameters
divisorThe divisor to select the chunk size.
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]srcThe source vector to extract from.
[in]maskThe control mask to select which chunk is extracted.
Returns
The destination vector containing the extracted part.

Extracts the specified part of the source simd vector and stores it in the first chunk starting at offset 0 in the destination vector.

◆ extract_quarter()

template<uint8_t index, simd::simd_concept simd_t>
constexpr simd_t seqan3::detail::extract_quarter ( simd_t const &  src)
constexpr

Extracts one quarter of the given simd vector and stores it in the lower quarter of the target vector.

Template Parameters
indexAn index value in the range of [0, 1, 2, 3].
simd_tThe simd type.
Parameters
srcThe source to extract the quarter from.
Returns
A simd vector with the lower bits set with the respective quarter from src. If the simd vector contains less than 4 elements, the unchanged source will be returned.

Only the first simd length / 4 elements are defined. The value of the remaining elements is implementation defined.

int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int16x8_t b = seqan3::detail::extract_half<1>(a);
int16x8_t c = seqan3::detail::extract_quarter<1>(a);
int16x8_t d = seqan3::detail::extract_eighth<7>(a);
seqan3::debug_stream << b << '\n'; // [4,-5,6,-7,0,0,0,0]
seqan3::debug_stream << c << '\n'; // [2,-3,0,0,0,0,0,0]
seqan3::debug_stream << d << '\n'; // [-7,0,0,0,0,0,0,0]
return 0;
}

Example operation for SSE4:

i := index * 32
dst[31:0] := src[i+31:i]

◆ fill()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::fill ( typename simd_traits< simd_t >::scalar_type const  scalar)
constexprnoexcept

Fills a seqan3::simd::simd_type vector with a scalar value.

Template Parameters
simd_tThe simd type which satisfies seqan3::simd::simd_concept.
Parameters
[in]scalarThe scalar value to fill the seqan3::simd::simd_type vector.
int main()
{
uint16x8_t a = seqan3::fill<uint16x8_t>(4);
seqan3::debug_stream << a << "\n"; // [4,4,4,4,4,4,4,4]
// or:
uint16x8_t b = seqan3::simd::fill<uint16x8_t>(4);
seqan3::debug_stream << b << "\n"; // [4,4,4,4,4,4,4,4]
return 0;
}

◆ iota()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::iota ( typename simd_traits< simd_t >::scalar_type const  offset)
constexpr

Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2, ...

Template Parameters
simd_tThe simd type which satisfies seqan3::simd::simd_concept.
Parameters
[in]offsetThe scalar offset to fill the seqan3::simd::simd_type vector.
int main()
{
uint16x8_t a = seqan3::iota<uint16x8_t>(1);
seqan3::debug_stream << a << "\n"; // [1,2,3,4,5,6,7,8]
// or:
uint16x8_t b = seqan3::simd::iota<uint16x8_t>(1);
seqan3::debug_stream << b << "\n"; // [1,2,3,4,5,6,7,8]
return 0;
}

◆ load()

template<simd::simd_concept simd_t>
constexpr simd_t seqan3::simd::load ( void const *  mem_addr)
constexpr

Load simd_t size bits of integral data from memory.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]mem_addrThe memory address to load from. Does not need to be aligned on any particular boundary.
int main()
{
std::vector<uint16_t> memory{0, 1, 2, 3, 4, 5, 6, 7};
uint16x8_t a = seqan3::simd::load<uint16x8_t>(memory.data());
seqan3::debug_stream << a << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}

◆ operator<<()

template<typename char_t , typename simd_t >
debug_stream_type<char_t>& seqan3::operator<< ( debug_stream_type< char_t > &  s,
simd_t &&  simd 
)
inlineprivate

Overload for debug_stream for simd types.

Todo:
Make this public again. We made this documentation internal-documentation only for the 3.0.0 release, because the API was not in shape yet. Remove the private and todo commands and remove seqan3::simd from SEQAN3_DOXYGEN_EXCLUDE_SYMBOLS in seqan3-doxygen.cmake.

◆ store()

template<simd::simd_concept simd_t>
constexpr void seqan3::simd::store ( void *  mem_addr,
simd_t const &  simd_vec 
)
constexpr

Store simd_t size bits of integral data into memory.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept.
Parameters
[in]mem_addrThe memory address to write to. Does not need to be aligned on any particular boundary.
[in]simd_vecThe simd vector to read the data from.
int main()
{
uint16x8_t a = seqan3::simd::iota<uint16x8_t>(0);
seqan3::simd::store(memory.data(), a);
seqan3::debug_stream << memory << '\n'; // [0,1,2,3,4,5,6,7]
return 0;
}
constexpr void store(void *mem_addr, simd_t const &simd_vec)
Store simd_t size bits of integral data into memory.
Definition: algorithm.hpp:358
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition: simd_traits.hpp:41

◆ transpose()

template<simd::simd_concept simd_t>
constexpr void seqan3::simd::transpose ( std::array< simd_t, simd_traits< simd_t >::length > &  matrix)
constexpr

Transposes the given simd vector matrix.

Template Parameters
simd_tThe simd vector type; must model seqan3::simd::simd_concept and must be a simd built-in type.
Parameters
[in,out]matrixThe matrix that is transposed in place.
#include <array>
int main()
{
std::array<uint8x4_t, 4> matrix{{uint8x4_t{0, 1, 2, 3},
uint8x4_t{0, 1, 2, 3},
uint8x4_t{0, 1, 2, 3},
uint8x4_t{0, 1, 2, 3}}};
seqan3::debug_stream << matrix[0] << '\n'; // [0,0,0,0]
seqan3::debug_stream << matrix[1] << '\n'; // [1,1,1,1]
seqan3::debug_stream << matrix[2] << '\n'; // [2,2,2,2]
seqan3::debug_stream << matrix[3] << '\n'; // [3,3,3,3]
return 0;
}
constexpr void transpose(std::array< simd_t, simd_traits< simd_t >::length > &matrix)
Transposes the given simd vector matrix.
Definition: algorithm.hpp:405
Defines the requirements of a matrix (e.g. score matrices, trace matrices).

Exception

Strong exception guarantee.

Complexity

Quadratic.

◆ upcast()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::simd::upcast ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using sign extension of packed values.

Template Parameters
simd_tThe simd type; must model seqan3::simd::simd_concept and must be a builtin simd type.
int main()
{
int16x8_t a{0, -1, 2, -3, 4, -5, 6, -7};
int32x4_t b = seqan3::simd::upcast<int32x4_t>(a);
seqan3::debug_stream << b << '\n'; // [0,-1,2,-3]
return 0;
}

◆ upcast_signed()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_signed ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using signed extension of packed values.

Template Parameters
target_simd_tThe target simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
source_simd_tThe source simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
Parameters
[in]srcThe source to upcast into target_simd_t.

◆ upcast_unsigned()

template<simd::simd_concept target_simd_t, simd::simd_concept source_simd_t>
constexpr target_simd_t seqan3::detail::upcast_unsigned ( source_simd_t const &  src)
constexpr

Upcasts the given vector into the target vector using unsigned extension of packed values.

Template Parameters
target_simd_tThe target simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
source_simd_tThe source simd type; must model seqan3::simd::simd_concept and must be a native builtin simd type.
Parameters
[in]srcThe source to upcast into target_simd_t.

Variable Documentation

◆ default_simd_length

template<typename scalar_t , template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_length
constexpr
Initial value:
= []
{
constexpr auto max_length = default_simd_max_length<simd_backend_t>;
if constexpr (max_length == 0)
return min_viable_uint_v<1u>;
else
return min_viable_uint_v<max_length / sizeof(scalar_t)>;
}()
constexpr auto min_viable_uint_v
Given a value, cast the value as the smallest unsigned integer that can hold it.
Definition: integer_traits.hpp:37

seqan3::detail::default_simd_length returns the default length depending on the given scalar_t type, which is used in seqan3::simd::simd_type.

Template Parameters
scalar_tThe underlying type of a simd vector
simd_backend_tThe name of the simd backend.

◆ default_simd_max_length

template<template< typename, size_t > typename simd_backend_t>
constexpr auto seqan3::detail::default_simd_max_length = 0u
constexpr

seqan3 auto-detects the maximum number of packable [u]int8_t types.

Template Parameters
simd_backend_tThe name of the simd backend.
int main()
{
constexpr auto max_length = seqan3::detail::default_simd_max_length<seqan3::detail::default_simd_backend>;
uint8_simd_t a = seqan3::fill<uint8_simd_t>(4);
uint8_simd_t b = seqan3::fill<uint8_simd_t>(5);
uint8_simd_t c = a + b;
seqan3::debug_stream << c << "\n"; // [9,9,9,9,9,9,9,9]
return 0;
}

This value is influenced by compiler flags like -march=native, -msse4, -mavx2, etc and sets this value accordingly.

See also
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#x86-Options for simd instruction sets and their flags.

◆ default_simd_max_length< builtin_simd >

template<>
constexpr auto seqan3::detail::default_simd_max_length< builtin_simd >
constexpr
Initial value:
= []()
{
return min_viable_uint_v<0u>;
}()

This function specializes seqan3::detail::default_simd_max_length for seqan3::detail::builtin_simd.

The redefinition of default_simd_max_length influences the default length (i.e., seqan3::detail::default_simd_length) of seqan3::simd::simd_type for seqan3::detail::builtin_simd types.

◆ iota_simd

template<simd_concept index_simd_t>
constexpr detail::iota_simd_view_fn<index_simd_t> seqan3::views::iota_simd
inlineconstexpr

An iota view over a simd vector.

Template Parameters
index_simd_tThe represented index type; must model seqan3::simd::simd_concept.

This view is an equivalent implementation to:

// The simd type with 8 unsigned shorts.
int main()
{
// Generate ascending simd index using a iota view in combination with a transfor view.
auto simd_iota_view = std::views::iota(0, 10)
| std::views::transform([] (uint16_t const idx)
{
return seqan3::simd::fill<uint16x8_t>(idx);
});
for (auto && simd_id : simd_iota_view)
seqan3::debug_stream << simd_id << '\n'; // [0, 0, ..., 0], [1, 1, ..., 1], ... [9, 9, ..., 9]
return 0;
}
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:434
Adaptations of concepts from the Ranges TS.

However, benchmarks showed that increasing a simd vector is faster than constructing it every time (up-to 2x speed-up). This speed-up justifies an own class that does this task more efficiently.

This view is a lightweight wrapper around a seqan3::detail::counted_simd_iterator pair. Note the regular std::views::iota view cannot be used with two simd types:

std::views::iota(simd_begin, simd_end);

because the return type of the comparison of two simd vector types is not convertible to bool.

View properties

Concepts and traits rrng_t (returned range type)
std::ranges::input_range guaranteed
std::ranges::forward_range guaranteed
std::ranges::bidirectional_range lost
std::ranges::random_access_range lost
std::ranges::contiguous_range lost
std::ranges::viewable_range guaranteed
std::ranges::view guaranteed
std::ranges::sized_range guaranteed
std::ranges::common_range guaranteed
std::ranges::output_range lost
std::ranges::borrowed_range guaranteed
seqan3::const_iterable_range guaranteed
std::ranges::range_reference_t index_simd_t

This is a source view. For more details, see Views.

Example

// The simd type with 8 unsigned shorts.
int main()
{
// Generate ascending simd index.
for (auto && simd_id : seqan3::views::iota_simd<uint16x8_t>(0, 10))
seqan3::debug_stream << simd_id << '\n'; // [0, 0, ..., 0], [1, 1, ..., 1], ... [9, 9, ..., 9]
return 0;
}

◆ is_builtin_simd_v

template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_builtin_simd_v = is_builtin_simd<builtin_simd_t>::value
constexpr

Helper variable to test whether a type is a simd builtin type.

Template Parameters
builtin_simd_tThe type to check.
See also
seqan3::detail::is_builtin_simd

◆ is_native_builtin_simd_v

template<typename builtin_simd_t >
constexpr bool seqan3::detail::is_native_builtin_simd_v = is_native_builtin_simd<builtin_simd_t>::value
constexpr

Helper variable to test whether a type is a native simd builtin type.

Template Parameters
builtin_simd_tThe type to check.
See also
seqan3::detail::is_native_builtin_simd_v

◆ to_simd

template<simd::simd_concept simd_t>
constexpr auto seqan3::views::to_simd
inlineconstexpr

A view that transforms a range of ranges into chunks of seqan3::simd vectors.

Template Parameters
urng_tThe type of the range being processed.
simd_tThe target simd vector type.
Parameters
[in]urangeThe range being processed.
[in]paddingAn optional padding value.
Returns
A range of ranges with the original sequences transformed into simd vectors.

Header File

#include <seqan3/utility/simd/views/to_simd.hpp>

This view can be used to transform a collection of sequences into chunks of simd vectors. This transformation is also known as Array-of-Structure to Structure-of-Array transformation. It is used to transform the memory layout of the sequences to a more efficient form when used in vectorised algorithms. The number of sequences contained in the range to be transformed cannot be larger than the number of elements stored in the target simd vector, i.e. the size of urange <= simd_traits<simd_t>::length. After applying the transformation one column of the outer range is transposed into a simd vector. This means that the characters of all sequences at a given position x are stored in a simd vector retaining the original order. The returned range itself is a range-of-ranges. When dereferencing the iterator a std::span over a std::array with at most simd length many vectors is returned. If a sequence is empty or ends before the largest sequence in the collection, it can be padded with an optional value.

View properties

Concepts and traits urng_t (underlying range type) rrng_t (returned range type)
std::ranges::input_range required preserved
std::ranges::forward_range required lost
std::ranges::bidirectional_range lost
std::ranges::random_access_range lost
std::ranges::contiguous_range lost
std::ranges::viewable_range required guaranteed
std::ranges::view guaranteed
std::ranges::sized_range preserved (iff std::ranges::sized_range<std::ranges::range_value_t<urng_t>> is true)
std::ranges::common_range lost
std::ranges::output_range lost
seqan3::const_iterable_range lost
std::ranges::range_reference_t std::span<simd_t>
  • urng_t is the type of the range modified by this view (input).
  • the expression std::ranges::input_range<std::ranges::range_value_t<urng_t> must evaluate to true
  • the expression std::default_initializable<std::ranges::range_value_t<urng_t>> must evaluate to true
  • the expression semialphabet<std::ranges::range_value_t<std::ranges::range_value_t<urng_t>>> must evaluate to true
  • rrng_type is the type of the range returned by this view.
  • for more details, see Views.

Example

#include <vector>
int main()
{
using namespace seqan3::literals;
// Adds 7 sequences. The eighth will be set to a default value.
batch.push_back("ACGTACGTACGTACGATCG"_dna4);
batch.push_back("AGTGAGCTACGGACTAGCTACGACT"_dna4);
batch.push_back("GACTAGCACGAGCGAGATCG"_dna4);
batch.push_back("GGATCGACGGACTAGC"_dna4);
batch.push_back("ACGTACGACGGACGTACGAGCGAGCTACGAGC"_dna4);
batch.push_back("ACGATCGACGACTAGCGAC"_dna4);
batch.push_back("GTACGGATGGTAAACCGCACAT"_dna4);
// Applies lazy transformation using `8` as a padding symbol if a sequence ends early.
auto to_soa = batch | seqan3::views::to_simd<uint16x8_t>(8);
size_t chunk_count = 0;
for (auto && chunk : to_soa)
{
seqan3::debug_stream << "Chunk " << chunk_count++ << ":\n";
for (auto & vec : chunk)
seqan3::debug_stream << vec << '\n';
}
return 0;
}
Provides seqan3::dna4, container aliases and string literals.
constexpr auto chunk
A chunk view.
Definition: chunk.hpp:29
The SeqAn namespace for literals.
T push_back(T... args)

The output is as follows:

Chunk 0:
[0,0,2,2,0,0,2,8]
[1,2,0,2,1,1,3,8]
[2,3,1,0,2,2,0,8]
[3,2,3,3,3,0,1,8]
[0,0,0,1,0,3,2,8]
[1,2,2,2,1,1,2,8]
[2,1,1,0,2,2,0,8]
[3,3,0,1,0,0,3,8]
Chunk 1:
[0,0,1,2,1,1,2,8]
[1,1,2,2,2,2,2,8]
[2,2,0,0,2,0,3,8]
[3,2,2,1,0,1,0,8]
[0,0,1,3,1,3,0,8]
[1,1,2,0,2,0,0,8]
[2,3,0,2,3,2,1,8]
[0,0,2,1,0,1,1,8]
Chunk 2:
[3,2,0,8,1,2,2,8]
[1,1,3,8,2,0,1,8]
[2,3,1,8,0,1,0,8]
[8,0,2,8,2,8,1,8]
[8,1,8,8,1,8,0,8]
[8,2,8,8,2,8,3,8]
[8,0,8,8,0,8,8,8]
[8,1,8,8,2,8,8,8]
Chunk 3:
[8,3,8,8,1,8,8,8]
[8,8,8,8,3,8,8,8]
[8,8,8,8,0,8,8,8]
[8,8,8,8,1,8,8,8]
[8,8,8,8,2,8,8,8]
[8,8,8,8,0,8,8,8]
[8,8,8,8,2,8,8,8]
[8,8,8,8,1,8,8,8]