当前位置: 首页>>代码示例>>C#>>正文


C# Complex.SparseVector类代码示例

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


SparseVector类属于MathNet.Numerics.LinearAlgebra.Complex命名空间,在下文中一共展示了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<Complex> CreateVector(IList<Complex> 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: 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<Complex> OuterProduct(SparseVector v)
 {
     return OuterProduct(this, v);
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:11,代码来源:SparseVector.cs

示例3: 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<Complex> 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:XiBeichuan,项目名称:hydronumerics,代码行数:36,代码来源:SparseVector.cs

示例4: 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<Complex> Negate()
        {
            var result = new SparseVector(Count)
                         {
                             _nonZeroValues = new Complex[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:XiBeichuan,项目名称:hydronumerics,代码行数:25,代码来源:SparseVector.cs

示例5: 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 Complex[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:XiBeichuan,项目名称:hydronumerics,代码行数:20,代码来源:SparseVector.cs

示例6: 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:XiBeichuan,项目名称:hydronumerics,代码行数:38,代码来源:SparseVector.cs

示例7: CanScaleAVectorWhenSettingPreviousNonzeroElementsToZero

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

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

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

示例8: 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 Complex(50.0, 0), vectorA.DotProduct(vectorB));
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:16,代码来源:SparseVectorTest.cs

示例9: CanPointwiseMultiplySparseVector

        public void CanPointwiseMultiplySparseVector()
        {
            var zeroArray = new[] {Complex.Zero, new Complex(1.0, 1), Complex.Zero, new Complex(1.0, 1), Complex.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<Complex>) result.Storage;
            Assert.AreEqual(2, resultStorage.ValueCount);
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:17,代码来源:SparseVectorTest.cs

示例10: CheckSparseMechanismByZeroMultiply

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

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

            // Multiply by 0
            vector *= 0;

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

示例11: CheckSparseMechanismBySettingValues

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

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

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

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

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

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

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

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

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

示例12: CanCreateSparseMatrix

 public void CanCreateSparseMatrix()
 {
     var vector = new SparseVector(3);
     var matrix = Matrix<Complex>.Build.SameAs(vector, 2, 3);
     Assert.IsInstanceOf<SparseMatrix>(matrix);
     Assert.AreEqual(2, matrix.RowCount);
     Assert.AreEqual(3, matrix.ColumnCount);
 }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源: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<Complex> Multiply(Complex scalar)
        {
            if (scalar == Complex.One)
            {
                return Clone();
            }

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

            var copy = new SparseVector(this);
            Control.LinearAlgebraProvider.ScaleArray(scalar, copy._storage.Values, copy._storage.Values);
            return copy;
        }
开发者ID:cdrnet,项目名称:mathnet-numerics-native,代码行数: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:EricGT,项目名称:mathnet-numerics,代码行数:7,代码来源:SparseVectorTest.cs


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