Elementwise - Lazy operation proxies for iterables

Elementwise provides convenient, fully lazy, abstract programming behavior for interacting with iterable objects. All attempts at attribute access on OperationProxy objects return generator factories wrapped in OperationProxy objects. This means that you can generatively build up complex operation chains and apply these chains of operations repeatedly, to different source iterables. Additionally, each OperationProxy object has a reference to its parent OperationProxy, allowing you to traverse up the function tree, undoing operations or modying previous processes.

Elementwise provides three proxy objects:

1.) ElementwiseProxy
This broadcasts all operations performed on the proxy to every member of the proxied iterable.
2.) PairwiseProxy

This treats the arguments of all operations performed as iterables which emit the correct argument value for the operation on the element from the proxied iterable with the same index. For example:

>>> PairwiseProxy([1, 2, 3, 4]) + [1, 2, 3, 4]
PairwiseProxy([2, 4, 6, 8])
3.) RecursiveElementwiseProxy
This behaves like ElementwiseProxy, with the notable exception that when a member value is a non string iterable, it will recursively try to apply the operation to child nodes. This proxy is capable of arbitrary graph traversal in a depth first fashion, and will not visit a node twice.

Each of the proxy objects can mutate into any of the other types by calling a mutator method.

When you would like to perform the operation chain represented by your proxy, simply iterate over it. The easiest way to do this is probably to call list with the proxy as the argument.

If you would like to perform the same operation chain on another iterable, all OperationProxy subclasses support OperationProxy.replicate() which takes an iterable and generates a new chain, which is a duplicate of the current chain with that iterable as the base data source.

If for some reason you would like to undo an operation, all OperationProxy subclasses support OperationProxy.undo(), which accepts an integer number of operations that should be undone (defaulting to 1) and returns a reference to the OperationProxy representing that step in the chain.

Note

There are some exceptions to the broadcasting behavior that can not be circumvented. This includes most methods uesd by builtin types that were formerly functions, such as __str__ and __nonzero__. When you need to broadcast these operations, use ElementwiseProxy.apply().

class elementwise.ElementwiseProxy(iterable=(), parent=None)[source]

Provides elementwise operator behavior, attribute access and method calls over a parent iterable.

First, create an ElementwiseProxy from any iterable, like so:

nums = ElementwiseProxy([1, 2, 3, 4])

You can perform a large vareity of operations on the proxy, and it will create a chain of operations to be applied to the contents of the iterable being proxied. The proxy is fully lazy, so none of the operations will be applied until you begin to request values from the proxy by iterating over it.

For example:

