

def test_random_exact(self):
    for dtype in REAL_DTYPES:
        for n in (20, 200):
            for lapack_driver in TestLstsq.lapack_drivers:
                for overwrite in (True, False):
                    a = np.asarray(random([n, n]), dtype=dtype)
                    for i in range(n):
                        a[(i, i)] = (20 * (0.1 + a[(i, i)]))
                    for i in range(4):
                        b = np.asarray(random([n, 3]), dtype=dtype)
                        a1 = a.copy()
                        b1 = b.copy()
                        try:
                            out = lstsq(a1, b1, lapack_driver=lapack_driver, overwrite_a=overwrite, overwrite_b=overwrite)
                        except LstsqLapackError:
                            if (lapack_driver is None):
                                mesg = 'LstsqLapackError raised with lapack_driver being None.'
                                raise AssertionError(mesg)
                            else:
                                continue
                        x = out[0]
                        r = out[2]
                        assert_((r == n), ('expected efficient rank %s, got %s' % (n, r)))
                        if (dtype is np.float32):
                            assert_allclose(dot(a, x), b, rtol=(500 * np.finfo(a1.dtype).eps), atol=(500 * np.finfo(a1.dtype).eps), err_msg=('driver: %s' % lapack_driver))
                        else:
                            assert_allclose(dot(a, x), b, rtol=(1000 * np.finfo(a1.dtype).eps), atol=(1000 * np.finfo(a1.dtype).eps), err_msg=('driver: %s' % lapack_driver))

dataset/ETHPy150Open scipy/scipy/scipy/linalg/tests/test_basic.py TestLstsq.test_random_exact/original