예제 #1
0
 def test_expr_contains(self):
     expr = ('#Add', ('#Mul', (1.5, ('#CPow1.2000e+00', ('#x', )))),
             ('#Mul', (1.2, ), (7, )))
     self.assertTrue(simplify.expr_contains(expr, '#x'))
     self.assertFalse(simplify.expr_contains(expr, '#CPow'))
     self.assertTrue(simplify.expr_contains(expr, '#CPow1.2000e+00'))
     self.assertTrue(simplify.expr_contains(expr, '#Mul'))
     self.assertTrue(simplify.expr_contains(expr, '#Add'))
     self.assertTrue(simplify.expr_contains(expr[1], '#x'))
     self.assertFalse(simplify.expr_contains(expr[2], '#x'))
예제 #2
0
def extract_s_stat_multipliers(expr):
  if expr[0] != '#Mul':
    return (), expr
  s_stats = []
  multipliers = []
  for i in expr[1:]:
    if expr_contains(i, '#x'):
      multiplier, s_stat = extract_s_stat_multipliers(i)
      multipliers += multiplier
      s_stats += s_stat
    else:
      multipliers.append(i)
  return tuple(multipliers), tuple(s_stats)
예제 #3
0
파일: conjugacy.py 프로젝트: wujsAct/edward
def extract_s_stat_multipliers(expr):
  if expr[0] != '#Mul':
    return (), expr
  s_stats = []
  multipliers = []
  for i in expr[1:]:
    if expr_contains(i, '#x'):
      multiplier, s_stat = extract_s_stat_multipliers(i)
      multipliers += multiplier
      s_stats += s_stat
    else:
      multipliers.append(i)
  return tuple(multipliers), tuple(s_stats)