Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread James A. Bednar
| Date: Wed, 05 Sep 2007 21:19:58 +0200 | From: G?nter Dannoritzer <[EMAIL PROTECTED]> | Subject: Re: [Numpy-discussion] Use my own data type with NumPy | | The purpose of my (Python) class is to model a fixed point data | type. So I can specify how many bits are used for integer and how | ma

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bill Spotz
The setup.py script in numpy/doc/swig is for compiling test code for numpy.i. It is properly invoked by the Makefile, which will first run swig to generate the wrapper code for the test classes. All a developer, who is using swig to interface some code with numpy in python, needs is numpy

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Günter Dannoritzer
Christopher Barker wrote: [...] > > Why would a FixPoint object have to look like a sequence, with a length > and a _getitem_? That's where the confusion is coming from. > That allows me to slice bits. > If I understand your needs, a FixPoint object is a number -- you'll want > to override __

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread David Goldsmith
Travis Vaught wrote: > Have you seen this? > > http://www.scipy.org/Cookbook/SWIG_and_NumPy > Unclear (to me): precisely what does one get from running python numpy/docs/swig/setup.py install, and is the product necessary, and if so, which other components rely on the product? I ask 'cause I'

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Christopher Barker
Philip Austin wrote: > Albert Strasheim has done some work on this: > http://thread.gmane.org/gmane.comp.python.c++/11559/focus=11560 Thanks for the pointer. Not a lot of docs, and it looks like he's using boost::python, and I want to use SWIG, but I'm sure there's something useful in there. -

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Philip Austin
Christopher Barker writes: > > I've seen that -- it does look like all we'd need is the header. > > So, can one: > > - create a Multiarray from an existing data pointer? > > - get the data pointer for an existing Multiarray? > > I think that's what I'd need to make the numpy arr

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Christopher Barker
Matthieu Brucher wrote: > Blitz++ is more or less avandoned. It uses indexes than can be > not-portable between 32bits platforms and 64bits ones. Oh well -- that seems remarkably short sited, but would I have done better? > The Boost.Array is a fixed-size array, determined at compile-time, Ah,

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Christopher Barker
Günter Dannoritzer wrote: > The purpose of my (Python) class is to model a fixed point data type. So > I can specify how many bits are used for integer and how many bits are > used for fractional representation. > it would be possible to create a > list of my FixedPoint instances and then assign t

Re: [Numpy-discussion] How-to: Uniform vector scale

2007-09-05 Thread Christopher Barker
Robert Dailey wrote: > The > interpreter outputs: > "ValueError: shape mismatch: objects cannot be broadcast to a single > shape" You need to post your actually input and output. The above works fine for me, just as you'd expect: >>> A = N.array([2,3,4]) >>> B = N.array([5,6,7]) >>> S =

[Numpy-discussion] numpy.rot90 bug with >2D arrays

2007-09-05 Thread Zachary Pincus
Hello, numpy.rot90 (from twodim_base.by) says it works only on the first two axes of an array, but due to its use of the transpose method (which reverses the shape tuple), can affect other axes. For example: a = numpy.ones((50,40,3)) b = numpy.rot90(a) assert(b.shape == (3,40,50)) # desired r

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bryan Van de Ven
Christopher Barker wrote: > Does anyone know the status of support for valarrays now? I used std::valarray to implement a variant of the example Matrix class in Stroustrup's book (2D only) about two years ago. I was aware that is in disuse, by and large, but it worked well enough for my purpose

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Robert Kern
Günter Dannoritzer wrote: > Christopher Barker wrote: > [...] >> The solution is to make an empty object array first, then populate it. > [...] >> Does that help? > > Robert, Chris, thanks for that explanation. I understand that now. > > The purpose of my (Python) class is to model a fixed point

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Günter Dannoritzer
Christopher Barker wrote: > [...] > The solution is to make an empty object array first, then populate it. [...] > > Does that help? Robert, Chris, thanks for that explanation. I understand that now. The purpose of my (Python) class is to model a fixed point data type. So I can specify how man

