Compilation breaks for problems with no constraints
syanga opened this issue · comments
Alan Yang commented
In the example, when I replace
problem = cp.Problem(cp.Minimize(cp.sum_squares(A @ x - b)), [x >= 0])
with
problem = cp.Problem(cp.Minimize(cp.sum_squares(A @ x - b)))
I get
>>> cpg.generate_code(problem, code_dir='nonneg_LS', solver='SCS')
Generating code with CVXPYgen ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/Caskroom/miniforge/base/envs/veclib/lib/python3.10/site-packages/cvxpygen/cpg.py", line 672, in generate_code
utils.write_module_def(f, info_opt, info_usr, info_can)
File "/opt/homebrew/Caskroom/miniforge/base/envs/veclib/lib/python3.10/site-packages/cvxpygen/utils.py", line 1227, in write_module_def
max(info_usr[C.D_NAME_TO_SIZE].values())
ValueError: max() arg is an empty sequence
Replacing line 1227 with
max(info_usr[C.D_NAME_TO_SIZE].values(), default=0)
seems to fix the issue.
Steven Diamond commented
Fixed on master.