Re: [Numpy-discussion] memmap from fd?

2009-01-09 Thread Neal Becker
Robert Kern wrote: > On Fri, Jan 9, 2009 at 08:08, Neal Becker wrote: >> Robert Kern wrote: >> >>> On Fri, Jan 9, 2009 at 06:05, Neal Becker wrote: I'm working on interfacing to a custom FPGA board. The kernel driver exposes the FPGA memory via mmap. It might be nice to use

Re: [Numpy-discussion] help with typemapping a C function to use numpy arrays

2009-01-09 Thread Egor Zindy
Hello again! On Sat, Jan 10, 2009 at 7:11 AM, Rich E wrote: > Well I see it works, however with one change: the %apply typemaps need > to be done before %include'ing the header file, or else nothing in > that header file will automatically get typemapped (only the functions > that are written us

Re: [Numpy-discussion] 2-D function and meshgrid

2009-01-09 Thread Paulo J. S. Silva
Chuck, Thanks, your version is much faster. I would prefer a solution that doesn't force me to re-implement weirdDistance (as my two solutions were). But the function is so simple that it is easier just to re-write it for speed as you did. By the way, I came out with one more solution that looks

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Sturla Molden
> Sturla Molden wrote: >> For the same problems where you would use meshgrid in Matlab. > > well, I used to use meshgrid a lot because MATLAB could not do > broadcasting. Which is probably why the OP has been trying to use it. mgrid and ogrid are both meshgrids, with ogrid having a sparse represen

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 16:04, Christopher Barker wrote: > Sturla Molden wrote: >> For the same problems where you would use meshgrid in Matlab. > > well, I used to use meshgrid a lot because MATLAB could not do > broadcasting. Which is probably why the OP has been trying to use it. > > A note for

Re: [Numpy-discussion] help with typemapping a C function to use numpy arrays

2009-01-09 Thread Rich E
Well I see it works, however with one change: the %apply typemaps need to be done before %include'ing the header file, or else nothing in that header file will automatically get typemapped (only the functions that are written using %inline will be typemapped, which in the case of the exampe you wro

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Christopher Barker
Sturla Molden wrote: > For the same problems where you would use meshgrid in Matlab. well, I used to use meshgrid a lot because MATLAB could not do broadcasting. Which is probably why the OP has been trying to use it. A note for the docs: The docs refer to ogrid and nd_grid, and as far as I can

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Sturla Molden
>> However, just using the slices on the matrix instead of passing the >> slices through ogrid is faster. > > So what is ogrid useful for? For the same problems where you would use meshgrid in Matlab. That is certain graphics problem for example; e.g. evaluating a surface z = f(x,y) over a grid o

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 15:40, Christopher Barker wrote: > So what is ogrid useful for? > > Just curious... Floating point grids. x, y = ogrid[0:1:101j, 0:1:101j] -- 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 a

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Christopher Barker
Robert Kern wrote: > Instead, if you put both arguments into ogrid: > > In [4]: ogrid[0:5, 0:6] > Out[4]: > [array([[0], >[1], >[2], >[3], >[4]]), > array([[0, 1, 2, 3, 4, 5]])] > > We get the kind of arrays you need. These shapes are compatible, > through broadca

Re: [Numpy-discussion] inplace matrix multiplication

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 08:25, Frédéric Bastien wrote: > Hi, > > I would like to know how I can make a call to the blas function gemm in > numpy. I need a multiply and accumulate for matrix and I don't want to > allocate a new matrix each time I do it. You can't in numpy. With scipy.linalg.fblas.d

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 11:32, Nicolas ROUX wrote: > Thanks ! > > -1- The code style is good and the performance vs matlab is good. > With 400x400: > Matlab = 1.56 sec (with nested "for" loop, so no optimization) > Numpy = 0.99 sec (with broadcasting) > > > -2- Now with the code below I have s

Re: [Numpy-discussion] memmap from fd?

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 08:08, Neal Becker wrote: > Robert Kern wrote: > >> On Fri, Jan 9, 2009 at 06:05, Neal Becker wrote: >>> I'm working on interfacing to a custom FPGA board. The kernel driver >>> exposes the FPGA memory via mmap. >>> >>> It might be nice to use numpy memmap to read/write da

