Skip to content

Commit

Permalink
adding some minor changes like typing and adding a convex attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
William Zijie Zhang authored and William Zijie Zhang committed Aug 8, 2024
1 parent 3b244f2 commit 921cd71
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cvxpy/reductions/cvx_attr2constr.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'diag',
'PSD',
'NSD',
'bounds'
'bounds',
'sparsity'
]

# Attributes that define lower and upper bounds.
Expand All @@ -57,14 +58,14 @@
]


def convex_attributes(variables):
def convex_attributes(variables) -> List[str]:
"""Returns a list of the (constraint-generating) convex attributes present
among the variables.
"""
return attributes_present(variables, CONVEX_ATTRIBUTES)


def attributes_present(variables, attr_map):
def attributes_present(variables, attr_map) -> List[str]:
"""Returns a list of the relevant attributes present
among the variables.
"""
Expand All @@ -87,7 +88,7 @@ def recover_value_for_variable(variable, lowered_value, project: bool = True):
return lowered_value


def lower_value(variable, value):
def lower_value(variable, value) -> np.ndarray:
if attributes_present([variable], SYMMETRIC_ATTRIBUTES):
return value[np.triu_indices(variable.shape[0])]
elif variable.attributes['diag']:
Expand Down Expand Up @@ -136,11 +137,10 @@ def apply(self, problem):
new_attr = var.attributes.copy()
for key in reduction_attributes:
if new_attr[key]:
new_var = True
if key == 'bounds':
new_var = True
new_attr[key] = None
else:
new_var = True
new_attr[key] = False

if attributes_present([var], SYMMETRIC_ATTRIBUTES):
Expand Down Expand Up @@ -185,7 +185,7 @@ def apply(self, problem):
inverse_data = (id2new_var, id2old_var, cons_id_map)
return cvxtypes.problem()(obj, constr), inverse_data

def invert(self, solution, inverse_data):
def invert(self, solution, inverse_data) -> Solution:
if not inverse_data:
return solution

Expand Down

0 comments on commit 921cd71

Please sign in to comment.