Skip to content

DOC: Clarify tiny/xmin in finfo and machar (gh-16253) #16253

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

Merged
merged 10 commits into from
May 18, 2020

Conversation

rk-mlu
Copy link
Contributor

@rk-mlu rk-mlu commented May 15, 2020

This commit adds a note to the documentation of finfo clarifying that
the attribute tiny does not represent the smallest positive usable
number. Instead, it refers to the smallest positive number with there
being no leading 0's in the mantissa, that is, the smallest positive
normalized floating-point number.
Alternatively, one can say that tiny is the smallest positive floating
point number with full precision. The smallest positive subnormal
floating point number is typically orders of magnitudes smaller, but
has reduced precision since leading 0's in the mantissa are used to
allow smaller exponents than indicated by minexp.

The commit also adds a brief clarification to the docstring of machar.

Closes #16252

This commit adds a note to the documentation of finfo clarifying that
the attribute `tiny` does not represent the smallest positive usable
number. Instead it refers to the smallest positive number with there
being no leading 0's in the mantisse (normalized floating point number).
Alternatively, `tiny` represents the smallest positive floating point
number with full precision. The smallest positive subnormal floating
point number is typically orders of magnitudes smaller, but has reduced
precision since leading 0's in the mantisse are used to allow smaller
exponents than indicated by `minexp`.

The commit also adds a brief clarification to the docstring of machar.

Closes numpy#16252
Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

This is a nice clarification for the docs; however, it might be worth considering replacing some of the text that has been added with an external reference. The descriptions are valuable and interesting, but a lot of the details are not NumPy-specific and thus a more brief summary followed by a reference might be more appropriate. IMO the wiki page on denormal numbers provides a nice overview of some of the details that have been added here.

rk-mlu added 2 commits May 15, 2020 22:11
More concise version of the clarification in finfo, as recommended by @rossbar.
Co-authored-by: Anirudh Subramanian <anirudh2290@apache.org>
Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

Thanks for the previous changes - I have a few more suggestions, LMK what you think!

Comment on lines 340 to 342
The smallest positive floating point number with there being no
leading 0's in the mantissa. Type of `tiny` is an appropriate
floating point type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The smallest positive floating point number with there being no
leading 0's in the mantissa. Type of `tiny` is an appropriate
floating point type.
The smallest positive non-subnormal (see Notes) floating point
number. Type of `tiny` is an appropriate floating point type.

This is just my opinion, but I have a slight preference for leaving the details of denormal numbers (i.e. "being no leading 0's in the mantissa") out of the parameter description and instead refer to greater levels of detail outside of the parameters section.

LMK what you think!

Copy link
Contributor Author

@rk-mlu rk-mlu May 17, 2020

Choose a reason for hiding this comment

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

@rossbar That is fine with me, too.

Please take note that I used the phrase "being no leading 0's in the mantissa" since it already appeared in the description of another parameter in the same docstring. Cf. minexp.

To keep it consistent, I guess, we should modify the phrase there as well. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I was suprised how often we used "mantissa" since I am not sure its a good start for a general audience. I liked the "with full precision", but overall, I guess a see notes is just the right way to explain it.

Mainly commenting, because it seemed to me like we can just drop the current second sentence, saying that it gives out the correct type seems pretty irrelevant (all of these are obviously returned as the same type as is being queried).

Copy link
Member

Choose a reason for hiding this comment

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

As for "mantissa" - I think we should prefer "significand". See also this stronger opinion against mantissa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I tried to combine these comments in the most recent commit. In particular, I tried
to avoid usage of the word mantissa if possible.

Regarding the matter "significand" vs. "mantissa": I have no strong feelings about this. The former is used in the IEEE 754-standard, while the latter seems to be a bit more common in the scientific computing literature. But I have no overview how often and where mantissa is in use within the NumPy documentation. For instance, finfo has the attribute nmant which would need to be renamed, too.

So, this topic might be a little beyond the scope of this PR.

rk-mlu and others added 3 commits May 17, 2020 17:58
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Docstrings are modified to reflect recent comments to PR.
Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

The changes pertaining to Notes and tiny look good to me (except for a couple minor formatting notes). However, I think something might have been lost in the changes to minexp - I think the original wording "power of the base" or "power of ibeta" was valuable. I don't mind the getting rid of the explicit use of "mantissa" in favor of the "full precision" wording, but I think the removal of the description of the exponent should be undone.

Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
@rk-mlu
Copy link
Contributor Author

rk-mlu commented May 18, 2020

Regarding minexp:
No problem, I will restore the original description of minexp in finfoand machar.

However, in my opinion the descriptions given for each attribute currently differ somewhat in the level of detail. But perhaps this can be better addressed in a general revision that also deals with the "mantissa" vs. "significand" issue.

@seberg seberg self-requested a review May 18, 2020 13:28
Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks @rk-mlu for the input and being so responsive!

@seberg
Copy link
Member

seberg commented May 18, 2020

Thanks @rk-mlu for improving this and Ross for the review!

@seberg seberg merged commit 0eb532d into numpy:master May 18, 2020
@seberg seberg changed the title DOC: Modified documentation of finfo and machar DOC: Calrify tiny/xmin in finfo and machar (gh-16253) May 18, 2020
@charris charris changed the title DOC: Calrify tiny/xmin in finfo and machar (gh-16253) DOC: Clarify tiny/xmin in finfo and machar (gh-16253) May 18, 2020
@rk-mlu rk-mlu deleted the finfo-doc-update branch May 18, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output of np.finfo is misleading
6 participants