Skip to content

Commit 2a492a7

Browse files
Transurgeonclaude
andauthored
Centralize sparsediffpy import into _bindings.py (#174)
* Centralize sparsediffpy import into _bindings.py Move the duplicated try/except import of sparsediffpy from c_problem.py and converters.py into a single _bindings.py module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * cleanup fix * fix import issue * fix import for c_problem as well --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ce8fda1 commit 2a492a7

File tree

2 files changed

+2
-17
lines changed

2 files changed

+2
-17
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@
1616
"""
1717

1818
import numpy as np
19+
from sparsediffpy import _sparsediffengine as _diffengine
1920

2021
import cvxpy as cp
21-
22-
# Import the low-level C bindings
23-
try:
24-
from sparsediffpy import _sparsediffengine as _diffengine
25-
except ImportError as e:
26-
raise ImportError(
27-
"NLP support requires sparsediffpy. Install with: pip install sparsediffpy"
28-
) from e
29-
3022
from cvxpy.reductions.solvers.nlp_solvers.diff_engine.converters import (
3123
build_variable_dict,
3224
convert_expr,

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@
2121

2222
import numpy as np
2323
from scipy import sparse
24+
from sparsediffpy import _sparsediffengine as _diffengine
2425

2526
import cvxpy as cp
2627
from cvxpy.reductions.inverse_data import InverseData
2728

28-
# Import the low-level C bindings
29-
try:
30-
from sparsediffpy import _sparsediffengine as _diffengine
31-
except ImportError as e:
32-
raise ImportError(
33-
"NLP support requires sparsediffpy. Install with: pip install sparsediffpy"
34-
) from e
35-
3629

3730
def normalize_shape(shape):
3831
"""Normalize shape to 2D (d1, d2) for the C engine."""

0 commit comments

Comments
 (0)