Re: [Numpy-discussion] ufunc oddities

2008-05-25 Thread Stéfan van der Walt
2008/5/25 Anne Archibald <[EMAIL PROTECTED]>: > 2008/5/25 Charles R Harris <[EMAIL PROTECTED]>: > >> So, please tell me how numpy is supposed to work. Write as much as you >> please. If you are so moved, why not write the tests for all 64 ufuncs for >> all types and combinations and verify that the

Re: [Numpy-discussion] ufunc oddities

2008-05-25 Thread Charles R Harris
On Sun, May 25, 2008 at 11:30 AM, Anne Archibald <[EMAIL PROTECTED]> wrote: > 2008/5/25 Charles R Harris <[EMAIL PROTECTED]>: > > > So, please tell me how numpy is supposed to work. Write as much as you > > please. If you are so moved, why not write the tests for all 64 ufuncs > for > > all types

Re: [Numpy-discussion] ufunc oddities

2008-05-25 Thread Anne Archibald
2008/5/25 Charles R Harris <[EMAIL PROTECTED]>: > So, please tell me how numpy is supposed to work. Write as much as you > please. If you are so moved, why not write the tests for all 64 ufuncs for > all types and combinations and verify that they are all correct as specified > and raise errors wh

Re: [Numpy-discussion] ufunc oddities

