Skip to content

Commit 14ec3af

Browse files
committed
fixes crashes for left matmul
1 parent ee6e20c commit 14ec3af

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

cvxpy/cvxcore/python/canonInterface.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ def get_problem_matrix(linOps,
292292
default_canon_backend = get_default_canon_backend()
293293
canon_backend = default_canon_backend if not canon_backend else canon_backend
294294

295+
# DIFFENGINE is a reduction-layer replacement for ConeMatrixStuffing and
296+
# has no lin_ops backend of its own. When code paths reach this matrix
297+
# builder directly (e.g. tests that bypass the stuffing reduction), fall
298+
# through to the CPP backend so the lin_ops pipeline still works.
299+
if canon_backend == s.DIFFENGINE_BACKEND:
300+
canon_backend = s.CPP_CANON_BACKEND
301+
295302
if canon_backend == s.CPP_CANON_BACKEND:
296303
from cvxpy.cvxcore.python.cppbackend import build_matrix
297304
return build_matrix(id_to_col, param_to_size, param_to_col, var_length, constr_length, linOps)

cvxpy/reductions/solvers/nlp_solvers/diff_engine/converters.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,24 @@ def convert_matmul(expr, children, var_dict, n_vars, param_dict):
6565

6666
if left_arg.is_constant():
6767
A = _matmul_normalize_1d(left_arg.value, 'left')
68-
param_node = param_dict[left_arg.id] if isinstance(left_arg, cp.Parameter) else None
68+
if isinstance(left_arg, cp.Parameter):
69+
param_node = param_dict[left_arg.id]
70+
elif left_arg.parameters():
71+
param_node = left_child
72+
else:
73+
param_node = None
6974
if sparse.issparse(A):
7075
return make_sparse_left_matmul(param_node, right_child, A)
7176
return make_dense_left_matmul(param_node, right_child, A)
7277

7378
elif right_arg.is_constant():
7479
A = _matmul_normalize_1d(right_arg.value, 'right')
75-
param_node = param_dict[right_arg.id] if isinstance(right_arg, cp.Parameter) else None
80+
if isinstance(right_arg, cp.Parameter):
81+
param_node = param_dict[right_arg.id]
82+
elif right_arg.parameters():
83+
param_node = right_child
84+
else:
85+
param_node = None
7686
if sparse.issparse(A):
7787
return make_sparse_right_matmul(param_node, left_child, A)
7888
return make_dense_right_matmul(param_node, left_child, A)

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ testpaths = [
5959
"cvxpy/tests/"
6060
]
6161

62+
[tool.uv.sources]
63+
# Local dev override: build sparsediffpy from the adjacent source tree so we
64+
# pick up bindings (vstack / diag_mat / upper_tri / parameter support) that
65+
# haven't shipped a PyPI release yet. Remove once sparsediffpy >= 0.3.0 is
66+
# published.
67+
sparsediffpy = { path = "../SparseDiffPy", editable = true }
68+
6269
[build-system]
6370
requires = [
6471
"numpy >= 2.0.0",

0 commit comments

Comments
 (0)