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


Python abc.b方法代码示例

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


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

示例1: test_get_most_simple_representation

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [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') 
开发者ID:qutech,项目名称:qupulse,代码行数:18,代码来源:sympy_tests.py

示例2: test_symbolic_shape

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_symbolic_shape(self):
        symbolic = Broadcast(a, (b,))
        self.assertIs(symbolic.func, Broadcast)
        self.assertEqual(symbolic.args, (a, (b,)))

        subs_b = symbolic.subs({b: 6})
        self.assertIs(subs_b.func, Broadcast)
        self.assertEqual(subs_b.args, (a, (6,)))

        subs_a = symbolic.subs({a: 3})
        self.assertIs(subs_a.func, Broadcast)
        self.assertEqual(subs_a.args, (3, (b,)))

        subs_both_scalar = symbolic.subs({a: 3, b: 6})
        self.assertEqual(subs_both_scalar, sympy.Array([3, 3, 3, 3, 3, 3]))

        subs_both_array = symbolic.subs({a: (1, 2, 3, 4, 5, 6), b: 6})
        self.assertEqual(subs_both_array, sympy.Array([1, 2, 3, 4, 5, 6]))

        with self.assertRaises(ValueError):
            symbolic.subs({a: (1, 2, 3, 4, 5, 6), b: 7}) 
开发者ID:qutech,项目名称:qupulse,代码行数:23,代码来源:sympy_tests.py

示例3: test_scalar_broad_cast

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_scalar_broad_cast(self):
        symbolic = Broadcast(a, (6,))
        self.assertIs(symbolic.func, Broadcast)
        self.assertEqual(symbolic.args, (a, (6,)))

        subs_symbol = symbolic.subs({a: b})
        self.assertIs(subs_symbol.func, Broadcast)
        self.assertEqual(subs_symbol.args, (b, (6,)))

        subs_scalar = symbolic.subs({a: 3.4})
        self.assertEqual(subs_scalar, sympy.Array([3.4, 3.4, 3.4, 3.4, 3.4, 3.4]))

        subs_symbol_vector = symbolic.subs({a: (b, 1, 2, 3, 4, 5)})
        self.assertEqual(subs_symbol_vector, sympy.Array([b, 1, 2, 3, 4, 5]))

        subs_numeric_vector = symbolic.subs({a: (0, 1, 2, 3, 4, 5)})
        self.assertEqual(subs_numeric_vector, sympy.Array([0, 1, 2, 3, 4, 5]))

        with self.assertRaises(ValueError):
            symbolic.subs({a: (b, 4, 5)})

        with self.assertRaises(ValueError):
            symbolic.subs({a: (8, 5, 3, 5, 5, 4, 4, 5)}) 
开发者ID:qutech,项目名称:qupulse,代码行数:25,代码来源:sympy_tests.py

示例4: test_numeric_evaluation

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_numeric_evaluation(self):
        symbolic = Broadcast(a, (b,))

        arguments = {'a': (1, 2., 3), 'b': 3}
        expected = np.asarray([1, 2., 3])
        result, _ = evaluate_lambdified(symbolic, ['a', 'b'], arguments, None)
        np.testing.assert_array_equal(expected, result)

        with self.assertRaises(ValueError):
            arguments = {'a': (1, 2., 3), 'b': 4}
            evaluate_lambdified(symbolic, ['a', 'b'], arguments, None)

        arguments = {'a': 1, 'b': 3}
        expected = np.asarray([1, 1, 1])
        result, _ = evaluate_lambdified(symbolic, ['a', 'b'], arguments, None)
        np.testing.assert_array_equal(expected, result) 
开发者ID:qutech,项目名称:qupulse,代码行数:18,代码来源:sympy_tests.py

示例5: test_RandomDomain

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_RandomDomain():
    from sympy.stats import Normal, Die, Exponential, pspace, where
    X = Normal('x1', 0, 1)
    assert upretty(where(X > 0)) == u("Domain: x₁ > 0")

    D = Die('d1', 6)
    assert upretty(where(D > 4)) == u('Domain: d₁ = 5 ∨ d₁ = 6')

    A = Exponential('a', 1)
    B = Exponential('b', 1)
    assert upretty(pspace(Tuple(A, B)).domain) == u('Domain: a ≥ 0 ∧ b ≥ 0') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_pretty.py

示例6: theq

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def theq(a, b):
    """ theano equality """
    astr = theano.printing.debugprint(a, file='str')
    bstr = theano.printing.debugprint(b, file='str')

    if not astr == bstr:
        print()
        print(astr)
        print(bstr)

    return astr == bstr 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_theanocode.py

示例7: wigner_d_naive

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def wigner_d_naive(l, m, n, beta):
    """
    Numerically naive implementation of the Wigner-d function.
    This is useful for checking the correctness of other implementations.

    :param l: the degree of the Wigner-d function. l >= 0
    :param m: the order of the Wigner-d function. -l <= m <= l
    :param n: the order of the Wigner-d function. -l <= n <= l
    :param beta: the argument. 0 <= beta <= pi
    :return: d^l_mn(beta) in the TODO: what basis? complex, quantum(?), centered, cs(?)
    """
    from scipy.special import eval_jacobi
    try:
        from scipy.misc import factorial
    except:
        from scipy.special import factorial

    from sympy.functions.special.polynomials import jacobi, jacobi_normalized
    from sympy.abc import j, a, b, x
    from sympy import N
    #jfun = jacobi_normalized(j, a, b, x)
    jfun = jacobi(j, a, b, x)
    # eval_jacobi = lambda q, r, p, o: float(jfun.eval(int(q), int(r), int(p), float(o)))
    # eval_jacobi = lambda q, r, p, o: float(N(jfun, int(q), int(r), int(p), float(o)))
    eval_jacobi = lambda q, r, p, o: float(jfun.subs({j:int(q), a:int(r), b:int(p), x:float(o)}))

    mu = np.abs(m - n)
    nu = np.abs(m + n)
    s = l - (mu + nu) / 2
    xi = 1 if n >= m else (-1) ** (n - m)

    # print(s, mu, nu, np.cos(beta), type(s), type(mu), type(nu), type(np.cos(beta)))
    jac = eval_jacobi(s, mu, nu, np.cos(beta))
    z = np.sqrt((factorial(s) * factorial(s + mu + nu)) / (factorial(s + mu) * factorial(s + nu)))

    # print(l, m, n, beta, np.isfinite(mu), np.isfinite(nu), np.isfinite(s), np.isfinite(xi), np.isfinite(jac), np.isfinite(z))
    assert np.isfinite(mu) and np.isfinite(nu) and np.isfinite(s) and np.isfinite(xi) and np.isfinite(jac) and np.isfinite(z)
    assert np.isfinite(xi * z * np.sin(beta / 2) ** mu * np.cos(beta / 2) ** nu * jac)
    return xi * z * np.sin(beta / 2) ** mu * np.cos(beta / 2) ** nu * jac 
开发者ID:AMLab-Amsterdam,项目名称:lie_learn,代码行数:41,代码来源:wigner_d.py

示例8: test_get_free_symbols

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_get_free_symbols(self):
        expr = a * b / 5
        self.assert_symbol_sets_equal([a, b], get_free_symbols(expr)) 
开发者ID:qutech,项目名称:qupulse,代码行数:5,代码来源:sympy_tests.py

示例9: test_get_free_symbols_indexed

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_get_free_symbols_indexed(self):
        expr = a_[i] * IndexedBase(a*b)[j]
        self.assert_symbol_sets_equal({a, b, i, j}, set(get_free_symbols(expr))) 
开发者ID:qutech,项目名称:qupulse,代码行数:5,代码来源:sympy_tests.py

示例10: test_get_variables

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_get_variables(self):
        expr = a * b / 5
        self.assertEqual({'a', 'b'}, set(get_variables(expr))) 
开发者ID:qutech,项目名称:qupulse,代码行数:5,代码来源:sympy_tests.py

示例11: test_get_variables_indexed

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_get_variables_indexed(self):
        expr = a_[i] * IndexedBase(a*b)[j]
        self.assertEqual({'a', 'b', 'i', 'j'}, set(get_variables(expr))) 
开发者ID:qutech,项目名称:qupulse,代码行数:5,代码来源:sympy_tests.py

示例12: test_array_broadcast

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_array_broadcast(self):
        expected = sympy.Array([1, 2, a, b])

        self.assertEqual(expected, Broadcast(list(expected), (4,)))
        self.assertEqual(expected, Broadcast(tuple(expected), (4,)))
        self.assertEqual(expected, Broadcast(expected, (4,))) 
开发者ID:qutech,项目名称:qupulse,代码行数:8,代码来源:sympy_tests.py

示例13: test_expression_equality

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def test_expression_equality(self):
        """Sympy decided to change their equality reasoning"""
        self.assertEqual(sympy.sympify('3'), sympy.sympify('3.'))
        self.assertEqual(sympy.sympify('3 + a'), sympy.sympify('3 + a'))
        self.assertEqual(sympy.sympify('3 + a'), sympy.sympify('3. + a'))

        expr_with_float = sympy.sympify('a*(b - 3.0) + (-b + c)*(d + 4.0)/2')
        expr_with_int = sympy.sympify('a*(b - 3) + (-b + c)*(d + 4)/2')
        expr_with_int_other_order = sympy.sympify('(b-3)*a + (c-b)*(d+4) / 2')

        self.assertEqual(expr_with_float, expr_with_int)
        self.assertEqual(expr_with_int, expr_with_int_other_order)
        self.assertEqual(expr_with_float, expr_with_int_other_order) 
开发者ID:qutech,项目名称:qupulse,代码行数:15,代码来源:sympy_tests.py

示例14: _Add

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def _Add(a, b):
    return Add(a, b, evaluate=False) 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:4,代码来源:test.py

示例15: _Mul

# 需要导入模块: from sympy import abc [as 别名]
# 或者: from sympy.abc import b [as 别名]
def _Mul(a, b):
    return Mul(a, b, evaluate=False) 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:4,代码来源:test.py


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