Utilities#

Miscellaneous functions are listed here.

Parser#

configuration bbfft::parse_fft_descriptor(std::string_view desc)#

Parses an FFT descriptor.

See user manual for a description of the input format

Parameters:

desc – descriptor

Returns:

configuration

device_info bbfft::parse_device_info(std::string_view desc)#

Parses a device info descriptor.

See user manual for a description of the input format

Parameters:

desc – descriptor

Returns:

device info

Tensor indexer#

template<typename IdxT, unsigned int D, layout L = layout::row_major>
class tensor_indexer#

Utility class to compute addresses for multi-dimensional data.

Template Parameters:
  • IdxT – Index type

  • D – Tensor dimension

  • L – Storage layout

Public Types

using multi_idx_t = std::array<IdxT, D>#

Data type of multi-indices.

Public Functions

inline tensor_indexer()#

Construct empty indexer.

inline tensor_indexer(multi_idx_t shape)#

Construct indexer for \(N_1\times\dots\times N_D\) tensor.

Strides are computed automatically assuming packed data as following:

Row-major layout: \(s = (N_{D-1}\cdot\ldots\cdot N_2, \dots, N_{D-1}, 1)\)

Column-major layout: \(s = (1, N_1, \dots, N_1\cdot\ldots\cdot N_{D-1})\)

Parameters:

shape – The numbers \(N_1,\dots,N_D\)

inline tensor_indexer(multi_idx_t shape, multi_idx_t stride)#

Construct indexer for \(N_1\times\dots\times N_D\) tensor with manual strides.

Parameters:
  • shape – The numbers \(N_1,\dots,N_D\)

  • stride – Custom strides

template<typename ...Indices, typename = std::enable_if_t<sizeof...(Indices) == D, int>>
inline IdxT operator()(Indices... is) const#

Compute linear index for entry \((i_1, ..., i_D)\).

Indices are computed as following:

\[a = \sum_{j=1}^D i_j s_j,\]
where \(s_j\) are the entries of the stride array.

Template Parameters:

Indices – Index types of arguments

Parameters:

...is – Indices

Returns:

Linear index

inline IdxT operator()(multi_idx_t const &idx) const#

Compute linear index.

Parameters:

idx – Multi-index

Returns:

Linear index

inline auto shape() const -> std::conditional_t<L == layout::row_major, multi_idx_t, multi_idx_t const&>#

Tensor shape.

Returns:

Numbers \(N_1,\dots,N_D\)

inline auto shape(unsigned int d) const#

Tensor shape.

Parameters:

d – mode

Returns:

Number \(N_d\)

inline auto stride() const -> std::conditional_t<L == layout::row_major, multi_idx_t, multi_idx_t const&>#

Strides.

Returns:

Stride array

inline auto stride(unsigned int d) const#

Stride for d-th mode.

Parameters:

d – mode

Returns:

Stride

inline IdxT size() const#

Compute number of elements in tensor.

Returns:

Size (multiply with element type to get number of bytes)

inline constexpr auto dim() const#

Dimension.

Returns:

Dimension

template<unsigned int Dfrom = 0, unsigned int Dto = D - 1>
inline bool may_fuse() const#

Checks whether indices may be fused.

“Fusing” means that one may treat 2 or more neighbouring indices as a single super-index. Modes may only be fused it they are packed in memory.

Template Parameters:
  • Dfrom – First fused mode

  • Dto – Last fused mode

Returns:

True if modes may be fused

template<unsigned int Dfrom = 0, unsigned int Dto = D - 1>
inline auto fused() const#

Returns a tensor indexer with fused modes.

See also

may_fuse()

Template Parameters:
  • Dfrom – First fused mode

  • Dto – Last fused mode

Returns:

Fused tensor indexer

template<std::size_t E>
inline bool may_reshape_mode(int mode, std::array<IdxT, E> const &mode_shape) const#

Checks whether a mode may be reshaped.

“Reshaping a mode” means that one views a 1-D mode as a E-D tensor. E.g. for the tensor X_{i,j,k} of size N1 x N2 x N3 a reshape of mode 1 (= index j) with mode shape M1 x M2 means that we view the data of tensor X as the tensor X’_{i,j1,j2,k} of size N1 x M1 x M2 x N3.

Template Parameters:

E – reshape dimension

Parameters:
  • mode – The mode number to reshape; counting starts from 0

  • mode_shape – The E-D shape of the mode

Returns:

True if the mode may be reshaped

template<std::size_t E>
inline auto reshaped_mode(int mode, std::array<IdxT, E> mode_shape) const#

Returns a tensor indexer with reshaped mode.

Template Parameters:

E – reshape dimension

Parameters:
  • mode – The mode number to reshape; counting starts from 0

  • mode_shape – The E-D shape of the mode

Returns:

Reshaped tensor indexer

Storage layout#

enum class bbfft::layout#

Tensor storage layout.

Row major format: The mode varying fastest in memory is specified last

Column major format: The mode varying fastest in memory is specified first

Values:

enumerator row_major#

Row major layout.

enumerator col_major#

Column major layout.

Functions#

template<std::size_t Dout, typename IdxT, std::size_t Din>
constexpr auto bbfft::fit_array(std::array<IdxT, Din> const &in, IdxT fill_value = IdxT(0))#

Truncate or extend std::array.

Template Parameters:
  • Dout – Length of output array

  • IdxT – Array value type

  • Din – Length of input array

Parameters:
  • in – Input array

  • fill_value – Fill value if extension is needed

Returns:

Truncated or extended array