From ca48c9c8e2fce8dec18d9f204134e031067bffc6 Mon Sep 17 00:00:00 2001 From: Victor Leikehman Date: Mon, 20 Oct 2014 09:14:17 +0300 Subject: [PATCH] wip --- smop/Makefile | 17 +++++++++++++++-- smop/backend.py | 8 ++++---- smop/main.py | 2 +- smop/mybench.m | 6 +++--- smop/runtime.py | 6 ++++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/smop/Makefile b/smop/Makefile index 7005c2a9..1c9ba5f1 100644 --- a/smop/Makefile +++ b/smop/Makefile @@ -10,8 +10,22 @@ PYTHON = python FLAGS = -X interp1.m,interpn.m,nargchk.m,nargoutchk.m,profexplore.m,profshow.m,quadgk.m,quadl.m V = 2.7 ALL = \*.m +GENERAL = accumarray.py accumdim.py bicubic.py bincoeff.py\ + bitcmp.py bitget.py bitset.py blkdiag.py cart2pol.py cart2sph.py\ + cell2mat.py celldisp.py chop.py circshift.py common_size.py cplxpair.py\ + cumtrapz.py curl.py dblquad.py deal.py del2.py display.py divergence.py\ + fieldnames.py flipdim.py fliplr.py flipud.py gradient.py idivide.py\ + int2str.py interp1.py interp2.py interp3.py interpft.py interpn.py\ + isa.py iscolumn.py isdir.py isequal.py isequaln.py isrow.py isscalar.py\ + issquare.py isvector.py loadobj.py logspace.py methods.py nargchk.py\ + narginchk.py nargoutchk.py nextpow2.py nthargout.py num2str.py pol2cart.py\ + polyarea.py postpad.py prepad.py profexplore.py profile.py profshow.py\ + quadgk.py quadl.py quadv.py randi.py rat.py repmat.py rot90.py rotdim.py\ + saveobj.py shiftdim.py shift.py sortrows.py sph2cart.py structfun.py\ + subsindex.py trapz.py triplequad.py -general: accumarray.py accumdim.py bicubic.py bincoeff.py bitcmp.py bitget.py bitset.py blkdiag.py cart2pol.py cart2sph.py cell2mat.py celldisp.py chop.py circshift.py common_size.py cplxpair.py cumtrapz.py curl.py dblquad.py deal.py del2.py display.py divergence.py fieldnames.py flipdim.py fliplr.py flipud.py gradient.py idivide.py int2str.py interp1.py interp2.py interp3.py interpft.py interpn.py isa.py iscolumn.py isdir.py isequal.py isequaln.py isrow.py isscalar.py issquare.py isvector.py loadobj.py logspace.py methods.py nargchk.py narginchk.py nargoutchk.py nextpow2.py nthargout.py num2str.py pol2cart.py polyarea.py postpad.py prepad.py profexplore.py profile.py profshow.py quadgk.py quadl.py quadv.py randi.py rat.py repmat.py rot90.py rotdim.py saveobj.py shiftdim.py shift.py sortrows.py sph2cart.py structfun.py subsindex.py trapz.py triplequad.py +all: mybench.py runtime.py + $(PYTHON) -c "import mybench ; mybench.mybench()" go_so: solver.so $(PYTHON) go.py @@ -31,7 +45,6 @@ solver.py: solver.m r8_random.m check: $(PYTHON) runtime.py $(PYTHON) test_runtime.py - $(PYTHON) test_matlabarray.py $(PYTHON) test_sparsearray.py $(PYTHON) test_lexer.py diff --git a/smop/backend.py b/smop/backend.py index fe30bf8c..9901f536 100644 --- a/smop/backend.py +++ b/smop/backend.py @@ -96,7 +96,7 @@ def _backend(self,level=0): @extend(node.string) def _backend(self,level=0): - return "char(%s)" % repr(self.value) + return "char('%s')" % (self.value) @extend(node.number) def _backend(self,level=0): @@ -301,15 +301,15 @@ def _backend(self,level=0): except exec execfile exit False file filter finally float for format from frozenset getattr global globals hasattr hash help hex id if import __import__ in input int intern is isinstance issubclass iter lambda len license list - locals long map max memoryview min next None not not NotImplemented object oct + locals long map memoryview next None not not NotImplemented object oct open or ord pass pow print property quit raise range raw_input reduce reload repr return reversed round set setattr slice sorted staticmethod str sum super - True try tuple type unichr unicode vars while with xrange yield zip + True try tuple type unichr unicode vars while with xrange yield zip struct """.split()) @extend(node.ident) def _backend(self,level=0): - return self.name #if self.name not in reserved else "_"+self.name + return self.name if self.name not in reserved else self.name+'_' @extend(node.stmt_list) def _backend(self,level=0): diff --git a/smop/main.py b/smop/main.py index 5a96162c..f6adea4c 100644 --- a/smop/main.py +++ b/smop/main.py @@ -7,7 +7,7 @@ import lexer,parse,resolve,backend,options,node,graphviz import networkx as nx import readline -from runtime import * +#from runtime import * #from version import __version__ __version__ = version.__version__ diff --git a/smop/mybench.m b/smop/mybench.m index a8eddd02..6c719a2f 100644 --- a/smop/mybench.m +++ b/smop/mybench.m @@ -77,7 +77,7 @@ %create output file moVersio = strrep(version(),' ','_'); - outFileName = ['results_',moVersio,'.txt']; + outFileName = "foo.txt" %['results_',moVersio,'.txt']; fid = fopen(outFileName,'w'); if NORMALIZE_TIMES @@ -119,9 +119,9 @@ fprintf(1,'%d ',ii); if IS_OCTAVE, fflush(stdout); end - tic(); + t0=tic(); mytests{i}.test(x); - t1=toc(); + t1=toc(t0); if isfield(mytests{i}, 'goldResult') && NORMALIZE_TIMES == true goldResult = mytests{i}.goldResult; diff --git a/smop/runtime.py b/smop/runtime.py index 54828827..2e702bc0 100644 --- a/smop/runtime.py +++ b/smop/runtime.py @@ -391,7 +391,7 @@ def __str__(self): return "\n".join("".join(s) for s in self) raise NotImplementedError -class struct(object): +class struct_(object): def __init__(self,*args): for i in range(0,len(args),2): setattr(self,str(args[i]),args[i+1]) @@ -491,7 +491,9 @@ def fflush(fp): fp.flush() def fprintf(fp,fmt,*args): - print str(fmt) % tuple(str(a) if isinstance(a,char) else a for a in args) + if not isinstance(fp,file): + fp = stdout + fp.write(str(fmt) % tuple(str(a) if isinstance(a,char) else a for a in args)) def fullfile(*args): return os.path.join(*args)