Skip to content

[diskann-utils] Simplify StridedView. - #1376

Open
Mark Hildebrand (hildebrandmw) wants to merge 4 commits into
mainfrom
mhildebr/strided
Open

[diskann-utils] Simplify StridedView.#1376
Mark Hildebrand (hildebrandmw) wants to merge 4 commits into
mainfrom
mhildebr/strided

Conversation

@hildebrandmw

Copy link
Copy Markdown
Contributor

We apparently don't need owned or mutable StridedViews. This struct was getting in the way of simplifying the Matrix type, so I decided to do the following:

  1. Collapse everything into a single Strided<'a, T> struct.
  2. Ensure that the layout for a Strided is well formed.
  3. Shrink the memory representation from 40 bytes to 32 bytes.
  4. Implement a custom Rows iterator so we no longer panic if the column-stride is zero.

Note that currently, From<MatrixView<'a, T>> can panic. This is because MatrixView and friends don't actually guarantee that nrows * ncols does not overflow usize::MAX. I have another PR in the pipeline to fix that, but ran into a chicken and egg problem with Strided preventing that PR from making progress.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It introduces a new unsafe, pointer-based core view type and manual auto-trait impls, which warrants careful human review despite largely mechanical downstream updates.

Pull request overview

This PR refactors diskann-utils’ strided matrix view abstraction by collapsing prior owned/mutable view variants into a single borrowed Strided<'a, T> with an explicit validated Layout, and updates downstream quantization/benchmark/provider code to use the new API.

Changes:

  • Replaced StridedView/MutStridedView/StridedBase with Strided<'a, T>, plus a Layout validator and a non-panicking Rows iterator.
  • Updated PQ training, k-means, transposed tables, providers error bridging, and benchmark recall code to use Strided::try_from_data(...), rows(), and new accessors.
  • Introduced a small internal helper for slice-to-NonNull conversion to support the new representation.
File summaries
FileDescription
diskann-utils/src/strided.rsReplaces the old strided view types with Strided<'a, T>, adds Layout validation, new element/row accessors, and a custom Rows iterator; updates tests accordingly.
diskann-utils/src/lib.rsAdds the new internal module to support Strided’s representation.
diskann-utils/src/internal.rsAdds an internal helper for creating NonNull from a slice base pointer.
diskann-quantization/src/product/train.rsSwitches PQ training chunk views from StridedView to Strided and uses rows() instead of row_iter().
diskann-quantization/src/product/tables/transposed/table.rsUpdates pivot slicing to construct Strided via try_from_data.
diskann-quantization/src/product/tables/transposed/pivots.rsUpdates APIs and call sites to accept Strided and uses rows() / row_unchecked() access.
diskann-quantization/src/multi_vector/block_transposed.rsUpdates block-transpose construction to accept Strided and uses row_unchecked().
diskann-quantization/src/algorithms/kmeans/plusplus.rsUpdates kmeans++ helpers to consume Strided and uses row_or_panic() for copying selected points.
diskann-quantization/src/algorithms/kmeans/lloyds.rsUpdates Lloyd’s implementation to consume Strided and iterate with rows().
diskann-providers/src/model/pq/strided.rsUpdates error-bridging to the new non-generic TryFromError type.
diskann-benchmark-core/src/recall.rsUpdates optional distance matrix handling to accept Strided and uses row_or_panic().
Review details

Suppressed comments (2)

diskann-utils/src/strided.rs:329

  • The doc comment says TryFromError is for Strided::new, but there is no new constructor; the fallible constructor is try_from_data. This makes rustdoc misleading for callers.
/// Errors for [`Strided::new`].
#[derive(Debug, Error)]

diskann-utils/src/strided.rs:353

  • The From<MatrixView> impl can panic via .expect(...). From is expected to be infallible; if this conversion is genuinely fallible (overflow or length mismatch), prefer TryFrom<MatrixView> (and/or keep From only after MatrixView invariants are strengthened).
 matrix.nrows(),
matrix.ncols(),
matrix.ncols(),
)
.expect("this will be made infallible in the future")
  • Files reviewed: 11/11 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threaddiskann-utils/src/internal.rs
Comment threaddiskann-utils/src/strided.rs
Comment threaddiskann-utils/src/strided.rs Outdated
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.69512% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.53%. Comparing base (600c2b9) to head (e941c51).

Files with missing linesPatch %Lines
diskann-quantization/src/product/train.rs66.66%1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## main #1376 +/- ##
==========================================
- Coverage 91.55% 91.53% -0.02% 
==========================================
Files 521 522 +1 Lines 100302 100195 -107 ==========================================
- Hits 91828 91716 -112 - Misses 8474 8479 +5 
FlagCoverage Δ
miri91.53% <99.69%> (-0.02%)⬇️
unittests91.21% <99.69%> (-0.02%)⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
diskann-benchmark-core/src/recall.rs99.06% <100.00%> (ø)
diskann-providers/src/model/pq/strided.rs100.00% <100.00%> (ø)
...skann-quantization/src/algorithms/kmeans/lloyds.rs99.23% <100.00%> (ø)
...ann-quantization/src/algorithms/kmeans/plusplus.rs99.48% <100.00%> (+<0.01%)⬆️
...-quantization/src/multi_vector/block_transposed.rs98.79% <100.00%> (ø)
...antization/src/product/tables/transposed/pivots.rs98.68% <100.00%> (-0.02%)⬇️
...uantization/src/product/tables/transposed/table.rs99.28% <100.00%> (ø)
diskann-utils/src/internal.rs100.00% <100.00%> (ø)
diskann-utils/src/lib.rs100.00% <ø> (ø)
diskann-utils/src/strided.rs100.00% <100.00%> (ø)
... and 1 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hildebrandmw@codecov-commenter