46 { 11., 0., 13., 0., 15. },
47 { 0., 22., 0., 24., 0. },
48 { 31., 0., 33., 0., 35. },
49 { 0., 42., 0., 44., 0. },
50 { 51., 0., 53., 0., 55. }
62 cond[0] = mh.ConditionNumber();
68 cond[1] = mh.ConditionNumber();
74 main(
int argc,
char* argv[])
78 scale.
iMaxIter = argc >= 2 ? atoi(argv[1]) : 100;
79 scale.
dTol = argc >= 3 ? atof(argv[2]) :
sqrt(std::numeric_limits<doublereal>::epsilon());
149 const int N =
sizeof(matScale)/
sizeof(matScale[0]);
151 for (
int iMatScale = 0; iMatScale < N; ++iMatScale) {
152 std::vector<integer> perm(5), invperm(5);
158 for (
int i = 0; i < 5; i++) {
159 invperm[perm[i]] = i;
171 for (
unsigned ir = 0; ir < 5; ir++) {
172 for (
unsigned ic = 0; ic < 5; ic++) {
173 if (
mat[ir][ic] != 0.) {
174 nm(ir + 1, ic + 1) =
mat[ir][ic];
175 npm(ir + 1, ic + 1) =
mat[ir][ic];
176 fm(ir + 1, ic + 1) =
mat[ir][ic];
177 spm(ir + 1, ic + 1) =
mat[ir][ic];
182 std::vector<doublereal> Ax0, Ax1, Axd0, Axd1;
183 std::vector<integer> Ai0, Ai1, Ap0, Ap1, Aid0, Apd0, Aid1, Apd1;
195 ScaleMatrix(
"Naive", *matScale[iMatScale].pNaive, nm);
196 ScaleMatrix(
"NaivePerm", *matScale[iMatScale].pNaivePerm, npm);
197 ScaleMatrix(
"Full", *matScale[iMatScale].pFull, fm);
198 ScaleMatrix(
"Dir0", *matScale[iMatScale].pDirCCol0, dirccm0);
199 ScaleMatrix(
"Dir1", *matScale[iMatScale].pDirCCol1, dirccm1);
200 ScaleMatrix(
"CC0", *matScale[iMatScale].pCCol0, ccm0);
201 ScaleMatrix(
"CC1", *matScale[iMatScale].pCCol1, ccm1);
202 ScaleMatrix(
"Map", *matScale[iMatScale].pMap, spm);
205 for (
unsigned i = 0; i <
sizeof(matScale)/
sizeof(matScale[0]); ++i) {
206 delete matScale[i].pNaive;
207 delete matScale[i].pNaivePerm;
208 delete matScale[i].pFull;
209 delete matScale[i].pCCol0;
210 delete matScale[i].pCCol1;
211 delete matScale[i].pDirCCol0;
212 delete matScale[i].pDirCCol1;
213 delete matScale[i].pMap;
220 std::cout <<
"------------------------------------------------------------" << std::endl;
221 std::cout << title <<
": " << (fOK ?
"OK" :
"NOK") <<
" : " <<
typeid(matScale).name() << std::endl;
223 std::cout <<
"condition number before scaling:" << cond[0] << std::endl;
224 std::cout <<
"condition number after scaling:" << cond[1] << std::endl;
226 matScale.
Report(std::cout);
227 const std::vector<doublereal>& r = matScale.
GetRowScale();
228 const std::vector<doublereal>&
c = matScale.
GetColScale();
232 for (
int i = 0; i < N; ++i) {
234 <<
" r[" << i <<
"]=" << std::setw(12) << (r.empty() ? 1. : r[i])
235 <<
" c[" << i <<
"]=" << std::setw(12) << (c.empty() ? 1. : c[i])
239 std::cout <<
"matrix after scaling:" << std::endl << mh << std::endl;
240 std::cout <<
"------------------------------------------------------------" << std::endl;
virtual integer iGetNumCols(void) const =0
int main(int argc, char *argv[])
integer MakeCompressedColumnForm(doublereal *const Ax, integer *const Ai, integer *const Ap, int offset=0) const
bool ComputeScaleFactors(const T &mh)
const std::vector< doublereal > & GetRowScale() const
std::ostream & Report(std::ostream &os) const
const std::vector< doublereal > & GetColScale() const
void ScaleMatrix(const char *title, MatrixScale< T > &matScale, T &mh)
static doublereal mat[5][5]
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
void ReportMatScale(const char *title, bool fOK, const MatrixScaleBase &matScale, const MatrixHandler &mh, const double cond[2])
static std::stack< cleanup * > c
virtual integer iGetNumRows(void) const =0
T & ScaleMatrix(T &mh) const