Fix column-major parameter ordering in parameterized matmul#72
Merged
dance858 merged 6 commits intoparameter-support-v2from Apr 7, 2026
Merged
Fix column-major parameter ordering in parameterized matmul#72dance858 merged 6 commits intoparameter-support-v2from
dance858 merged 6 commits intoparameter-support-v2from
Conversation
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>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
I cleaned up the code and the tests. We also raise an error now for sparse matrix parameters. |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.