Repository navigation
Compile dot, cross, det and transpose of a name compiled as a number - #2558
Merged
Merged
Conversation
The 2.8.0 entry in BREAKING-CHANGES said dot and cross were computed "when they are substituted, by Simplify, Evaled, or a compiled delegate", which reads as though Substitute carried the product out. It does not, and never did: dot([0, 0, 1], v) with v = [x, y, z] substituted is dot([0, 0, 1], [x, y, z]) on 2.8.0, 2.9.0 and master. The behaviour is the right half. Substitute computes nothing in any node, and the matrix nodes beside these - det, transpose, trace, an entry - rebuild the same way; the entry's own table, the det entry's table and the MathS.Matrices.DotProduct example all substitute and then call Simplify or Evaled. So the sentence is reworded, the test class's summary with it, and a test pins that substitution leaves the node and simplification carries it out. Part of #105. Co-authored-by: Claude Opus 5.5 <[email protected]>
Since #105 simplification leaves dot, cross, det, transpose, trace and an entry as nodes where a name stands beside a written matrix, as in dot([0, 0, 1], cos(p) * [x, y, z]): the name may stand for a matrix. Both compilers inherited that caution although a variable compiled as a number is one. - Compile(params Variable[]), whose variables are all numbers, had no form for any of the six nodes, so dot(x * [1, 2], [3, 4]) was refused with a request to report a bug. - Compile<...> converted a double to the long of a written vector of whole numbers, so dot(x * [1, 2], [3, 4]) and det(x * [[1, 2], [3, 4]]) were 0 at x = 0.5, and dot([0, 0, 1], v) over a double vector was refused for its element types. - Both multiplied a transpose beside written matrices out as a number: [1, 0]T * transpose(x * [[1, 2], [3, 4]]) * [0, 1] was 0, not 3 x. MatrixOperationsOverNumbers now carries the six out before compiling, innermost first, wherever every name in one is compiled as a number, through the nodes' own simplification with a namesAreNumbers switch, so the rules for conditions, piecewise and det(transpose(X)) are not copied. One still left that is taken of a number has no value and is refused before simplification can read it as a number; FastExpression refuses any left, saying where vectors and matrices are compiled. A name compiled as a matrix is untouched. The LINQ tensor path widens rather than narrows: a matrix beside a wider number is widened to it, which fixes det(x * A) over a long[,] A (0 at x = 0.5) and refuses no complex number beside a double matrix, and dot and cross widen two vectors over different element types as a sum of two matrices already did. Measured on v2.9.0 and on this branch; the table is in BREAKING-CHANGES. On v2.9.0, 22 of the new tests fail and the rest, the controls, pass; all pass here. Not fixed here: InnerSimplified itself still reads [1, 0]T * transpose(A) * [0, 1] as 0 for a symbolic A, and the LINQ compiler still compiles a constant beside a long[,] argument as a long, so trace(A * 0.5) is 0. Part of #105. Co-authored-by: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2558 +/- ##
==========================================
+ Coverage 86.70% 86.71% +0.01%
==========================================
Files 343 344 +1
Lines 74754 74810 +56
Branches 21810 21822 +12
==========================================
+ Hits 64814 64874 +60
+ Misses 5374 5368 -6
- Partials 4566 4568 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 26, 2026
…NGES entries Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 26, 2026
…hader (#2562) MathS.Shaders.Hlsl and Glsl refused dot, cross, det, transpose, trace and an entry of an expression with a name beside a written matrix, such as dot(x * [1, 2], [3, 4]), giving as the reason that every variable of the shader is a number, which is why each has a value. The shader now carries them out with MatrixOperationsOverNumbers, as Compile does since #2558, and a product of written matrices left after that is reduced to the number it gives, as Compile reduces it (#425). An operation still left, such as a transpose of a variable, is refused before simplification could read it as a number beside the written matrices (#2557). Closes #2561. Co-authored-by: Claude Opus 5.5 <[email protected]>
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 27, 2026
v2.9.0 and 2.10.0's last kernel change, from one interleaved run of the key-commits workflow (45925911365). A 3067th column is added to the two history tables at the top, from the Kernel Benchmark's run on that commit (45924828059). Allocation is flat except CompileEasy +2.47% and CompileHard +1.40%, one step at the 3059th (#2558), a walk of the nodes before compiling. The SolveHard timing rise on the runner is not seen re-timed on one desktop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rafael-SOWNet
added a commit
that referenced
this pull request
Nov 27, 2026
* Temporary: measure the 3053rd and the 3067th, interleaved, for the 2.10.0 pair Restored before this branch is merged. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Revert "Temporary: measure the 3053rd and the 3067th, interleaved, for the 2.10.0 pair" This reverts commit bae6f6e. * Measure the 2.10.0 performance pair, the 3053rd and the 3067th v2.9.0 and 2.10.0's last kernel change, from one interleaved run of the key-commits workflow (45925911365). A 3067th column is added to the two history tables at the top, from the Kernel Benchmark's run on that commit (45924828059). Allocation is flat except CompileEasy +2.47% and CompileHard +1.40%, one step at the 3059th (#2558), a walk of the nodes before compiling. The SolveHard timing rise on the runner is not seen re-timed on one desktop. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Since #105, simplification leaves
dot,cross,det,transpose,traceand an entryA[k, l]as nodes where a name stands beside a written matrix, as indot([0, 0, 1], cos(p) * [x, y, z]), because the name may stand for a matrix. Both compilers inherited that caution, although a variable compiled as a number is one. So the third component of a rotated vector,dot([0, 0, 1], cos(p) * [x, y, z] + sin(p) / abs([a, b, c]) * cross([a, b, c], [x, y, z])), could not be compiled at all.What was refused or wrong
.Compile("a", "b", "c", "p", "x", "y", "z")DotProductfdoes not support compilationcos(p) z + sin(p) (a y - b x) / abs([a, b, c])Compile<double, …, double>Int64andDouble-3.9818867534572675at(0.3, 1, 1.7, 2.4, 3.1, 3.8, 4.5)dot(x * [1, 2], [3, 4]),Compile("x")11 xdot(x * [1, 2], [3, 4]),Compile<double, double>atx = 0.505.5det(x * [[1, 2], [3, 4]]),Compile<double, double>atx = 0.50-0.5[1, 0]T * transpose(x * [[1, 2], [3, 4]]) * [0, 1], either compiler, atx = 0.303 x:0.8999999999999999[0, 0, 1]T * cross(x * [1, 0, 0], [0, y, 0]), either compilerx ydet(x * A),Compile<double, long[,], double>atx = 0.5,A = [[1, 2], [3, 4]]0-0.5[1, 0]T * transpose(A) * [0, 1], withAcompiled as a number0The full table, measured on the 2.9.0 package and on this branch, is the new BREAKING-CHANGES entry.
How
MatrixOperationsOverNumbers(new, inFunctions/Compilation) carries the six nodes out before compiling, innermost first, wherever every name in one is compiled as a number. ForCompile(params Variable[])that is every name; forCompile<...>, every argument that is not a vector or a matrix. It goes through each node's own simplification with a newnamesAreNumbersswitch, so the rules for conditions, piecewise anddet(transpose(X))are not copied.Compile<..., double[]>andCompile<..., double[,]>take vectors and matrices, instead of asking for a bug report.TensorCompilation.WidenedBeside), where the number used to be converted to the matrix's element type and truncated.dotandcrosswiden two vectors over different element types, as a sum of two matrices already did.Substitute
The 2.8.0 entry said these nodes are computed "when they are substituted".
Substitutecomputes nothing in any node, and that entry's own table already substituted and then simplified. The sentence now says so, and a test inDotAndCrossNodesTestpins it.Tested
MatrixOperationOverNumbersCompilationTest(new) and additions toDotAndCrossNodesTestcheck each value against the definition written out, at real, negative and non-real points. 22 of them fail on 2.9.0; the others are controls and pass on both.Not in this PR
InnerSimplifieditself still reads[1, 0]T * transpose(A) * [0, 1]as0for a symbolicA. The compilers no longer reach that path for these operands; the simplifier fix is its own PR.long[,]argument aslong, sotrace(A * 0.5)is0. Its fix is a PR stacked on this one, since it reusesWidenedBeside.🤖 Generated with Claude Code