Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Boltzmann: fix import statements in doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerl13 committed Jun 21, 2019
1 parent 1da6bd2 commit 5303f2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/sage/combinat/boltzmann_sampling/generator.pyx
Expand Up @@ -186,9 +186,6 @@ cdef int c_simulate(first_rule, int size_max, flat_rules, randstate rstate):
# Actual generation
# ---

cdef inline wrap_choice(float weight, int id):
return (WRAP_CHOICE, weight, id)

cdef c_generate(first_rule, rules, builders, randstate rstate):
generated = []
cdef list todo = [first_rule]
Expand All @@ -201,16 +198,16 @@ cdef c_generate(first_rule, rules, builders, randstate rstate):
todo.append((FUNCTION, weight, symbol))
todo.append(rules[symbol])
elif type == ATOM:
atom_name, __ = args
generated.append(atom_name)
(name, size) = args
generated.append((name, size))
elif type == UNION:
r = rstate.c_rand_double() * weight
for i in range(len(args)):
arg = args[i]
__, arg_weight, __ = arg
r -= arg_weight
if r <= 0:
todo.append(wrap_choice(arg_weight, i))
todo.append((WRAP_CHOICE, arg_weight, i))
todo.append(arg)
break
elif type == PRODUCT:
Expand Down
10 changes: 9 additions & 1 deletion src/sage/combinat/boltzmann_sampling/oracle.py
Expand Up @@ -29,10 +29,12 @@


def oracle(sys, **kargs):
"""Build different oracle given different inputs
"""Build different oracles given different inputs
EXAMPLES::
sage: from sage.combinat.boltzmann_sampling.oracle import SimpleOracle, OracleFromFunctions
sage: leaf = Atom("leaf", size=0)
sage: z = Atom("z")
sage: g = Grammar(rules={"B": Union(leaf, Product(z, "B", "B"))})
Expand All @@ -55,6 +57,8 @@ class SimpleOracle(SageObject):
EXAMPLES::
sage: from sage.combinat.boltzmann_sampling.oracle import SimpleOracle
sage: leaf = Atom("leaf", size=0)
sage: z = Atom("z")
sage: g = Grammar(rules={"B": Union(leaf, Product(z, "B", "B"))})
Expand Down Expand Up @@ -149,6 +153,8 @@ def find_singularity(oracle, precision=1e-6, zstart=0., zmin=0., zmax=1., diverg
EXAMPLE::
sage: from sage.combinat.boltzmann_sampling.oracle import SimpleOracle
sage: leaf = Atom("leaf", size=0)
sage: z = Atom("z")
sage: g = Grammar(rules={"B": Union(leaf, Product(z, "B", "B"))})
Expand Down Expand Up @@ -190,6 +196,8 @@ def __init__(self, sys, precision_ring=SR):
EXAMPLES::
sage: from sage.combinat.boltzmann_sampling.oracle import OracleFromFunctions
sage: B(z) = (1 - sqrt(1 - 4 * z)) / (2 * z)
sage: oracle = OracleFromFunctions({"z": z, "B": B})
sage: oracle.eval_rule("z", {"z":1/4})
Expand Down

0 comments on commit 5303f2a

Please sign in to comment.