1 #ifndef TILEDARRAY_CONVERSIONS_DENSETOSPARSE_H__INCLUDED
2 #define TILEDARRAY_CONVERSIONS_DENSETOSPARSE_H__INCLUDED
4 #include "../dist_array.h"
13 template <
typename Tile,
typename ResultPolicy = SparsePolicy,
15 std::enable_if_t<!is_dense_v<ResultPolicy> && is_dense_v<ArgPolicy>,
16 DistArray<Tile, ResultPolicy>>
19 using ShapeType =
typename ResultPolicy::shape_type;
20 using ShapeValueType =
typename ShapeType::value_type;
24 dense_array.
trange().tiles_range(), 0.0);
26 const auto end = dense_array.
end();
27 const auto begin = dense_array.
begin();
28 for (
auto it = begin; it != end; ++it) {
30 norm(it->get(), tile_norms[it.ordinal()]);
35 ShapeType shape(dense_array.
world(), tile_norms, dense_array.
trange());
37 ArrayType sparse_array(dense_array.
world(), dense_array.
trange(), shape);
42 for (
auto it = begin; it != end; ++it) {
43 const auto ord = it.ordinal();
44 if (!sparse_array.is_zero(ord)) {
45 sparse_array.set(ord, it->get().clone());
53 template <
typename Tile,
typename Policy>