예제 #1
0
 def test_parameter_arithmetic(self, p, q):
     """Test parameter arithmetic works as expected,"""
     pp = FreeParameter("x")
     qq = FreeParameter("y")
     pp.val = p
     qq.val = q
     binary_arithmetic(pp, qq, p, q)
예제 #2
0
    def test_par_evaluate_dtype_TF(self, p, dtype):
        """Test the TF parameter evaluation works when a dtype is provided"""
        pytest.importorskip("tensorflow", minversion="2.0")
        import tensorflow as tf

        x = FreeParameter("x")
        x.val = tf.Variable(p)
        res = par_evaluate(x, dtype=dtype)
        assert res.dtype is tf.as_dtype(dtype)
    def test_par_evaluate(self, p):
        x = FreeParameter("x")
        with pytest.raises(ParameterError, match="unbound parameter with no default value"):
            par_evaluate(x)

        # val only
        x.val = p
        assert np.all(par_evaluate(x) == p)

        # default only
        x.val = None
        x.default = p
        assert np.all(par_evaluate(x) == p)

        # both val and default
        x.val = p
        x.default = 0.0
        assert np.all(par_evaluate(x) == p)
예제 #4
0
 def test_parameter_unary_negation(self, p):
     """Test unary negation works as expected."""
     pp = FreeParameter("x")
     pp.val = p
     assert par_evaluate(-p) == pytest.approx(-p)
     assert par_evaluate(-pp) == pytest.approx(-p)
예제 #5
0
 def test_parameter_right_literal_arithmetic(self, p, q):
     """Test parameter arithmetic works as expected."""
     pp = FreeParameter("x")
     pp.val = p
     binary_arithmetic(pp, q, p, q)
예제 #6
0
 def test_parameter_left_literal_arithmetic(self, p, q):
     """Test parameter arithmetic works as expected."""
     qq = FreeParameter("x")
     qq.val = q
     binary_arithmetic(p, qq, p, q)
예제 #7
0
 def test_par_evaluate_dtype_numpy(self, p, dtype):
     """Test the numpy parameter evaluation works when a dtype is provided"""
     x = FreeParameter("x")
     x.val = p
     res = par_evaluate(x, dtype=dtype)
     assert res.dtype.type is dtype