00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "tool/global.hxx"
00029 #include "numeric/matrix.hxx"
00030 #include <sstream>
00031 #include <stdio.h>
00032
00033 using ::std::vector;
00034 using ::std::string;
00035 using ::std::ostringstream;
00036 using ::scsolver::numeric::Matrix;
00037
00038 namespace scsolver {
00039
00040 #if SCSOLVER_DEBUG
00041 void Debug( const char* s )
00042 {
00043 fprintf(stdout, "%s\n", s);
00044 fflush(stdout);
00045 }
00046 #else
00047 void Debug( const char* )
00048 {
00049 }
00050 #endif
00051
00052 string repeatString( const char* str, unsigned long nNum )
00053 {
00054 ostringstream os;
00055 for ( unsigned int i = 0; i < nNum; ++i )
00056 os << str;
00057 return os.str();
00058 }
00059
00060 void vectorToMatrix(const vector<double>& vec, Matrix& mx, bool rowMatrix)
00061 {
00062 size_t vecSize = vec.size();
00063 if (rowMatrix)
00064 {
00065 Matrix tmp(1, vecSize);
00066 for (size_t i = 0; i < vecSize; ++i)
00067 tmp(0, i) = vec[i];
00068 mx.swap(tmp);
00069 }
00070 else
00071 {
00072 Matrix tmp(vecSize, 1);
00073 for (size_t i = 0; i < vecSize; ++i)
00074 tmp(i, 0) = vec[i];
00075 mx.swap(tmp);
00076 }
00077 }
00078
00079 void matrixToVector(const Matrix& mx, vector<double>& vec)
00080 {
00081 bool rowMatrix = mx.cols() > 1;
00082 if (rowMatrix)
00083 {
00084
00085
00086 size_t n = mx.cols();
00087 vector<double> tmp;
00088 tmp.reserve(n);
00089 for (size_t i = 0; i < n; ++i)
00090 tmp.push_back(mx(0, i));
00091 vec.swap(tmp);
00092 }
00093 else
00094 {
00095
00096
00097 size_t n = mx.rows();
00098 vector<double> tmp;
00099 tmp.reserve(n);
00100 for (size_t i = 0; i < n; ++i)
00101 tmp.push_back(mx(i, 0));
00102 vec.swap(tmp);
00103 }
00104 }
00105
00106 }