def test_idiv(self): x = UTPS(numpy.array([1.,2.,3.]), P = 1) x2 = x.copy() y = UTPS(numpy.array([5.,7.,11.]), P = 1) x /= y assert_array_almost_equal(div(x2,y,x2).data,x.data)
def test_idiv_vectorized(self): try: import sympy except: return x = UTPS(numpy.array([1.,2.,3, 4.,6.]),P = 2) y = UTPS(numpy.array([5.,7.,11, 1.,2.]),P = 2) t = sympy.symbols('t') sx1 = x.data[0] + x.data[1]*t + x.data[2]*t**2 sy1 = y.data[0] + y.data[1]*t + y.data[2]*t**2 sz1 = sx1/sy1 sx2 = x.data[0] + x.data[3]*t + x.data[4]*t**2 sy2 = y.data[0] + y.data[3]*t + y.data[4]*t**2 sz2 = sx2/sy2 correct1 = numpy.array([ x.data[0]/y.data[0], sz1.series(t).coeff(t).evalf(), sz1.series(t).coeff(t**2).evalf()]) correct2 = numpy.array([ x.data[0]/y.data[0], sz2.series(t).coeff(t).evalf(), sz2.series(t).coeff(t**2).evalf()]) x = div(x,y,x) assert_array_almost_equal(correct1, x.data[[0,1,2]]) assert_array_almost_equal(correct2, x.data[[0,3,4]])
def test_compare_pushforward_pullback_derivatives2(self): x = UTPS(numpy.array([1.,0.,0.,0.]), P = 1) y = UTPS(numpy.array([2.,1.,0.,0.]), P = 1) z = div(x,y) zbar = UTPS([1.,0.,0., 0.], P = 1) xbar = UTPS(numpy.zeros(4), P = 1) ybar = UTPS(numpy.zeros(4), P = 1) epb_div(x,y,z, zbar, xbar, ybar) facs = numpy.array([1.,1.,2.,6.]) assert_array_almost_equal((z.data*facs)[1:], (ybar.data*facs)[:-1])
def test_div_epb(self): x = UTPS(numpy.array([1.,2.,3.]), P = 1) y = UTPS(numpy.array([5.,7.,11.]), P = 1) z = div(x,y) zbar = UTPS(numpy.random.rand(3), P = 1) xbar = UTPS(numpy.zeros(3), P = 1) ybar = UTPS(numpy.zeros(3), P = 1) xbar2 = zbar/y ybar2 = - zbar*z/y epb_div(x,y,z, zbar, xbar, ybar) assert_array_almost_equal(xbar2.data, xbar.data) assert_array_almost_equal(ybar2.data, ybar.data)
def test_idiv(self): try: import sympy except: return x = UTPS(numpy.array([1.,4.,3.]), P = 1) x2 = UTPS(numpy.array([1.,4.,3.]), P = 1) y = UTPS(numpy.array([5.,1, 7.]), P = 1) x = div(x,y,x) assert_array_almost_equal([5.,1, 7.], y.data) t = sympy.symbols('t') sx = x2.data[0] + x2.data[1]*t + x2.data[2]*t**2 sy = y.data[0] + y.data[1]*t + y.data[2]*t**2 sz = sx/sy correct = numpy.array([ x2.data[0]/y.data[0], sz.series(t).coeff(t).evalf(), sz.series(t).coeff(t**2).evalf()]) assert_array_almost_equal(correct, x.data)
def test_div(self): x = UTPS(numpy.array([1.,2.,3.]), P = 1) y = UTPS(numpy.array([5.,7.,11.]), P = 1) z = x / y assert_array_almost_equal(div(x,y).data,z.data)