picos.sum does not work on variable vectors
Calling picos.sum(v), when v is an instance of picos.expressions.Variable with multiple entries (i.e. a vector), raises a TypeError.
MWE:
import picos as pic
p=picos.Problem()
v=p.add_variable('v',15)
pic.sum(v)
Actual Result: TypeError: dimension too small (see traceback at end)
Expected result:
<1×1 Affine Expression: ∑(v[i] : i ∈ [0…14])>
The expected result is produced if instead of pic.sum(v) I take pic.sum(v+0), which is why I report this as a bug rather than a feature request.
The root cause of this issue appears to be that a variable vector is not properly an iterable, so you cant do for item in v
.
But the code to do sum assumes that this is possible.
See Traceback:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-fd05a1d5fdae> in <module>
----> 1 picos.sum(v)
~/miniconda3/envs/uq/lib/python3.6/site-packages/picos/tools.py in sum(lst, it, indices)
74 DeprecationWarning)
75
---> 76 if not all(isinstance(expression, Expression) for expression in lst):
77 return builtin_sum(lst)
78
~/miniconda3/envs/uq/lib/python3.6/site-packages/picos/tools.py in <genexpr>(.0)
74 DeprecationWarning)
75
---> 76 if not all(isinstance(expression, Expression) for expression in lst):
77 return builtin_sum(lst)
78
~/miniconda3/envs/uq/lib/python3.6/site-packages/picos/expressions.py in __getitem__(self, index)
3973 JJ = rangeT
3974 VV = [1.] * nsz
-> 3975 newfacs = {self: spmatrix(VV, II, JJ, (nsz, sz))}
3976 if not self.constant is None:
3977 newcons = self.constant[rangeT]
~/miniconda3/envs/uq/lib/python3.6/site-packages/picos/tools.py in spmatrix(*args, **kwargs)
2174 """
2175 try:
-> 2176 return cvx.spmatrix(*args, **kwargs)
2177 except TypeError as error:
2178 # CVXOPT does not like NumPy's int64 scalar type for indices, so attempt
TypeError: dimension too small