public unsafe void DotProductPointer() { int size = 101; float[] v1 = new float[size]; float[] v2 = new float[size]; for (int i = 0; i < size; i++) { v1[i] = v2[i] = i; fixed(float *ptr = v1, ptr2 = v2) { double res = VectorizationFloat.DotProductFMA(ptr, ptr2, size); double res2 = 0; for (int i = 0; i < size; i++) { res2 += v1[i] * v2[i]; } Assert.AreEqual(res, res2); } }
public void DotProduct() { int size = 101; float[] v1 = new float[size]; float[] v2 = new float[size]; for (int i = 0; i < size; i++) { v1[i] = v2[i] = i; } double res = VectorizationFloat.DotProductFMA(v1, v2, size); double res2 = 0; for (int i = 0; i < size; i++) { res2 += v1[i] * v2[i]; } Assert.AreEqual(res, res2); }