Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Johann Cohen-Tanugi

Ubuntu has a much shorter cycle of updates than Fedora, indeed.

On 03/10/2010 06:27 AM, Charles R Harris wrote:



On Tue, Mar 9, 2010 at 5:52 PM, Johann Cohen-Tanugi 
co...@lpta.in2p3.fr mailto:co...@lpta.in2p3.fr wrote:


more fun :
[co...@jarrett tests]$ pwd
/home/cohen/sources/python/numpy/numpy/core/tests
[co...@jarrett tests]$ python -c 'import test_ufunc'

python: Modules/gcmodule.c:277: visit_decref: Assertion
`gc-gc.gc_refs != 0' failed.
Aborted (core dumped)

and in the debugger:
(gdb) run
Starting program: /usr/bin/python
warning: .dynamic section for /lib/libpthread.so.0 is not at the
expected address

warning: difference appears to be caused by prelink, adjusting
expectations
warning: .dynamic section for /lib/libdl.so.2 is not at the
expected address

warning: difference appears to be caused by prelink, adjusting
expectations
warning: .dynamic section for /lib/libc.so.6 is not at the
expected address

warning: difference appears to be caused by prelink, adjusting
expectations
[Thread debugging using libthread_db enabled]

Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:45)
[GCC 4.4.2 20091222 (Red Hat 4.4.2-20)] on linux2
Type help, copyright, credits or license for more information.
 import test_ufunc



python: Modules/gcmodule.c:277: visit_decref: Assertion
`gc-gc.gc_refs != 0' failed.

Program received signal SIGABRT, Aborted.
0x00aab416 in __kernel_vsyscall ()
Missing separate debuginfos, use: debuginfo-install
atlas-3.8.3-12.fc12.i686 libgcc-4.4.3-4.fc12.i686
libgfortran-4.4.3-4.fc12.i686
(gdb) bt
#0  0x00aab416 in __kernel_vsyscall ()
#1  0x00159a91 in raise (sig=6) at
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0x0015b35a in abort () at abort.c:92
#3  0x00152be8 in __assert_fail (assertion=value optimized out,
file=value optimized out, line=value optimized out,
function=value optimized out) at assert.c:81
#4  0x0050931e in visit_decref (op=value optimized out,
data=value optimized out) at Modules/gcmodule.c:277
#5  0x0047c8c2 in dict_traverse (op=value optimized out,
visit=value optimized out, arg=value optimized out) at
Objects/dictobject.c:2003
#6  0x00509af3 in subtract_refs (generation=value optimized out)
at Modules/gcmodule.c:296

#7  collect (generation=value optimized out) at
Modules/gcmodule.c:817
#8  0x0050a640 in PyGC_Collect () at Modules/gcmodule.c:1292
#9  0x004fb0f0 in Py_Finalize () at Python/pythonrun.c:424
#10 0x0050868f in Py_Main (argc=value optimized out, argv=value
optimized out) at Modules/main.c:625
#11 0x080485c8 in main (argc=value optimized out, argv=value
optimized out) at Modules/python.c:23

which looks identical to the bt I sent to Robert earlier on.

HTH,
Johann


On 03/10/2010 12:43 AM, Johann Cohen-Tanugi wrote:



On 03/10/2010 12:33 AM, Johann Cohen-Tanugi wrote:



On 03/10/2010 12:07 AM, Pauli Virtanen wrote:

ti, 2010-03-09 kello 21:14 +0100, Johann Cohen-Tanugi kirjoitti:
   

thinking about it, this morning there was a fedora update to python, so
I am using 2.6.2-4.fc12.
Looks like the problem is in python itself, hence this piece of info.
 

That the problem would be in Python is not so clear to me. Can you try
running it with the previous Python shipped by Fedora? Do you see the
problem then? What's the previous version, btw?
   

