[Numpy-discussion] question about optimizing
Charles R Harris
Sat May 17 15:18:43 CDT 2008
On Sat, May 17, 2008 at 1:45 PM, Charles R Harris <email@example.com>
> On Sat, May 17, 2008 at 1:18 PM, Anne Archibald <firstname.lastname@example.org>
>> 2008/5/17 Brian Blais <email@example.com>:
>> > at least for me, that was the motivation. I am trying to build a
>> > framework for part of the brain, which requires connected layers of
>> > A layer is either a 1D or 2D structure of nodes, with each node a
>> > relatively complex beast. Rather than reinvent the indexing (1D, 2D,
>> > slicing, etc...), I just inherited from ndarray. I thought, after the
>> > that some numpy functions on arrays would help speed up the code, which
>> > consists mostly of calling an update function on all nodes, passing each
>> > them an input vector. I wasn't sure if there would be any speed up for
>> > this, compared to
>> > for n in self.flat:
>> > n.update(input_vector)
>> > From the response, the answer seems to be no, and that I should stick
>> > the python loops for clarity. But also, the words of Anne Archibald,
>> > me think that I have made a bad choice by inheriting from ndarray,
>> > I am not sure what a convenient alternative would be.
>> Well, it doesn't exist yet, but a handy tool would be a factory
>> function "ArrayOf"; you would pass it a class, and it would produce a
>> subclass of ndarray designed to contain that class.
> Subclasses should generally be avoided unless they satisfy the "is a"
> criterion, which I don't think a matrix stack does. That is to say, a
> subclass should behave as an ndarray in *all* ways except for added
> functionality. All we want is an item type with dimensions.
Base classes also tend to have limited functionality that will be common to
all derived types. The object type in Python has only a few methods and
In : dir(object)
And overloading any of these is likely to cause trouble.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion