MCPcopy
hub / github.com/numpy/numpy / test_roots

Method test_roots

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

Source from the content-addressed store, hash-verified

126 assert_(np.isrealobj(np.poly(np.concatenate((a, np.conjugate(a))))))
127
128 def test_roots(self):
129 assert_array_equal(np.roots([1, 0, 0]), [0, 0])
130
131 # Testing for larger root values
132 for i in np.logspace(10, 25, num=1000, base=10):
133 tgt = np.array([-1, 1, i])
134 res = np.sort(np.roots(poly.polyfromroots(tgt)[::-1]))
135 # Adapting the expected precision according to the root value,
136 # to take into account numerical calculation error
137 assert_almost_equal(res, tgt, 14 - int(np.log10(i)))
138
139 for i in np.logspace(10, 25, num=1000, base=10):
140 tgt = np.array([-1, 1.01, i])
141 res = np.sort(np.roots(poly.polyfromroots(tgt)[::-1]))
142 # Adapting the expected precision according to the root value,
143 # to take into account numerical calculation error
144 assert_almost_equal(res, tgt, 14 - int(np.log10(i)))
145
146 @pytest.mark.parametrize("dtyp", [int, np.float32, np.float64])
147 def test_roots_dtype(self, dtyp):

Callers

nothing calls this directly

Calls 4

assert_array_equalFunction · 0.90
assert_almost_equalFunction · 0.90
rootsMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected