• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Complex.SparseMatrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Complex.SparseMatrix的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix类的具体用法?C# SparseMatrix怎么用?C# SparseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SparseMatrix类属于MathNet.Numerics.LinearAlgebra.Complex命名空间,在下文中一共展示了SparseMatrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            var input = new DenseVector(3);

            var solver = new TFQMR();
            Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:TFQMRTest.cs


示例2: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            var input = new DenseVector(3);

            var solver = new BiCgStab();
            Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
        }
开发者ID:jafffy,项目名称:mathnet-numerics,代码行数:8,代码来源:BiCgStabTest.cs


示例3: SolveWideMatrixThrowsArgumentException

        public void SolveWideMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(2, 3);
            var input = new DenseVector(2);

            var solver = new TFQMR();
            Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:TFQMRTest.cs


示例4: SolveWideMatrixThrowsArgumentException

        public void SolveWideMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(2, 3);
            var input = new DenseVector(2);

            var solver = new GpBiCg();
            Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:GpBiCgTest.cs


示例5: CheckResult

        /// <summary>
        /// Check the result.
        /// </summary>
        /// <param name="preconditioner">Specific preconditioner.</param>
        /// <param name="matrix">Source matrix.</param>
        /// <param name="vector">Initial vector.</param>
        /// <param name="result">Result vector.</param>
        protected override void CheckResult(IPreconditioner<Complex> preconditioner, SparseMatrix matrix, Vector<Complex> vector, Vector<Complex> result)
        {
            Assert.AreEqual(typeof(UnitPreconditioner<Complex>), preconditioner.GetType(), "#01");

            // Unit preconditioner is doing nothing. Vector and result should be equal
            for (var i = 0; i < vector.Count; i++)
            {
                Assert.IsTrue(vector[i] == result[i], "#02-" + i);
            }
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:17,代码来源:UnitPreconditionerTest.cs


示例6: CreateUnitMatrix

        /// <summary>
        /// Create unit matrix.
        /// </summary>
        /// <param name="size">Matrix size.</param>
        /// <returns>New unit matrix.</returns>
        internal SparseMatrix CreateUnitMatrix(int size)
        {
            var matrix = new SparseMatrix(size);
            for (var i = 0; i < size; i++)
            {
                matrix[i, i] = 2;
            }

            return matrix;
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:15,代码来源:PreConditionerTest.cs


示例7: CheckResult

        /// <summary>
        /// Check the result.
        /// </summary>
        /// <param name="preconditioner">Specific preconditioner.</param>
        /// <param name="matrix">Source matrix.</param>
        /// <param name="vector">Initial vector.</param>
        /// <param name="result">Result vector.</param>
        protected override void CheckResult(IPreconditioner<Complex> preconditioner, SparseMatrix matrix, Vector<Complex> vector, Vector<Complex> result)
        {
            Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01");

            // Compute M * result = product
            // compare vector and product. Should be equal
            var product = new DenseVector(result.Count);
            matrix.Multiply(result, product);

            for (var i = 0; i < product.Count; i++)
            {
                Assert.IsTrue(vector[i].Real.AlmostEqual(product[i].Real, -Epsilon.Magnitude()), "#02-" + i);
                Assert.IsTrue(vector[i].Imaginary.AlmostEqual(product[i].Imaginary, -Epsilon.Magnitude()), "#03-" + i);
            }
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:22,代码来源:DiagonalTest.cs


示例8: CanAddSparseMatricesBothWays

        public void CanAddSparseMatricesBothWays()
        {
            var m1 = new SparseMatrix(1, 3);
            var m2 = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            var sum1 = m1 + m2;
            var sum2 = m2 + m1;
            Assert.IsTrue(sum1.Equals(m2));
            Assert.IsTrue(sum1.Equals(sum2));

            var sparseResult = new SparseMatrix(1, 3);
            sparseResult.Add(m2, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            sparseResult.Add(m1, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            m1.Add(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            sparseResult.Add(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(2*sum1));

            var denseResult = new DenseMatrix(1, 3);
            denseResult.Add(m2, denseResult);
            Assert.IsTrue(denseResult.Equals(sum1));

            denseResult = DenseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            denseResult.Add(m1, denseResult);
            Assert.IsTrue(denseResult.Equals(sum1));

            var m3 = DenseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            var sum3 = m1 + m3;
            var sum4 = m3 + m1;
            Assert.IsTrue(sum3.Equals(m3));
            Assert.IsTrue(sum3.Equals(sum4));
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseMatrixTests.cs


示例9: ToRowMatrix

        /// <summary>
        /// Create a matrix based on this vector in row form (one single row).
        /// </summary>
        /// <returns>This vector as a row matrix.</returns>
        public override Matrix<Complex> ToRowMatrix()
        {
            var matrix = new SparseMatrix(1, Count);
            for (var i = 0; i < NonZerosCount; i++)
            {
                matrix.At(0, _nonZeroIndices[i], _nonZeroValues[i]);
            }

            return matrix;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:14,代码来源:SparseVector.cs


示例10: ToColumnMatrix

        /// <summary>
        /// Create a matrix based on this vector in column form (one single column).
        /// </summary>
        /// <returns>This vector as a column matrix.</returns>
        public override Matrix<Complex> ToColumnMatrix()
        {
            var matrix = new SparseMatrix(Count, 1);
            for (var i = 0; i < NonZerosCount; i++)
            {
                matrix.At(_nonZeroIndices[i], 0, _nonZeroValues[i]);
            }

            return matrix;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:14,代码来源:SparseVector.cs


示例11: OfDiagonalArray

 /// <summary>
 /// Create a new sparse matrix with the diagonal as a copy of the given array.
 /// This new matrix will be independent from the array.
 /// A new memory block will be allocated for storing the matrix.
 /// </summary>
 public static SparseMatrix OfDiagonalArray(int rows, int columns, Complex[] diagonal)
 {
     var m = new SparseMatrix(rows, columns);
     m.SetDiagonal(diagonal);
     return m;
 }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:11,代码来源:SparseMatrix.cs


示例12: OfDiagonalVector

 /// <summary>
 /// Create a new sparse matrix with the diagonal as a copy of the given vector.
 /// This new matrix will be independent from the vector.
 /// A new memory block will be allocated for storing the matrix.
 /// </summary>
 public static SparseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex> diagonal)
 {
     var m = new SparseMatrix(rows, columns);
     m.SetDiagonal(diagonal);
     return m;
 }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:11,代码来源:SparseMatrix.cs


示例13: CanMultiplyMatrixWithMatrixIntoResult

        /// <summary>
        /// Can multiply a matrix with matrix.
        /// </summary>
        /// <param name="nameA">Matrix A name.</param>
        /// <param name="nameB">Matrix B name.</param>
        public override void CanMultiplyMatrixWithMatrixIntoResult(string nameA, string nameB)
        {
            var matrixA = TestMatrices[nameA];
            var matrixB = TestMatrices[nameB];
            var matrixC = new SparseMatrix(matrixA.RowCount, matrixB.ColumnCount);
            matrixA.Multiply(matrixB, matrixC);

            Assert.AreEqual(matrixC.RowCount, matrixA.RowCount);
            Assert.AreEqual(matrixC.ColumnCount, matrixB.ColumnCount);

            for (var i = 0; i < matrixC.RowCount; i++)
            {
                for (var j = 0; j < matrixC.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(matrixA.Row(i)*matrixB.Column(j), matrixC[i, j], 15);
                }
            }
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:23,代码来源:DiagonalMatrixTests.cs


示例14: CanSubtractSparseMatricesBothWays

        public void CanSubtractSparseMatricesBothWays()
        {
            var m1 = new SparseMatrix(1, 3);
            var m2 = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            var diff1 = m1 - m2;
            var diff2 = m2 - m1;
            Assert.IsTrue(diff1.Equals(m2.Negate()));
            Assert.IsTrue(diff1.Equals(diff2.Negate()));

            var sparseResult = new SparseMatrix(1, 3);
            sparseResult.Subtract(m2, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff1));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            sparseResult.Subtract(m1, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff2));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            m1.Subtract(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff1));

            sparseResult = SparseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            sparseResult.Subtract(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(0*diff1));

            var denseResult = new DenseMatrix(1, 3);
            denseResult.Subtract(m2, denseResult);
            Assert.IsTrue(denseResult.Equals(diff1));

            denseResult = DenseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            denseResult.Subtract(m1, denseResult);
            Assert.IsTrue(denseResult.Equals(diff2));

            var m3 = DenseMatrix.OfArray(new Complex[,] {{0, 1, 1}});
            var diff3 = m1 - m3;
            var diff4 = m3 - m1;
            Assert.IsTrue(diff3.Equals(m3.Negate()));
            Assert.IsTrue(diff3.Equals(diff4.Negate()));
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseMatrixTests.cs


示例15: CanCreateLargeMatrix

 public void CanCreateLargeMatrix()
 {
     const int Order = 1000000;
     var matrix = new SparseMatrix(Order);
     Assert.AreEqual(Order, matrix.RowCount);
     Assert.AreEqual(Order, matrix.ColumnCount);
     Assert.DoesNotThrow(() => matrix[0, 0] = 1);
 }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源:SparseMatrixTests.cs


示例16: CanCreateLargeSparseMatrix

        public void CanCreateLargeSparseMatrix()
        {
            var matrix = new SparseMatrix(500, 1000);
            var nonzero = 0;
            var rnd = new System.Random(0);

            for (var i = 0; i < matrix.RowCount; i++)
            {
                for (var j = 0; j < matrix.ColumnCount; j++)
                {
                    var value = rnd.Next(10)*rnd.Next(10)*rnd.Next(10)*rnd.Next(10)*rnd.Next(10);
                    if (value != 0)
                    {
                        nonzero++;
                    }

                    matrix[i, j] = value;
                }
            }

            Assert.AreEqual(matrix.NonZerosCount, nonzero);
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:22,代码来源:SparseMatrixTests.cs


示例17: ToRowMatrix

        /// <summary>
        /// Create a matrix based on this vector in row form (one single row).
        /// </summary>
        /// <returns>This vector as a row matrix.</returns>
        public override Matrix<Complex> ToRowMatrix()
        {
            var matrix = new SparseMatrix(1, Count);
            for (var i = 0; i < _storage.ValueCount; i++)
            {
                matrix.At(0, _storage.Indices[i], _storage.Values[i]);
            }

            return matrix;
        }
开发者ID:cdrnet,项目名称:mathnet-numerics-native,代码行数:14,代码来源:SparseVector.cs


示例18: ToColumnMatrix

        /// <summary>
        /// Create a matrix based on this vector in column form (one single column).
        /// </summary>
        /// <returns>This vector as a column matrix.</returns>
        public override Matrix<Complex> ToColumnMatrix()
        {
            var matrix = new SparseMatrix(Count, 1);
            for (var i = 0; i < _storage.ValueCount; i++)
            {
                matrix.At(_storage.Indices[i], 0, _storage.Values[i]);
            }

            return matrix;
        }
开发者ID:cdrnet,项目名称:mathnet-numerics-native,代码行数:14,代码来源:SparseVector.cs


示例19: OuterProduct

        /// <summary>
        /// Outer product of two vectors
        /// </summary>
        /// <param name="u">First vector</param>
        /// <param name="v">Second vector</param>
        /// <returns>Matrix M[i,j] = u[i]*v[j] </returns>
        /// <exception cref="ArgumentNullException">If the u vector is <see langword="null" />.</exception> 
        /// <exception cref="ArgumentNullException">If the v vector is <see langword="null" />.</exception> 
        public static Matrix<Complex> OuterProduct(SparseVector u, SparseVector v)
        {
            if (u == null)
            {
                throw new ArgumentNullException("u");
            }

            if (v == null)
            {
                throw new ArgumentNullException("v");
            }

            var matrix = new SparseMatrix(u.Count, v.Count);
            for (var i = 0; i < u.NonZerosCount; i++)
            {
                for (var j = 0; j < v.NonZerosCount; j++)
                {
                    if (u._nonZeroIndices[i] == v._nonZeroIndices[j])
                    {
                        matrix.At(i, j, u._nonZeroValues[i] * v._nonZeroValues[j]);
                    }
                }
            }

            return matrix;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:34,代码来源:SparseVector.cs


示例20: Transpose

        /// <summary>
        /// Returns the transpose of this matrix.
        /// </summary>        
        /// <returns>The transpose of this matrix.</returns>
        public override Matrix<Complex> Transpose()
        {
            var ret = new SparseMatrix(ColumnCount, RowCount)
            {
                _columnIndices = new int[NonZerosCount],
                _nonZeroValues = new Complex[NonZerosCount]
            };

            // Do an 'inverse' CopyTo iterate over the rows
            for (var i = 0; i < _rowIndex.Length; i++)
            {
                // Get the begin / end index for the current row
                var startIndex = _rowIndex[i];
                var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;

                // Get the values for the current row
                if (startIndex == endIndex)
                {
                    // Begin and end are equal. There are no values in the row, Move to the next row
                    continue;
                }

                for (var j = startIndex; j < endIndex; j++)
                {
                    ret.SetValueAt(_columnIndices[j], i, _nonZeroValues[j]);
                }
            }

            return ret;
        }
开发者ID:nyurik,项目名称:mathnet-numerics,代码行数:34,代码来源:SparseMatrix.cs



注:本文中的MathNet.Numerics.LinearAlgebra.Complex.SparseMatrix类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Complex.SparseVector类代码示例发布时间:2022-05-26
下一篇:
C# Complex.DenseVector类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap