(self, a, b, tags)
| 1011 | class 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 | |
| 1041 | class TestLstsq(LstsqCases): |
nothing calls this directly
no test coverage detected