Standardize scalar function array construction - #9135
Draft
connortsui20 wants to merge 2 commits into
Draft
Conversation
Member
Author
|
Still need to figure out if there is a way to make the generic factor ext trait able to express more complicated validation logic as in |
connortsui20
force-pushed
the
ct/scalar-fn-factory-ext
branch
from
August 2, 2026 00:53
48d2bcc to
ce52f49
Compare
`L2Denorm` was registered as a `ScalarFnVTable`, but it never behaved like one. Its constructor took an `ExecutionCtx` and scanned both children to enforce a unit-norm invariant, `L2Norm` read its stored norms instead of recomputing, `CosineSimilarity` and `InnerProduct` reached into its physical children, and the compressor scheme named it as a produced encoding. Those are all properties of a physical decomposition, not of an operation over arbitrary well-typed values. Moves it to `vortex-tensor/src/encodings/l2_denorm/` as a real `VTable` with two slots (`normalized`, `norms`). Structural validation runs on construction and on deserialization, `try_new` additionally scans for the exact unit-norm invariant, and `try_new_trusted` skips that scan for lossy normalized children whose stored norms stay authoritative. Neither constructor is `unsafe`, since violating the contract produces wrong answers rather than undefined behavior. The encoding keeps the `vortex.tensor.l2_denorm` array ID and the same two-field metadata message, so the wire format is unchanged. Slice and filter now push down into both children through `reduce_parent`. The generic `ScalarFnArray` filter rule only fired when at most one child was non-constant, which for this encoding was almost never. Also makes `L2DenormScheme` cascade its two children like `TemporalScheme` does, which lets both `HACK TO SUPPORT L2 DENORMALIZATION` special cases come out of `CascadingCompressor`. The scheme now competes on measured size like every other scheme. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XEo4wnqKfAf1QLJbdrz76j Signed-off-by: Claude <noreply@anthropic.com>
Uses `ScalarFnFactoryExt` for tensor and geo scalar functions instead of maintaining per-function constructors. `L2Denorm` keeps its checked constructor because it validates the normalized-row invariant. Signed-off-by: "Connor Tsui" <connor.tsui20@gmail.com>
connortsui20
force-pushed
the
ct/scalar-fn-factory-ext
branch
from
August 2, 2026 18:03
ce52f49 to
bf43ecf
Compare
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.
(semi-related) Tracking Issue: #9129
Right now the tensor and geo scalar functions maintain bespoke inherent constructors alongside
ScalarFnFactoryExt::try_new_array. This removes the redundant constructors and migrates the in-tree callers to the shared factory API.Note that this intentionally removes public
new()andtry_new_array(...)methods fromCosineSimilarity,InnerProduct, andL2Norm, plustry_new_array(...)from the four geo scalar functions. This is a source compatibility break, which is why I split it out from the RowFn work and left the PR as a draft. The main review question is whether the smaller and consistent API is worth that break, or whether these should remain as forwarding methods.L2Denormused to be the awkward exception here: its constructors enforce or explicitly bypass the normalized-row invariant, which the generic factory can't express. That turned out to be a sign it was never a scalar function in the first place, so it moves to a dedicated array encoding in #9138 and is no longer part of this diff.Edit: rebased onto #9138. The GitHub base is still showing
develop, so this diff currently includes the #9138 commit. It needs to be re-pointed atct/l2-denorm-encoding.