[Scipy-svn] r4927 - in trunk/scipy/sparse/linalg/eigen/arpack/ARPACK: . FWRAPPERS

scipy-svn@scip... scipy-svn@scip...
Sun Nov 2 19:24:34 CST 2008


Author: cdavid
Date: 2008-11-02 19:24:17 -0600 (Sun, 02 Nov 2008)
New Revision: 4927

Added:
   trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/
   trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_c.c
   trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_f.f
Log:
Add wrapper to deal with C/Fortran idiosyncraties

Those wrappers deal with two problems:

1: BLAS functions returning complex values (cdot* and zdot*). With
Accelerate/veclib frameworks, those functions use the so-called g77 ABI, that
return the *address* of the returned value.

http://developer.apple.com/hardwaredrivers/ve/errata.html#fortran_conventions

To deal with it, we replace every call to this function by a call to a wrapped
function (e.g. wcdotu), which itself calls a C wrapper around the cblas_
functions. Effectively, we replace

cdotu call -> BLAS cdotu

By

wcdotu -> F77 wrapper -> C wrapper -> cblas_cdotu

We could call the cblas_ function in the F77 wrapper, but I have not found a
way to do that.

2: cladiv and zladiv: those LAPACK functions also return a complex value. In
this case, the problem is a bit different: Apple, in their infinite wisdom,
decided to keep the LAPACK name cladiv/zladiv for the CLAPACK function. So
instead of calling:

program main
complex X, Y, Z
complex cladiv
X = (1, 0)
Y = (0, 1)
Z = cladiv(X, Y)
print *, Z
end

you need to do

program main
complex X, Y, Z
X = (1, 0)
Y = (0, 1)
call cladiv(Z, X, Y)
end

We again deal with this by replacing the calls to cladiv/zladiv by our wrapper
functions wcladiv/wzladiv. Those F77 wrappers directly call fortran, so there
is no C wrapper.

Added: trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_c.c
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_c.c	2008-11-03 01:23:35 UTC (rev 4926)
+++ trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_c.c	2008-11-03 01:24:17 UTC (rev 4927)
@@ -0,0 +1,25 @@
+#include <vecLib/vecLib.h>
+
+#define WRAP_F77(a) a##_
+void WRAP_F77(veclib_cdotc)(const int *N, const complex float *X, const int *incX,
+const complex float *Y, const int *incY, complex float *dotc)
+{
+    cblas_cdotc_sub(*N, X, *incX, Y, *incY, dotc);
+}
+
+void WRAP_F77(veclib_cdotu)(const int *N, const complex float *X, const int *incX,
+const complex float *Y, const int *incY, complex float* dotu)
+{
+    cblas_cdotu_sub(*N, X, *incX, Y, *incY, dotu);
+}
+
+void WRAP_F77(veclib_zdotc)(const int *N, const double complex *X, const int
+*incX, const double complex *Y, const int *incY, double complex *dotu)
+{
+    cblas_zdotc_sub(*N, X, *incX, Y, *incY, dotu);
+}
+void WRAP_F77(veclib_zdotu)(const int *N, const double complex *X, const int
+*incX, const double complex *Y, const int *incY, double complex *dotu)
+{
+    cblas_zdotu_sub(*N, X, *incX, Y, *incY, dotu);
+}

Added: trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_f.f
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_f.f	2008-11-03 01:23:35 UTC (rev 4926)
+++ trunk/scipy/sparse/linalg/eigen/arpack/ARPACK/FWRAPPERS/veclib_cabi_f.f	2008-11-03 01:24:17 UTC (rev 4927)
@@ -0,0 +1,55 @@
+      double complex function wzdotc(n, zx, incx, zy, incy)
+      double complex zx(*), zy(*), z
+      integer n, incx, incy
+      
+      call veclib_zdotc(n, zx, incx, zy, incy, z)
+      
+      wzdotc = z
+      return
+      end
+      
+      double complex function wzdotu(n, zx, incx, zy, incy)
+      double complex zx(*), zy(*), z
+      integer n, incx, incy
+      
+      call veclib_zdotu(n, zx, incx, zy, incy, z)
+      
+      wzdotu = z
+      return
+      end
+      
+      complex function wcdotc(n, cx, incx, cy, incy)
+      complex cx(*), cy(*), c
+      integer n, incx, incy
+      
+      call veclib_cdotc(n, cx, incx, cy, incy, c)
+      
+      wcdotc = c
+      return
+      end
+      
+      complex function wcdotu(n, cx, incx, cy, incy)
+      complex cx(*), cy(*), c
+      integer n, incx, incy
+      
+      call veclib_cdotu(n, cx, incx, cy, incy, c)
+      
+      wcdotu = c
+      return
+      end
+
+      complex function wcladiv(x, y)
+      complex x, y, z
+      
+      call cladiv(z, x, y)
+      wcladiv = z
+      return
+      end
+
+      double complex function wzladiv(x, y)
+      double complex x, y, z
+      
+      call zladiv(z, x, y)
+      wzladiv = z
+      return
+      end



More information about the Scipy-svn mailing list