Repository navigation
A matrix compiles to a GenTensor over its elements' type, and the arithmetic on it to GenericTensor's operations - #1425
Merged
Merged
Conversation
…thmetic on it to GenericTensor's operations #526: "just run GenericTensor through our functions". Under the LINQ compiler a Matrix node is a GenTensor<T, TWrapper> over the common type of its compiled elements, filled element by element, and a sum, difference, product, quotient or whole power with a matrix in it is the tensor operation of that name -- PiecewiseAdd, PiecewiseSubtract, MatrixMultiply, the piecewise operations by a scalar converted to the element type, MatrixPower -- so that "A * B" compiled over two tensors is the matrix product and "2 A + B - 1" scales, adds and shifts. GenericTensor takes its element arithmetic from a struct and ships none for the numeric types, so DoubleOperations, SingleOperations, ComplexOperations, Int32Operations, Int64Operations and BigIntegerOperations are here, in AngouriMath.Core.Compilation.IntoLinq, and GenTensor<double, DoubleOperations> is the type to compile to and to pass a matrix in as. The methods the compiled tree calls are closed over each element type at compile time and named through expression trees, the way the protocol keeps its own tables: nothing generic is constructed at run time, which the trimming and NativeAOT analyzers refuse (#363). A matrix as a number, a number as a matrix, and a function of a matrix are UncompilableNodeException with a message that says so, where sin(A) was a KeyNotFoundException out of a type table. An expression of matrices with a scalar value still simplifies to the scalar first, as #425 made it. Closes #526. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
…enericTensor's expression-compiled ones, so the NativeAOT gate passes The first push failed TrimmingAndAot on both platforms: GenTensor.PiecewiseAdd, MatrixMultiply and the rest build and compile an expression tree for their loops, which ILC reports as IL3050 the moment they are reachable -- and Kit.For roots them for six element types. Add, Subtract, Multiply, the scalar operations and Power are now loops over the wrapper's Add and Multiply, and Power is by repeated squaring, refusing a negative exponent. GenTensor stays the container. The smoke test compiles a matrix expression now, so the gate covers this path from here on. Published natively and run locally: 45 checks, 0 failed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Member
Author
|
The first push failed TrimmingAndAot on both platforms — |
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.
#526, per the comment there: "just run GenericTensor through our functions".
Under the LINQ compiler a
Matrixnode compiles to aGenTensor<T, TWrapper>over its elements' common type, filled element by element from the compiled elements, and a sum, difference, product, quotient or whole power with a matrix in it becomes the tensor operation of that name —PiecewiseAdd/PiecewiseSubtract,MatrixMultiply, the piecewise operations by a scalar (converted to the element type),MatrixPower. GenericTensor takes its element arithmetic from a struct and ships none for the numeric types, soDoubleOperations,SingleOperations,ComplexOperations,Int32Operations,Int64Operations,BigIntegerOperationsare added inAngouriMath.Core.Compilation.IntoLinq;GenTensor<double, DoubleOperations>is the type to compile to and to pass a matrix in as, andTensorCompilation.TensorTypeOf(typeof(double))names it.AOT. The methods the compiled tree calls are closed over each element type at compile time (
Kit.For<double, DoubleOperations>()and five more) and named through expression trees, the way the protocol keeps its ownMethodInfotables: nothing generic is constructed at run time. The first draft usedMakeGenericType/MakeGenericMethod/NewArrayInitand the trimming and NativeAOT analyzers refused it as errors (IL2060, IL3050 — #363's gate doing its job), so a matrix is built byEmpty(rows, cols)and a chain ofSet(tensor, index, value)calls instead.Refusals, all
UncompilableNodeExceptionwith a message that says so: a matrix asked for as a number, a number as a matrix, two matrices over different element types, and a function of a matrix (sin(A)was aKeyNotFoundExceptionout of the type table). An expression of matrices with a scalar value still simplifies to the scalar first, as #425 made it ([[1, 0]] * [[a, b], [c, d]] * [[0], [1]]→2at(1, 2, 3, 4)).MatrixCompilationTest's three "a matrix cannot be compiled" rows are rewritten as "cannot be compiled as a number", which is what they now test;CompileMatrixTesthas the rows above.Exceptions.mdand BREAKING-CHANGES.md updated ("Addition, not silent"). Full suite: 11851 passed, 0 failed after that rewrite. Not on theSimplify/evaluation path, so the benchmark gate is not concerned.Closes #526.
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura