Skip to content

Commit

Permalink
Initial commit for selections v3
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Feb 10, 2018
0 parents commit 88462bf
Show file tree
Hide file tree
Showing 11 changed files with 815 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
25 changes: 25 additions & 0 deletions selections/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from pyparsing import ParserElement

from .backends import from_numexpr, to_numexpr
from .backends import from_root, to_root
from .expression import Expression
from .parser import ParsingException


__all__ = [
'Expression',
'ParsingException',
# numexpr
'from_numexpr',
'to_numexpr',
# ROOT
'from_root',
'to_root',
]


ParserElement.enablePackrat()
53 changes: 53 additions & 0 deletions selections/backends/ROOT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from ..identifiers import IDs
from ..parser import Operator, Function, Parser


__all__ = [
'root_parser',
]


config = [
Operator(IDs.MINUS, '-', rhs_only=True),
Operator(IDs.PLUS, '+', rhs_only=True),
Operator(IDs.ADD, '+'),
Operator(IDs.SUB, '-'),
Operator(IDs.MUL, '*'),
Operator(IDs.DIV, '/'),

Function(IDs.SQRT, 'sqrt'),
Function(IDs.SQRT, 'TMath::Sqrt'),
Function(IDs.ABS, 'TMath::Abs'),

Function(IDs.LOG, 'log'),
Function(IDs.LOG, 'TMath::Log'),
Function(IDs.LOG2, 'log2'),
Function(IDs.LOG2, 'TMath::Log2'),
Function(IDs.LOG10, 'log10'),
Function(IDs.LOG10, 'TMath::Log10'),

Function(IDs.EXP, 'exp'),
Function(IDs.EXP, 'TMath::Exp'),

Function(IDs.SIN, 'sin'),
Function(IDs.SIN, 'TMath::Sin'),
Function(IDs.ASIN, 'arcsin'),
Function(IDs.ASIN, 'TMath::ASin'),
Function(IDs.COS, 'cos'),
Function(IDs.COS, 'TMath::Cos'),
Function(IDs.ACOS, 'arccos'),
Function(IDs.ACOS, 'TMath::ACos'),
Function(IDs.TAN, 'tan'),
Function(IDs.TAN, 'TMath::Tan'),
Function(IDs.ATAN, 'arctan'),
Function(IDs.ATAN, 'TMath::ATan'),
Function(IDs.ATAN2, 'arctan2', 2),
Function(IDs.ATAN2, 'TMath::ATan2', 2),
]


root_parser = Parser('ROOT', config)
20 changes: 20 additions & 0 deletions selections/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from .numexpr import numexpr_parser
from .ROOT import root_parser


__all__ = [
'from_numexpr',
'to_numexpr',
'from_root',
'to_root',
]

from_numexpr = numexpr_parser.to_expression
to_numexpr = numexpr_parser.to_string

from_root = root_parser.to_expression
to_root = root_parser.to_string
50 changes: 50 additions & 0 deletions selections/backends/numexpr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from ..identifiers import IDs
from ..parser import Operator, Function, Parser


__all__ = [
'numexpr_parser',
]


config = [
Operator(IDs.MINUS, '-', rhs_only=True),
Operator(IDs.PLUS, '+', rhs_only=True),
Operator(IDs.ADD, '+'),
Operator(IDs.SUB, '-'),
Operator(IDs.MUL, '*'),
Operator(IDs.DIV, '/'),

Function(IDs.SQRT, 'sqrt'),
Function(IDs.ABS, 'abs'),
Function(IDs.WHERE, 'where', 3),

Function(IDs.LOG, 'log'),
Function(IDs.LOG10, 'log10'),
Function(IDs.LOG1p, 'log1p'),

Function(IDs.EXP, 'exp'),
Function(IDs.EXPM1, 'expm1'),

Function(IDs.SIN, 'sin'),
Function(IDs.ASIN, 'arcsin'),
Function(IDs.COS, 'cos'),
Function(IDs.ACOS, 'arccos'),
Function(IDs.TAN, 'tan'),
Function(IDs.ATAN, 'arctan'),
Function(IDs.ATAN2, 'arctan2', 2),

Function(IDs.SINH, 'sinh'),
Function(IDs.ASINH, 'arcsinh'),
Function(IDs.COSH, 'cosh'),
Function(IDs.ACOSH, 'arccosh'),
Function(IDs.TANH, 'tanh'),
Function(IDs.ATANH, 'arctanh'),
]


numexpr_parser = Parser('numexpr', config)
Loading

0 comments on commit 88462bf

Please sign in to comment.