Skip to content

Commit 07bbe7f

Browse files
authored
Merge pull request #2211 from davidbrochart/chunk_memory_layout
Add chunk_memory_layout to chunked_array factory
2 parents c76e293 + 497d66e commit 07bbe7f

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

include/xtensor/xchunked_array.hpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace xt
124124
static constexpr bool contiguous_layout = false;
125125

126126
template <class S>
127-
xchunked_array(chunk_storage_type&& chunks, S&& shape, S&& chunk_shape);
127+
xchunked_array(chunk_storage_type&& chunks, S&& shape, S&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
128128
~xchunked_array() = default;
129129

130130
xchunked_array(const xchunked_array&) = default;
@@ -134,10 +134,10 @@ namespace xt
134134
xchunked_array& operator=(xchunked_array&&) = default;
135135

136136
template <class E>
137-
xchunked_array(const xexpression<E>&e , chunk_storage_type&& chunks);
137+
xchunked_array(const xexpression<E>&e , chunk_storage_type&& chunks, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
138138

139139
template <class E, class S>
140-
xchunked_array(const xexpression<E>& e, chunk_storage_type&& chunks, S&& chunk_shape);
140+
xchunked_array(const xexpression<E>& e, chunk_storage_type&& chunks, S&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
141141

142142
template <class E>
143143
xchunked_array& operator=(const xexpression<E>& e);
@@ -195,7 +195,7 @@ namespace xt
195195
using dynamic_indexes_type = std::pair<std::vector<std::size_t>, std::vector<std::size_t>>;
196196

197197
template <class S1, class S2>
198-
void resize(S1&& shape, S2&& chunk_shape);
198+
void resize(S1&& shape, S2&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
199199

200200
template <class... Idxs>
201201
indexes_type<Idxs...> get_indexes(Idxs... idxs) const;
@@ -220,16 +220,16 @@ namespace xt
220220
template<class E>
221221
constexpr bool is_chunked(const xexpression<E>& e);
222222

223-
template <class T, class EXT = empty_extension, class S>
224-
xchunked_array<xarray<xarray<T>>, EXT> chunked_array(S&& shape, S&& chunk_shape);
223+
template <class T, layout_type L = XTENSOR_DEFAULT_LAYOUT, class EXT = empty_extension, class S>
224+
xchunked_array<xarray<xarray<T>>, EXT> chunked_array(S&& shape, S&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
225225

226-
template <class EXT = empty_extension, class E, class S>
226+
template <layout_type L = XTENSOR_DEFAULT_LAYOUT, class EXT = empty_extension, class E, class S>
227227
xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
228-
chunked_array(const xexpression<E>& e, S&& chunk_shape);
228+
chunked_array(const xexpression<E>& e, S&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
229229

230-
template <class EXT = empty_extension, class E>
230+
template <layout_type L = XTENSOR_DEFAULT_LAYOUT, class EXT = empty_extension, class E>
231231
xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
232-
chunked_array(const xexpression<E>&e);
232+
chunked_array(const xexpression<E>&e, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
233233

234234
/*******************************
235235
* chunk_helper implementation *
@@ -251,12 +251,12 @@ namespace xt
251251
}
252252

253253
template <class S1, class S2>
254-
static void resize(E& chunks, const S1& container_shape, const S2& chunk_shape)
254+
static void resize(E& chunks, const S1& container_shape, const S2& chunk_shape, layout_type chunk_memory_layout)
255255
{
256256
chunks.resize(container_shape);
257257
for(auto& c: chunks)
258258
{
259-
c.resize(chunk_shape);
259+
c.resize(chunk_shape, chunk_memory_layout);
260260
}
261261
}
262262
};
@@ -271,9 +271,9 @@ namespace xt
271271
}
272272

273273
template <class S1, class S2>
274-
static void resize(E& chunks, const S1& container_shape, const S2& chunk_shape)
274+
static void resize(E& chunks, const S1& container_shape, const S2& chunk_shape, layout_type chunk_memory_layout)
275275
{
276-
chunks.resize(container_shape, chunk_shape);
276+
chunks.resize(container_shape, chunk_shape, chunk_memory_layout);
277277
}
278278
};
279279

@@ -288,27 +288,27 @@ namespace xt
288288
return return_type::value;
289289
}
290290

291-
template <class T, class EXT, class S>
292-
inline xchunked_array<xarray<xarray<T>>, EXT> chunked_array(S&& shape, S&& chunk_shape)
291+
template <class T, layout_type L, class EXT, class S>
292+
inline xchunked_array<xarray<xarray<T>>, EXT> chunked_array(S&& shape, S&& chunk_shape, layout_type chunk_memory_layout)
293293
{
294-
using chunk_storage = xarray<xarray<T>>;
295-
return xchunked_array<chunk_storage, EXT>(chunk_storage(), std::forward<S>(shape), std::forward<S>(chunk_shape));
294+
using chunk_storage = xarray<xarray<T, L>>;
295+
return xchunked_array<chunk_storage, EXT>(chunk_storage(), std::forward<S>(shape), std::forward<S>(chunk_shape), chunk_memory_layout);
296296
}
297297

298-
template <class EXT, class E, class S>
298+
template <layout_type L, class EXT, class E, class S>
299299
inline xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
300-
chunked_array(const xexpression<E>& e, S&& chunk_shape)
300+
chunked_array(const xexpression<E>& e, S&& chunk_shape, layout_type chunk_memory_layout)
301301
{
302-
using chunk_storage = xarray<xarray<typename E::value_type>>;
303-
return xchunked_array<chunk_storage, EXT>(e, chunk_storage(), std::forward<S>(chunk_shape));
302+
using chunk_storage = xarray<xarray<typename E::value_type, L>>;
303+
return xchunked_array<chunk_storage, EXT>(e, chunk_storage(), std::forward<S>(chunk_shape), chunk_memory_layout);
304304
}
305305

306-
template <class EXT, class E>
306+
template <layout_type L, class EXT, class E>
307307
inline xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
308-
chunked_array(const xexpression<E>& e)
308+
chunked_array(const xexpression<E>& e, layout_type chunk_memory_layout)
309309
{
310-
using chunk_storage = xarray<xarray<typename E::value_type>>;
311-
return xchunked_array<chunk_storage, EXT>(e, chunk_storage());
310+
using chunk_storage = xarray<xarray<typename E::value_type, L>>;
311+
return xchunked_array<chunk_storage, EXT>(e, chunk_storage(), chunk_memory_layout);
312312
}
313313

314314
/************************************
@@ -421,25 +421,25 @@ namespace xt
421421

422422
template <class CS, class EX>
423423
template <class S>
424-
inline xchunked_array<CS, EX>::xchunked_array(CS&& chunks, S&& shape, S&& chunk_shape)
424+
inline xchunked_array<CS, EX>::xchunked_array(CS&& chunks, S&& shape, S&& chunk_shape, layout_type chunk_memory_layout)
425425
: m_chunks(std::move(chunks))
426426
{
427-
resize(std::forward<S>(shape), std::forward<S>(chunk_shape));
427+
resize(std::forward<S>(shape), std::forward<S>(chunk_shape), chunk_memory_layout);
428428
}
429429

430430
template <class CS, class EX>
431431
template <class E>
432-
inline xchunked_array<CS, EX>::xchunked_array(const xexpression<E>& e, CS&& chunks)
433-
: xchunked_array(e, std::move(chunks), detail::chunk_helper<E>::chunk_shape(e))
432+
inline xchunked_array<CS, EX>::xchunked_array(const xexpression<E>& e, CS&& chunks, layout_type chunk_memory_layout)
433+
: xchunked_array(e, std::move(chunks), detail::chunk_helper<E>::chunk_shape(e), chunk_memory_layout)
434434
{
435435
}
436436

437437
template <class CS, class EX>
438438
template <class E, class S>
439-
inline xchunked_array<CS, EX>::xchunked_array(const xexpression<E>& e, CS&& chunks, S&& chunk_shape)
439+
inline xchunked_array<CS, EX>::xchunked_array(const xexpression<E>& e, CS&& chunks, S&& chunk_shape, layout_type chunk_memory_layout)
440440
: m_chunks(std::move(chunks))
441441
{
442-
resize(e.derived_cast().shape(), std::forward<S>(chunk_shape));
442+
resize(e.derived_cast().shape(), std::forward<S>(chunk_shape), chunk_memory_layout);
443443
semantic_base::assign_xexpression(e);
444444
}
445445

@@ -570,7 +570,7 @@ namespace xt
570570

571571
template <class CS, class EX>
572572
template <class S1, class S2>
573-
inline void xchunked_array<CS, EX>::resize(S1&& shape, S2&& chunk_shape)
573+
inline void xchunked_array<CS, EX>::resize(S1&& shape, S2&& chunk_shape, layout_type chunk_memory_layout)
574574
{
575575
// compute chunk number in each dimension (shape_of_chunks)
576576
std::vector<std::size_t> shape_of_chunks(shape.size());
@@ -588,7 +588,7 @@ namespace xt
588588
}
589589
);
590590

591-
detail::chunk_helper<CS>::resize(m_chunks, shape_of_chunks, chunk_shape);
591+
detail::chunk_helper<CS>::resize(m_chunks, shape_of_chunks, chunk_shape, chunk_memory_layout);
592592

593593
m_shape = xtl::forward_sequence<shape_type, S1>(shape);
594594
m_chunk_shape = xtl::forward_sequence<shape_type, S2>(chunk_shape);

0 commit comments

Comments
 (0)