Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-13 Thread David Cournapeau
On 1/13/07, Francesc Altet <[EMAIL PROTECTED]> wrote: > El ds 13 de 01 del 2007 a les 14:42 +0900, en/na David Cournapeau va > escriure: > > > No, only if it's contiguous (I'm not sure about alignment) > > According to numpy ebook, you need alignement for deferencing > > pointers. But I guess non a

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-13 Thread Francesc Altet
El ds 13 de 01 del 2007 a les 14:42 +0900, en/na David Cournapeau va escriure: > > No, only if it's contiguous (I'm not sure about alignment) > According to numpy ebook, you need alignement for deferencing > pointers. But I guess non aligned arrays are not really common. Unaligned arrays can be qu

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread David Cournapeau
On 1/13/07, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On 1/12/07, David Cournapeau <[EMAIL PROTECTED]> wrote: > > On 1/13/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > > > I think it may have all been cleared up now, but just in case: > > > > > > > > but how do you get single strided?

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread Charles R Harris
On 1/12/07, David Cournapeau <[EMAIL PROTECTED]> wrote: On 1/13/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > I think it may have all been cleared up now, but just in case: > > but how do you get single strided? this is what always made it hard for > me to know how to write this kind of c

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread David Cournapeau
On 1/13/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > I think it may have all been cleared up now, but just in case: > > >>> a > array([[[ 0, 1, 2, 3], > [ 4, 5, 6, 7], > [ 8, 9, 10, 11]], > > [[12, 13, 14, 15], > [16, 17, 18, 19], > [20, 21

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread Travis Oliphant
Christopher Barker wrote: >>Now, it is exposed in the concept of an array iterator. Anybody >>can take advantage of it as it there is a C-API call to get an array >>iterator from the array >> >> > >Is this iterator as efficient as incrementing the index for contiguous >arrays? i.e. is ther

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread Christopher Barker
I think it may have all been cleared up now, but just in case: >>> a array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]) >>> a.flags C_CONTIGUOUS : True F_CONTIGUOUS : False

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-12 Thread David Cournapeau
Charles R Harris wrote: > > > Well, the common machines are 32 bit and 64 bit, so for instance > extended precision (usually 80 bits) ends up as 96 bits (3*32) on the > first and 128 (2*64) bits on the second, with the extra bits ignored. > The items in c structures will often have empty spaces

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Charles R Harris
On 1/12/07, Charles R Harris <[EMAIL PROTECTED]> wrote: On 1/11/07, David Cournapeau <[EMAIL PROTECTED]> wrote: > > Travis Oliphant wrote: > > > > This is one thing I've exposed (and made use of in more than one > place) > > with NumPy. In Numeric, the magic was in a few lines of the > ufunco

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Charles R Harris
On 1/11/07, David Cournapeau <[EMAIL PROTECTED]> wrote: Travis Oliphant wrote: > > This is one thing I've exposed (and made use of in more than one place) > with NumPy. In Numeric, the magic was in a few lines of the ufuncobject > file). Now, it is exposed in the concept of an array iterator.

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Charles R Harris
On 1/11/07, David Cournapeau <[EMAIL PROTECTED]> wrote: Charles R Harris wrote: > > > On 1/11/07, *David Cournapeau* <[EMAIL PROTECTED] > > wrote: > > Timothy Hochberg wrote: > > > > > > On 1/11/07, *Christopher Barker* <[EMAIL PROTECTED] >

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
Travis Oliphant wrote: > > This is one thing I've exposed (and made use of in more than one place) > with NumPy. In Numeric, the magic was in a few lines of the ufuncobject > file). Now, it is exposed in the concept of an array iterator. Anybody > can take advantage of it as it there is a C-A

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
Charles R Harris wrote: > > > On 1/11/07, *David Cournapeau* <[EMAIL PROTECTED] > > wrote: > > Timothy Hochberg wrote: > > > > > > On 1/11/07, *Christopher Barker* <[EMAIL PROTECTED] > > >

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Travis Oliphant
Timothy Hochberg wrote: > > > On 1/11/07, *Christopher Barker* <[EMAIL PROTECTED] > > wrote: > > [CHOP] > > > I'd still like to know if anyone knows how to efficiently loop through > all the elements of a non-contiguous array in C. > > > First, it's not that imp

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Charles R Harris
On 1/11/07, David Cournapeau <[EMAIL PROTECTED]> wrote: Timothy Hochberg wrote: > > > On 1/11/07, *Christopher Barker* <[EMAIL PROTECTED] > > wrote: > > [CHOP] > > > I'd still like to know if anyone knows how to efficiently loop through > all the elements of a n

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
Timothy Hochberg wrote: > > > On 1/11/07, *Christopher Barker* <[EMAIL PROTECTED] > > wrote: > > [CHOP] > > > I'd still like to know if anyone knows how to efficiently loop through > all the elements of a non-contiguous array in C. > > > First, it's not that imp

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
Christopher Barker wrote: > >> autogen works well enough for me; > > I didn't know about autogen -- that may be all we need. > numpy has code which already does something similar to autogen: you declare a function, and some template with a generic name, and the code generator replaces the generi

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Timothy Hochberg
On 1/11/07, Christopher Barker <[EMAIL PROTECTED]> wrote: [CHOP] I'd still like to know if anyone knows how to efficiently loop through all the elements of a non-contiguous array in C. First, it's not that important if the array is contiguous for this sort of thing. What you really care abo

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Christopher Barker
David Cournapeau wrote: > To do the actual clipping if the datatypes are 'native' is trivial in C: > a single loop, a comparison, that's it. only if it's also Contiguous. From a quick look at your posted code, it looks like it only works for contiguous arrays. > I don't think C++ is welcome

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread Francesc Altet
El dv 12 de 01 del 2007 a les 00:58 +0900, en/na David Cournapeau va escriure: > David Cournapeau wrote: > > Francesc Altet wrote: > >> A Dimecres 10 Gener 2007 22:49, Stefan van der Walt escrigué: > >>> On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: > El dt 09 de 01 del 2007

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
David Cournapeau wrote: > Francesc Altet wrote: >> A Dimecres 10 Gener 2007 22:49, Stefan van der Walt escrigué: >>> On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va escriure: time (putmask)--> 1

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-11 Thread David Cournapeau
Francesc Altet wrote: A Dimecres 10 Gener 2007 22:49, Stefan van der Walt escrigué: On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va escriure: time (putmask)--> 1.38 time (where)--> 2.713 time (numexpr where)--

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread David Cournapeau
Christopher Barker wrote: > > > A. M. Archibald wrote: > >> Why not write the algorithm in C? > > I did just that a while back, for Numeric. I've enclosed the code for > reference. > > Unfortunately, I never did figure out an efficient way to write this > sort of thing for all types, so it only

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread David Cournapeau
Stefan van der Walt wrote: > On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: >> El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va >> escriure: >>> Hi, >>> >>> I am finally implementing a C function to replace the current slow >>> implementation of clip in pyt

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread Christopher Barker
A. M. Archibald wrote: Why not write the algorithm in C? I did just that a while back, for Numeric. I've enclosed the code for reference. Unfortunately, I never did figure out an efficient way to write this sort of thing for all types, so it only does doubles. Also, it does a bunch of s

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread A. M. Archibald
On 10/01/07, Stefan van der Walt <[EMAIL PROTECTED]> wrote: > On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: > > El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va > > escriure: > > > Hi, > > > > > > I am finally implementing a C function to replace the curren

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread Stefan van der Walt
On Wed, Jan 10, 2007 at 08:28:14PM +0100, Francesc Altet wrote: > El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va > escriure: > > Hi, > > > > I am finally implementing a C function to replace the current slow > > implementation of clip in python as promised a few weeks ag

Re: [Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-10 Thread Francesc Altet
El dt 09 de 01 del 2007 a les 23:19 +0900, en/na David Cournapeau va escriure: > Hi, > > I am finally implementing a C function to replace the current slow > implementation of clip in python as promised a few weeks ago. The idea > is to implement it as the following: > > def clip(input, min

[Numpy-discussion] Need help for implementing a fast clip in numpy (was slow clip)

2007-01-09 Thread David Cournapeau
Hi, I am finally implementing a C function to replace the current slow implementation of clip in python as promised a few weeks ago. The idea is to implement it as the following: def clip(input, min, max): a = input.copy() putmask(a, a <= min, min) putmask(a, a >= max, max)