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

Method test_polyfit

numpy/ma/tests/test_extras.py:1410–1447  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1408class TestPolynomial:
1409 #
1410 def test_polyfit(self):
1411 # Tests polyfit
1412 # On ndarrays
1413 x = np.random.rand(10)
1414 y = np.random.rand(20).reshape(-1, 2)
1415 assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3))
1416 # ON 1D maskedarrays
1417 x = x.view(MaskedArray)
1418 x[0] = masked
1419 y = y.view(MaskedArray)
1420 y[0, 0] = y[-1, -1] = masked
1421 #
1422 (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True)
1423 (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3,
1424 full=True)
1425 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1426 assert_almost_equal(a, a_)
1427 #
1428 (C, R, K, S, D) = polyfit(x, y[:, -1], 3, full=True)
1429 (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, -1], 3, full=True)
1430 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1431 assert_almost_equal(a, a_)
1432 #
1433 (C, R, K, S, D) = polyfit(x, y, 3, full=True)
1434 (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1,:], 3, full=True)
1435 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1436 assert_almost_equal(a, a_)
1437 #
1438 w = np.random.rand(10) + 1
1439 wo = w.copy()
1440 xs = x[1:-1]
1441 ys = y[1:-1]
1442 ws = w[1:-1]
1443 (C, R, K, S, D) = polyfit(x, y, 3, full=True, w=w)
1444 (c, r, k, s, d) = np.polyfit(xs, ys, 3, full=True, w=ws)
1445 assert_equal(w, wo)
1446 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1447 assert_almost_equal(a, a_)
1448
1449 def test_polyfit_with_masked_NaNs(self):
1450 x = np.random.rand(10)

Callers

nothing calls this directly

Calls 7

assert_almost_equalFunction · 0.90
polyfitFunction · 0.90
assert_equalFunction · 0.90
reshapeMethod · 0.80
viewMethod · 0.45
compressedMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected