MCPcopy Index your code
hub / github.com/numpy/numpy / test_polyfit

Method test_polyfit

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

Source from the content-addressed store, hash-verified

1452class TestPolynomial:
1453
1454 def test_polyfit(self):
1455 # Tests polyfit
1456 # On ndarrays
1457 x = np.random.rand(10)
1458 y = np.random.rand(20).reshape(-1, 2)
1459 assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3))
1460 # ON 1D maskedarrays
1461 x = x.view(MaskedArray)
1462 x[0] = masked
1463 y = y.view(MaskedArray)
1464 y[0, 0] = y[-1, -1] = masked
1465 #
1466 (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True)
1467 (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3,
1468 full=True)
1469 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1470 assert_almost_equal(a, a_)
1471 #
1472 (C, R, K, S, D) = polyfit(x, y[:, -1], 3, full=True)
1473 (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, -1], 3, full=True)
1474 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1475 assert_almost_equal(a, a_)
1476 #
1477 (C, R, K, S, D) = polyfit(x, y, 3, full=True)
1478 (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1, :], 3, full=True)
1479 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1480 assert_almost_equal(a, a_)
1481 #
1482 w = np.random.rand(10) + 1
1483 wo = w.copy()
1484 xs = x[1:-1]
1485 ys = y[1:-1]
1486 ws = w[1:-1]
1487 (C, R, K, S, D) = polyfit(x, y, 3, full=True, w=w)
1488 (c, r, k, s, d) = np.polyfit(xs, ys, 3, full=True, w=ws)
1489 assert_equal(w, wo)
1490 for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)):
1491 assert_almost_equal(a, a_)
1492
1493 def test_polyfit_with_masked_NaNs(self):
1494 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