Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Stuart Reynolds
Doh! Thanks for that. On Tue, Nov 15, 2016 at 10:48 AM, Marten van Kerkwijk < m.h.vankerkw...@gmail.com> wrote: > Hi Stuart, > > It certainly seems correct behaviour to return the subclass you > created: after all, you might want to keep the information on > `columns` (e.g., consider doing nanmin

Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Nathan Goldbaum
You might also want to consider writing a wrapper object that contains an ndarray as a (possibly private) attribute and then presents different views or interpretations of that array. Subclassing ndarray is a pit of snakes, it's best to avoid it if you can (I say as the author and maintainer of an

Re: [Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Marten van Kerkwijk
Hi Stuart, It certainly seems correct behaviour to return the subclass you created: after all, you might want to keep the information on `columns` (e.g., consider doing nanmin along a given axis). Indeed, we certainly want to keep the unit in astropy's Quantity (which also is a subclass of ndarray

[Numpy-discussion] subclassing ndarray and keeping same ufunc behavior

2016-11-15 Thread Stuart Reynolds
I'm trying to subclass an ndarray so that I can add some additional fields. When I do this however, I get new odd behavior when my object is passed to a variety of numpy functions. For example nanmin returns now return an object of the type of my new array class, whereas previously I'd get a float6

Re: [Numpy-discussion] Subclassing ma.masked_array, code broken after version 1.9

2016-02-15 Thread Charles R Harris
On Mon, Feb 15, 2016 at 10:06 AM, Gutenkunst, Ryan N - (rgutenk) < rgut...@email.arizona.edu> wrote: > Thank Jonathan, > > Good to confirm this isn't something inappropriate I'm doing. I give up > transparency here in my application, so I'll just work around it. I leave > it up to wiser numpy head

Re: [Numpy-discussion] Subclassing ma.masked_array, code broken after version 1.9

2016-02-15 Thread Sebastian Berg
On Mo, 2016-02-15 at 17:06 +, Gutenkunst, Ryan N - (rgutenk) wrote: > Thank Jonathan, > > Good to confirm this isn't something inappropriate I'm doing. I give > up transparency here in my application, so I'll just work around it. > I leave it up to wiser numpy heads as to whether it's worth al

Re: [Numpy-discussion] Subclassing ma.masked_array, code broken after version 1.9

2016-02-15 Thread Gutenkunst, Ryan N - (rgutenk)
Thank Jonathan, Good to confirm this isn't something inappropriate I'm doing. I give up transparency here in my application, so I'll just work around it. I leave it up to wiser numpy heads as to whether it's worth altering these numpy.ma functions to enable subclassing. Best, Ryan On Feb 13,

Re: [Numpy-discussion] Subclassing ma.masked_array, code broken after version 1.9

2016-02-13 Thread Jonathan Helmus
On 2/12/16 6:06 PM, Gutenkunst, Ryan N - (rgutenk) wrote: Hello all, In 2009 I developed an application that uses a subclass of masked arrays as a central data object. My subclass Spectrum possesses additional attributes along with many custom methods. It was very convenient to be able to us

[Numpy-discussion] Subclassing ma.masked_array, code broken after version 1.9

2016-02-12 Thread Gutenkunst, Ryan N - (rgutenk)
Hello all, In 2009 I developed an application that uses a subclass of masked arrays as a central data object. My subclass Spectrum possesses additional attributes along with many custom methods. It was very convenient to be able to use standard numpy functions for doing arithmetic on these obje

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-02-01 Thread Todd
On Wed, Jan 30, 2013 at 11:20 AM, Sebastian Berg wrote: > > > > > > > > In my particular case at least, there are clear ways to > > handle corner > > > cases (like being passed a class that lacks these > > attributes), so in > > > principle there no problem

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-30 Thread Sebastian Berg
On Wed, 2013-01-30 at 10:24 +0100, Todd wrote: > On Tue, Jan 22, 2013 at 1:44 PM, Sebastian Berg > wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > > > The main exception I have found is concatenate (and > hstack/vstack

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-30 Thread Todd
On Tue, Jan 22, 2013 at 1:44 PM, Sebastian Berg wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > > The main exception I have found is concatenate (and hstack/vstack, > > which just wrap concatenate). In this case, __array_finalize__ is > > passed an array that has already been

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Sebastian Berg
On Tue, 2013-01-22 at 13:44 +0100, Sebastian Berg wrote: > Hey, > > On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > > I am trying to create a subclass of ndarray that has additional > > attributes. These attributes are maintained with most numpy functions > > if __array_finalize__ is used. > >

Re: [Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Sebastian Berg
Hey, On Tue, 2013-01-22 at 10:21 +0100, Todd wrote: > I am trying to create a subclass of ndarray that has additional > attributes. These attributes are maintained with most numpy functions > if __array_finalize__ is used. > You can cover a bit more if you also implement `__array_wrap__`, thou

[Numpy-discussion] Subclassing ndarray with concatenate

2013-01-22 Thread Todd
I am trying to create a subclass of ndarray that has additional attributes. These attributes are maintained with most numpy functions if __array_finalize__ is used. The main exception I have found is concatenate (and hstack/vstack, which just wrap concatenate). In this case, __array_finalize__ i

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Chris Barker
On Tue, May 22, 2012 at 1:07 PM, Dan Goodman wrote: > I think it would be useful to have an example of a completely > 'correctly' subclassed ndarray that handles all of these issues that > people could use as a template when they want to subclass ndarray. I think this is by definition impossible

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Tom Aldcroft
On Tue, May 22, 2012 at 4:07 PM, Dan Goodman wrote: > On 22/05/2012 18:20, Nathaniel Smith wrote: >> I don't know of anything that the docs are lacking in particular. It's >> just that subclassing in general is basically a special form of >> monkey-patching: you have this ecosystem of cooperating

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Dan Goodman
On 22/05/2012 18:20, Nathaniel Smith wrote: > I don't know of anything that the docs are lacking in particular. It's > just that subclassing in general is basically a special form of > monkey-patching: you have this ecosystem of cooperating methods, and > then you're inserting some arbitrary change

Re: [Numpy-discussion] subclassing ndarray subtleties??

2012-05-22 Thread Nathaniel Smith
On Mon, May 21, 2012 at 6:47 PM, Tom Aldcroft wrote: > Over on the scipy-user mailing list there was a question about > subclassing ndarray and I was interested to see two responses that > seemed to imply that subclassing should be avoided. > > >From Dag and Nathaniel, respectively: > > "Subclassi

[Numpy-discussion] subclassing ndarray subtleties??

2012-05-21 Thread Tom Aldcroft
Over on the scipy-user mailing list there was a question about subclassing ndarray and I was interested to see two responses that seemed to imply that subclassing should be avoided. >From Dag and Nathaniel, respectively: "Subclassing ndarray is a very tricky business -- I did it once and regrette

Re: [Numpy-discussion] subclassing array in c

2012-03-30 Thread mark florisson
On 30 March 2012 21:40, mark florisson wrote: > On 30 March 2012 21:38, mark florisson wrote: >> On 30 March 2012 19:53, Chris Barker wrote: >>> On Fri, Mar 30, 2012 at 10:57 AM, mark florisson >>> wrote: Although the segfault was caused by a bug in NumPy, you should probably also con

Re: [Numpy-discussion] subclassing array in c

2012-03-30 Thread mark florisson
On 30 March 2012 21:38, mark florisson wrote: > On 30 March 2012 19:53, Chris Barker wrote: >> On Fri, Mar 30, 2012 at 10:57 AM, mark florisson >> wrote: >>> Although the segfault was caused by a bug in NumPy, you should >>> probably also consider using Cython, which can make a lot of this pain

Re: [Numpy-discussion] subclassing array in c

2012-03-30 Thread mark florisson
On 30 March 2012 19:53, Chris Barker wrote: > On Fri, Mar 30, 2012 at 10:57 AM, mark florisson > wrote: >> Although the segfault was caused by a bug in NumPy, you should >> probably also consider using Cython, which can make a lot of this pain >> and boring stuff go away. > > Is there a good demo

Re: [Numpy-discussion] subclassing array in c

2012-03-30 Thread Chris Barker
On Fri, Mar 30, 2012 at 10:57 AM, mark florisson wrote: > Although the segfault was caused by a bug in NumPy, you should > probably also consider using Cython, which can make a lot of this pain > and boring stuff go away. Is there a good demo/sample somewhere of an ndarray subclass in Cython? So

Re: [Numpy-discussion] subclassing array in c

2012-03-30 Thread mark florisson
On 29 March 2012 09:07, Christoph Gohle wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > Am 08.03.2012 um 20:39 schrieb Pauli Virtanen: > >> 08.03.2012 17:37, Christoph Gohle kirjoitti: >>> thanks for testing. I have now tried on different platforms. I get >>> all kinds of crashes on

Re: [Numpy-discussion] subclassing array in c

2012-03-29 Thread Christoph Gohle
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 08.03.2012 um 20:39 schrieb Pauli Virtanen: > 08.03.2012 17:37, Christoph Gohle kirjoitti: >> thanks for testing. I have now tried on different platforms. I get >> all kinds of crashes on os x (now with numpy 1.6.1) and windows >> with numpy 1.6.0

Re: [Numpy-discussion] subclassing array in c

2012-03-29 Thread Christoph Gohle
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Am 08.03.2012 um 20:39 schrieb Pauli Virtanen: > 08.03.2012 17:37, Christoph Gohle kirjoitti: >> thanks for testing. I have now tried on different platforms. I get >> all kinds of crashes on os x (now with numpy 1.6.1) and windows >> with numpy 1.6.0

Re: [Numpy-discussion] subclassing array in c

2012-03-09 Thread Pauli Virtanen
09.03.2012 08:00, Christoph Gohle kirjoitti: > I don't want to look as if I want other people do my work, > so I would like to ask if there is a simple way of tracing > memory leaks (without recompiling the python interpreter)? The easiest way probably is to compile Numpy with debug symbols on, s

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Francesc Alted
Sure. Check the memcheck tool of Valgrind: http://valgrind.org/info/tools.html#memcheck It is a really amazing tool. Francesc On Mar 8, 2012, at 11:00 PM, Christoph Gohle wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi again, > > I don't want to look as if I want other peop

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Christoph Gohle
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi again, I don't want to look as if I want other people do my work, so I would like to ask if there is a simple way of tracing memory leaks (without recompiling the python interpreter)? Cheers, Christoph Am 09.03.2012 um 01:22 schrieb Christoph Go

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Christoph Gohle
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Am 08.03.2012 um 20:39 schrieb Pauli Virtanen: > 08.03.2012 17:37, Christoph Gohle kirjoitti: >> thanks for testing. I have now tried on different platforms. I get >> all kinds of crashes on os x (now with numpy 1.6.1) and windows >> with numpy 1.6

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Pauli Virtanen
08.03.2012 17:37, Christoph Gohle kirjoitti: > thanks for testing. I have now tried on different platforms. I get > all kinds of crashes on os x (now with numpy 1.6.1) and windows > with numpy 1.6.0. On Ubuntu with numpy 1.3.0 I get a hughe memory > leak... > > Any hints would be welcome. The typ

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Christoph Gohle
Dear Val, thanks for testing. I have now tried on different platforms. I get all kinds of crashes on os x (now with numpy 1.6.1) and windows with numpy 1.6.0. On Ubuntu with numpy 1.3.0 I get a hughe memory leak... Any hints would be welcome. Thanks, Christoph Am 08.03.2012 um 09:08 schrieb Va

Re: [Numpy-discussion] subclassing array in c

2012-03-08 Thread Val Kalatsky
Hi Christoph, I've just tried a=[spampub.UnitArray(i,{'s':i}) for i in xrange(1000)] and everything looks fine on my side. Probably my test environment is too different to give comparable results: In [3]: call(["uname", "-a"]) Linux ubuntu 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:32:27 UTC

Re: [Numpy-discussion] subclassing array in c

2012-03-07 Thread Christoph Gohle
Dear Val, I agree that more detail is needed. Sorry for that it was late yesterday. I am running Python 2.6.1, numpy development branch (numpy-2.0.0.dev_20101104-py2.6-macosx-10.6-universal.egg). maybe I should switch to release? I compile with your setup.py using 'python setup.py build_ext -

Re: [Numpy-discussion] subclassing array in c

2012-03-07 Thread Christoph Gohlke
FWIW, this crashes on Windows with numpy 1.6.1 but not numpy 1.7-git debug build. Christoph Gohlke On 3/7/2012 5:36 PM, Val Kalatsky wrote: > > Tried it on my Ubuntu 10.10 box, no problem: > > 1) Saved as spampub.c > 2) Compiled with (setup.py attached): python setup.py build_ext -i > 3) Tested

Re: [Numpy-discussion] subclassing array in c

2012-03-07 Thread Val Kalatsky
Tried it on my Ubuntu 10.10 box, no problem: 1) Saved as spampub.c 2) Compiled with (setup.py attached): python setup.py build_ext -i 3) Tested from ipython: In [1]: import spampub In [2]: ua=spampub.UnitArray([0,1,2,3.0],'liter') In [3]: ua Out[3]: UnitArray([ 0., 1., 2., 3.]) In [4]: ua.unit

