Skip to content

Commit

Permalink
Merge pull request #497 from ValeevGroup/gaudel/fix/zero_tensor_check…
Browse files Browse the repository at this point in the history
…_ToTxT

Zero inner tensors in ToT times T to give ToT checked.
  • Loading branch information
evaleev authored Dec 20, 2024
2 parents fb5d5b8 + bea7b74 commit a398b7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/TiledArray/einsum/tiledarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ auto einsum(expressions::TsrExpr<ArrayA_> A, expressions::TsrExpr<ArrayB_> B,
using ResultTensor = typename ArrayC::value_type;
using ResultShape = typename ArrayC::shape_type;

auto const& tnsrExprA = A;
auto const& tnsrExprB = B;
auto const &tnsrExprA = A;
auto const &tnsrExprB = B;

auto a = std::get<0>(Einsum::idx(A));
auto b = std::get<0>(Einsum::idx(B));
Expand Down Expand Up @@ -489,12 +489,12 @@ auto einsum(expressions::TsrExpr<ArrayA_> A, expressions::TsrExpr<ArrayB_> B,

auto sum_tot_2_tos = [](auto const &tot) {
using tot_t = std::remove_reference_t<decltype(tot)>;
typename tot_t::value_type result(
tot.range(), [tot](auto &&ix) {
if (!tot(ix).empty())
return tot(ix).sum();
else return typename tot_t::numeric_type{};
});
typename tot_t::value_type result(tot.range(), [tot](auto &&ix) {
if (!tot(ix).empty())
return tot(ix).sum();
else
return typename tot_t::numeric_type{};
});
return result;
};

Expand Down
9 changes: 6 additions & 3 deletions src/TiledArray/tensor/kernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ inline void inplace_tensor_op(Op&& op, TR& result, const Ts&... tensors) {

auto volume = result.total_size();
for (decltype(volume) ord = 0; ord < volume; ++ord) {
if constexpr (is_tensor_of_tensor_v<TR, Ts...>)
if constexpr (is_tensor_of_tensor_v<TR>)
if (result.data()[ord].range().volume() == 0) continue;
if constexpr (is_tensor_of_tensor_v<Ts...>)
if (((tensors.data()[ord].range().volume() == 0) || ...)) continue;
if constexpr (std::is_invocable_r_v<void, Op, typename TR::value_type&,
typename Ts::value_type...>)
Expand Down Expand Up @@ -997,8 +999,9 @@ auto tensor_reduce(ReduceOp&& reduce_op, JoinOp&& join_op,

auto result = identity;
for (std::remove_cv_t<decltype(volume)> ord = 0ul; ord < volume; ++ord) {
if (tensor1.data()[ord].range().volume() == 0
|| ((tensors.data()[ord].range().volume() == 0) || ...)) continue;
if (tensor1.data()[ord].range().volume() == 0 ||
((tensors.data()[ord].range().volume() == 0) || ...))
continue;
auto temp = tensor_reduce(reduce_op, join_op, identity, tensor1.data()[ord],
tensors.data()[ord]...);
join_op(result, temp);
Expand Down

0 comments on commit a398b7a

Please sign in to comment.