Skip to content

Fix column-major parameter ordering in parameterized matmul#72

Merged
dance858 merged 6 commits intoparameter-support-v2from
fix-colmajor-param-matmul
Apr 7, 2026
Merged

Fix column-major parameter ordering in parameterized matmul#72
dance858 merged 6 commits intoparameter-support-v2from
fix-colmajor-param-matmul

Conversation

@Transurgeon
Copy link
Copy Markdown
Collaborator

CVXPY sends parameter values in Fortran (column-major) order, but the matmul refresh functions assumed row-major/CSR order via raw memcpy. This produced incorrect matrix values for non-symmetric matrices.

For sparse matrices, iterate the CSR pattern and index into the column-major source array. For dense matrices, exploit the fact that column-major A is row-major A^T to memcpy directly into AT, then transpose to get A.

Also fixes a latent bug where sparse update_values would blindly copy the first nnz values from the full d1*d2 parameter array, which is wrong for matrices with structural zeros.

Adds tests for rectangular (3x2) and sparse (3x3 with zeros) cases.

CVXPY sends parameter values in Fortran (column-major) order, but the
matmul refresh functions assumed row-major/CSR order via raw memcpy.
This produced incorrect matrix values for non-symmetric matrices.

For sparse matrices, iterate the CSR pattern and index into the
column-major source array. For dense matrices, exploit the fact that
column-major A is row-major A^T to memcpy directly into AT, then
transpose to get A.

Also fixes a latent bug where sparse update_values would blindly copy
the first nnz values from the full d1*d2 parameter array, which is
wrong for matrices with structural zeros.

Adds tests for rectangular (3x2) and sparse (3x3 with zeros) cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dance858
Copy link
Copy Markdown
Collaborator

dance858 commented Apr 7, 2026

I cleaned up the code and the tests. We also raise an error now for sparse matrix parameters.

@dance858 dance858 merged commit 4202921 into parameter-support-v2 Apr 7, 2026
10 of 12 checks passed
@Transurgeon Transurgeon deleted the fix-colmajor-param-matmul branch April 7, 2026 18:34
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.

2 participants