Skip to content

fix: Correct stride calculation in AffineRank2RowMajor::packed()#3048

Open
bledden wants to merge 1 commit intoNVIDIA:mainfrom
bledden:fix/affine-rank2-row-major-packed-stride
Open

fix: Correct stride calculation in AffineRank2RowMajor::packed()#3048
bledden wants to merge 1 commit intoNVIDIA:mainfrom
bledden:fix/affine-rank2-row-major-packed-stride

Conversation

@bledden
Copy link

@bledden bledden commented Feb 21, 2026

Summary

I noticed that AffineRank2RowMajor::packed() returns AffineRank2RowMajor(1, extent.row()), which is identical to the column-major version. For a tightly packed row-major layout, columns should be contiguous (stride=1) and rows should be strided by the number of columns — so the correct call is AffineRank2RowMajor(extent.column(), 1).

This is consistent with:

  • The single-argument constructor (stride_[0] = stride; stride_[1] = 1)
  • The Affine2Layout_Factory<AffineRank2RowMajor> specialization, which multiplies by extent[1] (columns) for the row stride
  • The capacity() method, which computes extent.row() * stride_[0] — currently returning rows * 1 instead of rows * cols

Verification

For a 4×8 matrix:

  • Before (buggy): packed({4, 8}) → row_stride=1, col_stride=4, capacity=4
  • After (fixed): packed({4, 8}) → row_stride=8, col_stride=1, capacity=32

Fixes #2991

Signed-off-by: Blake Ledden bledden@users.noreply.github.com

The packed() method was returning AffineRank2RowMajor(1, extent.row()),
which sets row_stride=1 and column_stride=num_rows — identical to the
column-major version. For a tightly packed row-major layout, columns
should be contiguous (stride=1) and rows should be strided by the
number of columns.

Fixed to return AffineRank2RowMajor(extent.column(), 1), which is
consistent with the single-argument constructor and the
Affine2Layout_Factory specialization.

Fixes NVIDIA#2991

Signed-off-by: Blake Ledden <bledden@users.noreply.github.com>
Sign up for free to 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.

[BUG] Incorrect Stride Calculation in AffineRank2RowMajor::packed()

1 participant