38 # error "don't have header file for string"
45 using std::ostringstream;
58 bool isColumnMajor,
int startSize,
int valueSize,
int* start,
int* index,
59 double* value,
int dimension)
61 if ( !start || startSize <= 1 )
return NULL;
62 if ( !value || !index )
return NULL;
64 int iStartSize = dimension + 1;
66 matrix =
new SparseMatrix( !isColumnMajor, iStartSize, valueSize);
68 int iNumSource = startSize - 1;
69 int* miStart = matrix->
starts;
71 double* mdValue = matrix->
values;
73 for ( i = 0; i < iStartSize; i++)
79 for (i = 0; i < iNumSource; i++)
81 for (j = start[i]; j < start[ i + 1 ]; j++)
86 miStart[ index[
j] + 1] ++;
94 for (i = 1; i < iStartSize; i++ )
96 miStart[i] += miStart [i - 1] ;
102 for (i = 0; i < iNumSource; i++)
105 for (j = start[i]; j < start[ i + 1 ]; j++)
107 iTemp = miStart[ index[
j]];
108 miIndex [ iTemp] = i;
109 mdValue [ iTemp] = value[
j];
110 miStart[ index[
j]] ++;
115 for (i = iStartSize - 1; i >= 1; i-- )
117 miStart[i] = miStart [i - 1] ;
130 if (strcmp(str,
"INF") == 0)
132 *strEnd = (
char *)str + 3;
135 else if (strcmp(str,
"-INF") == 0)
137 *strEnd = (
char *)str + 4;
140 else if (strcmp(str,
"NaN") == 0)
142 *strEnd = (
char *)str + 3;
147 return strtod(str, strEnd);
159 ostringstream outStr;
185 charResult =
os_dtoa(x, 0, 0, &decimalPointPos, &sign, NULL);
188 if( sign == 1) outStr <<
"-";
189 strLength = strlen( charResult);
193 if(decimalPointPos == 9999)
195 for(k = 0; k < strLength; k++)outStr << charResult[ k];
198 if(decimalPointPos == strLength)
200 for(k = 0; k < strLength; k++)outStr << charResult[ k];
203 if(decimalPointPos >= 0)
205 if(decimalPointPos > strLength)
210 outStr << charResult[ 0];
211 if(decimalPointPos <= 5)
213 for(k = strLength; k < decimalPointPos; k++) outStr <<
"0";
218 for(k = 1; k < strLength; k++) outStr << charResult[ k];
220 outStr << decimalPointPos - 1;
225 outStr << charResult[ 0];
227 for(k = 1; k < strLength; k++) outStr << charResult[ k];
229 outStr << decimalPointPos - 1;
234 for(k = 0; k < decimalPointPos; k++) outStr << charResult[ k];
236 for(k = decimalPointPos; k < strLength; k++) outStr << charResult[ k];
241 outStr << charResult[ 0];
244 for(k = 1; k < strLength; k++)outStr << charResult[ k];
246 outStr << decimalPointPos -1 ;
268 return (
double) i/RAND_MAX;
281 return iMin + rand()%(iMax - iMin + 1);
double os_strtod(const char *s00, char **se)
static SparseMatrix * convertLinearConstraintCoefficientMatrixToTheOtherMajor(bool isColumnMajor, int startSize, int valueSize, int *start, int *index, double *value, int dimension)
Round a double number to the precision specified.
void os_freedtoa(char *s)
double os_strtod_wrap(const char *str, char **strEnd)
~MathUtil()
the class destructor
int * indexes
indexes holds an integer array of rowIdx (or colIdx) elements in coefMatrix (AMatrix).
double OSNaN()
returns the value for NaN used in OS
double OSiRand(int iMin, int iMax)
OSiRand(int iMin, int iMax)
a sparse matrix data structure
double * values
values holds a double array of value elements in coefMatrix (AMatrix), which contains nonzero element...
MathUtil()
the class constructor
char * os_dtoa(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
std::string os_dtoa_format(double x)
int * starts
starts holds an integer array of start elements in coefMatrix (AMatrix), which points to the start of...
bool OSIsnan(double x)
checks whether a given double is NaN
void fint fint fint real fint real * x