コード例 #1
0
 def test_summation_one_var(self):
     pool = Pool()
     pool.add_var("x", "int")
     pool.add_var("y", "int")
     b = Builder(pool)
     bounds = b.test("x", ">=", 0) & b.test("x", "<=", 10)
     d = b.ite(bounds, b.terminal("x"), b.terminal(0))
     d_const = Diagram(pool, SummationWalker(d, "x").walk())
     self.assertEqual(55, d_const.evaluate({}))
コード例 #2
0
    def test_summation_two_var_test(self):
        pool = Pool()
        pool.add_var("x", "int")
        pool.add_var("y", "int")
        b = Builder(pool)
        bounds = b.test("x", ">=", 0) & b.test("x", "<=", 1)
        bounds &= b.test("y", ">=", 1) & b.test("y", "<=", 3)
        two = b.test("x", ">=", "y")
        d = b.ite(bounds, b.ite(two, b.terminal("x"), b.terminal("10")), b.terminal(0))

        summed = Diagram(pool, SummationWalker(d, "x").walk())
        d_const = summed.reduce(["y"])
        for y in range(-20, 20):
            s = 0
            for x in range(-20, 20):
                s += d.evaluate({"x": x, "y": y})
            self.assertEqual(s, d_const.evaluate({"y": y}))
コード例 #3
0
from __future__ import print_function

import itertools
from png import Writer

from pyxadd.build import Builder
from pyxadd.diagram import Pool, Diagram
from pyxadd.matrix.matrix import assignments
from pyxadd.reduce import SmtReduce, LinearReduction
from pyxadd.view import export

pool = Pool()
pool.add_var("x", "int")
pool.add_var("xs", "int")
pool.add_var("y", "int")
pool.add_var("ys", "int")
b = Builder(pool)

# TODO needs control over interleaving


class RedGreenBlueDiagrams(object):
    def __init__(self, red, green, blue):
        self.diagrams = (red, green, blue)

    @staticmethod
    def all(diagram):
        return RedGreenBlueDiagrams(diagram, diagram, diagram)

    def _binary(self, op, other):
        if isinstance(other, RedGreenBlueDiagrams):
コード例 #4
0
ファイル: tensor.py プロジェクト: samuelkolb/py-xadd
from __future__ import print_function

import itertools
from png import Writer

from pyxadd.build import Builder
from pyxadd.diagram import Pool, Diagram
from pyxadd.matrix.matrix import assignments
from pyxadd.reduce import SmtReduce, LinearReduction
from pyxadd.view import export

pool = Pool()
pool.add_var("x", "int")
pool.add_var("xs", "int")
pool.add_var("y", "int")
pool.add_var("ys", "int")
b = Builder(pool)

# TODO needs control over interleaving


class RedGreenBlueDiagrams(object):
    def __init__(self, red, green, blue):
        self.diagrams = (red, green, blue)

    @staticmethod
    def all(diagram):
        return RedGreenBlueDiagrams(diagram, diagram, diagram)

    def _binary(self, op, other):
        if isinstance(other, RedGreenBlueDiagrams):