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

C# Numerics.Vector类代码示例

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

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



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

示例1: HWAcceleratedGetStats

 internal static void HWAcceleratedGetStats(ushort[] input, out ushort min, out ushort max, out double average)
 {
     var simdLength = Vector<ushort>.Count;
     var vmin = new Vector<ushort>(ushort.MaxValue);
     var vmax = new Vector<ushort>(ushort.MinValue);
     var i = 0;
     ulong total = 0;
     var lastSafeVectorIndex = input.Length - simdLength;
     for (i = 0; i < lastSafeVectorIndex; i += simdLength) {
         total += input[i];
         total += input[i + 1];
         total += input[i + 2];
         total += input[i + 3];
         total += input[i + 4];
         total += input[i + 5];
         total += input[i + 6];
         total += input[i + 7];
         var vector = new Vector<ushort>(input, i);
         vmin = Vector.Min(vector, vmin);
         vmax = Vector.Max(vector, vmax);
     }
     min = ushort.MaxValue;
     max = ushort.MinValue;
     for (var j = 0; j < simdLength; ++j) {
         min = Math.Min(min, vmin[j]);
         max = Math.Max(max, vmax[j]);
     }
     for (; i < input.Length; ++i) {
         min = Math.Min(min, input[i]);
         max = Math.Max(max, input[i]);
         total += input[i];
     }
     average = total / (double)input.Length;
 }
开发者ID:eoinmullan,项目名称:SimdSpike,代码行数:34,代码来源:UShortSimdProcessor.cs


示例2: lms

            public Vector<double> lms(Vector<double> signal, Vector<double> filtered_signal, int window_size)
            {
                int signal_size = signal.Count;

                double mi = 0.07; //Współczynnik szybkości adaptacji

                Vector<double> coeff = Vector<double>.Build.Dense(window_size, 0); //Wektor z wagami filtru
                Vector<double> bufor = Vector<double>.Build.Dense(window_size, 0); //Inicjalizacja bufora sygnału wejściowego
                Vector<double> out_signal = Vector<double>.Build.Dense(signal_size, 0);

                double dest;
                double err;

                for(int i = 0; i<signal_size; i++)
                {

                    bufor.CopySubVectorTo(bufor, 0, 1, window_size - 1);
                    bufor[0] = signal[i];

                    dest = coeff * bufor;
                    err = filtered_signal[i] - dest;

                    coeff.Add(2 * mi * err * bufor,coeff);

                    //coeff = coeff + (2 * mi * err * bufor);

                    out_signal[i] = dest;

                }

                return out_signal;
            }
开发者ID:Nefarin,项目名称:DadmProject,代码行数:32,代码来源:ECG_Baseline_Alg.cs


示例3: Ray4

        public Ray4( Ray[] rays )
        {
            int l = rays.Length;
        
            float[] ox4 = new float[l], oy4 = new float[l], oz4 = new float[l];
            float[] dx4 = new float[l], dy4 = new float[l], dz4 = new float[l];
            float[] t = new float[l];
            float[] nx4 = new float[l], ny4 = new float[l], nz4 = new float[l];
            int[] objIdx = new int[l];
            int[] inside = new int[l];
        
            for (int i = 0; i < rays.Length; i++)
            {
                ox4[i] = rays[i].O.X; oy4[i] = rays[i].O.Y; oz4[i] = rays[i].O.Z;
                dx4[i] = rays[i].D.X; dy4[i] = rays[i].D.Y; dz4[i] = rays[i].D.Z;
                t[i] = rays[i].t;
                nx4[i] = rays[i].N.X; ny4[i] = rays[i].N.Y; nz4[i] = rays[i].N.Z;
                objIdx[i] = rays[i].objIdx;
                inside[i] = rays[i].inside ? 1 : 0;
            }

            Ox4 = new Vector<float>(ox4); Oy4 = new Vector<float>(oy4); Oz4 = new Vector<float>(oz4);
            Dx4 = new Vector<float>(dx4); Dy4 = new Vector<float>(dy4); Dz4 = new Vector<float>(dz4);
            t4 = new Vector<float>(t);
            Nx4 = new Vector<float>(nx4); Ny4 = new Vector<float>(ny4); Nz4 = new Vector<float>(nz4);
            objIdx4 = new Vector<int>(objIdx);
            inside4 = new Vector<int>(inside);
            returnMask = new Vector<int>(0);
        }
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum3,代码行数:29,代码来源:ray.cs


示例4: Main

 static int Main(string[] args)
 {
     {
         var a = new Vector<uint>(1000000);
         var b = new Vector<uint>(0);
         var c = new Vector<uint>(1);
         var d = b - c;
         var e = d / a;
         if (e[0] != 4294)
         {
             return 0;
         }
     }
     {
         var a = new Vector<int>(1000000);
         var b = new Vector<int>(0);
         var c = new Vector<int>(1);
         var d = b - c;
         var e = d / a;
         if (e[0] != 0)
         {
             return 0;
         }
     }
     return 100;
 }
