From bb42a566bcf0259364048dfe5581d4ae4bfee37c Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Thu, 5 Nov 2026 15:47:07 +0100 Subject: [PATCH] mat: efficient complexify --- mat.cc | 38 ++++++++++++++++++++++++++++++++++++++ mat.h | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/mat.cc b/mat.cc index 7508baa..fcaedd9 100644 --- a/mat.cc +++ b/mat.cc @@ -5414,6 +5414,44 @@ for(int j=0; j +NRMat > complexify(const NRMat &rhs) { + NRMat > r(rhs.nrows(), rhs.ncols(), rhs.getlocation()); +#ifdef CUDALA + if(rhs.getlocation() == cpu){ +#endif + cblas_dcopy((size_t)rhs.nrows()*rhs.ncols(), &rhs(0,0), 1, (double*)(&r(0,0)), 2); +#ifdef CUDALA + }else{ + cublasDcopy((size_t)rhs.nrows()*rhs.ncols(), &rhs(0,0), 1, (double*)(&r(0,0)), 2); + TEST_CUBLAS("cublasDcopy");//"NRMat > complexify(const NRMat &)" + } +#endif + return r; +} + +template<> +NRMat > complexify(const NRMat &rhs) { + NRMat > r(rhs.nrows(), rhs.ncols(), rhs.getlocation()); +#ifdef CUDALA + if(rhs.getlocation() == cpu){ +#endif + cblas_scopy((size_t)rhs.nrows()*rhs.ncols(), &rhs(0,0), 1, (float*)(&r(0,0)), 2); +#ifdef CUDALA + }else{ + cublasScopy((size_t)rhs.nrows()*rhs.ncols(), &rhs(0,0), 1, (float*)(&r(0,0)), 2); + TEST_CUBLAS("cublasScopy");//"NRMat > complexify(const NRMat &)" + } +#endif + return r; +} + + /***************************************************************************//** * forced instantization in the corresponding object file ******************************************************************************/ diff --git a/mat.h b/mat.h index 19cb524..3009fb8 100644 --- a/mat.h +++ b/mat.h @@ -1454,6 +1454,10 @@ NRMat > complexify(const NRMat &rhs) { return r; } +//BLAS versions for double and float are in mat.cc +template<> NRMat > complexify(const NRMat &rhs); +template<> NRMat > complexify(const NRMat &rhs); + //this is general for any type, complexmatrix() uses blas for doubles template NRMat > complexify(const NRMat &rhsr, const NRMat &rhsi) {