Skip to content

Commit 8bdc40f

Browse files
committed
tensor: permuting axpy_to initializes an empty target
Tensor::axpy_to(arg, factor, perm) went straight to inplace_binary, which asserts the target is non-empty. The first contribution into an unallocated tensor -- e.g. a tensor-of-tensors contraction result inner cell, when the inner op carries a permutation -- therefore aborted at kernels.h:395. Mirror the non-permuting axpy_to overload: when the target is empty, initialize it to factor * (perm ^ arg). Fixes the einsum_manual/different_nested_ranks "ik;mn,j->ijk;nm" case (mixed-nested-rank outer product with an inner-mode permutation) and drops its TODO(tot-einsum-empty-result) breadcrumb.
1 parent 6e6e8ef commit 8bdc40f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/TiledArray/tensor/tensor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,15 @@ class Tensor {
22432243
return *this;
22442244
} else {
22452245
auto permuted = right.permute(perm);
2246+
if (empty()) {
2247+
// first contribution into an unallocated target (e.g. a contraction
2248+
// result inner cell): initialize to factor * (perm ^ arg) rather
2249+
// than asserting non-empty in inplace_binary -- mirrors the
2250+
// non-permuting axpy_to overload above.
2251+
*this = detail::clone_or_cast<Tensor>(permuted);
2252+
this->scale_to(factor);
2253+
return *this;
2254+
}
22462255
return inplace_binary(
22472256
permuted, [factor](auto& MADNESS_RESTRICT l, const auto& r) {
22482257
using L = std::remove_reference_t<decltype(l)>;

tests/einsum.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,6 @@ BOOST_AUTO_TEST_CASE(equal_nested_ranks) {
284284
{3, 2}));
285285
}
286286

287-
// TODO(tot-einsum-empty-result): this case intermittently aborts at
288-
// tensor/kernels.h:395 ("!empty(result, tensors...)" / "0 of N tiles set").
289-
// Pre-existing on feature/arena_tensor HEAD -- reproduces with the arena/ToT
290-
// work stashed, and crashes deterministically when einsum_manual is run as a
291-
// standalone --run_test subset. Root cause not yet diagnosed.
292287
BOOST_AUTO_TEST_CASE(different_nested_ranks) {
293288
using ArrayT = TA::DistArray<TA::Tensor<int>>;
294289
using ArrayToT = TA::DistArray<TA::Tensor<TA::Tensor<int>>>;

0 commit comments

Comments
 (0)