from pyLBM.generator import codegen
from sympy import *
M = Matrix([[1/4, 1/2, 0, 1/4],
[1/4, 0, 1/2, -1/4],
[1/4, -1/2, 0, 1/4],
[1/4, 0, -1/2, -1/4]])
f = MatrixSymbol('f', 4, 1)
m = MatrixSymbol('m', 4, 1)
res = codegen(('m2f', Eq(f, M*m)), "cython", header=False)
print(res[0][1]def m2f(double[::1] f, double[::1] m):
f[0] = 0.25*m[0] + 0.5*m[1] + 0.25*m[3]
f[1] = 0.25*m[0] + 0.5*m[2] - 0.25*m[3]
f[2] = 0.25*m[0] - 0.5*m[1] + 0.25*m[3]
f[3] = 0.25*m[0] - 0.5*m[2] - 0.25*m[3]from pyLBM.generator import codegen, Loop
from sympy import *
from sympy.abc import z
n, m = symbols('n m', integer=True)
A = IndexedBase('A', shape=(m, n, 4))
ff = IndexedBase('f', shape=(m, n, 4))
i = Idx('i', m)
j = Idx('j', n)
k = Idx('k', 4)
m = MatrixSymbol('m', 4, 1)
mnew = Matrix([A[i, j, kk] for kk in range(4)])
fnew = Matrix([ff[i, j, kk] for kk in range(4)])
eq = Matrix([[m[0]],
[m[1]],
[m[2]],
[ 0.0]])
for ii in range(mnew.shape[0]):
eq = eq.subs(m[ii], mnew[ii])
l2 = Loop('l2', k, Eq(z,k, evaluate=False))
l1 = Loop('l1', (i, j), [Eq(fnew, eq, evaluate=False), l2])
res = codegen(('test', l1), "CYTHON", header=False)
print(res[0][1])def test(double[:, :, ::1] f, double[:, :, ::1] A, double z):
cdef int j
cdef int k
cdef int i
for i in range(0, m):
for j in range(0, n):
f[i, j, 0] = A[i, j, 0]
f[i, j, 1] = A[i, j, 1]
f[i, j, 2] = A[i, j, 2]
f[i, j, 3] = 0.0
for k in range(0, 4):
z = k--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/be387a74-d6bb-48e9-921e-8b0c37365639%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Asst. Prof. Anthony Scopatz
Nuclear Engineering Program
Mechanical Engineering Dept.
University of South Carolina
sco...@cec.sc.edu
Office: (803) 777-9334
Cell: (512) 827-8239
Office: Horizon 1, #011 (ground floor, not first)
Book a meeting with me at https://scopatz.youcanbook.me/
Open up an issue: https://github.com/scopatz/me/issues
Check my calendar