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

Correctly document rand_distr features and forward "std" feature to num-traits #1100

Merged
merged 8 commits into from
Apr 8, 2021

Conversation

vks
Copy link
Collaborator

@vks vks commented Mar 5, 2021

Previously, the features were undocumented and it was incorrectly claimed that no_std is not supported.

Previously, the features were undocumented and it was incorrectly claimed that `no_std` is not supported.
Comment on lines 23 to 24
functions from `std`. Otherwise, the floating point functions from `num_traits`
and `libm` are used to support `no_std` environments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this not true right now? We don't seem to forward the std trait to num-traits, so would we even end up using the std implementations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya we need to add "rand-traits/std" to this line:

std = ["alloc", "rand/std"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "num-traits/std"?

This actually brings up another question though: should we prefer the std impls? This might affect portability of results.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "num-traits/std"

Whoops, ya

This actually brings up another question though: should we prefer the std impls?

I feel like we should, if only because that's what num-traits does. Also, preffering std over libm is what I would expect. But I don't have that strong a feeling either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should

Maybe; I don't have a strong opinion on it, though we should probably mention it in the book and maybe also try to gather data on where results may differ.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, I decided to forward our "std" feature as "num-traits/std", since this is the behavior I would expect.

Of course, this might technically be a value-breaking change. If we really want to have value stability for floating-point distributions, we might want to always use libm, because I am not sure that all implementations of the C standard math libraries produce the same results.

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another point: enabling std in rand does not enable std in rand_distr. Perhaps we don't want this though; in any case, we can't without rust-lang/cargo#8832.

Comment on lines 23 to 24
functions from `std`. Otherwise, the floating point functions from `num_traits`
and `libm` are used to support `no_std` environments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "num-traits/std"?

This actually brings up another question though: should we prefer the std impls? This might affect portability of results.

vks added 2 commits March 13, 2021 16:38
This means that the floating point functions from `std` are used if
available, instead of always using the ones from `libm`.
@vks
Copy link
Collaborator Author

vks commented Mar 13, 2021

Another point: enabling std in rand does not enable std in rand_distr. Perhaps we don't want this though; in any case, we can't without rust-lang/cargo#8832.

rand_distr depends on rand, not the other way around. So I think this is as it should be?

@vks vks changed the title Correctly document rand_distr features Correctly document rand_distr features and forward "std" feature to num-traits Mar 19, 2021
@vks
Copy link
Collaborator Author

vks commented Mar 19, 2021

Are the changes here ok or should I forgo forwarding "std" for now?

@dhardy
Copy link
Member

dhardy commented Mar 20, 2021

Fair enough, I decided to forward our "std" feature as "num-traits/std", since this is the behavior I would expect.

Of course, this might technically be a value-breaking change. If we really want to have value stability for floating-point distributions, we might want to always use libm, because I am not sure that all implementations of the C standard math libraries produce the same results.

Yes, I'd consider this a breaking change and not for a patch version. Also, regarding the latter point, better value portability sounds desirable. Is there any real cost to using libm — e.g. performance or incompatibility? Because if not, is it better to use it?

For now maybe we should add a different flag like std_math, and if the next release will be a patch release it should not be on by default.

@vks
Copy link
Collaborator Author

vks commented Mar 20, 2021

Ok, I reverted the change to use std float functions to keep the status quo and updated the README accordingly.

Is there any real cost to using libm — e.g. performance or incompatibility?

There are reports on their issue tracker about libm being twice as slow on some platforms. More worryingly, there are reports about incorrect results due to bugs in the floor implementation on x87 platforms. There are also some accuracy bugs.

For now maybe we should add a different flag like std_math, and if the next release will be a patch release it should not be on by default.

I'm not sure the differences in results would be big enough to justify a feature flag, but let's keep that for another PR.

@dhardy
Copy link
Member

dhardy commented Mar 20, 2021

I still don't see a reason not to add std_math = ["num_traits/std"] — except maybe supporting it in the future.

@vks
Copy link
Collaborator Author

vks commented Mar 27, 2021

I added an "std_math" feature and made sure our CI covers the different rand_distr features.

@vks
Copy link
Collaborator Author

vks commented Apr 7, 2021

@dhardy I think I addressed all of your concerns?

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. Approved.

@dhardy dhardy merged commit 2582115 into master Apr 8, 2021
@vks vks deleted the rand_distr-features-doc branch April 22, 2021 00:26
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

Successfully merging this pull request may close these issues.

3 participants