Compare commits
No commits in common. "bb43611f670ea49aa846c42f37a9de283fe0e671" and "7e4bfc9ba09d7ceb08f94a5e3c5240bc953e434a" have entirely different histories.
bb43611f67
...
7e4bfc9ba0
@ -7,12 +7,3 @@ steps:
|
||||
commands:
|
||||
- pip install -r requirements.txt
|
||||
- pytest --doctest-modules ./mapytex/
|
||||
- name: Publish
|
||||
image: plugins/pypi
|
||||
settings:
|
||||
username:
|
||||
from_secret: pypi_username
|
||||
password:
|
||||
from_secret: pypi_password
|
||||
when:
|
||||
event: tag
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from .calculus import Expression, Integer, Decimal, random_list
|
||||
from .calculus import Expression, Integer, Decimal
|
||||
|
||||
# Expression.set_render('tex')
|
||||
|
||||
|
@ -136,11 +136,9 @@ class Expression(object):
|
||||
:returns: TODO
|
||||
|
||||
:example:
|
||||
>>> e = Expression.random("{a}/{a*k}")
|
||||
>>> e # doctest: +SKIP
|
||||
>>> Expression.random("{a}/{a*k}") # doctest: +SKIP
|
||||
<Exp: -3 / -15>
|
||||
>>> e = Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}})
|
||||
>>> e # doctest: +SKIP
|
||||
>>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest: +SKIP
|
||||
<Exp: 18 / 108 - 3 * 9>
|
||||
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
|
||||
>>> ee = e.simplify()
|
||||
|
@ -31,7 +31,6 @@ Expression is the classe wich handle all calculus. It can randomly generate or i
|
||||
"""
|
||||
|
||||
from .API import Expression, Integer, Decimal
|
||||
from .core import random_list
|
||||
from decimal import getcontext
|
||||
#getcontext().prec = 2
|
||||
|
||||
|
@ -66,7 +66,6 @@ from .tree import Tree, AssocialTree
|
||||
from .compute import compute
|
||||
from .typing import typing, TypingError
|
||||
from .renders import tree2txt, tree2tex
|
||||
from .random import list_generator as random_list
|
||||
|
||||
|
||||
# -----------------------------
|
||||
|
@ -47,8 +47,8 @@ Tree with RdLeaf replaced by generated values
|
||||
>>> leafs
|
||||
['a', 'a*k']
|
||||
>>> rd_varia = extract_rv(leafs)
|
||||
>>> sorted(list(rd_varia))
|
||||
['a', 'k']
|
||||
>>> rd_varia # doctest: +SKIP
|
||||
{'a', 'k'}
|
||||
>>> generated = random_generator(rd_varia, conditions=['a%2+1'])
|
||||
>>> generated # doctest: +SKIP
|
||||
{'a': 7, 'k': 4}
|
||||
@ -61,18 +61,8 @@ Tree with RdLeaf replaced by generated values
|
||||
> 7
|
||||
> 28
|
||||
|
||||
List generator
|
||||
--------------
|
||||
|
||||
This function ignores tree structure and works with lists
|
||||
|
||||
>>> values = list_generator(["a", "a*b", "b", "c"], conditions=["b%c==1"])
|
||||
>>> values # doctest: +SKIP
|
||||
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
|
||||
"""
|
||||
|
||||
__all__ = ["list_generator"]
|
||||
|
||||
from random import choice
|
||||
from functools import reduce
|
||||
from .leaf import RdLeaf
|
||||
@ -254,35 +244,3 @@ def build_variable_scope(rd_variables, rejected, min_max, variables_scope):
|
||||
except KeyError:
|
||||
complete_scope[v]["min_max"] = min_max
|
||||
return complete_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")
|
||||
:param conditions: condition over variables
|
||||
: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:
|
||||
>>> 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
|
||||
>>> 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)
|
||||
if dictionnary:
|
||||
return generated
|
||||
return [generated[v] for v in var_list]
|
||||
|
Loading…
Reference in New Issue
Block a user