Re: [Numpy-discussion] Request for testing

2010-02-21 Thread Jochen Schroeder
No Warning for me:

└─(08:26 $)─ python isinf.py 
True


└─(08:26 $)─ python2.5 isinf.py 
True

Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2

Python 2.5.4 (r254:67916, Jan 20 2010, 21:43:02) 
[GCC 4.4.1] on linux2

numpy.version.version
'1.3.0'

└─(08:33 $)─ uname -a
Linux cudos0803 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 02:39:34 UTC 2010
x86_64 GNU/Linux

 └─(08:31 $)─ lsb_release -a
 No LSB modules are available.
 Distributor ID: Ubuntu
 Description:Ubuntu 9.10
 Release: 9.10
 Codename: karmic



On 02/21/10 03:30, Charles R Harris wrote:
 Hi All,
 
 I would be much obliged if some folks would run the attached script and report
 the output, numpy version, and python version. It just runs np.isinf(np.inf),
 which raises an invalid value warning with current numpy. As far as I can 
 see
 the function itself hasn't changed since numpy1.3, yet numpy1.3  python2.5
 gives no such warning.
 
 Chuck

 import numpy as np
 import warnings
 
 warnings.simplefilter('always')
 np.seterr(invalid='print')
 print (np.isinf(np.inf))

 ___
 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] Assigning complex values to a real array

2009-12-08 Thread Jochen Schroeder
On 12/08/09 02:32, David Warde-Farley wrote:
 On 7-Dec-09, at 11:13 PM, Dr. Phillip M. Feldman wrote:
 
  Example #1:
  IPython 0.10   [on Py 2.5.4]
  [~]|1 z= zeros(3)
  [~]|2 z[0]= 1+1J
 
  TypeError: can't convert complex to float; use abs(z)
 
 The problem is that you're using Python's built-in complex type, and  
 it responds to type coercion differently than NumPy types do. Calling  
 float() on a Python complex will raise the exception. Calling float()  
 on (for example) a numpy.complex64 will not. Notice what happens here:
 
 In [14]: z = zeros(3)
 
 In [15]: z[0] = complex64(1+1j)
 
 In [16]: z[0]
 Out[16]: 1.0
 
  Example #2:
 
  ### START OF CODE ###
  from numpy import *
  q = ones(2,dtype=complex)*(1 + 1J)
  r = zeros(2,dtype=float)
  r[:] = q
  print 'q = ',q
  print 'r = ',r
  ### END OF CODE ###
 
 Here, both operands are NumPy arrays. NumPy is in complete control of  
 the situation, and it's well documented what it will do.
 
 I do agree that the behaviour in example #1 is mildly inconsistent,  
 but such is the way with NumPy vs. Python scalars. They are mostly  
 transparently intermingled, except when they're not.
 
  At a minimum, this inconsistency needs to be cleared up.  My  
  preference
  would be that the programmer should have to explicitly downcast from
  complex to float, and that if he/she fails to do this, that an  
  exception be
  triggered.
 
 That would most likely break a *lot* of deployed code that depends on  
 the implicit downcast behaviour. A less harmful solution (if a  
 solution is warranted, which is for the Council of the Elders to  
 decide) would be to treat the Python complex type as a special case,  
 so that the .real attribute is accessed instead of trying to cast to  
 float.

I'm not sure how much code is actually relying on the implicit downcast, but
I'd argue that it's bad programming anyways. It is really difficult to spot if
you reviewing someone else's code. As others mentioned it's also a bitch to
track down a bug that has been accidentally introduced by this behaviour. 

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


Re: [Numpy-discussion] Interactive Shell/Editor/Workspace(variables)View/Plots

2009-06-08 Thread Jochen Schroeder
On 09/06/09 00:16, Gael Varoquaux wrote:
 On Mon, Jun 08, 2009 at 05:14:27PM -0500, Gökhan SEVER wrote:
 IPython's edit command works in a similar fashion, too.
 
 edit test.py
 
 The cool thing is that you can select text in the editor and execute in
 EPDLab. On the other hand, I know that IPython has hooks to grow this in
 the code base, and I would like this to grow also directly in IPython.
 
 Hell, I use vim. How cool would it be to select (using visual mode)
 snippets in vim, and execute them in a running Ipython session.

I think there's a vim script for executing the marked code in python. If
IPython has already hooks for executing code in an existing session, it
might be possible to adapt this script. 
Also I encourage everyone to have a look at pida:
http://pida.co.uk/
which is a python IDE using an embedded vim (although you can embed
other editors as well I think). The website looks like development has
been stale, but if you look at svn there've been commits lately.

Cheers
Jochen
 
 Gaël
 ___
 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] view takes no keyword arguments exception

2009-05-20 Thread Jochen Schroeder
Hi all,

I'm trying to help someone out with some problems with pyfftw
(pyfftw.berlios.de). He is seeing an exception,

TypeError: view() takes no keyword arguments  

This doesn't only happen when he uses pyfftw but also when he does the
following:

 import numpy as np  
 a=np.arange(10)   
 print a.view(dtype='float')
Traceback (most recent call last):  

  File stdin, line 1, in module   

TypeError: view() takes no keyword arguments   

I he's on Windows and sees this error both with numpy 1.1.1 and 1.3.
I'm a bit lost anybody have an idea what could be the problem? 

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


Re: [Numpy-discussion] view takes no keyword arguments exception

2009-05-20 Thread Jochen Schroeder
On 21/05/09 00:20, Stéfan van der Walt wrote:
 Hi Jochen
 
 2009/5/20 Jochen Schroeder cycoma...@gmail.com:
  I'm trying to help someone out with some problems with pyfftw
  (pyfftw.berlios.de). He is seeing an exception,
 
  TypeError: view() takes no keyword arguments
 
  This doesn't only happen when he uses pyfftw but also when he does the
  following:
 
  import numpy as np
  a=np.arange(10)
  print a.view(dtype='float')
  Traceback (most recent call last):
   File stdin, line 1, in module
  TypeError: view() takes no keyword arguments
 
  I he's on Windows and sees this error both with numpy 1.1.1 and 1.3.
  I'm a bit lost anybody have an idea what could be the problem?
 
 In the older versions of numpy, a.view(float) should work (float is
 preferable above 'float' as well), but I would guess that you are
 really looking for
 
 a.astype(float)

Sorry maybe I phrased my question wrongly.  I don't want to change the code 
(This was just a short example).
I just want to know why it is failing on his system and what he
can do so that a.view(dtype='...') is working. I suspected it was an old
numpy installation but the person is saying that he installed a new
version and is still seeing the same problem (or does he just have an
old version of numpy floating around). 

Cheers
Jochen

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


Re: [Numpy-discussion] Construct a large n-dimensional complex matrix

2009-04-07 Thread Jochen Schroeder
On 06/04/09 21:20, Robert Kern wrote:
 On Mon, Apr 6, 2009 at 20:53, Nathan Faggian nfagg...@unimelb.edu.au wrote:
  HI,
  I want to construct a large complex matrix, I have the real and imaginary
  components as double vectors, is there a fast way to construct a complex
  vector in numpy?
 
 C = np.empty((n,m), dtype=complex)
 C.real.flat[:] = real_values
 C.imag.flat[:] = imag_values
 
Just a question, is there any advantage to doing 
C = 1.j *imag_values + real_values
?

Cheers
Jochen
 -- 
 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 mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] numpy.ctypeslib.ndpointer and the restype attribute

2009-03-23 Thread Jochen Schroeder
On 23/03/09 15:40, Sturla Molden wrote:
 Jens Rantil wrote:
  Hi all,
 
  So I have a C-function in a DLL loaded through ctypes. This particular 
  function returns a pointer to a double. In fact I know that this 
  pointer points to the first element in an array of, say for simplicity, 
  200 elements.
 
  How do I convert this pointer to a NumPy array that uses this data (ie. 
  no copy of data in memory)? I am able to create a numpy array using a 
  copy of the data.

 
 def fromaddress(address, nbytes, dtype=double):
 
 class Dummy(object): pass
 
 d = Dummy()
 
 d.__array_interface__ = {
 
  'data' : (address, False),
 
  'typestr' : numpy.uint8.str,
 
  'descr' : numpy.uint8.descr,
 
  'shape' : (nbytes,),
 
  'strides' : None,
 
  'version' : 3
 
 }   
 
 return numpy.asarray(d).view( dtype=dtype )
 

Might I suggest that restype is going to be removed from the  documentation, 
it also cost me quite some time trying to get ndpointer to work with restype 
when I first tried it until I finally came to the conclusion that an
approach like the above is necessary and ndpointer does not work with
restype. 

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