/// <summary> /// Computes the percentage of weakly diagonally dominant rows/columns /// </summary> private void DiagonalDominant() { int n = S.RowCount; var ax = S.Values; var ap = S.RowPointers; var ai = S.ColumnIndices; var rwork = new double[n]; var cwork = new double[n]; var dwork = new double[n]; int i, j, k, end; double a, b, max = 0.0; double fnorm = 0.0; // Frobenius norm for (i = 0; i < n; i++) { end = ap[i + 1]; for (k = ap[i]; k < end; k++) { j = ai[k]; a = math.Abs(ax[k]); fnorm += math.Square(ax[k]); if (j == i) { dwork[i] = a; } else { rwork[i] += a; cwork[j] += a; } max = Math.Max(max, a); } } int ddomc = 0; // number of weakly diagonally dominant columns int ddomr = 0; // number of weakly diagonally dominant rows a = b = 0.0; for (i = 0; i < n; i++) { if (cwork[i] <= dwork[i]) { ddomc++; } if (rwork[i] <= dwork[i]) { ddomr++; } a = Math.Max(rwork[i] + dwork[i], a); // Infinity norm b = Math.Max(cwork[i] + dwork[i], b); // 1-norm } var info = this.StorageInfo; info.DiagonallyDominantRows = ddomr; info.DiagonallyDominantColumns = ddomc; info.MaxAbsoluteValue = max; info.FrobeniusNorm = Math.Sqrt(fnorm); info.InfNorm = a; info.OneNorm = b; }