Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python.
alex23
wuwei23 at gmail.com
Tue Dec 20 23:27:07 EST 2011
On Dec 21, 10:24 am, Nathan Rice <nathan.alexander.r... at gmail.com>
wrote:
> The idea is to provide a syntax that lets you do very complex things
> on collections in a more readable manner, without having 5 or 6 lines
> of generator expressions.
Have you seen PyLINQ? It has a similar approach to operating on
collections, returning a PyLINQ object after each call to facilitate
chaining. https://github.com/kalessin/PyLINQ/blob/master/pylinq/linq.py
This is a personal opinion on the code, but I'd move instantiating the
new ElementwiseProxy out of each method and into its own decorator:
# declare this outside of the class
def chainable(fn):
def _(self, *args, **kwargs):
return ElementwiseProxy(fn(self, *args, **kwargs), self)
return _
This way, each method that is chainable is a little more obvious
without inspecting the code, and the method body itself is only doing
what the method says it does:
@chainable
def __add__(self, other):
return (e + other for e in object.__getattribute__(self,
"iterable"))
Incidentally, displaying an ElementwiseProxy instance doesn't go down
well with iPython:
In [1]: from elementwise import *
In [2]: e = ElementwiseProxy(['one','two','three'])
In [3]: e
Out[3]: ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (6, 0))
More information about the Python-list
mailing list