Skip to content
Snippets Groups Projects
Commit e3380587 authored by Paul Nitzke's avatar Paul Nitzke
Browse files

Complete documentation for MatrixMarketWriter

* Also rename internal parameters to follow C# naming conventions
parent cf614f71
No related branches found
No related tags found
1 merge request!27Complete documentation and streamline coding style a bit
......@@ -2,22 +2,44 @@
namespace SparseTransform.Convert
{
/// <summary>
/// Provides an IWriter implementation that outputs a MatrixMarket string.
/// Supports output of both the seed matrix and compressed matrix.
/// </summary>
class MatrixMarketWriter : IWriter
{
private bool seed;
private DoubleMatrix inputMatrix;
/// <summary>
/// If true, write (only) the seed matrix
/// </summary>
private bool _seed;
/// <summary>
/// Input matrix that was read in using an IReader implementation.
/// Used for computing the compressed matrix.
/// </summary>
private DoubleMatrix _inputMatrix;
/// <summary>
/// Construct a new MatrixMarketWriter.
/// </summary>
/// <param name="seed">if true, output seed matrix</param>
/// <param name="inputMatrix">input matrix</param>
public MatrixMarketWriter(bool seed, DoubleMatrix inputMatrix)
{
this.inputMatrix = inputMatrix;
this.seed = seed;
this._inputMatrix = inputMatrix;
this._seed = seed;
}
/// <summary>
/// Transforms the <c>graph</c> to a MatrixMarket string.
/// If seed flag was set in constructor, the seed matrix is written.
/// </summary>
/// <param name="graph">IGraph implementation to transform</param>
/// <returns>MatrixMarket string</returns>
public string Write(IGraph graph)
{
IntegerMatrix? seedMatrix = graph.ToSeedMatrix(inputMatrix.RowCount);
if (seed)
IntegerMatrix? seedMatrix = graph.ToSeedMatrix(_inputMatrix.RowCount);
if (_seed)
{
// ziemlich wilder ausdruck, wa? Liefert die seed matrix aus einem AdjacencyGraph oder BipartiteGraph. (je nachdem was IGraph ist)
......@@ -29,18 +51,18 @@ namespace SparseTransform.Convert
}
else
{
if (seedMatrix is IntegerMatrix && inputMatrix is DoubleMatrix && seedMatrix.RowCount != 0)
if (seedMatrix is IntegerMatrix && _inputMatrix is DoubleMatrix && seedMatrix.RowCount != 0)
{
return CalculateCompressedMatrix(inputMatrix, seedMatrix).ToMatrixMarketString();
return CalculateCompressedMatrix(_inputMatrix, seedMatrix).ToMatrixMarketString();
}
return "null";
}
}
/// <summary>
/// todo
/// Calculate the compressed matrix from the input and seed matrix.
/// The formula is A*S = B where A is the input and B the compressed matrix.
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private DoubleMatrix CalculateCompressedMatrix(DoubleMatrix inputMatrix, IntegerMatrix seedMatrix)
{
return inputMatrix.Multiply(seedMatrix);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment