jackmott / LinqFaster

Linq-like extension functions for Arrays, Span<T>, and List<T> that are faster and allocate less.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] using SumS on a ushort[] throws System.InvalidCastException

Smurf-IV opened this issue · comments

Code:

                    ushort[] pRowArrayClip = samePool.Rent(countClip);
                    Array.Copy(pRowArrayFull, pRowArrayClip, countClip);
                    double average = pRowArrayClip.SumS();

Exception:

                   System.InvalidCastException : Specified cast is not valid.
                       at JM.LinqFaster.SIMD.LinqFasterSIMD.SumS[T](T[] source)
                       at #########

Should ushort not be supported

not sure, it looks like it should work, I'll investigate

ushort[].Sum() from normal linq does not appear to be supported (And also not in SumF)

What would the expected result be a Double ? Decimal ????

the result of a sum on ushort should be a ushort, the way it is currently implemented.

which, won't typically be useful!

probably why linq doesn't support it.

ok the problem is that a ushort + a ushort = an int32.
So, this could be supported if instead of using a generic sum method, we made one for each type, and ushort returned an int32 for the sum.

that's a bunch of grunt work though.

probably why linq doesn't support it.
So this should mean that this implementation not allow it to be used for ushort's, and not allow it to compile (As per linq)

ok the problem is that a ushort + a ushort = an int32.
So, this could be supported if instead of using a generic sum method, we made one for each type, and ushort returned an int32 for the sum.

that's a bunch of grunt work though.

Work done in the pending #20

Convert SumF function into a generic function
Add new managed types (sbyte, byte, short, ushort, int, uint, long, ulong)
Add tests for some of the new types
Add new Benchmark tests