Re: [Numpy-discussion] read ascii file from complex fortran format() -- genfromtxt

2010-09-22 Thread Andrew Jaffe
On 21/09/2010 18:29, David Huard wrote:
 Have you tried

 http://code.google.com/p/python-fortranformat/

 It's not officially released yet but it's probably worth a try.


Well, I noticed it, bugt the website does say This is a work in 
progress, a working version is not yet available!

Andrew



 David H.

 On Tue, Sep 21, 2010 at 8:25 AM, Andrew Jaffe a.h.ja...@gmail.com
 mailto:a.h.ja...@gmail.com wrote:

 Hi all,

 I've got an ascii file with a relatively complicated structure,
 originally written by fortran with the format:

  135format(a12,1x,2(f10.5,1x),i3,1x,4(f9.3,1x),4(i2,1x),3x,
   1 16(f7.2,1x),i3,3x,f13.5,1x,f10.5,1x,f10.6,1x,i3,1x,
   2 4(f10.6,1x),
   2 i2,1x,f5.2,1x,f10.3,1x,i3,1x,f7.2,1x,f7.2,3x,4(f7.4,1x),
   3 4(f7.2,1x),3x,f7.2,1x,i4,3x,f10.3,1x,14(f6.2,1x),i3,1x,
   1  3x,2f10.5,8f11.2,2f10.5,f12.3,3x,
   4 2(a6,1x),a23,1x,a22,1x,a22)

 Note, in particular, that many of the strings contain white space.

 Is there a relatively straightforward way to translate this into  dtype
 (and delimiter?) arguments for use with genfromtxt or do I just have to
 do it by hand?

 Andrew
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org mailto: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] read ascii file from complex fortran format() -- genfromtxt

2010-09-22 Thread Pierre GM

On Sep 21, 2010, at 2:25 PM, Andrew Jaffe wrote:

 Hi all,
 
 I've got an ascii file with a relatively complicated structure, 
 originally written by fortran with the format:
 
 135format(a12,1x,2(f10.5,1x),i3,1x,4(f9.3,1x),4(i2,1x),3x,
  1 16(f7.2,1x),i3,3x,f13.5,1x,f10.5,1x,f10.6,1x,i3,1x,
  2 4(f10.6,1x),
  2 i2,1x,f5.2,1x,f10.3,1x,i3,1x,f7.2,1x,f7.2,3x,4(f7.4,1x),
  3 4(f7.2,1x),3x,f7.2,1x,i4,3x,f10.3,1x,14(f6.2,1x),i3,1x,
  1  3x,2f10.5,8f11.2,2f10.5,f12.3,3x,
  4 2(a6,1x),a23,1x,a22,1x,a22)
 
 Note, in particular, that many of the strings contain white space.
 
 Is there a relatively straightforward way to translate this into  dtype 
 (and delimiter?) arguments for use with genfromtxt or do I just have to 
 do it by hand?

By hand might be the easiest. If possible, try to put the empty spaces at the 
beginning of the string (eg, your 3x,f13.5 would be 16 characters). Use 
`autostrip=True`. Use a sequence as delimiter (like in your case 
(12,11,11,3,10,10,10,10,3,3,10,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,16...)), that 
should be more efficient.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtype from |S10 to object in array?

2010-09-22 Thread josef . pktd
On Wed, Sep 22, 2010 at 2:04 AM, keekychen.shared
keekychen.sha...@gmail.com wrote:
  Dear All,

 See below code pls,

 import sicpy
 import numpy as np

 x = np.zeros((2,),dtype=('i4,f4,a10'))
 x[:] = [(1,2.,'Hello'),(2,3.,World)]

 y = x['f2']
 #array(['Hello', 'World'],
      dtype='|S10')

 x['f2'] = y
 x
 #array([(1, 2.0, 'Hello'), (2, 3.0, 'World')],
      dtype=[('f0', 'i4'), ('f1', 'f4'), ('f2', '|S10')])

 y = y.astype('object')
 y
 array([Hello, World], dtype=object)


 x['f2'] = y
 array([(1, 2.0, 'HellWorld'), (2, 3.0, '\x00\x00\x00\x00\x00\x00\x18')],
      dtype=[('f0', 'i4'), ('f1', 'f4'), ('f2', '|S10')])

 ##here comes the problem: the f2 col type has not been changed and the
 data is not I wanted...
 

 here is why I need using this:
 suppose I have a datasource, csv, sql based db or what ever look like this:

 1, 2.0, 'Hello'
 2, 3.0, 'World'
 3, 2.0, 'other string'

 I want to read them to a numpy array and process it's columns, it has no
 problem for processing the float or int type but string.
 After reading the manual and found the object dtype may store variable
 string then I want to exact the string col into an new array, try to
 process it then store back to the numpy matrix then store it back to
 the data source.

 May I know how I can do that? I do not care performance now.


