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

Method do

numpy/linalg/tests/test_linalg.py:1013–1038  ·  view source on GitHub ↗
(self, a, b, tags)

Source from the content-addressed store, hash-verified

1011class LstsqCases(LinalgSquareTestCase, LinalgNonsquareTestCase):
1012
1013 def do(self, a, b, tags):
1014 arr = np.asarray(a)
1015 m, n = arr.shape
1016 u, s, vt = linalg.svd(a, False)
1017 x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1)
1018 if m == 0:
1019 assert_((x == 0).all())
1020 if m <= n:
1021 assert_almost_equal(b, dot(a, x))
1022 assert_equal(rank, m)
1023 else:
1024 assert_equal(rank, n)
1025 assert_almost_equal(sv, sv.__array_wrap__(s))
1026 if rank == n and m > n:
1027 expect_resids = (
1028 np.asarray(abs(np.dot(a, x) - b)) ** 2).sum(axis=0)
1029 expect_resids = np.asarray(expect_resids)
1030 if np.asarray(b).ndim == 1:
1031 expect_resids = expect_resids.reshape((1,))
1032 assert_equal(residuals.shape, expect_resids.shape)
1033 else:
1034 expect_resids = np.array([]).view(type(x))
1035 assert_almost_equal(residuals, expect_resids)
1036 assert_(np.issubdtype(residuals.dtype, np.floating))
1037 assert_(consistent_subclass(x, b))
1038 assert_(consistent_subclass(residuals, b))
1039
1040
1041class TestLstsq(LstsqCases):

Callers

nothing calls this directly

Calls 11

assert_Function · 0.90
assert_almost_equalFunction · 0.90
dotFunction · 0.90
assert_equalFunction · 0.90
consistent_subclassFunction · 0.85
dotMethod · 0.80
reshapeMethod · 0.80
allMethod · 0.45
__array_wrap__Method · 0.45
sumMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected