Exemple #1
0
        /// <summary>
        /// Expand matrix to full storage (symmetric matrix is expected to store upper part only).
        /// </summary>
        public static SparseMatrix Expand(this SparseMatrix A)
        {
            if (A.Any((i, j, a) => i > j && a != 0.0))
            {
                throw new Exception("Expected matrix to be upper.");
            }

            // Transpose A.
            var T = A.Transpose();

            // Remove diagonal.
            T.Keep((i, j, a) => i != j);

            return((SparseMatrix)A.Add(T));
        }