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

C# Complex32.SparseVector类代码示例

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

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



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

示例1: CreateVector

        /// <summary>
        /// Creates a new instance of the Vector class.
        /// </summary>
        /// <param name="data">The array to create this vector from.</param>
        /// <returns>The new <c>Vector</c>.</returns>
        protected override Vector<Complex32> CreateVector(IList<Complex32> data)
        {
            var vector = new SparseVector(data.Count);
            for (var index = 0; index < data.Count; index++)
            {
                vector[index] = data[index];
            }

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


示例2: TryParse

        /// <summary>
        /// Converts the string representation of a complex sparse vector to double-precision sparse vector equivalent.
        /// A return value indicates whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">
        /// A string containing a complex vector to convert.
        /// </param>
        /// <param name="formatProvider">
        /// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information about value.
        /// </param>
        /// <param name="result">
        /// The parsed value.
        /// </param>
        /// <returns>
        /// If the conversion succeeds, the result will contain a complex number equivalent to value.
        /// Otherwise the result will be <c>null</c>.
        /// </returns>
        public static bool TryParse(string value, IFormatProvider formatProvider, out SparseVector result)
        {
            bool ret;
            try
            {
                result = Parse(value, formatProvider);
                ret = true;
            }
            catch (ArgumentNullException)
            {
                result = null;
                ret = false;
            }
            catch (FormatException)
            {
                result = null;
                ret = false;
            }

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


示例3: OuterProduct

 /// <summary>
 /// Outer product of this and another vector.
 /// </summary>
 /// <param name="v">The vector to operate on.</param>
 /// <returns>
 /// Matrix M[i,j] = this[i] * v[j].
 /// </returns>
 public Matrix<Complex32> OuterProduct(SparseVector v)
 {
     return OuterProduct(this, v);
 }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:11,代码来源:SparseVector.cs


示例4: SubVector

        /// <summary>
        /// Creates a vector containing specified elements.
        /// </summary>
        /// <param name="index">The first element to begin copying from.</param>
        /// <param name="length">The number of elements to copy.</param>
        /// <returns>A vector containing a copy of the specified elements.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><list><item>If <paramref name="index"/> is not positive or
        /// greater than or equal to the size of the vector.</item>
        /// <item>If <paramref name="index"/> + <paramref name="length"/> is greater than or equal to the size of the vector.</item>
        /// </list></exception>
        /// <exception cref="ArgumentException">If <paramref name="length"/> is not positive.</exception>
        public override Vector<Complex32> SubVector(int index, int length)
        {
            if (index < 0 || index >= Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (length <= 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            if (index + length > Count)
            {
                throw new ArgumentOutOfRangeException("length");
            }

            var result = new SparseVector(length);
            for (var i = index; i < index + length; i++)
            {
                result.At(i - index, At(i));
            }

            return result;
        }
开发者ID:kevkon3,项目名称:mathnet-numerics,代码行数:36,代码来源:SparseVector.cs


示例5: Negate

        /// <summary>
        /// Returns a negated vector.
        /// </summary>
        /// <returns>The negated vector.</returns>
        /// <remarks>Added as an alternative to the unary negation operator.</remarks>
        public override Vector<Complex32> Negate()
        {
            var result = new SparseVector(Count)
                         {
                             _nonZeroValues = new Complex32[NonZerosCount],
                             _nonZeroIndices = new int[NonZerosCount],
                             NonZerosCount = NonZerosCount
                         };

            if (NonZerosCount != 0)
            {
                CommonParallel.For(
                    0,
                    NonZerosCount,
                    index => result._nonZeroValues[index] = -_nonZeroValues[index]);
                Buffer.BlockCopy(_nonZeroIndices, 0, result._nonZeroIndices, 0, NonZerosCount * Constants.SizeOfInt);
            }

            return result;
        }
开发者ID:kevkon3,项目名称:mathnet-numerics,代码行数:25,代码来源:SparseVector.cs


示例6: SparseVector

        /// <summary>
        /// Initializes a new instance of the <see cref="SparseVector"/> class by
        /// copying the values from another.
        /// </summary>
        /// <param name="other">
        /// The vector to create the new vector from.
        /// </param>
        public SparseVector(SparseVector other)
            : this(other.Count)
        {
            // Lets copy only needed data. Portion of needed data is determined by NonZerosCount value
            _nonZeroValues = new Complex32[other.NonZerosCount];
            _nonZeroIndices = new int[other.NonZerosCount];
            NonZerosCount = other.NonZerosCount;

            if (other.NonZerosCount != 0)
            {
                CommonParallel.For(0, other.NonZerosCount, index => _nonZeroValues[index] = other._nonZeroValues[index]);
                Buffer.BlockCopy(other._nonZeroIndices, 0, _nonZeroIndices, 0, other.NonZerosCount * Constants.SizeOfInt);
            }
        }
开发者ID:kevkon3,项目名称:mathnet-numerics,代码行数:21,代码来源:SparseVector.cs


示例7: CanCreateSparseMatrix

 public void CanCreateSparseMatrix()
 {
     var vector = new SparseVector(3);
     var matrix = Matrix<Complex32>.Build.SameAs(vector, 2, 3);
     Assert.IsInstanceOf<SparseMatrix>(matrix);
     Assert.AreEqual(2, matrix.RowCount);
     Assert.AreEqual(3, matrix.ColumnCount);
 }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:8,代码来源:SparseVectorTest.cs


示例8: CheckSparseMechanismByZeroMultiply

        public void CheckSparseMechanismByZeroMultiply()
        {
            var vector = new SparseVector(10000);

            // Add non-zero elements
            vector[200] = new Complex32(1.5f, 1);
            vector[500] = new Complex32(3.5f, 1);
            vector[800] = new Complex32(5.5f, 1);
            vector[0] = new Complex32(7.5f, 1);

            // Multiply by 0
            vector *= 0;

            var storage = (SparseVectorStorage<Complex32>) vector.Storage;
            Assert.AreEqual(Complex32.Zero, vector[200]);
            Assert.AreEqual(Complex32.Zero, vector[500]);
            Assert.AreEqual(Complex32.Zero, vector[800]);
            Assert.AreEqual(Complex32.Zero, vector[0]);
            Assert.AreEqual(0, storage.ValueCount);
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:20,代码来源:SparseVectorTest.cs


示例9: CheckSparseMechanismBySettingValues

        public void CheckSparseMechanismBySettingValues()
        {
            var vector = new SparseVector(10000);
            var storage = (SparseVectorStorage<Complex32>) vector.Storage;

            // Add non-zero elements
            vector[200] = new Complex32(1.5f, 1);
            Assert.AreEqual(new Complex32(1.5f, 1), vector[200]);
            Assert.AreEqual(1, storage.ValueCount);

            vector[500] = new Complex32(3.5f, 1);
            Assert.AreEqual(new Complex32(3.5f, 1), vector[500]);
            Assert.AreEqual(2, storage.ValueCount);

            vector[800] = new Complex32(5.5f, 1);
            Assert.AreEqual(new Complex32(5.5f, 1), vector[800]);
            Assert.AreEqual(3, storage.ValueCount);

            vector[0] = new Complex32(7.5f, 1);
            Assert.AreEqual(new Complex32(7.5f, 1), vector[0]);
            Assert.AreEqual(4, storage.ValueCount);

            // Remove non-zero elements
            vector[200] = Complex32.Zero;
            Assert.AreEqual(Complex32.Zero, vector[200]);
            Assert.AreEqual(3, storage.ValueCount);

            vector[500] = Complex32.Zero;
            Assert.AreEqual(Complex32.Zero, vector[500]);
            Assert.AreEqual(2, storage.ValueCount);

            vector[800] = Complex32.Zero;
            Assert.AreEqual(Complex32.Zero, vector[800]);
            Assert.AreEqual(1, storage.ValueCount);

            vector[0] = Complex32.Zero;
            Assert.AreEqual(Complex32.Zero, vector[0]);
            Assert.AreEqual(0, storage.ValueCount);
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseVectorTest.cs


示例10: CanScaleAVectorWhenSettingPreviousNonzeroElementsToZero

        public void CanScaleAVectorWhenSettingPreviousNonzeroElementsToZero()
        {
            var vector = new SparseVector(20);
            vector[10] = 1.0f;
            vector[11] = 2.0f;
            vector[11] = 0.0f;

            var scaled = new SparseVector(20);
            vector.Multiply(3.0f, scaled);

            Assert.AreEqual(3.0f, scaled[10].Real);
            Assert.AreEqual(0.0f, scaled[11].Real);
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:13,代码来源:SparseVectorTest.cs


示例11: CanPointwiseMultiplySparseVector

        public void CanPointwiseMultiplySparseVector()
        {
            var zeroArray = new[] {Complex32.Zero, new Complex32(1.0f, 1), Complex32.Zero, new Complex32(1.0f, 1), Complex32.Zero};
            var vector1 = SparseVector.OfEnumerable(Data);
            var vector2 = SparseVector.OfEnumerable(zeroArray);
            var result = new SparseVector(vector1.Count);

            vector1.PointwiseMultiply(vector2, result);

            for (var i = 0; i < vector1.Count; i++)
            {
                Assert.AreEqual(Data[i]*zeroArray[i], result[i]);
            }

            var resultStorage = (SparseVectorStorage<Complex32>) result.Storage;
            Assert.AreEqual(2, resultStorage.ValueCount);
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:17,代码来源:SparseVectorTest.cs


示例12: CanDotProductOfTwoSparseVectors

        public void CanDotProductOfTwoSparseVectors()
        {
            var vectorA = new SparseVector(10000);
            vectorA[200] = 1;
            vectorA[500] = 3;
            vectorA[800] = 5;
            vectorA[100] = 7;
            vectorA[900] = 9;

            var vectorB = new SparseVector(10000);
            vectorB[300] = 3;
            vectorB[500] = 5;
            vectorB[800] = 7;

            Assert.AreEqual(new Complex32(50.0f, 0), vectorA.DotProduct(vectorB));
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:16,代码来源:SparseVectorTest.cs


示例13: Multiply

        /// <summary>
        /// Multiplies a scalar to each element of the vector.
        /// </summary>
        /// <param name="scalar">The scalar to multiply.</param>
        /// <returns>A new vector that is the multiplication of the vector and the scalar.</returns>
        public override Vector<Complex32> Multiply(Complex32 scalar)
        {
            if (scalar == Complex32.One)
            {
                return Clone();
            }

            if (scalar == Complex32.Zero)
            {
                return new SparseVector(Count);
            }

            var copy = new SparseVector(this);
            Control.LinearAlgebraProvider.ScaleArray(scalar, copy._nonZeroValues, copy._nonZeroValues);
            return copy;
        }
开发者ID:Huddle,项目名称:mathnet-numerics,代码行数:21,代码来源:SparseVector.cs


示例14: CanCreateSparseMatrix

 public void CanCreateSparseMatrix()
 {
     var vector = new SparseVector(3);
     var matrix = vector.CreateMatrix(2, 3);
     Assert.AreEqual(2, matrix.RowCount);
     Assert.AreEqual(3, matrix.ColumnCount);
 }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:7,代码来源:SparseVectorTest.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Solvers.Iterator类代码示例发布时间:2022-05-26
下一篇:
C# Complex32.SparseMatrix类代码示例发布时间: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