[Python-ideas] Vectorization [was Re: Add list.join() please]
Ben Rudiak-Gould
benrudiak at gmail.com
Sat Feb 2 18:54:18 EST 2019
On Sat, Feb 2, 2019 at 3:31 PM Steven D'Aprano <steve at pearwood.info> wrote:
> The comprehension version isn't awful:
>
> [(a*2).name.upper() for a in seq]
>
> but not all vectorized operations can be written as a chain of calls on
> a single sequence.
>
If they are strictly parallel (no dot products) and you know when writing
the code which variables hold vectors, then (denoting the vector variables
by v1, ..., vn) you can always write
[(expr with x1, ..., xn substituted for v1, ..., vn)
for x1, ..., xn in zip(v1, ..., vn)]
which seems not much worse than the auto-vectorized version (with or
without special syntax).
Haskell (GHC) has parallel list comprehension syntax (
https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#parallel-list-comprehensions)
so you don't have to explicitly call zip. I wouldn't mind having that in
Python but I don't know what the syntax would be.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190202/8173e336/attachment.html>
More information about the Python-ideas
mailing list