10#ifndef XTENSOR_CHUNKED_VIEW_HPP
11#define XTENSOR_CHUNKED_VIEW_HPP
13#include <xtl/xsequence.hpp>
15#include "../chunk/xchunked_array.hpp"
16#include "../containers/xstorage.hpp"
17#include "../views/xstrided_view.hpp"
39 using self_type = xchunked_view<E>;
40 using expression_type = std::decay_t<E>;
41 using value_type =
typename expression_type::value_type;
42 using reference =
typename expression_type::reference;
43 using const_reference =
typename expression_type::const_reference;
44 using pointer =
typename expression_type::pointer;
45 using const_pointer =
typename expression_type::const_pointer;
46 using size_type =
typename expression_type::size_type;
47 using difference_type =
typename expression_type::difference_type;
52 template <
class OE,
class S>
53 xchunked_view(OE&& e, S&& chunk_shape);
56 xchunked_view(OE&& e);
61 typename std::enable_if_t<!is_chunked_t<OE>::value, xchunked_view<E>&> operator=(
const OE& e);
64 typename std::enable_if_t<is_chunked_t<OE>::value, xchunked_view<E>&> operator=(
const OE& e);
66 size_type dimension()
const noexcept;
67 const shape_type& shape()
const noexcept;
68 const shape_type& chunk_shape()
const noexcept;
69 size_type grid_size()
const noexcept;
70 const shape_type& grid_shape()
const noexcept;
72 expression_type& expression()
noexcept;
73 const expression_type& expression()
const noexcept;
75 chunk_iterator chunk_begin();
76 chunk_iterator chunk_end();
78 const_chunk_iterator chunk_begin()
const;
79 const_chunk_iterator chunk_end()
const;
80 const_chunk_iterator chunk_cbegin()
const;
81 const_chunk_iterator chunk_cend()
const;
87 shape_type m_chunk_shape;
88 shape_type m_grid_shape;
92 template <
class E,
class S>
100 template <
class OE,
class S>
101 inline xchunked_view<E>::xchunked_view(OE&& e, S&& chunk_shape)
102 : m_expression(std::forward<OE>(e))
103 , m_chunk_shape(xtl::forward_sequence<shape_type, S>(chunk_shape))
105 m_shape.resize(e.dimension());
106 const auto& s = e.shape();
107 std::copy(s.cbegin(), s.cend(), m_shape.begin());
113 inline xchunked_view<E>::xchunked_view(OE&& e)
114 : m_expression(std::forward<OE>(e))
116 m_shape.resize(e.dimension());
117 const auto& s = e.shape();
118 std::copy(s.cbegin(), s.cend(), m_shape.begin());
122 void xchunked_view<E>::init()
125 m_grid_shape.resize(m_shape.size());
129 m_chunk_shape.cbegin(),
130 m_grid_shape.begin(),
133 std::size_t cn = s / cs;
141 m_chunk_nb = std::accumulate(
142 std::begin(m_grid_shape),
143 std::end(m_grid_shape),
151 typename std::enable_if_t<!is_chunked_t<OE>::value, xchunked_view<E>&>
152 xchunked_view<E>::operator=(
const OE& e)
154 auto end = chunk_end();
155 for (
auto it = chunk_begin(); it != end; ++it)
165 typename std::enable_if_t<is_chunked_t<OE>::value, xchunked_view<E>&>
166 xchunked_view<E>::operator=(
const OE& e)
168 m_chunk_shape.resize(e.dimension());
169 const auto& cs = e.chunk_shape();
170 std::copy(cs.cbegin(), cs.cend(), m_chunk_shape.begin());
172 auto it2 = e.chunks().begin();
173 auto end1 = chunk_end();
174 for (
auto it1 = chunk_begin(); it1 != end1; ++it1, ++it2)
178 auto lhs_shape = el1.shape();
179 if (lhs_shape != el2.shape())
188 return range(0, size);
202 inline auto xchunked_view<E>::dimension() const noexcept -> size_type
204 return m_shape.size();
208 inline auto xchunked_view<E>::shape() const noexcept -> const shape_type&
214 inline auto xchunked_view<E>::chunk_shape() const noexcept -> const shape_type&
216 return m_chunk_shape;
220 inline auto xchunked_view<E>::grid_size() const noexcept -> size_type
226 inline auto xchunked_view<E>::grid_shape() const noexcept -> const shape_type&
232 inline auto xchunked_view<E>::expression() noexcept -> expression_type&
238 inline auto xchunked_view<E>::expression() const noexcept -> const expression_type&
244 inline auto xchunked_view<E>::chunk_begin() -> chunk_iterator
246 shape_type chunk_index(m_shape.size(), size_type(0));
247 return chunk_iterator(*
this, std::move(chunk_index), 0u);
251 inline auto xchunked_view<E>::chunk_end() -> chunk_iterator
253 return chunk_iterator(*
this, shape_type(grid_shape()), grid_size());
257 inline auto xchunked_view<E>::chunk_begin() const -> const_chunk_iterator
259 shape_type chunk_index(m_shape.size(), size_type(0));
260 return const_chunk_iterator(*
this, std::move(chunk_index), 0u);
264 inline auto xchunked_view<E>::chunk_end() const -> const_chunk_iterator
266 return const_chunk_iterator(*
this, shape_type(grid_shape()), grid_size());
270 inline auto xchunked_view<E>::chunk_cbegin() const -> const_chunk_iterator
272 return chunk_begin();
276 inline auto xchunked_view<E>::chunk_cend() const -> const_chunk_iterator
281 template <
class E,
class S>
282 inline xchunked_view<E> as_chunked(E&& e, S&& chunk_shape)
284 return xchunked_view<E>(std::forward<E>(e), std::forward<S>(chunk_shape));
288 inline xchunked_view<E> as_chunked(E&& e)
290 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.