开发者ID:l1183479157,项目名称:coreclr,代码行数:26,代码来源:DivSignedUnsignedTest.cs


示例5: ContainsPossibly

        public static bool ContainsPossibly(byte[] buffer, int index, int end, ref Vector<byte> value)
        {
            if (!Vector.IsHardwareAccelerated || index + Vector<byte>.Count >= end || index + Vector<byte>.Count >= buffer.Length)
                return true;

            return !Vector.Equals(new Vector<byte>(buffer, index), value).Equals(Vector<byte>.Zero);
        }
开发者ID:evest,项目名称:Netling,代码行数:7,代码来源:ByteHelpers.cs


示例6: VectorizedSceneUpdateNodesTests

        public VectorizedSceneUpdateNodesTests()
        {
            Width = 20;
            Height = 20;
            Length = 1f;

            Grid = new PackedHexagonalGrid(Width, Height, Padding, Length);
            NodesX = Grid.VerticesX.ToArray();
            NodesY = Grid.VerticesY.ToArray();

            var random = new Random();
            Func<float> randomFloat = () => (float)random.NextDouble();

            VelocitiesX = Enumerable.Range(0, NodesX.Length).Select(_ => randomFloat()).ToArray();
            VelocitiesY = Enumerable.Range(0, NodesY.Length).Select(_ => randomFloat()).ToArray();

            const float dt = 0.01f;
            Dt = new Vector<float>(dt);

            UpdateNodesReferenceImplementation(dt, NodesX, NodesY, VelocitiesX, VelocitiesY);
            ReferenceNodesX = NodesX.ToArray();
            ReferenceNodesY = NodesY.ToArray();

            RestoreNodes();

            JitMethods();
        }
开发者ID:Jorenkv,项目名称:Tearing,代码行数:27,代码来源:VectorizedSceneUpdateNodesTests.cs


示例7: Plane

	public Plane( Vector3 ABC, float D )
	{
		Nx = new Vector<float>(ABC.X);
        Ny = new Vector<float>(ABC.Y);
        Nz = new Vector<float>(ABC.Z);
        d = new Vector<float>(D);
	}
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum3,代码行数:7,代码来源:geometry.cs


示例8: Approximate

        /// <summary>
        /// Approximates the solution to the matrix equation <b>Ax = b</b>.
        /// </summary>
        /// <param name="rhs">The right hand side vector.</param>
        /// <param name="lhs">The left hand side vector. Also known as the result vector.</param>
        public void Approximate(Vector rhs, Vector lhs)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException("rhs");
            }

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

            if (_inverseDiagonals == null)
            {
                throw new ArgumentException(Resources.ArgumentMatrixDoesNotExist);
            }

            if ((lhs.Count != rhs.Count) || (lhs.Count != _inverseDiagonals.Length))
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength, "rhs");
            }

            for (var i = 0; i < _inverseDiagonals.Length; i++)
            {
                lhs[i] = rhs[i] * _inverseDiagonals[i];
            }
        }
开发者ID:KeithVanderzanden,项目名称:mmbot,代码行数:32,代码来源:Diagonal.cs


示例9: Multiply_SIMD_2

        public static double[] Multiply_SIMD_2(Matrix A, Matrix B)
        {
            // Abour 50% fateser when matrix size >= 8x8

            var vecSize = Vector<double>.Count;
            var bRemainer = B.Columns % Vector<double>.Count;
            if (B.Columns % Vector<double>.Count != 0)
            {
                B.AddColumns(bRemainer);
            }

            var C = new double[A.Rows * B.Columns];

            for (int i = 0; i < A.Rows; i++)
            {
                for (int k = 0; k < A.Columns; k++)
                {
                    for (int j = 0; j < B.Columns; j += vecSize)
                    {
                        var vC = new Vector<double>(C, i * A.Rows + j);
                        var vB = new Vector<double>(B.internalArray, k * B.Columns + j);
                        var vA = new Vector<double>(A.internalArray[i * A.Columns + k]);
                        vC += vA * vB;
                        vC.CopyTo(C, i * A.Rows + j);
                    }
                }
            }

            return C.ToArray();
        }
开发者ID:MathFerret1013,项目名称:Linear-Algebra,代码行数:30,代码来源:Class1.cs


示例10: DenseVector

 /// <summary>
 /// Initializes a new instance of the <see cref="DenseVector"/> class by
 /// copying the values from another.
 /// </summary>
 /// <param name="other">
 /// The vector to create the new vector from.
 /// </param>
 public DenseVector(Vector<Complex> other) : this(other.Count)
 {
         CommonParallel.For(
             0, 
             Data.Length, 
             index => this[index] = other[index]);
 }
开发者ID:bstrausser,项目名称:mathnet-numerics,代码行数:14,代码来源:DenseVector.cs


示例11: SeekWorksAcrossBlocks

        public void SeekWorksAcrossBlocks()
        {
            Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}");
            Console.WriteLine($"Vector<byte>.Count == {Vector<byte>.Count}");

            using (var pool = new MemoryPool2())
            {
                var block1 = pool.Lease(256);
                var block2 = block1.Next = pool.Lease(256);
                var block3 = block2.Next = pool.Lease(256);

                foreach (var ch in Enumerable.Range(0, 34).Select(x => (byte)x))
                {
                    block1.Array[block1.End++] = ch;
                }
                foreach (var ch in Enumerable.Range(34, 25).Select(x => (byte)x))
                {
                    block2.Array[block2.End++] = ch;
                }
                foreach (var ch in Enumerable.Range(59, 197).Select(x => (byte)x))
                {
                    block3.Array[block3.End++] = ch;
                }

                var vectorMaxValues = new Vector<byte>(byte.MaxValue);

                var iterator = block1.GetIterator();
                foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
                {
                    var vectorCh = new Vector<byte>(ch);

                    var hit = iterator;
                    hit.Seek(ref vectorCh);
                    Assert.Equal(ch, iterator.GetLength(hit));

                    hit = iterator;
                    hit.Seek(ref vectorCh, ref vectorMaxValues);
                    Assert.Equal(ch, iterator.GetLength(hit));

                    hit = iterator;
                    hit.Seek(ref vectorMaxValues, ref vectorCh);
                    Assert.Equal(ch, iterator.GetLength(hit));

                    hit = iterator;
                    hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues);
                    Assert.Equal(ch, iterator.GetLength(hit));

                    hit = iterator;
                    hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues);
                    Assert.Equal(ch, iterator.GetLength(hit));

                    hit = iterator;
                    hit.Seek(ref vectorMaxValues, ref vectorMaxValues, ref vectorCh);
                    Assert.Equal(ch, iterator.GetLength(hit));
                }
            }
        }
开发者ID:leloulight,项目名称:KestrelHttpServer,代码行数:57,代码来源:MemoryPoolBlock2Tests.cs


示例12: ConvertToString

        public static string ConvertToString(BigInteger n, bool escape, int radix)
        {
            if (radix == -1)
            {
                radix = (int)Runtime.GetDynamic(Symbols.PrintBase);
            }

            if (radix == -1)
            {
                radix = 10;
            }
            else if (radix < 2 || radix > 36)
            {
                throw new LispException("Invalid number base: {0}", radix);
            }

            if (n == 0)
            {
                return "0";
            }

            var sign = (n >= 0) ? "" : "-";
            n = (n >= 0) ? n : -n;
            var stk = new Vector();
            while (n != 0)
            {
                var d = (int)(n % radix);
                if (d <= 9)
                {
                    stk.Add((char)(d + '0'));
                }
                else {
                    stk.Add((char)(d - 10 + 'a'));
                }
                n = n / radix;
            }
            stk.Reverse();
            if (escape)
            {
                switch (radix)
                {
                    case 10:
                        return sign + Runtime.MakeString(stk.ToArray());
                    case 16:
                        return sign + "0x" + Runtime.MakeString(stk.ToArray());
                    case 8:
                        return sign + "0" + Runtime.MakeString(stk.ToArray());
                    case 2:
                        return "#b" + sign + Runtime.MakeString(stk.ToArray());
                    default:
                        return "#" + radix + "r" + sign + Runtime.MakeString(stk.ToArray());
                }
            }
            else {
                return sign + Runtime.MakeString(stk.ToArray());
            }
        }
开发者ID:jantolenaar,项目名称:kiezellisp,代码行数:57,代码来源:number.cs


示例13: BoundingBoxWide

 public unsafe BoundingBoxWide(BoundingBox* boundingBoxes, Vector<int>[] masks)
 {
     Min = new Vector3Wide(ref boundingBoxes[0].Min);
     Max = new Vector3Wide(ref boundingBoxes[0].Max);
     for (int i = 1; i < Vector<float>.Count; ++i)
     {
         BoundingBoxWide wide = new BoundingBoxWide(ref boundingBoxes[i]);
         ConditionalSelect(ref masks[i], ref wide, ref this, out this);
     }
 }
开发者ID:RossNordby,项目名称:scratchpad,代码行数:10,代码来源:BoundingBox.cs


