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


Groups > comp.lang.python > #17604

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

Date 2011-12-20 14:45 -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>
Newsgroups comp.lang.python
Message-ID <mailman.3876.1324410310.27778.python-list@python.org> (permalink)

Show all headers | 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 | Previous | NextNext in thread | 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
  Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-20 20:29 +0000
    Re: 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 15:45 -0500
      Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-20 21:00 +0000
        Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Paul Rubin <no.email@nospam.invalid> - 2011-12-20 13:08 -0800
          Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-21 00:12 +0000
        Re: 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 16:20 -0500
          Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-21 00:28 +0000
            Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Ethan Furman <ethan@stoneleaf.us> - 2011-12-21 09:22 -0800
    Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. MRAB <python@mrabarnett.plus.com> - 2011-12-20 20:47 +0000
    Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. Chris Angelico <rosuav@gmail.com> - 2011-12-21 08:10 +1100

csiph-web