def sample_iter_lambdify(expr, condition=None, numsamples=S.Infinity, **kwargs):
 if condition:
  ps = pspace(Tuple(expr, condition))
 else:
  ps = pspace(expr)
 rvs = list(ps.values)
 fn = lambdify(rvs, expr, **kwargs)
 if condition:
  given_fn = lambdify(rvs, condition, **kwargs)
 try:
  d = ps.sample()
  args = [d[rv] for rv in rvs]
  fn(*args)
  if condition:
   given_fn(*args)
 except Exception:
  raise TypeError('Expr/condition too complex for lambdify')
 def return_generator():
  count = 0
  while (count < numsamples):
   d = ps.sample()
   args = [d[rv] for rv in rvs]
   if condition:
    gd = given_fn(*args)
    if ((gd != True) and (gd != False)):
     raise ValueError('Conditions must not contain free symbols')
    if (not gd):
     continue
   (yield fn(*args))
   count += 1
 return return_generator()

def sample_iter_lambdify ( expr , condition = None , numsamples = S . Infinity , ** kwargs ) : if condition : ps = pspace ( Tuple ( expr , condition ) ) else : ps = pspace ( expr ) rvs = list ( ps . values ) fn = lambdify ( rvs , expr , ** kwargs ) if condition : given_fn = lambdify ( rvs , condition , ** kwargs ) try : d = ps . sample ( ) args = [ d [ rv ] for rv in rvs ] fn ( * args ) if condition : given_fn ( * args ) except Exception : raise TypeError ( 'Expr/condition too complex for lambdify' ) def return_generator ( ) : count = 0 while ( count < numsamples ) : d = ps . sample ( ) args = [ d [ rv ] for rv in rvs ] if condition : gd = given_fn ( * args ) if ( ( gd != True ) and ( gd != False ) ) : raise ValueError ( 'Conditions must not contain free symbols' ) if ( not gd ) : continue ( yield fn ( * args ) ) count += 1 return return_generator ( )
see sample_iter uses lambdify for computation .