Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: victorlei/smop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: metamorph-inc/smop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Feb 26, 2016

  1. Copy the full SHA
    df0248f View commit details
  2. Compile smop/runtime.pyd

    ksmyth committed Feb 26, 2016
    Copy the full SHA
    d6fdff6 View commit details

Commits on Feb 27, 2016

  1. Use setuptools

    ksmyth committed Feb 27, 2016
    Copy the full SHA
    8a425ea View commit details

Commits on Mar 1, 2016

  1. Upgrade PLY to 3.8

    ksmyth committed Mar 1, 2016
    Copy the full SHA
    6fdd46c View commit details

Commits on Mar 2, 2016

  1. Support nested functions

    ksmyth committed Mar 2, 2016
    Copy the full SHA
    ca1779f View commit details

Commits on May 11, 2016

  1. Copy the full SHA
    4ae96ea View commit details

Commits on May 13, 2016

  1. PEP-440 compliant version

    ksmyth committed May 13, 2016
    Copy the full SHA
    9f6d004 View commit details
  2. cleanup

    ksmyth committed May 13, 2016
    Copy the full SHA
    47c8b7f View commit details
  3. travis and appveyor

    ksmyth committed May 13, 2016
    Copy the full SHA
    c950246 View commit details

Commits on May 17, 2016

  1. Fix slice for 64bit

    ksmyth committed May 17, 2016
    Copy the full SHA
    555221c View commit details
  2. appveyor: add Python27-x64

    ksmyth committed May 17, 2016
    Copy the full SHA
    5828d12 View commit details

Commits on May 18, 2016

  1. Modernize (towards py 3)

    ksmyth committed May 18, 2016
    Copy the full SHA
    b49db5d View commit details

Commits on Sep 29, 2016

  1. gitignore

    ksmyth committed Sep 29, 2016
    Copy the full SHA
    b91f0ce View commit details
  2. Fix import

    ksmyth committed Sep 29, 2016
    Copy the full SHA
    fea61da View commit details

Commits on Nov 20, 2017

  1. Copy the full SHA
    af384fa View commit details

Commits on Nov 21, 2017

  1. Need six

    ksmyth committed Nov 21, 2017
    Copy the full SHA
    bf9aebe View commit details

Commits on Apr 4, 2018

  1. Copy the full SHA
    d1c5a0a View commit details

Commits on May 14, 2018

  1. Copy the full SHA
    59c3fa4 View commit details

Commits on Dec 15, 2021

  1. Remove version wonkiness

    ksmyth committed Dec 15, 2021
    Copy the full SHA
    da4d0d2 View commit details
  2. Python3

    ksmyth committed Dec 15, 2021
    Copy the full SHA
    ba87c29 View commit details

Commits on Dec 16, 2021

  1. numpy 1.12 compat

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    adb4f55 View commit details
  2. numpy 1.15 compat

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    af4308c View commit details
  3. networkx 2 support

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    b262079 View commit details
  4. Python 3 support

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    d1b3e3d View commit details
  5. Copy the full SHA
    7f449ba View commit details
  6. Dont write version.py

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    581ea80 View commit details
  7. Copy the full SHA
    3942f81 View commit details
  8. Build Python39 x64

    ksmyth committed Dec 16, 2021
    Copy the full SHA
    e907dbe View commit details

Commits on Dec 17, 2021

  1. Copy the full SHA
    b79cfb3 View commit details
  2. Copy the full SHA
    ade5e30 View commit details

Commits on Jan 17, 2023

  1. imports first

    ksmyth committed Jan 17, 2023
    Copy the full SHA
    9d88e74 View commit details
  2. Python 3.10 and 3.11

    ksmyth committed Jan 17, 2023
    Copy the full SHA
    ccfbd25 View commit details
  3. Copy the full SHA
    49b7ec0 View commit details
  4. Drop Python 2

    ksmyth committed Jan 17, 2023
    Copy the full SHA
    9bf6295 View commit details

Commits on Jan 20, 2023

  1. Fix version in main.py

    ksmyth committed Jan 20, 2023
    Copy the full SHA
    6da7fc7 View commit details
Showing with 2,454 additions and 1,744 deletions.
  1. +8 −0 .coveragerc
  2. +10 −3 .gitignore
  3. +24 −0 .travis.yml
  4. +38 −0 appveyor.yml
  5. +5 −0 coverage.sh
  6. +12 −0 requirements.txt
  7. +33 −6 setup.py
  8. +7 −3 smop/__init__.py
  9. +20 −18 smop/backend.py
  10. +11 −11 smop/callgraph.py
  11. +93 −23 smop/core.py
  12. +5 −3 smop/go.py
  13. +10 −8 smop/graphviz.py
  14. +461 −419 smop/lex.py
  15. +43 −21 smop/lexer.py
  16. +6 −4 smop/lm.py
  17. +43 −43 smop/main.py
  18. +2 −1 smop/mybench.py
  19. +14 −7 smop/node.py
  20. +107 −52 smop/parse.py
  21. +14 −12 smop/rank.py
  22. +18 −6 smop/recipes.py
  23. +24 −23 smop/resolve.py
  24. +8 −7 smop/rewrite.py
  25. +11 −11 smop/runtime.pyx
  26. +8 −5 smop/sparsearray.py
  27. +20 −10 smop/test_core.py
  28. +51 −39 smop/test_lexer.py
  29. +58 −0 smop/test_lib.py
  30. +2 −1 smop/test_matlabarray.py
  31. +82 −7 smop/test_parse.py
  32. +3 −2 smop/test_sparsearray.py
  33. +18 −14 smop/typeof.py
  34. +1,185 −985 smop/yacc.py
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
plugins = Cython.Coverage
include =
smop*

[report]
include =
smop*
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,9 +3,16 @@
*.swp
a.py
*.egg-info
parser.out
parsetab.py
version.py
/smop/parser.out
/smop/parsetab.py
/smop/lextab.py
dist/
build/
runtime/
.coverage
cover/
venv/
venv_64/
*.pyd
smop/runtime.c
smop/version.py
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: python
sudo: required
dist: trusty
cache: pip
git:
depth: 1000000 # need full history for `git describe`
addons:
apt:
packages:
- libatlas3-base
python:
- "2.7"
install:
- git fetch --tags
- "sed -r 's/^(numpy|scipy).*//' -i requirements.txt"
- "pip install --upgrade https://github.com/metamorph-inc/scipy/releases/download/v0.17.0/numpy-1.11.0-cp27-none-linux_x86_64.whl"
- "pip install --upgrade https://github.com/metamorph-inc/scipy/releases/download/v0.17.0/scipy-0.17.0-cp27-none-linux_x86_64.whl"
- "dpkg -l | grep 'openblas\\|atlas\\|lapack'"
- "update-alternatives --get-selections | grep 'blas\\|lapack'"
- "pip install -r requirements.txt"
- "pip install --no-deps ."
script:
- "python setup.py build_ext --inplace"
- nosetests
38 changes: 38 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
environment:
matrix:
- PYTHON: "C:\\Python39"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON: "C:\\Python39-x64"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON: "C:\\Python310"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON: "C:\\Python310-x64"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON: "C:\\Python311"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- PYTHON: "C:\\Python311-x64"
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
cache:
- '%LOCALAPPDATA%\pip\cache'
install:
- '%PYTHON%\python -m virtualenv venv'
- '.\venv\Scripts\pip install --upgrade -r requirements.txt'
build_script:
- '.\venv\Scripts\python setup.py build_ext --inplace'
- '.\venv\Scripts\python setup.py bdist_wheel'
- sha1sum dist/*.whl
test_script:
- '.\venv\Scripts\nosetests --traverse-namespace smop'
# nosetests.exe --with-coverage --cover-html --traverse-namespace --cover-branches --cover-erase --cover-tests
# coverage html -d cover
artifacts:
- path: 'dist\*.whl'
deploy:
- provider: GitHub
artifact: 'dist\*.whl'
draft: false
prerelease: false
auth_token:
secure: yFXzatuZuCoIHQ1VmlpfLPND2jGU4l1NHkNUfoLXrrTfo5m7VxYJNGiXp7OnpCgp
on:
appveyor_repo_tag: true
5 changes: 5 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
python setup.py build_ext --inplace
nosetests.exe --with-coverage --cover-html --traverse-namespace --cover-branches --cover-erase --cover-tests
coverage html -d cover
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--index-url https://pypi.metamorphsoftware.com/
--extra-index-url https://pypi.python.org/simple
numpy==1.22.4; sys_platform == 'win32'
numpy; sys_platform != 'win32'
scipy==1.8.1; sys_platform == 'win32'
scipy; sys_platform != 'win32'
Cython
six
networkx
coverage
nose-py3; python_version>'3.8'
nose; python_version<='3.8'
39 changes: 33 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from __future__ import absolute_import
import os
import re

from setuptools import setup
from Cython.Build import cythonize
from distutils.extension import Extension

import numpy

# generate lextab.py
import smop.lexer
smop.lexer.new()
import smop.lextab
# generate parsetab.py
import smop.parse
import smop.parsetab

try:
versionstring = os.popen("git describe").read().strip()
open("smop/version.py","w").write("__version__ = '%s'\n" % versionstring)
except:
versionstring = "'0.26'"
versionstring = os.popen("git describe --tags").read().strip()
versionparts = re.match('([^-]+)(?:-(\\d+)-(g[^-]+))?', versionstring).groups()
if versionparts[2]:
versionstring = '{}+{}'.format(versionparts[0], versionparts[2])

setup(
author = 'Victor Leikehman',
@@ -19,9 +33,22 @@
version = versionstring,
entry_points = { 'console_scripts': [ 'smop = smop.main:main', ], },
packages = ['smop'],
zip_safe = True,
#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 = ['numpy', 'scipy', 'networkx', 'six'],
setup_requires = ['numpy', 'six'],

ext_modules = # cythonize(["smop/solver.pyx", include_dirs = [numpy.get_include()],),

cythonize([Extension("smop.runtime",
sources = ["smop/runtime.pyx"],
include_dirs = [numpy.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
),
])
)

# python -c "import smop.solver; import smop.runtime"
10 changes: 7 additions & 3 deletions smop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import absolute_import
# SMOP compiler -- Simple Matlab/Octave to Python compiler
# Copyright 2011-2014 Victor Leikehman

import version
import parse,resolve,backend,main
from version import __version__
import pkg_resources

try:
__version__ = pkg_resources.get_distribution('smop').version
except pkg_resources.DistributionNotFound:
__version__ = 'UNKNOWN'
38 changes: 20 additions & 18 deletions smop/backend.py
Original file line number Diff line number Diff line change
@@ -9,11 +9,13 @@
more than one return value. Otherwise optional.
return value: return (x,y,z)[:nargout] or return x
"""
from __future__ import absolute_import

import logging
logger = logging.getLogger(__name__)
import node,options
from node import extend
import smop.node as node
from . import options
from .node import extend

indent = " "*4

@@ -74,7 +76,7 @@ def _backend(self,level=0):
@extend(node.return_stmt)
def _backend(self,level=0):
if not self.ret:
return "return"
return "return"
else:
return "return %s" % self.ret._backend()

@@ -113,7 +115,7 @@ def _backend(self,level=0):
return "false"
else:
return "true"

# @extend(node.range)
# def _backend(self,level=0):
# i = node.ident.new("I")
@@ -154,7 +156,7 @@ def _backend(self,level=0):
self.args[1]._backend())
if self.op == ":":
return "arange(%s)" % self.args._backend()

if self.op == "end":
# if self.args:
# return "%s.shape[%s]" % (self.args[0]._backend(),
@@ -247,7 +249,7 @@ def _backend(self,level=0):
s = "%s=copy(%s)" % (self.ret._backend(),
self.args._backend())
else:
s = "%s=%s" % (self.ret._backend(),
s = "%s=%s" % (self.ret._backend(),
self.args._backend())
return s

@@ -280,7 +282,7 @@ def _backend(self,level=0):
# if i._rank() == 0:
# return "%s :: %s\n" % (fortran_type[i._type()],
# i)
# return ("%s,DIMENSION(%s),ALLOCATABLE :: %s\n" %
# return ("%s,DIMENSION(%s),ALLOCATABLE :: %s\n" %
# (fortran_type[i._type()],
# ",".join([":" for j in range(i._rank())]), i))
# except:
@@ -290,7 +292,7 @@ def _backend(self,level=0):
s = self.head._backend(level)
t = self.body._backend(level+1)
return "%s%s" % (s,t)


# Sometimes variable names collide with _python reserved
# words and constants. We handle this in the _backend rather than in
@@ -328,9 +330,9 @@ def _backend(self,level=0):
del self.args[-1]
s = ",".join(["%s=None" % a for a in self.args if isinstance(a,node.ident)]+["*args,**kwargs"])
s = "def %s(%s):\n" % (self.ident._backend(), s)
s += ' nargout = kwargs["nargout"] if kwargs else None\n'
s += ' varargin = cellarray(args)\n'
s += " nargin = %d-[%s].count(None)+len(args)\n" % (len(self.args),
s += indent*level + ' nargout = kwargs["nargout"] if kwargs else None\n'
s += indent*level + ' varargin = cellarray(args)\n'
s += indent*level + " nargin = %d-[%s].count(None)+len(args)\n" % (len(self.args),
",".join([(a._backend() if isinstance(a,node.ident) else a.ret._backend())
for a in self.args])) # sic: a.name
return s
@@ -396,7 +398,7 @@ def _backend(self,level=0):
### def _backend(self,level=0):
### return "%s.lower()==%s.lower()" % (self.args[0]._backend(),
### self.args[1]._backend())

### @extend(node.isequal)
### def _backend(self,level=0):
### return "np.array_equal(%s)" % self.args._backend()
@@ -420,7 +422,7 @@ def _backend(self,level=0):
### # self.args[0]._backend())
### # else:
### return "%s.shape" % self.args[0]._backend()
###
###
### if self.args[1].__class__ is node.number:
### return "%s.shape[%s]" % (self.args[0]._backend(),
### self.args[1].value-1)
@@ -437,7 +439,7 @@ def _backend(self,level=0):
### self.args[1].value-1)
### return "np.cumsum(%s,%s-1)" % (self.args[0]._backend(),
### self.args[1]._backend())

@extend(node.dot)
def _backend(self,level=0):
return "%s.dot(%s)" % (self.args[0]._backend(),
@@ -451,12 +453,12 @@ def _backend(self,level=0):
### @exceptions
### def _backend(self,level=0):
### return "open(%s)" % self.args._backend()
###
###
### @extend(node.fclose)
### @exceptions
### def _backend(self,level=0):
### return "%s.close()" % self.args._backend()
###
###
### @extend(node.min)
### @extend(node.max)
### @extend(node.sum)
@@ -465,7 +467,7 @@ def _backend(self,level=0):
### def _backend(self,level=0):
### cls_name = self.__class__.__name__
### return ("np." + cls_name + "(%s)") % self.args._backend()
###
###
### @extend(node.exist)
### @exceptions
### def _backend(self,level=0):
@@ -489,7 +491,7 @@ def _backend(self,level=0):
### @exceptions
### def _backend(self,level=0):
### return "loadmat(%s,matlab_compatible=True)" % self.args._backend()
###
###
### @extend(node.save)
### @exceptions
### def _backend(self,level=0):
22 changes: 11 additions & 11 deletions smop/callgraph.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import parse,sys
from __future__ import absolute_import
from . import parse
import sys
import networkx as nx
import node,resolve
import smop.node as node
import smop.resolve as resolve


def callgraph(func_list):
"""
Build callgraph of func_list, ignoring
built-in functions
"""
"""Build callgraph of func_list, ignoring built-in functions."""
G = nx.DiGraph()
for func in func_list:
G.add_node(func.head.ident.name)
for func in func_list:
assert isinstance(func,node.function)
assert isinstance(func, node.function)
func_name = func.head.ident.name
resolve.resolve(func)
for s in node.postorder(func):
if (s.__class__ is node.funcall and
s.func_expr.__class__ is node.ident and
s.func_expr.__class__ is node.ident and
s.func_expr.name in G.nodes()):
G.add_edge(func_name,s.func_expr.name)
G.add_edge(func_name, s.func_expr.name)
return G

G = nx.DiGraph()

def postorder_edge(u):
if isinstance(u,node.node):
if isinstance(u, node.node):
for v in u:
for t in postorder_edge(v):
yield (v,t)
Loading