[SciPy-User] SciPy-User Digest, Vol 121, Issue 3
Gabriel Gaster
gabe at gabegaster.com
Wed Sep 4 13:08:22 EDT 2013
Thanks David,
I hadn't thought about it that way, but that makes sense.
Cheers,
Gabe
> Date: Tue, 3 Sep 2013 12:37:23 -0700 (PDT)
> From: David Baddeley <david_baddeley at yahoo.com.au (mailto:david_baddeley at yahoo.com.au)>
> Subject: Re: [SciPy-User] __sizeof__ seems wrong
> To: SciPy Users List <scipy-user at scipy.org (mailto:scipy-user at scipy.org)>
> Message-ID: <1378237043.576.YahooMailNeo at web163905.mail.gq1.yahoo.com (mailto:1378237043.576.YahooMailNeo at web163905.mail.gq1.yahoo.com)>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi Gabriel,
>
> I believe that sizeof returns the size of the 'ndarray' object (ie a pointer to the data, information about dimensions, strides, and data type etc ..), not the actual data. The full size in memory would be array.nbytes + array.__sizeof__(). The situation is, however, complicated in that the ndarray object doesn't necessarily own it's memory, and with the possibility of having multiple ndarrays pointing at the same data (ie after slicing), and it makes more sense to think of an ndarray object as being a kind of smart pointer rather than actually encompassing it's data, making the current implementation of __sizeof__ correct. One could potentially make sizeof return the full size if the array owned it's data, the 'pointer' size otherwise, but this is likely to be hard (if not impossible) to implement consistently over all possible use cases.
>
> cheers,
> David
>
>
> ________________________________
> From: Gabriel Gaster <gabe at gabegaster.com (mailto:gabe at gabegaster.com)>
> To: scipy-user at scipy.org (mailto:scipy-user at scipy.org)
> Sent: Tuesday, 3 September 2013 1:18 PM
> Subject: [SciPy-User] __sizeof__ seems wrong
>
>
>
> This might be a bug/fix that is more appropriate for the numpy list -- but it also relates to scipy sparse...
>
> Run the following code:
>
> from scipy import sparse
> x = sparse.rand(100,10,.2)
> print x.__sizeof__()
> ## 32 or 16, depending
> print x.data.__sizeof__()
> ## 80 or 40, depending
> print x.data.nbytes
> ## 1600
>
> import numpy
> print numpy.arange(200).__sizeof__()
> ## 80 or 40, depending
> print numpy.arange(200).nbytes
>
> ## 1600
>
> 1. Why is nbytes different than __sizeof__ ? ?I believe nbytes and do not believe __sizeof__. __sizeof__ should just be rewritten to default to nbytes.
> 2. It seems that the __sizeof__ methods need to be updated for numpy.array AND for scipy.sparse.
>
> I would be happy to do this -- but before I do, I wanted to sanity check with the list.
> Thanks.
>
> Gabe
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org (mailto:SciPy-User at scipy.org)
> http://mail.scipy.org/mailman/listinfo/scipy-user
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130903/e352615a/attachment-0001.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130904/d0e005e1/attachment.html>
More information about the SciPy-User
mailing list