Skip to content

Commit

Permalink
Merge pull request #11631 from pmla/lsap-constant-cost
Browse files Browse the repository at this point in the history
Revert to old behaviour for constant cost matrices in `linear_sum_assignment`
  • Loading branch information
tylerjereddy committed Mar 7, 2020
2 parents c5b9f5e + c050fd9 commit e3bf555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scipy/optimize/rectangular_lsap/rectangular_lsap.cpp
Expand Up @@ -59,7 +59,9 @@ augmenting_path(int nc, std::vector<double>& cost, std::vector<double>& u,
int num_remaining = nc;
std::vector<int> remaining(nc);
for (int it = 0; it < nc; it++) {
remaining[it] = it;
// Filling this up in reverse order ensures that the solution of a
// constant cost matrix is the identity matrix (c.f. #11602).
remaining[it] = nc - it - 1;
}

std::fill(SR.begin(), SR.end(), false);
Expand Down
9 changes: 9 additions & 0 deletions scipy/optimize/tests/test_linear_assignment.py
Expand Up @@ -91,3 +91,12 @@ def test_linear_sum_assignment_input_validation():
I = np.identity(3)
I[:, 0] = np.inf
assert_raises(ValueError, linear_sum_assignment, I)


def test_constant_cost_matrix():
# Fixes #11602
n = 8
C = np.ones((n, n))
row_ind, col_ind = linear_sum_assignment(C)
assert_array_equal(row_ind, np.arange(n))
assert_array_equal(col_ind, np.arange(n))

0 comments on commit e3bf555

Please sign in to comment.