private void WriteSymmetricMatrix(ISparseSymmetricMatrix matrix, StreamWriter writer) { string numberFormat = NumericFormat.GetRealNumberFormat(); writer.Write($"{matrix.NumRows} {matrix.NumColumns} {matrix.CountNonZerosUpper()}"); foreach (var(row, col, val) in matrix.EnumerateNonZerosUpper()) { writer.WriteLine(); writer.Write($"{row} {col} "); writer.Write(numberFormat, val); } }
/// <summary> /// Writes the non zero entries of the provided symmetric sparse matrix to the file at <paramref name="path"/>. /// </summary> /// <param name="matrix">The symmetric sparse matrix to write.</param> /// <param name="path">The absolute path of the file, where <paramref name="matrix"/> will be written.</param> /// <param name="append">If true, <paramref name="matrix"/> will be written after the current contents of the file at /// <paramref name="path"/>. If false, it will overwrite them.</param> public void WriteToFile(ISparseSymmetricMatrix matrix, string path, bool append = false) { Utilities.WriteToFile((writer) => WriteSymmetricMatrix(matrix, writer), path, append); }
/// <summary> /// Writes the non zero entries of the provided symmetric sparse matrix to Console. /// </summary> /// <param name="matrix">The symmetric sparse matrix to write.</param> public void WriteToConsole(ISparseSymmetricMatrix matrix) { Utilities.WriteToConsole((writer) => WriteSymmetricMatrix(matrix, writer)); }