Example #1
0
    def _test_lu(dtype):
        rand = _Random()
        a = rand.randmat(4, 4, dtype)
        bmat = rand.randmat(4, 4, dtype)
        bvec = rand.randvec(4, dtype)

        lu = lu_factor(a)
        xmat = lu_solve(lu, bmat)
        xvec = lu_solve(lu, bvec)

        assert_array_almost_equal(dtype, np.dot(a, xmat), bmat)
        assert_array_almost_equal(dtype, np.dot(a, xvec), bvec)
Example #2
0
    def _test_lu(dtype):
        rand = _Random()
        a = rand.randmat(4, 4, dtype)
        bmat = rand.randmat(4, 4, dtype)
        bvec = rand.randvec(4, dtype)

        lu = lu_factor(a)
        xmat = lu_solve(lu, bmat)
        xvec = lu_solve(lu, bvec)

        assert_array_almost_equal(dtype, np.dot(a, xmat), bmat)
        assert_array_almost_equal(dtype, np.dot(a, xvec), bvec)
Example #3
0
    def _test_rcond_from_lu(dtype):
        rand = _Random()
        a = rand.randmat(10, 10, dtype)

        norm1_a = np.linalg.norm(a, 1)
        normI_a = np.linalg.norm(a, np.inf)

        lu = lu_factor(a)

        rcond1 = rcond_from_lu(lu, norm1_a, '1')
        rcondI = rcond_from_lu(lu, normI_a, 'I')

        err1 = abs(rcond1 -
                   1/(norm1_a * np.linalg.norm(np.linalg.inv(a), 1)))
        errI = abs(rcondI -
                   1/(normI_a * np.linalg.norm(np.linalg.inv(a), np.inf)))

        #rcond_from_lu returns an estimate for the reciprocal
        #condition number only; hence we shouldn't be too strict about
        #the assertions here
        #Note: in my experience the estimate is excellent for somewhat
        #larger matrices
        assert_true(err1/rcond1 < 0.1)
        assert_true(errI/rcondI < 0.1)
Example #4
0
    def _test_rcond_from_lu(dtype):
        rand = _Random()
        a = rand.randmat(10, 10, dtype)

        norm1_a = np.linalg.norm(a, 1)
        normI_a = np.linalg.norm(a, np.inf)

        lu = lu_factor(a)

        rcond1 = rcond_from_lu(lu, norm1_a, '1')
        rcondI = rcond_from_lu(lu, normI_a, 'I')

        err1 = abs(rcond1 - 1 /
                   (norm1_a * np.linalg.norm(np.linalg.inv(a), 1)))
        errI = abs(rcondI - 1 /
                   (normI_a * np.linalg.norm(np.linalg.inv(a), np.inf)))

        #rcond_from_lu returns an estimate for the reciprocal
        #condition number only; hence we shouldn't be too strict about
        #the assertions here
        #Note: in my experience the estimate is excellent for somewhat
        #larger matrices
        assert err1 / rcond1 < 0.1
        assert errI / rcondI < 0.1