>>> print nums.bit_length()
1, 2, 2, 3
>>> nums + 1
2, 3, 4, 5
>>> print nums * 2
2, 4, 6, 8
>>> print nums == 2
False, True, False, False
>>> print ((nums + 1) * 2 + 3).apply(float)
7.0, 9.0, 11.0, 13.0
>>> print (nums.apply(float) + 0.0001).apply(round, 2)
1.0, 2.0, 3.0, 4.0
>>> print abs(nums - 3)
2, 1, 0, 1
>>> print (nums * 2 + 3) / 4
>>> list(efoo2.undo(3))
1, 2, 3, 4
>>> print ((nums * 2 + 3) / 4).replicate([2, 2, 3, 3])
1, 1, 2, 2
>>> words = ElementwiseProxy(["one", "two", "three", "four"])
>>> print (words + " little indians").upper().split(" ").apply(reversed).apply("_".join) * 2
'INDIANS_LITTLE_ONEINDIANS_LITTLE_ONE', 'INDIANS_LITTLE_TWOINDIANS_LITTLE_TWO', 'INDIANS_LITTLE_THREEINDIANS_LITTLE_THREE', 'INDIANS_LITTLE_FOURINDIANS_LITTLE_FOUR'
__add__(other)[source]
Returns:A function which returns:
(e + other for e in self)
Return type:FunctionType -> GeneratorType
__and__(other)[source]
Returns:A function which returns:
(e & other for e in self)
Return type:FunctionType -> GeneratorType
__call__(*args, **kwargs)[source]
Returns:A function which returns:
(e(*args, **kwargs) for e in self)
Return type:FunctionType -> GeneratorType
__cmp__(other)[source]
Returns:A function which returns:
(cmp(e, other) for e in self)
Return type:FunctionType -> GeneratorType
__contains__(item)[source]
Returns:A function which returns:
(item in e for e in self)
Return type:FunctionType -> GeneratorType
__div__(other)[source]
Returns:A function which returns:
(e / other for e in self).
Return type:FunctionType -> GeneratorType
__divmod__(other)[source]
Returns:A function which returns:
(divmod(e, other) for e in self).
Return type:FunctionType -> GeneratorType
__eq__(other)[source]
Returns:A function which returns:
(e == other for e in self)
Return type:FunctionType -> GeneratorType
__floordiv__(other)[source]
Returns:A function which returns:
(e // other for e in self).
Return type:FunctionType -> GeneratorType
__ge__(other)[source]
Returns:A function which returns:
(e >= other for e in self)
Return type:FunctionType -> GeneratorType
__gt__(other)[source]
Returns:A function which returns:
(e > other for e in self)
Return type:FunctionType -> GeneratorType
__iadd__(other)[source]
Returns:A function which returns:
(e |= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__iand__(other)[source]
Returns:A function which returns:
(e &= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__idiv__(other)[source]
Returns:A function which returns:
(e /= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ifloordiv__(other)[source]
Returns:A function which returns:
(e //= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ilshift__(other)[source]
Returns:A function which returns:
(e <<= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imod__(other)[source]
Returns:A function which returns:
(e %= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imul__(other)[source]
Returns:A function which returns:
(e *= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ior__(other)[source]
Returns:A function which returns:
(e |= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ipow__(other, modulo=None)[source]
Returns:A function which returns:
(e **= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__irshift__(other)[source]
Returns:A function which returns:
(e >>= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__isub__(other)[source]
Returns:A function which returns:
(e -= other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__itruediv__(other)[source]
Returns:A function which returns:
(e |= other for e in self)

using truediv.

Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ixor__(other)[source]
Returns:A function which returns:
(e =^ other for e in self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__le__(other)[source]
Returns:A function which returns:
(e <= other for e in self)
Return type:FunctionType -> GeneratorType
__lshift__(other)[source]
Returns:A function which returns:
(e << other for e in self).
Return type:FunctionType -> GeneratorType
__lt__(other)[source]
Returns:A function which returns:
(e < other for e in self)
Return type:FunctionType -> GeneratorType
__mod__(other)[source]
Returns:A function which returns:
(e % other for e in self).
Return type:FunctionType -> GeneratorType
__mul__(other)[source]
Returns:A function which returns:
(e * other for e in self).
Return type:FunctionType -> GeneratorType
__ne__(other)[source]
Returns:A function which returns:
(e != other for e in self)
Return type:FunctionType -> GeneratorType
__or__(other)[source]
Returns:A function which returns:
(e | other for e in self)
Return type:FunctionType -> GeneratorType
__pow__(other, modulo=None)[source]
Returns:A function which returns:
(pow(e, other, modulo) for e in self).
Return type:FunctionType -> GeneratorType
__radd__(other)[source]
Returns:A function which returns:
(other + e for e in self).
Return type:FunctionType -> GeneratorType
__rand__(other)[source]
Returns:A function which returns:
(other & e for e in self).
Return type:FunctionType -> GeneratorType
__rdiv__(other)[source]
Returns:A function which returns:
(other / e for e in self).
Return type:FunctionType -> GeneratorType
__rdivmod__(other)[source]
Returns:A function which returns:
(divmod(other, e) for e in self).
Return type:FunctionType -> GeneratorType
__rfloordiv__(other)[source]
Returns:A function which returns:
(other // e for e in self).
Return type:FunctionType -> GeneratorType
__rlshift__(other)[source]
Returns:A function which returns:
(other << e for e in self).
Return type:FunctionType -> GeneratorType
__rmod__(other)[source]
Returns:A function which returns:
(e % other for e in self)
Return type:FunctionType -> GeneratorType
__rmul__(other)[source]
Returns:A function which returns:
(other * e for e in self).
Return type:FunctionType -> GeneratorType
__ror__(other)[source]
Returns:A function which returns:
(other | e for e in self).
Return type:FunctionType -> GeneratorType
__rpow__(other)[source]
Returns:A function which returns:
(pow(other, e) for e in self)
Return type:FunctionType -> GeneratorType
__rrshift__(other)[source]
Returns:A function which returns:
(other >> e for e in self)
Return type:FunctionType -> GeneratorType
__rshift__(other)[source]
Returns:A function which returns:
(e >> other for e in self).
Return type:FunctionType -> GeneratorType
__rsub__(other)[source]
Returns:A function which returns:
(other - e for e in self)
Return type:FunctionType -> GeneratorType
__rtruediv__(other)[source]
Returns:A function which returns:
(other / e for e in self)

using truediv.

Return type:FunctionType -> GeneratorType
__rxor__(other)[source]
Returns:A function which returns:
(other ^ e for e in self)
Return type:FunctionType -> GeneratorType
__sub__(other)[source]
Returns:A function which returns:
(e - other for e in self).
Return type:FunctionType -> GeneratorType
__truediv__(other)[source]
Returns:A function which returns:
(e / other for e in self), using truediv.
Return type:FunctionType -> GeneratorType
__xor__(other)[source]
Returns:A function which returns:
(e ^ other for e in self)
Return type:FunctionType -> GeneratorType
apply(func, *args, **kwargs)[source]
Parameters:func – The function to be applied.
Returns:A function which returns:
(func(e, *args, **kwargs) for e in self)
Return type:FunctionType -> GeneratorType
class elementwise.ElementwiseProxyMixin[source]

Provides iterable objects with a proxy that broadcasts operations to member elements.

each[source]

Syntactic sugar for ElementwiseProxy(self)

class elementwise.IteratorProxy(iterable, cacheable=False)[source]

This is a simple proxy object for iterators, which provides a few extra features:

  • Supports value caching.
  • Accepts callables that generates iterables.
  • Supports slicing, and will try to behave intelligently about how it does so, depending on whether the source iterable is a sequence.
  • Concatenates iterators using the + operator.
  • Generates a cartesian product of two iterators using the * operator.
  • Generates a cartesian product of an iterable multiplied by itself N times using the (* N) expression.
__add__(other)[source]

Concatenates self and other. Implemented using itertools.chain.

__getitem__(key)[source]

Respect the getitem attribute on the parent if it exists. Otherwise, try to use itertools.islice.

__iter__()[source]

If the underlying iterable is cacheable and the cache has been built up, the cache will be iterated over. Otherwise the underlying iterable will be iterated over.

__mul__(other)[source]

If other is an integer, return the cartesian product of self repeated other times. Otherwise, return the cartiasn product of self and other

__weakref__

list of weak references to the object (if defined)

cache[source]

The cache property returns cached values, or redirects to the iterable property if the source iterable is not cacheable.

class elementwise.OperationProxy(iterable=(), parent=None)[source]

Base class for Proxy objects.

__weakref__

list of weak references to the object (if defined)

replicate(iterable)[source]

Creates a copy of this operation chain, with iterable as the source.

undo(steps=1)[source]

Starting from the current operation, undo the previous steps operations in the chain.

Parameters:steps (int) – The number of operations to undo.
Returns:A new chain reprenseting the state of the chain steps operations prior.
Return type:OperationProxy (or a subclass thereof)
class elementwise.PairwiseProxy(iterable=(), parent=None)[source]

Provides pairwise operator behavior, attribute access and method calls over a parent iterable.

First, create an PairProxy from any iterable, like so:

nums = PairwiseProxy([1, 2, 3, 4])

You can perform a large vareity of operations on the proxy, and it will create a chain of operations to be applied to the contents of the iterable being proxied. The proxy is completely lazy, so none of the operations will be applied until you begin to request values from the proxy by iterating over it.

For example:

>>> nums + [1, 2, 3, 4]
2, 4, 6, 8
>>> nums * [2, 2, 3, 3]
2, 4, 9, 12
>>> nums == [2, 2, 3, 5]
False, True, True, False
>>> (nums.apply(float) / itertools.count(2) + itertools.count(1)).apply(round, args=itertools.repeat([2]))
1.5, 2.67, 3.75, 4.8
>>> abs(nums - [3, 2, 1, 1])
2, 0, 2, 3
>>> (nums * [2, 2, 1, 5] + [3, 5, 9, 0]) / [4, 1, 2, 3]
1, 9, 6, 6
>>> ((nums * itertools.repeat(2) + itertools.repeat(3)) / itertools.repeat(4)).replicate([2, 2, 3, 3])
1, 0, 0, 0
>>> ((nums * [2, 3, 4, 5]) > [5, 6, 7, 8]) != [True, True, False, True]
True, True, True, False
__add__(other)[source]
Returns:A function which returns:
imap(lambda x, y: x + y, self, other)
Return type:FunctionType -> GeneratorType
__and__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x & y, self, other)
Return type:FunctionType -> GeneratorType
__call__(args=None, kwargs=None)[source]
Parameters:
  • args (Sequence) – The positional arguments for each element of the PairwiseProxy
  • kwargs (Sequence) – The keyword arguments for each element of the PairwiseProxy
Returns:

A function which returns:

imap(self, self, args, kwargs)

Return type:

FunctionType -> GeneratorType

__cmp__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(cmp, self, other)
Return type:FunctionType -> GeneratorType
__contains__(item)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y in x, self, other)
Return type:FunctionType -> GeneratorType
__div__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x / y, self, other)
Return type:FunctionType -> GeneratorType
__divmod__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x % y, self, other)
Return type:FunctionType -> GeneratorType
__eq__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x == y, self, other)
Return type:FunctionType -> GeneratorType
__floordiv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x // y, self, other)
Return type:FunctionType -> GeneratorType
__ge__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y / x, self, other)
Return type:FunctionType -> GeneratorType
__gt__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x > y, self, other)
Return type:FunctionType -> GeneratorType
__iadd__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x += y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__iand__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x &= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__idiv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x /= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ifloordiv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x // y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ilshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x <<= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imod__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x % y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imul__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x *= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ior__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x |= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ipow__(other, modulo=None)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: pow(x, y, modulo), self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__irshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x >>= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__isub__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x -= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__itruediv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x /= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ixor__(other)[source]
Returns:A function which returns:
imap(lambda x, y: x ^= y, self, other)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__le__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x <= y, self, other)
Return type:FunctionType -> GeneratorType
__lshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x << y, self, other)
Return type:FunctionType -> GeneratorType
__lt__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x < y, self, other)
Return type:FunctionType -> GeneratorType
__mod__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x % y, self, other)
Return type:FunctionType -> GeneratorType
__mul__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x * y, self, other)
Return type:FunctionType -> GeneratorType
__ne__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x != y, self, other)
Return type:FunctionType -> GeneratorType
__or__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x | y, self, other)
Return type:FunctionType -> GeneratorType
__pow__(other, modulo=None)[source]
Parameters:others (Sequence) – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x + y, self, other)
Return type:FunctionType -> GeneratorType
__radd__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y + x, self, other)
Return type:FunctionType -> GeneratorType
__rand__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y & x, self, other)
Return type:FunctionType -> GeneratorType
__rdiv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y / x, self, other)
Return type:FunctionType -> GeneratorType
__rdivmod__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: divmod(y, x), self, other)
Return type:FunctionType -> GeneratorType
__rfloordiv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y // x, self, other)
Return type:FunctionType -> GeneratorType
__rlshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y << x, self, other)
Return type:FunctionType -> GeneratorType
__rmod__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y % x, self, other)
Return type:FunctionType -> GeneratorType
__rmul__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y * x, self, other)
Return type:FunctionType -> GeneratorType
__ror__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y | x, self, other)
Return type:FunctionType -> GeneratorType
__rpow__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y ** x, self, other)
Return type:FunctionType -> GeneratorType
__rrshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y >> x, self, other)
Return type:FunctionType -> GeneratorType
__rshift__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x >> y, self, other)
Return type:FunctionType -> GeneratorType
__rsub__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y - x, self, other)
Return type:FunctionType -> GeneratorType
__rtruediv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y / x, self, other)

