Fix #359: inv() skew guard only rejects rank-2 matrix products - #435
Merged
Merged
Conversation
is_provably_skew now matches only the skew() projection itself,
inner_product(P_skew, {3,4}, X, {1,2}) with rank-2 X, instead of any
contraction with P_skew on the left.
contains_skew_factor only recurses where det(M1·M2) = det(M1)·det(M2)
applies: tensor_mul chains whose children are all rank-2, and
single-index contractions of two rank-2 operands. inv(C:skew(A)) with
rank-4 C is generically invertible and no longer rejected.
Tests in TensorSpacePropagationTest: rank-4 contraction and other P_skew
contraction patterns are accepted, rank-2 products with a skew factor
are still rejected, and a numerical check confirms det(C:skew(A)) != 0,
P_skew{1,3}:A is not skew, and B·skew(A) is singular.
Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #359.
The
inv()singularity guard rejected operands that are generically invertible.is_provably_skewmatched anyinner_productwithP_skewon the left. It now requires the exactskew()projection:inner_product(P_skew, {3,4}, X, {1,2})with rank-2X(viaas_projector_contraction).inner_product(P_skew, {1,3}, X, {1,2})is not skew in general.contains_skew_factorrecursed through everytensor_mulandinner_product. The determinant argumentdet(M1·M2) = det(M1)·det(M2) = 0only holds for products of rank-2 matrices, so it now recurses only throughtensor_mulchains whose children are all rank-2, and single-index contractions of two rank-2 operands (a product of the operands or their transposes). Scalar multiples and negations are unchanged.inv(inner_product(C, {3,4}, skew(A), {1,2}))with rank-4Cis no longer rejected.inv()is the only caller of the classifier.Tests (
TensorSpacePropagationTest):InvAllowsRank4ContractionOfSkew:C4:skew(X)andC4:W(annotated skew) are accepted.SkewProjectorWithOtherIndicesIsNotSkew:P_skew{1,3}:Xis not classified skew andinvaccepts it.SkewClassificationMatchesNumerics: with random data in 3D,det(C4:skew(A)) != 0andinvevaluates to its inverse,P_skew{1,3}:Ais not skew,skew(A)is skew, andB·skew(A)andinner(B{1}, skew(A){2})are singular.InvRejectsMatrixProductsWithSkewFactor:skew(X),skew(X)·Band a single-index contraction withskew(X)are still rejected.Negative control: against the classifier on
main, the first three fail; the rejection test passes on both. No existing test encoded the over-general rejection. Full suite 2350/2350 (gcc-14 Debug,-Werrorexcept the pedantic/deprecated-declarations warnings already onmain).