-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Completion of g77 ABI wrappers for MacOSX #2695
Conversation
The Travis-CI failure is actually interesting. Note that it happens for one matrix in the non-symmetric solvers in both single and double precision. It only happens for the python 2.6 build, presumably because the random matrix tested is different in all builds. Is building in Travis-CI determinsitic, i.e. would I get the same failure in a second build? I have since a short while a suspicion that there is another bug in ARPACK, and it would be helpful to get the failing matrix ... Anyways, the failure has nothing to do with my changes, as far as I can tell. It would have been there also before. |
I can reproduce the Travis CI failure, on Python 2.6 on Ubuntu. It doesn't occur on master branch, so it's probably caused by one of the changes here. It does not occur on Python 2.7, so something is subtly going wrong. (Future advice: avoid merging the master branch to your own branch while working on a feature, and it's better to have one PR per one feature added.) |
Thanks, pv, for the input. Can you tell me what numpy version you are using? That should enable me to reproduce that error on my ubuntu laptop. Is the error deterministic for you (i.e. reproducible on successive runs)? About the format: should I disentangle the PR? |
Numpy version was 1.7.1 for both. The error is deterministic. The matrix itself is here: https://dl.dropboxusercontent.com/u/5453551/eigs-fail.npz EDIT: ok, the order the tests are run in is different for different Python versions, so the starting vectors should also differ. The eigenvalues returned here are correct, but not those satisfying the About the PR: no reorganization is needed for now, I can sort it out when merging. |
This sounds promising! Is the expansion of |
Works for me on OS X 10.8 (without |
One error on OS X 10.6 (repeated 7 times):
|
@pv: Indeed, it seems we hit a very unlucky seed. In fact, but repeatedly calling eigs() a few hundred times on the matrix you posted, I eventually do get the same (wrong) result even for python 2.7 and vanilla scipy 0.12 as shipped in Ubuntu 12.04. As you noted, the eigenvalues/vectors are correct, it's just that the method didn't converge to the one desired. Fixing the starting vector is one way of course, although it wouldn't prevent such a situation with an unlucky seed, for example when the random test matrix changes, for example due to changes in numpy, etc. |
|
@michaelwimmer: Numpy is committed to keeping the random sequence (for a given seed) the same, so a test with a fixed starting vector |
@pv : An alternative to a fixed starting vector would be to retry the computation if the eigenvalues and -vectors are in principle correct (as is the case here), but the eigenvalues are not the desired ones. The problem I see with a fixed starting vector is that if even with numpy having the same random numbers, if different python versions have a different order of tests (as you said was the case with python 2.6), we could run into the same problem in the future. |
@michaelwimmer: the different order of tests affects only Arpack's internal random generator, which I believe is not used if a starting vector is specified. However, retrying the computation is also an OK solution, and might be better. |
@rgommers: does it work now on 10.6? The wrappers under One possible place to put the unified wrappers could be under |
This now works for 10.6 and 10.8. Haven't been able to check 10.5, but I guess it should work there too. If not we'll find out soon enough. |
Sorry, was away for a few days. Unfortunately I'm also unable to find a machine with 10.5 to test on ... So, is there anything left for me to do in this PR? @pv about the unified wrappers: Right now, the wz/cdotc/u wrappers for ARPACK and iterative are functions (as expected from the fortran routines), whereas the wrappers of the same name in linalg and lib are routines. This also has to be "unified". But that's not a problem by itself. |
Looks ready to go to me. I also looked through the f2py changes and didn't see anything out of place. |
BUG: Completion of g77 ABI wrappers for MacOSX The MacOSX Accelerate framework adheres to g77 ABI conventions. This implies that - every function returning a single precision floating point value (Fortran REAL) in fact returns a double precision value (Fortran DOUBLE PRECISION) - every function returning a complex number is in fact internally a subroutine with the result as the first argument, i.e. COMPLEX FUNCTION X(A, B, C) is in fact SUBROUTINE X(RESULT, A, B, C) Trying to link gfortran generated code with this different ABI results either in crashes (typically for complex) or wrong results (especially for REAL). Scipy already contained wrappers that solved these ABI issues for some BLAS/LAPACK routines (in particular C,ZDOTC, C,ZDOTU), but these ABI wrappers were rather incomplete. As a result, the scipy tests involving single precision failed often on OSX machines (see e.g. issue scipygh-2248). In this pull request: - the ABI wrappers for the basic lapack/blas wrappers in scipy.linalg and scipy.lib are completed - the ABI wrappers for the Fortran routines in scipy.sparse.linalg.isolve are completed - test cases for single precision for the iterative solvers are added (there were no before, so the failure of the iterative solvers on OSX was unnoticed) - the ABI wrappers for ARPACK are completed - single precision in ARPACK has been enabled again With these changes, all relevant tests pass again for my MacOSX 10.8 machine that showed many failures before these patches.
Rebased and merged in 62883c9. Thanks a lot! |
This does not look like g77 ABI: |
From vBLAS.h /*
=================================================================================================
Prototypes for FORTRAN BLAS
===========================
These are prototypes for the FORTRAN callable BLAS functions. They are implemented in C for
Mac OS, as thin shims that simply call the C BLAS counterpart. These routines should never be
called from C, but need to be included here so they will get output for the stub library. It
won't hurt to call them from C, but who would want to since you can't pass literals for sizes?
FORTRAN compilers are typically MPW tools and use PPCLink, so they will link with the official
vecLib stub from Apple.
=================================================================================================
*/
/*
* SDOT()
*
* Availability:
* Mac OS X: in version 10.0 and later in vecLib.framework
* CarbonLib: not in Carbon, but vecLib is compatible with CarbonLib
* Non-Carbon CFM: in vecLib 1.0.2 and later
*/
extern float
SDOT(
const int * /* N */,
const float * /* X */,
const int * /* incX */,
const float * /* Y */,
const int * /* incY */) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER; This is not g77 ABI. It seems this PR duplicates a CBLAS wrapper already present in Accelerate. |
@sturlamolden: Well, Apple was in fact even inconsistent with their own design choices. LAPACK all adheres to the g77 convention. BLAS is a bit of a mixture, with SDOT actually not adhering to this convention. (If you google a bit for it, this was reported elsewhere). However, this is all taken into account in the wrappers now, to my knowledge. |
Testing on OSX 10.9 is seems the C prototype for SDOT in vBLAS.h is incorrect. In reality SDOT returns a double with -m64. |
The MacOSX Accelerate framework adheres to g77 ABI conventions (this is stated for example here, although the solution presented there is incomplete): This implies that
value (Fortran DOUBLE PRECISION)
COMPLEX FUNCTION X(A, B, C)
is in factSUBROUTINE X(RESULT, A, B, C)
Trying to link gfortran generated code with this different ABI results either in crashes (typically for complex) or wrong results (especially for REAL). Scipy already contained wrappers that solved these ABI issues for some BLAS/LAPACK routines (in particular C,ZDOTC, C,ZDOTU), but these ABI wrappers were rather incomplete.
As a result, the scipy tests involving single precision failed often on OSX machines (see e.g. issue #2248).
In this pull request:
With these changes, all relevant tests pass again for my MacOSX 10.8 machine that showed many failures before these patches.