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
dance858 added a commit that referenced this pull request Apr 10, 2026
…53)

* Unify constants and parameters into single parameter_expr type

Constants and updatable parameters are now represented by a single
parameter_expr node. Constants use param_id == PARAM_FIXED (-1),
while updatable parameters use param_id >= 0. Bivariate ops
(left_matmul, right_matmul, scalar_mult, vector_mult) accept an
optional param_source node and refresh their internal data on
forward/jacobian/hessian evaluation. Adds problem_register_params
and problem_update_params for problem-level parameter management.
Also adds update_values to the Matrix interface for parameter refresh.

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

* Address review comments on parameter-support-v2

- Remove redundant refresh_param_values calls from eval_jacobian and
  eval_wsum_hess in left_matmul (forward always runs first)
- Use memcpy in problem_register_params for pointer array copy
- Add PARAM_FIXED guard in problem_update_params to skip fixed constants
- Remove unused right_matmul_expr struct from subexpr.h
- Add test_param_fixed_skip_in_update covering mixed fixed/updatable params
- Add CLAUDE.md for Claude Code guidance

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

* Run clang-format and remove CLAUDE.md

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

* Set has_been_refreshed to false in parameter constructor

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

* Remove CLAUDE.md from PR

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

* remove unused constructors

* run formatter and push it up

* Update includes in test_param_prob.h to use atoms/ prefix

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

* Fix column-major parameter ordering in parameterized matmul (#72)

* Fix column-major parameter ordering in parameterized matmul

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>

* Run clang-format on changed files

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

* introduce explicit transpose function for dense matrix

* clean up refresh dense right

* clean up tests...

* one more test

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: dance858 <danielcederberg1@gmail.com>

* add test that fails with current appraoch

* new parameter abstraction that fixess the fialing test

* remove dead code

* reset csc

* add raise error to catch bugs

* add initial attempt for fixing parameters and broadcasting (#73)

* add initial attempt for fixing parameters and broadcasting

* add test for params with broadcast

* cleanup test to fit more with other tests style

* some progress on supporting backwards compatible constants

* add some parameter broadcast tests as well

* cleanup left matmul as well

* some very minor cleanups

* some error checks and numerical diff to tests

* we don't always have to run forward of parameter in left matmul

* we don't always have to call forward for parameter node in vector mult

* comment out forward parameter pass in scalar mult because it is not needed, I think

* add test for scalar case to be consistent with vector mult

---------

Co-authored-by: dance858 <danielcederberg1@gmail.com>

* error message and format

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: dance858 <danielcederberg1@gmail.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.

2 participants