26 #ifndef TILEDARRAY_CONVERSIONS_TRUNCATE_H__INCLUDED
27 #define TILEDARRAY_CONVERSIONS_TRUNCATE_H__INCLUDED
34 template <
typename,
typename>
45 template <
typename Tile,
typename Policy>
46 inline std::enable_if_t<is_dense_v<Policy>,
void>
truncate(
48 typename Policy::shape_type::value_type = 0) {}
55 template <
typename Tile,
typename Policy>
56 inline std::enable_if_t<!is_dense_v<Policy>,
void>
truncate(
58 typename Policy::shape_type::value_type thresh =
59 Policy::shape_type::threshold()) {
61 const typename Policy::shape_type::value_type previous_thresh =
62 Policy::shape_type::threshold();
63 const auto need_to_change_thresh = (thresh != previous_thresh);
64 if (need_to_change_thresh)
65 array.
world().gop.serial_invoke(
66 [thresh] { Policy::shape_type::threshold(thresh); });
68 array =
foreach (array,
69 [](value_type& result_tile,
const value_type& arg_tile) ->
70 typename Policy::shape_type::value_type {
72 typename Policy::shape_type::value_type;
73 result_type arg_tile_norm;
74 norm(arg_tile, arg_tile_norm);
75 result_tile = arg_tile;
78 if (need_to_change_thresh)
79 array.
world().gop.serial_invoke(
80 [previous_thresh] { Policy::shape_type::threshold(previous_thresh); });
85 #endif // TILEDARRAY_CONVERSIONS_TRUNCATE_H__INCLUDED