Skip to content
Snippets Groups Projects
Select Git revision
  • 8a7790ca648273b9c68d9110d11fc53b9abd67e8
  • master default protected
  • gitkeep
  • Issue/2463-newCoscinePIDTypes
  • dev protected
  • Issue/2309-docs
  • Issue/2259-updatePids
  • Issue/1321-pidEnquiryOverhaul
  • Issue/2158-emailServicedesk
  • uiv2
  • Hotfix/2130-uiv2ContactChange
  • Hotfix/2087-efNet6
  • Issue/1910-MigrationtoNET6.0
  • Issue/1971-projectEditCreateMigration
  • Issue/1980-userManagement
  • Sprint/2022-01
  • Sprint/2021-2022
  • Issue/1741-semanticSearchActions
  • Sprint/2021-23
  • Issue/1746-ApplicationProfileStoringMethod
  • Hotfix/1466-projectCreationTimeout
  • v3.3.2
  • v3.3.1
  • v3.3.0
  • v3.2.0
  • v3.1.0
  • v3.0.0
  • v2.4.1
  • v2.4.0
  • v2.3.0
  • v2.2.0
  • v2.1.1
  • v2.1.0
  • v2.0.0
  • v1.18.0
  • v1.17.1
  • v1.17.0
  • v1.16.0
  • v1.15.1
  • v1.15.0
  • v1.14.0
41 results

NotificationAction.cs

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    MatrixMarketWriter.cs 2.58 KiB
    using SparseTransform.DataStructures;
    
    namespace SparseTransform.Convert
    {
        /// <summary>
        /// Provides an IWriter implementation that outputs a MatrixMarket string.
        /// Supports output of both the seed matrix and compressed matrix.
        /// </summary>
        public class MatrixMarketWriter : IWriter
        {
            /// <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;
            }
    
            /// <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)
                {
                    // ziemlich wilder ausdruck, wa? Liefert die seed matrix aus einem AdjacencyGraph oder BipartiteGraph. (je nachdem was IGraph ist)
                    
                    if (seedMatrix is IntegerMatrix && seedMatrix.RowCount != 0)
                    {
                        return seedMatrix.ToMatrixMarketString();
                    }
                    return "null";
                }
                else
                {
                    if (seedMatrix is IntegerMatrix && _inputMatrix is DoubleMatrix && seedMatrix.RowCount != 0)
                    {
                        return CalculateCompressedMatrix(_inputMatrix, seedMatrix).ToMatrixMarketString();
                    }
                    return "null";
                }
            }
    
            /// <summary>
            /// 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>
            private DoubleMatrix CalculateCompressedMatrix(DoubleMatrix inputMatrix, IntegerMatrix seedMatrix)
            {
                return inputMatrix.Multiply(seedMatrix);
            }
        }
    }