ghord
ghord

Reputation: 13817

Vector.Dot not working correctly

I'm trying to use System.Numeric.Vectors nuget package (version 4.4.0), but following code does not work as expected:

static void Main(string[] args)
{
    var cnt = Vector<int>.Count;

    var arr = new int[] { 42, 42, 42, 42 };
    var arr2 = new int[] { 1, 1, 1, 1 };

    var vec = new Vector<int>(arr, 0);
    var vec2 = new Vector<int>(arr2, 0);

    var result = Vector.Dot(vec, vec2);

    if (result != 168)
        throw new Exception($"Expected 168 actual {result} (cnt: {cnt}, acc:{Vector.IsHardwareAccelerated})");
}

Code throws exception on x64 Release .NET 4.7 build with message: Expected 168 actual -458674576 (cnt: 4, acc:True).

All other builds where Vector is not hardware accelerated give correct results.

Is this bug in RyuJIT or am I doing something wrong?


EDIT

After replacing int with float, code is giving correct result. Is this code not working with int expected result?

Upvotes: 1

Views: 204

Answers (0)

Related Questions