I *guess* that you can do this by changing only the type of the string
column to object

dt = np.dtype([('f0', 'i4'), ('f1', 'f4'), ('f2', object)])


 x = np.zeros((2,),dtype=('i4,f4,O'))
 x[:] = [(1,2.,'Hello'),(2,3.,World)]
 x
array([(1, 2.0, 'Hello'), (2, 3.0, 'World')],
  dtype=[('f0', 'i4'), ('f1', 'f4'), ('f2', '|O4')])
 x['f2'] = 'hello'
 x
array([(1, 2.0, 'hello'), (2, 3.0, 'hello')],
  dtype=[('f0', 'i4'), ('f1', 'f4'), ('f2', '|O4')])


Josef



 Thanks for any hints

 Rgs,

 KC







 ___
 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] searching binary data

2010-09-22 Thread Neal Becker
A colleague of mine posed the following problem.  He wants to search large 
files of binary data for sequences.

I thought of using mmap (to avoid reading all data into memory at once) and 
then turning this into a numpy array (using buffer=).

But, how to then efficiently find a sequence? 

Note that I'm not committed to using numpy or mmap as part of the solution.

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


Re: [Numpy-discussion] searching binary data

2010-09-22 Thread David Cournapeau
On Wed, Sep 22, 2010 at 11:10 PM, Neal Becker ndbeck...@gmail.com wrote:
 A colleague of mine posed the following problem.  He wants to search large
 files of binary data for sequences.


Is there a reason why you cannot use one of the classic string search
algorithms applied to the bytestream ?

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


Re: [Numpy-discussion] searching binary data

2010-09-22 Thread Neal Becker
David Cournapeau wrote:

 On Wed, Sep 22, 2010 at 11:10 PM, Neal Becker ndbeck...@gmail.com wrote:
 A colleague of mine posed the following problem.  He wants to search
 large files of binary data for sequences.

 
 Is there a reason why you cannot use one of the classic string search
 algorithms applied to the bytestream ?
 

What would you suggest?  Keep in mind the file is to big to fit into memory 
all at once.

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


Re: [Numpy-discussion] printable random seed ?

2010-09-22 Thread Robert Kern
On Wed, Sep 22, 2010 at 09:27,  josef.p...@gmail.com wrote:
 I would like to generate random numbers based on a random seed, for
 example what numpy.random does if the seed is not specified. But I
 would also like to print out the initial state, so I can replicate the
 random numbers.

 Can I get a human readable or printable version of the initial state?

[~]
|13 prng = np.random.RandomState()

[~]
|14 prng2 = np.random.RandomState()

[~]
|15 prng.randint(100, size=10)
array([74, 62, 56, 94, 86, 59, 69, 94, 42, 18])

[~]
|16 prng2.randint(100, size=10)
array([21, 58, 34, 55,  9, 81, 45,  3, 93, 62])

[~]
|17 prng2.set_state(prng.get_state())

[~]
|18 prng.randint(100, size=10)
array([37, 57,  2,  0, 68,  9, 75, 88, 11,  7])

[~]
|19 prng2.randint(100, size=10)
array([37, 57,  2,  0, 68,  9, 75, 88, 11,  7])

[~]
|20 prng.get_state()

