Main Page | Namespace List | Class List | File List | Class Members | File Members

MyLapack.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Claudio Attaccalite                             *
00003  *   claudio@freescience.info                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020  
00021 #include "MyLapack.h"
00022 
00023 using namespace std;
00024 
00025 /********** Double Precision **************/
00026 
00027 double DLU_det(DMatrix &A,int *ipiv)
00028 {
00029         double det=A(0,0);
00030         int isum=0;
00031         if(ipiv[0]!=0) isum=1;
00032         for(int i=1;i<A.dim1();i++)
00033         {
00034                 det*=A(i,i);
00035                 if(ipiv[i]!=i) isum++;
00036         }
00037         if(isum%2!=0) det=-det;
00038         return det;
00039 }
00040 
00041 int DLU_decomp(DMatrix &A,int *ipiv)
00042 {
00043 int info;
00044 int n=A.dim1();
00045 F77_FUNC(dgetrf,DGETRF)(&n,&n,A.array(),&n,ipiv,&info);
00046 return info;
00047 }
00048 
00049 int DLU_invert(DMatrix &A,int *ipiv,double *work,int &lwork)
00050 { 
00051 int info;
00052 int n  =A.dim2();
00053 int lda=A.dim1();
00054 F77_FUNC(dgetri,DGETRI)(&n,A.array(),&lda,ipiv,work,&lwork,&info);
00055 return info;
00056 }
00057 
00058 
00059 int DSYEV(char jobz,char uplo,DMatrix &M,DVector &V,double *work,int &lwork)
00060 {
00061 int n  =M.dim2();
00062 int lda=M.dim1();
00063 int info;
00064 F77_FUNC(dsyev,DSYEV)(&jobz,&uplo,&n,M.array(),&lda,V.array(),work,&lwork,&info);
00065  return info;
00066 }
00067 
00068 int DLU_solve(DMatrix &M,int *ipiv,DVector &b)
00069 { 
00070 int info;
00071 int one=1;
00072 int n=M.dim1();
00073 F77_FUNC(dgetrs,DGETRS)("N", &n, &one,M.array(),&n,ipiv,b.array(),&n, &info);
00074 return info;
00075 }
00076 
00077 /********** Single Precision **************/
00078 
00079 float SLU_det(SMatrix &A,int *ipiv)
00080 {
00081         float det=A(0,0);
00082         int isum=0;
00083         if(ipiv[0]!=0) isum=1;
00084         for(int i=1;i<A.dim1();i++)
00085         {
00086                 det*=A(i,i);
00087                 if(ipiv[i]!=i) isum++;
00088         }
00089         if(isum%2!=0) det=-det;
00090         return det;
00091 }
00092 
00093 int SLU_decomp(SMatrix &A,int *ipiv)
00094 {
00095 int info;
00096 int n=A.dim1();
00097 F77_FUNC(sgetrf,SGETRF)(&n,&n,A.array(),&n,ipiv,&info);
00098 return info;
00099 }
00100 
00101 int SLU_invert(SMatrix &A,int *ipiv,float *work,int &lwork)
00102 { 
00103 int info;
00104 int n  =A.dim2();
00105 int lda=A.dim1();
00106 F77_FUNC(sgetri,SGETRI)(&n,A.array(),&lda,ipiv,work,&lwork,&info);
00107 return info;
00108 }
00109 
00110 
00111 int SSYEV(char jobz,char uplo,SMatrix &M,SVector &V,float *work,int &lwork)
00112 {
00113 int n  =M.dim2();
00114 int lda=M.dim1();
00115 int info;
00116 F77_FUNC(ssyev,SSYEV)(&jobz,&uplo,&n,M.array(),&lda,V.array(),work,&lwork,&info);
00117  return info;
00118 }
00119 
00120 int SLU_solve(SMatrix &M,int *ipiv,SVector &b)
00121 { 
00122 int info;
00123 int one=1;
00124 int n=M.dim1();
00125 F77_FUNC(sgetrs,SGETRS)("N", &n, &one,M.array(),&n,ipiv,b.array(),&n, &info);
00126 return info;
00127 }

Generated on Wed Aug 16 19:03:50 2006 for MyLapack by  doxygen 1.4.4