00001 #ifndef GMatrix_UTIL_H
00002 #define GMatrix_UTIL_H
00003
00004 #include "GObject.h"
00005 #include "GMatrix.h"
00006 #include "io/GError_Output.h"
00007 #include <string>
00008
00009 namespace GMathLib
00010 {
00011
00016 namespace GMatrix_Util{
00017
00023 inline void Identity_Matrix(GMatrix& mx){
00024 int column = mx.Column();
00025 int row = mx.Row();
00026
00027
00028 if( column != row ){
00029 const std::string context = "A given matrix is not a square matrix.";
00030 IO::GError_Output::Puts("GMatrix_Util::Identity_Matrix", context);
00031
00032 }else{
00033
00034 for(int i = 0; i < row; i++){
00035 for(int j=0; j < column; j++){
00036 if(i == j){
00037 mx.SetElement(i, j, 1);
00038 }else{
00039 mx.SetElement(i, j, 0);
00040 }
00041 }
00042 }
00043
00044 }
00045 }
00046
00047 }
00048 }
00049
00050 #endif