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

recursive for list and tuple seems like a safe default #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kootenpv
Copy link

No description provided.

@mrocklin
Copy link
Member

This seems like a sensible change to me. Would you be willing to add a test as well?

@kootenpv
Copy link
Author

@mrocklin I would, but I just noticed that my nbytes are different from the doctests. Maybe the numbers are from a 32-bit system? I wouldn't be very comfortable adding untested values as a test, that doesn't sound right :-)

In my case:

>>> nbytes(123)
28
>>> nbytes([123, 123])
56 

Which made me realize the list itself is not being counted.

I did some experiments, and it seems that a list/tuple's size also depends on the number of elements in it. I'll make another change to the code.

@mrocklin
Copy link
Member

You can make tests that are 32/64 bit invariant, for example you can test something like the following:

assert nbytes([x, x, x]) == nbytes(x) * 3 + nbytes([])

Where x in a numpy array

@kootenpv
Copy link
Author

Also... in case the elements are referring to the same object, it is going to be an overestimation.

As I've learned the hard way, in your example, you still would have to add the overhead of the pointer to the object in the list (usually 4 bytes per additional element in the list).

@kootenpv
Copy link
Author

It's pretty difficult to write a test for it, as the actual value is not static w.r.t. to the different python versions :)

I think to get an even better estimate we'd have to consider the ids of the objects and make sure we count them only once (though I guess we could assume no duplicate objects).

Does require skipping as a test to pass though because of other python versions.
@mrocklin
Copy link
Member

mrocklin commented Sep 30, 2017 via email

Base automatically changed from master to main February 10, 2021 01:01
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.

2 participants