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); }
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); }
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; }
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()); } }
public void AddToRow(ref float[] vec, int i) { SIMD.Add(ref Data[i], ref vec); }
public void AddToRow(ReadOnlySpan <float> vec, int i) { SIMD.Add(Data.AsSpan().Slice(i * Columns, Columns), vec); }
public void AddToRow(float[] vec, int i) { SIMD.Add(Data[i], vec); }