LinqFaster icon indicating copy to clipboard operation
LinqFaster copied to clipboard

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

Open Smurf-IV opened this issue 6 years ago • 9 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 #########

Smurf-IV avatar Jul 19 '19 14:07 Smurf-IV

Should ushort not be supported

Smurf-IV avatar Jul 19 '19 14:07 Smurf-IV

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

jackmott avatar Jul 19 '19 15:07 jackmott

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

Smurf-IV avatar Jul 19 '19 15:07 Smurf-IV

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

Smurf-IV avatar Jul 19 '19 15:07 Smurf-IV

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.

jackmott avatar Jul 19 '19 15:07 jackmott

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.

jackmott avatar Jul 19 '19 15:07 jackmott

output type always the same as input type currently, same as linq.

On Fri, Jul 19, 2019 at 10:11 AM Simon Coghlan [email protected] wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jackmott/LinqFaster/issues/18?email_source=notifications&email_token=ABD3XZR4UZSJLSUCKOXOQ6DQAHKR7A5CNFSM4IFGOQQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2L5IKI#issuecomment-513266729, or mute the thread https://github.com/notifications/unsubscribe-auth/ABD3XZQONZFFV4QNGDBSTNDQAHKR7ANCNFSM4IFGOQQQ .

jackmott avatar Jul 19 '19 15:07 jackmott

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)

Smurf-IV avatar Jul 21 '19 06:07 Smurf-IV

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

Smurf-IV avatar Aug 03 '19 07:08 Smurf-IV