Beispiel #1
0
        public Matrix Uniform(float a)
        {
            float a2 = 2 * a;
            float an = -a;

            ThreadSafeFastRandom.NextFloats(Data.AsSpan());
            SIMD.Multiply(Data.AsSpan(), a2);
            SIMD.Add(Data.AsSpan(), an);

            return(this);
        }
Beispiel #2
0
        public Matrix Uniform(float a)
        {
            float a2 = 2 * a;
            float an = -a;

            Parallel.For(0, Rows, (i) =>
            {
                ThreadSafeFastRandom.NextFloats(Data[i]);
                SIMD.Multiply(ref Data[i], a2);
                SIMD.Add(ref Data[i], an);
            });
            return(this);
        }
Beispiel #3
0
        public void ResizeAndFillRows(int newRows, float a)
        {
            float a2 = 2 * a;
            float an = -a;

            Array.Resize(ref Data, newRows * Columns);
            var toFill = Data.AsSpan().Slice(Rows * Columns);

            ThreadSafeFastRandom.NextFloats(toFill);
            SIMD.Multiply(toFill, a2);
            SIMD.Add(toFill, an);

            Rows = newRows;
        }
Beispiel #4
0
        public unsafe void Can_Add_Scalar_To_Vector()
        {
            var mem = Marshal.AllocHGlobal(16 * sizeof(float));
            var ptr = (float *)mem.ToPointer();

            for (var i = 0; i < 8; ++i)
            {
                *ptr++ = i;
            }

            SIMD.Add((ptr - 8), 10, ptr, 8);
            for (var i = 0; i < 8; ++i)
            {
                Assert.AreEqual((i + 10.0f).ToString(), (*ptr++).ToString());
            }
        }
Beispiel #5
0
 public void AddToRow(ref float[] vec, int i)
 {
     SIMD.Add(ref Data[i], ref vec);
 }
Beispiel #6
0
 public void AddToRow(ReadOnlySpan <float> vec, int i)
 {
     SIMD.Add(Data.AsSpan().Slice(i * Columns, Columns), vec);
 }
Beispiel #7
0
 public void AddToRow(float[] vec, int i)
 {
     SIMD.Add(Data[i], vec);
 }