For TensorPrimitives.IndexOfMax<T> where the number of elements is larger that the largest value T can represent and can be vectorized, the incorrect index of can be calculated.
Consider the following example
usingSystem;usingSystem.Numerics.Tensors;byte[]data=newbyte[(int)byte.MaxValue+3];data[(int)byte.MaxValue+2]=255;intresult=TensorPrimitives.IndexOfMax(data);Console.WriteLine(result);
This will print "1". ((255 + 2) % 256).
Another example, using a signed short
usingSystem;usingSystem.Numerics.Tensors;short[]data=newshort[(int)short.MaxValue+3];data[(int)short.MaxValue+2]=255;intresult=TensorPrimitives.IndexOfMax(data);Console.WriteLine(result);
This will print -32767.
This likely affects IndexOfMin, IndexOfMaxMagnitude, and IndexOfMinMagnitude since they share IndexOfMinMaxCore.
This also only impacts vectorized code paths. When .NET is forced to using scalar code paths using DOTNET_EnableHWIntrinsic=0, then the outputs are 257 and 32769, respectively.
For
TensorPrimitives.IndexOfMax<T>where the number of elements is larger that the largest valueTcan represent and can be vectorized, the incorrect index of can be calculated.Consider the following example
This will print "1". (
(255 + 2) % 256).Another example, using a signed
shortThis will print
-32767.This likely affects
IndexOfMin,IndexOfMaxMagnitude, andIndexOfMinMagnitudesince they shareIndexOfMinMaxCore.This also only impacts vectorized code paths. When .NET is forced to using scalar code paths using
DOTNET_EnableHWIntrinsic=0, then the outputs are257and32769, respectively.