2.6.2-1 IIRC. I would have to check, and I am not sure how to
either query this information or step back one update up with yum :(

Memory errors are somewhat difficult to debug. Can you try running only
a certain subset of the tests, first

nosetests numpy.core
   

crash

Be sure to set Pythonpath so that you get the correct Numpy version. If
it segfaults, proceed to (under numpy/core/tests)

nosetests test_multiarray.py
nosetests test_multiarray.py:TestNewBufferProtocol
   

neither crash, so the problem is not there

I followed your lead and tried each script and ended up with :
[co...@jarrett tests]$ nosetests test_ufunc.py
.
--
Ran 13 tests in 1.146s

OK
python: Modules/gcmodule.c:277: visit_decref: Assertion
`gc-gc.gc_refs != 0' failed.
Aborted (core dumped)

so test_ufunc.py seems to be at stake


Since the crash occurs in cyclic garbage collection, I'm doubting a bit
the numpy/core/src/multiarray/numpymemoryview.c implementation, since
that's the only part in Numpy that supports that.

Alternatively, just replace numpymemoryview.c with the attached one
which has cyclic GC stripped, and see if you still get the crash.

Cheers,
Pauli


   




Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Johann Cohen-Tanugi


On 03/10/2010 01:55 AM, Pauli Virtanen wrote:
 more fun :
 [co...@jarrett tests]$ pwd
 /home/cohen/sources/python/numpy/numpy/core/tests
 [co...@jarrett tests]$ python -c 'import test_ufunc'
 python: Modules/gcmodule.c:277: visit_decref: Assertion `gc-gc.gc_refs
 != 0' failed.
 Aborted (core dumped)
  
 What happens if you only import the umath_tests module (or something, it's a 
 .so under numpy.core)?

[co...@jarrett core]$ export 
PYTHONPATH=/home/cohen/.local/lib/python2.6/site-packages/numpy/core:$PYTHONPATH
[co...@jarrett core]$ python
Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:45)
[GCC 4.4.2 20091222 (Red Hat 4.4.2-20)] on linux2
Type help, copyright, credits or license for more information.
  import umath_tests
 
