Repository navigation
Commit 95d7a2a
committed
Tensor: an empty-operand fast path must own its copy, not alias the source
`detail::clone_or_cast<Tensor>(right)` deep-copies only when `Right` *is*
`Tensor`, where it calls `clone()`. For any other nested-tensor `Right` -- most
importantly the `TensorInterface<..., BlockRange>` that `Tensor::block()`
yields -- it falls into a generic branch that `std::copy`s the *cells*, and a
cell is a shallow handle: an `ArenaTensor` is a non-owning view, and
`TA::Tensor` is itself reference-counted. The copy therefore shared storage
with `right`, and the empty-`this` fast paths mutate it immediately afterwards:
t.subt_to(p.block(...)); // neg_to() -> p's cells negated
t.add_to(p.block(...), 3.0); // scale_to() -> p's cells scaled
Both corrupt a const source operand. The value-returning `add`/`subt`
empty-left exits have the same defect one step removed: they hand the caller a
result aliasing `right`, so the caller's first mutation writes through.
Route all eight of these through a new `owning_copy_of`, which for a nested
tensor builds the copy with `arena_trivial_unary` -- a fresh slab, elements
copied, no shared cells -- and keeps `clone_or_cast` for the flat and
same-type cases where it is already a deep copy. Being range-addressed, that
kernel also handles a strided source correctly.
This is reachable only because the null-cell guard earlier in this branch made
`add_to`/`subt_to` compile for a non-contiguous `Right` at all; previously they
failed to instantiate. The unscaled `add_to`'s aliasing predates that and is
fixed here too.
Also in this commit:
- `arena_trivial_scaled` joins its unary and binary siblings in addressing
operands through `arena_cell_offset` and taking counts from the `total_size`
CPO. It still used `nbatch()` and linear `data()[ord]`, so the mixed
`Tensor<ArenaTensor>` +/-/* `Tensor<scalar>` overloads failed to compile
against a `block()` operand under TA_ASSERT_THROW and silently read the wrong
scalars under TA_ASSERT_IGNORE -- a TA_ASSERT_POLICY-dependent difference.
- einsum's view-inner ToT x T diagnostic now fires only once a source inner
cell is actually populated. It threw on entry to the loop, which rejected the
fully screened case that used to work: `axpy_to` early-returns on a null
source, so an all-null operand never needed the destination to have storage
and correctly produced a null result tile.
- A test pins intersection sparsity for the plain owning ToT. `Tensor::mult`'s
intersection rule applies in the `is_ta_tensor_v` branch as well, so it is a
behavior change for `TA::Tensor<TA::Tensor<T>>`, not only for arena tiles;
the pre-existing mult_mismatched_null_inners is written permissively and
passes under either rule.
Two of the six new corruption regressions were confirmed failing before the
fix (`-1 != 1` and `3 != 1`); the rest exercise the same path.1 parent fc6c692 commit 95d7a2a
4 files changed
Lines changed: 162 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
948 | 948 | | |
949 | 949 | | |
950 | 950 | | |
951 | | - | |
952 | | - | |
| 951 | + | |
| 952 | + | |
953 | 953 | | |
954 | 954 | | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
962 | 980 | | |
963 | 981 | | |
964 | 982 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
489 | 489 | | |
490 | 490 | | |
491 | 491 | | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
492 | 495 | | |
493 | | - | |
| 496 | + | |
| 497 | + | |
494 | 498 | | |
495 | | - | |
| 499 | + | |
496 | 500 | | |
497 | 501 | | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
502 | 506 | | |
503 | 507 | | |
504 | 508 | | |
505 | | - | |
506 | | - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
507 | 512 | | |
508 | 513 | | |
509 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2167 | 2167 | | |
2168 | 2168 | | |
2169 | 2169 | | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
2170 | 2203 | | |
2171 | 2204 | | |
2172 | 2205 | | |
| |||
2175 | 2208 | | |
2176 | 2209 | | |
2177 | 2210 | | |
2178 | | - | |
| 2211 | + | |
2179 | 2212 | | |
2180 | 2213 | | |
2181 | 2214 | | |
| |||
2290 | 2323 | | |
2291 | 2324 | | |
2292 | 2325 | | |
2293 | | - | |
| 2326 | + | |
2294 | 2327 | | |
2295 | 2328 | | |
2296 | 2329 | | |
| |||
2461 | 2494 | | |
2462 | 2495 | | |
2463 | 2496 | | |
2464 | | - | |
| 2497 | + | |
2465 | 2498 | | |
2466 | 2499 | | |
2467 | 2500 | | |
| |||
2497 | 2530 | | |
2498 | 2531 | | |
2499 | 2532 | | |
2500 | | - | |
| 2533 | + | |
2501 | 2534 | | |
2502 | 2535 | | |
2503 | 2536 | | |
| |||
2529 | 2562 | | |
2530 | 2563 | | |
2531 | 2564 | | |
2532 | | - | |
| 2565 | + | |
2533 | 2566 | | |
2534 | 2567 | | |
2535 | 2568 | | |
| |||
2585 | 2618 | | |
2586 | 2619 | | |
2587 | 2620 | | |
2588 | | - | |
| 2621 | + | |
2589 | 2622 | | |
2590 | 2623 | | |
2591 | 2624 | | |
| |||
2837 | 2870 | | |
2838 | 2871 | | |
2839 | 2872 | | |
2840 | | - | |
| 2873 | + | |
2841 | 2874 | | |
2842 | 2875 | | |
2843 | 2876 | | |
| |||
2874 | 2907 | | |
2875 | 2908 | | |
2876 | 2909 | | |
2877 | | - | |
| 2910 | + | |
2878 | 2911 | | |
2879 | 2912 | | |
2880 | 2913 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
697 | 778 | | |
0 commit comments