From aaf706fcff3922b478f5eaf818745aec12afc775 Mon Sep 17 00:00:00 2001 From: Victor Lei Date: Sun, 14 Aug 2016 20:36:55 +0300 Subject: [PATCH] New: support for boolean ops --- .gitignore | 1 - setup.py | 10 +++------- smop/backend.py | 13 ++++++++++++- smop/core.py | 12 ++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index e23f6cf0..20fa5360 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ a.py *.egg-info parser.out parsetab.py -version.py dist/ build/ runtime/ diff --git a/setup.py b/setup.py index a2327015..cd5fbeae 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,7 @@ import os from setuptools import setup -try: - versionstring = os.popen("git describe").read().strip() - open("smop/version.py","w").write("__version__ = '%s'\n" % versionstring) -except: - versionstring = "'0.26'" +from smop.version import __version__ setup( author = 'Victor Leikehman', @@ -16,12 +12,12 @@ url = 'https://github.com/victorlei/smop', download_url = 'https://github.com/victorlei/smop/archive/master.zip', name = 'smop', - version = versionstring, + version = __version__, entry_points = { 'console_scripts': [ 'smop = smop.main:main', ], }, packages = ['smop'], #package_dir = {'':'src'}, #test_suite = "smop.testsuite.test_lexer", #include_package_data = True, #package_data = { 'smop': ['*.m', 'Makefile'], }, - install_requires = ['numpy', 'scipy', 'networkx'], + install_requires = ['ply', 'numpy', 'scipy', 'networkx', 'pygraphviz'], ) diff --git a/smop/backend.py b/smop/backend.py index 7c8a8b31..ac143381 100644 --- a/smop/backend.py +++ b/smop/backend.py @@ -125,7 +125,18 @@ def _backend(self,level=0): @extend(node.expr) def _backend(self,level=0): - if self.op == '@': # FIXME + if self.op in ("!","not"): # ??? + return "not %s" % self.args[0] + if self.op in ("&","and"): + return "logical_and(%s)" % self.args._backend() + if self.op == "&&": + return " and ".join(t._backend() for t in self.args) + if self.op in ("|","or"): + return "logical_or(%s)" % self.args._backend() + if self.op == "||": + return " or ".join(t._backend() for t in self.args) + + if self.op == '@': # FIXMEj return self.args[0]._backend() if self.op == "\\": diff --git a/smop/core.py b/smop/core.py index 7c26b95c..1b6f5990 100644 --- a/smop/core.py +++ b/smop/core.py @@ -352,6 +352,9 @@ def abs(a): def all(a): return numpy.all(a) +def any(a): + return numpy.any(a) + def arange(start,stop,step=1,**kwargs): """ >>> a=arange(1,10) # 1:10 @@ -390,6 +393,15 @@ def eig(a): u,v = np.linalg.eig(a) return u.T +def logical_not(a): + return numpy.logical_not(a) + +def logical_and(a,b): + return numpy.logical_and(a,b) + +def logical_or(a,b): + return numpy.logical_or(a,b) + def exist(a,b): if str(b) == 'builtin': return str(a) in globals()