Stratax 0.2.0
Loading...
Searching...
No Matches
Slice.hpp File Reference
#include <stratax/core/containers/Matrix.hpp>
#include <stratax/core/containers/Tensor.hpp>
#include <stratax/core/containers/Vector.hpp>
#include <stratax/core/Exceptions.hpp>
#include <stratax/core/containers/Shape.hpp>
#include <stratax/core/Slice.hpp>
#include <stratax/core/containers/Strides.hpp>
#include <stratax/core/validation/Validation.hpp>
#include <array>
#include <cstddef>
#include <limits>
#include <vector>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

struct  stratax::ops::detail::ResolvedSlice

Namespaces

namespace  stratax
namespace  stratax::ops
namespace  stratax::ops::detail

Functions

std::ptrdiff_t stratax::ops::detail::clamp (std::ptrdiff_t value, std::ptrdiff_t lower, std::ptrdiff_t upper)
ResolvedSlice stratax::ops::detail::normalize_slice (const stratax::core::Slice &slice, std::size_t extent, const char *message)
template<std::size_t N, std::size_t... Is>
stratax::core::Shape stratax::ops::detail::shape_from_slices_impl (const std::array< stratax::core::Slice, N > &ranges, std::index_sequence< Is... >)
 Builds a shape from a compile-time slice array.
template<std::size_t N>
stratax::core::Shape stratax::ops::detail::shape_from_slices (const std::array< stratax::core::Slice, N > &ranges)
 Builds a shape from a slice array.
template<typename T>
stratax::container::Vector< T > slice (const stratax::container::Vector< T > &vec, const stratax::core::Slice &slice)
 Copies a half-open range from a vector.
template<typename T>
stratax::container::Matrix< T > slice (const stratax::container::Matrix< T > &mat, const stratax::core::Slice &rows, const stratax::core::Slice &cols)
 Copies a rectangular half-open region from a matrix.
template<typename T, typename... Slices>
stratax::container::Tensor< T > slice (const stratax::container::Tensor< T > &tensor, Slices... slices)
 Copies a multidimensional half-open region from a tensor.
template<typename T>
stratax::container::Tensor< T > slice (const stratax::container::Tensor< T > &tensor, const std::vector< stratax::core::Slice > &slices)
 Copies a multidimensional half-open region from a tensor using a vector of slices.

Function Documentation

◆ slice() [1/4]

template<typename T>
stratax::container::Matrix< T > slice ( const stratax::container::Matrix< T > & mat,
const stratax::core::Slice & rows,
const stratax::core::Slice & cols )

Copies a rectangular half-open region from a matrix.

Rows in [rows.start(), rows.stop()) and columns in [cols.start(), cols.stop()) are copied into a new row-major matrix, sampling each axis by its slice step.

Parameters
matSource matrix.
rowsRow slice.
colsColumn slice.
Returns
Matrix containing the selected region.
Exceptions
Exceptions::IndexErrorIf either slice exceeds the matrix bounds.

Definition at line 182 of file Slice.hpp.

◆ slice() [2/4]

template<typename T>
stratax::container::Tensor< T > slice ( const stratax::container::Tensor< T > & tensor,
const std::vector< stratax::core::Slice > & slices )

Copies a multidimensional half-open region from a tensor using a vector of slices.

One Slice must be provided for each tensor dimension via the vector. The result shape is formed from the size of each slice, and values are copied in row-major order honoring each slice step.

Parameters
tensorSource tensor.
slicesVector of slices, one per tensor dimension.
Returns
Tensor containing the selected region.
Exceptions
Exceptions::DimensionErrorIf the vector size does not match the tensor rank.
Exceptions::IndexErrorIf any slice exceeds the corresponding dimension.

Definition at line 317 of file Slice.hpp.

◆ slice() [3/4]

template<typename T, typename... Slices>
stratax::container::Tensor< T > slice ( const stratax::container::Tensor< T > & tensor,
Slices... slices )

Copies a multidimensional half-open region from a tensor.

One Slice must be provided for each tensor dimension. The result shape is formed from the size of each slice, and values are copied in row-major order honoring each slice step.

Parameters
tensorSource tensor.
slicesOne slice per tensor dimension.
Returns
Tensor containing the selected region.
Exceptions
Exceptions::DimensionErrorIf the number of slices does not match the tensor rank.
Exceptions::IndexErrorIf any slice exceeds the corresponding dimension.

Definition at line 232 of file Slice.hpp.

◆ slice() [4/4]

template<typename T>
stratax::container::Vector< T > slice ( const stratax::container::Vector< T > & vec,
const stratax::core::Slice & slice )

Copies a half-open range from a vector.

The returned vector contains elements in [slice.start(), slice.stop()) sampled with slice.step() using the source vector's flat storage order.

Parameters
vecSource vector.
sliceHalf-open element range.
Returns
Vector containing the selected elements.
Exceptions
Exceptions::IndexErrorIf the slice stop is greater than vec.size().

Definition at line 143 of file Slice.hpp.