Changeset 2646 in Sophya
- Timestamp:
- Feb 7, 2005, 5:42:27 PM (21 years ago)
- Location:
- trunk/SophyaExt/LinAlg
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/LinAlg/intflapack.cc
r2615 r2646 48 48 its is available from http://www.netlib.org. 49 49 50 The present version of our LapackServer (Feb 2001) provides only 51 interfaces for the linear system solver and singular value 52 decomposition (SVD). Only arrays with BaseArray::FortranMemoryMapping 50 The present version of LapackServer (Feb 2005) provides 51 interfaces for the linear system solver, singular value 52 decomposition (SVD), Least square solver and 53 eigen value / eigen vector decomposition. 54 Only arrays with BaseArray::FortranMemoryMapping 53 55 can be handled by LapackServer. LapackServer can be instanciated 54 56 for simple and double precision real or complex array types. 55 57 \warning The input array is overwritten in most cases. 56 58 The example below shows solving a linear system A*X = B 57 59 … … 456 458 if(work) delete [] work; 457 459 return(info); 460 } 461 462 //////////////////////////////////////////////////////////////////////////////////// 463 //! Square matrix inversion using Lapack linear system solver 464 /*! Compute the inverse of a square matrix using linear system solver routine 465 Input arrays should have FortranMemory mapping (column packed). 466 \param a : input matrix, overwritten on output 467 \param ainv : output matrix, contains inverse(a) on exit. 468 ainv is allocated if it has size 0 469 If not allocated, ainv is automatically 470 \return : return code from LapackServer::LinSolve() 471 \sa LapackServer::LinSolve() 472 */ 473 template <class T> 474 int LapackServer<T>::ComputeInverse(TMatrix<T>& a, TMatrix<T> & ainv) 475 { 476 if ( a.NbDimensions() != 2 ) 477 throw(SzMismatchError("LapackServer::Inverse() NDim(a) != 2")); 478 if ( a.GetMemoryMapping() != BaseArray::FortranMemoryMapping ) 479 throw(SzMismatchError("LapackServer::Inverse() a NOT in FortranMemoryMapping")); 480 if ( a.NRows() != a.NCols() ) 481 throw(SzMismatchError("LapackServer::Inverse() a NOT square matrix (a.NRows!=a.NCols)")); 482 if (ainv.IsAllocated()) { 483 bool smo, ssz; 484 ssz = a.CompareSizes(ainv, smo); 485 if ( (ssz == false) || (smo == false) ) 486 throw(SzMismatchError("LapackServer::Inverse() ainv<>a Size/MemOrg mismatch ")); 487 } 488 else ainv.SetSize(a.NRows(), a.NCols(), BaseArray::FortranMemoryMapping, false); 489 ainv = IdentityMatrix(); 490 return LinSolve(a, ainv); 458 491 } 459 492 … … 1026 1059 1027 1060 1028 1029 ////////////////////////////////////////////////////////////////////////////////////1030 void rztest_lapack(TArray<r_4>& aa, TArray<r_4>& bb)1031 {1032 if ( aa.NbDimensions() != 2 ) throw(SzMismatchError("rztest_lapack(TMatrix<r_4> A Not a Matrix"));1033 if ( aa.SizeX() != aa.SizeY()) throw(SzMismatchError("rztest_lapack(TMatrix<r_4> A Not a square Matrix"));1034 if ( bb.NbDimensions() != 2 ) throw(SzMismatchError("rztest_lapack(TMatrix<r_4> A Not a Matrix"));1035 if ( bb.SizeX() != aa.SizeX() ) throw(SzMismatchError("rztest_lapack(TMatrix<r_4> A <> B "));1036 if ( !bb.IsPacked() || !bb.IsPacked() )1037 throw(SzMismatchError("rztest_lapack(TMatrix<r_4> Not packed A or B "));1038 1039 int_4 n = aa.SizeX();1040 int_4 nrhs = bb.SizeY();1041 int_4 lda = n;1042 int_4 ldb = bb.SizeX();1043 int_4 info;1044 int_4* ipiv = new int_4[n];1045 sgesv_(&n, &nrhs, aa.Data(), &lda, ipiv, bb.Data(), &ldb, &info);1046 delete[] ipiv;1047 cout << "rztest_lapack/Info= " << info << endl;1048 cout << aa << "\n" << bb << endl;1049 return;1050 }1051 1052 1061 /////////////////////////////////////////////////////////////// 1053 1062 #ifdef __CXX_PRAGMA_TEMPLATES__ -
trunk/SophyaExt/LinAlg/intflapack.h
r2572 r2646 18 18 virtual int LeastSquareSolve(TArray<T>& a, TArray<T> & b); 19 19 virtual int LeastSquareSolveSVD_DC(TMatrix<T>& a,TMatrix<T>& b,TVector<r_8>& s,int_4& rank,r_8 rcond=-1.); 20 21 // Calcul de la matrice inverse en utilisant la resolution de syst. lineaire 22 virtual int ComputeInverse(TMatrix<T>& a, TMatrix<T>& ainv); 20 23 21 24 virtual int SVD(TArray<T>& a, TArray<T> & s); … … 66 69 inline int LapackLeastSquareSolve(TArray<T>& a, TArray<T> & b) 67 70 { LapackServer<T> lps; return( lps.LeastSquareSolve(a, b) ); } 71 72 /*! \ingroup LinAlg 73 \fn LapackInverse(TMatrix<T>&) 74 \brief Computes the inverse matrix using linear system solver LapackServer::LinSolve. 75 */ 76 template <class T> 77 inline TMatrix<T> LapackInverse(TMatrix<T>& a) 78 { LapackServer<T> lps; TMatrix<T> ainv; lps.ComputeInverse(a, ainv); return ainv; } 68 79 69 80 /*! \ingroup LinAlg
Note:
See TracChangeset
for help on using the changeset viewer.