From 143192d1c13eba5242ec5cbba5641f9e86b1397c Mon Sep 17 00:00:00 2001 From: Kelly Marchisio Date: Tue, 14 Dec 2021 15:34:53 -0500 Subject: [PATCH] Fixes #1 - fix outlier handling in qap/qapot --- pkg/pkg/gmp/qap.py | 2 ++ pkg/pkg/gmp/qapot.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pkg/pkg/gmp/qap.py b/pkg/pkg/gmp/qap.py index 7132f31..52365e8 100644 --- a/pkg/pkg/gmp/qap.py +++ b/pkg/pkg/gmp/qap.py @@ -385,6 +385,8 @@ def _quadratic_assignment_faq( # check outlier cases if n == 0 or partial_match.shape[0] == n: + # Cannot assume partial_match is sorted. + partial_match = np.row_stack(sorted(partial_match, key=lambda x: x[0])) score = _calc_score(A, B, partial_match[:, 1]) res = {"col_ind": partial_match[:, 1], "fun": score, "nit": 0} return OptimizeResult(res) diff --git a/pkg/pkg/gmp/qapot.py b/pkg/pkg/gmp/qapot.py index e471c70..8e3e3e0 100644 --- a/pkg/pkg/gmp/qapot.py +++ b/pkg/pkg/gmp/qapot.py @@ -395,6 +395,8 @@ def _quadratic_assignment_faq_ot( # check outlier cases if n == 0 or partial_match.shape[0] == n: + # Cannot assume partial_match is sorted. + partial_match = np.row_stack(sorted(partial_match, key=lambda x: x[0])) score = _calc_score(A, B, partial_match[:, 1]) res = {"col_ind": partial_match[:, 1], "fun": score, "nit": 0} return OptimizeResult(res)