('MT19937',
 array([1368120112,  957462593, 2623310617, 4207155283,  446940397,
   3506388262, 4104366519,  371500243, 4029407620,  899392379,

   1843090101, 248497, 4085469971,  306955884,   23307203,
   1640066622,   48186677,  637144011,  854838500], dtype=uint32),
 26,
 0,
 2.5933437794758841e-288)

 Alternatively, what's a good way to  randomly generate an initial
 state?

np.random.RandomState() will do the best thing on each platform.

-- 
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] searching binary data

2010-09-22 Thread Robert Kern
On Wed, Sep 22, 2010 at 09:10, Neal Becker ndbeck...@gmail.com wrote:
 A colleague of mine posed the following problem.  He wants to search large
 files of binary data for sequences.

 I thought of using mmap (to avoid reading all data into memory at once) and
 then turning this into a numpy array (using buffer=).

 But, how to then efficiently find a sequence?

mmap objects have most of the usual string methods:


[~]
|2 f = open('./scratch/foo.py', 'r+b')

[~]
|4 m = mmap.mmap(f.fileno(), 0)

[~]
|6 m.find('import')
11

[~]
|7 m[11:17]
'import'


-- 
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


[Numpy-discussion] [PATCH] F2Py on Python 3

2010-09-22 Thread Lisandro Dalcin
It seems that lib2to3 does not process the main f2py bootstrap script
that gets autogenerated by f2py's setup.py. The trivial patch below
replaces the print statements with sys.stderr.write() calls. After
that change, f2py works just fine in Python 3.2


Index: numpy/f2py/setup.py
===
--- numpy/f2py/setup.py (revision 8716)
+++ numpy/f2py/setup.py (working copy)
@@ -62,7 +62,7 @@
 except ValueError: pass
 os.environ[NO_SCIPY_IMPORT]=f2py
 if mode==g3-numpy:
-print  sys.stderr, G3 f2py support is not implemented, yet.
+sys.stderr.write(G3 f2py support is not implemented, yet.\n)
 sys.exit(1)
 elif mode==2e-numeric:
 from f2py2e import main
@@ -72,7 +72,7 @@
 elif mode==2e-numpy:
 from numpy.f2py import main
 else:
-print  sys.stderr, Unknown mode:,`mode`
+sys.stderr.write(Unknown mode: '%s'\n % mode)
 sys.exit(1)
 main()
 '''%(os.path.basename(sys.executable)))


-- 
Lisandro Dalcin
---
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] searching binary data

2010-09-22 Thread David Cournapeau
On Wed, Sep 22, 2010 at 11:25 PM, Neal Becker ndbeck...@gmail.com wrote:
 David Cournapeau wrote:

 On Wed, Sep 22, 2010 at 11:10 PM, Neal Becker ndbeck...@gmail.com wrote:
 A colleague of mine posed the following problem.  He wants to search
 large files of binary data for sequences.


 Is there a reason why you cannot use one of the classic string search
 algorithms applied to the bytestream ?


 What would you suggest?  Keep in mind the file is to big to fit into memory
 all at once.

Do you care about speed ? String search and even regular expression
are supposed to work on mmap data, but I have never used them on large
datasets, so I don't know how they would perform.

Otherwise, depending on the data and whether you can afford
pre-computing, algorithms like Knuth Morris Pratt can speed things up.
But I would assume you would have to do it in C to hope any speed gain
compared to python string search .

cheers,

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


Re: [Numpy-discussion] [PATCH] F2Py on Python 3

2010-09-22 Thread Charles R Harris
On Wed, Sep 22, 2010 at 8:35 AM, Lisandro Dalcin dalc...@gmail.com wrote:

 It seems that lib2to3 does not process the main f2py bootstrap script
 that gets autogenerated by f2py's setup.py. The trivial patch below
 replaces the print statements with sys.stderr.write() calls. After
 that change, f2py works just fine in Python 3.2


 Index: numpy/f2py/setup.py
 ===
 --- numpy/f2py/setup.py (revision 8716)
 +++ numpy/f2py/setup.py (working copy)
 @@ -62,7 +62,7 @@
 except ValueError: pass
  os.environ[NO_SCIPY_IMPORT]=f2py
  if mode==g3-numpy:
 -print  sys.stderr, G3 f2py support is not implemented, yet.
 +sys.stderr.write(G3 f2py support is not implemented, yet.\n)
 sys.exit(1)
  elif mode==2e-numeric:
 from f2py2e import main
 @@ -72,7 +72,7 @@
  elif mode==2e-numpy:
 from numpy.f2py import main
  else:
 -print  sys.stderr, Unknown mode:,`mode`
 +sys.stderr.write(Unknown mode: '%s'\n % mode)
 sys.exit(1)
  main()
  '''%(os.path.basename(sys.executable)))



