def test_symarray(): try: import numpy as np except ImportError: return x0, x1, x2 = arr = symarray('x', 3) assert arr.shape == (3,) assert symarray('y', (2, 3)).shape == (2, 3)
def test_more_than_255_args(): # SymPy's lambdify can handle at most 255 arguments # this is a proof of concept that this limitation does # not affect SymEngine's Lambdify class if not HAVE_NUMPY: # nosetests work-around return import numpy as np n = 257 x = se.symarray('x', n) p, q, r = 17, 42, 13 terms = [i*s for i, s in enumerate(x, p)] exprs = [se.add(*terms), r + x[0], -99] callback = se.Lambdify(x, exprs) input_arr = np.arange(q, q + n*n).reshape((n, n)) out = callback(input_arr) ref = np.empty((n, 3)) coeffs = np.arange(p, p + n) for i in range(n): ref[i, 0] = coeffs.dot(np.arange(q + n*i, q + n*(i+1))) ref[i, 1] = q + n*i + r ref[:, 2] = -99 assert np.allclose(out, ref)
def test_symarray(): try: import numpy as np except ImportError: return x0, x1, x2 = arr = symarray('x', 3) assert arr.shape == (3, ) assert symarray('y', (2, 3)).shape == (2, 3)
def _get_cse_exprs_big(): # this is essentially a performance test (can be replaced by a benchmark) x, p = se.symarray('x', 14), se.symarray('p', 14) exp = se.exp exprs = [ x[0] + x[1] - x[4] + 36.252574322669, x[0] - x[2] + x[3] + 21.3219379611249, x[3] + x[5] - x[6] + 9.9011158998744, 2 * x[3] + x[5] - x[7] + 18.190422234653, 3 * x[3] + x[5] - x[8] + 24.8679190043357, 4 * x[3] + x[5] - x[9] + 29.9336062089226, -x[10] + 5 * x[3] + x[5] + 28.5520551531262, 2 * x[0] + x[11] - 2 * x[4] - 2 * x[5] + 32.4401680272417, 3 * x[1] - x[12] + x[5] + 34.9992934135095, 4 * x[1] - x[13] + x[5] + 37.0716199972041, (p[0] - p[1] + 2 * p[10] + 2 * p[11] - p[12] - 2 * p[13] + p[2] + 2 * p[5] + 2 * p[6] + 2 * p[7] + 2 * p[8] + 2 * p[9] - exp(x[0]) + exp(x[1]) - 2 * exp(x[10]) - 2 * exp(x[11]) + exp(x[12]) + 2 * exp(x[13]) - exp(x[2]) - 2 * exp(x[5]) - 2 * exp(x[6]) - 2 * exp(x[7]) - 2 * exp(x[8]) - 2 * exp(x[9])), (-p[0] - p[1] - 15 * p[10] - 2 * p[11] - 3 * p[12] - 4 * p[13] - 4 * p[2] - 3 * p[3] - 2 * p[4] - 3 * p[6] - 6 * p[7] - 9 * p[8] - 12 * p[9] + exp(x[0]) + exp(x[1]) + 15 * exp(x[10]) + 2 * exp(x[11]) + 3 * exp(x[12]) + 4 * exp(x[13]) + 4 * exp(x[2]) + 3 * exp(x[3]) + 2 * exp(x[4]) + 3 * exp(x[6]) + 6 * exp(x[7]) + 9 * exp(x[8]) + 12 * exp(x[9])), (-5 * p[10] - p[2] - p[3] - p[6] - 2 * p[7] - 3 * p[8] - 4 * p[9] + 5 * exp(x[10]) + exp(x[2]) + exp(x[3]) + exp(x[6]) + 2 * exp(x[7]) + 3 * exp(x[8]) + 4 * exp(x[9])), -p[1] - 2 * p[11] - 3 * p[12] - 4 * p[13] - p[4] + exp(x[1]) + 2 * exp(x[11]) + 3 * exp(x[12]) + 4 * exp(x[13]) + exp(x[4]), (-p[10] - 2 * p[11] - p[12] - p[13] - p[5] - p[6] - p[7] - p[8] - p[9] + exp(x[10]) + 2 * exp(x[11]) + exp(x[12]) + exp(x[13]) + exp(x[5]) + exp(x[6]) + exp(x[7]) + exp(x[8]) + exp(x[9])) ] return tuple(x) + tuple(p), exprs, np.ones(len(x) + len(p))
def test_more_than_255_args(): # SymPy's lambdify can handle at most 255 arguments # this is a proof of concept that this limitation does # not affect SymEngine's Lambdify class n = 257 x = se.symarray('x', n) p, q, r = 17, 42, 13 terms = [i*s for i, s in enumerate(x, p)] exprs = [se.add(*terms), r + x[0], -99] callback = se.Lambdify(x, exprs) input_arr = np.arange(q, q + n*n).reshape((n, n)) out = callback(input_arr) ref = np.empty((n, 3)) coeffs = np.arange(p, p + n, dtype=np.int64) for i in range(n): ref[i, 0] = coeffs.dot(np.arange(q + n*i, q + n*(i+1), dtype=np.int64)) ref[i, 1] = q + n*i + r ref[:, 2] = -99 assert np.allclose(out, ref)
from Numerical_CFS.configfunktion import writeconfig from Numerical_CFS.SymEngineFast import * import mpmath as mp import symengine as si import sympy as sy import numpy as np import scipy.misc as sm tt = si.symarray('t', 8) r = si.symarray('r', 1) T = 1 #float, Lifetime of the universe, which is needed for the # Schwartzfunktion N = 1 #integer, Shell-Number kappa = 0 #float, Needed for boundary constant kappa_Anzahl = 1 #float, Needed for plotting a diagram for various # kappas x_Anf = 0 x_End = np.pi Integration_bound = [[x_Anf, x_End], [0, T]] ind = 0 #Which Impuls should be varied, 0 for K1 and 1 for K2 w_List = [0.] K_List = [1] Rho_List = [1] # i have to set this here for the initialing of the class C_FS System_Parameters = [K_List, Rho_List, w_List, kappa] CFS_Action = C_F_S(N, T, System_Parameters, Integration_bound,
import ctypes import subprocess sigma1 = si.zeros(2) sigma1[1, 0] = 1 sigma1[0, 1] = 1 sigma2 = si.zeros(2) sigma2[1, 0] = I sigma2[0, 1] = -I sigma3 = si.zeros(2) sigma3[0, 0] = 1 sigma3[1, 1] = -1 ident = si.zeros(2) ident[0, 0] = 1 ident[1, 1] = 1 r = si.symarray('r', 1) t = si.symarray('t', 1) ''' For more information on these Functions, look in to the master thesis of Nikki Kilbertus, which is included on the github site. If you are up to it, you can read from page 1, but from a numerical perspective Chapter 2.3 Numerical Recipe (page 24ff) is important. The main function is called get_Action. Codewise speaking this programm can be split into Get_Integrand and Get_Action. In Get_Integrand as the name already spills it out, i'm constructing the Integrand, which will be later on integrated in Get_Action to get the Action. Get_Integrand =============