Skip to content

Fix colmajor param matmul#71

Closed
Transurgeon wants to merge 21 commits intomainfrom
fix-colmajor-param-matmul
Closed

Fix colmajor param matmul#71
Transurgeon wants to merge 21 commits intomainfrom
fix-colmajor-param-matmul

Conversation

@Transurgeon
Copy link
Copy Markdown
Collaborator

This PR fixes the refresh_param_values functions to read the parameter values as if they were flattened in column order (which is actually always the case for CVXPY/DNLP). The changes should be minimal and quite clean.
There are still some questions about the sparse parameters, but maybe let's revisit that at a later time.
Currently it will still form a "dense" parameter vector since it takes the shape of the array. I made it so that we select the correct values in column-order, but it won't be as efficient since we might still need to go through all the structural zeros.

Transurgeon and others added 16 commits March 25, 2026 16:30
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>
- 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>
Resolves conflicts from main's workspace refactor (iwork/dwork -> work->),
elementwise atom split (elementwise_univariate -> full_dom/restricted_dom),
chain rule refactor, vstack addition, and numerical diff checker.

Removed stale test_jacobian_composite_log tests (incompatible with main's
chain rule refactor; covered by test_chain_rule_jacobian and numerical diff).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolves conflicts from folder structure refactor (#63) and more tests (#62).
Moves scalar_mult/vector_mult to src/affine/ and test files to new
subdirectory structure. Updates affine.h declarations with parameter support
signatures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve merge conflicts in parameter.c and scalar_mult.c: keep
parameter-support-v2 features (parameter_expr, param_id, free_type_data)
while adopting _impl suffix naming from main. Fix old 2-arg
new_left_matmul calls in test_chain_rule_jacobian.h to use new 3-arg
signature with NULL param_node.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve conflicts from quad-form chain rule PRs (#65, #66):
- Keep parameter_expr struct from this branch
- Update new_left_matmul calls in new tests to use 3-arg signature (NULL param_node)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve conflicts from matmul chain rule PR (#67):
- subexpr.h: keep both vector_mult_expr and new matmul_expr/const types
- dense_matrix.c: adopt shared I_kron_A functions, keep update_values
- Add missing dense_matrix.h include in right_matmul.c
- Update new matmul tests to use 3-arg left_matmul signature

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/affine/const_scalar_mult.c
#	src/affine/const_vector_mult.c
#	src/affine/constant.c
#	src/atoms/affine/const_scalar_mult.c
#	src/atoms/affine/const_vector_mult.c
#	src/atoms/affine/constant.c
#	src/atoms/affine/parameter.c
#	src/atoms/affine/right_matmul.c
#	src/atoms/affine/scalar_mult.c
#	src/atoms/affine/vector_mult.c
#	tests/jacobian_tests/affine/test_scalar_mult.h
#	tests/jacobian_tests/affine/test_vector_mult.h
#	tests/wsum_hess/affine/test_scalar_mult.h
#	tests/wsum_hess/affine/test_vector_mult.h
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve conflicts from tracked allocation PR (#70): use SP_CALLOC/SP_MALLOC
macros in parameter-support files while keeping parameter-specific types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
@Transurgeon
Copy link
Copy Markdown
Collaborator Author

this is a duplicate PR of #72 .. we can close it (but this has the full changes from main.. so maybe worth keeping until we merge the other PRs).

@Transurgeon
Copy link
Copy Markdown
Collaborator Author

Transurgeon commented Apr 7, 2026

I'll close this PR since @dance858 resumed work on #53, with a fix for parameters appearing in multiple expressions.

@Transurgeon Transurgeon closed this Apr 7, 2026
@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