Looks reasonable. Want to try running this through the git process just for
practice? Of course, it is only two lines so if git seems a bit much I'll
make the change for you.

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


Re: [Numpy-discussion] slicing / indexing question

2010-09-22 Thread Anne Archibald
On 21 September 2010 19:20, Timothy W. Hilton hil...@meteo.psu.edu wrote:

 I have an 80x1200x1200 nd.array of floats this_par.  I have a
 1200x1200 boolean array idx, and an 80-element float array pars.  For
 each element of idx that is True, I wish to replace the corresponding
 80x1x1 slice of this_par with the elements of pars.

 I've tried lots of variations on the theme of
this_par[idx[np.newaxis, ...]] = pars[:, np.newaxis, np.newaxis]
 but so far, no dice.

How about this?


In [1]: A = np.zeros((2,3,5))

In [2]: B = np.array([1,2])

In [3]: C = np.zeros((3,5), dtype=np.bool)

In [4]: C[1,1] = True

In [5]: C[2,3] = True

In [6]: C
Out[6]:
array([[False, False, False, False, False],
   [False,  True, False, False, False],
   [False, False, False,  True, False]], dtype=bool)

In [7]: A[:,C] = B[:,np.newaxis]

In [8]: A
Out[8]:
array([[[ 0.,  0.,  0.,  0.,  0.],
[ 0.,  1.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  1.,  0.]],

   [[ 0.,  0.,  0.,  0.,  0.],
[ 0.,  2.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  2.,  0.]]])

The key is that indexing with C replaces the two axes C is indexing
with only one; boolean indexing necessarily flattens the relevant
axes. You can check this with (e.g.) A[:,C].shape.

Be careful with these mixed indexing modes (partly fancy indexing,
partly slicing) as they can sometimes seem to reorder your axes for
you:

In [16]: np.zeros((2,3,7))[:,np.ones(5,dtype=int),np.ones(5,dtype=int)].shape
Out[16]: (2, 5)

In [17]: np.zeros((2,3,7))[np.ones(5,dtype=int),:,np.ones(5,dtype=int)].shape
Out[17]: (5, 3)

In [18]: np.zeros((2,3,7))[np.ones(5,dtype=int),np.ones(5,dtype=int),:].shape
Out[18]: (5, 7)

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


Re: [Numpy-discussion] Removing numpy numpy-1.1.0 in Python 2.5

2010-09-22 Thread Christopher Barker
Wayne Watson wrote:
   I've considered it, but it's way too time consuming to work out the 
 details.  I spent a week some time ago dealing with a simple test 
 program, maybe 10 lines of code, trying to get it to work, which I think 
 I did.  I just need to work what I've got.

There is a lot to be said for something that works already.

However, I think it is generally a bad idea to distribute software based 
on python that relies on the standard python install with particular 
packages -- this will only work if you assume that that machine will not 
use python for anything else -- if two pieces of software both do this, 
  but need different versions of packages, you are guaranteed breakage.

RedHat did it with python way back when (I have no idea if they've 
changed that -- but it was pain).

ESRI (GIS system) delivers the standard Windows Python version something 
with its GIS tools, and things break if you upgrade parts of it.

Apple uses its system Python for some of its admin tools, and again, 
relies on who knows which versions of which packages.

All this points to delivering python to your users separately from the 
standard install.

If it's one app, use py2exe, py2app, pyInstaller, bbfreeze, whatever.

If it's a collection of apps, you may want to built it on a custom 
python install, and/or maybe virtualenv.

Anyway, if you know your users, and know they will, for sure, not use 
Python for anything else, then it's not a problem, but I think it's hard 
to know that.

py2exe can be a pain, but it's usually short term pain -- once you have 
it working for your project, it keeps working (untill you add a new 
package anyway...)

-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] Asking for opinions: Priops

2010-09-22 Thread Sebastian Walter
Hello Friedrich,

I have read your proposal. You describe issues that I have also
encountered several times.
I believe that your priops approach would be an improvement over the
current overloading of binary operators.
That being said, I think the issue is not so much numpy but rather the
way Python implements operator overloading using methods like __add__
and __radd__.  Hence, your suggestion seems to be a Python Enhancement
Proposal and should be discussed without any references to numpy or
bugs related to numpy.set_numeric_ops.
Maybe you could also have a look at Go's interfaces (Googles
programming language) which seems to be somewhat related to your
approach. Also, have you checked the Python mail archive? Issues like
that tend to be discussed from time to time.

On a more practical note: Why exactly do you use set_numeric_ops? You
could also
1) use numpy.ndarrays with dtype=object
2) or create new numpy.ndarray -like class and set  __array_priority__  2
both approaches work well for me.

just my 2 cents,
Sebastian



On Thu, Sep 16, 2010 at 2:02 PM, Friedrich Romstedt
friedrichromst...@gmail.com wrote:
 I just ran across the problem of priorities with ndarrays again and it
 keeps biting me.  I did once ago a workaround to get my ``undarray``
 class's methods be called when being the second operand of e.g.
 ndarray + undarray.  But since I wrote it, always Python crashes
 on exit with the message:

 Python-32(68665) malloc: *** error for object 0x239680: incorrect
 checksum for freed object - object was probably modified after being
 freed.
 *** set a breakpoint in malloc_error_break to debug

 (Of course only if I imported the module.  Occasionally I also
 observed Bus errors, and even segfaults.)
 I overloaded the numpy ops via numpy.set_numeric_ops() with
 self-written classes, which are *not* derived from numpy.ufunc, and do
 not resemble numpy ufuncs completely.

 So I want to do it properly this time.

 I therefore started with writing a Letter of Intent, and put it online
 on http://github.com/friedrichromstedt/priops .

 Opinions?

 Friedrich

 P.S.: I will start coding anyway, but it would be nice.

 P.P.S.: The package this originates from is also online, under
 http://github.com/friedrichromstedt/upy, or
 http://upy.sourceforge.net.  I will probably create a small example
 script demonstrating the crash.
 ___
 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] Indexing and lookup issues

2010-09-22 Thread Ross Williamson
Hi everyone

I suspect this is easy but I'm stuck

say I have a 1D array:

t = [10,11,12]

and a 2D array:

id = [[0,1,0]
[0,2,0]
[2,0,2]]

In could in IDL do y = t[id] which would produce:

y = [[10,11,10]
[10,12,10]
[12,10,12]]

i.e. use the indexes in id on the lookup array t.

Is there an easy way to do this in numpy?

Cheers
Ross

-- 
Ross Williamson
University of Chicago
Department of Astronomy  Astrophysics
773-834-9785 (office)
312-504-3051 (Cell)
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Indexing and lookup issues

2010-09-22 Thread Anne Archibald
On 22 September 2010 16:38, Ross Williamson
rosswilliamson@gmail.com wrote:
 Hi everyone

 I suspect this is easy but I'm stuck

 say I have a 1D array:

 t = [10,11,12]

 and a 2D array:

 id = [[0,1,0]
 [0,2,0]
 [2,0,2]]

 In could in IDL do y = t[id] which would produce:

 y = [[10,11,10]
 [10,12,10]
 [12,10,12]]

 i.e. use the indexes in id on the lookup array t.

 Is there an easy way to do this in numpy?

In [1]: t = np.array([10,11,12])

In [2]: id = np.array([[0,1,0], [0,2,0], [2,0,2]])

In [3]: t[id]
Out[3]:
array([[10, 11, 10],
   [10, 12, 10],
   [12, 10, 12]])

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


Re: [Numpy-discussion] Asking for opinions: Priops

