当前位置: 首页>>代码示例>>Python>>正文


Python sympy.Float方法代码示例

本文整理汇总了Python中sympy.Float方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.Float方法的具体用法?Python sympy.Float怎么用?Python sympy.Float使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy的用法示例。


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

示例1: test_sympy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_sympy():
    # Raw values.
    assert_json_roundtrip_works(sympy.Symbol('theta'))
    assert_json_roundtrip_works(sympy.Integer(5))
    assert_json_roundtrip_works(sympy.Rational(2, 3))
    assert_json_roundtrip_works(sympy.Float(1.1))

    # Basic operations.
    s = sympy.Symbol('s')
    t = sympy.Symbol('t')
    assert_json_roundtrip_works(t + s)
    assert_json_roundtrip_works(t * s)
    assert_json_roundtrip_works(t / s)
    assert_json_roundtrip_works(t - s)
    assert_json_roundtrip_works(t**s)

    # Linear combinations.
    assert_json_roundtrip_works(t * 2)
    assert_json_roundtrip_works(4 * t + 3 * s + 2) 
开发者ID:quantumlib,项目名称:Cirq,代码行数:21,代码来源:json_serialization_test.py

示例2: _sympy_format

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def _sympy_format(self, method, variables, backend, default, **kwargs):
        variables = variables or {}
        if backend in (None, math):
            backend = sympy
        variables = defaultkeydict(
            None if default is None else (lambda k: backend.Symbol(default(k))),
            {k: v if isinstance(v, Expr) else (backend.Symbol(v) if isinstance(v, str) else backend.Float(v))
             for k, v in variables.items()})
        expr = self(variables, backend=backend, **kwargs).simplify()
        if method == 'latex':
            return backend.latex(expr)
        elif method == 'str':
            return str(expr)
        elif method == 'unicode':
            return backend.pretty(expr, use_unicode=True)
        elif method == 'mathml':
            from sympy.printing.mathml import mathml
            return mathml(expr)
        else:
            raise NotImplementedError("Unknown method: %s" % method) 
开发者ID:bjodah,项目名称:chempy,代码行数:22,代码来源:_expr.py

示例3: indexify

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def indexify(self, indices=None, lshift=False, subs=None):
        """Create a types.Indexed from the current object."""
        if indices is not None:
            return Indexed(self.indexed, *indices)

        # Substitution for each index (spacing only used in own dimension)
        subs = subs or {}
        subs = [{**{d.spacing: 1, -d.spacing: -1}, **subs} for d in self.dimensions]

        # Add halo shift
        shift = self._size_nodomain.left if lshift else tuple([0]*len(self.dimensions))
        # Indices after substitutions
        indices = [sympy.sympify((a - o + f).xreplace(s)) for a, o, f, s in
                   zip(self.args, self.origin, shift, subs)]
        indices = [i.xreplace({k: sympy.Integer(k) for k in i.atoms(sympy.Float)})
                   for i in indices]
        return self.indexed[indices] 
开发者ID:devitocodes,项目名称:devito,代码行数:19,代码来源:basic.py

示例4: _parse_evaluate_numeric_result

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def _parse_evaluate_numeric_result(self,
                                       result: Union[Number, numpy.ndarray],
                                       call_arguments: Any) -> Union[Number, numpy.ndarray]:
        allowed_types = (float, numpy.number, int, complex, bool, numpy.bool_, TimeType)
        if isinstance(result, tuple):
            result = numpy.array(result)
        if isinstance(result, numpy.ndarray):
            if issubclass(result.dtype.type, allowed_types):
                return result
            else:
                obj_types = set(map(type, result.flat))
                if obj_types == {sympy.Float} or obj_types == {sympy.Float, sympy.Integer}:
                    return result.astype(float)
                elif obj_types == {sympy.Integer}:
                    return result.astype(numpy.int64)
                else:
                    raise NonNumericEvaluation(self, result, call_arguments)
        elif isinstance(result, allowed_types):
            return result
        elif isinstance(result, sympy.Float):
            return float(result)
        elif isinstance(result, sympy.Integer):
            return int(result)
        else:
            raise NonNumericEvaluation(self, result, call_arguments) 
开发者ID:qutech,项目名称:qupulse,代码行数:27,代码来源:expressions.py

示例5: __init__

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def __init__(self,name,v,g):
        super(_Param,self).__init__(name,g)
        self.val = v
        self._sym = sp.Dummy(self._name,real=True)
        self._symobj = self._sym
        self._val = sp.Float(self.val) 
开发者ID:realthunder,项目名称:FreeCAD_assembly3,代码行数:8,代码来源:sys_sympy.py

示例6: getSymObj

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def getSymObj(self):
        return sp.Float(self.d) 
开发者ID:realthunder,项目名称:FreeCAD_assembly3,代码行数:4,代码来源:sys_sympy.py

