示例#1
0
def test_many_iter_ecp():
    # warm starting with the previously found solution should take 0 iterations
    data, cone = ex.many_iter_ecp()
    sol = scs.solve(data, cone)
    assert sol['info']['iter'] >= 500

    sol = scs.solve(data, cone, warm_start = sol)
    assert sol['info']['iter'] == 0
示例#2
0
def test_many_iter_ecp():
    # warm starting with the previously found solution should take 0 iterations
    data, cone = ex.many_iter_ecp()
    sol = scs.solve(data, cone)
    assert sol['info']['iter'] >= 500

    sol = scs.solve(data, cone, warm_start=sol)
    assert sol['info']['iter'] == 0
示例#3
0
def test_many_iter_ecp_tol():
    # warm starting with a solution at a lower tolerance should reduce
    # the number of iterations needed
    data, cone = ex.many_iter_ecp()

    # intially takes ~920 iters for eps 1e-4
    sol = scs.solve(data, cone, eps=1e-4)
    assert sol['info']['iter'] >= 800

    # ~640 for eps 1e-3
    sol = scs.solve(data, cone, eps=1e-3)
    assert 500 <= sol['info']['iter'] <= 700

    # use 1e-3 sol as warm start for 1e-4
    # extra digit only takes ~280 iters more
    sol = scs.solve(data, cone, warm_start = sol, eps=1e-4)
    assert sol['info']['iter'] < 300
示例#4
0
def test_b_len():
    data, cone = ex.simple_lp()
    b = data['b']
    b = np.append(b, b)
    data['b'] = b

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#5
0
def test_numdim_b():
    data, cone = ex.simple_lp()
    b = data['b']
    b = np.array(b, ndmin=2).T
    data['b'] = b

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#6
0
def test_warm():
    data, cone, true_x = ex.simple_pcp()

    # computing a fresh solution takes some number of iters
    sol = scs.solve(data, cone)
    assert sol['info']['iter'] >= 10

    # should take 0 iterations
    sol = scs.solve(data, cone, warm_start = sol)
    assert sol['info']['iter'] == 0

    # change solution a bit
    sol['x'] *= 2

    # perturbing the solution should take a few iterations to correct
    sol = scs.solve(data, cone, warm_start = sol)
    assert sol['info']['iter'] >= 3
示例#7
0
def test_warm():
    data, cone, true_x = ex.simple_pcp()

    # computing a fresh solution takes some number of iters
    sol = scs.solve(data, cone)
    assert sol['info']['iter'] >= 10

    # should take 0 iterations
    sol = scs.solve(data, cone, warm_start=sol)
    assert sol['info']['iter'] == 0

    # change solution a bit
    sol['x'] *= 2

    # perturbing the solution should take a few iterations to correct
    sol = scs.solve(data, cone, warm_start=sol)
    assert sol['info']['iter'] >= 3
示例#8
0
def test_cone_size():
    # test that the solve method recognizes that the length of the cone
    # does not match the number of rows of A
    data, cone = ex.simple_lp()
    cone['l'] = 5

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#9
0
def test_b_len():
    data, cone = ex.simple_lp()
    b = data['b']
    b = np.append(b,b)
    data['b'] = b

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#10
0
def test_numdim_b():
    data, cone = ex.simple_lp()
    b = data['b']
    b = np.array(b, ndmin=2).T
    data['b'] = b

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#11
0
def test_many_iter_ecp_tol():
    # warm starting with a solution at a lower tolerance should reduce
    # the number of iterations needed
    data, cone = ex.many_iter_ecp()

    # intially takes ~920 iters for eps 1e-4
    sol = scs.solve(data, cone, eps=1e-4)
    assert sol['info']['iter'] >= 800

    # ~640 for eps 1e-3
    sol = scs.solve(data, cone, eps=1e-3)
    assert 500 <= sol['info']['iter'] <= 700

    # use 1e-3 sol as warm start for 1e-4
    # extra digit only takes ~280 iters more
    sol = scs.solve(data, cone, warm_start=sol, eps=1e-4)
    assert sol['info']['iter'] < 300
示例#12
0
def test_solve():
    data, cone = ex.simple_lp()
    m,n = data['A'].shape
    
    ws = dict(x=np.zeros(n), y=np.zeros(m), s=np.zeros(m))

    sol = scs.solve(data, cone, warm_start = ws)

    # make sure sol and ws contain *different* numpy arrays
    assert any(ws['x'] != sol['x'])
    assert any(ws['y'] != sol['y'])
    assert any(ws['s'] != sol['s'])
示例#13
0
def test_solve():
    data, cone = ex.simple_lp()
    m, n = data['A'].shape

    ws = dict(x=np.zeros(n), y=np.zeros(m), s=np.zeros(m))

    sol = scs.solve(data, cone, warm_start=ws)

    # make sure sol and ws contain *different* numpy arrays
    assert any(ws['x'] != sol['x'])
    assert any(ws['y'] != sol['y'])
    assert any(ws['s'] != sol['s'])
示例#14
0
def test_simple_direct():
    data, cone = ex.simple_lp()
    sol = scs.solve(data, cone, use_indirect=False)
示例#15
0
def test_extra_arg():
    data, cone = ex.simple_lp()
    sol = scs.solve(data, cone, eps=1e-9, alpha=.1, nonsense_arg='nonsense')
示例#16
0
def test_b():
    data, cone = ex.simple_lp()
    data['b'] = data['b'].astype(np.float32)

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#17
0
def test_A_indptr():
    data, cone = ex.simple_lp()
    data['A'].indptr = data['A'].indptr.astype(np.int32)

    with pytest.warns(UserWarning):
        sol = scs.solve(data, cone)
示例#18
0
def test_simple_lp():
    data, cone = ex.simple_lp()
    sol = scs.solve(data, cone)
示例#19
0
def test_simple_pcp():
    data, cone, true_x = ex.simple_pcp()
    sol = scs.solve(data, cone, eps=1e-6)

    assert np.allclose(sol['x'], true_x)
示例#20
0
def test_b():
    data, cone = ex.simple_lp()
    data['b'] = data['b'].astype(np.float32)

    with pytest.raises(ValueError):
        sol = scs.solve(data, cone)
示例#21
0
def test_str_output():
    data, cone = ex.simple_lp()
    sol = scs.solve(data, cone)

    assert sol['info']['status'] == 'Solved'
示例#22
0
def test_A_data():
    data, cone = ex.simple_lp()
    data['A'].data = data['A'].data.astype(np.float32)

    with pytest.warns(UserWarning):
        sol = scs.solve(data, cone)
示例#23
0
def test_A_indptr():
    data, cone = ex.simple_lp()
    data['A'].indptr = data['A'].indptr.astype(np.int32)

    with pytest.warns(UserWarning):
        sol = scs.solve(data, cone)
示例#24
0
def test_A_data():
    data, cone = ex.simple_lp()
    data['A'].data = data['A'].data.astype(np.float32)

    with pytest.warns(UserWarning):
        sol = scs.solve(data, cone)