rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
rexlib::strided_layout Class Reference

Public Member Functions

 strided_layout (const strided_layout &other) noexcept
 
 strided_layout (strided_layout &&other) noexcept
 
strided_layout & operator= (const strided_layout &other) noexcept
 
strided_layout & operator= (strided_layout &&other) noexcept
 
std::size_t hash () const noexcept
 Obtain a hash of the layout.
 
std::size_t get_rank () const noexcept
 Get the number of axis in the layout.
 
void get_extents (std::vector< std::size_t > &extents) const
 Get the extents of the layout.
 
void get_strides (std::vector< std::ptrdiff_t > &strides) const
 Get the strides of the layout.
 
std::ptrdiff_t get_offset () const noexcept
 Get the offset of the data.
 
std::size_t compute_storage_requirement () const noexcept
 Computes the minimum storage size (in elements) for this layout.
 
std::size_t compute_element_count () const noexcept
 Computes the number of elements referenced by the layout.
 
bool extents_equal (span< const std::size_t > extents) const noexcept
 Check if this layout has a specific shape.
 
REXLIB_NODISCARD strided_layout apply_subscripts (span< const dynamic_subscript > subscripts) const
 Apply a set of dynamic subscripts to this layout.
 
REXLIB_NODISCARD strided_layout transpose () const
 Reverse the order of the axes.
 
REXLIB_NODISCARD strided_layout permute (span< const std::size_t > order) const
 Permute the order of the axes.
 
REXLIB_NODISCARD strided_layout matrix_transpose (std::ptrdiff_t axis1=-1, std::ptrdiff_t axis2=-2) const
 Swap two axes in the layout.
 
REXLIB_NODISCARD strided_layout matrix_diagonal (std::ptrdiff_t axis1=-1, std::ptrdiff_t axis2=-2) const
 Obtains a layout view to the matrix diagonal defined by two axes.
 
REXLIB_NODISCARD strided_layout squeeze () const
 Remove insignificant axes of the layout.
 
REXLIB_NODISCARD strided_layout broadcast_to (span< const std::size_t > extents) const
 Perform a broadcast of the layout to match the provided extents.
 
const strided_layout_implementation & get_implementation () const noexcept
 Get the implementation of this layout.
 

Static Public Member Functions

static strided_layout make_contiguous_layout (span< const std::size_t > extents)
 Create a contiguous layout from the provided extents.
 
static strided_layout make_custom_layout (span< const std::size_t > extents, span< const std::ptrdiff_t > strides, std::ptrdiff_t offset=0)
 

Friends

bool operator== (const strided_layout &lhs, const strided_layout &rhs) noexcept
 
bool operator!= (const strided_layout &lhs, const strided_layout &rhs) noexcept
 

Member Function Documentation

◆ apply_subscripts()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::apply_subscripts ( span< const dynamic_subscript >  subscripts) const

Apply a set of dynamic subscripts to this layout.

Parameters
subscriptsThe subscripts.
Returns
strided_layout The resulting layout.
Exceptions
std::invalid_argumentIf not all subscripts are processed. Or subscript is out of bounds

◆ broadcast_to()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::broadcast_to ( span< const std::size_t >  extents) const

Perform a broadcast of the layout to match the provided extents.

This function modifies the layout to match the provided extents by adding phantom axes or adjusting existing axes.

Parameters
extentsExtents to broadcast to. untouched. Must be greater or equal to rank. Defaults to zero.
Returns
strided_layout The resulting broadcasted layout.
Exceptions
std::invalid_argumentIf the layout has more axes than extents.
std::invalid_argumentIf the axes cannot be broadcasted to the provided extents.

◆ compute_element_count()

std::size_t rexlib::strided_layout::compute_element_count ( ) const
noexcept

Computes the number of elements referenced by the layout.

Returns
std::size_t Number of elements.

◆ compute_storage_requirement()

std::size_t rexlib::strided_layout::compute_storage_requirement ( ) const
noexcept

Computes the minimum storage size (in elements) for this layout.

Returns
std::size_t Minimum storage size in elements.

◆ extents_equal()

bool rexlib::strided_layout::extents_equal ( span< const std::size_t >  extents) const
noexcept

Check if this layout has a specific shape.

Parameters
extentsThe extents to be compared.
Returns
true If the provided extents match layout's extents.
false If the provided extents do not match layout's extents.

◆ get_extents()

void rexlib::strided_layout::get_extents ( std::vector< std::size_t > &  extents) const

Get the extents of the layout.

Parameters
extentsOutput parameter where the extents are written.

◆ get_implementation()

const strided_layout_implementation & rexlib::strided_layout::get_implementation ( ) const
noexcept

Get the implementation of this layout.

Returns
const strided_layout_implementation& The implementation reference.
Note
The implementation class is not part of the public API. This method is provided for internal use and testing purposes.

◆ get_offset()

std::ptrdiff_t rexlib::strided_layout::get_offset ( ) const
noexcept

Get the offset of the data.

Returns
std::size_t The offset in elements.

◆ get_rank()

std::size_t rexlib::strided_layout::get_rank ( ) const
noexcept

Get the number of axis in the layout.

Returns
std::size_t

◆ get_strides()

void rexlib::strided_layout::get_strides ( std::vector< std::ptrdiff_t > &  strides) const

Get the strides of the layout.

Parameters
stridesOutput parameter where the strides are written.

◆ hash()

std::size_t rexlib::strided_layout::hash ( ) const
noexcept

Obtain a hash of the layout.

Returns
std::size_t The hash.

◆ make_contiguous_layout()

static strided_layout rexlib::strided_layout::make_contiguous_layout ( span< const std::size_t >  extents)
static

Create a contiguous layout from the provided extents.

Parameters
extentsExtents of the layout.
Returns
strided_layout The resulting layout.

◆ matrix_diagonal()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::matrix_diagonal ( std::ptrdiff_t  axis1 = -1,
std::ptrdiff_t  axis2 = -2 
) const

Obtains a layout view to the matrix diagonal defined by two axes.

Parameters
axis1First axis of the diagonal. Must be in [-rank, rank).
axis2Second axis of the diagonal. Must be in [-rank, rank). Cannot be equal to axis1.
Returns
strided_layout The resulting layout of the matrix_diagonal.
Exceptions
std::out_of_rangeIf either axis1 or axis2 exceeds bounds.
std::invalid_argumentIf axis1 and axis2 are equal.

◆ matrix_transpose()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::matrix_transpose ( std::ptrdiff_t  axis1 = -1,
std::ptrdiff_t  axis2 = -2 
) const

Swap two axes in the layout.

Parameters
axis1Index of the first axis. Must be in [-rank, rank).
axis2Index of the second axis. Must be in [-rank, rank).
Returns
strided_layout Permuted layout.
Exceptions
std::out_of_rangeIf either axis1 or axis2 exceeds bounds.

◆ permute()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::permute ( span< const std::size_t >  order) const

Permute the order of the axes.

Parameters
orderOrder acquired by the new layout. Must have the same size as the amount of dimensions and it must feature strictly one instance of each number in [0, rank).
Returns
strided_layout Permuted layout.
Exceptions
std::invalid_argumentIf the permutation order is invalid.

◆ squeeze()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::squeeze ( ) const

Remove insignificant axes of the layout.

Returns
strided_layout The resulting layout.

◆ transpose()

REXLIB_NODISCARD strided_layout rexlib::strided_layout::transpose ( ) const

Reverse the order of the axes.

Returns
strided_layout The resulting layout.

The documentation for this class was generated from the following file: