(self, a, b, tags)
| 915 | class LstsqCases(LinalgSquareTestCase, LinalgNonsquareTestCase): |
| 916 | |
| 917 | def do(self, a, b, tags): |
| 918 | arr = np.asarray(a) |
| 919 | m, n = arr.shape |
| 920 | u, s, vt = linalg.svd(a, False) |
| 921 | x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1) |
| 922 | if m == 0: |
| 923 | assert_((x == 0).all()) |
| 924 | if m <= n: |
| 925 | assert_almost_equal(b, dot(a, x)) |
| 926 | assert_equal(rank, m) |
| 927 | else: |
| 928 | assert_equal(rank, n) |
| 929 | assert_almost_equal(sv, sv.__array_wrap__(s)) |
| 930 | if rank == n and m > n: |
| 931 | expect_resids = ( |
| 932 | np.asarray(abs(np.dot(a, x) - b)) ** 2).sum(axis=0) |
| 933 | expect_resids = np.asarray(expect_resids) |
| 934 | if np.asarray(b).ndim == 1: |
| 935 | expect_resids.shape = (1,) |
| 936 | assert_equal(residuals.shape, expect_resids.shape) |
| 937 | else: |
| 938 | expect_resids = np.array([]).view(type(x)) |
| 939 | assert_almost_equal(residuals, expect_resids) |
| 940 | assert_(np.issubdtype(residuals.dtype, np.floating)) |
| 941 | assert_(consistent_subclass(x, b)) |
| 942 | assert_(consistent_subclass(residuals, b)) |
| 943 | |
| 944 | |
| 945 | class TestLstsq(LstsqCases): |
nothing calls this directly
no test coverage detected