Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Sebastian Haase
On Feb 4, 2008 9:05 PM, Christopher Barker <[EMAIL PROTECTED]> wrote: > Lou Pecora wrote: > > I > > would recommend using the C API > > I would recommend against this -- there is a lot of code to write in > extensions to make sure you do reference counting, etc, and it is hard > to get right. > > M

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Gael Varoquaux
On Tue, Feb 05, 2008 at 09:15:29AM +0100, Sebastian Haase wrote: > Can ctypes do this ? No. Ctypes is only a way of loading C (and not C++) libraries in Python. That makes it very simple, but not very powerful. Gaël ___ Numpy-discussion mailing list Num

Re: [Numpy-discussion] An idea for future numpy windows installers

2008-02-05 Thread David Cournapeau
Alexander Michael wrote: > On Feb 4, 2008 5:13 AM, David Cournapeau <[EMAIL PROTECTED]> wrote: >> Hi, >> >> While studying a bit nsis (an open source system to build windows >> installers), I realized that it would be good if we could detect the >> target CPU and install the right numpy according

Re: [Numpy-discussion] Generating a series of integers

2008-02-05 Thread Sebastian Haase
On Feb 5, 2008 11:33 AM, Francesc Altet <[EMAIL PROTECTED]> wrote: > Hi, > > I need to generate a series of uint8 integers similar to: > > In [37]: numpy.linspace(10, 20, num=25).astype('uint8') > Out[37]: > array([10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 16, >16, 17, 17,

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Sebastian Haase
On Feb 5, 2008 9:21 AM, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > On Tue, Feb 05, 2008 at 09:15:29AM +0100, Sebastian Haase wrote: > > Can ctypes do this ? > > No. Ctypes is only a way of loading C (and not C++) libraries in Python. > That makes it very simple, but not very powerful. > > Gaël (so

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread David Cournapeau
Gael Varoquaux wrote: > On Tue, Feb 05, 2008 at 09:15:29AM +0100, Sebastian Haase wrote: > >> Can ctypes do this ? >> > > No. Ctypes is only a way of loading C (and not C++) libraries in Python. > That makes it very simple, but not very powerful. > I would not call ctypes not very powerf

[Numpy-discussion] Generating a series of integers

2008-02-05 Thread Francesc Altet
Hi, I need to generate a series of uint8 integers similar to: In [37]: numpy.linspace(10, 20, num=25).astype('uint8') Out[37]: array([10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 17, 18, 18, 19, 19, 20], dtype=uint8) i.e. create evenly spaced samples in a ra

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Ondrej Certik
On Feb 5, 2008 11:23 AM, David Cournapeau <[EMAIL PROTECTED]> wrote: > Gael Varoquaux wrote: > > On Tue, Feb 05, 2008 at 09:15:29AM +0100, Sebastian Haase wrote: > > > >> Can ctypes do this ? > >> > > > > No. Ctypes is only a way of loading C (and not C++) libraries in Python. > > That makes it ver

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Gael Varoquaux
On Tue, Feb 05, 2008 at 11:48:37AM +0100, Sebastian Haase wrote: > Thanks fr the reply. > How about "manual" overloading. I mean, if -- for example -- I have > two functions mmms_b and mmms_i in C, I could still use ctypes; could > I then "merge" them into one python function, which "re-routes" > d

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Gael Varoquaux
On Tue, Feb 05, 2008 at 11:48:38AM +0100, Ondrej Certik wrote: > I use Cython, mostly for the same reasons Gael is using ctypes - it's trivial. Actually, when I want to do something really trivial, I use scipy.weave.inline ( see http://scipy.org/PerformancePython for an example of scipy.weave.inli

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Matthieu Brucher
> > This is what SWIG must be doing internally -- right ?! > Yes, it is with an additional typemap that checks the type of the data. I don't think that it is a good idea for numpy to add such multi-dispatching, it is not its job. There are a lot of ways to do it, and besides it would be very cumb

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread David Cournapeau
Gael Varoquaux wrote: > On Tue, Feb 05, 2008 at 11:48:37AM +0100, Sebastian Haase wrote: >> Thanks fr the reply. >> How about "manual" overloading. I mean, if -- for example -- I have >> two functions mmms_b and mmms_i in C, I could still use ctypes; could >> I then "merge" them into one python fun

[Numpy-discussion] C-api to slicing?

2008-02-05 Thread Neal Becker
Is there a C-api to array slicing? ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Ondrej Certik
On Feb 5, 2008 11:52 AM, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > On Tue, Feb 05, 2008 at 11:48:38AM +0100, Ondrej Certik wrote: > > I use Cython, mostly for the same reasons Gael is using ctypes - it's > > trivial. > > Actually, when I want to do something really trivial, I use > scipy.weave.i

[Numpy-discussion] Problem accessing elements of an array of dtype="O" from C

2008-02-05 Thread Chris Ball
Hi, I'm having some trouble accessing elements in an array of dtype="O" from C code; I hope someone on the list could give me some advice (because I might be doing something stupid). I have an array of simple objects, created as follows: class CF(object): def __init__(self,num=0.0):

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Lou Pecora
--- Gael Varoquaux <[EMAIL PROTECTED]> wrote: Re: ctypes > I don't use windows much. One thing I liked about > ctypes when I used it, > was that what I found it pretty easy to get working > on both Linux and > Windows. > > Gaël I got ctypes to install easily on Mac OS X 10.4.11 and it passe

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Gael Varoquaux
On Tue, Feb 05, 2008 at 06:45:25AM -0800, Lou Pecora wrote: > Hmmm... last time I tried ctypes it seemed pretty > Windows oriented and I got nowhere. But enough people > have said how easy it is that I'll give it another > try. I don't use windows much. One thing I liked about ctypes when I used

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Lou Pecora
Hmmm... last time I tried ctypes it seemed pretty Windows oriented and I got nowhere. But enough people have said how easy it is that I'll give it another try. Believe me, I'd be happy to be wrong and find a nice easy way to pass NumPy arrays and such. Thanks. -- Lou Pecora --- Gael Varoquaux

[Numpy-discussion] New to ctypes. Some problems with loading shared library.

2008-02-05 Thread Lou Pecora
I got ctypes installed and passing its own tests. But I cannot get the shared library to load. I am using Mac OS X 10.4.11, Python 2.4 running through the Terminal. I am using Albert Strasheim's example on http://scipy.org/Cookbook/Ctypes2 except that I had to remove the defined 'extern' for FOO

Re: [Numpy-discussion] New to ctypes. Some problems with loading shared library.

2008-02-05 Thread Ryan May
Lou Pecora wrote: > I got ctypes installed and passing its own tests. But > I cannot get the shared library to load. I am using > Mac OS X 10.4.11, Python 2.4 running through the > Terminal. > > I am using Albert Strasheim's example on > http://scipy.org/Cookbook/Ctypes2 except that I had to > r

Re: [Numpy-discussion] New to ctypes. Some problems with loading shared library.

2008-02-05 Thread Lou Pecora
> Well, it's looking for test1ctypes.dylib, which I > guess is a MacOSX > shared library? Meanwhile, you made a > test1ctypes.so, which is why it > can't find it. You could try using this instead: > > _test1 = N.ctypeslib.load_library('test1ctypes.so', > '.') > > or try to get gcc to make a t

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Kent-Andre Mardal
Vince Fulco gmail.com> writes: > > Dear Numpy Experts- I find myself working with Numpy arrays and > wanting to access *simple* C++ functions for time series returning the > results to Numpy. As I am a relatively new user of Python/Numpy, the > number of paths to use in incorporating C++ code

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Damian Eads
Dear Vince, You probably have heard better solutions but I think what I do works and is simple to learn. When I need to call C++ code from Python, I write a wrapper extern "C" function that calls the C++ function that returns the result. Then I just use ctypes to call the extern "C" function fr

[Numpy-discussion] matrix rank of numpy array or matrix

2008-02-05 Thread mark
Hello - Is there a function to compute the matrix rank of a numpy array or matrix? So I don't mean the current rank(), which gives the number of dimensions. I mean the number of independent equations of a matrix. Thanks, Mark ___ Numpy-discussion maili

Re: [Numpy-discussion] matrix rank of numpy array or matrix

2008-02-05 Thread mark
Thanks. I rewrote the line as: from numpy.linalg import svd from numpy import sum,where def matrixrank(A,tol=1e-8): s = svd(A,compute_uv=0) return sum( where( s>tol, 1, 0 ) ) Would be nice to include matrixrank in numpy, as it is really useful, Thanks again, Mark On Feb 5, 7:59 pm, "Ni

Re: [Numpy-discussion] matrix rank of numpy array or matrix

2008-02-05 Thread Nils Wagner
On Tue, 5 Feb 2008 10:54:01 -0800 (PST) mark <[EMAIL PROTECTED]> wrote: > Hello - > > Is there a function to compute the matrix rank of a >numpy array or > matrix? > So I don't mean the current rank(), which gives the >number of > dimensions. > I mean the number of independent equations of a m

Re: [Numpy-discussion] matrix rank of numpy array or matrix

2008-02-05 Thread Keith Goodman
On Feb 5, 2008 10:54 AM, mark <[EMAIL PROTECTED]> wrote: > Is there a function to compute the matrix rank of a numpy array or > matrix? I'm sure there's a more direct way, but numpy.linalg.lstsq returns the rank of a matrix. ___ Numpy-discussion mailing

Re: [Numpy-discussion] matrix rank of numpy array or matrix

2008-02-05 Thread Nils Wagner
On Tue, 5 Feb 2008 11:37:12 -0800 (PST) mark <[EMAIL PROTECTED]> wrote: > Thanks. > I rewrote the line as: > > from numpy.linalg import svd > from numpy import sum,where > > def matrixrank(A,tol=1e-8): >s = svd(A,compute_uv=0) >return sum( where( s>tol, 1, 0 ) ) > > Would be nice to in

Re: [Numpy-discussion] C-api to slicing?

2008-02-05 Thread Robert Kern
Neal Becker wrote: > Is there a C-api to array slicing? PyObject_GetItem(), PySlice_New(), and friends, for the most part. -- 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

Re: [Numpy-discussion] Numpy and C++ integration...

2008-02-05 Thread Glen W. Mabey
On Tue, Feb 05, 2008 at 12:16:02PM -0600, Kent-Andre Mardal wrote: > We have created a small Python module Instant (www.fenics.org/instant) on top > of SWIG, which makes integration of C/C++ and NumPy arrays easy in some cases. Hello, Thank you for posting about instant. I think it looks like a

[Numpy-discussion] Stride of 2 for correlate()

2008-02-05 Thread Chris Finley
Greetings, After searching the archives, I was unable to find a good method for changing the stride of the correlate or convolve routines. I am doing a Daubechies analysis of some sample data, say data = arange(0:80). The coefficient array or four floats (say daub_g2[0:4]) is correlated over the d

Re: [Numpy-discussion] Stride of 2 for correlate()

2008-02-05 Thread Anne Archibald
On 05/02/2008, Chris Finley <[EMAIL PROTECTED]> wrote: > After searching the archives, I was unable to find a good method for > changing the stride of the correlate or convolve routines. I am doing a > Daubechies analysis of some sample data, say data = arange(0:80). The > coefficient array or fou

Re: [Numpy-discussion] Problem accessing elements of an array of dtype="O" from C

2008-02-05 Thread Travis E. Oliphant
Chris Ball wrote: > Hi, > > I'm having some trouble accessing elements in an array of dtype="O" > from C code; I hope someone on the list could give me some advice > (because I might be doing something stupid). > > I have an array of simple objects, created as follows: > > class CF(object): > d

[Numpy-discussion] [Bug] important bug in method sum

2008-02-05 Thread humufr
Hello, when doing some test I saw a very important bug in numpy (at least on the svn version and 1.0.3 (ubuntu package)). I'm using a svn version of numpy: In [31]: numpy.__version__ Out[31]: '1.0.5.dev4767' The problem is for an array larger than 256*256 the su

Re: [Numpy-discussion] [Bug] important bug in method sum

2008-02-05 Thread humufr
Sorry its not really a bug. I understood why . It's an integer and I'm doing an overflow. Perhaps an error message can be printed or an automatic change (with a warning) can be done. I think that I prefer to loose the type but keep the value correct. N. ___

Re: [Numpy-discussion] [Bug] important bug in method sum

2008-02-05 Thread Keith Goodman
On Feb 5, 2008 11:58 AM, <[EMAIL PROTECTED]> wrote: > The problem is for an array larger than 256*256 the sum is going crazy. > > In [45]: numpy.arange(256*256) > Out[45]: array([0, 1, 2, ..., 65533, 65534, 65535]) > > In [46]: numpy.arange(256*256).sum() > Out[46]: 2147450880 > > In [

Re: [Numpy-discussion] [Bug] important bug in method sum

2008-02-05 Thread Charles R Harris
On Feb 5, 2008 9:27 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Feb 5, 2008 11:58 AM, <[EMAIL PROTECTED]> wrote: > > The problem is for an array larger than 256*256 the sum is going crazy. > > > > In [45]: numpy.arange(256*256) > > Out[45]: array([0, 1, 2, ..., 65533, 65534, 655