using truediv.

Return type:FunctionType -> GeneratorType
__rxor__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: y ^ x, self, other)
Return type:FunctionType -> GeneratorType
__sub__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x - y, self, other)
Return type:FunctionType -> GeneratorType
__truediv__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x / y, self, other)
Return type:FunctionType -> GeneratorType
__xor__(other)[source]
Parameters:other – The other object to use for each element of the PairwiseProxy
Returns:A function which returns:
imap(lambda x, y: x ^ y, self, other)
Return type:FunctionType -> GeneratorType
apply(func, args=None, kwargs=None)[source]
Parameters:
  • func – The function to be applied.
  • args (Sequence) – The positional arguments for each element of the PairwiseProxy
  • kwargs (Sequence) – The keyword arguments for each element of the PairwiseProxy
Returns:

A function which returns:

imap(func, self, args, kwargs)

Return type:

FunctionType -> GeneratorType

class elementwise.PairwiseProxyMixin[source]

Provides iterable objects with a proxy that performs pairwise operations using elements of supplied iterables.

pair[source]

Syntactic sugar for PairwiseProxy(self)

class elementwise.ProxyMixin[source]

Base class for Proxy Mixins.

__weakref__

list of weak references to the object (if defined)

class elementwise.RecursiveElementwiseProxy(iterable=(), parent=None)[source]

