00001
00003 #ifndef Impala_Core_Matrix_MatSvd_h
00004 #define Impala_Core_Matrix_MatSvd_h
00005
00006 #include "Core/Matrix/MatFunc.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Matrix
00013 {
00014
00015
00016 template<class ArrayT>
00017 inline void
00018 MatSvd(ArrayT* a, ArrayT*& u, ArrayT*& s, ArrayT*& v)
00019 {
00020 char job = 'A';
00021 int rows = a->H();
00022 int cols = a->W();
00023 double* aData;
00024 double* uData;
00025 double* sData;
00026 double* vData;
00027 int lwork = 1;
00028 double* workData;
00029 int info;
00030 int bla = dgesvd_(&job, &job, &rows, &cols, aData,
00031 &rows, sData, uData, &rows, vData,
00032 &cols, workData, &lwork, &info);
00033
00034
00035 if(info < 0)
00036 {
00037 std::cerr << "[MatSvd] illegal value@" << info << ": " << aData[-info-1] << std::endl;
00038 return;
00039 }
00040 if(info < 0)
00041 {
00042 std::cerr << "[MatSvd] did not converge" << std::endl;
00043 return;
00044 }
00045
00046 u = new ArrayT(uData);
00047 s = new ArrayT(sData);
00048 v = new ArrayT(vData);
00049 }
00050
00051
00052 }
00053 }
00054 }
00055
00056 #endif