2010-09-22 Thread Charles R Harris
On Wed, Sep 22, 2010 at 1:31 PM, Sebastian Walter 
sebastian.wal...@gmail.com wrote:

 Hello Friedrich,

 I have read your proposal. You describe issues that I have also
 encountered several times.
 I believe that your priops approach would be an improvement over the
 current overloading of binary operators.
 That being said, I think the issue is not so much numpy but rather the
 way Python implements operator overloading using methods like __add__
 and __radd__.  Hence, your suggestion seems to be a Python Enhancement
 Proposal and should be discussed without any references to numpy or
 bugs related to numpy.set_numeric_ops.
 Maybe you could also have a look at Go's interfaces (Googles
 programming language) which seems to be somewhat related to your
 approach. Also, have you checked the Python mail archive? Issues like
 that tend to be discussed from time to time.

 On a more practical note: Why exactly do you use set_numeric_ops? You
 could also
 1) use numpy.ndarrays with dtype=object
 2) or create new numpy.ndarray -like class and set  __array_priority__  2
 both approaches work well for me.

 just my 2 cents,
 Sebastian



 On Thu, Sep 16, 2010 at 2:02 PM, Friedrich Romstedt
 friedrichromst...@gmail.com wrote:
  I just ran across the problem of priorities with ndarrays again and it
  keeps biting me.  I did once ago a workaround to get my ``undarray``
  class's methods be called when being the second operand of e.g.
  ndarray + undarray.  But since I wrote it, always Python crashes
  on exit with the message:
 
  Python-32(68665) malloc: *** error for object 0x239680: incorrect
  checksum for freed object - object was probably modified after being
  freed.
  *** set a breakpoint in malloc_error_break to debug
 
  (Of course only if I imported the module.  Occasionally I also
  observed Bus errors, and even segfaults.)
  I overloaded the numpy ops via numpy.set_numeric_ops() with
  self-written classes, which are *not* derived from numpy.ufunc, and do
  not resemble numpy ufuncs completely.
 
  So I want to do it properly this time.
 
  I therefore started with writing a Letter of Intent, and put it online
  on http://github.com/friedrichromstedt/priops .
 
  Opinions?
 
  Friedrich
 
  P.S.: I will start coding anyway, but it would be nice.
 
  P.P.S.: The package this originates from is also online, under
  http://github.com/friedrichromstedt/upy, or
  http://upy.sourceforge.net.  I will probably create a small example
  script demonstrating the crash.
  ___
  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] [PATCH] F2Py on Python 3

2010-09-22 Thread Charles R Harris
On Wed, Sep 22, 2010 at 12:08 PM, Lisandro Dalcin dalc...@gmail.com wrote:

 On 22 September 2010 13:48, Charles R Harris charlesr.har...@gmail.com
 wrote:
 
 
  On Wed, Sep 22, 2010 at 8:35 AM, Lisandro Dalcin dalc...@gmail.com
 wrote:
 
  It seems that lib2to3 does not process the main f2py bootstrap script
  that gets autogenerated by f2py's setup.py. The trivial patch below
  replaces the print statements with sys.stderr.write() calls. After
  that change, f2py works just fine in Python 3.2
 
 
  Index: numpy/f2py/setup.py
  ===
  --- numpy/f2py/setup.py (revision 8716)
  +++ numpy/f2py/setup.py (working copy)
  @@ -62,7 +62,7 @@
  except ValueError: pass
   os.environ[NO_SCIPY_IMPORT]=f2py
   if mode==g3-numpy:
  -print  sys.stderr, G3 f2py support is not implemented, yet.
  +sys.stderr.write(G3 f2py support is not implemented, yet.\n)
  sys.exit(1)
   elif mode==2e-numeric:
  from f2py2e import main
  @@ -72,7 +72,7 @@
   elif mode==2e-numpy:
  from numpy.f2py import main
   else:
  -print  sys.stderr, Unknown mode:,`mode`
  +sys.stderr.write(Unknown mode: '%s'\n % mode)
  sys.exit(1)
   main()
   '''%(os.path.basename(sys.executable)))
 
 
 
  I'm also wondering if we shouldn't raise an error instead of writing to
  stderr.
 

 sys.exit(1) below the sys.stderr.write() is supposed to exit Python
 with an error status to the invoker of f2py. So I think nothing more
 have to be done.



Done in  29cccb6.

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


Re: [Numpy-discussion] [PATCH] F2Py on Python 3

2010-09-22 Thread Fernando Perez
On Wed, Sep 22, 2010 at 7:16 PM, Charles R Harris
charlesr.har...@gmail.com wrote:

 Done in  29cccb6.


Mmh, I think it broke something:

  File /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build.py,
line 37, in run
old_build.run(self)
  File /usr/lib/python2.6/distutils/command/build.py, line 135, in run
self.run_command(cmd_name)
  File /usr/lib/python2.6/distutils/cmd.py, line 333, in run_command
self.distribution.run_command(command)
  File /usr/lib/python2.6/distutils/dist.py, line 995, in run_command
cmd_obj.run()
  File 
/home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
line 39, in run
self.scripts = self.generate_scripts(self.scripts)
  File 
/home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
line 24, in generate_scripts
script = func(build_dir)
  File numpy/f2py/setup.py, line 78, in generate_f2py_py
'''%(os.path.basename(sys.executable)))
TypeError: not enough arguments for format string

