Skip to content

DOC: Add examples for setbufsize & getbufsize #22727

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

Closed
wants to merge 2 commits into from

Conversation

jnclt
Copy link

@jnclt jnclt commented Dec 3, 2022

Add examples for getbufsize and setbufsize as requested by #22266.

Written as part of PyData 2022 sprint.

@jnclt jnclt changed the title DOC: Add examples for setbufsize & getbufsize #22266 DOC: Add examples for setbufsize & getbufsize Dec 3, 2022
Copy link
Member

@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

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

The results of these are dependent on the OS, and CI failures are indicative of this. MacOS Python 3.8 on Azure reports:

numpy.core.setbufsize
---------------------

File "build/testenv/lib/python3.8/site-packages/numpy/__init__.py", line 199, in setbufsize
Failed example:
    np.getbufsize()
Expected:
    8192
Got:
    20000


File "build/testenv/lib/python3.8/site-packages/numpy/__init__.py", line 201, in setbufsize
Failed example:
    np.setbufsize(4096)
Expected:
    8192
Got:
    20000

numpy.core.getbufsize
---------------------

File "build/testenv/lib/python3.8/site-packages/numpy/__init__.py", line 232, in getbufsize
Failed example:
    np.getbufsize()
Expected:
    8192
Got:
    4096

@jnclt
Copy link
Author

jnclt commented Dec 3, 2022

I didn't realize the examples are actually tested, thanks for pointing it out.
I don't see how to make them platform-independent, so I'd just close this PR.
Perhaps examples for these functions aren't that helpful after all?

@HaoZeke
Copy link
Member

HaoZeke commented Dec 3, 2022

I didn't realize the examples are actually tested, thanks for pointing it out. I don't see how to make them platform-independent, so I'd just close this PR. Perhaps examples for these functions aren't that helpful after all?

Rather than closing this perhaps just marking the outputs as "to be skipped", and mention the OS and indicative output in a comment?

    refguide can be signalled to skip testing code by adding
    ``#doctest: +SKIP`` to the end of the line. If the output varies or is
    random, add ``# may vary`` or ``# random`` to the comment. for example

    >>> plt.plot(...)  # doctest: +SKIP
    >>> random.randint(0,10)
    5 # random

@jnclt jnclt requested a review from HaoZeke December 4, 2022 13:11
@mhvk
Copy link
Contributor

mhvk commented Dec 4, 2022

I looked at this PR as I've often wondered whether the default buffer sizes are close to optimal for some of my more performance critical code, and was a little disappointed here to only see examples added of usage, which is really quite trivial (though good to mention it has to be a multiple of 16 bytes).

Maybe it is still useful, but that in that case probably best to set back the buffer size in the example -- as is, after the testing code passes through this example, the buffer size is now different for all further tests it does.

Comment on lines +199 to +203
>>> original_size = np.getbufsize()
>>> np.setbufsize(4096) == original_size
True
>>> np.getbufsize()
4096
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
>>> original_size = np.getbufsize()
>>> np.setbufsize(4096) == original_size
True
>>> np.getbufsize()
4096
>>> original_size = np.getbufsize()
>>> np.setbufsize(4096)
>>> np.getbufsize()
4096
>>> np.setbufsize(original_size)

Copy link
Member

Choose a reason for hiding this comment

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

The == test doesn't add anything and is potentially confusing. Also resets the size as @mhvk suggested.

Examples
--------
>>> np.getbufsize() # doctest: +SKIP
8192 # may vary
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
8192 # may vary
8192 # varies by OS

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't vary by OS, the variations seem due to the test run itself, I think. The typing tests are slow and don't run everwywhere, and set the bufsize to 4096 without setting it back. The 20000 is/was maybe also the doc tests running twice or so?

I am not sure when to modify buffer sizes best. There is an older issue I saw recently, that suggested we should just make them generally smaller, also to better use CPU caches (I guess times change)...

Copy link
Author

Choose a reason for hiding this comment

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

I realize I don't know enough about the use cases of these functions to meaningfully improve the docs atm. If I manage to find an example that demonstrates the impact on performance, I'll open another PR. Feel free to close this one, unless you want to discuss this further.

@mattip
Copy link
Member

mattip commented Dec 6, 2022

i think this would be more convincing with guidance when to change the buffer size. Is there some explanation elsewhere as to why one would want to change it?

@seberg
Copy link
Member

seberg commented Dec 8, 2022

Its too bad, but I suppose we should close this eve though there are some nice starts smaller things in here.
Thanks for the attempt! I suppose it wasn't really sprintable, because it needs at least some experimentation to add meaningful info (I made a note in the tracking issue).

If anyone wants to continue, please do not hesitate, or I am happy to reopen again.

(Which btw. could also lead to improving the buffer sizes ;)).

@seberg seberg closed this Dec 8, 2022
@InessaPawson
Copy link
Member

@jnclt Thank you for giving it a go, Lefteris! Feel free to work on another “sprintable” issue that peaks your interest.

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

Successfully merging this pull request may close these issues.

6 participants