Skip to content

Commit

Permalink
Fix sign error with log_sum_exp (#1689)
Browse files Browse the repository at this point in the history
* fix sign error with log_sum_exp

* docs

(cherry picked from commit 06854d9)
  • Loading branch information
SteveDiamond authored and rileyjmurray committed May 16, 2022
1 parent d724a21 commit 55f1fa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cvxpy/atoms/log_sum_exp.py
Expand Up @@ -69,7 +69,8 @@ def _column_grad(self, value):
def sign_from_args(self) -> Tuple[bool, bool]:
"""Returns sign (is positive, is negative) of the expression.
"""
return (False, False)
# Non-negative when arg is non-negative.
return (self.args[0].is_nonneg(), False)

def is_atom_convex(self) -> bool:
"""Is the atom convex?
Expand Down
15 changes: 15 additions & 0 deletions cvxpy/tests/test_atoms.py
Expand Up @@ -1305,3 +1305,18 @@ def test_partial_transpose_exceptions(self) -> None:
cp.partial_transpose(X, dims=[2, 4], axis=0)
self.assertEqual(str(cm.exception),
"Dimension of system doesn't correspond to dimension of subsystems.")

def test_log_sum_exp(self) -> None:
"""Test log_sum_exp sign.
"""
# Test for non-negative x
x = Variable(nonneg=True)
atom = cp.log_sum_exp(x)
self.assertEqual(atom.curvature, s.CONVEX)
self.assertEqual(atom.sign, s.NONNEG)

# Test for non-positive x
x = Variable(nonpos=True)
atom = cp.log_sum_exp(x)
self.assertEqual(atom.curvature, s.CONVEX)
self.assertEqual(atom.sign, s.UNKNOWN)

0 comments on commit 55f1fa8

Please sign in to comment.