Giter VIP home page Giter VIP logo

elementwise's Introduction

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.

  • ElementwiseProxyMixin.each
    mutates the current proxy into an ElementwiseProxy.
  • PairwiseProxyMixin.each
    mutates the current proxy into a PairwiseProxy.
  • RecursiveElementwiseProxyMixin.recurse
    mutates the current proxy into a RecursiveElementwiseProxy.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.