Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #442

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <nathan.alexander.rice@gmail.com>
X-Original-To python-announce-list@python.org
Delivered-To python-announce-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'example:': 0.03; 'value,': 0.04; 'attribute': 0.07; 'url:pypi': 0.08; 'assert': 0.09; 'false,': 0.09; 'foo': 0.09; 'subject:method': 0.09; 'url:github': 0.09; 'def': 0.13; 'intermediate': 0.15; '"with': 0.16; '[2,': 0.16; 'chained': 0.16; 'subject:function': 0.16; 'subject:python.': 0.16; 'subject:release': 0.16; 'syntax': 0.16; 'to:2**1': 0.21; 'message-id:@mail.gmail.com': 0.28; 'expressions': 0.29; 'true,': 0.29; 'print': 0.29; 'class': 0.29; 'correct': 0.29; 'comments.': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'subject:support': 0.30; 'rather': 0.33; 'there': 0.33; 'object': 0.33; 'to:addr:python-list': 0.34; 'things': 0.34; 'expanding': 0.35; 'url:python': 0.36; 'to:addr :python-announce-list': 0.37; 'to:name:python-list': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'role': 0.37; 'could': 0.37; 'some': 0.38; 'received:209.85': 0.38; 'url:org': 0.39; 'subject: (': 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'might': 0.40; 'chain': 0.66; 'sfxlen:3': 0.66; 'url:0': 0.67; 'refuse': 0.67; '11,': 0.68; 'concept': 0.74; 'calls,': 0.84; 'length:': 0.84; 'nathan': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=2N6ovxu7TLzZZkFQg2IvX83hhb70R55nrQI0a5n4FEc=; b=FufdxROTmE2L58Dmobr6BIeqvSmOAELFRWNpn5CdGwHmBAQzyAk2EEhn2hyoJlg+sH p9aGLzL0sG5Ip0s/TyTPiASSydG1EO8Mtni0Rla/O3ng8odq48aH1pH+E5JJaquXpszL YQzpHi3XO/CzBuu9ikpSy8ocsa/XZj1+jmxX8=
MIME-Version 1.0
Date Tue, 20 Dec 2011 14:45:06 -0500
Subject Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python.
From Nathan Rice <nathan.alexander.rice@gmail.com>
To python-list <python-list@python.org>, python-announce-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-Mailman-Approved-At Wed, 21 Dec 2011 17:59:06 +0100
X-BeenThere python-announce-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id Announcement-only list for the Python programming language <python-announce-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-announce-list>
List-Post <mailto:python-announce-list@python.org>
List-Help <mailto:python-announce-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe>
Approved python-announce-list@python.org
Newsgroups comp.lang.python.announce
Message-ID <mailman.3925.1324486747.27778.python-announce-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324486747 news.xs4all.nl 6920 [2001:888:2000:d::a6]:52718
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python.announce:442

Show key headers only | View raw


Elementwise provides a proxy object for iterables which supports
chained method calls, as well as elementwise expressions and some
built-in functions.

Example:

    class ExampleList(ElementwiseProxyMixin, list):
        def __new__(cls, iterable):
            return list.__new__(cls, iterable)
    foo = ExampleList([1, 2, 3, 4])

    # You could also do: efoo = ElementwiseProxy(foo)
    efoo = foo.each

    assert list(efoo.bit_length()) == [1, 2, 2, 3]
    print "bit length: ", list(efoo.bit_length())
    assert list(efoo + 1) == [2, 3, 4, 5]
    print "with addition of 1: ", list(efoo + 1)
    assert list(efoo * 2) == [2, 4, 6, 8]
    print "with multiplication by 2: ", list(efoo * 2)
    assert list(efoo == 2) == [False, True, False, False]
    print "testing equality: ", efoo == 2
    assert list((efoo + 1) * 2 + 3) == [7, 9, 11, 13]
    print "chaining addition and multiplication: ", (efoo + 1) * 2 + 3

Each ElementwiseProxy also has a "parent" attribute so you can
backtrack in the chain as needed rather than store each intermediate
value, if you think you might need them.

There are still some issues with proper support of things like bool()
and int(), which refuse to return things that are not of the correct
type.

Get it:

    PyPi: http://pypi.python.org/pypi/elementwise/0.111220
    GitHub: https://github.com/nathan-rice/Elementwise

This was developed as a proof of concept for expanding the role of
element-wise syntax in python, and to that end I welcome comments.

Nathan Rice

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Nathan Rice <nathan.alexander.rice@gmail.com> - 2011-12-20 14:45 -0500

csiph-web