Skip to content

Commit

Permalink
make array given range of local tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
asadchev committed Aug 3, 2022
1 parent 4f1f836 commit e967606
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/TiledArray/dist_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <madness/world/parallel_archive.h>
#include <cstdlib>
#include <tuple>

namespace TiledArray {

Expand Down Expand Up @@ -1708,6 +1709,38 @@ auto norm2(const DistArray<Tile, Policy>& a) {
return std::sqrt(squared_norm(a));
}

template<typename Array, typename Tiles>
Array make_array(
World &world,
const detail::trange_t<Array> &tiled_range,
Tiles begin, Tiles end)
{
Array array;
using Tuple = std::remove_reference_t<decltype(*begin)>;
using Index = std::tuple_element_t<0,Tuple>;
using shape_type = typename Array::shape_type;
if constexpr (shape_type::is_dense()) {
array = Array(world, tiled_range);
}
else {
std::vector< std::pair<Index,float> > tile_norms;
for (Tiles it = begin; it != end; ++it) {
auto [index,tile] = *it;
tile_norms.push_back({index,tile.norm()});
}
shape_type shape(world, tile_norms, tiled_range);
array = Array(world, tiled_range, shape);
}
for (Tiles it = begin; it != end; ++it) {
auto [index,tile] = *it;
if (array.is_zero(index)) continue;
array.set(index,tile);
}
return array;
}



} // namespace TiledArray

// serialization
Expand Down

0 comments on commit e967606

Please sign in to comment.