2008-05-25 Thread Robert Kern
On Sat, May 24, 2008 at 11:14 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > It used to be stay in type and has been changed, and I don't disagree with > that, it was discussed on the list. Nevertheless, booleans are different, > both their own kind and integers. But my problem is not convenien

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 10:08 PM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > > On Sat, May 24, 2008 at 9:21 PM, Alan G Isaac <[EMAIL PROTECTED]> > wrote: > >> If you want bools, change the accumulator dtype:: > >>>>> x.sum(dtype=bool) > > > On Sat, 24 May 2008, Charles R Harris apparently wrote

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 10:00 PM, Nathan Bell <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:48 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > You can't overflow in modular arithmetic, which is how numpy is supposed > to > > work. Try > > > > In [51]: x > > Out[51]: array([2147

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Alan G Isaac
> On Sat, May 24, 2008 at 9:21 PM, Alan G Isaac <[EMAIL PROTECTED]> wrote: >> If you want bools, change the accumulator dtype:: >>>>> x.sum(dtype=bool) On Sat, 24 May 2008, Charles R Harris apparently wrote: > Shouldn't that be the other way round? If you want integers, do > x.sum(dtype=int

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:50 PM, Nathan Bell <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:40 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > The question is consistency. A programmer should just have to remember a > few > > simple rules, not a host of special cases. It makes t

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Nathan Bell
On Sat, May 24, 2008 at 10:48 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > You can't overflow in modular arithmetic, which is how numpy is supposed to > work. Try > > In [51]: x > Out[51]: array([2147483647, 2147483647]) > > In [52]: x.sum() > Out[52]: -2 > I would call that an overflow. H

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Nathan Bell
On Sat, May 24, 2008 at 10:40 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > The question is consistency. A programmer should just have to remember a few > simple rules, not a host of special cases. It makes things easier to learn > and the code easier to understand because the intent is alway

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:40 PM, Nathan Bell <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:32 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > But the accumalator is of the same kind unless the kind is boolean, in > which > > case it is integer. Clear as a bell. > > > > I believ

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Nathan Bell
On Sat, May 24, 2008 at 10:32 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > But the accumalator is of the same kind unless the kind is boolean, in which > case it is integer. Clear as a bell. > I believe the rule is that any integer type smaller than the machine word size is effectively upca

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:35 PM, Nathan Bell <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:24 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > > > Shouldn't that be the other way round? If you want integers, do > > x.sum(dtype=int). Ints don't sum in float64 by default. > > > >

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Nathan Bell
On Sat, May 24, 2008 at 10:24 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > Shouldn't that be the other way round? If you want integers, do > x.sum(dtype=int). Ints don't sum in float64 by default. > The default behavior (x.sum() -> int) is more useful than (x.sum() -> bool) since x.any()

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:18 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:12 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > On Sat, May 24, 2008 at 9:06 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > >> > >> On Sat, May 24, 2008 at 10:02 PM, Charles R Harris >

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:21 PM, Alan G Isaac <[EMAIL PROTECTED]> wrote: > On Sat, 24 May 2008, Keith Goodman apparently wrote: > >>> x = np.array([True, True], dtype=bool) > >>> x.sum() > >2 > > > > If you want bools, change the accumulator dtype:: > >>>> x.sum(dtype=bool) Shouldn't tha

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 10:12 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > On Sat, May 24, 2008 at 9:06 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sat, May 24, 2008 at 10:02 PM, Charles R Harris >> <[EMAIL PROTECTED]> wrote: >> > So what about the rule that the array type takes prec

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Alan G Isaac
On Sat, 24 May 2008, Keith Goodman apparently wrote: >>> x = np.array([True, True], dtype=bool) >>> x.sum() >2 If you want bools, change the accumulator dtype:: >>> x.sum(dtype=bool) True Cheers, Alan Isaac ___ Numpy-discussion mailin

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 10:15 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > On Sat, May 24, 2008 at 9:11 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sat, May 24, 2008 at 10:06 PM, Robert Kern <[EMAIL PROTECTED]> >> wrote: >> > On Sat, May 24, 2008 at 10:02 PM, Charles R Harris >> > <[

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:11 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:06 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > > On Sat, May 24, 2008 at 10:02 PM, Charles R Harris > > <[EMAIL PROTECTED]> wrote: > >> So what about the rule that the array type takes precedenc

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 9:06 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:02 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > So what about the rule that the array type takes precedence over the > scalar > > type? That is broken for booleans. > > Yes, and if it wasn

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 10:06 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 10:02 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: >> So what about the rule that the array type takes precedence over the scalar >> type? That is broken for booleans. > > Yes, and if it wasn't a

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 10:02 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > So what about the rule that the array type takes precedence over the scalar > type? That is broken for booleans. Yes, and if it wasn't an intentional special case (I don't recall discussing it on the list, but it might

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 8:59 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 9:45 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > >> I'm not sure why you're showing me numpy C code. I am talking about > >> the Python bools True and False. > > > > Because I'm talking about

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:57 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > How about > > In [14]: x += 5 > > In [15]: x > Out[15]: array([ True, True], dtype=bool) Output = bool. > In [16]: x.tostring() > Out[16]: '\x01\x01' > > > In [17]: x + 5 > Out[17]: array([6, 6]) Output != bool. > I

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:45 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: >> I'm not sure why you're showing me numpy C code. I am talking about >> the Python bools True and False. > > Because I'm talking about ufuncs. The original question was about ufuncs > and, since array booleans are not tr

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 8:48 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 9:46 PM, Keith Goodman <[EMAIL PROTECTED]> > wrote: > > On Sat, May 24, 2008 at 7:36 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > >> On Sat, May 24, 2008 at 9:28 PM, Keith Goodman <[EMAIL PROTECTED]

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:46 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 7:36 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> On Sat, May 24, 2008 at 9:28 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: >>> I think it's interesting how python and numpy bools behave differently

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Keith Goodman
On Sat, May 24, 2008 at 7:36 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 9:28 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: >> I think it's interesting how python and numpy bools behave differently. >> x = np.array([True, True], dtype=bool) x[0] + x[1] >> True >>

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 8:40 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 9:37 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > > > On Sat, May 24, 2008 at 8:25 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > >> > >> On Sat, May 24, 2008 at 9:09 PM, Charles R Harris

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:37 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Sat, May 24, 2008 at 8:25 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sat, May 24, 2008 at 9:09 PM, Charles R Harris >> <[EMAIL PROTECTED]> wrote: >> > >> > On Sat, May 24, 2008 at 7:47 PM, Robert Kern <[E

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 8:25 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 9:09 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > > > On Sat, May 24, 2008 at 7:47 PM, Robert Kern <[EMAIL PROTECTED]> > wrote: > >> > >> On Sat, May 24, 2008 at 8:31 PM, Charles R Harris > >

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:28 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > I think it's interesting how python and numpy bools behave differently. > >>> x = np.array([True, True], dtype=bool) >>> x[0] + x[1] > True >>> x[0] & x[1] > True >>> >>> x = [True, True] >>> x[0] + x[1] > 2 >>> x[0]

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Keith Goodman
On Sat, May 24, 2008 at 7:09 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Sat, May 24, 2008 at 7:47 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sat, May 24, 2008 at 8:31 PM, Charles R Harris >> <[EMAIL PROTECTED]> wrote: >> > Hi All, >> > >> > I'm writing tests for ufuncs and tu

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 9:09 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > On Sat, May 24, 2008 at 7:47 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sat, May 24, 2008 at 8:31 PM, Charles R Harris >> <[EMAIL PROTECTED]> wrote: >> > Hi All, >> > >> > I'm writing tests for ufuncs and turn

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 7:47 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > On Sat, May 24, 2008 at 8:31 PM, Charles R Harris > <[EMAIL PROTECTED]> wrote: > > Hi All, > > > > I'm writing tests for ufuncs and turned up some oddities: > > > > In [4]: degrees(True) > > Out[4]: 57.29578 > > > > In [5]:

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Robert Kern
On Sat, May 24, 2008 at 8:31 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > Hi All, > > I'm writing tests for ufuncs and turned up some oddities: > > In [4]: degrees(True) > Out[4]: 57.29578 > > In [5]: radians(True) > Out[5]: 0.017453292 > > In [6]: sin(True) > Out[6]: 0.84147096 > > Do we want

Re: [Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
On Sat, May 24, 2008 at 7:31 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > Hi All, > > I'm writing tests for ufuncs and turned up some oddities: > > In [4]: degrees(True) > Out[4]: 57.29578 > > In [5]: radians(True) > Out[5]: 0.017453292 > > In [6]: sin(True) > Out[6]: 0.84147096 > > Do we wan

[Numpy-discussion] ufunc oddities

2008-05-24 Thread Charles R Harris
Hi All, I'm writing tests for ufuncs and turned up some oddities: In [4]: degrees(True) Out[4]: 57.29578 In [5]: radians(True) Out[5]: 0.017453292 In [6]: sin(True) Out[6]: 0.84147096 Do we want numeric functions to apply to booleans? Chuck ___ Nump