Re: [Numpy-discussion] Strange Error with NumPy Addendum

2009-08-12 Thread Robert Kern
On Fri, Aug 7, 2009 at 07:15, Nanime Puloskinpulo...@gmail.com wrote:
 But if it were an unsigned int64, it should be able to hold 2**64 or at
 least 2**64-1.
 Am I correct?

There is no numpy.sin() implementation for uint64s, just the floating
point types.

-- 
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] Strange Error with NumPy Addendum

2009-08-07 Thread Nanime Puloski
But if it were an unsigned int64, it should be able to hold 2**64 or at
least 2**64-1.
Am I correct?

On Fri, Aug 7, 2009 at 1:03 AM, David Warde-Farley d...@cs.toronto.eduwrote:

 On 6-Aug-09, at 7:29 PM, Robert Kern wrote:

  For that value, yes, but not for long objects in general. We don't
  look at the value itself, just the type.

 Err, don't look at the value (of a long), except when it's
 representable with an integer dtype, right? Hence why 2**63 - 1 works.

 David
 ___
 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] Strange Error with NumPy

2009-08-06 Thread Nanime Puloski
Can anyone explain to me why I receive an error(AtrributeError) in NumPy
when I do numpy.sin(2**64), but not when I do numpy.sin(2.0**64),
numpy.sin(float(2**64)) or even numpy.sin(2)?

Where is the root problem in all of this?
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Strange Error with NumPy

2009-08-06 Thread Robert Kern
On Thu, Aug 6, 2009 at 17:01, Nanime Puloskinpulo...@gmail.com wrote:
 Can anyone explain to me why I receive an error(AtrributeError) in NumPy
 when I do numpy.sin(2**64), but not when I do numpy.sin(2.0**64),
 numpy.sin(float(2**64)) or even numpy.sin(2)?

 Where is the root problem in all of this?

numpy deals with objects that can be natively represented by the C
numerical types on your machine. On your machine 2**64 gives you a
Python long object which cannot be converted to one of the native C
numerical types, so numpy.sin() treats it as a regular Python object.
The default implementation of all of the ufuncs when faced with a
Python object it doesn't know about is to look for a method on the
object of the same name. long.sin() does not exist, so you get an
AttributeError.

-- 
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] Strange Error with NumPy

2009-08-06 Thread David Warde-Farley
On 6-Aug-09, at 6:01 PM, Nanime Puloski wrote:

 Can anyone explain to me why I receive an error(AtrributeError) in  
 NumPy
 when I do numpy.sin(2**64), but not when I do numpy.sin(2.0**64),
 numpy.sin(float(2**64)) or even numpy.sin(2)?

In [6]: type(2**64)
Out[6]: type 'long'

In [7]: type(2)
Out[7]: type 'int'

In [8]: type(2.0**64)
Out[8]: type 'float'

Probably because 2**64 yields a long, which is an arbitrary precision  
type in Python, and numpy is having trouble casting it to something it  
can use (it's too big for numpy.int64). Notice that np.sin(2**63 - 1)  
works fine while np.sin(2**63) doesn't - 2**63 - 1 is the largest  
value that an int64 can hold.

You're right that it could be approximately represented as a float32  
or float64, but numpy won't cast from exact types to inexact types  
without you telling it to do so.

I agree that the error message is less than ideal.

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


[Numpy-discussion] Strange Error with NumPy Addendum

2009-08-06 Thread Nanime Puloski
Thank you for your responses so far.
What I also do not understand is why sin(2**64) works with
the standard Python math module, but fails to do so with NumPy?

To Robert Kern:
Can't 2^64 be represented in C as a long double?
It seems to work well on my machine.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Strange Error with NumPy Addendum

2009-08-06 Thread Robert Kern
On Thu, Aug 6, 2009 at 18:26, Nanime Puloskinpulo...@gmail.com wrote:
 Thank you for your responses so far.
 What I also do not understand is why sin(2**64) works with
 the standard Python math module, but fails to do so with NumPy?

math.sin() always converts the argument to a float. We do not.

 To Robert Kern:
 Can't 2^64 be represented in C as a long double?

For that value, yes, but not for long objects in general. We don't
look at the value itself, just the type.

-- 
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] Strange Error with NumPy Addendum

2009-08-06 Thread David Warde-Farley
On 6-Aug-09, at 7:29 PM, Robert Kern wrote:

 For that value, yes, but not for long objects in general. We don't
 look at the value itself, just the type.

Err, don't look at the value (of a long), except when it's  
representable with an integer dtype, right? Hence why 2**63 - 1 works.

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


Re: [Numpy-discussion] Strange Error with NumPy Addendum

2009-08-06 Thread Robert Kern
On Fri, Aug 7, 2009 at 00:03, David Warde-Farleyd...@cs.toronto.edu wrote:
 On 6-Aug-09, at 7:29 PM, Robert Kern wrote:

 For that value, yes, but not for long objects in general. We don't
 look at the value itself, just the type.

 Err, don't look at the value (of a long), except when it's
 representable with an integer dtype, right? Hence why 2**63 - 1 works.

Err, you may be right.

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