def test_all_inf(): cost = np.empty((5, 5), dtype=float) cost[:] = np.inf with raises(ValueError): lapmod(*sparse_from_dense(cost)) with raises(ValueError): lapmod(*sparse_from_masked(cost))
def test_inf_row(): cost = np.array( [[0., 0., 0., 0., np.inf], [np.inf, np.inf, 0., 0., 0.], [np.inf, np.inf, np.inf, np.inf, np.inf], [np.inf, np.inf, np.inf, 0., 0.], [0., 0., 0., np.inf, np.inf]], dtype=float) with raises(ValueError): ret = lapmod(*sparse_from_dense(cost)) ret = lapmod(*sparse_from_masked(cost)) assert len(ret) == 3 assert ret[0] == np.inf
def test_inf_unique(): cost = np.array([[1000, 4, 1], [1, 1000, 3], [5, 1, 1000]]) cost_ext = np.empty((4, 4)) cost_ext[:] = np.inf cost_ext[:3, :3] = cost cost_ext[3, 3] = 0 with raises(ValueError): ret = lapmod(*sparse_from_dense(cost_ext)) ret = lapmod(*sparse_from_masked(cost_ext)) assert len(ret) == 3 assert ret[0] == 3. assert np.all(ret[1] == [2, 0, 1, 3])
def test_dense_1kx1k_int_hard(dense_1kx1k_int_hard): cost, opt = dense_1kx1k_int_hard ret = lapmod(*sparse_from_dense(cost)) assert len(ret) == 3 assert ret[0] == opt lapjv_ret = lapjv(cost) assert ret[0] == lapjv_ret[0]
def test_dense_100x100_int(dense_100x100_int): cost, opt = dense_100x100_int ret = lapmod(*sparse_from_dense(cost)) assert len(ret) == 3 assert ret[0] == opt lapjv_ret = lapjv(cost) assert ret[0] == lapjv_ret[0]
def test_sparse_4kx4k_int(sparse_4kx4k_int): cost, mask, opt = sparse_4kx4k_int ret = lapmod(*sparse_from_masked(cost, mask)) assert len(ret) == 3 assert ret[0] == opt cost[~mask] = get_platform_maxint() lapjv_ret = lapjv(cost) assert ret[0] == lapjv_ret[0]
def test_sparse_square(cost, expected): ret = lapmod(*sparse_from_masked(cost)) assert len(ret) == len(expected) assert cost[range(cost.shape[0]), ret[1]].sum() == ret[0] assert cost[ret[2], range(cost.shape[1])].sum() == ret[0] assert ret[0] == expected[0] assert np.all(ret[1] == expected[1]) assert np.all(ret[2] == expected[2]) dense_ret = lapjv(cost) assert ret[0] == dense_ret[0] assert np.all(ret[1] == dense_ret[1]) assert np.all(ret[2] == dense_ret[2])
def test_infs_unsolvable(): cost = np.array( [[0., 0., 0., np.inf, np.inf], [np.inf, np.inf, np.inf, 0., 0.], [np.inf, np.inf, np.inf, 0., 0.], [np.inf, np.inf, np.inf, 0., 0.], [0., 0., 0., np.inf, np.inf]], dtype=float) lapjv_ret = lapjv(cost) assert lapjv_ret[0] == np.inf ret = lapmod(*sparse_from_masked(cost)) assert len(ret) == 3 assert ret[0] == np.inf cost = np.array( [[19., 22., 16., np.inf, np.inf], [np.inf, np.inf, np.inf, 4., 13.], [np.inf, np.inf, np.inf, 3., 14.], [np.inf, np.inf, np.inf, 10., 12.], [11., 14., 13., np.inf, np.inf]], dtype=float) lapjv_ret = lapjv(cost) assert lapjv_ret[0] == np.inf ret = lapmod(*sparse_from_masked(cost)) assert len(ret) == 3 assert ret[0] == np.inf
def test_sparse_100x100_int(sparse_100x100_int): cost, mask, opt = sparse_100x100_int ret = lapmod(*sparse_from_masked(cost, mask)) assert len(ret) == 3 assert ret[0] == opt
def test_eps(dense_eps): cost, opt = dense_eps ret = lapmod(*sparse_from_dense(cost)) assert len(ret) == 3 assert ret[0] == opt