Skip to content

Commit b6f34a3

Browse files
committed
Adds missing reshape orders
1 parent bcf7ede commit b6f34a3

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

dsp/cone_transforms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
import scipy.sparse as sp
1010
from cvxpy import SOC
1111
from cvxpy.atoms import reshape
12-
from cvxpy.atoms.affine.upper_tri import upper_tri_to_full
1312
from cvxpy.constraints import ExpCone
1413
from cvxpy.constraints.constraint import Constraint
1514
from cvxpy.constraints.psd import PSD
1615
from cvxpy.expressions.constants import Constant
1716
from cvxpy.problems.objective import Objective
1817
from cvxpy.reductions.dcp2cone.cone_matrix_stuffing import ConeDims
1918

19+
try:
20+
from cvxpy.expressions.variable import upper_tri_to_full
21+
except ImportError:
22+
from cvxpy.atoms.affine.upper_tri import upper_tri_to_full
2023

2124
def return_zero() -> float:
2225
return 0.0
@@ -493,9 +496,9 @@ def split_K_repr_affine(
493496
C = cp.Constant(0)
494497
D = cp.Constant(0)
495498
for v in convex_vars:
496-
C += -var_to_mat_mapping.get(v.id, 0) @ cp.vec(v)
499+
C += -var_to_mat_mapping.get(v.id, 0) @ cp.vec(v, order="F")
497500
for v in concave_vars:
498-
D += -var_to_mat_mapping.get(v.id, 0) @ cp.vec(v)
501+
D += -var_to_mat_mapping.get(v.id, 0) @ cp.vec(v, order="F")
499502

500503
return C, D, cp.Constant(b)
501504

@@ -579,6 +582,6 @@ def switch_convex_concave(
579582
inds = np.triu_indices(n, k=0) # includes diagonal
580583
v = v[inds]
581584

582-
constraints += [(P.T @ u_bar)[start:end] + cp.vec(v) == 0]
585+
constraints += [(P.T @ u_bar)[start:end] + cp.vec(v, order="F") == 0]
583586

584587
return KRepresentation(f=f_bar, t=t_bar, constraints=constraints)

dsp/problem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def semi_infinite_epigraph(
210210
inds = np.triu_indices(v.shape[0], k=0) # includes diagonal
211211
expr += A_ @ v[inds]
212212
else:
213-
expr += A_ @ cp.vec(v)
213+
expr += A_ @ cp.vec(v, order="F")
214214

215215
z = const_vec - expr # Ax + b in K
216216

dsp/saddle_atoms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def _get_K_repr(self, local_to_glob: LocalToGlob, switched: bool = False) -> KRe
282282
epi_exp = cp.Variable(self.exponents.size, name="exp_epi")
283283
constraints = [
284284
epi_exp >= self.exponents, # handles composition in exponent
285-
ExpCone(cp.reshape(epi_exp + u, (f_local.size,)), np.ones(f_local.size), f_local),
285+
ExpCone(cp.reshape(epi_exp + u, (f_local.size,), order="F"), np.ones(f_local.size), f_local),
286286
t >= -u - 1,
287287
]
288288

@@ -430,7 +430,7 @@ def _get_K_repr(self, local_to_glob: LocalToGlob, switched: bool = False) -> KRe
430430
local_to_glob.y_size if not switched else local_to_glob.x_size,
431431
name="f_global_saddle_quad_form",
432432
)
433-
constraints += [F_global == B.T @ cp.vec(F_local)]
433+
constraints += [F_global == B.T @ cp.vec(F_local, order="F")]
434434

435435
K_repr = KRepresentation(
436436
f=F_global,

dsp/saddle_extremum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def __init__(self, f: cp.Expression) -> None:
243243

244244
obj = -f
245245
for x, y in zip(x_vars, y_vars, strict=True):
246-
obj += dsp.inner(cp.vec(y), cp.vec(x))
246+
obj += dsp.inner(cp.vec(y, order="F"), cp.vec(x, order="F"))
247247

248248
super().__init__(obj, [])
249249

0 commit comments

Comments
 (0)