Example #1
0
def test_var_accepts_comma():
    v1 = var('x y z')
    v2 = var('x,y,z')
    v3 = var('x,y z')

    assert v1 == v2
    assert v1 == v3
Example #2
0
def test_var_accepts_comma():
    v1 = var('x y z')
    v2 = var('x,y,z')
    v3 = var('x,y z')

    assert v1 == v2
    assert v1 == v3
Example #3
0
def test_var_return():
    raises(ValueError, lambda: var(''))
    v2 = var('q')
    v3 = var('q p')

    assert v2 == Symbol('q')
    assert v3 == (Symbol('q'), Symbol('p'))
Example #4
0
def test_var():
    var("a")
    assert a == Symbol("a")

    var("b bb cc zz _x")
    assert b == Symbol("b")
    assert bb == Symbol("bb")
    assert cc == Symbol("cc")
    assert zz == Symbol("zz")
    assert _x == Symbol("_x")

    v = var(['d', 'e', 'fg'])
    assert d == Symbol('d')
    assert e == Symbol('e')
    assert fg == Symbol('fg')

    # check return value
    assert v == [d, e, fg]

    # see if var() really injects into global namespace
    raises(NameError, lambda: z1)
    _make_z1()
    assert z1 == Symbol("z1")

    raises(NameError, lambda: z2)
    _make_z2()
    assert z2 == Symbol("z2")
Example #5
0
def test_var():
    var("a")
    assert a == Symbol("a")

    var("b bb cc zz _x")
    assert b == Symbol("b")
    assert bb == Symbol("bb")
    assert cc == Symbol("cc")
    assert zz == Symbol("zz")
    assert _x == Symbol("_x")

    v = var(['d', 'e', 'fg'])
    assert d == Symbol('d')
    assert e == Symbol('e')
    assert fg == Symbol('fg')

    # check return value
    assert v == [d, e, fg]

    # see if var() really injects into global namespace
    raises(NameError, lambda: z1)
    _make_z1()
    assert z1 == Symbol("z1")

    raises(NameError, lambda: z2)
    _make_z2()
    assert z2 == Symbol("z2")
Example #6
0
def test_var_return():
    raises(ValueError, lambda: var(''))
    v2 = var('q')
    v3 = var('q p')

    assert v2 == Symbol('q')
    assert v3 == (Symbol('q'), Symbol('p'))
Example #7
0
def run_benchmark(n):
    var("x y z w")
    e = (x + y + z + w)**n
    f = e * (e + w)
    t1 = clock()
    g = f.expand()
    t2 = clock()
    print("%s ms" % (1000 * (t2 - t1)))
Example #8
0
def run_benchmark(n):
    var("x y z w")
    e = (x + y + z + w)**n
    f = e * (e + w)
    t1 = clock()
    g = f.expand()
    t2 = clock()
    print("%s ms" % (1000 * (t2 - t1)))
Example #9
0
    def __init__(self, num_lados: int):
        """Construtor.

        Args:
            num_lados: Número de lados do elemento finito poligonal.
        """
        self._num_lados = num_lados

        super().__init__(self.coordenadas_vertices(), None)

        # Variáveis simbólicas necessárias para o cálculo das funções de forma.
        self._x = symengine.var('x')
        self._y = symengine.var('y')
Example #10
0
def extract_input_dep(free_syms):
	ret_list = list()
	flist = [str(i) for i in free_syms]
	flist.sort()
	for fsyms in flist:
		ret_list += [str(fsyms), " = ", str(Globals.inputVars[seng.var(fsyms)]["INTV"]), ";"]
	return "".join(ret_list)
 def test_add(self):
     x, y = symengine.var('x y')
     self.adder.inputs['a'] = x
     self.adder.inputs['b'] = y
     done = self.adder.process()
     self.assertEqual(done, 0)
     self.assertEqual(self.adder.outputs['f(x)'], (x + y))
Example #12
0
 def eval(obj, round_mode="fl64"):
     name = str(obj.token.value)
     obj.depth = 0
     #obj.set_rounding(round_mode)
     intv = Globals.inputVars.get(obj.token.value, None)
     if intv is not None and (intv["INTV"][0] == intv["INTV"][1]):
         return intv["INTV"][0]
     else:
         return seng.var(name)
 def test_add_cell(self):
     x, y = symengine.var('x y')
     self.adder_cell.inputs['a'] << x
     self.adder_cell.inputs['b'] << y
     done = self.adder_cell.process(0)
     self.assertEqual(done, 0)
     result = []
     self.adder_cell.outputs['f(x)'] >> result
     self.assertEqual(result[-1], (x + y))
