Exemplo n.º 1
0
    def test_constant(self):
        """Test the parameter class.
        """
        x = Constant(2)
        y = Constant(2j+1)
        z = Constant(2j)

        assert not x.is_complex()
        assert not x.is_imag()
        assert y.is_complex()
        assert not y.is_imag()
        assert z.is_complex()
        assert z.is_imag()
Exemplo n.º 2
0
 def test_conj(self):
     """Test imag.
     """
     A = np.ones((2, 2))
     expr = Constant(A) + 1j*Constant(A)
     expr = cvx.conj(expr)
     assert not expr.is_real()
     assert expr.is_complex()
     assert not expr.is_imag()
     self.assertItemsAlmostEqual(expr.value, A - 1j*A)
Exemplo n.º 3
0
 def test_imag(self) -> None:
     """Test imag.
     """
     A = np.ones((2, 2))
     expr = Constant(A) + 2j*Constant(A)
     expr = cvx.imag(expr)
     assert expr.is_real()
     assert not expr.is_complex()
     assert not expr.is_imag()
     self.assertItemsAlmostEqual(expr.value, 2*A)
Exemplo n.º 4
0
    def test_real(self):
        """Test real.
        """
        A = np.ones((2, 2))
        expr = Constant(A) + 1j*Constant(A)
        expr = cvx.real(expr)
        assert expr.is_real()
        assert not expr.is_complex()
        assert not expr.is_imag()
        self.assertItemsAlmostEqual(expr.value, A)

        x = Variable(complex=True)
        expr = cvx.imag(x) + cvx.real(x)
        assert expr.is_real()