Re: [Numpy-discussion] List Array References?

2008-02-15 Thread Stefan van der Walt
Hi Alexander

On Thu, Feb 14, 2008 at 03:43:46PM -0500, Alexander Michael wrote:
 Is there a way to list all of the arrays that are referencing a given
 array? Similarly, is there a way to get a list of all arrays that are
 currently in memory?

As far as I know, the reference count to the array is increased when
you create a view, but the views themselves are not tracked anywhere.
You can therefore say whether there are references around, but you
cannot identify the Python objects.

I'm curious why you need this information -- maybe there is an
alternative solution to your problem?

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] List Array References?

2008-02-15 Thread Robin
On Thu, Feb 14, 2008 at 8:43 PM, Alexander Michael [EMAIL PROTECTED] wrote:
 Is there a way to list all of the arrays that are referencing a given
  array? Similarly, is there a way to get a list of all arrays that are
  currently in memory?

For the second question, if you are working interactively in Ipython, you can do
%who ndarray
or
%whos ndarray
to get a list of arrays.

It might be possible to get this functionality within a script/program
through the ipython api, but I'm afraid I don't know much about that.

Cheers,

Robin
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] List Array References?

2008-02-15 Thread Davide Albanese
Whith standard Python:
  who()

Robin ha scritto:
 On Thu, Feb 14, 2008 at 8:43 PM, Alexander Michael [EMAIL PROTECTED] wrote:
   
 Is there a way to list all of the arrays that are referencing a given
  array? Similarly, is there a way to get a list of all arrays that are
  currently in memory?
 

 For the second question, if you are working interactively in Ipython, you can 
 do
 %who ndarray
 or
 %whos ndarray
 to get a list of arrays.

 It might be possible to get this functionality within a script/program
 through the ipython api, but I'm afraid I don't know much about that.

 Cheers,

 Robin
 ___
 Numpy-discussion mailing list
 Numpy-discussion@scipy.org
 http://projects.scipy.org/mailman/listinfo/numpy-discussion
   

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] List Array References?

2008-02-15 Thread Stefan van der Walt
On Fri, Feb 15, 2008 at 08:28:08AM -0500, Alexander Michael wrote:
 On Fri, Feb 15, 2008 at 7:12 AM, Stefan van der Walt [EMAIL PROTECTED] 
 wrote:
   As far as I know, the reference count to the array is increased when
   you create a view, but the views themselves are not tracked anywhere.
   You can therefore say whether there are references around, but you
   cannot identify the Python objects.
 
 I would like to occasionally dynamically grow an array (i.e. add
 length to existing dimensions) as I do not know th ultimately required
 length beforehand, but I have a good guess so I won't be need to
 reallocate that often if at all. The only way I know how to do this is
 numpy is to create a new larger array with the new dimensions and copy
 the existing data from the smaller array into it. Perhaps there is a
 better way that doesn't invalidate views on the array? I want to make
 sure that there are no outstanding references to the old array (i.e.
 views on it, etc.) so that I can raise a helpful exception while
 developing.

Numpy does complain if you attempt to resize an array with views on
it:

  In [8]: x = np.array([1,2,3])

  In [14]: y = x[::-1]

  In [18]: x.resize((4,))
  ---
  ValueErrorTraceback (most recent call last)

  /tmp/ipython console in module()

  ValueError: cannot resize an array that has been referenced or is
  referencing another array in this way.  Use the resize function

You can catch that exception and work from there.  I hope that is what
you had in mind?

Regards
Stéfan
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] List Array References?

2008-02-15 Thread Alexander Michael
On Fri, Feb 15, 2008 at 11:51 AM, Stefan van der Walt [EMAIL PROTECTED] wrote:
  Numpy does complain if you attempt to resize an array with views on
  it:

   In [8]: x = np.array([1,2,3])

   In [14]: y = x[::-1]

   In [18]: x.resize((4,))
   ---
   ValueErrorTraceback (most recent call last)

   /tmp/ipython console in module()

   ValueError: cannot resize an array that has been referenced or is
   referencing another array in this way.  Use the resize function

  You can catch that exception and work from there.  I hope that is what
  you had in mind?

Actually, I'm essentially trying to figure out how situations like
that are arising. I'm not
using resize, because it reshapes the array when adding to any
dimension other than
the first. At the end of the day I want to enlarge an array without
leaving any
references dangling.

Thanks for the suggestion!
Alex
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] List Array References?

2008-02-14 Thread Alexander Michael
Is there a way to list all of the arrays that are referencing a given
array? Similarly, is there a way to get a list of all arrays that are
currently in memory?

Thanks,
Alex
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion