Compare commits

...

4 Commits
V2.2 ... master

Author SHA1 Message Date
Bertrand Benjamin 7f8939eab2 Test: separate expression build and showing it
continuous-integration/drone/push Build is passing Details
2020-08-21 19:07:34 +02:00
Bertrand Benjamin 0cadc6734e Feat: return value for random_list
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2020-08-20 20:50:54 +02:00
Bertrand Benjamin f767aa390c Fix: rename list_generator to random_list
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2020-08-20 20:42:46 +02:00
Bertrand Benjamin 55985bfe20 Tagging: bad version number!
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2020-08-20 17:40:16 +02:00
6 changed files with 24 additions and 14 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
from .calculus import Expression, Integer, Decimal, list_generator
from .calculus import Expression, Integer, Decimal, random_list
# Expression.set_render('tex')

View File

@ -136,9 +136,11 @@ class Expression(object):
:returns: TODO
:example:
>>> Expression.random("{a}/{a*k}") # doctest: +SKIP
>>> e = Expression.random("{a}/{a*k}")
>>> e # doctest: +SKIP
<Exp: -3 / -15>
>>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest: +SKIP
>>> e = Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}})
>>> e # doctest: +SKIP
<Exp: 18 / 108 - 3 * 9>
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
>>> ee = e.simplify()

View File

@ -31,7 +31,7 @@ Expression is the classe wich handle all calculus. It can randomly generate or i
"""
from .API import Expression, Integer, Decimal
from .core import list_generator
from .core import random_list
from decimal import getcontext
#getcontext().prec = 2

View File

@ -66,7 +66,7 @@ from .tree import Tree, AssocialTree
from .compute import compute
from .typing import typing, TypingError
from .renders import tree2txt, tree2tex
from .random import list_generator
from .random import list_generator as random_list
# -----------------------------

View File

@ -71,7 +71,7 @@ This function ignores tree structure and works with lists
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
"""
__all__ = ["generator"]
__all__ = ["list_generator"]
from random import choice
from functools import reduce
@ -256,7 +256,7 @@ def build_variable_scope(rd_variables, rejected, min_max, variables_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
: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 min_max: (min, max) limits in between variables will be generated
: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
:example:
>>> values = list_generator(["a", "a*b", "b", "c"])
>>> values # doctest: +SKIP
>>> values["a"] * values["b"] == values["a*b"]
>>> a, ab, b, c = list_generator(["a", "a*b", "b", "c"])
>>> a, ab, b, c # doctest: +SKIP
(5, -20, -4, -3)
>>> a * b == ab
True
>>> values["a*b"] # doctest: +SKIP
>>> values["a"] * values["b"] # doctest: +SKIP
>>> ab # 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_gen = random_generator(rv, conditions, rejected, min_max, variables_scope)
generated = compute_leafs(var_list, rv_gen)
return generated
if dictionnary:
return generated
return [generated[v] for v in var_list]

View File

@ -7,7 +7,7 @@ except ImportError:
setup(
name="mapytex",
version="2.2",
version="2.3.2",
description="Computing like a student",
author="Benjamin Bertrand",
author_email="programming@opytex.org",