Skip to content

Commit cd03d91

Browse files
authored
Merge pull request #131 from davidbrochart/chunked_shape
Support initialized list for chunked_file_array shapes
2 parents 4940c50 + 64e9bf7 commit cd03d91

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

include/xtensor-io/xchunk_store_manager.hpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ namespace xt
226226
std::size_t pool_size = 1,
227227
layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
228228

229+
template <class T, class IOH, layout_type L = XTENSOR_DEFAULT_LAYOUT, class IP = xindex_path, class EXT = empty_extension, class S>
230+
xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
231+
chunked_file_array(std::initializer_list<S> shape,
232+
std::initializer_list<S> chunk_shape,
233+
const std::string& path,
234+
std::size_t pool_size = 1,
235+
layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
236+
229237
/**
230238
* Creates a chunked file array.
231239
* This function returns an uninitialized ``xchunked_array<xchunk_store_manager<xfile_array<T, IOH>>>``.
@@ -254,6 +262,15 @@ namespace xt
254262
std::size_t pool_size = 1,
255263
layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
256264

265+
template <class T, class IOH, layout_type L = XTENSOR_DEFAULT_LAYOUT, class IP = xindex_path, class EXT = empty_extension, class S>
266+
xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
267+
chunked_file_array(std::initializer_list<S> shape,
268+
std::initializer_list<S> chunk_shape,
269+
const std::string& path,
270+
const T& init_value,
271+
std::size_t pool_size = 1,
272+
layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
273+
257274
/**
258275
* Creates a chunked file array.
259276
* This function returns a ``xchunked_array<xchunk_store_manager<xfile_array<T, IOH>>>`` initialized from an expression.
@@ -367,13 +384,33 @@ namespace xt
367384

368385
template <class T, class IOH, layout_type L, class IP, class EXT, class S>
369386
inline xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
370-
chunked_file_array(S&& shape, S&& chunk_shape, const std::string& path, const T& init_value,std::size_t pool_size, layout_type chunk_memory_layout)
387+
chunked_file_array(std::initializer_list<S> shape, std::initializer_list<S> chunk_shape, const std::string& path, std::size_t pool_size, layout_type chunk_memory_layout)
388+
{
389+
using sh_type = std::vector<std::size_t>;
390+
auto sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(shape);
391+
auto ch_sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(chunk_shape);
392+
return chunked_file_array<T, IOH, L, IP, EXT, sh_type>(std::move(sh), std::move(ch_sh), path, pool_size, chunk_memory_layout);
393+
}
394+
395+
template <class T, class IOH, layout_type L, class IP, class EXT, class S>
396+
inline xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
397+
chunked_file_array(S&& shape, S&& chunk_shape, const std::string& path, const T& init_value, std::size_t pool_size, layout_type chunk_memory_layout)
371398
{
372399
using chunk_storage = xchunk_store_manager<xfile_array<T, IOH, L>, IP>;
373400
chunk_storage chunks(shape, chunk_shape, path, pool_size, init_value, chunk_memory_layout);
374401
return xchunked_array<chunk_storage, EXT>(std::move(chunks), std::forward<S>(shape), std::forward<S>(chunk_shape));
375402
}
376403

404+
template <class T, class IOH, layout_type L, class IP, class EXT, class S>
405+
inline xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
406+
chunked_file_array(std::initializer_list<S> shape, std::initializer_list<S> chunk_shape, const std::string& path, const T& init_value, std::size_t pool_size, layout_type chunk_memory_layout)
407+
{
408+
using sh_type = std::vector<std::size_t>;
409+
auto sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(shape);
410+
auto ch_sh = xtl::forward_sequence<sh_type, std::initializer_list<S>>(chunk_shape);
411+
return chunked_file_array<T, IOH, L, IP, EXT, sh_type>(std::move(sh), std::move(ch_sh), path, init_value, pool_size, chunk_memory_layout);
412+
}
413+
377414
template <class IOH, layout_type L, class IP, class EXT, class E, class S>
378415
inline xchunked_array<xchunk_store_manager<xfile_array<typename E::value_type, IOH, L>, IP>, EXT>
379416
chunked_file_array(const xexpression<E>& e, S&& chunk_shape, const std::string& path, std::size_t pool_size, layout_type chunk_memory_layout)

include/xtensor-io/xfile_array.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ namespace xt
675675
if (m_init)
676676
{
677677
std::fill(m_storage.begin(), m_storage.end(), m_init_value);
678+
m_dirty = true;
678679
}
679680
}
680681
}

test/test_xchunk_store_manager.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@ namespace xt
121121
EXPECT_EQ(v, init_value);
122122
}
123123
}
124+
125+
TEST(xchunked_array, shape_initializer_list)
126+
{
127+
std::vector<size_t> shape = {4, 4};
128+
std::vector<size_t> chunk_shape = {2, 2};
129+
auto a = chunked_file_array<double, xio_disk_handler<xio_binary_config>>({4, 4}, {2, 2}, "files3");
130+
for (auto v: a)
131+
{
132+
EXPECT_EQ(v, 5.5);
133+
}
134+
}
124135
}

0 commit comments

Comments
 (0)