public static SparseEqSystem Generate(CSparse.Double.SparseMatrix eqSystem) { var buf = new SparseEqSystem(); var lastCol = eqSystem.ColumnCount; var eqs = buf.Equations = new SparseRow[eqSystem.RowCount]; var colNnzs = buf.ColumnNonzeros = new int[eqSystem.ColumnCount]; buf.RowNonzeros = new int[eqSystem.RowCount]; for (var i = 0; i < eqs.Length; i++) { buf.Equations[i] = new SparseRow(1); } foreach (var tuple in eqSystem.EnumerateIndexed2()) { var rw = tuple.Item1; //tuple.Item1; var col = tuple.Item2; //tuple.Item2; var val = tuple.Item3; eqs[rw].Add(col, val); if (col != lastCol) { colNnzs[col]++; } } for (var i = 0; i < eqs.Length; i++) { buf.RowNonzeros[i] = buf.Equations[i].CalcNnz(lastCol); } buf.RowCount = eqSystem.RowCount; buf.ColumnCount = eqSystem.ColumnCount; return(buf); }