Skip to content

Fix #342, #343: index sequences are part of node identity - #399

Merged
petlenz merged 1 commit into
mainfrom
fix-342-343-index-sequence-identity
Jul 30, 2026
Merged

Fix #342, #343: index sequences are part of node identity#399
petlenz merged 1 commit into
mainfrom
fix-342-343-index-sequence-identity

Conversation

@petlenz

@petlenz petlenz commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #342, fixes #343. Stacked on #388.

Two nodes stored index sequences but inherited base-class hash/equality that ignore them — the same bug class #266 fixed for inner_product_wrapper:

Before After
permute_indices(T,{2,1,3}) == permute_indices(T,{1,3,2}) → true; difference → 0{3} distinct; stays symbolic
dot_product(A,{1,2},B,{1,2}) == dot_product(A,{1,2},B,{2,1}) → true (A:B ≡ A:Bᵀ); sum → 2*dot(...), difference → 0 distinct; no false merge/cancel

Design

Tests

2 new IndexSequenceIdentity lock-in tests (hash + equality + no-false-cancel + exact-match-still-cancels, both nodes). Full suite: 2428/2428 pass. gcc-14 -Werror syntax check clean.

@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 951d0e8 to 8f5ef67 Compare July 25, 2026 12:06
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 150c225 to 3e626cc Compare July 25, 2026 12:09
petlenz added a commit that referenced this pull request Jul 25, 2026
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>
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 8f5ef67 to 9af5448 Compare July 25, 2026 13:25
@petlenz petlenz closed this Jul 25, 2026
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 3e626cc to 9af5448 Compare July 25, 2026 13:25
petlenz added a commit that referenced this pull request Jul 25, 2026
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>
petlenz added a commit that referenced this pull request Jul 25, 2026
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>
@petlenz petlenz reopened this Jul 25, 2026
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 42da614 to 9121a68 Compare July 25, 2026 22:30
petlenz added a commit that referenced this pull request Jul 25, 2026
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>
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 9121a68 to a4eff94 Compare July 26, 2026 12:14
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 9af5448 to 54ae610 Compare July 26, 2026 12:14
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch 2 times, most recently from b731e94 to 8e05846 Compare July 26, 2026 17:18
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 90ead43 to 60f222f Compare July 26, 2026 17:18
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 8e05846 to 352c37e Compare July 26, 2026 17:42
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch 2 times, most recently from 32b1fd9 to cb35152 Compare July 26, 2026 18:16
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch 2 times, most recently from b20178b to 517baa9 Compare July 26, 2026 18:40
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from cb35152 to 444bca1 Compare July 26, 2026 18:40
permute_indices_wrapper and tensor_inner_product_to_scalar stored
their index sequences but inherited unary_op/binary_op hashing and
equality, which see only the children. Two different permutations of
the same tensor compared equal (permute(T,{2,1,3}) == permute(T,{1,3,2}),
their difference folded to 0{3}), and A:B compared equal to A:B^T
(dot_product with sequences {1,2}/{1,2} vs {1,2}/{2,1}), so sums and
differences of distinct contractions silently mis-merged.

Both nodes now override update_hash_value (folding in the sequences,
mirroring inner_product_wrapper's #266 fix, with the m_hash_value
reset the #266 version lacks) and provide operator== / operator<
comparing the sequences before delegating to the base comparison.

Lock-in tests: distinct permutations/sequences neither hash- nor
compare-equal and no longer cancel; identical ones still fold to
zero.

Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
@petlenz
petlenz force-pushed the fix-342-343-index-sequence-identity branch from 517baa9 to df50715 Compare July 26, 2026 19:03
@petlenz
petlenz force-pushed the fix-344-pow-division-rules branch from 444bca1 to 44b9918 Compare July 26, 2026 19:03
@petlenz
petlenz changed the base branch from fix-344-pow-division-rules to main July 30, 2026 06:49
@petlenz
petlenz merged commit 8c95a80 into main Jul 30, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant