@@ -98,6 +98,15 @@ namespace xt
9898 const std::string& directory,
9999 std::size_t pool_size,
100100 layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
101+
102+ template <class S , class T >
103+ xchunk_store_manager (S&& shape,
104+ S&& chunk_shape,
105+ const std::string& directory,
106+ std::size_t pool_size,
107+ const T& init_value,
108+ layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
109+
101110 ~xchunk_store_manager () = default ;
102111
103112 xchunk_store_manager (const xchunk_store_manager&) = default ;
@@ -157,6 +166,15 @@ namespace xt
157166 template <class ... Idxs>
158167 std::array<std::size_t , sizeof ...(Idxs)> get_indexes (Idxs... idxs) const ;
159168
169+ template <class S , class T >
170+ void initialize (S&& shape,
171+ S&& chunk_shape,
172+ const std::string& directory,
173+ bool init,
174+ const T& init_value,
175+ std::size_t pool_size,
176+ layout_type chunk_memory_layout);
177+
160178 using chunk_pool_type = std::vector<EC>;
161179 using index_pool_type = std::vector<shape_type>;
162180
@@ -175,6 +193,15 @@ namespace xt
175193 std::size_t pool_size = 1 ,
176194 layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
177195
196+ template <class T , class IOH , layout_type L = XTENSOR_DEFAULT_LAYOUT, class IP = xindex_path, class EXT = empty_extension, class S >
197+ xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
198+ chunked_file_array (S&& shape,
199+ S&& chunk_shape,
200+ const std::string& path,
201+ const T& init_value,
202+ std::size_t pool_size = 1 ,
203+ layout_type chunk_memory_layout = XTENSOR_DEFAULT_LAYOUT);
204+
178205 template <class IOH , layout_type L = XTENSOR_DEFAULT_LAYOUT, class IP = xindex_path, class EXT = empty_extension, class E , class S >
179206 xchunked_array<xchunk_store_manager<xfile_array<typename E::value_type, IOH, L>, IP>, EXT>
180207 chunked_file_array (const xexpression<E>& e,
@@ -252,6 +279,15 @@ namespace xt
252279 return xchunked_array<chunk_storage, EXT>(std::move (chunks), std::forward<S>(shape), std::forward<S>(chunk_shape));
253280 }
254281
282+ template <class T , class IOH , layout_type L, class IP , class EXT , class S >
283+ inline xchunked_array<xchunk_store_manager<xfile_array<T, IOH, L>, IP>, EXT>
284+ 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)
285+ {
286+ using chunk_storage = xchunk_store_manager<xfile_array<T, IOH, L>, IP>;
287+ chunk_storage chunks (shape, chunk_shape, path, pool_size, init_value, chunk_memory_layout);
288+ return xchunked_array<chunk_storage, EXT>(std::move (chunks), std::forward<S>(shape), std::forward<S>(chunk_shape));
289+ }
290+
255291 template <class IOH , layout_type L, class IP , class EXT , class E , class S >
256292 inline xchunked_array<xchunk_store_manager<xfile_array<typename E::value_type, IOH, L>, IP>, EXT>
257293 chunked_file_array (const xexpression<E>& e, S&& chunk_shape, const std::string& path, std::size_t pool_size, layout_type chunk_memory_layout)
@@ -283,13 +319,47 @@ namespace xt
283319 layout_type chunk_memory_layout)
284320 : m_shape(shape)
285321 , m_unload_index(0u )
322+ {
323+ initialize (shape, chunk_shape, directory, false , 0 , pool_size, chunk_memory_layout);
324+ }
325+
326+ template <class EC , class IP >
327+ template <class S , class T >
328+ inline xchunk_store_manager<EC, IP>::xchunk_store_manager(S&& shape,
329+ S&& chunk_shape,
330+ const std::string& directory,
331+ std::size_t pool_size,
332+ const T& init_value,
333+ layout_type chunk_memory_layout)
334+ : m_shape(shape)
335+ , m_unload_index(0u )
336+ {
337+ initialize (shape, chunk_shape, directory, true , init_value, pool_size, chunk_memory_layout);
338+ }
339+
340+ template <class EC , class IP >
341+ template <class S , class T >
342+ inline void xchunk_store_manager<EC, IP>::initialize(S&& shape,
343+ S&& chunk_shape,
344+ const std::string& directory,
345+ bool init,
346+ const T& init_value,
347+ std::size_t pool_size,
348+ layout_type chunk_memory_layout)
286349 {
287350 if (pool_size == SIZE_MAX)
288351 {
289352 // as many "physical" chunks in the pool as there are "logical" chunks
290353 pool_size = size ();
291354 }
292- m_chunk_pool.resize (pool_size, EC (" " , xfile_mode::init_on_fail));
355+ if (init)
356+ {
357+ m_chunk_pool.resize (pool_size, EC (" " , xfile_mode::init_on_fail, init_value));
358+ }
359+ else
360+ {
361+ m_chunk_pool.resize (pool_size, EC (" " , xfile_mode::init_on_fail));
362+ }
293363 m_index_pool.resize (pool_size);
294364 // resize the pool chunks
295365 for (auto & chunk: m_chunk_pool)
0 commit comments