diff --git a/nonclass.cc b/nonclass.cc index e60cdc0..7b36641 100644 --- a/nonclass.cc +++ b/nonclass.cc @@ -1,7 +1,12 @@ +#ifndef NONCBLAS extern "C" { #include "atlas_enum.h" #include "clapack.h" } +#else +#include "noncblas.h" +#endif + #include "vec.h" #include "smat.h" #include "mat.h" @@ -157,7 +162,6 @@ extern "C" void FORNAME(dspsv)(const char *UPLO, const int *N, const int *NRHS, static void linear_solve_do(NRSMat &a, double *b, const int nrhs, const int ldb, double *det, int n) { int r, *ipiv; - if (det) cerr << "@@@ sign of the determinant not implemented correctly yet\n"; a.copyonwrite(); ipiv = new int[n]; char U = 'U'; @@ -169,8 +173,7 @@ static void linear_solve_do(NRSMat &a, double *b, const int nrhs, const if (det && r >= 0) { *det = a(0,0); for (int i=1; i 0 && b) laerror("singular matrix in linear_solve(SMat&, Mat*, double*"); diff --git a/nonclass.h b/nonclass.h index f1efb40..8b99cdf 100644 --- a/nonclass.h +++ b/nonclass.h @@ -66,11 +66,12 @@ declare_la(complex) // Separate declarations //general nonsymmetric matrix and generalized diagonalization extern void gdiagonalize(NRMat &a, NRVec &wr, NRVec &wi, - NRMat *vl, NRMat *vr, const bool corder=1, int n=0, + NRMat *vl, NRMat *vr, const bool corder=1, int n=0, const int sorttype=0, const bool biorthonormalize=0, NRMat *b=NULL, NRVec *beta=NULL); extern void gdiagonalize(NRMat &a, NRVec< complex > &w, NRMat< complex >*vl, NRMat< complex > *vr, - const bool corder=1, int n=0, NRMat *b=NULL, NRVec *beta=NULL); + const bool corder=1, int n=0, const int sorttype=0, const bool biorthonormalize=0, + NRMat *b=NULL, NRVec *beta=NULL); extern NRMat matrixfunction(NRSMat a, double (*f) (double)); extern NRMat matrixfunction(NRMat a, complex (*f)(const complex &),const bool adjust=0); @@ -100,7 +101,7 @@ const NRMat inverse(NRMat a, T *det=0) //general determinant template -const typename LA_traits::elementtype determinant(MAT a)//again passed by value +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"); @@ -108,6 +109,38 @@ linear_solve(a,NULL,&det); return det; } +//general determinant destructive on input +template +const typename LA_traits::elementtype determinant_destroy(MAT &a) //passed by reference +{ +typename LA_traits::elementtype det; +if(a.nrows()!=a.ncols()) laerror("determinant of non-square matrix"); +linear_solve(a,NULL,&det); +return det; +} + +//general submatrix +template +const NRMat::elementtype> submatrix(const MAT a, const INDEX rows, const INDEX cols, int indexshift=0, bool ignoresign=false) +{ +NRMat::elementtype> r(rows.size(),cols.size()); + +if(ignoresign) +{ +for(int i=0; i &v);