The point of the test was to try out the edge case of p=0, which should give an expression of all 1's.
But I get the following error. Any idea what I'm doing wrong, @SteveDiamond?
$ ipython mytest.py
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/ajfriend/Dropbox/work/cvxpy/mytest.py in <module>()
7
8 prob = cvx.Problem(cvx.Maximize(cvx.sum_entries(g) + y), [0 <= x, x <= 1, y <= 2])
----> 9 prob.solve()
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/problems/problem.pyc in solve(self, *args, **kwargs)
154 return func(self, *args, **kwargs)
155 else:
--> 156 return self._solve(*args, **kwargs)
157
158 @classmethod
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/problems/problem.pyc in _solve(self, solver, ignore_dcp, warm_start, verbose, **kwargs)
224 raise Exception("Problem does not follow DCP rules.")
225
--> 226 objective, constraints = self.canonicalize()
227 # Choose a solver/check the chosen solver.
228 if solver is None:
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/problems/problem.pyc in canonicalize(self)
101 """
102 canon_constr = []
--> 103 obj, constr = self.objective.canonical_form
104 canon_constr += constr
105
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/performance_utils.pyc in _lazyprop(self)
36 """
37 if not hasattr(self, attr_name):
---> 38 setattr(self, attr_name, func(self))
39 return getattr(self, attr_name)
40 return _lazyprop
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/canonical.pyc in canonical_form(self)
44 A tuple of (affine expression, [constraints]).
45 """
---> 46 return self.canonicalize()
47
48 @abc.abstractmethod
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/problems/objective.pyc in canonicalize(self)
82 """Negates the target expression's objective.
83 """
---> 84 obj, constraints = super(Maximize, self).canonicalize()
85 return (lu.neg_expr(obj), constraints)
86
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/problems/objective.pyc in canonicalize(self)
44 """Pass on the target expression's objective and constraints.
45 """
---> 46 return self._expr.canonical_form
47
48 def variables(self):
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/performance_utils.pyc in _lazyprop(self)
36 """
37 if not hasattr(self, attr_name):
---> 38 setattr(self, attr_name, func(self))
39 return getattr(self, attr_name)
40 return _lazyprop
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/canonical.pyc in canonical_form(self)
44 A tuple of (affine expression, [constraints]).
45 """
---> 46 return self.canonicalize()
47
48 @abc.abstractmethod
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/atoms/atom.pyc in canonicalize(self)
114 constraints = []
115 for arg in self.args:
--> 116 obj, constr = arg.canonical_form
117 arg_objs.append(obj)
118 constraints += constr
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/performance_utils.pyc in _lazyprop(self)
36 """
37 if not hasattr(self, attr_name):
---> 38 setattr(self, attr_name, func(self))
39 return getattr(self, attr_name)
40 return _lazyprop
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/utilities/canonical.pyc in canonical_form(self)
44 A tuple of (affine expression, [constraints]).
45 """
---> 46 return self.canonicalize()
47
48 @abc.abstractmethod
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/atoms/atom.pyc in canonicalize(self)
109 # Non-parameterized expressions are evaluated immediately.
110 else:
--> 111 return Constant(self.value).canonical_form
112 else:
113 arg_objs = []
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/expressions/constants/constant.pyc in __init__(self, value)
34 self._sparse = True
35 else:
---> 36 self._value = intf.DEFAULT_INTERFACE.const_to_matrix(value)
37 self._sparse = False
38 # Set DCP attributes.
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/interface/base_matrix_interface.pyc in new_converter(self, value, convert_scalars)
47 def scalar_const(converter):
48 def new_converter(self, value, convert_scalars=False):
---> 49 if not convert_scalars and cvxpy.interface.matrix_utilities.is_scalar(value):
50 return cvxpy.interface.matrix_utilities.scalar_value(value)
51 else:
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/interface/matrix_utilities.pyc in is_scalar(constant)
76 # Is the constant a scalar?
77 def is_scalar(constant):
---> 78 return size(constant) == (1, 1)
79
80 def from_2D_to_1D(constant):
/Users/ajfriend/Dropbox/work/cvxpy/cvxpy/interface/matrix_utilities.pyc in size(constant)
68 return INTERFACES[sp.csc_matrix].size(constant)
69 else:
---> 70 raise TypeError("%s is not a valid type for a Constant value." % type(constant))
71
72 # Is the constant a column vector?
TypeError: <type 'NoneType'> is not a valid type for a Constant value.