Re: [Numpy-discussion] subclassing array in c

2012-03-07 Thread Val Kalatsky
Seeing the backtrace would be helpful. Can you do whatever leads to the segfault from python run from gdb? Val On Wed, Mar 7, 2012 at 7:04 PM, Christoph Gohle wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi, > > I have been struggeling for quite some time now. Desperate as I am, n

[Numpy-discussion] subclassing array in c

2012-03-07 Thread Christoph Gohle
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I have been struggeling for quite some time now. Desperate as I am, now I need help. I was trying to subclass ndarrays in a c extension (see code below) and do constantly get segfaults. I have been checking my INCREF and DECREF stuff up and

[Numpy-discussion] subclassing ndarray

2011-11-21 Thread Chris.Barker
Hi folks, I'm working on a "ragged array" class -- an array that can store and work with what can be considered tabular data, with the rows of different lengths: """ ragged_array A "ragged" array class -- build on numpy The idea is to be able to store data that is essentially 2-d, but each

[Numpy-discussion] Subclassing ndarray

2011-11-18 Thread Fabrice Silva
Hi, I wish I could subclass ndarray so that I can use the ufuncs, but that I could ensure the array remains Fortran contiguous, and that the number of dimension is always 3 (even if the dtype can be more complex than a simple numerical type). My intention is to deal with fields that can be scalar,

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pierre GM
On Jul 28, 2010, at 7:52 PM, Pauli Virtanen wrote: > Wed, 28 Jul 2010 18:43:30 -0400, Pierre GM wrote: > [clip] >> Mmh. I did create a PyMappingMethod structure called MyArray_as_mapping, >> and MyArray_as_mapping.mp_subscript points to the function that I want >> to use. However, I'd like the My

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pauli Virtanen
Wed, 28 Jul 2010 18:43:30 -0400, Pierre GM wrote: [clip] > Mmh. I did create a PyMappingMethod structure called MyArray_as_mapping, > and MyArray_as_mapping.mp_subscript points to the function that I want > to use. However, I'd like the MyArray_as_mapping.length and > MyArray.mp_ass_subscript to po

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Pierre GM
On Jul 28, 2010, at 5:52 PM, Travis Oliphant wrote: > > On Jul 26, 2010, at 11:58 AM, Pierre GM wrote: > >> All, >> I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain >> C). It's slowly coming together, but I'm now running into a problem: I need >> to overwrite __get

