Skip to content

pcattori/dataflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

dataflow

Toy example of setting up a delayed-execution graph, or "dataflow" in TensorFlow terminology.

Check out the stackoverflow question that inspired this demo.

usage

step 1

Use the @dataflow decorator to wrap a function with dataflow capabilities:

@dataflow
def f(x, y):
    return x**2 % y

@dataflow
def g(a, b, c):
    return a * b + c

@dataflow
def h(i, j):
    return i / j

Calling these function will now store the function and arguments for execution at a later point.

In other words, no mathematical operations will happen until you call graph.execute() in step 3.

step 2

Compose many @dataflow functions into a graph:

graph = f(g(1, 2, h(3, 4)), 5)

step 3

Execute the function:

answer = graph.execute()

variables

You can also define variables that get bound to values at execution time:

z = Variable()
seed = Variable()

graph = f(g(z, 2, h(4, z)), seed)

You can execute the same graph with different values bound to the variables:

answer1 = graph.execute({z: 1., seed: 5})
answer2 = graph.execute({z: 3., seed: 13})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages