def test__clean_inputs1(): c = [1, 2] A_ub = [[1, 1], [2, 2]] b_ub = [1, 1] A_eq = [[1, 1], [2, 2]] b_eq = [1, 1] bounds = None outputs = _clean_inputs( c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array(c)) assert_allclose(outputs[1], np.array(A_ub)) assert_allclose(outputs[2], np.array(b_ub)) assert_allclose(outputs[3], np.array(A_eq)) assert_allclose(outputs[4], np.array(b_eq)) assert_(outputs[5] == [(0, None)] * 2, "") assert_(outputs[0].shape == (2,), "") assert_(outputs[1].shape == (2, 2), "") assert_(outputs[2].shape == (2,), "") assert_(outputs[3].shape == (2, 2), "") assert_(outputs[4].shape == (2,), "")
def test__clean_inputs2(): c = 1 A_ub = [[1]] b_ub = 1 A_eq = [[1]] b_eq = 1 bounds = (0, 1) outputs = _clean_inputs( c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array(c)) assert_allclose(outputs[1], np.array(A_ub)) assert_allclose(outputs[2], np.array(b_ub)) assert_allclose(outputs[3], np.array(A_eq)) assert_allclose(outputs[4], np.array(b_eq)) assert_(outputs[5] == [(0, 1)], "") assert_(outputs[0].shape == (1,), "") assert_(outputs[1].shape == (1, 1), "") assert_(outputs[2].shape == (1,), "") assert_(outputs[3].shape == (1, 1), "") assert_(outputs[4].shape == (1,), "")
def test__clean_inputs2(): c = 1 A_ub = [[1]] b_ub = 1 A_eq = [[1]] b_eq = 1 bounds = (0, 1) outputs = _clean_inputs(c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array(c)) assert_allclose(outputs[1], np.array(A_ub)) assert_allclose(outputs[2], np.array(b_ub)) assert_allclose(outputs[3], np.array(A_eq)) assert_allclose(outputs[4], np.array(b_eq)) assert_(outputs[5] == [(0, 1)], "") assert_(outputs[0].shape == (1, ), "") assert_(outputs[1].shape == (1, 1), "") assert_(outputs[2].shape == (1, ), "") assert_(outputs[3].shape == (1, 1), "") assert_(outputs[4].shape == (1, ), "")
def test__clean_inputs1(): c = [1, 2] A_ub = [[1, 1], [2, 2]] b_ub = [1, 1] A_eq = [[1, 1], [2, 2]] b_eq = [1, 1] bounds = None outputs = _clean_inputs(c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array(c)) assert_allclose(outputs[1], np.array(A_ub)) assert_allclose(outputs[2], np.array(b_ub)) assert_allclose(outputs[3], np.array(A_eq)) assert_allclose(outputs[4], np.array(b_eq)) assert_(outputs[5] == [(0, None)] * 2, "") assert_(outputs[0].shape == (2, ), "") assert_(outputs[1].shape == (2, 2), "") assert_(outputs[2].shape == (2, ), "") assert_(outputs[3].shape == (2, 2), "") assert_(outputs[4].shape == (2, ), "")
def test_aliasing2(): c = np.array([1, 1]) A_ub = np.array([[1, 1], [2, 2]]) b_ub = np.array([[1], [1]]) A_eq = np.array([[1, 1]]) b_eq = np.array([1]) bounds = [(-np.inf, np.inf), (None, 1)] c_copy = c.copy() A_ub_copy = A_ub.copy() b_ub_copy = b_ub.copy() A_eq_copy = A_eq.copy() b_eq_copy = b_eq.copy() bounds_copy = deepcopy(bounds) _clean_inputs(c, A_ub, b_ub, A_eq, b_eq, bounds) assert_allclose(c, c_copy, err_msg="c modified by _clean_inputs") assert_allclose(A_ub, A_ub_copy, err_msg="A_ub modified by _clean_inputs") assert_allclose(b_ub, b_ub_copy, err_msg="b_ub modified by _clean_inputs") assert_allclose(A_eq, A_eq_copy, err_msg="A_eq modified by _clean_inputs") assert_allclose(b_eq, b_eq_copy, err_msg="b_eq modified by _clean_inputs") assert_(bounds == bounds_copy, "bounds modified by _clean_inputs")
def test_aliasing(): c = 1 A_ub = [[1]] b_ub = [1] A_eq = [[1]] b_eq = [1] bounds = (-np.inf, np.inf) c_copy = deepcopy(c) A_ub_copy = deepcopy(A_ub) b_ub_copy = deepcopy(b_ub) A_eq_copy = deepcopy(A_eq) b_eq_copy = deepcopy(b_eq) bounds_copy = deepcopy(bounds) _clean_inputs(c, A_ub, b_ub, A_eq, b_eq, bounds) assert_(c == c_copy, "c modified by _clean_inputs") assert_(A_ub == A_ub_copy, "A_ub modified by _clean_inputs") assert_(b_ub == b_ub_copy, "b_ub modified by _clean_inputs") assert_(A_eq == A_eq_copy, "A_eq modified by _clean_inputs") assert_(b_eq == b_eq_copy, "b_eq modified by _clean_inputs") assert_(bounds == bounds_copy, "bounds modified by _clean_inputs")
def test__clean_inputs3(): c = [[1, 2]] A_ub = np.random.rand(2, 2) b_ub = [[1], [2]] A_eq = np.random.rand(2, 2) b_eq = [[1], [2]] bounds = [(0, 1)] outputs = _clean_inputs(c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array([1, 2])) assert_allclose(outputs[2], np.array([1, 2])) assert_allclose(outputs[4], np.array([1, 2])) assert_(outputs[5] == [(0, 1)] * 2, "") assert_(outputs[0].shape == (2, ), "") assert_(outputs[2].shape == (2, ), "") assert_(outputs[4].shape == (2, ), "")
def test__clean_inputs3(): c = [[1, 2]] A_ub = np.random.rand(2, 2) b_ub = [[1], [2]] A_eq = np.random.rand(2, 2) b_eq = [[1], [2]] bounds = [(0, 1)] outputs = _clean_inputs( c=c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds) assert_allclose(outputs[0], np.array([1, 2])) assert_allclose(outputs[2], np.array([1, 2])) assert_allclose(outputs[4], np.array([1, 2])) assert_(outputs[5] == [(0, 1)] * 2, "") assert_(outputs[0].shape == (2,), "") assert_(outputs[2].shape == (2,), "") assert_(outputs[4].shape == (2,), "")
def test_good_bounds(): c = [1, 2] outputs = _clean_inputs(c=c, bounds=None) assert_(outputs[5] == [(0, None)] * 2, "") outputs = _clean_inputs(c=c, bounds=(1, 2)) assert_(outputs[5] == [(1, 2)] * 2, "") outputs = _clean_inputs(c=c, bounds=[(1, 2)]) assert_(outputs[5] == [(1, 2)] * 2, "") outputs = _clean_inputs(c=c, bounds=[(1, np.inf)]) assert_(outputs[5] == [(1, None)] * 2, "") outputs = _clean_inputs(c=c, bounds=[(-np.inf, 1)]) assert_(outputs[5] == [(None, 1)] * 2, "") outputs = _clean_inputs(c=c, bounds=[(-np.inf, np.inf), (-np.inf, np.inf)]) assert_(outputs[5] == [(None, None)] * 2, "")