コード例 #1
0
    def test_par_is_symbolic(self, r):
        """Recognizing symbolic parameters."""
        p = FreeParameter("x")
        q = MeasuredParameter(RegRef(0))

        assert not par_is_symbolic(r)
        assert par_is_symbolic(pf.sin(r))
        assert par_is_symbolic(q)
        assert par_is_symbolic(p)
        assert par_is_symbolic(pf.sin(p))
        assert par_is_symbolic(p + r)
        assert par_is_symbolic(p - r)
        assert par_is_symbolic(p * r)
        assert par_is_symbolic(p / r)
        assert par_is_symbolic(p**r)
        assert par_is_symbolic(p - p)  # no simplification

        # object array with symbols
        a = np.array([[0.1, 3, 0], [0.3, 2, p], [1, 2, 4]])
        assert a.dtype == object
        assert par_is_symbolic(a)

        # object array, no symbols
        a = np.array([[0.1, 3, 0], [0.3, 2, 0], [1, 2, 4]], dtype=object)
        assert a.dtype == object
        assert not par_is_symbolic(a)

        # float array, no symbols
        a = np.array([[0.1, 3, 0], [0.3, 2, 0], [1, 2, 4]])
        assert a.dtype != object
        assert not par_is_symbolic(a)
        assert par_is_symbolic(pf.sin(a))
コード例 #2
0
 def test_measured_par(self):
     """Compare two ways of creating measured parameter instances from RegRefs."""
     r = RegRef(0)
     s = RegRef(1)
     p = MeasuredParameter(r)
     assert p == r.par
     assert p != s.par
コード例 #3
0
    def test_par_regref_deps(self):
        """RegRef dependencies of parameters."""
        r = [RegRef(k) for k in range(2)]
        R0 = set([r[0]])
        R = set(r)

        s = 0.4
        x = FreeParameter("x")
        p = MeasuredParameter(r[0])
        q = MeasuredParameter(r[1])

        assert par_regref_deps(s) == set()
        assert par_regref_deps(x) == set()
        assert par_regref_deps(p) == R0
        assert par_regref_deps(s * p) == R0
        assert par_regref_deps(x * p) == R0
        assert par_regref_deps(p + q) == R
        assert par_regref_deps(s * p + q**x) == R
コード例 #4
0
    def test_raw_parameter_printing(self):
        """Raw printing of parameter expressions."""

        c = MeasuredParameter(RegRef(1))
        d = FreeParameter("x")

        assert str(c) == "q1"
        assert str(d) == "{x}"
        assert str(0.1234567 * d) == "0.1234567*{x}"
        assert str(np.array([0, 1, -3, 0.987654]) * d) == "[0 1.0*{x} -3.0*{x} 0.987654*{x}]"
        assert str(pf.exp(1 + c) / d ** 2) == "exp(q1 + 1)/{x}**2"
コード例 #5
0
    def test_par_str(self):
        """String representations of parameters."""

        a = 0.1234567
        b = np.array([0, 0.987654])
        c = MeasuredParameter(RegRef(1))
        d = FreeParameter('x')

        assert par_str(a) == '0.1235'  # rounded to 4 decimals
        assert par_str(b) == '[0.     0.9877]'
        assert par_str(c) == 'q1'
        assert par_str(d) == '{x}'
        assert par_str(b * d) == '[0 0.987654*{x}]'  # not rounded to 4 decimals due to Sympy's internal settings (object array!)
コード例 #6
0
    def test_par_str(self):
        """String representations of parameters."""

        a = 0.1234567
        b = np.array([0, 0.987654])
        c = MeasuredParameter(RegRef(1))
        d = FreeParameter("x")

        assert par_str(a) == "0.1235"  # rounded to 4 decimals
        assert par_str(b) == "[0.     0.9877]"
        assert par_str(c) == "q1"
        assert par_str(d) == "{x}"
        assert (
            par_str(b * d) == "[0 0.987654*{x}]"
        )  # not rounded to 4 decimals due to Sympy's internal settings (object array!)