Re: [Numpy-discussion] How-to: Uniform vector scale

2007-09-05 Thread Robert Kern
Robert Dailey wrote: > Hi, > > I have a scalar value S. I want to perform the following math on vectors > A and B (both of type array): > > A + B * S > > By order of operations, B * S should be done first. This is a vector > multiplied by a real number and should be valid. However, the > interpr

[Numpy-discussion] How-to: Uniform vector scale

2007-09-05 Thread Robert Dailey
Hi, I have a scalar value S. I want to perform the following math on vectors A and B (both of type array): A + B * S By order of operations, B * S should be done first. This is a vector multiplied by a real number and should be valid. However, the interpreter outputs: "ValueError: shape mism

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Lou Pecora
--- Robert Kern <[EMAIL PROTECTED]> wrote: > > Besides constructing the Euclidean norm itself (as > shown by others here), you > can also use numpy.linalg.norm() to calculate any of > several different norms of > a vector or a matrix: Right. linalg.norm also gives the proper magnitude of compl

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread lorenzo bolla
maybe numpy.vdot is good for you. In [3]: x = numpy.random.rand(4) In [4]: x Out[4]: array([ 0.45426898, 0.22369238, 0.98731244, 0.7758774 ]) In [5]: numpy.sqrt(numpy.vdot(x,x)) Out[5]: 1.35394615117 hth, lorenzo On 9/5/07, Robert Dailey <[EMAIL PROTECTED]> wrote: > > Oh I think I get it.

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Robert Kern
Robert Dailey wrote: > Thanks for your response. > > I was not able to find len() in the numpy documentation at the following > link: > http://www.scipy.org/doc/numpy_api_docs/namespace_index.html > > > Perhaps I'm looking in the wron

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bill Baxter
On 9/6/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > Bill Spotz wrote: > However, I'm beginning to have my doubts about valarrays. I'm reading: > > Josuttis, Nicolai M. 1999. "The C+= Standard Library: A Tutorial and > Reference" > > It's 8 years old now, but he writes: > > "The valarray clas

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Matthieu Brucher
> > He goes on to suggest that Blitz++ might have more of a future. (though > it looks like he's involved with the Boost project now) Blitz++ is more or less avandoned. It uses indexes than can be not-portable between 32bits platforms and 64bits ones. Is there another alternative? At the momen

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Robert Dailey
Oh I think I get it. You mean the built-in len() function? This isn't what I am looking for. len() returns the number of components in the vector (e.g. whether it is a 2D, 3D, etc vector). I found that magnitude can be calculated using hypot() in the math module that comes with python. However, th

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Matthieu Brucher
2007/9/5, Robert Dailey <[EMAIL PROTECTED]>: > > Thanks for your response. > > I was not able to find len() in the numpy documentation at the following > link: > http://www.scipy.org/doc/numpy_api_docs/namespace_index.html > > Perhaps I'm looking in the wrong location? Yes, it's a Python function

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Zachary Pincus
Hello, 'len' is a (pretty basic) python builtin function for getting the length of anything with a list-like interface. (Or more generally, getting the size of anything that is sized, e.g. a set or dictionary.) Numpy arrays offer a list-like interface allowing you to iterate along their fir

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Christopher Barker
Bill Spotz wrote: > Yes, this resizing memory management issue is the main reason I haven't > tried to implement it in numpy.i yet. > > A possibly better solution would be to develop a class that inherits > from std::valarray but also implements the array interface > attributes (these attribut

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Robert Dailey
Thanks for your response. I was not able to find len() in the numpy documentation at the following link: http://www.scipy.org/doc/numpy_api_docs/namespace_index.html Perhaps I'm looking in the wrong location? On 9/5/07, Matthieu Brucher <[EMAIL PROTECTED]> wrote: > > > > 2007/9/5, Robert Dailey

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bill Spotz
On Sep 5, 2007, at 11:38 AM, Christopher Barker wrote: > Of course, it should be possible to write C++ wrappers around the core > ND-array object, if anyone wants to take that on! boost::python has done this for Numeric, but last I checked, they have not upgraded to numpy. ** Bill Spotz

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bill Spotz
On Sep 5, 2007, at 11:19 AM, Christopher Barker wrote: > Bill Spotz wrote: >> I have been considering adding some C++ STL support to numpy/doc/ >> swig/ >> numpy.i. Probably std::vector <=> PyArrayObject (and some >> std::complex support as well). Is this what you had in mind? > > well, std::va

Re: [Numpy-discussion] Improving bug triage in trac ?

2007-09-05 Thread Robert Kern
David Cournapeau wrote: > Hi there, > > I am personnally a bit annoyed by the way trac handle bug reports, > and would like to know if there is space for improvement. I do not know > much about bug tracking systems, so maybe I just don't know how to use > it, though. The main thing I dislik

Re: [Numpy-discussion] numpy build fails on powerpc ydl

2007-09-05 Thread Charles R Harris
On 9/5/07, Vincent Broman <[EMAIL PROTECTED]> wrote: > > Harris asked about long doubles. > On my YDL, SIZEOF_LONG_DOUBLE and sizeof( long double) were both 8. Hmm, so long doubles are just doubles, I kinda suspected that. I'm not really familiar with this code, but what happens if you go to nump

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Christopher Barker
Joris De Ridder wrote: > A related question, just out of curiosity: is there a technical > reason why Numpy has been coded in C rather than C++? There was a fair bit of discussion about this back when the numarray project started, which was a re-implementation of the original Numeric. IIRC, on

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, "Bill Spotz" <[EMAIL PROTECTED]> wrote: > I have been considering adding some C++ STL support to numpy/doc/swig/ > numpy.i. Probably std::vector <=> PyArrayObject (and some > std::complex support as well). Is this what you had in mind? That sounds very useful

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Christopher Barker
Günter Dannoritzer wrote: > My data type is indexable and sliceable and what happens now is when I > create an array, NumPy is adding the instance as a list of the indexed > values. How can I force NumPy to handle my data type as an 'Object' Object arrays are tricky, 'cause it's hard for numpy t

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Matthieu Brucher
2007/9/5, Robert Dailey <[EMAIL PROTECTED]>: > > Hi, > > I have two questions: > > 1) Is there any way in numpy to represent vectors? Currently I'm using > 'array' for vectors. A vector is an array with one dimension, it's OK. You could use a matrix of dimension 1xn or nx1 as well. 2) Is there