Provides recursive elementwise operator behavior, attribute access and method calls over a parent iterable.

First, create an RecursiveElementwiseProxy from any iterable, like so:

treenums = RecursiveElementwiseProxy([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

Yyou can perform a large vareity of operations on the proxy, and it will create a chain of operations to be applied to the contents of the iterable being proxied. The proxy is fully lazy, so none of the operations will be applied until you begin to request values from the proxy by iterating over it.

For example:

>>> treenums + 1
((2, 3, 4), (5, 6, 7), (8, 9, 10))
>>> treenums * 2
((2, 4, 6), (8, 10, 12), (14, 16, 18))
>>> (treenums * 2 + 1).apply(float)
((3.0, 5.0, 7.0), (9.0, 11.0, 13.0), (15.0, 17.0, 19.0))
__add__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e + other, self)
Return type:FunctionType -> GeneratorType
__and__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e & other, self)
Return type:FunctionType -> GeneratorType
__call__(*args, **kwargs)[source]
Returns:A function which returns:
graphmap(lambda e: e(*args, **kwargs), self)
Return type:FunctionType -> GeneratorType
__cmp__(other)[source]
Returns:A function which returns:
graphmap(lambda e: cmp(e, other), self)
Return type:FunctionType -> GeneratorType
__contains__(item)[source]
Returns:A function which returns:
graphmap(lambda e: item in e, self)
Return type:FunctionType -> GeneratorType
__div__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e / other, self)
Return type:FunctionType -> GeneratorType
__divmod__(other)[source]
Returns:A function which returns:
graphmap(lambda e: divmod(e, other), self)
Return type:FunctionType -> GeneratorType
__eq__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e == other, self)
Return type:FunctionType -> GeneratorType
__floordiv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e // other, self)
Return type:FunctionType -> GeneratorType
__ge__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e >= other, self)
Return type:FunctionType -> GeneratorType
__gt__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e > other, self)
Return type:FunctionType -> GeneratorType
__iadd__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e += other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__iand__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e &= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__idiv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e /= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ifloordiv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e //= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ilshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e:  <<= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imod__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e %= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__imul__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e *= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ior__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e |= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ipow__(other, modulo=None)[source]
Returns:A function which returns:
graphmap(lambda e: e **= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__irshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e >>= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__isub__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e -= other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__itruediv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e |= other, self)

