Thanks for quick responses guys.

Patrick, please find attached the patch that implements your suggestion
which does fix the test failures. I've
reused GSL_EIGEN_SORT_VAL_{ASC,DESC}, that were previously unused for
complex numbers, for the new type of comparison.

Victor


On Mon, Aug 18, 2014 at 12:21 PM, Patrick Alken <patrick.al...@colorado.edu>
wrote:

> GSL is already sorting the eigenvalues based on magnitude, so the problem
> seems to be that with the extra -O3 optimization, the gsl_eigen_gen and
> gsl_eigen_genv routines are producing slightly different results, leading
> to a different sorting order. One way to fix this would be to sort by real
> part first and then by imaginary part, but it may be a little while until I
> can look into this further.
>
> Patrick
>
>
> On 08/18/2014 12:59 PM, Martin Jansche wrote:
>
>> I'm not sure if GSL makes any guarantees about the direction of
>> eigenvectors. It looks like the test might pass if one only looks at the
>> magnitude of the values. Perhaps the test could be made robust against
>> sign
>> changes by looking at absolute values.
>>
>>
>>
>> On Mon, Aug 18, 2014 at 1:53 PM, victor.zverov...@gmail.com <
>> victor.zverov...@gmail.com> wrote:
>>
>>  Hello,
>>>
>>> I noticed that eigen test fails on 32-bit Linux (x86) when compiled with
>>> -O3 flag:
>>>
>>> $ ./configure CFLAGS="-O3"
>>> $ make
>>> $ eigen/test
>>> FAIL: gen, direct eigenvalue(4) imag, random (-0.481216772353650846
>>> observed vs 0.481216772353650846 expected) [877968]
>>> FAIL: gen, direct eigenvalue(5) imag, random (0.481216772353650901
>>> observed
>>> vs -0.481216772353650846 expected) [877970]
>>> FAIL: gen, direct eigenvalue(15) imag, random (6.85872455924790447
>>> observed
>>> vs -6.85872455924790536 expected) [877990]
>>> FAIL: gen, direct eigenvalue(16) imag, random (-6.85872455924790536
>>> observed vs 6.85872455924790625 expected) [877992]
>>>
>>> I'm using GSL version 1.16, 32-bit Ubuntu 10.04 and GCC 4.4.3.
>>>
>>> Best regards,
>>> Victor
>>>
>>>
>
>
From 79347f3fb612e203e68e19a708ae91f1d679c2d9 Mon Sep 17 00:00:00 2001
From: Victor Zverovich <victor.zverov...@gmail.com>
Date: Mon, 18 Aug 2014 14:23:16 -0700
Subject: [PATCH] Sort eigenvalues by real part first and then by imaginary
 part to make eigen_test more robust.

---
 eigen/sort.c | 13 +++++++++++++
 eigen/test.c |  4 ++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/eigen/sort.c b/eigen/sort.c
index 54d1316..0eb5b40 100644
--- a/eigen/sort.c
+++ b/eigen/sort.c
@@ -26,6 +26,15 @@
 #include <gsl/gsl_complex.h>
 #include <gsl/gsl_complex_math.h>
 
+/* Compares real parts of a and b and, if they are not approximately equal,
+ * returns Re(a) < Re(b); otherwise returns Im(a) < Im(b). */
+static INLINE_DECL int
+complex_less(gsl_complex a, gsl_complex b)
+{
+  return gsl_fcmp(GSL_REAL(a), GSL_REAL(b), GSL_DBL_EPSILON) == 0 ?
+    GSL_IMAG(a) < GSL_IMAG(b) : GSL_REAL(a) < GSL_REAL(b);
+}
+
 /* The eigen_sort below is not very good, but it is simple and
  * self-contained. We can always implement an improved sort later.  */
 
@@ -208,7 +217,11 @@ gsl_eigen_nonsymmv_sort (gsl_vector_complex * eval,
                   test = (gsl_complex_abs (ej) > gsl_complex_abs (ek));
                   break;
                 case GSL_EIGEN_SORT_VAL_ASC:
+                  test = complex_less(ej, ek);
+                  break;
                 case GSL_EIGEN_SORT_VAL_DESC:
+                  test = complex_less(ek, ej);
+                  break;
                 default:
                   GSL_ERROR ("invalid sort type", GSL_EINVAL);
                 }
diff --git a/eigen/test.c b/eigen/test.c
index 20b9f8a..0cc291a 100644
--- a/eigen/test.c
+++ b/eigen/test.c
@@ -1267,8 +1267,8 @@ test_eigen_gen_pencil(const gsl_matrix * A, const gsl_matrix * B,
     }
 
   /* sort eval and evalv and test them */
-  gsl_eigen_nonsymmv_sort(w->eval, NULL, GSL_EIGEN_SORT_ABS_ASC);
-  gsl_eigen_nonsymmv_sort(w->evalv, NULL, GSL_EIGEN_SORT_ABS_ASC);
+  gsl_eigen_nonsymmv_sort(w->eval, NULL, GSL_EIGEN_SORT_VAL_ASC);
+  gsl_eigen_nonsymmv_sort(w->evalv, NULL, GSL_EIGEN_SORT_VAL_ASC);
   test_eigenvalues_complex(w->evalv, w->eval, "gen", desc);
 
   gsl_eigen_genv_sort(w->alphav, w->betav, w->evec, GSL_EIGEN_SORT_ABS_ASC);
-- 
1.9.1

Reply via email to