• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python codeprinter.CodePrinter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.printing.codeprinter.CodePrinter的典型用法代码示例。如果您正苦于以下问题:Python CodePrinter类的具体用法?Python CodePrinter怎么用?Python CodePrinter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CodePrinter类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, settings={}):
     CodePrinter.__init__(self, settings)
     self.known_functions = dict(known_functions)
     userfuncs = settings.get('user_functions', {})
     self.known_functions.update(userfuncs)
     self._dereference = set(settings.get('dereference', []))
     self.reserved_words = set(reserved_words)
开发者ID:bjodah,项目名称:sympy,代码行数:7,代码来源:rust.py


示例2: __init__

 def __init__(self, settings={}):
     """Register function mappings supplied by user"""
     CodePrinter.__init__(self, settings)
     self.known_functions = dict(known_functions)
     userfuncs = settings.get('user_functions', {})
     for k, v in userfuncs.items():
         if not isinstance(v, list):
             userfuncs[k] = [(lambda *x: True, v)]
     self.known_functions.update(userfuncs)
开发者ID:B-Rich,项目名称:sympy,代码行数:9,代码来源:ccode.py


示例3: __init__

 def __init__(self, settings=None):
     CodePrinter.__init__(self, settings)
     self._init_leading_padding()
     assign_to = self._settings['assign_to']
     if isinstance(assign_to, basestring):
         self._settings['assign_to'] = C.Symbol(assign_to)
     elif not isinstance(assign_to, (C.Basic, type(None))):
         raise TypeError("FCodePrinter cannot assign to object of type %s" %
                 type(assign_to))
开发者ID:jenshnielsen,项目名称:sympy,代码行数:9,代码来源:fcode.py


示例4: _print_Float

 def _print_Float(self, expr):
     if expr == float("inf"):
         return "1e200"
     elif expr == float("-inf"):
         return "-1e200"
     else:
         return CodePrinter._print_Float(self, expr)
开发者ID:jwpeterson,项目名称:moose,代码行数:7,代码来源:fparser.py


示例5: _print_Mul

 def _print_Mul(self, expr):
     # purpose: print complex numbers nicely in Fortran.
     if expr.is_number and expr.is_imaginary:
         return "cmplx(0,%s)" % (
             self._print(-S.ImaginaryUnit*expr)
         )
     else:
         return CodePrinter._print_Mul(self, expr)
开发者ID:jenshnielsen,项目名称:sympy,代码行数:8,代码来源:fcode.py


示例6: _print_Function

 def _print_Function(self, expr):
     # All constant function args are evaluated as floats
     prec =  self._settings['precision']
     args = [N(a, prec) for a in expr.args]
     eval_expr = expr.func(*args)
     if not isinstance(eval_expr, C.Function):
         return self._print(eval_expr)
     else:
         return CodePrinter._print_Function(self, expr.func(*args))
开发者ID:AdrianPotter,项目名称:sympy,代码行数:9,代码来源:fcode.py


示例7: _print_Function

 def _print_Function(self, expr):
     if expr.func.__name__ in self.known_functions:
         cond_cfunc = self.known_functions[expr.func.__name__]
         for cond, cfunc in cond_cfunc:
             if cond(*expr.args):
                 return "%s(%s)" % (cfunc, self.stringify(expr.args, ", "))
     if hasattr(expr, '_imp_') and isinstance(expr._imp_, C.Lambda):
         # inlined function
         return self._print(expr._imp_(*expr.args))
     return CodePrinter._print_Function(self, expr)
开发者ID:B-Rich,项目名称:sympy,代码行数:10,代码来源:ccode.py


示例8: _print_Mul

    def _print_Mul(self, expr, **kwargs):
        if(self._settings['use_operators']):
            return CodePrinter._print_Mul(self, expr, **kwargs)
        terms = expr.as_ordered_factors()
        def mul(a,b):
            # return self.known_functions['mul']+'(%s, %s)' % (a,b)
            return self._print_Function_with_args('mul', (a,b))

        s = reduce(lambda a,b: mul(a,b), map(lambda t: self._print(t), terms))
        return s
开发者ID:cklb,项目名称:sympy,代码行数:10,代码来源:glsl.py


示例9: __init__

 def __init__(self, settings={}):
     CodePrinter.__init__(self, settings)
     self.known_functions = dict(known_functions)
     userfuncs = settings.get('user_functions', {})
     self.known_functions.update(userfuncs)
     # leading columns depend on fixed or free format
     if self._settings['source_format'] == 'fixed':
         self._lead_code = "      "
         self._lead_cont = "     @ "
         self._lead_comment = "C     "
     elif self._settings['source_format'] == 'free':
         self._lead_code = ""
         self._lead_cont = "      "
         self._lead_comment = "! "
     else:
         raise ValueError("Unknown source format: %s" % self._settings[
                          'source_format'])
     standards = set([66, 77, 90, 95, 2003, 2008])
     if self._settings['standard'] not in standards:
         raise ValueError("Unknown Fortran standard: %s" % self._settings[
                          'standard'])
