From 69b08da2fd9449e8c5b6866e684aa14b9e859808 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Wed, 4 Mar 2026 12:48:40 +0100 Subject: [PATCH] determinant(): added workaround for openblas dgesv incompatibiility --- noncblas.cc | 1 + nonclass.cc | 17 +++++++++++------ nonclass.h | 30 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/noncblas.cc b/noncblas.cc index 5468978..4511d1c 100644 --- a/noncblas.cc +++ b/noncblas.cc @@ -648,6 +648,7 @@ int clapack_dgesv(const CBLAS_ORDER Order, const int N, const int NRHS, double *A, const int lda, int *ipiv, double *B, const int ldb) { +std::cout <<"In MY clapack_dgesv, N and NRHS = "<< N<<" "<< NRHS<<"\n"; FINT INFO=0; if(Order!=CblasRowMajor) laerror("CblasRowMajor order asserted"); //B should be in the same physical order, just transpose A in place and the LU result on output diff --git a/nonclass.cc b/nonclass.cc index 33496e7..e479412 100644 --- a/nonclass.cc +++ b/nonclass.cc @@ -140,15 +140,23 @@ static void linear_solve_do(NRMat &A, double *B, const int nrhs, const i int r, *ipiv; int iswap=0; - + if(nrhs==0) std::cout<<"Warning: some dgesv implementations might skip LU decomposition when nrhs==0\n"; if (n==A.nrows() && A.nrows() != A.ncols()) laerror("linear_solve() call for non-square matrix"); A.copyonwrite(); ipiv = new int[A.nrows()]; #ifdef IPIV_DEBUG for(int i=0; i &A, double *B, const int nrhs, const i if(det && r>0) *det = 0; #ifdef IPIV_DEBUG std::cout <<"iswap = "< &a, double *b, const int nrhs, const int ldb, double *det, int n) { + if(nrhs==0) std::cout<<"Warning: some dspsv implementations might skip LU decomposition when nrhs==0\n"; FINT r, *ipiv; a.copyonwrite(); ipiv = new FINT[n]; diff --git a/nonclass.h b/nonclass.h index 1bb0864..029d2db 100644 --- a/nonclass.h +++ b/nonclass.h @@ -272,16 +272,9 @@ typename LA_traits::normtype MatrixNorm(const MAT &A, const char norm); template typename LA_traits::normtype CondNumber(const MAT &A, const char norm); - -//general determinant -template -const typename LA_traits::elementtype determinant(MAT a)//passed by value -{ -typename LA_traits::elementtype det; -if(a.nrows()!=a.ncols()) laerror("determinant of non-square matrix"); -linear_solve(a,NULL,&det); -return det; -} +#ifdef HAS_MKL +#define NO_OPENBLAS_WORKAROUND +#endif //general determinant destructive on input template @@ -289,10 +282,27 @@ const typename LA_traits::elementtype determinant_destroy(MAT &a) //passed { typename LA_traits::elementtype det; if(a.nrows()!=a.ncols()) laerror("determinant of non-square matrix"); + +//for openblas 0.3.31 we have to fake some RHS otherwise LU decomp. is not performed +#ifdef NO_OPENBLAS_WORKAROUND linear_solve(a,NULL,&det); +#else +//fake rhs +NRVec::elementtype> b(a.ncols()); +for(int i=0; i::elementtype)i; +linear_solve(a,b,&det); +#endif return det; } +//general determinant +template +const typename LA_traits::elementtype determinant(MAT a)//passed by value +{ +a.copyonwrite(); +return determinant_destroy(a); +} + //------------------------------------------------------------------------------ // solves set of linear equations using gesvx