示例7: test_mpfr

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_mpfr():
    if have_mpfr:
        a = RealMPFR('100', 100)
        b = sympy.Float('100', 29)
        assert sympify(b) == a
        assert b == a._sympy_() 
开发者ID:symengine,项目名称:symengine.py,代码行数:8,代码来源:test_sympy_conv.py

示例8: test_mpc

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_mpc():
    if have_mpc:
        a = ComplexMPC('1', '2', 100)
        b = sympy.Float(1, 29) + sympy.Float(2, 29) * sympy.I
        assert sympify(b) == a
        assert b == a._sympy_() 
开发者ID:symengine,项目名称:symengine.py,代码行数:8,代码来源:test_sympy_conv.py

示例9: test_hbar

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_hbar():
    assert hbar.is_commutative is True
    assert hbar.is_real is True
    assert hbar.is_positive is True
    assert hbar.is_negative is False
    assert hbar.is_irrational is True

    assert hbar.evalf() == Float(1.05457162e-34) 
开发者ID:sympsi,项目名称:sympsi,代码行数:10,代码来源:test_constants.py

示例10: test_scalar_sympy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_scalar_sympy():
    assert represent(Integer(1)) == Integer(1)
    assert represent(Float(1.0)) == Float(1.0)
    assert represent(1.0 + I) == 1.0 + I 
开发者ID:sympsi,项目名称:sympsi,代码行数:6,代码来源:test_represent.py

示例11: test_scalar_numpy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_scalar_numpy():
    if not np:
        skip("numpy not installed.")

    assert represent(Integer(1), format='numpy') == 1
    assert represent(Float(1.0), format='numpy') == 1.0
    assert represent(1.0 + I, format='numpy') == 1.0 + 1.0j 
开发者ID:sympsi,项目名称:sympsi,代码行数:9,代码来源:test_represent.py

示例12: test_scalar_scipy_sparse

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def test_scalar_scipy_sparse():
    if not np:
        skip("numpy not installed.")
    if not scipy:
        skip("scipy not installed.")

    assert represent(Integer(1), format='scipy.sparse') == 1
    assert represent(Float(1.0), format='scipy.sparse') == 1.0
    assert represent(1.0 + I, format='scipy.sparse') == 1.0 + 1.0j 
开发者ID:sympsi,项目名称:sympsi,代码行数:11,代码来源:test_represent.py

示例13: _decompose_into_amount_unit_suffix

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def _decompose_into_amount_unit_suffix(self) -> Tuple[int, str, str]:
        if (isinstance(self._picos, sympy.Mul) and
                len(self._picos.args) == 2 and
                isinstance(self._picos.args[0], (sympy.Integer, sympy.Float))):
            scale = self._picos.args[0]
            rest = self._picos.args[1]
        else:
            scale = self._picos
            rest = 1

        if scale % 1000_000_000 == 0:
            amount = scale / 1000_000_000
            unit = 'millis'
            suffix = 'ms' 
开发者ID:quantumlib,项目名称:Cirq,代码行数:16,代码来源:duration.py

示例14: _is_supported_formula

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def _is_supported_formula(formula: sympy.Basic) -> bool:
    if isinstance(formula, (sympy.Symbol, sympy.Integer, sympy.Float,
                            sympy.Rational, sympy.NumberSymbol)):
        return True
    if isinstance(formula, (sympy.Add, sympy.Mul)):
        return all(_is_supported_formula(f) for f in formula.args)
    return False 
开发者ID:quantumlib,项目名称:Cirq,代码行数:9,代码来源:quirk_gate.py

示例15: _implicit_conversion

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Float [as 别名]
def _implicit_conversion(obj):
    if isinstance(obj, (int, float)):
        return Constant(obj)
    elif isinstance(obj, Expr):
        return obj
    elif isinstance(obj, str):
        return Symbol(unique_keys=(obj,))

    if sympy is not None:
        if isinstance(obj, sympy.Mul):
            if len(obj.args) != 2:
                raise NotImplementedError("Did you use evaluate=False?")
            return _MulExpr([_implicit_conversion(obj.args[0]), _implicit_conversion(obj.args[1])])
        elif isinstance(obj, sympy.Add):
            if len(obj.args) != 2:
                raise NotImplementedError("Did you use evaluate=False?")
            return _AddExpr([_implicit_conversion(obj.args[0]), _implicit_conversion(obj.args[1])])
        elif isinstance(obj, sympy.Pow):
            return _PowExpr(_implicit_conversion(obj.base), _implicit_conversion(obj.exp))
        elif isinstance(obj, sympy.Float):
            return Constant(float(obj))
        elif isinstance(obj, sympy.Symbol):
            return Symbol(unique_keys=(obj.name,))

    raise NotImplementedError(
        "Don't know how to convert %s (of type %s)" % (obj, type(obj))) 
开发者ID:bjodah,项目名称:chempy,代码行数:28,代码来源:_expr.py


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