Feat: return value for random_list
This commit is contained in:
parent
f767aa390c
commit
0cadc6734e
@ -71,7 +71,7 @@ This function ignores tree structure and works with lists
|
|||||||
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
|
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ["generator"]
|
__all__ = ["list_generator"]
|
||||||
|
|
||||||
from random import choice
|
from random import choice
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
@ -256,7 +256,7 @@ def build_variable_scope(rd_variables, rejected, min_max, variables_scope):
|
|||||||
return complete_scope
|
return complete_scope
|
||||||
|
|
||||||
|
|
||||||
def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), variables_scope={}):
|
def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), variables_scope={}, dictionnary=False):
|
||||||
""" Generate random computed values from the list
|
""" Generate random computed values from the list
|
||||||
|
|
||||||
:param rd_variables: list of random variables to generate (can be computed value - "a*b")
|
:param rd_variables: list of random variables to generate (can be computed value - "a*b")
|
||||||
@ -264,17 +264,25 @@ def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), var
|
|||||||
:param rejected: Rejected values for the generator (default [0])
|
:param rejected: Rejected values for the generator (default [0])
|
||||||
:param min_max: (min, max) limits in between variables will be generated
|
:param min_max: (min, max) limits in between variables will be generated
|
||||||
:param variables_scope: rejected and min_max define for individual variables
|
:param variables_scope: rejected and min_max define for individual variables
|
||||||
|
:param dictionnary: the return value will be a dictionnary with var_list as keys (default False)
|
||||||
:return: dictionnary of generated variables
|
:return: dictionnary of generated variables
|
||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> values = list_generator(["a", "a*b", "b", "c"])
|
>>> a, ab, b, c = list_generator(["a", "a*b", "b", "c"])
|
||||||
>>> values # doctest: +SKIP
|
>>> a, ab, b, c # doctest: +SKIP
|
||||||
>>> values["a"] * values["b"] == values["a*b"]
|
(5, -20, -4, -3)
|
||||||
|
>>> a * b == ab
|
||||||
True
|
True
|
||||||
>>> values["a*b"] # doctest: +SKIP
|
>>> ab # doctest: +SKIP
|
||||||
>>> values["a"] * values["b"] # doctest: +SKIP
|
-20
|
||||||
|
>>> a, b # doctest: +SKIP
|
||||||
|
5, -4
|
||||||
|
>>> list_generator(["a", "a*b", "b", "c"], dictionnary=True) # doctest: +SKIP
|
||||||
|
{'a': -3, 'a*b': 18, 'b': -6, 'c': -4}
|
||||||
"""
|
"""
|
||||||
rv = extract_rv(var_list)
|
rv = extract_rv(var_list)
|
||||||
rv_gen = random_generator(rv, conditions, rejected, min_max, variables_scope)
|
rv_gen = random_generator(rv, conditions, rejected, min_max, variables_scope)
|
||||||
generated = compute_leafs(var_list, rv_gen)
|
generated = compute_leafs(var_list, rv_gen)
|
||||||
|
if dictionnary:
|
||||||
return generated
|
return generated
|
||||||
|
return [generated[v] for v in var_list]
|
||||||
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ except ImportError:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="mapytex",
|
name="mapytex",
|
||||||
version="2.3.1",
|
version="2.3.2",
|
||||||
description="Computing like a student",
|
description="Computing like a student",
|
||||||
author="Benjamin Bertrand",
|
author="Benjamin Bertrand",
|
||||||
author_email="programming@opytex.org",
|
author_email="programming@opytex.org",
|
||||||
|
Loading…
Reference in New Issue
Block a user