using truediv.

Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__ixor__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e =^ other, self)
Return type:FunctionType -> GeneratorType

Warning

For mutable types, this operations can not be undone once finalized.

__le__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e <= other, self)
Return type:FunctionType -> GeneratorType
__lshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e << other, self)
Return type:FunctionType -> GeneratorType
__lt__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e < other, self)
Return type:FunctionType -> GeneratorType
__mod__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e % other, self)
Return type:FunctionType -> GeneratorType
__mul__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e * other, self)
Return type:FunctionType -> GeneratorType
__ne__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e != other, self)
Return type:FunctionType -> GeneratorType
__or__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e | other, self)
Return type:FunctionType -> GeneratorType
__pow__(other, modulo=None)[source]
Returns:A function which returns:
graphmap(lambda e: pow(e, other, modulo), self)
Return type:FunctionType -> GeneratorType
__radd__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other + e, self)
Return type:FunctionType -> GeneratorType
__rand__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other & e, self)
Return type:FunctionType -> GeneratorType
__rdiv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other / e, self)
Return type:FunctionType -> GeneratorType
__rdivmod__(other)[source]
Returns:A function which returns:
graphmap(lambda e: divmod(other, e), self)
Return type:FunctionType -> GeneratorType
__rfloordiv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other // e, self)
Return type:FunctionType -> GeneratorType
__rlshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other << e, self)
Return type:FunctionType -> GeneratorType
__rmod__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e % other for e in self)
Return type:FunctionType -> GeneratorType
__rmul__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other * e, self)
Return type:FunctionType -> GeneratorType
__ror__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other | e, self)
Return type:FunctionType -> GeneratorType
__rpow__(other)[source]
Returns:A function which returns:
graphmap(lambda e: pow(other, e), self)
Return type:FunctionType -> GeneratorType
__rrshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other >> e, self)
Return type:FunctionType -> GeneratorType
__rshift__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e >> other, self)
Return type:FunctionType -> GeneratorType
__rsub__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other - e, self)
Return type:FunctionType -> GeneratorType
__rtruediv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other / e, self)

using truediv.

Return type:FunctionType -> GeneratorType
__rxor__(other)[source]
Returns:A function which returns:
graphmap(lambda e: other ^ e, self)
Return type:FunctionType -> GeneratorType
__sub__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e - other, self)
Return type:FunctionType -> GeneratorType
__truediv__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e / other, self)

using truediv.

Return type:FunctionType -> GeneratorType
__xor__(other)[source]
Returns:A function which returns:
graphmap(lambda e: e ^ other, self)
Return type:FunctionType -> GeneratorType
apply(f, *args, **kwargs)[source]

Depth first graph traversal and function application.

class elementwise.RecursiveElementwiseProxyMixin[source]

Provides iterable objects with a proxy that broadcasts operations recursively to member elements.

recurse[source]

Syntactic sugar for RecursiveElementwiseProxy(self)

elementwise.as_strlike(iterable, f=<type 'str'>)[source]

Generate a string-like representation of iterable, using f. repr requires special case behavior, since the repr() of a string is enclosed in an additional set of quotes.

elementwise.cacheable(f)[source]
Parameters:
  • f (FunctionType) – The function to be decorated.
  • self (OperationProxy subclass) – The cacheable instance.

Cacheable functions have their return iterable wrapped in an IterableProxy. If self.__cacheable__ evaluates to True, the IterableProxy will cache results as it is iterated over.

elementwise.chainable(f)[source]

Chainable functions should return an instance of their class, with a reference to their parent function.

Parameters:
  • f (FunctionType) – The function to be decorated.
  • self (OperationProxy subclass) – The chainable instance.
elementwise.copy_func(f, code=None, globals_=None, name=None, argdefs=None, closure=None)[source]

Create a copy of a function, replacing any portions specified.

elementwise.create_cell(obj)[source]

Create a cell object which references obj.

elementwise.graphmap(f, graph)[source]

Depth first graph traversal and function application. Cycles are avoided by maintaining a set of observed object ids and testing for set membership before edge traversal.

Indices and tables

Table Of Contents

This Page