Skip to content

Commit 96d3096

Browse files
committed
Support initialized list for chunked_array shapes
1 parent 1c9b74a commit 96d3096

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

include/xtensor/xchunked_array.hpp

Lines changed: 15 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,18 @@ 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+
sh_type sh = xtl::make_sequence<sh_type>(shape.size());
342+
std::copy(shape.begin(), shape.end(), sh.begin());
343+
sh_type ch_sh = xtl::make_sequence<sh_type>(chunk_shape.size());
344+
std::copy(chunk_shape.begin(), chunk_shape.end(), ch_sh.begin());
345+
using chunk_storage = xarray<xarray<T, L>>;
346+
return xchunked_array<chunk_storage, EXT>(chunk_storage(), std::move(sh), std::move(ch_sh), chunk_memory_layout);
347+
}
348+
334349
template <layout_type L, class EXT, class E, class S>
335350
inline xchunked_array<xarray<xarray<typename E::value_type>>, EXT>
336351
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)