private static void TestWriteOperation(ISparsityPattern pattern, string referenceFile, SparsityPatternWriter writer) { string tempFile = Guid.NewGuid().ToString() + ".txt"; writer.WriteToFile(pattern, tempFile); bool success = IOUtilities.AreFilesEquivalent(referenceFile, tempFile); File.Delete(tempFile); Assert.True(success); }
private void WriteToStream(ISparsityPattern pattern, StreamWriter writer) { for (int i = 0; i < pattern.NumRows; ++i) { for (int j = 0; j < pattern.NumColumns; ++j) { if (pattern.IsNonZero(i, j)) { writer.Write("1 "); } else { writer.Write("0 "); } } writer.WriteLine(); } }
/// <summary> /// Writes the sparsity pattern of a matrix to the file at <paramref name="path"/>. /// </summary> /// <param name="matrix">The sparsity pattern of the 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(ISparsityPattern matrix, string path, bool append = false) { Utilities.WriteToFile((writer) => WriteToStream(matrix, writer), path, append); }
/// <summary> /// Writes the sparsity pattern of a matrix to Console. /// </summary> /// <param name="matrix">The sparsity pattern of the matrix to write.</param> public void WriteToConsole(ISparsityPattern matrix) { Utilities.WriteToConsole((writer) => WriteToStream(matrix, writer)); }
private static void TestWriteOperation(ISparsityPattern matrix, string referenceFile) => TestWriteOperation(matrix, referenceFile, new SparsityPatternWriter());