If I revert to the previous commit, it installs fine again.

Cheers,

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


Re: [Numpy-discussion] [PATCH] F2Py on Python 3

2010-09-22 Thread Charles R Harris
On Wed, Sep 22, 2010 at 9:14 PM, Fernando Perez fperez@gmail.comwrote:

 On Wed, Sep 22, 2010 at 7:16 PM, Charles R Harris
 charlesr.har...@gmail.com wrote:
 
  Done in  29cccb6.
 

 Mmh, I think it broke something:

  File /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build.py,
 line 37, in run
old_build.run(self)
  File /usr/lib/python2.6/distutils/command/build.py, line 135, in run
self.run_command(cmd_name)
  File /usr/lib/python2.6/distutils/cmd.py, line 333, in run_command
self.distribution.run_command(command)
  File /usr/lib/python2.6/distutils/dist.py, line 995, in run_command
cmd_obj.run()
  File
 /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
 line 39, in run
self.scripts = self.generate_scripts(self.scripts)
  File
 /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
 line 24, in generate_scripts
script = func(build_dir)
  File numpy/f2py/setup.py, line 78, in generate_f2py_py
 '''%(os.path.basename(sys.executable)))
 TypeError: not enough arguments for format string

 If I revert to the previous commit, it installs fine again.


I wondered about that, it is probably the old `mode` vs  plain old mode. I
had just hoped it was tested. Can you check that out?

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


Re: [Numpy-discussion] [PATCH] F2Py on Python 3

2010-09-22 Thread Charles R Harris
On Wed, Sep 22, 2010 at 10:00 PM, Charles R Harris 
charlesr.har...@gmail.com wrote:



 On Wed, Sep 22, 2010 at 9:14 PM, Fernando Perez fperez@gmail.comwrote:

 On Wed, Sep 22, 2010 at 7:16 PM, Charles R Harris
 charlesr.har...@gmail.com wrote:
 
  Done in  29cccb6.
 

 Mmh, I think it broke something:

  File /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build.py,
 line 37, in run
old_build.run(self)
  File /usr/lib/python2.6/distutils/command/build.py, line 135, in run
self.run_command(cmd_name)
  File /usr/lib/python2.6/distutils/cmd.py, line 333, in run_command
self.distribution.run_command(command)
  File /usr/lib/python2.6/distutils/dist.py, line 995, in run_command
cmd_obj.run()
  File
 /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
 line 39, in run
self.scripts = self.generate_scripts(self.scripts)
  File
 /home/fperez/tmp/src/scipy/numpy/numpy/distutils/command/build_scripts.py,
 line 24, in generate_scripts
script = func(build_dir)
  File numpy/f2py/setup.py, line 78, in generate_f2py_py
 '''%(os.path.basename(sys.executable)))
 TypeError: not enough arguments for format string

 If I revert to the previous commit, it installs fine again.


 I wondered about that, it is probably the old `mode` vs  plain old mode. I
 had just hoped it was tested. Can you check that out?


Should be fixed in 8f6114b.

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