Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant expressions involving the <class 'cvxpy.atoms.affine.transpose.transpose'> atom not supported. #2

Open
snietfeld opened this issue Dec 10, 2017 · 0 comments

Comments

@snietfeld
Copy link

If I modify the example code slightly to add a new parameter that requires a transpose operation, i.e.:

import cvxpy_codegen as cg
m = 10
n = 5
A = cg.Parameter(m, n, name='A')
b = cg.Parameter(m, name='b')
c = cg.Parameter(n, name='c')           # <--------- New param
x = cg.Variable(n, name='x')
f0 = cg.norm(A*x - b) - c.T*x           # <--------- Transpose added
prob = cg.Problem(cg.Minimize(f0))
prob.codegen('least_squares_example')

I get the following exception:

Traceback (most recent call last):
File "transpose_test.py", line 10, in
prob.codegen('least_squares_example')
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/problem.py", line 31, in codegen
CodeGenerator(obj, constraints, vars, params).codegen(target_dir)
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/code_generator.py", line 100, in codegen
self.template_vars.update(param_handler.get_template_vars())
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 72, in get_template_vars
self.process_expression(root_param)
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 92, in process_expression
data_arg = self.process_expression(expr.atom)
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/param/param_handler.py", line 121, in process_expression
data_list = get_atom_data(expr, arg_data)
File "/usr/local/lib/python3.5/dist-packages/cvxpy_codegen-0.0.1-py3.5.egg/cvxpy_codegen/atoms/atoms.py", line 68, in get_atom_data
raise TypeError("Constant expressions involving the %s atom not supported." % str(type(expr)))
TypeError: Constant expressions involving the <class 'cvxpy.atoms.affine.transpose.transpose'> atom not supported.

I can get it to run by removing the transpose operator and redefining the parameter as a row vector, i.e.: c = cg.Parameter(1,n, name='c')

...but it would be nice to support the canonical constraint form where c is a column vector. As it is I'll have to always remember to transpose that value in particular before passing in to the C function call or Python wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant