xstrided_view
Defined in xtensor/xstrided_view.hpp
-
template<class CT, class S, layout_type L = layout_type::dynamic, class FST = detail::flat_storage_getter<CT, ::xt::layout_type::row_major>>
class xstrided_view : public xt::xview_semantic<xstrided_view<CT, S, layout_type::dynamic, detail::flat_storage_getter<CT, ::xt::layout_type::row_major>>>, public select_iterable_base_t<layout_type::dynamic, std::decay_t<CT>::static_layout, xstrided_view<CT, S, layout_type::dynamic, detail::flat_storage_getter<CT, ::xt::layout_type::row_major>>>, private xt::xstrided_view_base<xstrided_view<CT, S, layout_type::dynamic, detail::flat_storage_getter<CT, ::xt::layout_type::row_major>>>, public extension::xstrided_view_base_t<CT, S, layout_type::dynamic, detail::flat_storage_getter<CT, ::xt::layout_type::row_major>> View of an xexpression using strides.
The xstrided_view class implements a view utilizing an initial offset and strides.
See also
- Template Parameters:
CT – the closure type of the xexpression type underlying this view
L – the layout of the strided view
S – the strides type of the strided view
FST – the flat storage type used for the strided view
Constructor
-
template<class CTA, class SA>
inline xstrided_view(CTA &&e, SA &&shape, strides_type &&strides, std::size_t offset, layout_type layout) noexcept Constructs an xstrided_view.
- Parameters:
e – the underlying xexpression for this view
shape – the shape of the view
strides – the strides of the view
offset – the offset of the first element in the underlying container
layout – the layout of the view
Data
Extended copy semantic
-
template<class E>
inline auto operator=(const xexpression<E> &e) -> self_type& The extended assignment operator.
Public Functions
-
inline const inner_backstrides_type &backstrides() const noexcept
Returns the backstrides of the xtrided_view_base.
-
inline layout_type layout() const noexcept
Returns the layout of the xtrided_view_base.
-
inline const inner_shape_type &shape() const noexcept
Returns the shape of the xtrided_view_base.
-
inline const inner_strides_type &strides() const noexcept
Returns the strides of the xtrided_view_base.
-
template<class ...Args>
inline auto unchecked(Args... args) -> reference Returns a reference to the element at the specified position in the view.
Warning
This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be preferred whenever it is possible.
Warning
This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:
xt::xarray<double> a = {{0, 1}, {2, 3}}; xt::xarray<double> b = {0, 1}; auto fd = a + b; double res = fd.uncheked(0, 1);
- Parameters:
args – a list of indices specifying the position in the view. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the view, else the behavior is undefined.
-
template<class ...Args>
inline auto unchecked(Args... args) const -> const_reference Returns a constant reference to the element at the specified position in the view.
Warning
This method is meant for performance, for expressions with a dynamic number of dimensions (i.e. not known at compile time). Since it may have undefined behavior (see parameters), operator() should be preferred whenever it is possible.
Warning
This method is NOT compatible with broadcasting, meaning the following code has undefined behavior:
xt::xarray<double> a = {{0, 1}, {2, 3}}; xt::xarray<double> b = {0, 1}; auto fd = a + b; double res = fd.uncheked(0, 1);
- Parameters:
args – a list of indices specifying the position in the view. Indices must be unsigned integers, the number of indices must be equal to the number of dimensions of the view, else the behavior is undefined.
-
template<class E, class ST>
inline auto data() noexcept -> std::enable_if_t<detail::provides_data_interface<E, ST>::value, pointer> Returns a pointer to the underlying array serving as element storage.
The first element of the view is at data() + data_offset().
-
template<class E, class ST>
inline auto data() const noexcept -> std::enable_if_t<detail::provides_data_interface<E, ST>::value, const_pointer> Returns a constant pointer to the underlying array serving as element storage.
The first element of the view is at data() + data_offset().
-
inline size_type data_offset() const noexcept
Returns the offset to the first element in the view.
-
template<class It>
inline auto element(It first, It last) -> reference Returns a reference to the element at the specified position in the view.
- Parameters:
first – iterator starting the sequence of indices
last – iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the the number of dimensions of the view..
-
template<class It>
inline auto element(It first, It last) const -> const_reference Returns a constant reference to the element at the specified position in the view.
- Parameters:
first – iterator starting the sequence of indices
last – iterator ending the sequence of indices The number of indices in the sequence should be equal to or greater than the the number of dimensions of the view..
-
inline xexpression_type &expression() noexcept
Returns a reference to the underlying expression of the view.
-
inline const xexpression_type &expression() const noexcept
Returns a constant reference to the underlying expression of the view.
-
inline storage_type &storage() noexcept
Returns a reference to the buffer containing the elements of the view.
-
inline const storage_type &storage() const noexcept
Returns a constant reference to the buffer containing the elements of the view.
-
template<class O>
inline bool broadcast_shape(O &shape, bool reuse_cache = false) const Broadcast the shape of the view to the specified parameter.
- Parameters:
shape – the result shape
reuse_cache – parameter for internal optimization
- Returns:
a boolean indicating whether the broadcasting is trivial
-
typedef std::vector<xstrided_slice<std::ptrdiff_t>> xt::xstrided_slice_vector
vector of slices used to build a
xstrided_view
-
template<layout_type L = layout_type::dynamic, class E, class S, class X>
inline auto xt::strided_view(E &&e, S &&shape, X &&strides, std::size_t offset, layout_type layout) noexcept Construct a strided view from an xexpression, shape, strides and offset.
- Parameters:
e – xexpression
shape – the shape of the view
strides – the new strides of the view
offset – the offset of the first element in the underlying container
layout – the new layout of the expression
- Template Parameters:
L – the static layout type of the view (default: dynamic)
E – type of xexpression
S – strides type
X – strides type
- Returns:
the view
-
template<class E>
inline auto xt::strided_view(E &&e, const xstrided_slice_vector &slices) Function to create a dynamic view from an xexpression and an xstrided_slice_vector.
xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}}; xt::xstrided_slice_vector sv({xt::range(0, 1)}); sv.push_back(xt::range(0, 3, 2)); auto v = xt::strided_view(a, sv); // ==> {{1, 3}}
You can also achieve the same with the following short-hand syntax:
xt::xarray<double> a = {{1, 2, 3}, {4, 5, 6}}; auto v = xt::strided_view(a, {xt::range(0, 1), xt::range(0, 3, 2)}); // ==> {{1, 3}}
- Parameters:
e – xexpression
slices – the slice vector
- Returns:
initialized strided_view according to slices
-
template<layout_type L = ::xt::layout_type::row_major, class E, class S>
inline auto xt::reshape_view(E &&e, S &&shape, layout_type) Return a view on a container with a new shape.
- Deprecated:
Note: if you resize the underlying container, this view becomes invalidated.
- Parameters:
e – xexpression to reshape
shape – new shape
order – traversal order (optional)
- Returns:
view on xexpression with new shape