本文整理汇总了Python中sympy.printing.ccode.CCodePrinter类的典型用法代码示例。如果您正苦于以下问题:Python CCodePrinter类的具体用法?Python CCodePrinter怎么用?Python CCodePrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCodePrinter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_ccode_Indexed
def test_ccode_Indexed():
from sympy.tensor import IndexedBase, Idx
from sympy import symbols
s, n, m, o = symbols('s n m o', integer=True)
i, j, k = Idx('i', n), Idx('j', m), Idx('k', o)
x = IndexedBase('x')[j]
A = IndexedBase('A')[i, j]
B = IndexedBase('B')[i, j, k]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=SymPyDeprecationWarning)
p = CCodePrinter()
p._not_c = set()
assert p._print_Indexed(x) == 'x[j]'
assert p._print_Indexed(A) == 'A[%s]' % (m*i+j)
assert p._print_Indexed(B) == 'B[%s]' % (i*o*m+j*o+k)
assert p._not_c == set()
A = IndexedBase('A', shape=(5,3))[i, j]
assert p._print_Indexed(A) == 'A[%s]' % (3*i + j)
A = IndexedBase('A', shape=(5,3), strides='F')[i, j]
assert ccode(A) == 'A[%s]' % (i + 5*j)
A = IndexedBase('A', shape=(29,29), strides=(1, s), offset=o)[i, j]
assert ccode(A) == 'A[o + s*j + i]'
Abase = IndexedBase('A', strides=(s, m, n), offset=o)
assert ccode(Abase[i, j, k]) == 'A[m*j + n*k + o + s*i]'
assert ccode(Abase[2, 3, k]) == 'A[3*m + n*k + o + 2*s]'
开发者ID:Lenqth,项目名称:sympy,代码行数:32,代码来源:test_ccode.py
示例2: test_ccode_Indexed
def test_ccode_Indexed():
from sympy.tensor import IndexedBase, Idx
from sympy import symbols
n, m, o = symbols('n m o', integer=True)
i, j, k = Idx('i', n), Idx('j', m), Idx('k', o)
p = CCodePrinter()
p._not_c = set()
x = IndexedBase('x')[j]
assert p._print_Indexed(x) == 'x[j]'
A = IndexedBase('A')[i, j]
assert p._print_Indexed(A) == 'A[%s]' % (m*i+j)
B = IndexedBase('B')[i, j, k]
assert p._print_Indexed(B) == 'B[%s]' % (i*o*m+j*o+k)
assert p._not_c == set()
开发者ID:B-Rich,项目名称:sympy,代码行数:16,代码来源:test_ccode.py
示例3: test_ccode_Indexed
def test_ccode_Indexed():
from sympy.tensor import IndexedBase, Idx
from sympy import symbols
i, j, k, n, m, o = symbols('i j k n m o', integer=True)
p = CCodePrinter()
p._not_c = set()
x = IndexedBase('x')[Idx(j, n)]
assert p._print_Indexed(x) == 'x[j]'
A = IndexedBase('A')[Idx(i, m), Idx(j, n)]
assert p._print_Indexed(A) == 'A[%s]' % str(j + n*i)
B = IndexedBase('B')[Idx(i, m), Idx(j, n), Idx(k, o)]
assert p._print_Indexed(B) == 'B[%s]' % str(k + i*n*o + j*o)
assert p._not_c == set()
开发者ID:Maihj,项目名称:sympy,代码行数:16,代码来源:test_ccode.py
示例4: _print_Mul
def _print_Mul(self, expr):
if len(expr.args) == 2: # log2 and log10
a, b = expr.args
if is_inv(a) and is_log(a.base) and is_log(b):
log_base = a.base.args[0]
if log_base in [2, 10]:
return "log%d(%s)" % (log_base, self._print(b.args[0]))
return CCodePrinter._print_Mul(self, expr)
开发者ID:hunse,项目名称:codify,代码行数:8,代码来源:oclcode.py
示例5: test_ccode_Indexed
def test_ccode_Indexed():
from sympy.tensor import IndexedBase, Idx
from sympy import symbols
n, m, o = symbols('n m o', integer=True)
i, j, k = Idx('i', n), Idx('j', m), Idx('k', o)
x = IndexedBase('x')[j]
A = IndexedBase('A')[i, j]
B = IndexedBase('B')[i, j, k]
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=SymPyDeprecationWarning)
p = CCodePrinter()
p._not_c = set()
assert p._print_Indexed(x) == 'x[j]'
assert p._print_Indexed(A) == 'A[%s]' % (m*i+j)
assert p._print_Indexed(B) == 'B[%s]' % (i*o*m+j*o+k)
assert p._not_c == set()
开发者ID:rpmuller,项目名称:sympy,代码行数:19,代码来源:test_ccode.py
示例6: _print_Pow
def _print_Pow(self, expr):
if expr.base == 2:
return "exp2(%s)" % self._print(expr.exp)
if expr.base == 10:
return "exp10(%s)" % self._print(expr.exp)
if expr.exp == 0.5 and isinstance(expr.base, Add):
args = expr.base.args
if len(args) == 2 and all(map(is_square, args)):
if self.order != 'none':
args = self._as_ordered_terms(expr.base, order=None)
# TODO: (above) is it fine to use `order=None`?
return "hypot(%s, %s)" % (self._print(args[0].args[0]),
self._print(args[1].args[0]))
if expr.exp == Rational(1, 3):
return "cbrt(%s)" % self._print(expr.base)
if expr.exp.is_integer and expr.exp != -1:
return "pown(%s, %s)" % (
self._print(expr.base), self._print(expr.exp))
if expr.exp.is_positive and expr.exp != 0.5:
return "powr(%s, %s)" % (
self._print(expr.base), self._print(expr.exp))
return CCodePrinter._print_Pow(self, expr)
开发者ID:hunse,项目名称:codify,代码行数:22,代码来源:oclcode.py
示例7: _indent_code
def _indent_code(self, codelines):
p = CCodePrinter()
return p.indent_code(codelines)
开发者ID:Eskatrem,项目名称:sympy,代码行数:3,代码来源:codegen.py
示例8: __init__
def __init__(self, settings={}):
CCodePrinter.__init__(self, settings)
开发者ID:marcoscimatec,项目名称:opesci-fd,代码行数:2,代码来源:codeprinter.py
示例9: __init__
def __init__(self, settings={}):
settings = dict(settings)
userfuncs = settings.setdefault('user_functions', {})
for k, v in known_functions.items():
userfuncs.setdefault(k, v)
CCodePrinter.__init__(self, settings)
开发者ID:hunse,项目名称:codify,代码行数:6,代码来源:oclcode.py
注:本文中的sympy.printing.ccode.CCodePrinter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论