Re: [Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-28 Thread Travis Oliphant
On Jul 26, 2010, at 11:58 AM, Pierre GM wrote: > All, > I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain > C). It's slowly coming together, but I'm now running into a problem: I need > to overwrite __getitem__ and I'm not sure how to do it. I was thinking about > us

[Numpy-discussion] Subclassing ndarray in C: getitem ?

2010-07-26 Thread Pierre GM
All, I'm teaching myself how to subclass ndarrays in C (not in Cython, just plain C). It's slowly coming together, but I'm now running into a problem: I need to overwrite __getitem__ and I'm not sure how to do it. I was thinking about using my own function instead of array_as_mapping.mp_subscrip

Re: [Numpy-discussion] Subclassing ma.MaskedArray

2010-03-16 Thread Matt Knox
David Carmean halibut.com> writes: > > > I understand that ma.MaskedArray is a subclass of ndarray; in addition to > the requirements for subclassing the latter, what does ma.MaskedArray add to > the list? I.e. what do I have to watch out for? You may want to take a look at the TimeSeries cl

[Numpy-discussion] Subclassing ma.MaskedArray

2010-03-16 Thread David Carmean
I understand that ma.MaskedArray is a subclass of ndarray; in addition to the requirements for subclassing the latter, what does ma.MaskedArray add to the list? I.e. what do I have to watch out for? Basically I need a version of Luke Campagnola's MetaArray ( http://www.scipy.org/Cookbook/M