Example #14
0
def test_var():
    var("a")
    assert a == Symbol("a")

    var("b bb cc zz _x")
    assert b == Symbol("b")
    assert bb == Symbol("bb")
    assert cc == Symbol("cc")
    assert zz == Symbol("zz")
    assert _x == Symbol("_x")

    v = var(['d', 'e', 'fg'])
    assert d == Symbol('d')
    assert e == Symbol('e')
    assert fg == Symbol('fg')

    # check return value
    assert v == [d, e, fg]
Example #15
0
def test_var():
    var("a")
    assert a == Symbol("a")

    var("b bb cc zz _x")
    assert b == Symbol("b")
    assert bb == Symbol("bb")
    assert cc == Symbol("cc")
    assert zz == Symbol("zz")
    assert _x == Symbol("_x")

    v = var(['d', 'e', 'fg'])
    assert d == Symbol('d')
    assert e == Symbol('e')
    assert fg == Symbol('fg')

    # check return value
    assert v == [d, e, fg]
Example #16
0
def test_symengine(arr, sig3):
    """Test symengine."""
    try:
        import symengine as sge
        x, y, z = sge.var("x y z")
        fn = sge.acos(x) / y + sge.exp(-z)
        func = numbafy(fn, (x, y, z), compiler="vectorize", signatures=sig3)
        result = func(arr, arr, arr)
        check = np.arccos(arr) / arr + np.exp(-arr)
        assert np.allclose(result, check) == True
    except ImportError:
        pass
Example #17
0
def test_symengine(arr, sig3):
    """Test symengine."""
    try:
        import symengine as sge
        x, y, z = sge.var("x y z")
        fn = sge.acos(x)/y + sge.exp(-z)
        func = numbafy(fn, (x, y, z), compiler="vectorize", signatures=sig3)
        result = func(arr, arr, arr)
        check = np.arccos(arr)/arr + np.exp(-arr)
        assert np.allclose(result, check) == True
    except ImportError:
        pass
Example #18
0
def genSig(sym_expr):
    d = OrderedDict()
    flist = [str(i) for i in sym_expr.free_symbols]
    flist.sort()
    freeSyms = [seng.var(fs) for fs in flist]
    fpt = map(lambda i : (str(freeSyms[i]), str(i)+"_"+"{intv}".format(intv=Globals.inputVars[freeSyms[i]]["INTV"])), \
                          range(len(freeSyms)))
    d = {p[0]: p[1] for p in fpt}

    regex = re.compile("(%s)" % "|".join(map(re.escape, d.keys())))

    strSig = regex.sub(lambda mo: d[mo.string[mo.start():mo.end()]],
                       str(sym_expr))

    return hashSig(strSig, "md5")
Example #19
0
def abstractNodes(results):

    rev_symTable = {v: k for k, v in Globals.symTable.items()}

    for node, res in results.items():
        Globals.FID += 1
        name = seng.var("_F" + str(Globals.FID))
        name = rev_symTable.get(node, name)
        node.__class__ = FreeVar
        node.children = ()
        node.depth = 0

        node.set_noise(node, (res["ERR"], res["SERR"]))
        node.mutate_to_abstract(name, ID)

        #errWidth = (res["ERR"]+res["SERR"])*pow(2, -53)
        #intv = [res["INTV"][0] - errWidth, res["INTV"][1] + errWidth]

        #Globals.inputVars[name] = {"INTV" : intv}
        Globals.inputVars[name] = {"INTV": res["INTV"]}
        Globals.symTable[name] = node

    del rev_symTable
Example #20
0
def genSig(sym_expr):
	try:
		if seng.count_ops(sym_expr) == 0 :
			return float(str(sym_expr))
	except ValueError:
		pass
	d = OrderedDict()
	flist = [str(i) for i in sym_expr.free_symbols]
	flist.sort()
	freeSyms = [seng.var(fs) for fs in flist]
	# make this to a map
	#for i in range(0, len(freeSyms)):
	#	inp = freeSyms[i]
	#	d[inp] = str(i)+"_"+"{intv}".format(intv=Globals.inputVars[inp]["INTV"])

	fpt = map(lambda i : (str(freeSyms[i]), str(i)+"_"+"{intv}".format(intv=Globals.inputVars[freeSyms[i]]["INTV"])), \
	                      range(len(freeSyms)))
	d =	{p[0]:p[1] for p in fpt}

	regex = re.compile("(%s)" % "|".join(map(re.escape, d.keys())))

	strSig = regex.sub(lambda mo: d[mo.string[mo.start():mo.end()]], str(sym_expr))

	return hashSig(strSig, "md5")
