# HG changeset patch
# User Michael C. Grant <mcg@cvxr.com>
# Date 1395018868 18000
#      Sun Mar 16 20:14:28 2014 -0500
# Branch stable-2
# Node ID a9eb29970f09ceacc15d31fc467137cd0f6139db
# Parent  564a74b2d509e984e73c54bc5b1bbb91c7ddb013
Uses CBLAS calls for complex BLAS functions.
ax_blas.m4: added USE_CBLAS_COMPLEX define.
CMatrix.cc,fCMatrix.cc: added CBLAS alternatives for zdotu/zdotc/cdotu/cdotc.

diff -r 564a74b2d509 -r a9eb29970f09 liboctave/array/CMatrix.cc
--- a/liboctave/array/CMatrix.cc	Thu Mar 06 17:32:49 2014 +0100
+++ b/liboctave/array/CMatrix.cc	Sun Mar 16 20:14:28 2014 -0500
@@ -59,7 +59,15 @@
 #include "oct-locbuf.h"
 #include "oct-norm.h"
 
-// Fortran functions we call.
+// Fortran and CBLAS functions we call.
+
+#if defined USE_CBLAS_COMPLEX
+#define XZDOTU_IMPL cblas_zdotu_sub
+#define XZDOTC_IMPL cblas_zdotc_sub
+#else
+#define XZDOTU_IMPL F77_FUNC(xzdotu,XZDOTU)
+#define XZDOTC_IMPL F77_FUNC(xzdotc,XZDOTC)
+#endif
 
 extern "C"
 {
@@ -255,6 +263,14 @@
                                const Complex*, const octave_idx_type&,
                                double*, double&
                                F77_CHAR_ARG_LEN_DECL);
+
+  void cblas_zdotu_sub      (octave_idx_type, const Complex*,
+                             octave_idx_type, const Complex*,
+                             octave_idx_type, Complex&);
+
+  void cblas_zdotc_sub      (octave_idx_type, const Complex*,
+                             octave_idx_type, const Complex*,
+                             octave_idx_type, Complex&);
 }
 
 static const Complex Complex_NaN_result (octave_NaN, octave_NaN);
@@ -3838,16 +3854,13 @@
             {
               if (cja == cjb)
                 {
-                  F77_FUNC (xzdotu, XZDOTU) (a_nc, a.data (), 1, b.data (), 1,
-                                             *c);
+                  XZDOTU_IMPL (a_nc, a.data (), 1, b.data (), 1, *c);
                   if (cja) *c = std::conj (*c);
                 }
               else if (cja)
-                F77_FUNC (xzdotc, XZDOTC) (a_nc, a.data (), 1, b.data (), 1,
-                                           *c);
+                XZDOTC_IMPL (a_nc, a.data (), 1, b.data (), 1, *c);
               else
-                F77_FUNC (xzdotc, XZDOTC) (a_nc, b.data (), 1, a.data (), 1,
-                                           *c);
+                XZDOTC_IMPL (a_nc, b.data (), 1, a.data (), 1, *c);
             }
           else if (b_nc == 1 && ! cjb)
             {
diff -r 564a74b2d509 -r a9eb29970f09 liboctave/array/fCMatrix.cc
--- a/liboctave/array/fCMatrix.cc	Thu Mar 06 17:32:49 2014 +0100
+++ b/liboctave/array/fCMatrix.cc	Sun Mar 16 20:14:28 2014 -0500
@@ -58,7 +58,15 @@
 #include "oct-locbuf.h"
 #include "oct-norm.h"
 
-// Fortran functions we call.
+// Fortran and CBLAS functions we call.
+
+#if defined USE_CBLAS_COMPLEX
+#define XCDOTU_IMPL cblas_cdotu_sub
+#define XCDOTC_IMPL cblas_cdotc_sub
+#else
+#define XCDOTU_IMPL F77_FUNC(xcdotu,XCDOTU)
+#define XCDOTC_IMPL F77_FUNC(xcdotc,XCDOTC)
+#endif
 
 extern "C"
 {
@@ -256,6 +264,14 @@
                                const FloatComplex*, const octave_idx_type&,
                                float*, float&
                                F77_CHAR_ARG_LEN_DECL);
+
+  void cblas_cdotu_sub      (octave_idx_type, const FloatComplex*,
+                             octave_idx_type, const FloatComplex*,
+                             octave_idx_type, FloatComplex&);
+
+  void cblas_cdotc_sub      (octave_idx_type, const FloatComplex*,
+                             octave_idx_type, const FloatComplex*,
+                             octave_idx_type, FloatComplex&);
 }
 
 static const FloatComplex FloatComplex_NaN_result (octave_Float_NaN,
@@ -3862,16 +3878,13 @@
             {
               if (cja == cjb)
                 {
-                  F77_FUNC (xcdotu, XCDOTU) (a_nc, a.data (), 1, b.data (), 1,
-                                             *c);
+                  XCDOTU_IMPL (a_nc, a.data (), 1, b.data (), 1, *c);
                   if (cja) *c = std::conj (*c);
                 }
               else if (cja)
-                F77_FUNC (xcdotc, XCDOTC) (a_nc, a.data (), 1, b.data (), 1,
-                                           *c);
+                XCDOTC_IMPL (a_nc, a.data (), 1, b.data (), 1, *c);
               else
-                F77_FUNC (xcdotc, XCDOTC) (a_nc, b.data (), 1, a.data (), 1,
-                                           *c);
+                XCDOTC_IMPL (a_nc, b.data (), 1, a.data (), 1, *c);
             }
           else if (b_nc == 1 && ! cjb)
             {
diff -r 564a74b2d509 -r a9eb29970f09 m4/ax_blas.m4
--- a/m4/ax_blas.m4	Thu Mar 06 17:32:49 2014 +0100
+++ b/m4/ax_blas.m4	Sun Mar 16 20:14:28 2014 -0500
@@ -140,6 +140,10 @@
 	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-framework vecLib"])
 	AC_MSG_RESULT($ax_blas_ok)
 	LIBS="$save_LIBS"
+	if test $ax_blas_ok = yes; then
+		AC_DEFINE(USE_CBLAS_COMPLEX,1,
+		[Define to 1 to use CBLAS equivalents of FORTRAN complex functions.])
+	fi
 fi
 
 # BLAS in Alpha CXML library?
