Repository navigation
Add rewriting with Theorem 1 - #21
Draft
ValerianRey wants to merge 1 commit into
Draft
ValerianRey wants to merge 1 commit into
ValerianRey wants to merge 1 commit into
Conversation
- Adds `rewrite(tensor)` and `rewrite_with(tensor, rules)`, which read any tensor built with the crate's functions as an expression tree and rewrite it into an equal one by rules, applied bottom-up until none applies - The first rule is Theorem 1, `f ∘ Σ ∘ Ū ∘ ψ = Σ ∘ (f ∘ U)‾ ∘ ψ`, for any reduction whose neutral element f keeps, so a zero-preserving function like relu is only applied to the stored values; two more rules move f through index maps and fuse functions on values - Adds `Function::parts`, by which a composition or a lifted function gives its parts with their types erased down to their domain and codomain, so the tree is read from the existing types and there is no second way of building tensors - `Multisets` can bound the size of its multisets, and COO, Diagonal, EmptyMapping, InvProjection and InvAffine set that bound in their codomain, which is how the rule knows that a tensor is sparse - `Composition` and `MultiFunction` hold their parts in an `Rc` Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
rewrite(tensor)andrewrite_with(tensor, rules). They read any tensor built with the crate's functions as an expression tree (Expr), and rewrite it into an equal one by rules, applied bottom-up until none applies. The result is itself a tensor.f ∘ Σ ∘ Ū ∘ ψ = Σ ∘ (f ∘ U)‾ ∘ ψ. It holds for any reduction whose neutral element f keeps, which is checked by evaluating f once. So a zero-preserving function like relu is only applied to the stored values.f ∘ (T ∘ ρ) = (f ∘ T) ∘ ρ) and fuse functions on values. This lets Theorem 1 apply to transposed sparse tensors, and to pairs likex + 1thenx - 1.Function::parts, whose default isNone. A composition or a lifted function returns its parts through it, with their types erased down to their domain and codomain. The tree is read from the existing types, so there is no second way of building tensors, and shared orRc<dyn Tensor>parts are looked into too. Anything else is a leaf.Multisetscan bound the size of its multisets (Multisets::at_most). COO, Diagonal, EmptyMapping, InvProjection and InvAffine set that bound in their codomain, and that is how the rule knows a tensor is sparse. A COO with a repeated coordinate or a sum over a dimension is left unchanged.CompositionandMultiFunctionnow hold their parts in anRc, so they can hand them out. Their public API is unchanged.Limits: functions that change the value type are leaves. InvAffine only claims at most one element when its basis has full column rank. Off the support,
negategives +0.0 after the rewrite where it gave −0.0 before.🤖 Generated with Claude Code