本文整理汇总了Python中sympy.Eq方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.Eq方法的具体用法?Python sympy.Eq怎么用?Python sympy.Eq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy
的用法示例。
在下文中一共展示了sympy.Eq方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def __new__(cls, *args, **kwargs):
if len(args) == 1:
# origin: ClusterizedEq(expr, **kwargs)
input_expr = args[0]
expr = sympy.Eq.__new__(cls, *input_expr.args, evaluate=False)
for i in cls._state:
v = kwargs[i] if i in kwargs else getattr(input_expr, i, None)
setattr(expr, '_%s' % i, v)
elif len(args) == 2:
# origin: ClusterizedEq(lhs, rhs, **kwargs)
expr = sympy.Eq.__new__(cls, *args, evaluate=False)
for i in cls._state:
setattr(expr, '_%s' % i, kwargs.pop(i))
else:
raise ValueError("Cannot construct ClusterizedEq from args=%s "
"and kwargs=%s" % (str(args), str(kwargs)))
return expr
示例2: test_get_most_simple_representation
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def test_get_most_simple_representation(self):
cpl = get_most_simple_representation(qc_sympify('1 + 1j'))
self.assertIsInstance(cpl, str)
self.assertTrue(bool(sympy.Eq(sympy.sympify(cpl), 1 + 1j)))
integer = get_most_simple_representation(qc_sympify('3'))
self.assertIsInstance(integer, int)
self.assertEqual(integer, 3)
flt = get_most_simple_representation(qc_sympify('3.1'))
self.assertIsInstance(flt, float)
self.assertEqual(flt, 3.1)
st = get_most_simple_representation(qc_sympify('a + b'))
self.assertIsInstance(st, str)
self.assertEqual(st, 'a + b')
示例3: convert_relation
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def convert_relation(rel):
if rel.expr():
return convert_expr(rel.expr())
lh = convert_relation(rel.relation(0))
rh = convert_relation(rel.relation(1))
if rel.LT():
return sympy.StrictLessThan(lh, rh)
elif rel.LTE():
return sympy.LessThan(lh, rh)
elif rel.GT():
return sympy.StrictGreaterThan(lh, rh)
elif rel.GTE():
return sympy.GreaterThan(lh, rh)
elif rel.EQUAL():
return sympy.Eq(lh, rh)
示例4: __init__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def __init__(self, left, right):
super(Eq, self).__init__({'left': left, 'right': right})
示例5: sympy
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def sympy(self):
return sympy.Eq(self.children['left'], self.children['right'])
示例6: get_episode_equations
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def get_episode_equations():
"""Get the score equations for a :class:`~subliminal.video.Episode`
The equations are the following:
1. hash = resolution + video_codec + audio_codec + series + season + episode + release_group
2. series = resolution + video_codec + audio_codec + season + episode + 1
3. tvdb_id = series
4. season = resolution + video_codec + audio_codec + 1
5. imdb_id = series + season + episode
6. resolution = video_codec
7. video_codec = 2 * audio_codec
8. title = season + episode
9. season = episode
10. release_group = season
11. audio_codec = 1
:return: the score equations for an episode
:rtype: list of :class:`sympy.Eq`
"""
equations = []
equations.append(Eq(hash, resolution + video_codec + audio_codec + series + season + episode + release_group))
equations.append(Eq(series, resolution + video_codec + audio_codec + season + episode + release_group))
equations.append(Eq(tvdb_id, series))
equations.append(Eq(season, resolution + video_codec + audio_codec + 1))
equations.append(Eq(imdb_id, series + season + episode))
equations.append(Eq(resolution, video_codec))
equations.append(Eq(video_codec, 2 * audio_codec))
equations.append(Eq(title, season + episode))
equations.append(Eq(season, episode))
equations.append(Eq(release_group, season))
equations.append(Eq(audio_codec, 1))
return equations
示例7: get_movie_equations
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def get_movie_equations():
"""Get the score equations for a :class:`~subliminal.video.Movie`
The equations are the following:
1. hash = resolution + video_codec + audio_codec + title + year + release_group
2. imdb_id = hash
3. resolution = video_codec
4. video_codec = 2 * audio_codec
5. title = resolution + video_codec + audio_codec + year + 1
6. release_group = resolution + video_codec + audio_codec + 1
7. year = release_group + 1
8. audio_codec = 1
:return: the score equations for a movie
:rtype: list of :class:`sympy.Eq`
"""
equations = []
equations.append(Eq(hash, resolution + video_codec + audio_codec + title + year + release_group))
equations.append(Eq(imdb_id, hash))
equations.append(Eq(resolution, video_codec))
equations.append(Eq(video_codec, 2 * audio_codec))
equations.append(Eq(title, resolution + video_codec + audio_codec + year + 1))
equations.append(Eq(video_codec, 2 * audio_codec))
equations.append(Eq(release_group, resolution + video_codec + audio_codec + 1))
equations.append(Eq(year, release_group + 1))
equations.append(Eq(audio_codec, 1))
return equations
示例8: block4
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def block4(exprs, iters, dims):
# Non-perfect loop nest due to conditional
# for i
# if i % 2 == 0
# for j
return iters[0](Conditional(Eq(Mod(dims['i'], 2), 0), iters[1](exprs[0])))
示例9: test_printAST
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def test_printAST(block1, block2, block3, block4):
str1 = printAST(block1)
assert str1 in """
<Iteration i::i::(0, 3, 1)>
<Iteration j::j::(0, 5, 1)>
<Iteration k::k::(0, 7, 1)>
<Expression a[i] = a[i] + b[i] + 5.0>
"""
str2 = printAST(block2)
assert str2 in """
<Iteration i::i::(0, 3, 1)>
<Expression a[i] = a[i] + b[i] + 5.0>
<Iteration j::j::(0, 5, 1)>
<Iteration k::k::(0, 7, 1)>
<Expression a[i] = -a[i] + b[i]>
"""
str3 = printAST(block3)
assert str3 in """
<Iteration i::i::(0, 3, 1)>
<Iteration s::s::(0, 4, 1)>
<Expression a[i] = a[i] + b[i] + 5.0>
<Iteration j::j::(0, 5, 1)>
<Iteration k::k::(0, 7, 1)>
<Expression a[i] = -a[i] + b[i]>
<Expression a[i] = 4*a[i]*b[i]>
<Iteration q::q::(0, 4, 1)>
<Expression a[i] = 8.0*a[i] + 6.0/b[i]>
"""
str4 = printAST(block4)
assert str4 in """
<Iteration i::i::(0, 3, 1)>
<If Eq(Mod(i, 2), 0)>
<Iteration j::j::(0, 5, 1)>
<Expression a[i] = a[i] + b[i] + 5.0>
"""
示例10: __new__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def __new__(cls, *args, **kwargs):
return sympy.Eq.__new__(cls, *args, evaluate=False)
示例11: q_affine
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def q_affine(expr, vars):
"""
Return True if ``expr`` is (separately) affine in the variables ``vars``,
False otherwise.
Notes
-----
Exploits:
https://stackoverflow.com/questions/36283548\
/check-if-an-equation-is-linear-for-a-specific-set-of-variables/
"""
vars = as_tuple(vars)
free_symbols = expr.free_symbols
# At this point, `expr` is (separately) affine in the `vars` variables
# if all non-mixed second order derivatives are identically zero.
for x in vars:
if expr is x:
continue
if x not in free_symbols:
# At this point the only hope is that `expr` is constant
return q_constant(expr)
# The vast majority of calls here are incredibly simple tests
# like q_affine(x+1, [x]). Catch these quickly and
# explicitly, instead of calling the very slow function `diff`.
if expr.is_Add and len(expr.args) == 2:
if expr.args[1] is x and expr.args[0].is_Number:
continue
if expr.args[0] is x and expr.args[1].is_Number:
continue
try:
if diff(expr, x) is nan or not Eq(diff(expr, x, x), 0):
return False
except TypeError:
return False
return True
示例12: __new__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def __new__(cls, lhs, rhs=0, subdomain=None, coefficients=None, implicit_dims=None,
**kwargs):
kwargs['evaluate'] = False
obj = sympy.Eq.__new__(cls, lhs, rhs, **kwargs)
obj._subdomain = subdomain
obj._substitutions = coefficients
obj._implicit_dims = as_tuple(implicit_dims)
return obj
示例13: solve
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def solve(eq, target, **kwargs):
"""
Algebraically rearrange an Eq w.r.t. a given symbol.
This is a wrapper around ``sympy.solve``.
Parameters
----------
eq : expr-like
The equation to be rearranged.
target : symbol
The symbol w.r.t. which the equation is rearranged. May be a `Function`
or any other symbolic object.
**kwargs
Symbolic optimizations applied while rearranging the equation. For more
information. refer to ``sympy.solve.__doc__``.
"""
if isinstance(eq, Eq):
eq = eq.lhs - eq.rhs if eq.rhs != 0 else eq.lhs
sols = []
for e, t in zip(as_tuple(eq), as_tuple(target)):
# Try first linear solver
try:
cc = linear_coeffs(e.evaluate, t)
sols.append(-cc[1]/cc[0])
except ValueError:
warning("Equation is not affine w.r.t the target, falling back to standard"
"sympy.solve that may be slow")
kwargs['rational'] = False # Avoid float indices
kwargs['simplify'] = False # Do not attempt premature optimisation
sols.append(sympy.solve(e.evaluate, t, **kwargs)[0])
# We need to rebuild the vector/tensor as sympy.solve outputs a tuple of solutions
if len(sols) > 1:
return target.new_from_mat(sols)
else:
return sols[0]
示例14: scipy_constraints
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def scipy_constraints(self, constraints):
"""
Returns all constraints in a scipy compatible format.
:param constraints: List of either MinimizeModel instances (this is what
is provided by :class:`~symfit.core.fit.Fit`),
:class:`~symfit.core.models.BaseModel`, or
:class:`sympy.core.relational.Relational`.
:return: dict of scipy compatible statements.
"""
cons = []
types = { # scipy only distinguishes two types of constraint.
sympy.Eq: 'eq', sympy.Ge: 'ineq',
}
for constraint in constraints:
if isinstance(constraint, MinimizeModel):
# Typically the case when called by `Fit
constraint_type = constraint.model.constraint_type
elif hasattr(constraint, 'constraint_type'):
# Model object, not provided by `Fit`. Do the best we can.
if self.parameters != constraint.params:
raise AssertionError('The constraint should accept the same'
' parameters as used for the fit.')
constraint_type = constraint.constraint_type
constraint = MinimizeModel(constraint, data=self.objective.data)
elif isinstance(constraint, sympy.Rel):
constraint_type = constraint.__class__
constraint = self.objective.model.__class__.as_constraint(
constraint, self.objective.model
)
constraint = MinimizeModel(constraint, data=self.objective.data)
else:
raise TypeError('Unknown type for a constraint.')
con = {
'type': types[constraint_type],
'fun': constraint,
}
cons.append(con)
cons = tuple(cons)
return cons
示例15: __init__
# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Eq [as 别名]
def __init__(self, relation: Union[str, sympy.Expr]):
super().__init__()
if isinstance(relation, str) and '==' in relation:
# The '==' operator is interpreted by sympy as exactly, however we need a symbolical evaluation
self._expression = sympy.Eq(*sympy.sympify(relation.split('==')))
else:
self._expression = sympy.sympify(relation)
if not isinstance(self._expression, sympy.boolalg.Boolean):
raise ValueError('Constraint is not boolean')
self._expression = Expression(self._expression)