MCPcopy Create free account
hub / github.com/numpy/numpy / test_poly1d_math

Method test_poly1d_math

numpy/lib/tests/test_polynomial.py:45–64  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

43 assert_equal(q(5), 86.0)
44
45 def test_poly1d_math(self):
46 # here we use some simple coeffs to make calculations easier
47 p = np.poly1d([1., 2, 4])
48 q = np.poly1d([4., 2, 1])
49 assert_equal(p/q, (np.poly1d([0.25]), np.poly1d([1.5, 3.75])))
50 assert_equal(p.integ(), np.poly1d([1/3, 1., 4., 0.]))
51 assert_equal(p.integ(1), np.poly1d([1/3, 1., 4., 0.]))
52
53 p = np.poly1d([1., 2, 3])
54 q = np.poly1d([3., 2, 1])
55 assert_equal(p * q, np.poly1d([3., 8., 14., 8., 3.]))
56 assert_equal(p + q, np.poly1d([4., 4., 4.]))
57 assert_equal(p - q, np.poly1d([-2., 0., 2.]))
58 assert_equal(p ** 4, np.poly1d([1., 8., 36., 104., 214., 312., 324., 216., 81.]))
59 assert_equal(p(q), np.poly1d([9., 12., 16., 8., 6.]))
60 assert_equal(q(p), np.poly1d([3., 12., 32., 40., 34.]))
61 assert_equal(p.deriv(), np.poly1d([2., 2.]))
62 assert_equal(p.deriv(2), np.poly1d([2.]))
63 assert_equal(np.polydiv(np.poly1d([1, 0, -1]), np.poly1d([1, 1])),
64 (np.poly1d([1., -1.]), np.poly1d([0.])))
65
66 @pytest.mark.parametrize("type_code", TYPE_CODES)
67 def test_poly1d_misc(self, type_code: str) -> None:

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
pFunction · 0.85
integMethod · 0.45
derivMethod · 0.45

Tested by

no test coverage detected