Re: [Numpy-discussion] Vector magnitude?

2007-09-05 Thread Gael Varoquaux
On Wed, Sep 05, 2007 at 11:55:36AM -0500, Robert Dailey wrote: >1) Is there any way in numpy to represent vectors? Currently I'm using >'array' for vectors. What do you call a vector ? For me a vector is an element of an linear space. In numerical methods what is comonly called a vector is

Re: [Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Robert Kern
Günter Dannoritzer wrote: > Hi, > > I am trying to use my own data type with NumPy, but get some funny > result when creating a NumPy array with it. > > My data type is indexable and sliceable and what happens now is when I > create an array, NumPy is adding the instance as a list of the indexed

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Christopher Barker
Bill Spotz wrote: > I have been considering adding some C++ STL support to numpy/doc/swig/ > numpy.i. Probably std::vector <=> PyArrayObject (and some > std::complex support as well). Is this what you had in mind? well, std::valarray is not the same as std::vector, though there are similarit

Re: [Numpy-discussion] numpy build fails on powerpc ydl

2007-09-05 Thread Vincent Broman
Harris asked about long doubles. On my YDL, SIZEOF_LONG_DOUBLE and sizeof( long double) were both 8. Vincent Broman ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] Vector magnitude?

2007-09-05 Thread Robert Dailey
Hi, I have two questions: 1) Is there any way in numpy to represent vectors? Currently I'm using 'array' for vectors. 2) Is there a way to calculate the magnitude (length) of a vector in numpy? Thanks. ___ Numpy-discussion mailing list Numpy-discussio

Re: [Numpy-discussion] 2-d in-place operation performance vs 1-d non in-place