Re: [Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Darren Dale
Hi Pauli, On Thu, Mar 11, 2010 at 3:38 PM, Pauli Virtanen wrote: > Thanks for testing. I wish the test suite was more complete (hint! > hint! :) I'll be happy to contribute, but lately I get a few 15-30 minute blocks a week for this kind of work (hence the short attempt to work on Quantities thi

Re: [Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Pauli Virtanen
Hi Darren, to, 2010-03-11 kello 11:11 -0500, Darren Dale kirjoitti: > Now that the trunk has some support for python3, I am working on > making Quantities work with python3 as well. I'm running into some > problems related to subclassing ndarray that can be illustrated with a > simple script, repr

[Numpy-discussion] subclassing ndarray in python3

2010-03-11 Thread Darren Dale
Now that the trunk has some support for python3, I am working on making Quantities work with python3 as well. I'm running into some problems related to subclassing ndarray that can be illustrated with a simple script, reproduced below. It looks like there is a problem with the reflected operations,

Re: [Numpy-discussion] Subclassing record array

2009-10-18 Thread Darren Dale
On Sun, Oct 18, 2009 at 12:22 AM, Charles R Harris wrote: > > > On Sat, Oct 17, 2009 at 9:13 AM, Loïc BERTHE wrote: >> >>   Hi, >> >> I would like to create my own class of record array to deal with units. >> >> Here is the code I used, inspired from >> >> http://docs.scipy.org/doc/numpy-1.3.x/us

Re: [Numpy-discussion] Subclassing record array

2009-10-17 Thread Charles R Harris
On Sat, Oct 17, 2009 at 9:13 AM, Loïc BERTHE wrote: > Hi, > > I would like to create my own class of record array to deal with units. > > Here is the code I used, inspired from > > http://docs.scipy.org/doc/numpy-1.3.x/user/basics.subclassing.html#slightly-more-realistic-example-attribute-added

[Numpy-discussion] Subclassing record array

2009-10-17 Thread Loïc BERTHE
Hi, I would like to create my own class of record array to deal with units. Here is the code I used, inspired from http://docs.scipy.org/doc/numpy-1.3.x/user/basics.subclassing.html#slightly-more-realistic-example-attribute-added-to-existing-array : [code] from numpy import * class BlocArra

Re: [Numpy-discussion] subclassing

2009-09-29 Thread Keith Goodman
On Tue, Sep 29, 2009 at 11:25 AM, Robert Kern wrote: > On Tue, Sep 29, 2009 at 13:19, Keith Goodman wrote: >> I ran across a problem while using numpy. But the problem is more of >> python problem. I hope I am not too far off topic. >> >> I have a class and a subclass: >> >> class myclass: >> >>

Re: [Numpy-discussion] subclassing

2009-09-29 Thread Robert Kern
On Tue, Sep 29, 2009 at 13:19, Keith Goodman wrote: > I ran across a problem while using numpy. But the problem is more of > python problem. I hope I am not too far off topic. > > I have a class and a subclass: > > class myclass: > >    def __init__(self, x): >        self.x = x > >    def __getit

[Numpy-discussion] subclassing

2009-09-29 Thread Keith Goodman
I ran across a problem while using numpy. But the problem is more of python problem. I hope I am not too far off topic. I have a class and a subclass: class myclass: def __init__(self, x): self.x = x def __getitem__(self, index): if type(index) is slice: x =

Re: [Numpy-discussion] subclassing from np.ndarray and np.rec.recarray

2009-07-06 Thread Pierre GM
On Jul 6, 2009, at 1:12 PM, Elaine Angelino wrote: > Hi -- We are subclassing from np.rec.recarray and are confused about > how some methods of np.rec.recarray relate to (differ from) > analogous methods of its parent, np.ndarray. Below are specific > questions about the __eq__, __getitem__

[Numpy-discussion] subclassing from np.ndarray and np.rec.recarray

2009-07-06 Thread Elaine Angelino
Hi -- We are subclassing from np.rec.recarray and are confused about how some methods of np.rec.recarray relate to (differ from) analogous methods of its parent, np.ndarray. Below are specific questions about the __eq__, __getitem__ and view methods, we'd appreciate answers to our specific questio

[Numpy-discussion] subclassing ndarray

2008-12-05 Thread Steve Schmerler
Hi all I'm subclassing ndarray following [1] and I'd like to know if i'm doing it right. My goals are - ndarray subclass MyArray with additional methods - replacement for np.array, np.asarray on module level returning MyArray instances - expose new methods as functions on module level

Re: [Numpy-discussion] subclassing matrix

2008-01-12 Thread Basilisk96
Thanks Stefan and Colin, The subclass documentation made this a little clearer now. Instead of using a super() call in __new__, I now do this: #construct a matrix based on the input ret = _N.matrix(data, dtype=dtype) #promote it to Vector ret = ret.view(cls) The second statement

Re: [Numpy-discussion] subclassing matrix

2008-01-12 Thread Colin J. Williams
Basilisk96 wrote: > On Jan 12, 1:36 am, "Timothy Hochberg" <[EMAIL PROTECTED]> wrote: >> I believe that you need to look at __array_finalize__ and __array_priority__ >> (and there may be one other thing as well, I can't remember; it's late). >> Search for __array_finalize__ and that will probably h

Re: [Numpy-discussion] subclassing matrix

2008-01-12 Thread Stefan van der Walt
On Sat, Jan 12, 2008 at 01:24:31PM -0800, Basilisk96 wrote: [...] > When is __array_finalize__ called? By adding some print traces, I can > see it's called every time an array is modified in any way i.e., > reshaped, transposed, etc., and also during operations like u+v, u-v, > A*u. But it's not

Re: [Numpy-discussion] subclassing matrix

2008-01-12 Thread Basilisk96
On Jan 12, 1:36 am, "Timothy Hochberg" <[EMAIL PROTECTED]> wrote: > I believe that you need to look at __array_finalize__ and __array_priority__ > (and there may be one other thing as well, I can't remember; it's late). > Search for __array_finalize__ and that will probably help get you started. >

Re: [Numpy-discussion] subclassing matrix

2008-01-11 Thread Timothy Hochberg
On Jan 11, 2008 9:59 PM, Basilisk96 <[EMAIL PROTECTED]> wrote: > On Jan 11, 2008, Colin J. Williams wrote: > > > You make a good case that it's good not > > to need to ponder what sort of > > vector you are dealing with. > > > > My guess is that the answer to your > > question is "no" but I would

Re: [Numpy-discussion] subclassing matrix

2008-01-11 Thread Basilisk96
On Jan 11, 2008, Colin J. Williams wrote: > You make a good case that it's good not > to need to ponder what sort of > vector you are dealing with. > > My guess is that the answer to your > question is "no" but I would need to > play with your code to see that. My > feeling is that, at the bottom

Re: [Numpy-discussion] subclassing matrix

2008-01-10 Thread Basilisk96
Yes, that certainly meets the need. In previous applications, I never thought to use Vector because it was sufficient for me to adopt the convention of a column vector to represent XY points. That way, I could do things like c * R * u + t. Isn't that simple? Not only is it easy on the eyes, but i

Re: [Numpy-discussion] subclassing matrix

2008-01-10 Thread Colin J. Williams
Basilisk96 wrote: > Hello folks, > > In the course of a project that involved heavy use of geometry and > linear algebra, I found it useful to create a Vector subclass of > numpy.matrix (represented as a column vector in my case). Why not consider a matrix with a shape of (1, n) as a row vector

[Numpy-discussion] subclassing matrix

2008-01-09 Thread Basilisk96
Hello folks, In the course of a project that involved heavy use of geometry and linear algebra, I found it useful to create a Vector subclass of numpy.matrix (represented as a column vector in my case). I'd like to hear comments about my use of this "class promotion" statement in __new__: ret

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-11 Thread Bernhard Voigt
Hi Pierre, that's great! I didn't do exactly what I wanted, but seeing how to overwrite the __getitem__ and __getslice__ methods I can adapt my class that it works with the use cases I need. Thanks for your help! Bernhard On 5/11/07, Pierre GM <[EMAIL PROTECTED]> wrote: Bernhard, Looks like y

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-10 Thread Pierre GM
Bernhard, Looks like you have to modify your __getitem__ and __getslice__ methods. The following seems to work in simple cases. The numpy.array in front of numpy.ndarray.__getxxx__ is to transform the 'numpy.void def __getitem__(self, key): if isinstance(key, arraydict) and key.dtyp

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-10 Thread Bernhard Voigt
Sorry for the spam, but I didn't modify the subject of the previous mail. Here's the message again but now with the right subject: Dear Pierre, I've attached the arraydict implementation file. You can run it and take a look at the following example on your own: In [25]: run arraydict.py create

Re: [Numpy-discussion] subclassing ndarray and recarray

2007-05-09 Thread Pierre GM
On Wednesday 09 May 2007 08:54:37 Bernhard Voigt wrote: > I'm trying to subclass ndarray or recarray to build a record array that has > a dictionary with a mapping of keys to array indexes and vice versa. Bernhard, Could you send me the rest of your code ? I'd like to test a couple of things bef

[Numpy-discussion] subclassing ndarray and recarray

2007-05-09 Thread Bernhard Voigt
I'm trying to subclass ndarray or recarray to build a record array that has a dictionary with a mapping of keys to array indexes and vice versa. I come across the problem, that depending on the field access method I get different types back: # a is a sublcass of record array print type(a) pr

[Numpy-discussion] Subclassing ndarray in Pyrex

2007-01-31 Thread Pierre GM
I'm still trying to subclass ndarray in Pyrex, without much success so far. I started to follow Francesc's suggestion (http://projects.scipy.org/pipermail/numpy-discussion/2007-January/025644.html), but that doesn't fit what I need: the myarray class Francesc introduced is just an object, not

Re: [Numpy-discussion] subclassing float64 (and friends)

2007-01-05 Thread Travis Oliphant
Stefan van der Walt wrote: > On Wed, Jan 03, 2007 at 05:12:40PM -0600, eric jones wrote: > >> Thanks for the update. For now, I'll try doing what I need to by >> sub-classing float. But, I'm gonna miss __array_finalize__ :-). >> > > Looks like r3493 is intended to fix this. The 'view' m

Re: [Numpy-discussion] subclassing float64 (and friends)

2007-01-05 Thread Stefan van der Walt
On Wed, Jan 03, 2007 at 05:12:40PM -0600, eric jones wrote: > Thanks for the update. For now, I'll try doing what I need to by > sub-classing float. But, I'm gonna miss __array_finalize__ :-). Looks like r3493 is intended to fix this. The 'view' method works now, but I still see In [2]: impor

Re: [Numpy-discussion] subclassing float64 (and friends)

2007-01-03 Thread eric jones
Thanks for the update. For now, I'll try doing what I need to by sub-classing float. But, I'm gonna miss __array_finalize__ :-). eric Travis Oliphant wrote: > eric jones wrote: > > >> Hey all, >> >> I am playing around with sub-classing the new-fangled float64 objects >> and friends. I r

