| 58 | |
| 59 | |
| 60 | dReal dMatrixComparison::nextMatrix (dReal *A, int n, int m, int lower_tri, const char *name, ...) |
| 61 | { |
| 62 | if (A==0 || n < 1 || m < 1 || name==0) dDebug (0,"bad args to nextMatrix"); |
| 63 | int num = n*dPAD(m); |
| 64 | |
| 65 | if (afterfirst==0) { |
| 66 | dMatInfo *mi = (dMatInfo*) dAlloc (sizeof(dMatInfo)); |
| 67 | mi->n = n; |
| 68 | mi->m = m; |
| 69 | mi->size = num * sizeof(dReal); |
| 70 | mi->data = (dReal*) dAlloc (mi->size); |
| 71 | memcpy (mi->data,A,mi->size); |
| 72 | |
| 73 | va_list ap; |
| 74 | va_start (ap,name); |
| 75 | vsprintf (mi->name,name,ap); |
| 76 | if (strlen(mi->name) >= sizeof (mi->name)) dDebug (0,"name too long"); |
| 77 | |
| 78 | mat.push (mi); |
| 79 | return 0; |
| 80 | } |
| 81 | else { |
| 82 | if (lower_tri && n != m) |
| 83 | dDebug (0,"dMatrixComparison, lower triangular matrix must be square"); |
| 84 | if (index >= mat.size()) dDebug (0,"dMatrixComparison, too many matrices"); |
| 85 | dMatInfo *mp = mat[index]; |
| 86 | index++; |
| 87 | |
| 88 | dMatInfo mi; |
| 89 | va_list ap; |
| 90 | va_start (ap,name); |
| 91 | vsprintf (mi.name,name,ap); |
| 92 | if (strlen(mi.name) >= sizeof (mi.name)) dDebug (0,"name too long"); |
| 93 | |
| 94 | if (strcmp(mp->name,mi.name) != 0) |
| 95 | dDebug (0,"dMatrixComparison, name mismatch (\"%s\" and \"%s\")", |
| 96 | mp->name,mi.name); |
| 97 | if (mp->n != n || mp->m != m) |
| 98 | dDebug (0,"dMatrixComparison, size mismatch (%dx%d and %dx%d)", |
| 99 | mp->n,mp->m,n,m); |
| 100 | |
| 101 | dReal maxdiff; |
| 102 | if (lower_tri) { |
| 103 | maxdiff = dMaxDifferenceLowerTriangle (A,mp->data,n); |
| 104 | } |
| 105 | else { |
| 106 | maxdiff = dMaxDifference (A,mp->data,n,m); |
| 107 | } |
| 108 | if (maxdiff > tol) |
| 109 | dDebug (0,"dMatrixComparison, matrix error (size=%dx%d, name=\"%s\", " |
| 110 | "error=%.4e)",n,m,mi.name,maxdiff); |
| 111 | return maxdiff; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | void dMatrixComparison::end() |
no test coverage detected