10#ifndef XTENSOR_CHUNKED_VIEW_HPP
11#define XTENSOR_CHUNKED_VIEW_HPP
13#include <xtl/xsequence.hpp>
15#include "xchunked_array.hpp"
16#include "xnoalias.hpp"
17#include "xstorage.hpp"
18#include "xstrided_view.hpp"
41 using expression_type = std::decay_t<E>;
42 using value_type =
typename expression_type::value_type;
43 using reference =
typename expression_type::reference;
44 using const_reference =
typename expression_type::const_reference;
45 using pointer =
typename expression_type::pointer;
46 using const_pointer =
typename expression_type::const_pointer;
47 using size_type =
typename expression_type::size_type;
48 using difference_type =
typename expression_type::difference_type;
53 template <
class OE,
class S>
62 typename std::enable_if_t<!is_chunked_t<OE>::value,
xchunked_view<E>&> operator=(
const OE&
e);
65 typename std::enable_if_t<is_chunked_t<OE>::value,
xchunked_view<E>&> operator=(
const OE&
e);
67 size_type dimension()
const noexcept;
69 const shape_type& chunk_shape()
const noexcept;
70 size_type grid_size()
const noexcept;
73 expression_type& expression()
noexcept;
74 const expression_type& expression()
const noexcept;
93 template <
class E,
class S>
101 template <
class OE,
class S>
106 m_shape.resize(
e.dimension());
107 const auto&
s =
e.shape();
108 std::copy(
s.cbegin(),
s.cend(), m_shape.begin());
114 inline xchunked_view<E>::xchunked_view(OE&& e)
115 : m_expression(std::forward<OE>(e))
117 m_shape.resize(e.dimension());
118 const auto& s = e.shape();
119 std::copy(s.cbegin(), s.cend(), m_shape.begin());
123 void xchunked_view<E>::init()
126 m_grid_shape.resize(m_shape.size());
130 m_chunk_shape.cbegin(),
131 m_grid_shape.begin(),
134 std::size_t cn = s / cs;
142 m_chunk_nb = std::accumulate(
143 std::begin(m_grid_shape),
144 std::end(m_grid_shape),
152 typename std::enable_if_t<!is_chunked_t<OE>::value, xchunked_view<E>&>
153 xchunked_view<E>::operator=(
const OE& e)
155 auto end = chunk_end();
156 for (
auto it = chunk_begin(); it != end; ++it)
166 typename std::enable_if_t<is_chunked_t<OE>::value, xchunked_view<E>&>
167 xchunked_view<E>::operator=(
const OE& e)
169 m_chunk_shape.resize(e.dimension());
170 const auto& cs = e.chunk_shape();
171 std::copy(cs.cbegin(), cs.cend(), m_chunk_shape.begin());
173 auto it2 = e.chunks().begin();
174 auto end1 = chunk_end();
175 for (
auto it1 = chunk_begin(); it1 != end1; ++it1, ++it2)
179 auto lhs_shape = el1.shape();
180 if (lhs_shape != el2.shape())
189 return range(0, size);
203 inline auto xchunked_view<E>::dimension() const noexcept -> size_type
205 return m_shape.size();
209 inline auto xchunked_view<E>::shape() const noexcept -> const shape_type&
215 inline auto xchunked_view<E>::chunk_shape() const noexcept -> const shape_type&
217 return m_chunk_shape;
221 inline auto xchunked_view<E>::grid_size() const noexcept -> size_type
227 inline auto xchunked_view<E>::grid_shape() const noexcept -> const shape_type&
233 inline auto xchunked_view<E>::expression() noexcept -> expression_type&
239 inline auto xchunked_view<E>::expression() const noexcept -> const expression_type&
245 inline auto xchunked_view<E>::chunk_begin() -> chunk_iterator
247 shape_type chunk_index(m_shape.size(), size_type(0));
248 return chunk_iterator(*
this, std::move(chunk_index), 0u);
252 inline auto xchunked_view<E>::chunk_end() -> chunk_iterator
254 return chunk_iterator(*
this, shape_type(grid_shape()), grid_size());
258 inline auto xchunked_view<E>::chunk_begin() const -> const_chunk_iterator
260 shape_type chunk_index(m_shape.size(), size_type(0));
261 return const_chunk_iterator(*
this, std::move(chunk_index), 0u);
265 inline auto xchunked_view<E>::chunk_end() const -> const_chunk_iterator
267 return const_chunk_iterator(*
this, shape_type(grid_shape()), grid_size());
271 inline auto xchunked_view<E>::chunk_cbegin() const -> const_chunk_iterator
273 return chunk_begin();
277 inline auto xchunked_view<E>::chunk_cend() const -> const_chunk_iterator
282 template <
class E,
class S>
283 inline xchunked_view<E> as_chunked(E&& e, S&& chunk_shape)
285 return xchunked_view<E>(std::forward<E>(e), std::forward<S>(chunk_shape));
289 inline xchunked_view<E> as_chunked(E&& e)
291 return xchunked_view<E>(std::forward<E>(e));
standard mathematical functions for xexpressions
std::vector< xstrided_slice< std::ptrdiff_t > > xstrided_slice_vector
vector of slices used to build a xstrided_view
auto strided_view(E &&e, S &&shape, X &&stride, std::size_t offset=0, layout_type layout=L) noexcept
Construct a strided view from an xexpression, shape, strides and offset.