开发者ID:AdrianPotter,项目名称:sympy,代码行数:21,代码来源:fcode.py


示例10: _print_Pow

 def _print_Pow(self, expr):
     PREC = precedence(expr)
     if expr.exp == -1:
         return '1.0/%s' % (self.parenthesize(expr.base, PREC))
     elif expr.exp == 0.5:
         if expr.base.is_integer:
             # Fortan intrinsic sqrt() does not accept integer argument
             if expr.base.is_Number:
                 return 'sqrt(%s.0d0)' % self._print(expr.base)
             else:
                 return 'sqrt(dble(%s))' % self._print(expr.base)
         else:
             return 'sqrt(%s)' % self._print(expr.base)
     else:
         return CodePrinter._print_Pow(self, expr)
开发者ID:jenshnielsen,项目名称:sympy,代码行数:15,代码来源:fcode.py


示例11: _print_Add

    def _print_Add(self, expr, order=None):
        if(self._settings['use_operators']):
            return CodePrinter._print_Add(self, expr, order=order)

        terms = expr.as_ordered_terms()

        def partition(p,l):
            return reduce(lambda x, y: (x[0]+[y], x[1]) if p(y) else (x[0], x[1]+[y]), l,  ([], []))
        def add(a,b):
            return self._print_Function_with_args('add', (a, b))
            # return self.known_functions['add']+'(%s, %s)' % (a,b)
        neg, pos = partition(lambda arg: _coeff_isneg(arg), terms)
        s = pos = reduce(lambda a,b: add(a,b), map(lambda t: self._print(t),pos))
        if(len(neg) > 0):
            # sum the absolute values of the negative terms
            neg = reduce(lambda a,b: add(a,b), map(lambda n: self._print(-n),neg))
            # then subtract them from the positive terms
            s = self._print_Function_with_args('sub', (pos,neg))
            # s = self.known_functions['sub']+'(%s, %s)' % (pos,neg)
        return s
开发者ID:cklb,项目名称:sympy,代码行数:20,代码来源:glsl.py


示例12: _print_Add

    def _print_Add(self, expr):
        # purpose: print complex numbers nicely in Fortran.
        # collect the purely real and purely imaginary parts:
        pure_real = []
        pure_imaginary = []
        mixed = []
        for arg in expr.args:
            if arg.is_number and arg.is_real:
                pure_real.append(arg)
            elif arg.is_number and arg.is_imaginary:
                pure_imaginary.append(arg)
            else:
                mixed.append(arg)
        if len(pure_imaginary) > 0:
            if len(mixed) > 0:
                PREC = precedence(expr)
                term = Add(*mixed)
                t = self._print(term)
                if t.startswith('-'):
                    sign = "-"
                    t = t[1:]
                else:
                    sign = "+"
                if precedence(term) < PREC:
                    t = "(%s)" % t

                return "cmplx(%s,%s) %s %s" % (
                    self._print(Add(*pure_real)),
                    self._print(-S.ImaginaryUnit*Add(*pure_imaginary)),
                    sign, t,
                )
            else:
                return "cmplx(%s,%s)" % (
                    self._print(Add(*pure_real)),
                    self._print(-S.ImaginaryUnit*Add(*pure_imaginary)),
                )
        else:
            return CodePrinter._print_Add(self, expr)
开发者ID:jenshnielsen,项目名称:sympy,代码行数:38,代码来源:fcode.py


示例13: _print_Float

 def _print_Float(self, expr):
     printed = CodePrinter._print_Float(self, expr)
     e = printed.find('e')
     if e > -1:
         return "%sd%s" % (printed[:e], printed[e + 1:])
     return "%sd0" % printed
开发者ID:jenshnielsen,项目名称:sympy,代码行数:6,代码来源:fcode.py


示例14: __init__

 def __init__(self, **kwargs):
     """Register function mappings supplied by user"""
     CodePrinter.__init__(self, kwargs)
     self.known_functions = dict(known_functions)
开发者ID:jwpeterson,项目名称:moose,代码行数:4,代码来源:fparser.py


示例15: setup_test_printer

def setup_test_printer(*args, **kwargs):
    p = CodePrinter(*args, **kwargs)
    p._not_supported = set()
    p._number_symbols = set()
    return p
开发者ID:Bercio,项目名称:sympy,代码行数:5,代码来源:test_codeprinter.py


示例16: __init__

 def __init__(self, settings={}):
     CodePrinter.__init__(self, settings)
     self.known_functions = dict(known_functions)
     userfuncs = settings.get('user_functions', {})
     self.known_functions.update(userfuncs)
开发者ID:abhi98khandelwal,项目名称:sympy,代码行数:5,代码来源:jscode.py



注:本文中的sympy.printing.codeprinter.CodePrinter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python conventions.split_super_sub函数代码示例发布时间:2022-05-27
下一篇:
Python ccode.CCodePrinter类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap