Skip to content

Commit c6ae887

Browse files
authored
Merge pull request #2258 from davidbrochart/chunked_shape
Support initialized list for chunked_array shapes
2 parents 629f77c + 4d5d52a commit c6ae887

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

include/xtensor/xchunked_array.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ namespace xt
234234
template <class T, layout_type L = XTENSOR_DEFAULT_LAYOUT, class EXT = empty_extension, class S>
235235
xchunked_array<xarray<xarray<T>>, EXT> chunked_array(S&& shape, S&& chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
236236

237+
template <class T, layout_type L = XTENSOR_DEFAULT_LAYOUT, class EXT = empty_extension, class S>
238+
xchunked_array<xarray<xarray<T>>, EXT> chunked_array(std::initializer_list<S> shape, std::initializer_list<S> chunk_shape, layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
239+
237240
/**
238241
* Creates an in-memory chunked array.
239242
* This function returns a ``xchunked_array<xarray<T>>`` initialized from an expression.
@@ -331,6 +334,15 @@ namespace xt
331334
return xchunked_array<chunk_storage, EXT>(chunk_storage(), std::forward<S>(shape), std::forward<S>(chunk_shape), chunk_memory_layout);
332335
}
333336

337+
template <class T, layout_type L, class EXT, class S>
338+
xchunked_array<xarray<xarray<T>>, EXT> chunked_array(std::initializer_list<S> shape, std::initializer_list<S> chunk_shape, layout_type chunk_memory_layout)
339+
{
340+
using sh_type = std::vector<std::size_t>;
341+
auto sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(shape);
342+
auto ch_sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(chunk_shape);
343+
return chunked_array<T, L, EXT, sh_type>(std::move(sh), std::move(ch_sh), chunk_memory_layout);
344+
}
345+
334346
template <layout_type L, class EXT, class E, class S>
335347
inline xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
336348
chunked_array(const xexpression<E>& e, S&& chunk_shape, layout_type chunk_memory_layout)

test/test_xchunked_array.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ namespace xt
2020

2121
TEST(xchunked_array, indexed_access)
2222
{
23-
std::vector<size_t> shape = {10, 10, 10};
24-
std::vector<size_t> chunk_shape = {2, 3, 4};
25-
auto a = chunked_array<double>(shape, chunk_shape);
23+
auto a = chunked_array<double>({10, 10, 10}, {2, 3, 4});
2624

2725
std::vector<size_t> idx = {3, 9, 8};
2826
double val;

0 commit comments

Comments
 (0)