python: Modules/gcmodule.c:277: visit_decref: Assertion `gc-gc.gc_refs 
!= 0' failed.
Aborted (core dumped)

so this import also trigger the crash at exit...

 Just importing test_ufunc.py probably doesn't run a lot of extension code. 
 Since you don't get crashes only by importing numpy, I really don't see many 
 alternatives any more...

 Thanks,
 Pauli

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Backwards slicing including the first element

2010-03-10 Thread Jerome Esteve
Dear all,

Is there a way to give an integer value to j when using a[i:j:-1] so that the 
first element of the array can be included in the slice ?

I would like to use some code like a[i:i-k:-1] to get a slice of length k. 

The numpy documentation seems to suggest that j=-1 should work:

Assume n is the number of elements in the dimension being sliced. Then, if i 
is not given it defaults to 0 for k  0 and n for k  0 . If j is not given it 
defaults to n for k  0 and -1 for k  0 . If k is not given it defaults to 1.

But a[i:i-k:-1] is empty if i-k is -1. The workaround is a[i::-1][:k], is there 
something simpler ?

Many thanks in advance, Jerome.

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] How to apply a function to an ndarray over a given dimension

2010-03-10 Thread Jorge Scandaliaris
Hi,
First, excuse me if I am over-optimizing, but I am curious if there exist a way
to apply a function to an ndarray over a given dimension. In case I don't make
myself clear, I have an array of shape( n,2,2) where each row represents a 2 by
2 covariance matrix, and I want to perform the eigenvalue decomposition of each
row. Right now I do it with list comprehensions:

import numpy as np
import scipy as sp

C = np.arange(10*2*2).reshape(10,2,2)
ed = [sp.linalg.eig(r) for r in C[:]]

Is there a better way, along the lines of vectorize, of doing this?


Cheers,

Jorge

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing structured arrays

2010-03-10 Thread Bruce Schultz


On 10/03/10 10:09, Bruce Schultz wrote:
 On Sat, Mar 6, 2010 at 8:35 AM, Gökhan Sever gokhanse...@gmail.com wrote:
   
 On Fri, Mar 5, 2010 at 8:00 AM, Bruce Schultz bruce.schu...@gmail.com
 wrote:
 
 Output is:
 ### ndarray
 [[ 1.   2. ]
  [ 3.   4.1]]
 ### structured array
 [(1.0, 2.0) (3.0, 4.0996)]
   
 I still couldn't figure out how floating point numbers look nicely on screen
 in cases like yours (i.e., trying numpy.array2string()) but you can make
 sure by using numpy.savetxt(file, array, fmt=%.1f) you will always have
 specified precision in the written file.
 

 Using numpy.array2string() gives the same format as the output above.
   
I started looking at how array2string() is implemented, and came up with
this patch which formats my structured array nicely, the same as an
unstructured array. It was mainly done as a proof of concept, so it only
works for floats and I'm probably doing the wrong thing to detect a
structured array by comparing the dtype to void.  Maybe someone with
more numpy experience can tell me if I'm on the right track...

=== modified file 'numpy/core/arrayprint.py'
--- numpy/core/arrayprint.py2010-02-21 16:16:34 +
+++ numpy/core/arrayprint.py2010-03-10 13:48:22 +
@@ -219,6 +219,10 @@
 elif issubclass(dtypeobj, _nt.unicode_) or \
  issubclass(dtypeobj, _nt.string_):
 format_function = repr
+elif issubclass(dtypeobj, _nt.void):
+#XXX this is for structured arrays
+format_function = StructuredFormatter(a)
+separator = '\n '
 else:
 format_function = str
 
@@ -231,6 +235,17 @@
 
 return lst
 
+class StructuredFormatter:
+def __init__(self, a):
+self.data = a
+self.dtype = a.dtype  #XXX use the dtype to build column formatters
+
+def __call__(self, x):
+ff = FloatFormat(self.data.view(float), _float_output_precision,
+  _float_output_suppress_small)
+return '[' + ' '.join([ff(n) for n in x]) + ']'
+
+   
 def _convert_arrays(obj):
 import numeric as _nc
 newtup = []



Cheers
Bruce

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Pauli Virtanen
Wed, 10 Mar 2010 10:28:07 +0100, Johann Cohen-Tanugi wrote:

 On 03/10/2010 01:55 AM, Pauli Virtanen wrote:
 more fun :
 [co...@jarrett tests]$ pwd
 /home/cohen/sources/python/numpy/numpy/core/tests [co...@jarrett
 tests]$ python -c 'import test_ufunc' python: Modules/gcmodule.c:277:
 visit_decref: Assertion `gc-gc.gc_refs != 0' failed.
 Aborted (core dumped)
  
 What happens if you only import the umath_tests module (or something,
 it's a .so under numpy.core)?

 [co...@jarrett core]$ export
 PYTHONPATH=/home/cohen/.local/lib/python2.6/site-packages/numpy/core:
$PYTHONPATH
 [co...@jarrett core]$ python
 Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:45) [GCC 4.4.2 20091222
 (Red Hat 4.4.2-20)] on linux2 Type help, copyright, credits or
 license for more information.
   import umath_tests
  
 python: Modules/gcmodule.c:277: visit_decref: Assertion `gc-gc.gc_refs
 != 0' failed.
 Aborted (core dumped)
 
 so this import also trigger the crash at exit...

Then it is clear that the umath_tests module does something that is not 
permitted. It's possible that there is a some sort of a refcount error 
somewhere in the generalized ufuncs mechanisms -- that part of Numpy is 
not heavily used.

Bug spotting challenge: Start from umath_tests.c.src:initumath_tests, 
follow the execution, and spot the bug (if any).

Pauli

PS. it might be a good idea to file a bug ticket now

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Johann Cohen-Tanugi
http://projects.scipy.org/numpy/ticket/1425 for the bug trac

well, I do feel challenged now... ;)
J

On 03/10/2010 03:11 PM, Pauli Virtanen wrote:
 Wed, 10 Mar 2010 10:28:07 +0100, Johann Cohen-Tanugi wrote:


 On 03/10/2010 01:55 AM, Pauli Virtanen wrote:
  
 more fun :
 [co...@jarrett tests]$ pwd
 /home/cohen/sources/python/numpy/numpy/core/tests [co...@jarrett
 tests]$ python -c 'import test_ufunc' python: Modules/gcmodule.c:277:
 visit_decref: Assertion `gc-gc.gc_refs != 0' failed.
 Aborted (core dumped)

  
 What happens if you only import the umath_tests module (or something,
 it's a .so under numpy.core)?


 [co...@jarrett core]$ export
 PYTHONPATH=/home/cohen/.local/lib/python2.6/site-packages/numpy/core:
  
 $PYTHONPATH

 [co...@jarrett core]$ python
 Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:45) [GCC 4.4.2 20091222
 (Red Hat 4.4.2-20)] on linux2 Type help, copyright, credits or
 license for more information.
 import umath_tests
   
 python: Modules/gcmodule.c:277: visit_decref: Assertion `gc-gc.gc_refs
 != 0' failed.
 Aborted (core dumped)

 so this import also trigger the crash at exit...
  
 Then it is clear that the umath_tests module does something that is not
 permitted. It's possible that there is a some sort of a refcount error
 somewhere in the generalized ufuncs mechanisms -- that part of Numpy is
 not heavily used.

 Bug spotting challenge: Start from umath_tests.c.src:initumath_tests,
 follow the execution, and spot the bug (if any).

   Pauli

 PS. it might be a good idea to file a bug ticket now

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Backwards slicing including the first element

2010-03-10 Thread Warren Weckesser
Jerome Esteve wrote:
 Dear all,

 Is there a way to give an integer value to j when using a[i:j:-1] so 
 that the first element of the array can be included in the slice ?

 I would like to use some code like a[i:i-k:-1] to get a slice of 
 length k. 

 The numpy documentation seems to suggest that j=-1 should work:

 Assume n is the number of elements in the dimension being sliced. 
 Then, if i is not given it defaults to 0 for k  0 and n for k  0 . 
 If j is not given it defaults to n for k  0 and -1 for k  0 . 
 If k is not given it defaults to 1.

 But a[i:i-k:-1] is empty if i-k is -1. The workaround is a[i::-1][:k], 
 is there something simpler ?

You could use a[i:i-(len(a)+k):-1].  This works because a[-len(a)] is 
the same as a[0].

For example:

-
In [57]: a
Out[57]: array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])

In [58]: i = 3

In [59]: for k in range(5):
   : print k, a[i:i-(len(a)+k):-1]
   :
   :
0 []
1 [13]
2 [13 12]
3 [13 12 11]
4 [13 12 11 10]

-


Warren


 Many thanks in advance, Jerome.

 

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
   

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Pauli Virtanen
Wed, 10 Mar 2010 15:40:04 +0100, Johann Cohen-Tanugi wrote:
 Pauli, isn't it hopeless to follow the execution of the source code when
 the crash actually occurs when I exit, and not when I execute. I would
 have to understand enough of this umath_tests.c.src to spot a refcount
 error or things like that

Yeah, it's not easy, and requires knowing how to track this type of 
errors. I didn't actually mean that you should try do it, just posed it 
as a general challenge to all interested parties :)

On a more serious note, maybe there's a compilation flag or something in 
Python that warns when refcounts go negative (or something).

Cheers,
Pauli

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Bruce Southey
On 03/10/2010 08:40 AM, Johann Cohen-Tanugi wrote:
 Pauli, isn't it hopeless to follow the execution of the source code when
 the crash actually occurs when I exit, and not when I execute. I would
 have to understand enough of this umath_tests.c.src to spot a refcount
 error or things like that

 On 03/10/2010 03:11 PM, Pauli Virtanen wrote:

 Wed, 10 Mar 2010 10:28:07 +0100, Johann Cohen-Tanugi wrote:


  
 On 03/10/2010 01:55 AM, Pauli Virtanen wrote:


 more fun :
 [co...@jarrett tests]$ pwd
 /home/cohen/sources/python/numpy/numpy/core/tests [co...@jarrett
 tests]$ python -c 'import test_ufunc' python: Modules/gcmodule.c:277:
 visit_decref: Assertion `gc-gc.gc_refs != 0' failed.
 Aborted (core dumped)



 What happens if you only import the umath_tests module (or something,
 it's a .so under numpy.core)?


  
 [co...@jarrett core]$ export
 PYTHONPATH=/home/cohen/.local/lib/python2.6/site-packages/numpy/core:


 $PYTHONPATH

  
 [co...@jarrett core]$ python
 Python 2.6.2 (r262:71600, Jan 25 2010, 18:46:45) [GCC 4.4.2 20091222
 (Red Hat 4.4.2-20)] on linux2 Type help, copyright, credits or
 license for more information.
   import umath_tests

 python: Modules/gcmodule.c:277: visit_decref: Assertion `gc-gc.gc_refs
 != 0' failed.
 Aborted (core dumped)

 so this import also trigger the crash at exit...


 Then it is clear that the umath_tests module does something that is not
 permitted. It's possible that there is a some sort of a refcount error
 somewhere in the generalized ufuncs mechanisms -- that part of Numpy is
 not heavily used.

 Bug spotting challenge: Start from umath_tests.c.src:initumath_tests,
 follow the execution, and spot the bug (if any).

  Pauli

 PS. it might be a good idea to file a bug ticket now

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


  
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

Hi,
I can say that I have the same problem with Fedora 11 and Python 2.6 
(both Fedora version and Unladen Swallow versions) with numpy 
2.0.0.dev8272. However, I first noticed it with scipy but I see it with 
numpy.

It does not appear to be with Python 2.5 with an svn version and I did 
not see it with numpy 1.3 or the removed numpy 1.4.

Bruce

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Backwards slicing including the first element

2010-03-10 Thread Warren Weckesser
Warren Weckesser wrote:
 Jerome Esteve wrote:
   
 Dear all,

 Is there a way to give an integer value to j when using a[i:j:-1] so 
 that the first element of the array can be included in the slice ?

 I would like to use some code like a[i:i-k:-1] to get a slice of 
 length k. 

 The numpy documentation seems to suggest that j=-1 should work:

 Assume n is the number of elements in the dimension being sliced. 
 Then, if i is not given it defaults to 0 for k  0 and n for k  0 . 
 If j is not given it defaults to n for k  0 and -1 for k  0 . 
 If k is not given it defaults to 1.

 But a[i:i-k:-1] is empty if i-k is -1. The workaround is a[i::-1][:k], 
 is there something simpler ?
 

 You could use a[i:i-(len(a)+k):-1].  This works because a[-len(a)] is 
 the same as a[0].

   

I'm going to be pedantic and amend that last sentence.  While it is true 
the a[-len(a)] is the same as a[0], that is not why this works.  A 
better explanation is that Python is lenient about handling the value 
given as the end position in a slice.  It does not have to be a valid 
index.  If the value is out of range, Python will include everything up 
to the end of the actual data, and it will not raise an error.  So you 
can do slices like the following:
-
In [101]: w
Out[101]: [10, 11, 12, 13, 14]

In [102]: w[2:-5:-1]
Out[102]: [12, 11]

In [103]: w[2:-6:-1]
Out[103]: [12, 11, 10]

In [104]: w[2:-7:-1]
Out[104]: [12, 11, 10]
-
Note that -6 and -7 are not valid indices; using w[-6]  will raise an 
IndexError.


Warren


 For example:

 -
 In [57]: a
 Out[57]: array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])

 In [58]: i = 3

 In [59]: for k in range(5):
: print k, a[i:i-(len(a)+k):-1]
:
:
 0 []
 1 [13]
 2 [13 12]
 3 [13 12 11]
 4 [13 12 11 10]

 -


 Warren

   
 Many thanks in advance, Jerome.

 

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
   
 

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
   

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Backwards slicing including the first element

2010-03-10 Thread josef . pktd
On Wed, Mar 10, 2010 at 10:19 AM, Warren Weckesser
warren.weckes...@enthought.com wrote:
 Warren Weckesser wrote:
 Jerome Esteve wrote:

 Dear all,

 Is there a way to give an integer value to j when using a[i:j:-1] so
 that the first element of the array can be included in the slice ?

 I would like to use some code like a[i:i-k:-1] to get a slice of
 length k.

 The numpy documentation seems to suggest that j=-1 should work:

 Assume n is the number of elements in the dimension being sliced.
 Then, if i is not given it defaults to 0 for k  0 and n for k  0 .
 If j is not given it defaults to n for k  0 and -1 for k  0 .
 If k is not given it defaults to 1.

 But a[i:i-k:-1] is empty if i-k is -1. The workaround is a[i::-1][:k],
 is there something simpler ?


 You could use a[i:i-(len(a)+k):-1].  This works because a[-len(a)] is
 the same as a[0].



 I'm going to be pedantic and amend that last sentence.  While it is true
 the a[-len(a)] is the same as a[0], that is not why this works.  A
 better explanation is that Python is lenient about handling the value
 given as the end position in a slice.  It does not have to be a valid
 index.  If the value is out of range, Python will include everything up
 to the end of the actual data, and it will not raise an error.  So you
 can do slices like the following:
 -
 In [101]: w
 Out[101]: [10, 11, 12, 13, 14]

 In [102]: w[2:-5:-1]
 Out[102]: [12, 11]

 In [103]: w[2:-6:-1]
 Out[103]: [12, 11, 10]

 In [104]: w[2:-7:-1]
 Out[104]: [12, 11, 10]
 -
 Note that -6 and -7 are not valid indices; using w[-6]  will raise an
 IndexError.


 Warren


 For example:

 -
 In [57]: a
 Out[57]: array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])

 In [58]: i = 3

 In [59]: for k in range(5):
    :     print k, a[i:i-(len(a)+k):-1]
    :
    :
 0 []
 1 [13]
 2 [13 12]
 3 [13 12 11]
 4 [13 12 11 10]

 -

I thought, I had also used the -1 before, but it only works with range, e.g.

 [(i,i-k,np.arange(5)[range(i,i-k,-1)]) for i in range(1,5)]
[(1, -1, array([1, 0])), (2, 0, array([2, 1])), (3, 1, array([3, 2])),
(4, 2, array([4, 3]))]

the or None trick is more complicated when counting down

 [(i,i-k,np.arange(5)[i:(i-k if (i-k!=-1) else None):-1]) for i in 
 range(1,5)]
[(1, -1, array([1, 0])), (2, 0, array([2, 1])), (3, 1, array([3, 2])),
(4, 2, array([4, 3]))]

I will mark Warrens solution as something to remember.

Josef



 Warren


 Many thanks in advance, Jerome.

 

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Bruce Southey
On 03/10/2010 08:59 AM, Pauli Virtanen wrote:
 Wed, 10 Mar 2010 15:40:04 +0100, Johann Cohen-Tanugi wrote:

 Pauli, isn't it hopeless to follow the execution of the source code when
 the crash actually occurs when I exit, and not when I execute. I would
 have to understand enough of this umath_tests.c.src to spot a refcount
 error or things like that
  
 Yeah, it's not easy, and requires knowing how to track this type of
 errors. I didn't actually mean that you should try do it, just posed it
 as a general challenge to all interested parties :)

 On a more serious note, maybe there's a compilation flag or something in
 Python that warns when refcounts go negative (or something).

 Cheers,
 Pauli

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

Hi,
I think I managed to find this. I reverted back my svn versions ($svn 
update -r 8262) and cleaned both the build and installation directories.

It occurred with changeset 8262 (earlier changesets appear okay but 
later ones do not)
http://projects.scipy.org/numpy/changeset/8262

Specifically in the file:
numpy/core/code_generators/generate_ufunc_api.py

There is an extra call to that should have been deleted on line 54(?).
Py_DECREF(numpy);

Attached a patch to ticket 1425
http://projects.scipy.org/numpy/ticket/1425


Bruce
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Backwards slicing including the first element

2010-03-10 Thread Chris Barker
 Jerome Esteve wrote:
 Is there a way to give an integer value to j when using a[i:j:-1] so 
 that the first element of the array can be included in the slice ?

Is this what you are looking for?

In [11]: a = np.arange(10)

In [12]: a[6::-1]
Out[12]: array([6, 5, 4, 3, 2, 1, 0])

I know it's not an integer, but it does indicate the last (or first) 
element of the array

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] crash at prompt exit after running test

2010-03-10 Thread Charles R Harris
On Wed, Mar 10, 2010 at 10:39 AM, Bruce Southey bsout...@gmail.com wrote:

 On 03/10/2010 08:59 AM, Pauli Virtanen wrote:
  Wed, 10 Mar 2010 15:40:04 +0100, Johann Cohen-Tanugi wrote:
 
  Pauli, isn't it hopeless to follow the execution of the source code when
  the crash actually occurs when I exit, and not when I execute. I would
  have to understand enough of this umath_tests.c.src to spot a refcount
  error or things like that
 
  Yeah, it's not easy, and requires knowing how to track this type of
  errors. I didn't actually mean that you should try do it, just posed it
  as a general challenge to all interested parties :)
 
  On a more serious note, maybe there's a compilation flag or something in
  Python that warns when refcounts go negative (or something).
 
  Cheers,
  Pauli
 
  ___
  NumPy-Discussion mailing list
  NumPy-Discussion@scipy.org
  http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
 Hi,
 I think I managed to find this. I reverted back my svn versions ($svn
 update -r 8262) and cleaned both the build and installation directories.

 It occurred with changeset 8262 (earlier changesets appear okay but
 later ones do not)
 http://projects.scipy.org/numpy/changeset/8262

 Specifically in the file:
 numpy/core/code_generators/generate_ufunc_api.py

 There is an extra call to that should have been deleted on line 54(?).
 Py_DECREF(numpy);

 Attached a patch to ticket 1425
 http://projects.scipy.org/numpy/ticket/1425


Look like my bad. I'm out of town at the moment so someone else needs to
apply the patch. That whole bit of code could probably use a daylight audit.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] numarray iterator question

2010-03-10 Thread Neal Becker
This is a bit confusing to me:

import numpy as np

u = np.ones ((3,3))

for u_row in u:
u_row = u_row * 2   doesn't work

print u
[[ 1.  1.  1.]
 [ 1.  1.  1.]
 [ 1.  1.  1.]]

for u_row in u:
u_row *= 2   does work
[[ 2.  2.  2.]
 [ 2.  2.  2.]
 [ 2.  2.  2.]]

Naively, I'm thinking a *= b === a = a * b.

Is this behavior expected?  I'm asking because I really want:

u_row = my_func (u_row)

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numarray iterator question

2010-03-10 Thread Robert Kern
On Wed, Mar 10, 2010 at 18:19, Neal Becker ndbeck...@gmail.com wrote:
 This is a bit confusing to me:

 import numpy as np

 u = np.ones ((3,3))

 for u_row in u:
    u_row = u_row * 2   doesn't work

 print u
 [[ 1.  1.  1.]
  [ 1.  1.  1.]
  [ 1.  1.  1.]]

 for u_row in u:
    u_row *= 2   does work
 [[ 2.  2.  2.]
  [ 2.  2.  2.]
  [ 2.  2.  2.]]

 Naively, I'm thinking a *= b === a = a * b.

http://docs.python.org/reference/simple_stmts.html#augmented-assignment-statements

An augmented assignment expression like x += 1 can be rewritten as
x = x + 1 to achieve a similar, but not exactly equal effect. In the
augmented version, x is only evaluated once. Also, when possible, the
actual operation is performed in-place, meaning that rather than
creating a new object and assigning that to the target, the old object
is modified instead.

 Is this behavior expected?  I'm asking because I really want:

 u_row = my_func (u_row)

Iterate over indices instead:

for i in range(len(u)):
u[i] = my_func(u[i])

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth.
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numarray iterator question

2010-03-10 Thread Warren Weckesser
Neal Becker wrote:
 This is a bit confusing to me:

 import numpy as np

 u = np.ones ((3,3))

 for u_row in u:
 u_row = u_row * 2   doesn't work

   
Try this instead:

for u_row in u:
u_row[:] = u_row * 2



Warren

 print u
 [[ 1.  1.  1.]
  [ 1.  1.  1.]
  [ 1.  1.  1.]]

 for u_row in u:
 u_row *= 2   does work
 [[ 2.  2.  2.]
  [ 2.  2.  2.]
  [ 2.  2.  2.]]

 Naively, I'm thinking a *= b === a = a * b.

 Is this behavior expected?  I'm asking because I really want:

 u_row = my_func (u_row)

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
   

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion