00001 #ifndef Impala_Core_Matrix_GetDiagonal_h 00002 #define Impala_Core_Matrix_GetDiagonal_h 00003 00004 #include "Basis/ILog.h" 00005 #include "Core/Matrix/MatFunc.h" 00006 #include "Core/Vector/VectorTem.h" 00007 00008 namespace Impala 00009 { 00010 namespace Core 00011 { 00012 namespace Matrix 00013 { 00014 00015 inline Vector::VectorTem<double> 00016 GetDiagonal(Mat* m) 00017 { 00018 ILOG_VAR(Core.Matrix.GetDiagonal); 00019 if(MatNrRow(m) != MatNrCol(m)) 00020 { 00021 ILOG_ERROR("only works for square matrices!"); 00022 return Vector::VectorTem<double>(0); 00023 } 00024 Vector::VectorTem<double> v(MatNrRow(m)); 00025 for(int i=0 ; i<MatNrRow(m) ; ++i) 00026 v[i] = *MatE(m, i, i); 00027 return v; 00028 } 00029 00030 } // namespace Matrix 00031 } // namespace Core 00032 } // namespace Impala 00033 00034 #endif