Re: [Numpy-discussion] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

2009-06-09 Thread Pauli Virtanen
Sun, 07 Jun 2009 12:09:40 +0200, Sebastian Walter wrote:
 from numpy import *
 import numpy
 print 'numpy.__version__=',numpy.__version__
 
 class adouble:
def __init__(self,x):
self.x = x
def __mul__(self,rhs):
if isinstance(rhs,adouble):
return adouble(self.x * rhs.x)
else:
return adouble(self.x * rhs)
def __str__(self):
return str(self.x)
[clip]
 print u * float64(3.)# _NOT_ OK!
[clip]
 
 Should I open a ticket for that?

Please do, the current behavior doesn't seem correct.

-- 
Pauli Virtanen

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


Re: [Numpy-discussion] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

2009-06-07 Thread Sebastian Walter
Apparently the bugfix has been undone in the current bleeding edge
version of numpy:


--- numpy_float64_issue.py
--
from numpy import *
import numpy
print 'numpy.__version__=',numpy.__version__

class adouble:
   def __init__(self,x):
   self.x = x
   def __mul__(self,rhs):
   if isinstance(rhs,adouble):
   return adouble(self.x * rhs.x)
   else:
   return adouble(self.x * rhs)
   def __str__(self):
   return str(self.x)

x = adouble(3.)
y = adouble(2.)
u = array([adouble(3.), adouble(5.)])
v = array([adouble(2.), adouble(7.)])
z = array([2.,3.])

print x * y  # ok
print u * v  # ok
print u * z  # ok
print u * 3. # ok
print u * z[0]   # _NOT_ OK!
print u * float64(3.)# _NOT_ OK!

 end  numpy_float64_issue.py  --

OUTPUT:

ba...@shlp:~/tmp$ python numpy_float64_issue.py
numpy.__version__= 1.4.0.dev7039
6.0
[6.0 35.0]
[6.0 15.0]
[9.0 15.0]
Traceback (most recent call last):
  File numpy_float64_issue.py, line 26, in module
print u * z[0]   # _NOT_ OK!
TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and
'numpy.float64'


Should I open a ticket for that?

Sebastian

On Tue, Jun 2, 2009 at 4:18 PM, Darren Daledsdal...@gmail.com wrote:


 On Tue, Jun 2, 2009 at 10:09 AM, Keith Goodman kwgood...@gmail.com wrote:

 On Tue, Jun 2, 2009 at 1:42 AM, Sebastian Walter
 sebastian.wal...@gmail.com wrote:
  Hello,
  Multiplying a Python float to a numpy.array of objects works flawlessly
  but not with a numpy.float64 .
  I tried  numpy version '1.0.4' on a 32 bit Linux and  '1.2.1' on a 64
  bit Linux: both raise the same exception.
 
  Is this a (known) bug?

 Yes, it was fixed in numpy-1.3.

 ___
 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] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

2009-06-02 Thread Keith Goodman
On Tue, Jun 2, 2009 at 1:42 AM, Sebastian Walter
sebastian.wal...@gmail.com wrote:
 Hello,
 Multiplying a Python float to a numpy.array of objects works flawlessly
 but not with a numpy.float64 .
 I tried  numpy version '1.0.4' on a 32 bit Linux and  '1.2.1' on a 64
 bit Linux: both raise the same exception.

 Is this a (known) bug?

 -- test.py 
 from numpy import *

 class adouble:
        def __init__(self,x):
                self.x = x
        def __mul__(self,rhs):
                if isinstance(rhs,adouble):
                        return adouble(self.x * rhs.x)
                else:
                        return adouble(self.x * rhs)
        def __str__(self):
                return str(self.x)

 x = adouble(3.)
 y = adouble(2.)
 u = array([adouble(3.), adouble(5.)])
 v = array([adouble(2.), adouble(7.)])
 z = array([2.,3.])

 print x * y              # ok
 print u * v              # ok
 print u * z              # ok
 print u * 3.             # ok
 print u * z[0]           # _NOT_ OK!
 print u * float64(3.)    # _NOT_ OK!



 -- output   -
 wal...@wronski$ python test.py
 6.0
 [6.0 35.0]
 [6.0 15.0]
 [9.0 15.0]
 Traceback (most recent call last):
  File test.py, line 24, in module
    print u * z[0]   # _NOT_ OK!
 TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and
 'numpy.float64'

Try adding __rmul__ = __mul__ like below:

from numpy import *

class adouble:
def __init__(self,x):
self.x = x
def __mul__(self,rhs):
if isinstance(rhs,adouble):
return adouble(self.x * rhs.x)
else:
return adouble(self.x * rhs)
__rmul__ = __mul__
def __str__(self):
return str(self.x)

def test():
x = adouble(3.)
print 3 * x

Output:

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


Re: [Numpy-discussion] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

2009-06-02 Thread Darren Dale
On Tue, Jun 2, 2009 at 10:09 AM, Keith Goodman kwgood...@gmail.com wrote:

 On Tue, Jun 2, 2009 at 1:42 AM, Sebastian Walter
 sebastian.wal...@gmail.com wrote:
  Hello,
  Multiplying a Python float to a numpy.array of objects works flawlessly
  but not with a numpy.float64 .
  I tried  numpy version '1.0.4' on a 32 bit Linux and  '1.2.1' on a 64
  bit Linux: both raise the same exception.
 
  Is this a (known) bug?


Yes, it was fixed in numpy-1.3.
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Multiplying Python float to numpy.array of objects works but fails with a numpy.float64, numpy Bug?

2009-06-02 Thread Sebastian Walter
On Tue, Jun 2, 2009 at 4:18 PM, Darren Dale dsdal...@gmail.com wrote:


 On Tue, Jun 2, 2009 at 10:09 AM, Keith Goodman kwgood...@gmail.com wrote:

 On Tue, Jun 2, 2009 at 1:42 AM, Sebastian Walter
 sebastian.wal...@gmail.com wrote:
  Hello,
  Multiplying a Python float to a numpy.array of objects works flawlessly
  but not with a numpy.float64 .
  I tried  numpy version '1.0.4' on a 32 bit Linux and  '1.2.1' on a 64
  bit Linux: both raise the same exception.
 
  Is this a (known) bug?


 Yes, it was fixed in numpy-1.3.

ok, cool
thanks for the info!


 ___
 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