Re: [Numpy-discussion] subclassing float64 (and friends)

2007-01-03 Thread Travis Oliphant
eric jones wrote: >Hey all, > >I am playing around with sub-classing the new-fangled float64 objects >and friends. I really like the new ndarray subclassing features >(__array_finalize__, etc.), and was exploring whether or not the scalars >worked the same way. I've stubbed my toe right out o

Re: [Numpy-discussion] subclassing float64 (and friends)

2007-01-03 Thread Stefan van der Walt
On Wed, Jan 03, 2007 at 04:29:10AM -0600, eric jones wrote: > I am playing around with sub-classing the new-fangled float64 objects > and friends. I really like the new ndarray subclassing features > (__array_finalize__, etc.), and was exploring whether or not the scalars > worked the same way.

[Numpy-discussion] subclassing float64 (and friends)

2007-01-03 Thread eric jones
Hey all, I am playing around with sub-classing the new-fangled float64 objects and friends. I really like the new ndarray subclassing features (__array_finalize__, etc.), and was exploring whether or not the scalars worked the same way. I've stubbed my toe right out of the blocks though. I

Re: [Numpy-discussion] subclassing recarray

2007-01-02 Thread Stefan van der Walt
Hi Matthew On Tue, Jan 02, 2007 at 02:30:34AM -0500, Matthew Koichi Grimes wrote: > Is it hard to subclass recarrays? I'm currently working on a subclass > that doesn't add much; just some methods that sets all the values to > zero and other similarly trivial things. It'd be nice to make it wor

[Numpy-discussion] subclassing recarray

2007-01-01 Thread Matthew Koichi Grimes
Is it hard to subclass recarrays? I'm currently working on a subclass that doesn't add much; just some methods that sets all the values to zero and other similarly trivial things. It'd be nice to make it work, but if I have to use external functions on a plain recarray instead of this subclass