Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPDictionary: Make it safe to copy dictionaries #37866

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/sage/numerical/interactive_simplex_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -3910,8 +3910,36 @@ def __init__(self, A, b, c, objective_value,
c = copy(c)
B = vector(basic_variables)
N = vector(nonbasic_variables)
# Issue #29101: vector does not guarantee that the result is freshly allocated
# if the input was already a vector
if B is basic_variables:
kwankyu marked this conversation as resolved.
Show resolved Hide resolved
B = copy(B)
if N is nonbasic_variables:
N = copy(N)
self._AbcvBNz = [A, b, c, objective_value, B, N, polygen(ZZ, objective_name)]

def __copy__(self):
r"""
TESTS:

Test that copies do not share state with the original::

sage: A = ([1, 1], [3, 1])
sage: b = (1000, 1500)
sage: c = (10, 5)
sage: P = InteractiveLPProblemStandardForm(A, b, c)
sage: D = P.initial_dictionary()
sage: D_2 = copy(D)
sage: D is D_2
False
sage: D.enter('x1')
sage: D.leave('x3')
sage: D.update()
sage: D_2 == D
False
"""
return type(self)(*self._AbcvBNz)

@staticmethod
def random_element(m, n, bound=5, special_probability=0.2):
r"""
Expand Down
Loading