Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Smurf-IV opened this issue Jul 19, 2019 · 9 comments
Open

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

Smurf-IV opened this issue Jul 19, 2019 · 9 comments

Comments

@Smurf-IV
Copy link

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
Copy link
Author

Should ushort not be supported

@jackmott
Copy link
Owner

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

@Smurf-IV
Copy link
Author

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

@Smurf-IV
Copy link
Author

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

@jackmott
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

jackmott commented Jul 19, 2019 via email

@Smurf-IV
Copy link
Author

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
Copy link
Author

Smurf-IV commented Aug 3, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants