Compare commits
38 Commits
master
...
fadd93b9a6
| Author | SHA1 | Date | |
|---|---|---|---|
| fadd93b9a6 | |||
| cb8010c7ac | |||
| f12ec38746 | |||
| f8b24472d1 | |||
| 240857a7ad | |||
| 70ec6933ac | |||
| 91779bd945 | |||
| 69e1e43966 | |||
| 16a6c4953d | |||
| 84c71f6b5d | |||
| 2a74722b19 | |||
| 43fd46379c | |||
| 2d296cf1d2 | |||
| 12109156d1 | |||
| 2fad004d6d | |||
| 207dead5d0 | |||
| e24bff23db | |||
| 69c2b3718d | |||
| 9c25142a4b | |||
| 931e55c35e | |||
| aba43c9f19 | |||
| b93f34bc38 | |||
| 204fdf755b | |||
| d75fd4c4cf | |||
| a32b684b6b | |||
| a5f062a151 | |||
| f8e1c7f962 | |||
| 1685c73051 | |||
| 04ac74d17a | |||
| 23ab39f7d4 | |||
| 41385ec561 | |||
| 8389a319f0 | |||
| 6e24756746 | |||
| d45ab560c9 | |||
| fa8beb6bb2 | |||
| b81281d78a | |||
| 071b8caf1d | |||
| 1ed0b9715a |
18
.drone.yml
18
.drone.yml
@@ -1,18 +0,0 @@
|
|||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: testing
|
|
||||||
image: python
|
|
||||||
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,5 +1,4 @@
|
|||||||
# Mapytex
|
# Mapytex
|
||||||
[](https://drone.opytex.org/lafrite/Mapytex)
|
|
||||||
|
|
||||||
Formal calculus with explanation python module and exercises creation tools.
|
Formal calculus with explanation python module and exercises creation tools.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from .calculus import Expression, Integer, Decimal, random_list
|
from .calculus import Expression, Integer, Decimal
|
||||||
|
|
||||||
# Expression.set_render('tex')
|
# Expression.set_render('tex')
|
||||||
|
|
||||||
|
|||||||
@@ -136,11 +136,9 @@ class Expression(object):
|
|||||||
:returns: TODO
|
:returns: TODO
|
||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> e = Expression.random("{a}/{a*k}")
|
>>> Expression.random("{a}/{a*k}") # doctest: +SKIP
|
||||||
>>> e # doctest: +SKIP
|
|
||||||
<Exp: -3 / -15>
|
<Exp: -3 / -15>
|
||||||
>>> e = Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}})
|
>>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest: +SKIP
|
||||||
>>> e # doctest: +SKIP
|
|
||||||
<Exp: 18 / 108 - 3 * 9>
|
<Exp: 18 / 108 - 3 * 9>
|
||||||
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
|
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
|
||||||
>>> ee = e.simplify()
|
>>> 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 .API import Expression, Integer, Decimal
|
||||||
from .core import random_list
|
|
||||||
from decimal import getcontext
|
from decimal import getcontext
|
||||||
#getcontext().prec = 2
|
#getcontext().prec = 2
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ from .tree import Tree, AssocialTree
|
|||||||
from .compute import compute
|
from .compute import compute
|
||||||
from .typing import typing, TypingError
|
from .typing import typing, TypingError
|
||||||
from .renders import tree2txt, tree2tex
|
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
|
>>> leafs
|
||||||
['a', 'a*k']
|
['a', 'a*k']
|
||||||
>>> rd_varia = extract_rv(leafs)
|
>>> rd_varia = extract_rv(leafs)
|
||||||
>>> sorted(list(rd_varia))
|
>>> rd_varia # doctest: +SKIP
|
||||||
['a', 'k']
|
{'a', 'k'}
|
||||||
>>> generated = random_generator(rd_varia, conditions=['a%2+1'])
|
>>> generated = random_generator(rd_varia, conditions=['a%2+1'])
|
||||||
>>> generated # doctest: +SKIP
|
>>> generated # doctest: +SKIP
|
||||||
{'a': 7, 'k': 4}
|
{'a': 7, 'k': 4}
|
||||||
@@ -61,18 +61,8 @@ Tree with RdLeaf replaced by generated values
|
|||||||
> 7
|
> 7
|
||||||
> 28
|
> 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 random import choice
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from .leaf import RdLeaf
|
from .leaf import RdLeaf
|
||||||
@@ -254,35 +244,3 @@ def build_variable_scope(rd_variables, rejected, min_max, variables_scope):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
complete_scope[v]["min_max"] = min_max
|
complete_scope[v]["min_max"] = min_max
|
||||||
return complete_scope
|
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]
|
|
||||||
|
|||||||
@@ -23,18 +23,12 @@ def random_generator(
|
|||||||
:param v_max: maximum accepted value
|
:param v_max: maximum accepted value
|
||||||
:param exact_mean: if set, the last generated number will be create in order that the computed mean is exacly equal to "exact_mean"
|
:param exact_mean: if set, the last generated number will be create in order that the computed mean is exacly equal to "exact_mean"
|
||||||
|
|
||||||
>>> random_generator(10) # doctest: +SKIP
|
>>> random_generator(10)
|
||||||
[-0.76, 0.46, 0.19, 0.08, -1.13, -0.5, 0.47, -2.11, 0.16, -1.05]
|
>>> random_generator(10, distrib = uniform, rd_args = (5, 10))
|
||||||
>>> random_generator(10, distrib = uniform, rd_args = (5, 10)) # doctest: +SKIP
|
>>> random_generator(10, distrib = "uniform", rd_args = (5, 10))
|
||||||
[9.01, 5.32, 5.59, 8.8, 7.36, 6.9, 6.05, 7.44, 9.47, 6.95]
|
>>> random_generator(10, v_min = 0)
|
||||||
>>> random_generator(10, distrib = "uniform", rd_args = (5, 10)) # doctest: +SKIP
|
>>> random_generator(10, exact_mean = 0)
|
||||||
[7.85, 9.01, 5.32, 5.59, 8.8, 7.36, 6.9, 6.05, 7.44, 9.47]
|
>>> random_generator(10, distrib = gauss, rd_args = (50,20), nbr_format = int)
|
||||||
>>> random_generator(10, v_min = 0) # doctest: +SKIP
|
|
||||||
[0.46, 0.19, 0.08, 0.47, 0.16, 0.87, 0.17, 1.79, 0.19, 1.12]
|
|
||||||
>>> random_generator(10, exact_mean = 0) # doctest: +SKIP
|
|
||||||
[-0.76, 0.46, 0.19, 0.08, -1.13, -0.5, 0.47, -2.11, 0.16, 3.14]
|
|
||||||
>>> random_generator(10, distrib = gauss, rd_args = (50,20), nbr_format = int) # doctest: +SKIP
|
|
||||||
[34, 59, 53, 51, 27, 40, 59, 7, 53, 28]
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# if exact_mean is set, we create automaticaly only length-1 value
|
# if exact_mean is set, we create automaticaly only length-1 value
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -7,7 +7,7 @@ except ImportError:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="mapytex",
|
name="mapytex",
|
||||||
version="2.3.2",
|
version="2.1",
|
||||||
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",
|
||||||
|
|||||||
Reference in New Issue
Block a user