From ed0d004b35df0e1f894ba901dfc953537780784f Mon Sep 17 00:00:00 2001 From: Victor Leikehman Date: Sun, 19 Oct 2014 10:00:00 +0300 Subject: [PATCH] Removed trailing underlines --- smop/backend.py | 23 ++++++++--- smop/go.py | 6 +-- smop/main.py | 16 ++++++-- smop/resolve.py | 10 ++--- smop/runtime.py | 86 ++++++++++++++++++++-------------------- smop/test_matlabarray.py | 28 ++++++------- smop/test_runtime.py | 68 +++++++++++++++---------------- smop/test_sparsearray.py | 74 +++++++++++++++++----------------- 8 files changed, 166 insertions(+), 145 deletions(-) diff --git a/smop/backend.py b/smop/backend.py index 7178c963..bd9f99c5 100644 --- a/smop/backend.py +++ b/smop/backend.py @@ -150,7 +150,7 @@ def _backend(self,level=0): self.args[2]._backend(), self.args[1]._backend()) if self.op == ":": - return "arange_(%s)" % self.args._backend() + return "arange(%s)" % self.args._backend() if self.op == "end": # if self.args: @@ -160,11 +160,12 @@ def _backend(self,level=0): return "end()" if self.op == ".": + #import pdb; pdb.set_trace() try: - is_parens = self.args[1].op != "parens" + is_parens = self.args[1].op == "parens" except: is_parens = False - if is_parens: + if not is_parens: return "%s%s" % (self.args[0]._backend(), self.args[1]._backend()) else: @@ -228,9 +229,19 @@ def _backend(self,level=0): # s = '' #if self.args.__class__ is node.funcall: # self.args.nargout = self.nargout - if (self.ret.__class__ is node.ident and + if self.ret.__class__ is node.expr and self.ret.op == "." : + try: + if self.ret.args[1].op == 'parens': + s = "setattr(%s,%s,%s)" % (self.ret.args[0]._backend(), + self.ret.args[1].args[0]._backend(), + self.args._backend()) + except: + s = "%s%s = copy(%s)" % (self.ret.args[0]._backend(), + self.ret.args[1]._backend(), + self.args._backend()) + elif (self.ret.__class__ is node.ident and self.args.__class__ is node.ident): - s = "%s=copy_(%s)" % (self.ret._backend(), + s = "%s=copy(%s)" % (self.ret._backend(), self.args._backend()) else: s = "%s=%s" % (self.ret._backend(), @@ -298,7 +309,7 @@ def _backend(self,level=0): @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/go.py b/smop/go.py index 2b4dfdb8..a5235a32 100644 --- a/smop/go.py +++ b/smop/go.py @@ -4,8 +4,8 @@ from runtime import * def main(): - ai = matlabarray(zeros_(10,10,dtype=int),dtype=int) - af = copy_(ai) + ai = matlabarray(zeros (10,10,dtype=int),dtype=int) + af = copy(ai) ai[1,1]=2 ai[2,2]=3 @@ -20,7 +20,7 @@ def main(): af[10,10]=5 t0 = time.clock() - mv = a.solver_(ai,af,0) + mv = a.solver(ai,af,0) t1 = time.clock() print t1-t0 print mv.shape diff --git a/smop/main.py b/smop/main.py index 4999d5d2..5a96162c 100644 --- a/smop/main.py +++ b/smop/main.py @@ -7,6 +7,7 @@ import lexer,parse,resolve,backend,options,node,graphviz import networkx as nx import readline +from runtime import * #from version import __version__ __version__ = version.__version__ @@ -101,7 +102,7 @@ def main(): print "? for help" while 1: try: - buf = raw_input("=>> ") + buf = raw_input("octave: ") if not buf: continue while buf[-1] == "\\": @@ -118,9 +119,18 @@ def main(): t = parse.parse(buf if buf[-1]=='\n' else buf+'\n') if not t: continue + print "t=", repr(t) + print 60*"-" resolve.resolve(t,symtab) - _ = backend.backend(t) - exec _ + print "t=", repr(t) + print 60*"-" + print "symtab:",symtab + s = backend.backend(t) + print "python:",s.strip() + try: + print eval(s) + except SyntaxError: + exec s except EOFError: return except Exception as ex: diff --git a/smop/resolve.py b/smop/resolve.py index 7c209d94..d049478f 100644 --- a/smop/resolve.py +++ b/smop/resolve.py @@ -80,14 +80,14 @@ def resolve(t, symtab=None, fp=None, func_name=None): G.node[n]["label"] = "%s\\n%s" % (n, u.props) for u in node.postorder(t): - if u.__class__ is node.func_decl: - u.ident.name += "_" - elif u.__class__ is node.funcall: + #if u.__class__ is node.func_decl: + # u.ident.name += "_" + if u.__class__ is node.funcall: try: if u.func_expr.props in "UR": # upd,ref u.__class__ = node.arrayref - else: - u.func_expr.name += "_" + #else: + # u.func_expr.name += "_" except: pass diff --git a/smop/runtime.py b/smop/runtime.py index a0b5af41..9c920c84 100644 --- a/smop/runtime.py +++ b/smop/runtime.py @@ -381,17 +381,17 @@ def __str__(self): raise NotImplementedError -def abs_(a): +def abs(a): """ Unless the argument is already as subclass of ndarray, convert the argument to ndarray, then apply numpy.abs """ return np.abs(np.asanyarray(a)) -def arange_(start,stop,step=1,**kwargs): +def arange(start,stop,step=1,**kwargs): """ - >>> a=arange_(1,10) # 1:10 - >>> size_(a) + >>> a=arange(1,10) # 1:10 + >>> size(a) matlabarray([[ 1, 10]]) """ return matlabarray(np.arange(start, @@ -399,32 +399,32 @@ def arange_(start,stop,step=1,**kwargs): step, **kwargs).reshape(1,-1),**kwargs) -def ceil_(a): +def ceil(a): """ Unless the argument is already as subclass of ndarray, convert the argument to ndarray, then apply numpy.ceil """ return np.ceil(np.asanyarray(a)) -def cell_(*args): +def cell(*args): if len(args) == 1: args += args return cellarray(np.zeros(args,dtype=object,order="F")) -def copy_(a): +def copy(a): return matlabarray(np.asanyarray(a).copy(order="F")) -def disp_(*args): +def disp(*args): print (args) false = False -def false_(*args): +def false(*args): if len(args) == 1: args += args return np.zeros(args,dtype=bool,order="F") -def find_(a,n=None,d=None,nargout=1): +def find(a,n=None,d=None,nargout=1): if d: raise NotImplementedError @@ -446,10 +446,10 @@ def find_(a,n=None,d=None,nargout=1): matlabarray((j+1).reshape(-1,1))) raise NotImplementedError -def floor_(a): - return np.floor_(np.asanyarray(a)) +def floor(a): + return np.floor(np.asanyarray(a)) -def fopen_(*args): +def fopen(*args): try: fp = open(*args) assert fp != -1 @@ -457,10 +457,10 @@ def fopen_(*args): except: return -1 -def fullfile_(*args): +def fullfile(*args): return os.path.join(*args) -def intersect_(a,b,nargout=1): +def intersect(a,b,nargout=1): if nargout == 1: c = sorted(set(a) & set(b)) if isinstance(a,str): @@ -473,40 +473,40 @@ def intersect_(a,b,nargout=1): return np.array(c) raise NotImplementedError -#def inf_(*args): +#def inf(*args): # t = np.empty(np.prod(args)) # t[:] = np.inf # return t.reshape(args) # #Inf_ = inf_ # -#def int_(t): +#def int(t): # return np.int(t) # -#def int32_(t): +#def int32(t): # return np.int(t) # -def iscellstr_(a): +def iscellstr(a): return isinstance(a,cellarray) and all(isinstance(t,str) for t in a) -def ischar_(a): +def ischar(a): try: return a.dtype == "|S1" except AttributeError: return False -def isempty_(a): +def isempty(a): try: return 0 in np.asarray(a).shape except AttributeError: return False -def isequal_(a,b): +def isequal(a,b): return np.array_equal(np.asanyarray(a), np.asanyarray(b)) -def isscalar_(a): +def isscalar(a): """np.isscalar returns True if a.__class__ is a scalar type (i.e., int, and also immutable containers str and tuple, but not list.) Our requirements are different""" @@ -515,47 +515,47 @@ def isscalar_(a): except AttributeError: return np.isscalar(a) -def length_(a): +def length(a): try: return max(np.asarray(a).shape) except ValueError: return 1 try: - def load_(a): + def load(a): return loadmat(a) # FIXME except: pass -def max_(a, d=0, nargout=0): +def max(a, d=0, nargout=0): if d or nargout: raise NotImplementedError return np.amax(a) -def min_(a, d=0, nargout=0): +def min(a, d=0, nargout=0): if d or nargout: raise NotImplementedError return np.amin(a) -def mod_(a,b): +def mod(a,b): try: return a % b except ZeroDivisionError: return a -def ndims_(a): +def ndims(a): return np.asarray(a).ndim -def numel_(a): +def numel(a): return np.asarray(a).size -def ones_(*args,**kwargs): +def ones(*args,**kwargs): if not args: return 1.0 if len(args) == 1: args += args return matlabarray(np.ones(args,order="F",**kwargs)) -def rand_(*args,**kwargs): +def rand(*args,**kwargs): if not args: return np.random.rand() if len(args) == 1: @@ -565,18 +565,18 @@ def rand_(*args,**kwargs): except: pass -def ravel_(a): +def ravel(a): return np.asanyarray(a).reshape(-1,1) -def round_(a): +def round(a): return np.round(np.asanyarray(a)) -def rows_(a): +def rows(a): return np.asarray(a).shape[0] -def size_(a, b=0, nargout=1): +def size(a, b=0, nargout=1): """ - >>> size_(zeros_(3,3)) + 1 + >>> size(zeros(3,3)) + 1 matlabarray([[4, 4]]) """ s = np.asarray(a).shape @@ -591,34 +591,34 @@ def size_(a, b=0, nargout=1): except IndexError: return 1 -def strread_(s, format="", nargout=1): +def strread(s, format="", nargout=1): if format == "": a = [float(x) for x in s.split()] return tuple(a) if nargout > 1 else np.asanyarray([a]) raise NotImplementedError -def strrep_(a,b,c): +def strrep(a,b,c): if isinstance(a,str): return a.replace(b,c) raise NotImplementedError # cell arrays -def sum_(a, dim=None): +def sum(a, dim=None): if dim is None: return np.asanyarray(a).sum() else: return np.asanyarray(a).sum(dim-1) -def toupper_(a): +def toupper(a): return char(str(a.data).upper()) true = True -def true_(*args): +def true(*args): if len(args) == 1: args += args return matlabarray(np.ones(args,dtype=bool,order="F")) -def zeros_(*args,**kwargs): +def zeros(*args,**kwargs): if not args: return 0.0 if len(args) == 1: diff --git a/smop/test_matlabarray.py b/smop/test_matlabarray.py index df4c915d..8ae1d0ea 100644 --- a/smop/test_matlabarray.py +++ b/smop/test_matlabarray.py @@ -9,7 +9,7 @@ def test010(self): a[a.shape[0]+1,[1,2,3]] = [123,456,789] a[a.shape[0]+1,[1,2,3]] = [123,456,789] a[a.shape[0]+1,[1,2,3]] = [123,456,789] - self.assertTrue(isequal_(a, [[123,456,789], + self.assertTrue(isequal (a, [[123,456,789], [123,456,789], [123,456,789]])) def test020(self): @@ -19,7 +19,7 @@ def test020(self): a[a.shape[0]+1,[1,2,3]] = 123 a[a.shape[0]+1,[1,2,3]] = 123 a[a.shape[0]+1,[1,2,3]] = 123 - self.assertTrue(isequal_(a, [[123,123,123], + self.assertTrue(isequal (a, [[123,123,123], [123,123,123], [123,123,123]])) @@ -32,7 +32,7 @@ def test030(self): a[a.shape[0]+1,1:3] = 123 a[a.shape[0]+1,1:3] = 123 #print a.shape - self.assertTrue(isequal_(a, [[123,123,123], + self.assertTrue(isequal (a, [[123,123,123], [123,123,123], [123,123,123]])) #@unittest.skip("FIXME") @@ -42,7 +42,7 @@ def test040(self): a[a.shape[0]+1,:] = 123 a[a.shape[0]+1,:] = 123 a[a.shape[0]+1,:] = 123 - self.assertTrue(isequal_(a, [[123], + self.assertTrue(isequal (a, [[123], [123], [123]])) @unittest.skip("wonders of matlab") @@ -63,7 +63,7 @@ def test050(self): """ a = matlabarray() a[:,:] = 99 - self.assertTrue(isequal_(a.item(0), 99)) + self.assertTrue(isequal (a.item(0), 99)) def test060(self): """One-dimensional assignment to empty array @@ -78,7 +78,7 @@ def test060(self): a = matlabarray() with self.assertRaises(IndexError): a[:] = 99 - self.assertTrue(isempty_(a)) + self.assertTrue(isempty (a)) #@unittest.skip("wonders of matlab") def test062(self): @@ -104,7 +104,7 @@ def test064(self): """ a = matlabarray() a[1:3] = [1,2,3] - self.assertTrue(isequal_(a, [1,2,3])) + self.assertTrue(isequal (a, [1,2,3])) def test070(self): """ @@ -117,7 +117,7 @@ def test070(self): """ a = matlabarray() a[1:a.shape[0]] = 9 - self.assertTrue(isempty_(a)) + self.assertTrue(isempty (a)) @unittest.skip("wonders of matlab") def test080(self): @@ -141,31 +141,31 @@ def test084(self): def test090(self): a = matlabarray([[11,22,33]]) a[4] = 44 - self.assertTrue(isequal_(a,[[11,22,33,44]])) + self.assertTrue(isequal (a,[[11,22,33,44]])) def test092(self): a = matlabarray([[11,22,33,44]]) a[5:7] = [55,66,77] - self.assertTrue(isequal_(a,[[11,22,33,44,55,66,77]])) + self.assertTrue(isequal (a,[[11,22,33,44,55,66,77]])) def test094(self): a = matlabarray([[11,22,33,44,55,66,77]]) a[[8,9]] = [88,99] - self.assertTrue(isequal_(a,[[11,22,33,44,55,66,77,88,99]])) + self.assertTrue(isequal (a,[[11,22,33,44,55,66,77,88,99]])) def test100(self): a = matlabarray([[1,3], [2,4]]) #a[: , a.shape[1]+1] = [5,6] a[: , 3] = [5,6] - self.assertTrue(isequal_(a,[[1,3,5], + self.assertTrue(isequal (a,[[1,3,5], [2,4,6]])) def test110(self): - a = zeros_(4,4,dtype=int) + a = zeros (4,4,dtype=int) a[2:3,2:3] = 1 #print a - self.assertTrue(isequal_(a,[[0,0,0,0], + self.assertTrue(isequal (a,[[0,0,0,0], [0,1,1,0], [0,1,1,0], [0,0,0,0]])) diff --git a/smop/test_runtime.py b/smop/test_runtime.py index 6ff4b746..9050bdd4 100644 --- a/smop/test_runtime.py +++ b/smop/test_runtime.py @@ -8,7 +8,7 @@ class Getitem(unittest.TestCase): def setUp(self): - self.a = matlabarray(arange_(1,20).reshape(4,5,order="F")) + self.a = matlabarray(arange(1,20).reshape(4,5,order="F")) # 2-dim def test01(self): self.assertEqual(self.a[1,1],1) @@ -17,14 +17,14 @@ def test02(self): self.assertEqual(self.a[4,5],20) def test03(self): - self.assertTrue(isequal_(self.a[:,:],self.a)) + self.assertTrue(isequal(self.a[:,:],self.a)) # 1-dim def test04(self): - a = matlabarray(arange_(1,20).reshape(4,5,order="F")) + a = matlabarray(arange(1,20).reshape(4,5,order="F")) aa = a[:] - bb = matlabarray(arange_(1,20).reshape(-1,1,order="F")) - self.assertTrue(isequal_(aa,bb)) + bb = matlabarray(arange(1,20).reshape(-1,1,order="F")) + self.assertTrue(isequal(aa,bb)) def test05(self): #import pdb; pdb.set_trace() @@ -33,43 +33,43 @@ def test05(self): [11,22,33,44], [11,22,33,44]] a = matlabarray([11,22,33,44], dtype=int) - self.assertTrue(isequal_(a[ [1,1,1,1] , 1:4], matlabarray(z))) - self.assertTrue(isequal_(a[ [1,1,1,1], : ], matlabarray(z))) - #self.assertTrue(isequal_(a[ [[1,1,1,1]], 1:4], matlabarray([z]))) + self.assertTrue(isequal(a[ [1,1,1,1] , 1:4], matlabarray(z))) + self.assertTrue(isequal(a[ [1,1,1,1], : ], matlabarray(z))) + #self.assertTrue(isequal(a[ [[1,1,1,1]], 1:4], matlabarray([z]))) def test06(self): - a=copy_(0) + a=copy(0) a[6]=666 - self.assertTrue(isequal_(a, [[0.,0.,0.,0.,0.,666.]])) + self.assertTrue(isequal(a, [[0.,0.,0.,0.,0.,666.]])) class Expand(unittest.TestCase): """ Expand on index error """ def setUp(self): - self.a = matlabarray(zeros_(1,4)) + self.a = matlabarray(zeros(1,4)) def test01(self): self.a[1,5]=1 - self.assertTrue(isequal_(self.a, + self.assertTrue(isequal(self.a, matlabarray([[0,0,0,0,1]]))) def test02(self): #with self.assertRaises(IndexError): - a = matlabarray(zeros_(1,4)) + a = matlabarray(zeros(1,4)) a[5]=1 # single index - self.assertTrue(isequal_(a, + self.assertTrue(isequal(a, matlabarray([[0,0,0,0,1]]))) #@unittest.skip("") def test03(self): - a=zeros_(1,4) + a=zeros(1,4) a[1:10:4]=1 "[[ 1. 0. 0. 0. 1. 0. 0. 0. 1. 0.]]" #@unittest.skip("") def test04(self): - a=zeros_(1,4) + a=zeros(1,4) with self.assertRaises(IndexError): a[5,5]=1 b = matlabarray( @@ -78,55 +78,55 @@ def test04(self): [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,1]]) - self.assertTrue(isequal_(a,b)) + self.assertTrue(isequal(a,b)) class Strread(unittest.TestCase): def test01(self): - a = strread_("0.11 0.22 0.33") - self.assertTrue(isequal_(a,[[0.11,0.22,0.33]])) + a = strread("0.11 0.22 0.33") + self.assertTrue(isequal(a,[[0.11,0.22,0.33]])) def test02(self): - a,b,c = strread_("0.11 0.22 0.33",nargout=3) + a,b,c = strread("0.11 0.22 0.33",nargout=3) self.assertEqual(a,0.11) self.assertEqual(b,0.22) self.assertEqual(c,0.33) class Core(unittest.TestCase): def setUp(self): - self.a = arange_(1,10).reshape(2,5,order="F") + self.a = arange(1,10).reshape(2,5,order="F") def test01(self): - b = abs_(-self.a) - self.assertTrue(isequal_(self.a,b)) + b = abs(-self.a) + self.assertTrue(isequal(self.a,b)) def test02(self): - b = ceil_(self.a) - self.assertTrue(isequal_(self.a,b)) + b = ceil(self.a) + self.assertTrue(isequal(self.a,b)) def test03(self): - b = false_(2,3) - self.assertTrue(isequal_(size_(b), [[2,3]])) + b = false(2,3) + self.assertTrue(isequal(size(b), [[2,3]])) def test_zeros(self): - self.assertEqual(zeros_(), 0.0) - self.assertTrue(isequal_(zeros_(2), zeros_(2,2))) - self.assertTrue(isequal_(zeros_(2,2), zeros_(2,2))) + self.assertEqual(zeros(), 0.0) + self.assertTrue(isequal(zeros(2), zeros(2,2))) + self.assertTrue(isequal(zeros(2,2), zeros(2,2))) #class Copy(unittest.TestCase): # def setUp(self): -# self.a = zeros_(1,4) +# self.a = zeros(1,4) # # def test01(self): # b=self.a.copy() # print self.a # print b -# self.assertTrue(isequal_(self.a,b)) +# self.assertTrue(isequal(self.a,b)) # b[1,1]=123 -# self.assertTrue(not isequal_(self.a,b)) +# self.assertTrue(not isequal(self.a,b)) # #c=b.copy() # #c[1,:]=1 -# #self.assertTrue(not isequal_(b,c)) +# #self.assertTrue(not isequal(b,c)) if __name__ == "__main__": unittest.main() diff --git a/smop/test_sparsearray.py b/smop/test_sparsearray.py index e2f92dc1..863a128b 100644 --- a/smop/test_sparsearray.py +++ b/smop/test_sparsearray.py @@ -5,10 +5,10 @@ class Slice(unittest.TestCase): def setUp(self): - self.a = sparsearray(arange_(1,4).reshape(2,2,order="F")) + self.a = sparsearray(arange (1,4).reshape(2,2,order="F")) def test01(self): - #self.assertTrue(isequal_(self.a[1:4],[1,2,3,4])) + #self.assertTrue(isequal (self.a[1:4],[1,2,3,4])) self.assertEqual(self.a[1,1], 1) self.assertEqual(self.a[2,1], 2) self.assertEqual(self.a[1,2], 3) @@ -19,35 +19,35 @@ def test01(self): # self.a[2,1] = 22 # self.a[1,2] = 33 # self.a[2,2] = 44 -# self.assertTrue(isequal_(self.a[1:4],[11,22,33,44])) +# self.assertTrue(isequal (self.a[1:4],[11,22,33,44])) # # def test03(self): # self.a[1] = 11 # self.a[2] = 22 # self.a[3] = 33 # self.a[4] = 44 -# self.assertTrue(isequal_(self.a[1:4],[11,22,33,44])) +# self.assertTrue(isequal (self.a[1:4],[11,22,33,44])) # # def test04(self): # #with self.assertRaises(ValueError): # self.a[1:4]=[11,22,33,44] -# self.assertTrue(isequal_(self.a[1:4],[11,22,33,44])) +# self.assertTrue(isequal (self.a[1:4],[11,22,33,44])) # # def test05(self): # self.a[:,:]=[[11,33],[22,44]] -# self.assertTrue(isequal_(self.a[1:4],[11,22,33,44])) +# self.assertTrue(isequal (self.a[1:4],[11,22,33,44])) # # def test06(self): # self.a[:]=[11,22,33,44] -# self.assertTrue(isequal_(self.a[1:4],[11,22,33,44])) +# self.assertTrue(isequal (self.a[1:4],[11,22,33,44])) # # def test07(self): # self.a[::3]=[11,44] -# self.assertTrue(isequal_(self.a[1:4],[11,2,3,44])) +# self.assertTrue(isequal (self.a[1:4],[11,2,3,44])) # # def test08(self): # self.a[1:4:3]=[11,44] -# self.assertTrue(isequal_(self.a[1:4],[11,2,3,44])) +# self.assertTrue(isequal (self.a[1:4],[11,2,3,44])) # # def test_007(self): # """ @@ -60,7 +60,7 @@ def test01(self): # # @unittest.skip("") # def test_008(self): -# a=zeros_(2,2) +# a=zeros (2,2) # a[[4,3,2,1]]=[1,2,3,4] # self.assertEqual(str(a), "[[ 1. 2.]\n [ 3. 4.]]") # @@ -68,31 +68,31 @@ def test01(self): # # @unittest.skip("") # def test_010(self): -# a=zeros_(2,2) +# a=zeros (2,2) # a[2,:]=[1,2] # self.assertEqual(str(a), "[[ 0. 0.]\n [ 1. 2.]]") # # @unittest.skip("") # def test_011(self): -# a=zeros_(2,2) +# a=zeros (2,2) # a[2,1:2]=[1,2] # self.assertEqual(str(a), "[[ 0. 0.]\n [ 1. 2.]]") # # @unittest.skip("") # def test_012(self): -# a=zeros_(2,2) +# a=zeros (2,2) # a[2,[1,2]]=[1,2] # self.assertEqual(str(a), "[[ 0. 0.]\n [ 1. 2.]]") # # @unittest.skip("") # def test_013(self): -# a=zeros_(2,2) +# a=zeros (2,2) # a[:,:]=[[1,2],[3,4]] # self.assertEqual(str(a), "[[ 1. 2.]\n [ 3. 4.]]") # # @unittest.skip("") # def test_014(self): -# a=zeros_(2,2) +# a=zeros (2,2) # with self.assertRaises(ValueError): # a[:,:]=[1,2,3,4] @@ -109,7 +109,7 @@ def test01(self): class Index(unittest.TestCase): def setUp(self): - self.a = sparsearray(arange_(1,4).reshape(2,2,order="F")) + self.a = sparsearray(arange (1,4).reshape(2,2,order="F")) def test01(self): """ @@ -117,7 +117,7 @@ def test01(self): without expansion. Using scalar index. """ self.a[4]=9 - self.assertTrue(isequal_(self.a, sparsearray([[1, 3],[2, 9]]))) + self.assertTrue(isequal (self.a, sparsearray([[1, 3],[2, 9]]))) def test02(self): """ @@ -127,42 +127,42 @@ def test02(self): self.a[2,2]=22 self.a[1,2]=12 self.a[2,1]=21 - self.assertTrue(isequal_(self.a, sparsearray([[11,12],[21,22]]))) + self.assertTrue(isequal (self.a, sparsearray([[11,12],[21,22]]))) class Indices(unittest.TestCase): def setUp(self): self.a = sparsearray(np.arange(1,5).reshape(2,2,order="F")) - self.c = sparsearray(arange_(1,20).reshape(4,5,order="F")) + self.c = sparsearray(arange (1,20).reshape(4,5,order="F")) def test01(self): with self.assertRaises(ValueError): self.a[100]=100 self.a[3,3]=33 - self.assertTrue(isequal_(self.a.todense(), np.asarray([[1,3,0],[2,4,0],[0,0,33]]))) + self.assertTrue(isequal (self.a.todense(), np.asarray([[1,3,0],[2,4,0],[0,0,33]]))) def test02(self): - self.assertTrue(isequal_(self.a[:], [1,2,3,4])) - self.assertTrue(isequal_(self.a[1:4], [1,2,3,4])) + self.assertTrue(isequal (self.a[:], [1,2,3,4])) + self.assertTrue(isequal (self.a[1:4], [1,2,3,4])) @unittest.skip("") def test03(self): - self.assertTrue(isequal_(self.a[:,:], [[1,3],[2,4]])) - self.assertTrue(isequal_(self.a[1:2,1:2], [1,2,3,4])) + self.assertTrue(isequal (self.a[:,:], [[1,3],[2,4]])) + self.assertTrue(isequal (self.a[1:2,1:2], [1,2,3,4])) def test04(self): a = sparsearray([1,2,3]) a[5]=100 a[3,3]=33 self.assertEqual(a.shape, (3,5)) - self.assertTrue(isequal_(a.todense(), [[1,2,3,0,100],[0,0,0,0,0],[0,0,33,0,0]])) + self.assertTrue(isequal (a.todense(), [[1,2,3,0,100],[0,0,0,0,0],[0,0,33,0,0]])) class Slice(unittest.TestCase): def setUp(self): - self.a = sparsearray(arange_(1,4).reshape(2,2,order="F")) + self.a = sparsearray(arange (1,4).reshape(2,2,order="F")) def test01(self): - #self.assertTrue(isequal_(self.a[1:4],[1,2,3,4])) + #self.assertTrue(isequal (self.a[1:4],[1,2,3,4])) self.assertEqual(self.a[1,1], 1) self.assertEqual(self.a[2,1], 2) self.assertEqual(self.a[1,2], 3) @@ -181,7 +181,7 @@ def test01(self): class Index(unittest.TestCase): def setUp(self): - self.a = sparsearray(arange_(1,4).reshape(2,2,order="F")) + self.a = sparsearray(arange (1,4).reshape(2,2,order="F")) def test01(self): """ @@ -189,7 +189,7 @@ def test01(self): without expansion. Using scalar index. """ self.a[4]=9 - self.assertTrue(isequal_(self.a, sparsearray([[1, 3],[2, 9]]))) + self.assertTrue(isequal (self.a, sparsearray([[1, 3],[2, 9]]))) def test02(self): """ @@ -199,34 +199,34 @@ def test02(self): self.a[2,2]=22 self.a[1,2]=12 self.a[2,1]=21 - self.assertTrue(isequal_(self.a, sparsearray([[11,12],[21,22]]))) + self.assertTrue(isequal (self.a, sparsearray([[11,12],[21,22]]))) class Indices(unittest.TestCase): def setUp(self): self.a = sparsearray(np.arange(1,5).reshape(2,2,order="F")) - self.c = sparsearray(arange_(1,20).reshape(4,5,order="F")) + self.c = sparsearray(arange (1,20).reshape(4,5,order="F")) def test01(self): with self.assertRaises(ValueError): self.a[100]=100 self.a[3,3]=33 - self.assertTrue(isequal_(self.a.todense(), np.asarray([[1,3,0],[2,4,0],[0,0,33]]))) + self.assertTrue(isequal (self.a.todense(), np.asarray([[1,3,0],[2,4,0],[0,0,33]]))) def test02(self): - self.assertTrue(isequal_(self.a[:], [1,2,3,4])) - self.assertTrue(isequal_(self.a[1:4], [1,2,3,4])) + self.assertTrue(isequal (self.a[:], [1,2,3,4])) + self.assertTrue(isequal (self.a[1:4], [1,2,3,4])) @unittest.skip("") def test03(self): - self.assertTrue(isequal_(self.a[:,:], [[1,3],[2,4]])) - self.assertTrue(isequal_(self.a[1:2,1:2], [1,2,3,4])) + self.assertTrue(isequal (self.a[:,:], [[1,3],[2,4]])) + self.assertTrue(isequal (self.a[1:2,1:2], [1,2,3,4])) def test04(self): a = sparsearray([1,2,3]) a[5]=100 a[3,3]=33 self.assertEqual(a.shape, (3,5)) - self.assertTrue(isequal_(a.todense(), [[1,2,3,0,100],[0,0,0,0,0],[0,0,33,0,0]])) + self.assertTrue(isequal (a.todense(), [[1,2,3,0,100],[0,0,0,0,0],[0,0,33,0,0]])) if __name__ == "__main__": unittest.main()