示例14: CheckResult

        protected override void CheckResult(IPreConditioner<Complex> preconditioner, SparseMatrix matrix, Vector<Complex> vector, Vector<Complex> result)
        {
            Assert.AreEqual(typeof(UnitPreconditioner), 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:xmap2008,项目名称:mathnet-numerics,代码行数:11,代码来源:UnitPreconditionerTest.cs


示例15: Cosine4

 static public Vector<float> Cosine4(Vector<float> alpha)
 {
     Vector<float> result = Vector<float>.One, lastTerm = Vector<float>.One;
     Vector<float> alpha2 = alpha * alpha;
     for (int i = 1; i < TERMS; i++)
     {
         lastTerm = Vector.Negate(lastTerm * alpha2);
         result += lastTerm / factorials[i * 2];
     }
     return result;
 }
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum3,代码行数:11,代码来源:rttools.cs


示例16: SumVector

 private static void SumVector(float[] a, float[] b, float[] c)
 {
     int N = c.Length;
     for (int i = 0; i < N; i += Vector<Single>.Count) // Count returns 16 for char, 4 for float, 2 for double.
     {
         var aSimd = new Vector<Single>(a, i); // create instance with offset i
         var bSimd = new Vector<Single>(b, i);
         Vector<Single> cSimd = aSimd + bSimd; // or Vector<Single> c_simd = Vector.Add(b_simd, a_simd);
         cSimd.CopyTo(c, i); //copy to array with offset
     }
 }
开发者ID:constructor-igor,项目名称:TechSugar,代码行数:11,代码来源:VectorSamples.cs


示例17: BandGetImpulseTests

 public BandGetImpulseTests()
 {
     int n = 20 * 20 * 3; // Must be a multiple of VectorizedScene.VectorSize (a multiple of 16 should be safe).
     NodesX1 = RandomFloats(n);
     NodesY1 = RandomFloats(n);
     NodesX2 = RandomFloats(n);
     NodesY2 = RandomFloats(n);
     RestLength = new Vector<float>(0.01f);
     Lambda = new Vector<float>(2);
     ImpulsesX = new float[n];
     ImpulsesY = new float[n];
 }
开发者ID:Jorenkv,项目名称:Tearing,代码行数:12,代码来源:BandGetImpulseTests.cs


示例18: HwAcceleratedSumUnchecked

 public static void HwAcceleratedSumUnchecked(ushort[] lhs, ushort[] rhs, ushort[] result)
 {
     var simdLength = Vector<ushort>.Count;
     var i = 0;
     for (i = 0; i < lhs.Length - simdLength; i += simdLength) {
         var va = new Vector<ushort>(lhs, i);
         var vb = new Vector<ushort>(rhs, i);
         (va + vb).CopyTo(result, i);
     }
     for (; i < lhs.Length; ++i) {
         result[i] = (ushort)(lhs[i] + rhs[i]);
     }
 }
开发者ID:eoinmullan,项目名称:SimdSpike,代码行数:13,代码来源:UShortSimdProcessor.cs


示例19: HeapSortDoublesIndices

        /// <summary>
        /// Sorts the elements of the <paramref name="values"/> vector in decreasing
        /// fashion using heap sort algorithm. The vector itself is not affected.
        /// </summary>
        /// <param name="lowerBound">The starting index.</param>
        /// <param name="upperBound">The stopping index.</param>
        /// <param name="sortedIndices">An array that will contain the sorted indices once the algorithm finishes.</param>
        /// <param name="values">The <see cref="Vector{T}"/> that contains the values that need to be sorted.</param>
        private static void HeapSortDoublesIndices(int lowerBound, int upperBound, int[] sortedIndices, Vector<Complex> values)
        {
            var start = ((upperBound - lowerBound + 1) / 2) - 1 + lowerBound;
            var end = (upperBound - lowerBound + 1) - 1 + lowerBound;

            BuildDoubleIndexHeap(start, upperBound - lowerBound + 1, sortedIndices, values);

            while (end >= lowerBound)
            {
                Exchange(sortedIndices, end, lowerBound);
                SiftDoubleIndices(sortedIndices, values, lowerBound, end);
                end -= 1;
            }
        }
开发者ID:hickford,项目名称:mathnet-numerics-native,代码行数:22,代码来源:IlutpElementSorter.cs


示例20: Foo

 static int Foo(Vector<int> vec)
 {
     int[] a = new int[5];
     // The index [5] is outside the bounds of array 'a',
     // so this should throw ArgumentOutOfRangeException.
     // There's a subsequent check for whether the destination
     // has enough space to receive the vector, which would
     // raise an ArgumentException; the bug was that assertion
     // prop was using the later exception check to prove the
     // prior one "redundant" because the commas confused the
     // ordering.
     vec.CopyTo(a, 5);
     return a[0];
 }
开发者ID:ReedCopsey,项目名称:coreclr,代码行数:14,代码来源:GitHub_6318.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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