Repository navigation
Description
Description
Description
While implementing blas/base/cgbmv, I noticed that the band matrix storage format expected by BLAS gbmv differs from the layout produced by @stdlib/array/base/banded/to-compact.
to-compact produces a diagonal-centered layout, whereas BLAS expects a band storage layout compatible with the gbmv routines (as documented in (Intel® oneAPI Math Kernel Library).
Because of this difference, to-compact cannot be directly used for preparing matrices for gbmv.
This behaviour is only present in colexicographic or column wise packing.
For example, given:
var A = [
[ 1, 2, 3, 0, 0 ],
[ -2, 4, 5, 6, 0 ],
[ -3, -5, 7, 8, 9 ],
[ 0, -6, -8, 10, 11 ],
[ 0, 0, -9,-11, 12 ]
];Output from to-compact
Column wise (colexicographic) packing
AC = toCompact( A, 2, 2, true );
/* e.g., returns =>
[
[ 0, 0, 1, -2, -3 ],
[ 0, 2, 4, -5, -6 ],
[ 3, 5, 7, -8, -9 ],
[ 6, 8, 10, -11, 0 ],
[ 9, 11, 12, 0, 0 ]
]
*/Expected BLAS band storage (MKL / Netlib)
BLAS gbmv expects band matrices packed differently.
Band Matrix
A general band matrix A of m rows and n columns with kl sub-diagonals, ku super-diagonals and leading dimension lda is represented as a one dimensional array a of size at least lda * n (respectively, lda * m) if column (respectively, row) major layout is used.
Before entry in any BLAS function using a general band matrix, the leading (kl + ku + 1) by n (respectively, m) part of the array a must contain the matrix A. This matrix must be supplied column-by-column (respectively, row-by-row), with the main diagonal of the matrix in row ku (respectively, column kl) of the array (0-based indexing), the first super-diagonal starting at position 1 (respectively, 0) in row (ku – 1) (respectively, column (kl + 1)), the first sub-diagonal starting at position 0 (respectively, 1) in row (ku + 1) (respectively, column (kl – 1)), and so on. Elements in the array a that do not correspond to elements in the band matrix (such as the top left ku-by-ku triangle) are not referenced.
Acompact = [
[ 0, 0, 1, 2, 3 ],
[ 0, -2, 4, 5, 6 ],
[ -3, -5, 7, 8, 9 ],
[ -6, -8, 10, 11, 0 ],
[ -9, -11, 12, 0, 0 ]
]Related Issues
Related issues # , # , and # .
Questions
No.
Demo
No response
Reproduction
var toCompact = require('@stdlib/array/base/banded/to-compact');
var A = [
[ 1, 2, 3, 0, 0 ],
[ -2, 4, 5, 6, 0 ],
[ -3, -5, 7, 8, 9 ],
[ 0, -6, -8, 10, 11 ],
[ 0, 0, -9,-11, 12 ]
];
var AC = toCompact( A, 2, 2, true );
console.log( AC );Expected Results
[
[ 0, 0, 1, 2, 3 ],
[ 0, -2, 4, 5, 6 ],
[ -3, -5, 7, 8, 9 ],
[ -6, -8, 10, 11, 0 ],
[ -9, -11, 12, 0, 0 ]
]Actual Results
[
[ 0, 0, 1, -2, -3 ],
[ 0, 2, 4, -5, -6 ],
[ 3, 5, 7, -8, -9 ],
[ 6, 8, 10, -11, 0 ],
[ 9, 11, 12, 0, 0 ]
]Version
No response
Environments
Node.js
Browser Version
No response
Node.js / npm Version
20.20.0
Platform
Linux
Checklist
- Read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
Activity
stdlib-bot commentedon Mar 10, 2026
👋 Hi there! 👋
And thank you for opening your first issue! We will get back to you shortly. 🏃 💨
If you have any further questions while waiting for a response, please join our Zulip community to chat with project maintainers and other community members.
kgryte commentedon Mar 11, 2026
@DivitJain26 What was the reason for closing this issue?
DivitJain26 commentedon Mar 11, 2026
Hi @kgryte
The reference I linked (Intel® oneAPI Math Kernel Library) only describes how matrices must be packed specifically for the
?gbmvroutine. It does not necessarily define a general banded storage convention applicable to all contexts. I also could not find a reference describing a general packing format.My confusion arose because each BLAS function may have its own packing requirements. In contrast,
@stdlib/array/base/banded/to-compactpacks a matrix either in colexicographic form (arranging diagonals column-wise) or lexicographic form (arranging diagonals row-wise). This layout does not align with the input format required by MKL?gbmv, but it might be the expected format for other functions used withinstdlib.Because different BLAS routines may impose their own storage requirements, I was unsure whether this difference indicated an inconsistency in
to-compactor simply that the helper function targets a more general banded representation used elsewhere instdlib.For that reason, I closed the issue.
DivitJain26 commentedon Mar 13, 2026
@kgryte should I reopen it?
[-][RFC]: mismatch between BLAS gbmv band storage and `@stdlib/array/base/banded/to-compact` layout[/-][+][RFC]: mismatch between BLAS band storage and `@stdlib/array/base/banded/to-compact` layout[/+][-][RFC]: mismatch between BLAS band storage and `@stdlib/array/base/banded/to-compact` layout[/-][+][RFC]: mismatch between BLAS band storage and `to-compact` layout[/+]