-def generate(nb_values=3, max_input=9, prog_len=6, nb_runs=5):
- prog_len = 1 + torch.randint(prog_len - 1, (1,)).item()
- prog = [rpl_ops[k] for k in torch.randint(len(rpl_ops), (prog_len,))]
+def generate(
+ nb_starting_values=3, nb_result_values_max=None, max_input=9, prog_len=6, nb_runs=5
+):
+ prog_len = (1 + torch.randint(2 * prog_len, (1,))).clamp(max=prog_len).item()
+
+ while True:
+ no_empty_stack = True
+ prog = [rpl_ops[k] for k in torch.randint(len(rpl_ops), (prog_len,))]
+
+ result = []
+ for _ in range(nb_runs):
+ stack = [
+ x.item() for x in torch.randint(max_input + 1, (nb_starting_values,))
+ ]
+ result_stack = rpl_exec(prog, stack)
+ if len(result_stack) == 0:
+ no_empty_stack = False
+ result = result + ["<input>"] + stack + ["<output>"] + result_stack
+
+ result = result + ["<prog>"] + prog
+ result = result + ["<end>"]