2007-09-05 Thread Francesc Altet
A Wednesday 05 September 2007, George Sakkis escrigué: > I was surprised to see that an in-place modification of a 2-d array > turns out to be slower from the respective non-mutating operation on > 1- d arrays, although the latter creates new array objects. Here is > the benchmarking code: > > impo

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread David Goldsmith
Not presently, as the C++ code I need to wrap now is using the valarray class template (largely at my behest), though I (and I imagine others) might find this useful in the future. DG Bill Spotz wrote: > I have been considering adding some C++ STL support to > numpy/doc/swig/numpy.i. Probably

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread David Goldsmith
No I hadn't - thanks! (Probably should have Google-d first, huh. :-[ ) DG Travis Vaught wrote: > Have you seen this? > > http://www.scipy.org/Cookbook/SWIG_and_NumPy > > Also, the numpy/doc/swig directory has the simple typemaps. > > Travis > > On Sep 5, 2007, at 7:08 AM, Xavier Gnata wrote: >

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread David Goldsmith
Point of clarification: below "well-tested" = "well-use-tested," not (necessarily) "well-unit-tested". DG David Goldsmith wrote: > Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array > typemap to share? Thanks! > > DG > -- ERD/ORR/NOS/NOAA

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Bill Spotz
I have been considering adding some C++ STL support to numpy/doc/swig/ numpy.i. Probably std::vector <=> PyArrayObject (and some std::complex support as well). Is this what you had in mind? On Sep 4, 2007, at 6:24 PM, David Goldsmith wrote: > Anyone have a well-tested SWIG-based C++ STL vala

[Numpy-discussion] 2-d in-place operation performance vs 1-d non in-place

2007-09-05 Thread George Sakkis
I was surprised to see that an in-place modification of a 2-d array turns out to be slower from the respective non-mutating operation on 1- d arrays, although the latter creates new array objects. Here is the benchmarking code: import timeit for n in 10,100,1000,1: setup = 'from numpy.rand

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Travis Vaught
Have you seen this? http://www.scipy.org/Cookbook/SWIG_and_NumPy Also, the numpy/doc/swig directory has the simple typemaps. Travis On Sep 5, 2007, at 7:08 AM, Xavier Gnata wrote: > I'm using the numpy C API (PyArray_SimpleNewFromData) to perform the > conversion but my code is written by hand

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Xavier Gnata
I'm using the numpy C API (PyArray_SimpleNewFromData) to perform the conversion but my code is written by hands. I would like to simplify it using SWIG but I also would like to see a good typemap valarray <=> numpy.array :) Joris : Historical ones? Maybe also the fact that distutils has some sm

Re: [Numpy-discussion] Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array typemap to share?

2007-09-05 Thread Joris De Ridder
A related question, just out of curiosity: is there a technical reason why Numpy has been coded in C rather than C++? Joris On 05 Sep 2007, at 02:24, David Goldsmith wrote: > Anyone have a well-tested SWIG-based C++ STL valarray <=> numpy.array > typemap to share? Thanks! > > DG > -- > ER

[Numpy-discussion] Improving bug triage in trac ?

2007-09-05 Thread David Cournapeau
Hi there, I am personnally a bit annoyed by the way trac handle bug reports, and would like to know if there is space for improvement. I do not know much about bug tracking systems, so maybe I just don't know how to use it, though. The main thing I dislike is the status of tickets and repo

[Numpy-discussion] Change array memory ownership status

2007-09-05 Thread Marc POINOT
I want to change the "status" of a numpy array. I mean this array was created by a server application using PyArray_FromDimsAndData that sets the NPY_OWNDATA flag to False. The server application believes the client would free the memory. But there are more than one client application and none k

[Numpy-discussion] Use my own data type with NumPy

2007-09-05 Thread Günter Dannoritzer
Hi, I am trying to use my own data type with NumPy, but get some funny result when creating a NumPy array with it. My data type is indexable and sliceable and what happens now is when I create an array, NumPy is adding the instance as a list of the indexed values. How can I force NumPy to handle