-
Notifications
You must be signed in to change notification settings - Fork 306
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
Change mean_axis to use FromPrimitive #518
Conversation
The documentation for the `Zero` and `One` traits says only that they are the additive and multiplicative identities; it doesn't say anything about converting an integer to a float by adding `One::one()` to `Zero::zero()` repeatedly. Additionally, it's nice to convert the length to `A` directly instead of having to use a loop.
I'd love to be constructive, but :( Isn't there a better way to convert the integer? We could limit this method to only float and complex numbers (do we have nice traits for that? https://github.com/bluss/complexfloat is a draft). Ideally we support a wider range of scalar types than complex numbers, though. |
The other trait from the The standard library implements some conversions from integers with Would an |
FromPrimitive does the right thing for floats at least. Num's traits feel imperfect (that we specify exactly Zero + Add + Div, we should do this at a bit higher level). Here we'd like an approxmating conversion that does not fail. On one hand I'd like to restrict this to complex numbers, since we know that we don't handle bignums graciously (we probably clone them too much inside sum_axis). But the other case is custom Copy-able scalars, and I guess it could make sense to panic in the usize to scalar conversion there. |
Why aren't we using
That's what we've been thinking about, but I think the best thing would be if we didn't have to convert the length to
This also got me thinking about the sum, too. It would be nice if the sum could exceed the maximum of the element type as long as the mean doesn't. For example, consider // for A = i8
if n <= 1 {
// use i8
} else if n <= 2 {
// use i16
} else if n <= 4 {
// use i32
} else if n <= 8 {
// use i64
} else {
// use i128
} In practice, this would mean that With the options we have available today, I think |
I think we need even more to do it in a way that saves copies for bignums, for exampe preferring to use Promoting sounds interesting but not important enough. Aren't for example accurate summation algorithms more interesting for sums and means? And I don't need bignums, I don't want us to spend significant time and complexity on things that ndarray probably isn't going to be used for. (This is why we lean heavily towards floats, isn't it?)
Yes. There are options of rewriting the numeric traits. I'd still like to do that, but of course I can't commit to doing that, don't have the time. |
I don't understand. With
Yes, for floating-point numbers. I was thinking about adding a
I agree. All I really care about for my use-cases is For the purpose of this PR, should we merge the current version in the next breaking release? |
Good point, that makes sense. Sure, let's merge this when we can. |
I think my vision for our numerical methods is still a more narrow (less generic) view of primitive numeric types and floats, and possibly using custom numerical traits instead of just the ones from num Add to that a |
Thanks! I meant to merge this after resolving the conflict. Apparently forgot. |
The documentation for the
Zero
andOne
traits says only that they are the additive and multiplicative identities; it doesn't say anything about converting an integer to a float by addingOne::one()
toZero::zero()
repeatedly. Additionally, it's nice to convert the length toA
directly instead of having to use a loop.