Skip to main content

lazy graph framework

Project description

lazy-graph

lazy-graph is python package for lazy evaluation, with enhancement for updating values of upstream and copying the entire lazy graph.

Install

Copy or link this folder directly. Or use pip to obtain the distribution pip install lazy_graph.

Documents

Simple example

from lazy import Root, Node


def add(a, b):
    print(f"calculating {a} + {b}")
    return a + b


print("create nodes")
a = Root(1)
b = Root(2)
c = Node(add, a, b)
print("get the value")
print(f"c is {c()}")

create nodes
get the value
calculating 1 + 2
c is 3

Update upstream

from lazy import Root, Node


def add(a, b):
    print(f"calculating {a} + {b}")
    return a + b


print("create nodes")
a = Root(1)
b = Root(2)
c = Node(add, a, b)
print("get the value")
print(f"c is {c()}")
print("get the value again")
print(f"c is {c()}")
print("update upstream")
a.reset(4)
print("get the new value")
print(f"c is {c()}")

create nodes
get the value
calculating 1 + 2
c is 3
get the value again
c is 3
update upstream
get the new value
calculating 4 + 2
c is 6

Normal argument or keyword argument are also available

from lazy import Root, Node


def add(a, b, c, d):
    print(f"calculating {a} + {b} + {c} + {d}")
    return a + b + c + d


print("create nodes")
a = Root(1)
c = Root(3)
z = Node(add, a, 2, c=c, d=4)
print("get the value")
print(f"c is {z()}")

create nodes
get the value
calculating 1 + 2 + 3 + 4
c is 10

Copy the lazy graph

from lazy import Root, Node, Copy


def add(a, b):
    print(f"calculating {a} + {b}")
    return a + b


print("create nodes")
a = Root(1)
b = Root(2)
c = Node(add, a, b)
print("get the value")
print(f"c is {c()}")

print("copy lazy graph")
copy = Copy()
new_a = copy(a)
new_b = copy(b)
new_c = copy(c)

print("get the new value")
print(f"new c is {new_c()}")

print("reset value")
a.reset(4)
new_a.reset(8)
print("get the old value and new value")
print(f"c is {c()}, new c is {new_c()}")

create nodes
get the value
calculating 1 + 2
c is 3
copy lazy graph
get the new value
new c is 3
reset value
get the old value and new value
calculating 4 + 2
calculating 8 + 2
c is 6, new c is 10

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

lazy_graph-0.3.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file lazy_graph-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lazy_graph-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for lazy_graph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e887f6ed4bcf30418e7f86277d1ffde614e48e7294d374af5c7790c0bbe4b55c
MD5 7cf2e4cd5a5d7a1e7b1825e10379f38f
BLAKE2b-256 c540d43151289a6a68b030e4c455677d193cfb52ddebe7e7136e1f7f91cc42ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page