Skip to content

Fix #353: t2s contraction evaluation honors the index sequences - #407

Closed
petlenz wants to merge 2 commits into
fix-354-t2s-constant-mulfrom
fix-353-t2s-contraction-sequences
Closed

petlenz wants to merge 2 commits into
fix-354-t2s-constant-mulfrom
fix-353-t2s-contraction-sequences

Conversation

@petlenz

@petlenz petlenz commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #353. Stacked on #406. Completes the node whose identity half landed in #399 (#343).

Before After
dot_product(A,{1,2},B,{2,1}) evaluated as plain A : B (542.5 vs correct 479.5 in the issue repro) contracts against the transpose
dot_product(u,{1},v,{1}) threw requires rank 2 tmech::dot — also unblocks evaluating diff(dot(u), s) for rank-1 args
rank>2 silently wrong / opaque throw clear not-implemented error referencing the #383 ceilings epic (general sequence-driven contraction is that epic's task)

Tests

Numeric lock-in comparing both rank-2 orientations against hand-computed sums plus the rank-1 dot. Full suite: 2446/2446 pass. gcc-14 clean.

@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from 2b561b2 to c0f0110 Compare July 25, 2026 12:35
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from c0f0110 to 84530ed Compare July 25, 2026 13:38
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from 84530ed to 2a4b143 Compare July 25, 2026 14:16
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from 2a4b143 to c0cd24e Compare July 25, 2026 22:33
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from c0cd24e to 3d0c609 Compare July 26, 2026 12:14
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch 2 times, most recently from c8fb55c to 1a17e02 Compare July 26, 2026 17:18
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from 1a17e02 to 3a5ad33 Compare July 26, 2026 17:42
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch 2 times, most recently from 05cdfad to c4a3309 Compare July 26, 2026 18:40
petlenz added 2 commits July 26, 2026 20:58
The tensor_inner_product_to_scalar evaluator always computed the plain
tmech::dcontract(l, r): dot_product(A,{1,2},B,{2,1}) (= A_ij B_ji)
silently evaluated as A : B, and rank-1 full contractions threw
'requires rank 2' even though the node is a legal dot product (which
also broke evaluating derivatives of dot() on rank-1 arguments).

tensor_data_dcontract_wrapper now receives both sequences: matching
rank-2 sequences contract plain ({2,1}/{2,1} sums the same pairs),
mismatched ones contract against the transpose, and rank-1 uses
tmech::dot. Rank>2 general contraction stays a clear
not-implemented error (tracked by the #383 evaluation-ceilings epic)
instead of a silently wrong value.

The identity half of this node (hash/== ignoring the sequences) landed
in #399.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
The dispatch derives Dim/Rank from the LHS; a mixed-rank node
(constructible through the weak || precondition in dot_product, #360)
reached a wrong-type static_cast and, with the new rank-1 branch,
returned silent garbage where it previously threw. The wrapper now
throws evaluation_error on operand rank/dim mismatch and on sequence
sizes not covering the rank.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
@petlenz
petlenz force-pushed the fix-353-t2s-contraction-sequences branch from c4a3309 to 3eb5bf3 Compare July 26, 2026 19:03
@petlenz
petlenz added this pull request to stack #425 September 15, 2026 20:15
@petlenz

petlenz commented Sep 15, 2026

Copy link
Copy Markdown
Member Author

Landed in main via #409 (merge a5f5ce8), which contained this branch at head 3eb5bf3. Closing without a separate merge.

@petlenz petlenz closed this Sep 15, 2026
@petlenz
petlenz deleted the fix-353-t2s-contraction-sequences branch September 15, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant