From b9dc73c2c4caf9e35fc69963af3ac32ea124d1a9 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Tue, 17 Nov 2026 12:36:03 +0100 Subject: [PATCH] xaxpy specializations for std::complex --- doc/nonclass.tex | 6 ++++-- nonclass.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/nonclass.tex b/doc/nonclass.tex index a7f03b2..a8c3d10 100644 --- a/doc/nonclass.tex +++ b/doc/nonclass.tex @@ -62,7 +62,8 @@ Function & Available for \\ \texttt{gdiagonalize} & real matrix (real or complex eigenvector storage), complex matrix \\ \texttt{trace2} with \texttt{NRSMat} & \texttt{double}, \texttt{float}, \texttt{complex}, \texttt{complex} (hermitian) \\ \texttt{diagonalize3}, \texttt{realmatrixfunction}, \texttt{complexmatrixfunction}, -\texttt{adjustphases}, \texttt{xcopy}, \texttt{xaxpy}, \texttt{xdot} & \texttt{double}, \texttt{float} \\ +\texttt{adjustphases}, \texttt{xcopy}, \texttt{xdot} & \texttt{double}, \texttt{float} \\ +\texttt{xaxpy} & \texttt{double}, \texttt{float}, \texttt{complex}, \texttt{complex} \\ templates of \texttt{matexp.h}, \texttt{power}, \texttt{commutator}, \texttt{twoside\_transform}, \dots & any type providing the needed operations \\ \bottomrule \end{tabular} @@ -315,7 +316,8 @@ Application from the source: overlap of Slater determinants with signed spin-orb \lafunc{NRMat reconstructmatrix(const M &implicitmat)}{Explicit matrix of an implicit one (applying \code{gemv} to unit vectors), for debugging; both template arguments must be given. Equivalent to \code{explicit_matrix} of \header{davidson.h} (chapter~\ref{ch:iterative}).} \lafunc{void xcopy(int n, const T *x, int incx, T *y, int incy); void xaxpy(int n, const T &a, const T *x, int incx, T *y, int incy); T xdot(int n, const T *x, int incx, const T *y, int incy)}{Type-generic -names of the CBLAS routines (to ease switching between \code{float}/\code{double}/complex in user code); specialized for \code{double} and \code{float}.} +names of the CBLAS routines (to ease switching between \code{float}/\code{double}/complex in user code); specialized for \code{double} and \code{float}, +\code{xaxpy} also for \code{complex} and \code{complex}.} \end{lareference} \section{Examples}\label{sec:nonclass:examples} diff --git a/nonclass.h b/nonclass.h index 0c99565..972035d 100644 --- a/nonclass.h +++ b/nonclass.h @@ -473,6 +473,18 @@ inline float xdot(int n, const float *x, int incx, const float *y, int in return cblas_sdot(n,x,incx,y,incy); } +template<> +inline void xaxpy >(int n, const std::complex &a, const std::complex *x, int incx, std::complex *y, int incy) +{ +cblas_zaxpy(n, &a, x, incx, y, incy); +} + +template<> +inline void xaxpy >(int n, const std::complex &a, const std::complex *x, int incx, std::complex *y, int incy) +{ +cblas_caxpy(n, &a, x, incx, y, incy); +} + //debugging aid: reconstruct an explicit matrix from the implicit version