Beispiel #1
0
    def test_deepcopy_trust_input(self):
        a = dscalar()  # the a is for 'anonymous' (un-named).
        x, s = dscalars("xs")

        f = function(
            [
                x,
                In(a, value=1.0, name="a"),
                In(s, value=0.0, update=s + a * x, mutable=True),
            ],
            s + a * x,
        )
        f.trust_input = True
        try:
            g = copy.deepcopy(f)
        except NotImplementedError as e:
            if e[0].startswith("DebugMode is not picklable"):
                return
            else:
                raise
        assert f.trust_input is g.trust_input
        f(np.asarray(2.0))
        with pytest.raises((ValueError, AttributeError, InvalidValueError)):
            f(2.0)
        g(np.asarray(2.0))
        with pytest.raises((ValueError, AttributeError, InvalidValueError)):
            g(2.0)
Beispiel #2
0
    def test_default_values(self):
        # Check that default values are restored
        # when an exception occurs in interactive mode.

        a, b = dscalars("a", "b")
        c = a + b
        funct = function([In(a, name="first"), In(b, value=1, name="second")], c)
        x = funct(first=1)
        try:
            funct(second=2)
        except TypeError:
            assert funct(first=1) == x