示例#1
0
    def test_fx_to_gx(self):
        res = autodiff(lambda x1: x1**x1, 3)
        assert res.value == 27 and res.derivative == pytest.approx(56.6625)

        res = autodiff(lambda x1: (x1**1.1)**(x1**1.1), 3)
        assert res.value == pytest.approx(
            57.1921) and res.derivative == pytest.approx(155.072)
示例#2
0
    def test_d_of_power(self):
        res = autodiff(lambda x1: x1**2, 3)
        assert res.value == 9 and res.derivative == 6

        res = autodiff(lambda x1: x1**0, 3)
        assert res.value == 1 and res.derivative == 0

        res = autodiff(lambda x1, x2: x1**x2, 3, 2)
        assert res.value == 9 and res.derivative == 6
示例#3
0
文件: model.py 项目: pf4d/issm
    def __init__(self):  #{{{

        # classtype=model.properties

        # for classe in dict.keys(classtype):
        # 	print classe
        # 	self.__dict__[classe] = classtype[str(classe)]

        self.mesh = mesh2d()
        self.mask = mask()
        self.geometry = geometry()
        self.constants = constants()
        self.smb = SMBforcing()
        self.basalforcings = basalforcings()
        self.materials = matice()
        self.damage = damage()
        self.friction = friction()
        self.flowequation = flowequation()
        self.timestepping = timestepping()
        self.initialization = initialization()
        self.rifts = rifts()
        self.slr = slr()

        self.debug = debug()
        self.verbose = verbose()
        self.settings = settings()
        self.toolkits = toolkits()
        self.cluster = generic()

        self.balancethickness = balancethickness()
        self.stressbalance = stressbalance()
        self.groundingline = groundingline()
        self.hydrology = hydrologyshreve()
        self.masstransport = masstransport()
        self.thermal = thermal()
        self.steadystate = steadystate()
        self.transient = transient()
        self.levelset = levelset()
        self.calving = calving()
        self.gia = giaivins()

        self.autodiff = autodiff()
        self.inversion = inversion()
        self.qmu = qmu()
        self.amr = amr()

        self.results = results()
        self.outputdefinition = outputdefinition()
        self.radaroverlay = radaroverlay()
        self.miscellaneous = miscellaneous()
        self.private = private()
示例#4
0
 def test_chain(self, f, args):
     # import pdb; pdb.set_trace()
     res = autodiff(f, *args)
     assert res.value == f(*args)
     assert res.derivative == pytest.approx(finite_diff(f, *args), rel=1e-3)
示例#5
0
    def test_d_of_constant(self):
        res = autodiff(lambda x1: 2, 111)
        assert res.value == 2 and res.derivative == 0

        res = autodiff(lambda x1, x2: x2, 2, 3)
        assert res.value == 3 and res.derivative == 0
示例#6
0
    def test_d_of_exp(self):
        res = autodiff(lambda x1: 2**x1, 3)
        assert res.value == 8 and res.derivative == pytest.approx(5.545177)

        res = autodiff(lambda x1, x2: x2**x1, 3, 2)
        assert res.value == 8 and res.derivative == pytest.approx(5.545177)
示例#7
0
 def test_d_of_product(self):
     res = autodiff(lambda x1: x1 * x1, 3)
     assert res.value == 9 and res.derivative == 6
示例#8
0
    def test_d_of_sub_with_constant(self):
        res = autodiff(lambda x1: x1 - 99, 2)
        assert res.value == -97 and res.derivative == 1

        res = autodiff(lambda x1: 99 - x1, 2)
        assert res.value == 97 and res.derivative == -1
示例#9
0
 def test_d_of_sub(self):
     res = autodiff(lambda x1: x1 - x1, 3)
     assert res.value == 0 and res.derivative == 0
示例#10
0
 def test_d_of_sum(self):
     res = autodiff(lambda x1: x1 + x1, 3)
     assert res.value == 6 and res.derivative == 2
示例#11
0
    def test_d_of_sum_with_constant(self):
        res = autodiff(lambda x1: x1 + 99, 2)
        assert res.value == 101 and res.derivative == 1

        res = autodiff(lambda x1: 99 + x1, 2)
        assert res.value == 101 and res.derivative == 1
示例#12
0
 def test_d_of_itself(self):
     res = autodiff(lambda x1: x1, 2)
     assert res.value == 2 and res.derivative == 1