Re: [Numpy-discussion] memmap problem

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 10:59, Neal Becker wrote: > I modified memmap.py to avoid the issues with needed to read. It is working, > but I am seeing these: > > m > Exception exceptions.EnvironmentError: (22, 'Invalid argument') in method eos_memmap.__del__ of eos_memmap([255, 255, 255], dtype=uin

Re: [Numpy-discussion] 2-D function and meshgrid

2009-01-09 Thread Charles R Harris
On Fri, Jan 9, 2009 at 11:45 AM, Paulo J. S. Silva wrote: > Hello, > > I have a function that receives a array of shape (2,) and returns a > number (a function from R^2 -> R). It basically looks like this: > >def weirdDistance2(x): > return dot(dot(weirdMatrix, x), x) > > (weirdMatrix is

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Sturla Molden
> -2- Now with the code below I have strange result. > With w=h=400: >- Using "slice"=> 0.99 sec >- Using "numpy.ogrid" => 0.01 sec It is not equivalent. The ogrid version only uses diagonal elements, and does less work. > It seems "ogrid" got better performance, but broadcas

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Christopher Barker
Nicolas ROUX wrote: > -2- Now with the code below I have strange result. > With w=h=400: > With w=400 and h=300: >- Using "numpy.ogrid", => broadcast ERROR ! > > The last broadcast error is: > "ValueError: shape mismatch: objects cannot be broadcast to a single shape" This is probably a br

[Numpy-discussion] 2-D function and meshgrid

2009-01-09 Thread Paulo J. S. Silva
Hello, I have a function that receives a array of shape (2,) and returns a number (a function from R^2 -> R). It basically looks like this: def weirdDistance2(x): return dot(dot(weirdMatrix, x), x) (weirdMatrix is a "global" (2,2) array) I want to see its level sets in the box [0, 1]

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Nicolas ROUX
Thanks ! -1- The code style is good and the performance vs matlab is good. With 400x400: Matlab = 1.56 sec (with nested "for" loop, so no optimization) Numpy = 0.99 sec (with broadcasting) -2- Now with the code below I have strange result. With w=h=400: - Using "slice"=> 0.99 se

[Numpy-discussion] memmap problem

2009-01-09 Thread Neal Becker
I modified memmap.py to avoid the issues with needed to read. It is working, but I am seeing these: m Exception exceptions.EnvironmentError: (22, 'Invalid argument') in ignored Exception exceptions.EnvironmentError: (22, 'Invalid argument') in ignored Out[22]: eos_memmap([ 0, 0, 0, ...,

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Sturla Molden
> I simplified the code to focus only on "what I" need, rather to bother you > with the full code. def test(): w = 3096 h = 2048 a = numpy.zeros((h,w), order='F') #Normally loaded with real data b = numpy.zeros((h,w,3), order='F') w0 = slice(0,w-2) w1 = slice(1,w-1)

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Nicolas ROUX
Sorry my previous mail was probalby not clear. This mail was following the tread we had before, so with some discussion legacy. I simplified the code to focus only on "what I" need, rather to bother you with the full code. I wrote below a code closer to what I need, where you will agree that vect

[Numpy-discussion] inplace matrix multiplication

2009-01-09 Thread Frédéric Bastien
Hi, I would like to know how I can make a call to the blas function gemm in numpy. I need a multiply and accumulate for matrix and I don't want to allocate a new matrix each time I do it. thanks for your time Frederic Bastien ___ Numpy-discussion maili

Re: [Numpy-discussion] memmap from fd?

2009-01-09 Thread Neal Becker
Robert Kern wrote: > On Fri, Jan 9, 2009 at 06:05, Neal Becker wrote: >> I'm working on interfacing to a custom FPGA board. The kernel driver >> exposes the FPGA memory via mmap. >> >> It might be nice to use numpy memmap to read/write data. One issue is >> that I think I will need to create th

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Sturla Molden
> I understand the weakness of the missing JITcompiler in Python vs Matlab, > that's why I invistigated numpy vectorization/broadcast. > (hoping to find a cool way to write our code in fast Numpy) > > I used the page http://www.scipy.org/PerformancePython to write my code > efficiently in Numpy. >

Re: [Numpy-discussion] memmap from fd?

2009-01-09 Thread Neal Becker
Robert Kern wrote: > On Fri, Jan 9, 2009 at 06:05, Neal Becker wrote: >> I'm working on interfacing to a custom FPGA board. The kernel driver >> exposes the FPGA memory via mmap. >> >> It might be nice to use numpy memmap to read/write data. One issue is >> that I think I will need to create th

Re: [Numpy-discussion] memmap from fd?

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 06:05, Neal Becker wrote: > I'm working on interfacing to a custom FPGA board. The kernel driver exposes > the FPGA memory via mmap. > > It might be nice to use numpy memmap to read/write data. One issue is that I > think I will need to create the memmap array from a fd,

[Numpy-discussion] memmap from fd?

2009-01-09 Thread Neal Becker
I'm working on interfacing to a custom FPGA board. The kernel driver exposes the FPGA memory via mmap. It might be nice to use numpy memmap to read/write data. One issue is that I think I will need to create the memmap array from a fd, not a file name. The reason is I wrote the driver to onl

Re: [Numpy-discussion] Numpy performance vs Matlab.

2009-01-09 Thread Nicolas ROUX
Hi ! Thanks a lot for your fast/detailed reply. A very good point for Numpy ;-) I spent all my time trying to prepare my testcase to better share with you, that's why I didn't reply fast. I understand the weakness of the missing JITcompiler in Python vs Matlab, that's why I invistigated numpy ve

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 03:27, Stéfan van der Walt wrote: > 2009/1/9 Robert Kern : >> try_run() is not the right thing to call for such a purpose. Use >> FCompiler.get_version(). > > That was just an example. What I want to do is run something like > "pkg-config blah" and parse the output, but I g

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread Stéfan van der Walt
2009/1/9 Robert Kern : > try_run() is not the right thing to call for such a purpose. Use > FCompiler.get_version(). That was just an example. What I want to do is run something like "pkg-config blah" and parse the output, but I get the idea from David's post that that is OK. Cheers Stéfan _

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread David Cournapeau
Stéfan van der Walt wrote: > 2009/1/9 David Cournapeau : > >>> What do you suggest as workarounds? >>> >> What about not using tests which need to run on the target platform :) >> > > Let me simplify the question. How do you detect the version of the > local Fortran compiler without

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread Robert Kern
On Fri, Jan 9, 2009 at 02:31, Stéfan van der Walt wrote: > 2009/1/9 David Cournapeau : >>> What do you suggest as workarounds? >> >> What about not using tests which need to run on the target platform :) > > Let me simplify the question. How do you detect the version of the > local Fortran compil

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread Stéfan van der Walt
2009/1/9 David Cournapeau : >> What do you suggest as workarounds? > > What about not using tests which need to run on the target platform :) Let me simplify the question. How do you detect the version of the local Fortran compiler without executing the compiler? Or is that OK, and you'd simply

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread David Cournapeau
Stéfan van der Walt wrote: > 2009/1/9 David Cournapeau : > >> It happened that in that particular case where it is used in numpy, I >> found a way around it, but I would like to get rid of it completely at >> some point. >> > > What do you suggest as workarounds? > > What about not usin

Re: [Numpy-discussion] Replacement for numpy.distutils.config.try_run

2009-01-09 Thread Stéfan van der Walt
2009/1/9 David Cournapeau : > It happened that in that particular case where it is used in numpy, I > found a way around it, but I would like to get rid of it completely at > some point. What do you suggest as workarounds? Stéfan ___ Numpy-discussion ma

Re: [Numpy-discussion] change made to test_print.py

2009-01-09 Thread Stéfan van der Walt
2009/1/9 David Cournapeau : > As Robert said, BTS is supposedly a better system for this for this kind > of things - but at least for me, trac is so slow and painful to use that > I try to avoid it as much as possible. We are running Trac 10.2 from November 2006, so it is quite possible that some