[Numpy-discussion] Tracking and inspecting numpy objects
sebastian at sipsolutions.net
Mon Sep 15 05:55:12 EDT 2014
On Mo, 2014-09-15 at 10:16 +0200, Mads Ipsen wrote:
> I am trying to inspect the reference count of numpy arrays generated by
> my application.
> Initially, I thought I could inspect the tracked objects using
> gc.get_objects(), but, with respect to numpy objects, the returned
> container is empty. For example:
> import numpy
> import gc
> data = numpy.ones(1024).reshape((32,32))
> objs = [o for o in gc.get_objects() if isinstance(o, numpy.ndarray)]
> print objs # Prints empty list
> print gc.is_tracked(data) # Print False
> Why is this? Also, is there some other technique I can use to inspect
> all numpy generated objects?
Two reasons. First of all, unless your array is an object arrays (or a
structured one with objects in it), there are no objects to track. The
array is a single python object without any referenced objects (except
possibly its `arr.base`).
Second of all -- and this is an issue -- numpy doesn't actually
implement the traverse slot, so it won't even work for object arrays
(numpy object arrays do not support circular garbage collection at this
time, please feel free to implement it ;)).
> Thanks in advance.
> Best regards,
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion