26 #ifndef TILEDARRAY_SPECIALARRAYS_DIAGONAL_ARRAY_H__INCLUDED 27 #define TILEDARRAY_SPECIALARRAYS_DIAGONAL_ARRAY_H__INCLUDED 45 auto max_low = *std::max_element(std::begin(lo), std::end(lo));
46 auto min_up = *std::min_element(std::begin(up), std::end(up));
50 if (max_low < min_up) {
51 return Range({max_low}, {min_up});
62 auto min_dim_len = *std::min_element(std::begin(ext), std::end(ext));
64 auto ndim = trange.
rank();
68 while(diag_elem < min_dim_len){
70 auto tile_idx = trange.
element_to_tile(std::vector<int>(ndim, diag_elem));
78 float t_norm = std::sqrt(val * val * d_range.volume());
79 shape(tile_idx) = t_norm;
82 diag_elem = d_range.upbound_data()[0];
89 template<
typename Array,
typename T>
91 auto const &trange = A.
trange();
92 const auto ndims = trange.rank();
95 auto tile_task = [val, &trange, ndims](
unsigned long ord){
96 auto rng = trange.make_tile_range(ord);
103 if (diags.volume() > 0) {
106 auto diag_lo = diags.lobound_data()[0];
107 auto diag_hi = diags.upbound_data()[0];
108 for (
auto elem = diag_lo; elem < diag_hi; ++elem) {
109 tile(std::vector<int>(ndims, elem)) = val;
118 const auto vol = trange.tiles_range().volume();
119 for (
auto ord = 0ul; ord < vol; ++ord) {
121 auto tile_future = A.
world().taskq.add(tile_task, ord);
122 A.
set(ord, tile_future);
137 template <
typename T>
157 template <
typename T>
173 template <
typename T,
typename Policy>
175 std::enable_if_t<std::is_same<Policy, DensePolicy>::value, Policy>
178 return dense_diagonal_array<T>(world, trange, val);
181 template <
typename T,
typename Policy>
183 std::enable_if_t<std::is_same<Policy, SparsePolicy>::value, Policy>
186 return sparse_diagonal_array<T>(world, trange, val);
191 #endif // TILEDARRAY_SPECIALARRAYS_DIAGONAL_ARRAY_H__INCLUDED A (hyperrectangular) interval on , space of integer n-indices.
DistArray< Tensor< T >, SparsePolicy > sparse_diagonal_array(World &world, TiledRange const &trange, T val=1)
size_array lobound() const
Range lower bound accessor.
std::size_t rank() const
The rank accessor.
std::enable_if< detail::is_input_iterator< InIter >::value >::type set(const Index &i, InIter first)
Set a tile and fill it using a sequence.
An N-dimensional tensor object.
Tensor< float > diagonal_shape(TiledRange const &trange, T val)
const trange_type & trange() const
Tiled range accessor.
Range diagonal_range(Range const &rng)
bool is_zero(const Index &i) const
Check for zero tiles.
DistArray< Tensor< T >, DensePolicy > dense_diagonal_array(World &world, TiledRange const &trange, T val=1)
range_type make_tile_range(const size_type &i) const
Construct a range for the tile indexed by the given ordinal index.
const range_type & tiles_range() const
Access the tile range.
World & world() const
World accessor.
DistArray< Tensor< T >, std::enable_if_t< std::is_same< Policy, DensePolicy >::value, Policy >> diagonal_array(World &world, TiledRange const &trange, T val=1)
bool is_local(const Index &i) const
Check if the tile at index i is stored locally.
Range data of a tiled array.
size_array upbound() const
Range upper bound accessor.
extent_type extent() const
Range extent accessor.
std::enable_if<! std::is_integral< Index >::value, typename range_type::index >::type element_to_tile(const Index &index) const
Convert an element index to a tile index.
const range_type & elements_range() const
Access the element range.
void write_tiles_to_array(Array &A, T val)