Example #21
0
from collections import OrderedDict, Counter, defaultdict
from itertools import combinations_with_replacement as cwr
import numpy as np
import pandas as pd
from numexpr import evaluate
try:
    from symengine import var, exp, cos, sin, Mul, Integer, Float
except ImportError:
    from sympy import symbols as var
    from sympy import exp, cos, sin, Mul, Integer, Float
from exa import Series
from exatomic.algorithms.overlap import _cartesian_shell_pairs, _iter_atom_shells
from exatomic.algorithms.numerical import fac, _tri_indices, _triangle, _enum_spherical


_x, _y, _z = var("_x _y _z")
_r = (_x ** 2 + _y ** 2 + _z ** 2) ** 0.5

lorder = ['s', 'p', 'd', 'f', 'g',
          'h', 'i', 'k', 'l', 'm']
lmap = OrderedDict()
rlmap = OrderedDict()
spher_ml_count = OrderedDict()
cart_ml_count = OrderedDict()
spher_lml_count = OrderedDict()
cart_lml_count = OrderedDict()
enum_cartesian = OrderedDict()
for i, L in enumerate(lorder):
    lmap[L] = i
    rlmap[i] = L
    spher_ml_count[L] = 2 * i + 1
Example #22
0
def _make_z1():
    var("z1")
Example #23
0
import sys
sys.path.append("..")
from timeit import default_timer as clock
from symengine import var
var("x y z")
f = (x**y + y**z + z**x)**100
print f
t1 = clock()
g = f.expand()
t2 = clock()
print "Total time:", t2-t1, "s"
Example #24
0
def __make_z2():
    var("z2")
Example #25
0
def _make_z1():
    var("z1")
Example #26
0
def __make_z2():
    var("z2")
Example #27
0
 def ID(self, t):
     if t.type not in (INPUTS, OUTPUTS, EXPRS):
         #t.value = sym.symbols(t.value)
         t.value = seng.var(t.value)
     return t
Example #28
0
from functools import reduce
from collections import OrderedDict, Counter, defaultdict
from itertools import combinations_with_replacement as cwr
import numpy as np
import pandas as pd
from numexpr import evaluate
try:
    from symengine import var, exp, cos, sin, Integer, Float
except ImportError:
    from sympy import symbols as var
    from sympy import exp, cos, sin, Integer, Float
from exatomic.exa import Series
from exatomic.algorithms.overlap import _cartesian_shell_pairs, _iter_atom_shells
from exatomic.algorithms.numerical import fac, _tri_indices, _triangle, _enum_spherical

_x, _y, _z = var("_x _y _z")
_r = (_x**2 + _y**2 + _z**2)**0.5

lorder = ['s', 'p', 'd', 'f', 'g', 'h', 'i', 'k', 'l', 'm']
lmap = OrderedDict()
rlmap = OrderedDict()
spher_ml_count = OrderedDict()
cart_ml_count = OrderedDict()
spher_lml_count = OrderedDict()
cart_lml_count = OrderedDict()
enum_cartesian = OrderedDict()
for i, L in enumerate(lorder):
    lmap[L] = i
    rlmap[i] = L
    spher_ml_count[L] = 2 * i + 1
    cart_ml_count[L] = (i + 1) * (i + 2) // 2
Example #29
0
import sys
sys.path.append("..")
from timeit import default_timer as clock
from symengine import var
var("x y z")
f = (x**y + y**z + z**x)**100
print f
t1 = clock()
g = f.expand()
t2 = clock()
print "Total time:", t2 - t1, "s"
Example #30
0
import sys
sys.path.append("..")
from timeit import default_timer as clock
from symengine import var
var("x y z w")
e = (x+y+z+w)**15
f = e*(e+w)
print f
t1 = clock()
g = f.expand()
t2 = clock()
print "Total time:", t2-t1, "s"
Example #31
0
import sys
sys.path.append("..")
from timeit import default_timer as clock
from symengine import var
var("x")
e = 1
for i in range(1, 351):
    e *= (i+x)**3
t1 = clock()
f = e.expand()
t2 = clock()
print("Total time:", t2-t1, "s")
Example #32
0
import sys

sys.path.append("..")
from timeit import default_timer as clock
from symengine import var

var("x y z w")
e = (x + y + z + w)**15
f = e * (e + w)
print f
t1 = clock()
g = f.expand()
t2 = clock()
print "Total time:", t2 - t1, "s"
Example #33
0
import sys
sys.path.append("..")
from timeit import default_timer as clock
from symengine import var
var("x")
e = 1
for i in range(1, 351):
    e *= (i+x)**3
#print e
t1 = clock()
f = e.expand()
t2 = clock()
print "Total time:", t2-t1, "s"