Skip to content

aliskhakov/redbeaver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redbeaver

Build Status

Installation

Download the source and run

$ python setup.py install

or install the latest stable release with

$ pip install redbeaver

Usage

Adding functions to Formula

from redbeaver.formula import Formula
f = Formula()
print f
{'fn_registry': {}, 'num_registry': {}, 'param_registry': {}}
@f(1)
def a(b, c):
    return b + c
print f
{'fn_registry': {'a': (('args', ['b', 'c']), ('src', ([u'@f4(1)\n', u'def a(b, c):\n', u'    return b + c\n'], 1)), ('call', <function wrapped_fn at 0x10fb28ed8>))}, 'num_registry': {1: <function wrapped_fn at 0x10fb28ed8>}, 'param_registry': {}}
@f(2)
def b(c):
    return 2 * c
print f
{'fn_registry': {'a': (('args', ['b', 'c']), ('src', ([u'@f4(1)\n', u'def a(b, c):\n', u'    return b + c\n'], 1)), ('call', <function wrapped_fn at 0x10fb28ed8>)), 'b': (('args', ['c']), ('src', ([u'@f4(2)\n', u'def b(c):\n', u'    return 2 * c\n'], 1)), ('call', <function wrapped_fn at 0x10fab9ed8>))}, 'num_registry': {1: <function wrapped_fn at 0x10fb28ed8>, 2: <function wrapped_fn at 0x10fab9ed8>}, 'param_registry': {}}
f(2)
<function __main__.wrapped_fn>
f('b')
(('args', ['c']),
 ('src', ([u'@f4(2)\n', u'def b(c):\n', u'    return 2 * c\n'], 1)),
 ('call', <function __main__.wrapped_fn>))
f('a')
(('args', ['b', 'c']),
 ('src', ([u'@f4(1)\n', u'def a(b, c):\n', u'    return b + c\n'], 1)),
 ('call', <function __main__.wrapped_fn>))

Parameters setting

f({'c': 5, 'd': 7})
f.get_params()
{'c': 5, 'd': 7}
f('c')
5

Formula calculation

from redbeaver.calc import Calc
calc = Calc(f)
calc('a')
15
f.get_params()
{'a': 15, 'b': 10, 'c': 5, 'd': 7}

Working with iterable params

f = Formula
calc = Calc(f)
@f(1)                                               
def a(b):                                           
    return b * 2                                    
@f(2)                                               
def b(c):                                           
    return c * 2                                    
f({'c': range(5)})                                  
calc('a', iterate_param='c')
[0, 4, 8, 12, 16]
f.get_params()
{'a': [0, 4, 8, 12, 16], 'c': [0, 1, 2, 3, 4], 'b': [0, 2, 4, 6, 8]}

Reset params

f.reset_params()
f.get_params()
{}

License

Apache License 2.0

About

Registry and solver of mathematical equations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages