Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python.

Ian Kelly ian.g.kelly at gmail.com
Wed Dec 21 12:51:37 EST 2011


On Wed, Dec 21, 2011 at 9:48 AM, Joshua Landau
<joshua.landau.ws at gmail.com> wrote:
> functions, that before you were doing on a single item.
> BEFORE:
> item = foreignfunc1(item)
> item = foreignfunc2(item)
> item = foreignfunc3(item)
>
> NOW (your method):
> item = ElementwiseProxy(item)
> item = foreignfunc1(item)
> item = foreignfunc2(item)
> item = foreignfunc3(item)
> item = list(item)

Shouldn't that be:

item = ElementwiseProxy(item)
item = item.apply(foreignfunc1)
item = item.apply(foreignfunc2)
item = item.apply(foreignfunc3)
item = list(item)

> You might think your method works. But what if foreignfunc is "str"? And you
> can't blacklist functions. You can't say everything works bar A, B and C.
> What if you get: "lambda x:str(x)"? You can't blacklist that. That makes the
> ElementwiseProxy version buggy and prone to unstable operation. If it's
> consistent, fine. But it's not.

I'm not sure I understand this criticism.  There is no "blacklisting"
going on that I am aware of.  The behavior seems consistent to me:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from elementwise import *
>>> ewp = ElementwiseProxy(range(5))
>>> str(ewp)
'0, 1, 2, 3, 4'
>>> (lambda x: str(x))(ewp)
'0, 1, 2, 3, 4'
>>> ewp.apply(str)
'0', '1', '2', '3', '4'
>>> ewp.apply(lambda x: str(x))
'0', '1', '2', '3', '4'

All of which is exactly what I expected to get.

Cheers,
Ian



More information about the Python-list mailing list