Skip to content

Add UnitVector tensor refinement - #9421

Draft
connortsui20 wants to merge 1 commit into
ct/extension-coerce-tofrom
ct/unit-vector
Draft

Add UnitVector tensor refinement#9421
connortsui20 wants to merge 1 commit into
ct/extension-coerce-tofrom
ct/unit-vector

Conversation

@connortsui20

@connortsui20 connortsui20 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Depends on #9418.

Rationale for this change

Normalized currently stores normalized Vector values with the same dtype as arbitrary vectors, so the unit-norm invariant is not represented in the type.

What changes are included in this PR?

Adds the UnitVector extension dtype for vectors whose rows have norm 1.0 within tolerance or are exactly zero. Adds the L2Normalize scalar function and uses it in the Normalized encoding, where vector directions become UnitVector while fixed-shape tensor directions retain their dtype.

What APIs are changed? Are there any user-facing changes?

Adds the public UnitVector dtype and L2Normalize scalar function. InnerProduct and CosineSimilarity accept compatible Vector and UnitVector pairs.

@connortsui20 connortsui20 changed the title ct/unit vector Add UnitVector tensor refinement Aug 14, 2026
@connortsui20 connortsui20 added the changelog/feature A new feature label Aug 14, 2026
@codspeed-hq

codspeed-hq Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 6 improved benchmarks
❌ 2 regressed benchmarks
✅ 1992 untouched benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime words_gather_scalar[65536] 8.3 µs 9.4 µs -12.02%
Simulation take[small_m/shuffled/primitive/nonnull/chunks=16384/indices=16] 1.1 ms 1.2 ms -11.37%
Simulation encode_nullable[256] 333.5 µs 231.5 µs +44.08%
Simulation encode_nullable[2] 1,109.2 µs 770.4 µs +43.98%
Simulation encode_nullable[32] 368.5 µs 259.4 µs +42.08%
Simulation encode_non_nullable[2] 866.5 µs 686.6 µs +26.21%
Simulation encode_non_nullable[256] 256.5 µs 209.3 µs +22.56%
Simulation encode_non_nullable[32] 304.8 µs 252.9 µs +20.51%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/unit-vector (7a41686) with ct/extension-coerce-to (ec1dddb)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant