Skip to content

Commit

Permalink
New: support for boolean ops
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Aug 14, 2016
1 parent f0ec4e4 commit aaf706f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ a.py
*.egg-info
parser.out
parsetab.py
version.py
dist/
build/
runtime/
10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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'],
)
13 changes: 12 additions & 1 deletion smop/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "\\":
Expand Down
12 changes: 12 additions & 0 deletions smop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit aaf706f

Please sign in to comment.