rem
stringlengths
1
322k
add
stringlengths
0
2.05M
context
stringlengths
4
228k
meta
stringlengths
156
215
self.dtype.char = self.data.dtype.char
self.dtype = self.data.dtype
def _check(self): M, N = self.shape nnz = self.indptr[-1] nzmax = len(self.colind) if (rank(self.data) != 1) or (rank(self.colind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "data, colind, and indptr arrays "\ "should be rank 1" if (len(self.data) != nzmax): raise ValueError, "data and row list should have same length" if (len(self.indptr) != M+1): raise ValueError, "index pointer should be of length #rows + 1" if (nnz>0) and (amax(self.colind[:nnz]) >= N): raise ValueError, "column-values must be < N" if (nnz > nzmax): raise ValueError, \ "last value of index list should be less than "\ "the size of data list" self.nnz = nnz self.nzmax = nzmax self.dtype.char = self.data.dtype.char if self.dtype.char not in 'fdFD': self.data = self.data + 0.0 self.dtype.char = self.data.dtype.char self.ftype = _transtabl[self.dtype.char]
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
self.dtype.char = self.data.dtype.char
self.dtype = self.data.dtype
def _check(self): M, N = self.shape nnz = self.indptr[-1] nzmax = len(self.colind) if (rank(self.data) != 1) or (rank(self.colind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "data, colind, and indptr arrays "\ "should be rank 1" if (len(self.data) != nzmax): raise ValueError, "data and row list should have same length" if (len(self.indptr) != M+1): raise ValueError, "index pointer should be of length #rows + 1" if (nnz>0) and (amax(self.colind[:nnz]) >= N): raise ValueError, "column-values must be < N" if (nnz > nzmax): raise ValueError, \ "last value of index list should be less than "\ "the size of data list" self.nnz = nnz self.nzmax = nzmax self.dtype.char = self.data.dtype.char if self.dtype.char not in 'fdFD': self.data = self.data + 0.0 self.dtype.char = self.data.dtype.char self.ftype = _transtabl[self.dtype.char]
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
new.dtype.char = new.data.dtype.char
new.dtype = new.data.dtype
def __mul__(self, other): """ Scalar, vector, or matrix multiplication """ if isscalar(other) or (isdense(other) and rank(other)==0): new = self.copy() new.data = other * new.data # allows type conversion new.dtype.char = new.data.dtype.char new.ftype = _transtabl[new.dtype.char] return new else: return self.dot(other)
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
new.dtype.char = new.data.dtype.char
new.dtype = new.data.dtype
def __rmul__(self, other): # other * self if isscalar(other) or (isdense(other) and rank(other)==0): new = self.copy() new.data = other * new.data # allows type conversion new.dtype.char = new.data.dtype.char new.ftype = _transtabl[new.dtype.char] return new else: other = asarray(other) return self.transpose().dot(other.transpose()).transpose()
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
new.dtype.char = new.data.dtype.char
new.dtype = new.data.dtype
def __pow__(self, other): """ Element-by-element power (unless other is a scalar, in which case return the matrix power.) """ if isscalar(other) or (isdense(other) and rank(other)==0): new = self.copy() new.data = new.data ** other new.dtype.char = new.data.dtype.char new.ftype = _transtabl[new.dtype.char] return new elif isspmatrix(other): ocs = other.tocsr() if (ocs.shape != self.shape): raise ValueError, "inconsistent shapes" dtypechar = _coerce_rules[(self.dtype.char, ocs.dtype.char)] data1, data2 = _convert_data(self.data, ocs.data, dtypechar) func = getattr(sparsetools, _transtabl[dtypechar]+'cscmul') c, colc, ptrc, ierr = func(data1, self.colind, self.indptr, data2, ocs.colind, ocs.indptr) if ierr: raise ValueError, "ran out of space (but shouldn't have happened)" M, N = self.shape return csr_matrix((c, colc, ptrc), dims=(M, N)) else: raise TypeError, "unsupported type for sparse matrix power"
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
new = csc_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype.char)
new = csc_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype)
def transpose(self, copy=False): M, N = self.shape new = csc_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype.char) if copy: new.data = self.data.copy() new.rowind = self.colind.copy() new.indptr = self.indptr.copy() else: new.data = self.data new.rowind = self.colind new.indptr = self.indptr new._check() return new
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
new = csr_matrix(self.shape, nzmax=self.nzmax, dtype=self.dtype.char)
new = csr_matrix(self.shape, nzmax=self.nzmax, dtype=self.dtype)
def copy(self): new = csr_matrix(self.shape, nzmax=self.nzmax, dtype=self.dtype.char) new.data = self.data.copy() new.colind = self.colind.copy() new.indptr = self.indptr.copy() new._check() return new
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
self.dtype.char = self.data.dtype.char
self.dtype = self.data.dtype
def __init__(self, obj, ij_in, dims=None, nzmax=None, dtype=None): spmatrix.__init__(self) try: # Assume the first calling convention # assert len(ij) == 2 if len(ij_in) != 2: if isdense( ij_in ) and (ij_in.shape[1] == 2): ij = (ij_in[:,0], ij_in[:,1]) else: raise AssertionError else: ij = ij_in if dims is None: M = int(amax(ij[0])) N = int(amax(ij[1])) self.shape = (M, N) else: # Use 2 steps to ensure dims has length 2. M, N = dims self.shape = (M, N) self.row = asarray(ij[0]) self.col = asarray(ij[1]) self.data = asarray(obj, dtype=dtype) self.dtype.char = self.data.dtype.char if nzmax is None: nzmax = len(self.data) self.nzmax = nzmax self._check() except Exception, e: raise e, "invalid input format"
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
self.data = array(data, self.dtype.char)
self.data = array(data, self.dtype)
def _normalize(self, rowfirst=False): if rowfirst: l = zip(self.row, self.col, self.data) l.sort() row, col, data = list(itertools.izip(*l)) return data, row, col if getattr(self, '_is_normalized', None): return self.data, self.row, self.col l = zip(self.col, self.row, self.data) l.sort() col, row, data = list(itertools.izip(*l)) self.col = asarray(col, 'i') self.row = asarray(row, 'i') self.data = array(data, self.dtype.char) setattr(self, '_is_normalized', 1) return self.data, self.row, self.col
755141cd47edbf647cfcd8d09fd47ede3320459c /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/755141cd47edbf647cfcd8d09fd47ede3320459c/sparse.py
if xb is None: xb=x[0] if xe is None: xe=x[-1]
if xb is None: xb=x.min() if xe is None: xe=x.max()
def splrep(x,y,w=None,xb=None,xe=None,k=3,task=0,s=None,t=None, full_output=0,nest=None,per=0,quiet=1): """Find the B-spline representation of 1-D curve. Description: Given the set of data points (x[i], y[i]) determine a smooth spline approximation of degree k on the interval xb <= x <= xe. The coefficients, c, and the knot points, t, are returned. Uses the FORTRAN routine curfit from FITPACK. Inputs: x, y -- The data points defining a curve y = f(x). w -- Strictly positive rank-1 array of weights the same length as x and y. The weights are used in computing the weighted least-squares spline fit. If the errors in the y values have standard-deviation given by the vector d, then w should be 1/d. Default is ones(len(x)). xb, xe -- The interval to fit. If None, these default to x[0] and x[-1] respectively. k -- The order of the spline fit. It is recommended to use cubic splines. Even order splines should be avoided especially with small s values. 1 <= k <= 5 task -- If task==0 find t and c for a given smoothing factor, s. If task==1 find t and c for another value of the smoothing factor, s. There must have been a previous call with task=0 or task=1 for the same set of data. If task=-1 find the weighted least square spline for a given set of knots, t. s -- A smoothing condition. The amount of smoothness is determined by satisfying the conditions: sum((w * (y - g))**2) <= s where g(x) is the smoothed interpolation of (x,y). The user can use s to control the tradeoff between closeness and smoothness of fit. Larger s means more smoothing while smaller values of s indicate less smoothing. Recommended values of s depend on the weights, w. If the weights represent the inverse of the standard-deviation of y, then a good s value should be found in the range (m-sqrt(2*m),m+sqrt(2*m)) where m is the number of datapoints in x, y, and w. t -- The knots needed for task=-1. full_output -- If non-zero, then return optional outputs. nest -- An over-estimate of the total number of knots of the spline to help in determining the storage space. By default nest=m/2. per -- If non-zero, data points are considered periodic with period x[m-1] - x[0] and a smooth periodic spline approximation is returned. Values of y[m-1] and w[m-1] are not used. quiet -- Non-zero to suppress messages. Outputs: (tck, {fp, ier, msg}) tck -- (t,c,k) a tuple containing the vector of knots, the B-spline coefficients, and the degree of the spline. fp -- The weighted sum of squared residuals of the spline approximation. ier -- An integer flag about splrep success. Success is indicated if ier<=0. If ier in [1,2,3] an error occurred but was not raised. Otherwise an error is raised. msg -- A message corresponding to the integer flag, ier. Remarks: SEE splev for evaluation of the spline and its derivatives. """ if task<=0: _curfit_cache = {'t': array([],'d'), 'wrk': array([],'d'), 'iwrk':array([],'i')} x,y=map(myasarray,[x,y]) m=len(x) if w is None: w=ones(m,'d') else: w=myasarray(w) if not len(w) == m: raise TypeError,' len(w)=%d is not equal to m=%d'%(len(w),m) if xb is None: xb=x[0] if xe is None: xe=x[-1] if not (-1<=task<=1): raise TypeError, 'task must be either -1,0, or 1' if s is None: s=m-sqrt(2*m) if t is None and task==-1: raise TypeError, 'Knots must be given for task=-1' if t is not None: _curfit_cache['t']=myasarray(t) n=len(_curfit_cache['t']) if task==-1 and n<2*k+2: raise TypeError, 'There must be at least 2*k+2 knots for task=-1' if (m != len(y)) or (m != len(w)): raise TypeError, 'Lengths of the first three arguments (x,y,w) must be equal' if not (1<=k<=5): raise TypeError, 'Given degree of the spline (k=%d) is not supported. (1<=k<=5)'%(k) if m<=k: raise TypeError, 'm>k must hold' if nest is None: nest=m/2 if nest<0: if per: nest=m+2*k else: nest=m+k+1 nest=max(nest,2*k+3) if task>=0 and s==0: if per: nest=m+2*k else: nest=m+k+1 if task==-1: _curfit_cache['t']=myasarray(t) if not (2*k+2<=len(t)<=min(nest,m+k+1)): raise TypeError, 'Number of knots n is not acceptable (2*k+2<=n<=min(nest,m+l+1))' t=_curfit_cache['t'] wrk=_curfit_cache['wrk'] iwrk=_curfit_cache['iwrk'] t,c,o = _fitpack._curfit(x,y,w,xb,xe,k,task,s,t,nest,wrk,iwrk,per) _curfit_cache['t']=t _curfit_cache['wrk']=o['wrk'] _curfit_cache['iwrk']=o['iwrk'] ier,fp=o['ier'],o['fp'] tck = [t,c,k] if ier<=0 and not quiet: print _iermess[ier][0] print "\tk=%d n=%d m=%d fp=%f s=%f"%(k,len(t),m,fp,s) if ier>0 and not full_output: if ier in [1,2,3]: print "Warning: "+_iermess[ier][0] else: try: raise _iermess[ier][1],_iermess[ier][0] except KeyError: raise _iermess['unknown'][1],_iermess['unknown'][0] if full_output: try: return tck,fp,ier,_iermess[ier][0] except KeyError: return tck,fp,ier,_iermess['unknown'][0] else: return tck
765182827eb04adbfb9c0419d9d947b712c20cb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/765182827eb04adbfb9c0419d9d947b712c20cb8/fitpack.py
if xb is None: xb=x[0] if xe is None: xe=x[-1] if yb is None: yb=y[0] if ye is None: ye=y[-1]
if xb is None: xb=x.min() if xe is None: xe=x.max() if yb is None: yb=y.min() if ye is None: ye=y.max()
def bisplrep(x,y,z,w=None,xb=None,xe=None,yb=None,ye=None,kx=3,ky=3,task=0,s=None, eps=1e-16,tx=None,ty=None,full_output=0,nxest=None,nyest=None,quiet=1): """Find a bivariate B-spline representation of a surface. Description: Given a set of data points (x[i], y[i], z[i]) representing a surface z=f(x,y), compute a B-spline representation of the surface. Inputs: x, y, z -- Rank-1 arrays of data points. w -- Rank-1 array of weights. By default w=ones(len(x)). xb, xe -- End points of approximation interval in x. yb, ye -- End points of approximation interval in y. By default xb, xe, yb, ye = x[0], x[-1], y[0], y[-1] kx, ky -- The degrees of the spline (1 <= kx, ky <= 5). Third order (kx=ky=3) is recommended. task -- If task=0, find knots in x and y and coefficients for a given smoothing factor, s. If task=1, find knots and coefficients for another value of the smoothing factor, s. bisplrep must have been previously called with task=0 or task=1. If task=-1, find coefficients for a given set of knots tx, ty. s -- A non-negative smoothing factor. If weights correspond to the inverse of the standard-deviation of the errors in z, then a good s-value should be found in the range (m-sqrt(2*m),m+sqrt(2*m)) where m=len(x) eps -- A threshold for determining the effective rank of an over-determined linear system of equations (0 < eps < 1) --- not likely to need changing. tx, ty -- Rank-1 arrays of the knots of the spline for task=-1 full_output -- Non-zero to return optional outputs. nxest, nyest -- Over-estimates of the total number of knots. If None then nxest = max(kx+sqrt(m/2),2*kx+3), nyest = max(ky+sqrt(m/2),2*ky+3) quiet -- Non-zero to suppress printing of messages. Outputs: (tck, {fp, ier, msg}) tck -- A list [tx, ty, c, kx, ky] containing the knots (tx, ty) and coefficients (c) of the bivariate B-spline representation of the surface along with the degree of the spline. fp -- The weighted sum of squared residuals of the spline approximation. ier -- An integer flag about splrep success. Success is indicated if ier<=0. If ier in [1,2,3] an error occurred but was not raised. Otherwise an error is raised. msg -- A message corresponding to the integer flag, ier. Remarks: SEE bisplev to evaluate the value of the B-spline given its tck representation. """ x,y,z=map(myasarray,[x,y,z]) x,y,z=map(ravel,[x,y,z]) # ensure 1-d arrays. m=len(x) if not (m==len(y)==len(z)): raise TypeError, 'len(x)==len(y)==len(z) must hold.' if w is None: w=ones(m,'d') else: w=myasarray(w) if not len(w) == m: raise TypeError,' len(w)=%d is not equal to m=%d'%(len(w),m) if xb is None: xb=x[0] if xe is None: xe=x[-1] if yb is None: yb=y[0] if ye is None: ye=y[-1] if not (-1<=task<=1): raise TypeError, 'task must be either -1,0, or 1' if s is None: s=m-sqrt(2*m) if tx is None and task==-1: raise TypeError, 'Knots_x must be given for task=-1' if tx is not None: _curfit_cache['tx']=myasarray(tx) nx=len(_surfit_cache['tx']) if ty is None and task==-1: raise TypeError, 'Knots_y must be given for task=-1' if ty is not None: _curfit_cache['ty']=myasarray(ty) ny=len(_surfit_cache['ty']) if task==-1 and nx<2*kx+2: raise TypeError, 'There must be at least 2*kx+2 knots_x for task=-1' if task==-1 and ny<2*ky+2: raise TypeError, 'There must be at least 2*ky+2 knots_x for task=-1' if not ((1<=kx<=5) and (1<=ky<=5)): raise TypeError, 'Given degree of the spline (kx,ky=%d,%d) is not supported. (1<=k<=5)'%(kx,ky) if m<(kx+1)*(ky+1): raise TypeError, 'm>=(kx+1)(ky+1) must hold' if nxest is None: nxest=kx+sqrt(m/2) if nyest is None: nyest=ky+sqrt(m/2) nxest,nyest=max(nxest,2*kx+3),max(nyest,2*ky+3) if task>=0 and s==0: nxest=int(kx+sqrt(3*m)) nyest=int(ky+sqrt(3*m)) if task==-1: _surfit_cache['tx']=myasarray(tx) _surfit_cache['ty']=myasarray(ty) tx,ty=_surfit_cache['tx'],_surfit_cache['ty'] wrk=_surfit_cache['wrk'] iwrk=_surfit_cache['iwrk'] u,v,km,ne=nxest-kx-1,nyest-ky-1,max(kx,ky)+1,max(nxest,nyest) bx,by=kx*v+ky+1,ky*u+kx+1 b1,b2=bx,bx+v-ky if bx>by: b1,b2=by,by+u-kx lwrk1=u*v*(2+b1+b2)+2*(u+v+km*(m+ne)+ne-kx-ky)+b2+1 lwrk2=u*v*(b2+1)+b2 tx,ty,c,o = _fitpack._surfit(x,y,z,w,xb,xe,yb,ye,kx,ky,task,s,eps, tx,ty,nxest,nyest,wrk,lwrk1,lwrk2) _curfit_cache['tx']=tx _curfit_cache['ty']=ty _curfit_cache['wrk']=o['wrk'] ier,fp=o['ier'],o['fp'] tck=[tx,ty,c,kx,ky] if ier<=0 and not quiet: print _iermess2[ier][0] print "\tkx,ky=%d,%d nx,ny=%d,%d m=%d fp=%f s=%f"%(kx,ky,len(tx), len(ty),m,fp,s) ierm=min(11,max(-3,ier)) if ierm>0 and not full_output: if ier in [1,2,3,4,5]: print "Warning: "+_iermess2[ierm][0] print "\tkx,ky=%d,%d nx,ny=%d,%d m=%d fp=%f s=%f"%(kx,ky,len(tx), len(ty),m,fp,s) else: try: raise _iermess2[ierm][1],_iermess2[ierm][0] except KeyError: raise _iermess2['unknown'][1],_iermess2['unknown'][0] if full_output: try: return tck,fp,ier,_iermess2[ierm][0] except KeyError: return tck,fp,ier,_iermess2['unknown'][0] else: return tck
765182827eb04adbfb9c0419d9d947b712c20cb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/765182827eb04adbfb9c0419d9d947b712c20cb8/fitpack.py
self.file.tell()
return self.file.tell()
def tell(self): self.file.tell()
4cb2f9dbed4a97a819a3f802aebaea2f1a6818c8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/4cb2f9dbed4a97a819a3f802aebaea2f1a6818c8/mio.py
def _get_namespace(self): return self.__namespace or default_namespace
def _get_namespace(self): if isinstance(self.__namespace, N.ndarray): return self.__namespace else: return self.__namespace or default_namespace
def _get_namespace(self): return self.__namespace or default_namespace
58d9f655e8cd3933b0b78fa33758e7170e41e0aa /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/58d9f655e8cd3933b0b78fa33758e7170e41e0aa/formula.py
if result[:11] == 'Bad command' and sys.platform == 'win32':
res = bbox_re.search(result) if res is None and sys.platform=='win32':
def convert_bounding_box(inname, outname): fid = open(inname,'r') oldfile = fid.read() fid.close() gsargs = '-dNOPAUSE -dBATCH -sDEVICE=bbox' # use cygwin gs if present cmd = 'gs %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command' and sys.platform == 'win32': cmd = 'gswin32c %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command': return False res = bbox_re.search(result) bbox = map(int,res.groups()) newstr = bbox2_re.sub("BoundingBox: %d %d %d %d" % tuple(bbox), oldfile) fid = open(outname, 'wb') fid.write(newstr) fid.close() return True
09d23f7e8e736abc56a2ea5a98859b764df109a3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/09d23f7e8e736abc56a2ea5a98859b764df109a3/gist.py
if result[:11] == 'Bad command':
res = bbox_re.search(result) if res is None: sys.stderr.write('To fix bounding box install ghostscript in the PATH')
def convert_bounding_box(inname, outname): fid = open(inname,'r') oldfile = fid.read() fid.close() gsargs = '-dNOPAUSE -dBATCH -sDEVICE=bbox' # use cygwin gs if present cmd = 'gs %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command' and sys.platform == 'win32': cmd = 'gswin32c %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command': return False res = bbox_re.search(result) bbox = map(int,res.groups()) newstr = bbox2_re.sub("BoundingBox: %d %d %d %d" % tuple(bbox), oldfile) fid = open(outname, 'wb') fid.write(newstr) fid.close() return True
09d23f7e8e736abc56a2ea5a98859b764df109a3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/09d23f7e8e736abc56a2ea5a98859b764df109a3/gist.py
res = bbox_re.search(result)
def convert_bounding_box(inname, outname): fid = open(inname,'r') oldfile = fid.read() fid.close() gsargs = '-dNOPAUSE -dBATCH -sDEVICE=bbox' # use cygwin gs if present cmd = 'gs %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command' and sys.platform == 'win32': cmd = 'gswin32c %s %s' % (gsargs, inname) w, r = os.popen4(cmd) w.close() result = r.read() r.close() if result[:11] == 'Bad command': return False res = bbox_re.search(result) bbox = map(int,res.groups()) newstr = bbox2_re.sub("BoundingBox: %d %d %d %d" % tuple(bbox), oldfile) fid = open(outname, 'wb') fid.write(newstr) fid.close() return True
09d23f7e8e736abc56a2ea5a98859b764df109a3 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/09d23f7e8e736abc56a2ea5a98859b764df109a3/gist.py
print diff
def kmeans_(obs,guess,thresh=1e-5): """* See kmeans Outputs: code_book -- the lowest distortion codebook found. avg_dist -- the average distance a observation is from a code in the book. Lower means the code_book matches the data better. Test: Note: not whitened in this example. >>> features = array([[ 1.9,2.3], ... [ 1.5,2.5], ... [ 0.8,0.6], ... [ 0.4,1.8], ... [ 1.0,1.0]]) >>> book = array((features[0],features[2])) >>> kmeans_(features,book) (array([[ 1.7 , 2.4 ], [ 0.73333333, 1.13333333]]), 0.40563916697728591) *""" code_book = array(guess,copy=1) Nc = code_book.shape[0] avg_dist=[] diff = thresh+1. while diff>thresh: #print diff #compute membership and distances between obs and code_book obs_code, distort = vq(obs,code_book,return_dist=1) avg_dist.append(scipy.mean(distort)) #recalc code_book as centroids of associated obs if(diff > thresh): has_members = [] for i in arange(Nc): cell_members = compress(equal(obs_code,i),obs,0) if cell_members.shape[0] > 0: code_book[i] = scipy.mean(cell_members,0) has_members.append(i) #remove code_books that didn't have any members #print has_members code_book = take(code_book,has_members,0) if len(avg_dist) > 1: diff = avg_dist[-2] - avg_dist[-1] #print avg_dist return code_book, avg_dist[-1]
54fafe1863b2401aeb8b2cfcba3dde51015b6fb8 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/54fafe1863b2401aeb8b2cfcba3dde51015b6fb8/vq.py
[0,1,1,1],
[1,1,1,1],
def check_diag(self): assert_equal(tri(4,k=1),array([[1,1,0,0], [1,1,1,0], [0,1,1,1], [1,1,1,1]])) assert_equal(tri(4,k=-1),array([[0,0,0,0], [1,0,0,0], [1,1,0,0], [1,1,1,0]]))
22efb1b19aa440ab9cf9d8310ee790a0c6130db1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/22efb1b19aa440ab9cf9d8310ee790a0c6130db1/test_basic.py
assert_equal(tril(a,k=-2),b)
assert_equal(triu(a,k=-2),b)
def check_diag(self): a = (100*get_mat(5)).astype('f') b = a.copy() for k in range(5): for l in range(max((k-1,0)),5): b[l,k] = 0 assert_equal(triu(a,k=2),b) b = a.copy() for k in range(5): for l in range(k+3,5): b[l,k] = 0 assert_equal(tril(a,k=-2),b)
22efb1b19aa440ab9cf9d8310ee790a0c6130db1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/22efb1b19aa440ab9cf9d8310ee790a0c6130db1/test_basic.py
def _check_bdtrik(self): assert_equal(cephes.bdtrik(1,3,0.5),3.0)
def check_bdtrik(self): cephes.bdtrik(1,3,0.5)
def _check_bdtrik(self): assert_equal(cephes.bdtrik(1,3,0.5),3.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_chndtrix(self):
def check_chndtrix(self):
def _check_chndtrix(self): assert_equal(cephes.chndtrix(0,1,0),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_gdtrib(self): assert_equal(cephes.gdtrib(1,0,1),5.0)
def check_gdtrib(self): cephes.gdtrib(1,0,1)
def _check_gdtrib(self): assert_equal(cephes.gdtrib(1,0,1),5.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_hankel1(self):
def check_hankel1(self):
def _check_hankel1(self): cephes.hankel1(1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_hankel1e(self):
def check_hankel1e(self):
def _check_hankel1e(self): cephes.hankel1e(1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_hankel2(self):
def check_hankel2(self):
def _check_hankel2(self): cephes.hankel2(1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_hankel2e(self):
def check_hankel2e(self):
def _check_hankel2e(self): cephes.hankel2e(1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_it2i0k0(self):
def check_it2i0k0(self):
def _check_it2i0k0(self): cephes.it2i0k0(1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_it2j0y0(self):
def check_it2j0y0(self):
def _check_it2j0y0(self): cephes.it2j0y0(1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_itairy(self):
def check_itairy(self):
def _check_itairy(self): cephes.itairy(1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def check_ive(self):
def _check_ive(self):
def check_ive(self): assert_equal(cephes.ive(1,0),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def check_jve(self):
def _check_jve(self):
def check_jve(self): assert_equal(cephes.jve(0,0),1.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_kei(self):
def check_kei(self):
def _check_kei(self): cephes.kei(2)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_ker(self):
def check_ker(self):
def _check_ker(self): cephes.ker(2)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_kerp(self):
def check_kerp(self):
def _check_kerp(self): cephes.kerp(2)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_mathieu_modcem2(self):
def check_mathieu_modcem2(self):
def _check_mathieu_modcem2(self): cephes.mathieu_modcem2(1,1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_mathieu_modsem2(self):
def check_mathieu_modsem2(self):
def _check_mathieu_modsem2(self): cephes.mathieu_modsem2(1,1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def check_modstruve(self):
def _check_modstruve(self):
def check_modstruve(self): assert_equal(cephes.modstruve(1,0),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
cephes.nbdtrik(1,1,1)
cephes.nbdtrik(1,.4,.5)
def __check_nbdtrik(self): cephes.nbdtrik(1,1,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_ncfdtr(self):
def check_ncfdtr(self):
def _check_ncfdtr(self): assert_equal(cephes.ncfdtr(1,1,1,0),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_ncfdtri(self):
def check_ncfdtri(self):
def _check_ncfdtri(self): assert_equal(cephes.ncfdtri(1,1,1,0),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_ncfdtridfd(self):
def check_ncfdtridfd(self):
def _check_ncfdtridfd(self): cephes.ncfdtridfd(1,0.5,0,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_nctdtrit(self):
def check_nctdtrit(self):
def _check_nctdtrit(self): cephes.nctdtrit(.1,0.2,.5)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_nrdtrimn(self):
def check_nrdtrimn(self):
def _check_nrdtrimn(self): assert_equal(cephes.nrdtrimn(0.5,1,1),1.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_nrdtrisd(self):
def check_nrdtrisd(self):
def _check_nrdtrisd(self): assert_equal(cephes.nrdtrisd(0.5,0.5,0.5),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_obl_ang1(self):
def check_obl_ang1(self):
def _check_obl_ang1(self): cephes.obl_ang1(1,1,1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_obl_ang1_cv(self): assert_equal(cephes.obl_ang1_cv(1,1,1,1,0),(1.0,0.0)) def check_obl_cv(self):
def check_obl_ang1_cv(self): result = cephes.obl_ang1_cv(1,1,1,1,0) assert_almost_equal(result[0],1.0) assert_almost_equal(result[1],0.0) def _check_obl_cv(self):
def _check_obl_ang1_cv(self): assert_equal(cephes.obl_ang1_cv(1,1,1,1,0),(1.0,0.0))
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_obl_rad1(self):
def check_obl_rad1(self):
def _check_obl_rad1(self): cephes.obl_rad1(1,1,1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_obl_rad1_cv(self):
def check_obl_rad1_cv(self):
def _check_obl_rad1_cv(self): cephes.obl_rad1_cv(1,1,1,1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_pbdv(self):
def check_pbdv(self):
def _check_pbdv(self): assert_equal(cephes.pbdv(1,0),(0.0,0.0))
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_pbvv(self):
def check_pbvv(self):
def _check_pbvv(self): cephes.pbvv(1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_pdtrik(self):
def check_pdtrik(self):
def _check_pdtrik(self): cephes.pdtrik(0.5,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_pro_ang1(self):
def check_pro_ang1(self):
def _check_pro_ang1(self): cephes.pro_ang1(1,1,1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_pro_ang1_cv(self):
def check_pro_ang1_cv(self):
def _check_pro_ang1_cv(self): assert_equal(cephes.pro_ang1_cv(1,1,1,1,0),(1.0,0.0))
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def check_pro_cv(self):
def _check_pro_cv(self):
def check_pro_cv(self): assert_equal(cephes.pro_cv(1,1,0),2.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
cephes.pro_rad1(1,1,1,0)
cephes.pro_rad1(1,1,1,0.1)
def check_pro_rad1(self): # x>1 gives segfault with ifc, but not with gcc # x<1 returns nan, no segfault cephes.pro_rad1(1,1,1,0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
assert_equal(cephes.smirnov(1,1),0.0)
assert_equal(cephes.smirnov(1,.1),0.9)
def check_smirnov(self): assert_equal(cephes.smirnov(1,1),0.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
assert_equal(cephes.smirnovi(1,0),1.0)
def check_smirnovi(self): assert_almost_equal(cephes.smirnov(1,cephes.smirnovi(1,0.4)),0.4) assert_almost_equal(cephes.smirnov(1,cephes.smirnovi(1,0.6)),0.6) assert_equal(cephes.smirnovi(1,0),1.0)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_stdtridf(self):
def check_stdtridf(self):
def _check_stdtridf(self): cephes.stdtridf(0.7,1)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
def _check_stdtrit(self):
def check_stdtrit(self):
def _check_stdtrit(self): cephes.stdtrit(1,0.7)
2a0571808f9b68627e9152f6f1037281e69d9d98 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a0571808f9b68627e9152f6f1037281e69d9d98/test_cephes.py
val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1))
val *= exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1)))
def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*n+1)/4.0/pi) val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1)) val *= exp(1j*m*theta) return val
10119a8f65df1234fc1da07197fb7e5e98ccd5a1 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/10119a8f65df1234fc1da07197fb7e5e98ccd5a1/basic.py
"""inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi)
"""Spherical harmonic of order m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi)
def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*n+1)/4.0/pi) val *= exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1))) val *= exp(1j*m*theta) return val
997b8fe2b95e9b5cba41b878e2e3f17f856ff0c0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/997b8fe2b95e9b5cba41b878e2e3f17f856ff0c0/basic.py
val = Pmn[m,n]
val = Pmn[-1, -1]
def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*n+1)/4.0/pi) val *= exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1))) val *= exp(1j*m*theta) return val
997b8fe2b95e9b5cba41b878e2e3f17f856ff0c0 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/997b8fe2b95e9b5cba41b878e2e3f17f856ff0c0/basic.py
deltax = fontsize*points / 2.8 * DX / DY
deltax = fontsize*points / 2.6 * DX / DY
def legend(text,linetypes=None,lleft=None,color='black',tfont='helvetica',fontsize=14,nobox=0): """Construct and place a legend. Description: Build a legend and place it on the current plot with an interactive prompt. Inputs: text -- A list of strings which document the curves. linetypes -- If not given, then the text strings are associated with the curves in the order they were originally drawn. Otherwise, associate the text strings with the corresponding curve types given. See plot for description. """ global _hold sys = gist.plsys() if sys == 0: gist.plsys(1) viewp = gist.viewport() gist.plsys(sys) DX = viewp[1] - viewp[0] DY = viewp[3] - viewp[2] width = DY / 10.0; if lleft is None: lleft = gist.mouse(0,0,"Click on point for lower left coordinate.") llx = lleft[0] lly = lleft[1] else: llx,lly = lleft[:2] savesys = gist.plsys() dx = width / 3.0 legarr = Numeric.arange(llx,llx+width,dx) legy = Numeric.ones(legarr.shape) dy = fontsize*points*1.2 deltay = fontsize*points / 2.8 deltax = fontsize*points / 2.8 * DX / DY ypos = lly + deltay; if linetypes is None: linetypes = _GLOBAL_LINE_TYPES[:] # copy them out gist.plsys(0) savehold = _hold _hold = 1 for k in range(len(text)): plot(legarr,ypos*legy,linetypes[k]) #print llx+width+deltax, ypos-deltay if text[k] != "": gist.plt(text[k],llx+width+deltax,ypos-deltay, color=color,font=tfont,height=fontsize,tosys=0) ypos = ypos + dy _hold = savehold if nobox: pass else: gist.plsys(0) maxlen = MLab.max(map(len,text)) c1 = (llx-deltax,lly-deltay) c2 = (llx + width + deltax + fontsize*points* maxlen/1.8 + deltax, lly + len(text)*dy) linesx0 = [c1[0],c1[0],c2[0],c2[0]] linesy0 = [c1[1],c2[1],c2[1],c1[1]] linesx1 = [c1[0],c2[0],c2[0],c1[0]] linesy1 = [c2[1],c2[1],c1[1],c1[1]] gist.pldj(linesx0,linesy0,linesx1,linesy1,color=color) gist.plsys(savesys) return
2a28b9e78ba8a60ef15cce71697f39697438dfd6 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/2a28b9e78ba8a60ef15cce71697f39697438dfd6/Mplot.py
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense array or matrix arg1 to CSC format if rank(arg1) == 2: s = arg1 if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype func = getattr(sparsetools, _transtabl[dtype.char]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) except (AssertionError, TypeError, ValueError): try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: # (data, ij) format temp = coo_matrix(s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr else: raise ValueError, "unrecognized form for csc_matrix constructor"
f288ca9c08fb1aa89622bce25bb448003735fa54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/f288ca9c08fb1aa89622bce25bb448003735fa54/sparse.py
raise ValueError, "dense array does not have rank 1 or 2"
raise ValueError, "dense array must have rank 1 or 2"
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense array or matrix arg1 to CSC format if rank(arg1) == 2: s = arg1 if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype func = getattr(sparsetools, _transtabl[dtype.char]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) except (AssertionError, TypeError, ValueError): try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: # (data, ij) format temp = coo_matrix(s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr else: raise ValueError, "unrecognized form for csc_matrix constructor"
f288ca9c08fb1aa89622bce25bb448003735fa54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/f288ca9c08fb1aa89622bce25bb448003735fa54/sparse.py
else: raise ValueError, "dense array must have rank 1 or 2"
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense array or matrix arg1 to CSR format if rank(arg1) == 2: s = arg1 ocsc = csc_matrix(transpose(s)) self.colind = ocsc.rowind self.indptr = ocsc.indptr self.data = ocsc.data self.shape = (ocsc.shape[1], ocsc.shape[0])
f288ca9c08fb1aa89622bce25bb448003735fa54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/f288ca9c08fb1aa89622bce25bb448003735fa54/sparse.py
def __getitem__(self, key):
def get(self, key, default=0.): """This overrides the dict.get method, providing type checking but otherwise equivalent functionality. """ try: i, j = key assert isinstance(i, int) and isinstance(j, int) except (AssertionError, TypeError, ValueError): raise IndexError, "index must be a pair of integers" try: assert not (i < 0 or i >= self.shape[0] or j < 0 or j >= self.shape[1]) except AssertionError: raise IndexError, "index out of bounds" return dict.get(self, key, default) def __getitem__(self, key):
def __getitem__(self, key): if self._validate: # Sanity checks: key must be a pair of integers if not isinstance(key, tuple) or len(key) != 2: raise TypeError, "key must be a tuple of two integers" if type(key[0]) != int or type(key[1]) != int: raise TypeError, "key must be a tuple of two integers"
f288ca9c08fb1aa89622bce25bb448003735fa54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/f288ca9c08fb1aa89622bce25bb448003735fa54/sparse.py
def __getitem__(self, key): if self._validate: # Sanity checks: key must be a pair of integers if not isinstance(key, tuple) or len(key) != 2: raise TypeError, "key must be a tuple of two integers" if type(key[0]) != int or type(key[1]) != int: raise TypeError, "key must be a tuple of two integers"
f288ca9c08fb1aa89622bce25bb448003735fa54 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/f288ca9c08fb1aa89622bce25bb448003735fa54/sparse.py
class _test_horiz_slicing(ScipyTestCase):
class _test_horiz_slicing:
def check_solve(self): """ Test whether the lu_solve command segfaults, as reported by Nils Wagner for a 64-bit machine, 02 March 2005 (EJS) """ n = 20 A = self.spmatrix((n,n), dtype=complex) x = numpy.rand(n) y = numpy.rand(n-1)+1j*numpy.rand(n-1) r = numpy.rand(n) for i in range(len(x)): A[i,i] = x[i] for i in range(len(y)): A[i,i+1] = y[i] A[i+1,i] = numpy.conjugate(y[i]) B = A.tocsc() xx = splu(B).solve(r) # Don't actually test the output until we know what it should be ...
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class _test_vert_slicing(ScipyTestCase):
class _test_vert_slicing:
def check_get_horiz_slice(self): """Test for new slice functionality (EJS)""" B = asmatrix(arange(50.).reshape(5,10)) A = self.spmatrix(B) assert_array_equal(B[1,:], A[1,:].todense()) assert_array_equal(B[1,2:5], A[1,2:5].todense())
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class _test_fancy_indexing(ScipyTestCase):
class _test_fancy_indexing:
def check_get_vert_slice(self): """Test for new slice functionality (EJS)""" B = asmatrix(arange(50.).reshape(5,10)) A = self.spmatrix(B) assert_array_equal(B[2:5,0], A[2:5,0].todense()) assert_array_equal(B[:,1], A[:,1].todense())
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class test_csr(_test_cs, _test_horiz_slicing):
class test_csr(_test_cs, _test_horiz_slicing, ScipyTestCase):
def check_fancy_indexing(self): """Test for new indexing functionality""" B = ones((5,10), float) A = dok_matrix(B) # Write me! # Both slicing and fancy indexing: not yet supported # assert_array_equal(B[(1,2),:], A[(1,2),:].todense()) # assert_array_equal(B[(1,2,3),:], A[(1,2,3),:].todense())
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class test_csc(_test_cs, _test_vert_slicing):
class test_csc(_test_cs, _test_vert_slicing, ScipyTestCase):
def check_empty(self): """Test manipulating empty matrices. Fails in SciPy SVN <= r1768 """ # This test should be made global (in _test_cs), but first we # need a uniform argument order / syntax for constructing an # empty sparse matrix. (coo_matrix is currently different). shape = (5, 5) for mytype in [float32, float64, complex64, complex128]: a = self.spmatrix(shape, dtype=mytype) b = a + a c = 2 * a d = a + a.tocsc() e = a * a.tocoo() assert_equal(e.A, a.A*a.A) # These fail in all revisions <= r1768: assert(e.dtype.type == mytype) assert(e.A.dtype.type == mytype)
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class test_dok(_test_cs):
class test_dok(_test_cs, ScipyTestCase):
def check_empty(self): """Test manipulating empty matrices. Fails in SciPy SVN <= r1768 """ # This test should be made global (in _test_cs), but first we # need a uniform argument order / syntax for constructing an # empty sparse matrix. (coo_matrix is currently different). shape = (5, 5) for mytype in [float32, float64, complex64, complex128]: a = self.spmatrix(shape, dtype=mytype) b = a + a c = 2 * a d = a + a.tocsc() e = a * a.tocoo() assert_equal(e.A, a.A*a.A) assert(e.dtype.type == mytype) assert(e.A.dtype.type == mytype)
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
class test_lil(_test_cs, _test_horiz_slicing):
class test_lil(_test_cs, _test_horiz_slicing, ScipyTestCase):
def check_set_slice(self): """Test for slice functionality (EJS)""" A = dok_matrix((5,10)) B = zeros((5,10), float) A[:,0] = 1 B[:,0] = 1 assert_array_equal(A.todense(), B) A[1,:] = 2 B[1,:] = 2 assert_array_equal(A.todense(), B) A[:,:] = 3 B[:,:] = 3 assert_array_equal(A.todense(), B) A[1:5, 3] = 4 B[1:5, 3] = 4 assert_array_equal(A.todense(), B) A[1, 3:6] = 5 B[1, 3:6] = 5 assert_array_equal(A.todense(), B) A[1:4, 3:6] = 6 B[1:4, 3:6] = 6 assert_array_equal(A.todense(), B) A[1, 3:10:3] = 7 B[1, 3:10:3] = 7 assert_array_equal(A.todense(), B) A[1:5, 0] = range(1,5) B[1:5, 0] = range(1,5) assert_array_equal(A.todense(), B) A[0, 1:10:2] = xrange(1,10,2) B[0, 1:10:2] = xrange(1,10,2) assert_array_equal(A.todense(), B) caught = 0 # The next 6 commands should raise exceptions try: A[0,0] = range(100) except TypeError: caught += 1 try: A[0,0] = arange(100) except TypeError: caught += 1 try: A[0,:] = range(100) except ValueError: caught += 1 try: A[:,1] = range(100) except ValueError: caught += 1 try: A[:,1] = A.copy() except: caught += 1 try: A[:,-1] = range(5) except IndexError: caught += 1 assert caught == 6
6629c0b7aeb5a52e13a6a827d4efca3e5b354615 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/6629c0b7aeb5a52e13a6a827d4efca3e5b354615/test_sparse.py
totalname = name apath, basename = os.path.split(name) name = name + ".ps"
if ignore == '.eps': totalname = name else: totalname = name + ignore apath, basename = os.path.split(totalname) name = totalname + ".ps"
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the project GNU Ghostscript program and will place a bitmap image in the postscript file. Any hardcopy file associated with the current window is first closed, but the default hardcopy file is unaffected. As a side effect, legends are turned off and color table dumping is turned on for the current window. SEE ALSO: window, fma, hcp, hcp_finish, plg """ import os name,ignore = os.path.splitext(name) totalname = name apath, basename = os.path.split(name) name = name + ".ps" window (hcp = name, dump = 1, legends = 0) hcp () window (hcp="") res = 1 if epsi: res = os.system ("ps2epsi " + name) if not res: os.remove(name) os.rename ("%s.epsi" % basename, "%s.eps" % totalname) else: os.rename("%s.ps" % totalname, "%s.eps" % totalname) if pdf: os.system("epstopdf %s.eps" % totalname)
701bf46873e09577172ce8d5a42e8183f5f54667 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/701bf46873e09577172ce8d5a42e8183f5f54667/gist.py
res = os.system ("ps2epsi " + name)
res = os.system ("ps2epsi " + totalname)
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the project GNU Ghostscript program and will place a bitmap image in the postscript file. Any hardcopy file associated with the current window is first closed, but the default hardcopy file is unaffected. As a side effect, legends are turned off and color table dumping is turned on for the current window. SEE ALSO: window, fma, hcp, hcp_finish, plg """ import os name,ignore = os.path.splitext(name) totalname = name apath, basename = os.path.split(name) name = name + ".ps" window (hcp = name, dump = 1, legends = 0) hcp () window (hcp="") res = 1 if epsi: res = os.system ("ps2epsi " + name) if not res: os.remove(name) os.rename ("%s.epsi" % basename, "%s.eps" % totalname) else: os.rename("%s.ps" % totalname, "%s.eps" % totalname) if pdf: os.system("epstopdf %s.eps" % totalname)
701bf46873e09577172ce8d5a42e8183f5f54667 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/701bf46873e09577172ce8d5a42e8183f5f54667/gist.py
os.remove(name)
os.remove(totalname)
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the project GNU Ghostscript program and will place a bitmap image in the postscript file. Any hardcopy file associated with the current window is first closed, but the default hardcopy file is unaffected. As a side effect, legends are turned off and color table dumping is turned on for the current window. SEE ALSO: window, fma, hcp, hcp_finish, plg """ import os name,ignore = os.path.splitext(name) totalname = name apath, basename = os.path.split(name) name = name + ".ps" window (hcp = name, dump = 1, legends = 0) hcp () window (hcp="") res = 1 if epsi: res = os.system ("ps2epsi " + name) if not res: os.remove(name) os.rename ("%s.epsi" % basename, "%s.eps" % totalname) else: os.rename("%s.ps" % totalname, "%s.eps" % totalname) if pdf: os.system("epstopdf %s.eps" % totalname)
701bf46873e09577172ce8d5a42e8183f5f54667 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/701bf46873e09577172ce8d5a42e8183f5f54667/gist.py
0.51053920]),8)
0.51053919]),8)
def check_airy(self):
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
for n in range(4):
for n in range(2):
def check_airye(self):
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
assert_array_almost_equal(a,b1,5)
for n in range(2,4): b1[n] = b[n]*exp(-abs(real(2.0/3.0*0.01*sqrt(0.01)))) assert_array_almost_equal(a,b1,6)
def check_airye(self):
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
numstring = arange(0,2.2,.1)
numstring = arange(0,2.21,.1)
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,array([3.,6.,9.,12., 15.,18.,21.,24.,27.])) numstringc = arange(3.3,27,4) assert_array_equal(numstringc,array([3.3,7.3,11.3,15.3, 19.3,23.3]))
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
2.,2.1]))
2.,2.1,2.2]))
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,array([3.,6.,9.,12., 15.,18.,21.,24.,27.])) numstringc = arange(3.3,27,4) assert_array_equal(numstringc,array([3.3,7.3,11.3,15.3, 19.3,23.3]))
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
assert_array_equal(numstringb,array([3.,6.,9.,12., 15.,18.,21.,24.,27.]))
assert_array_equal(numstringb,array([3,6,9,12, 15,18,21,24]))
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,array([3.,6.,9.,12., 15.,18.,21.,24.,27.])) numstringc = arange(3.3,27,4) assert_array_equal(numstringc,array([3.3,7.3,11.3,15.3, 19.3,23.3]))
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
assert_array_equal(a,z)
assert_array_equal(a,x)
def check_array(self): x = array([1,2,3,4]) y = array([1,2,3,4]) z = x*y assert_array_equal(z,array([1,4,9,16])) a = arange(1,5,1) assert_array_equal(a,z)
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
suites.append( unittest.makeSuite(test_airy,'check_') ) suites.append( unittest.makeSuite(test_airye,'check_') ) suites.append( unittest.makeSuite(test_arange,'check_') )
def test_suite(level=1): suites = [] if level > 0:
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
suites.append( unittest.makeSuite(test_array,'check_') )
def test_suite(level=1): suites = [] if level > 0:
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
def test_suite(level=1): suites = [] if level > 0:
1c136da30cb76cb9a2ee8c41c758d3b40c779b5b /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/1c136da30cb76cb9a2ee8c41c758d3b40c779b5b/test_basic.py
def resize1d(arr, newlen): old = len(arr) new = zeros((newlen,),arr.typecode()) new[:old] = arr return new
8df110dd1fa965e65fcb0c5bb92bcf9ed5376850 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/8df110dd1fa965e65fcb0c5bb92bcf9ed5376850/Sparse.py
'sss':[5,"Symmetric Sparse Skyline"],
'sss':[5,"Symmetric Sparse Skyline"],
def resize1d(arr, newlen): old = len(arr) new = zeros((newlen,),arr.typecode()) new[:old] = arr return new
8df110dd1fa965e65fcb0c5bb92bcf9ed5376850 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/8df110dd1fa965e65fcb0c5bb92bcf9ed5376850/Sparse.py
def _convert_data(data1,data2,newtype): if data1.typecode() != newtype: data1 = data1.astype(newtype) if data2.typecode() != newtype: data2 = data2.astype(newtype) return data1, data2
8df110dd1fa965e65fcb0c5bb92bcf9ed5376850 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/8df110dd1fa965e65fcb0c5bb92bcf9ed5376850/Sparse.py
s = asarray(s) if s.typecode() not in 'fdFD': s = s*1.0
def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csc') if isinstance(s,spmatrix): if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools,s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif isinstance(s,type(3)): M=s N=ij self.data = zeros((nzmax,),typecode) self.rowind = zeros((nzmax,),'i') self.indptr = zeros((N+1,),'i') self.shape = (M,N) elif (isinstance(s,ArrayType) or \ isinstance(s,type([]))): s = asarray(s) if (rank(s) == 2): # converting from a full array M, N = s.shape s = asarray(s) if s.typecode() not in 'fdFD': s = s*1.0 typecode = s.typecode() func = getattr(sparsetools,_transtabl[typecode]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,),typecode) rowa = zeros((nnz,),'i') ptra = zeros((N+1,),'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz)
8df110dd1fa965e65fcb0c5bb92bcf9ed5376850 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/8df110dd1fa965e65fcb0c5bb92bcf9ed5376850/Sparse.py
a = spmatrix(arange(1,9),[0,1,1,2,2,3,3,4],[0,1,3,0,2,3,4,4])
a = csc_matrix(arange(1,9),ij=transpose([[0,1,1,2,2,3,3,4],[0,1,3,0,2,3,4,4]]))
def lu_factor(A, permc_spec=2, diag_pivot_thresh=1.0, drop_tol=0.0, relax=1, panel_size=10): M,N = A.shape if (M != N): raise ValueError, "Can only factor square matrices." csc = A.tocsc() gstrf = eval('_superlu.' + csc.ftype + 'gstrf') return gstrf(N,csc.nnz,csc.data,csc.rowind,csc.indptr,permc_spec, diag_pivot_thresh, drop_tol, relax, panel_size)
8df110dd1fa965e65fcb0c5bb92bcf9ed5376850 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/8df110dd1fa965e65fcb0c5bb92bcf9ed5376850/Sparse.py
xplt.plot(x0,y0,type,x1,y1,type,hold=1)
plot(x0,y0,type,x1,y1,type,hold=1)
def axes(type='b|'): vals = gist.limits() x0 = [vals[0],vals[1]] y0 = [0,0] x1 = [0,0] y1 = [vals[2], vals[3]] xplt.plot(x0,y0,type,x1,y1,type,hold=1)
650923c5febe6d0f55f399a87a250ba0edb3dd6e /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/650923c5febe6d0f55f399a87a250ba0edb3dd6e/Mplot.py
hist = scipy.histogram
from scipy.stats import histogram as hist
def histogram(data,nbins=80,range=None,ntype=0,bar=1,bwidth=0.8,bcolor=0): """Plot a histogram. ntype is the normalization type. Use ntype == 2 to compare with probability density function. """ h = SSH.histogram(data,nbins,range) if ntype == 1: h.normalize() elif ntype == 2: h.normalizeArea() if bar: barplot(h[:,0],h[:,1],width=bwidth,color=bcolor) else: plot(h[:,0],h[:,1]) return h
7b561c3e05c41abc94290c9f55f0c1d8584fce0d /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/7b561c3e05c41abc94290c9f55f0c1d8584fce0d/Mplot.py
approx_grad = False,
approx_grad=0,
def fmin_l_bfgs_b(func, x0, fprime=None, args=(), approx_grad = False, bounds=None, m=10, factr=1e7, pgtol=1e-5, epsilon=1e-8, iprint=-1, maxfun=15000): """ Minimize a function func using the L-BFGS-B algorithm. Arguments: func -- function to minimize. Called as func(x, *args) x0 -- initial guess to minimum fprime -- gradient of func. If None, then func returns the function value and the gradient ( f, g = func(x, *args) ), unless approx_grad is True then func returns only f. Called as fprime(x, *args) args -- arguments to pass to function approx_grad -- if true, approximate the gradient numerically and func returns only function value. bounds -- a list of (min, max) pairs for each element in x, defining the bounds on that parameter. Use None for one of min or max when there is no bound in that direction m -- the maximum number of variable metric corrections used to define the limited memory matrix. (the limited memory BFGS method does not store the full hessian but uses this many terms in an approximation to it). factr -- The iteration stops when (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch where epsmch is the machine precision, which is automatically generated by the code. Typical values for factr: 1e12 for low accuracy; 1e7 for moderate accuracy; 10.0 for extremely high accuracy. pgtol -- The iteration will stop when max{|proj g_i | i = 1, ..., n} <= pgtol where pg_i is the ith component of the projected gradient. epsilon -- step size used when approx_grad is true, for numerically calculating the gradient iprint -- controls the frequency of output. <0 means no output. maxfun -- maximum number of function evaluations. Returns: x, f, d = fmin_lbfgs_b(func, x0, ...) x -- position of the minimum f -- value of func at the minimum d -- dictionary of information from routine d['warnflag'] is 0 if converged, 1 if too many function evaluations, 2 if stopped for another reason, given in d['task'] d['grad'] is the gradient at the minimum (should be 0 ish) d['funcalls'] is the number of function calls made. License of L-BFGS-B (Fortran code) ================================== The version included here (in fortran code) is 2.1 (released in 1997). It was written by Ciyou Zhu, Richard Byrd, and Jorge Nocedal <[email protected]>. It carries the following condition for use: This software is freely available, but we expect that all publications describing work using this software , or all commercial products using it, quote at least one of the references given below. References * R. H. Byrd, P. Lu and J. Nocedal. A Limited Memory Algorithm for Bound Constrained Optimization, (1995), SIAM Journal on Scientific and Statistical Computing , 16, 5, pp. 1190-1208. * C. Zhu, R. H. Byrd and J. Nocedal. L-BFGS-B: Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization (1997), ACM Transactions on Mathematical Software, Vol 23, Num. 4, pp. 550 - 560. """ n = len(x0) if bounds is None: bounds = [(None,None)] * n if len(bounds) != n: raise ValueError('length of x0 != length of bounds') if approx_grad: def func_and_grad(x): f = func(x, *args) g = approx_fprime(x, func, epsilon, *args) return f, g elif fprime is None: def func_and_grad(x): f, g = func(x, *args) return f, g else: def func_and_grad(x): f = func(x, *args) g = fprime(x, *args) return f, g nbd = NA.zeros((n,), NA.Int32) low_bnd = NA.zeros((n,), NA.Float) upper_bnd = NA.zeros((n,), NA.Float) bounds_map = {(None, None): 0, (1, None) : 1, (1, 1) : 2, (None, 1) : 3} for i in range(0, n): l,u = bounds[i] if l is not None: low_bnd[i] = l l = 1 if u is not None: upper_bnd[i] = u u = 1 nbd[i] = bounds_map[l, u] x = NA.array(x0) f = NA.array(0.0, NA.Float64) g = NA.zeros((n,), NA.Float64) wa = NA.zeros((2*m*n+4*n + 12*m**2 + 12*m,), NA.Float64) iwa = NA.zeros((3*n,), NA.Int32) task = NA.zeros((60,), NA.Character) csave = NA.zeros((60,), NA.Character) lsave = NA.zeros((4,), NA.Int32) isave = NA.zeros((44,), NA.Int32) dsave = NA.zeros((29,), NA.Float64) task[:] = 'START' n_function_evals = 0 while 1:
e8cf5e3ae8a7210059a0ad2e7db3c2e41cef4ca9 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/e8cf5e3ae8a7210059a0ad2e7db3c2e41cef4ca9/lbfgsb.py
x, f, d = fmin_l_bfgs_b(func, x0, approx_grad=True,
x, f, d = fmin_l_bfgs_b(func, x0, approx_grad=1,
def grad(x): g = NA.zeros(x.shape, NA.Float) t1 = x[1] - x[0]**2 g[0] = 2*(x[0]-1) - 16*x[0]*t1 for i in range(1, g.shape[0]-1): t2 = t1 t1 = x[i+1] - x[i]**2 g[i] = 8*t2 - 16*x[i]*t1 g[-1] = 8*t1 return g
e8cf5e3ae8a7210059a0ad2e7db3c2e41cef4ca9 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/e8cf5e3ae8a7210059a0ad2e7db3c2e41cef4ca9/lbfgsb.py
"""Convolve two N-dimensional arrays using FFT. SEE convolve
"""Convolve two N-dimensional arrays using FFT. See convolve.
def fftconvolve(in1, in2, mode="full"): """Convolve two N-dimensional arrays using FFT. SEE convolve """ s1 = array(in1.shape) s2 = array(in2.shape) if (s1.dtype.char in ['D','F']) or (s2.dtype.char in ['D', 'F']): cmplx=1 else: cmplx=0 size = s1+s2-1 IN1 = fftn(in1,size) IN1 *= fftn(in2,size) ret = ifftn(IN1) del IN1 if not cmplx: ret = real(ret) if mode == "full": return ret elif mode == "same": if product(s1) > product(s2): osize = s1 else: osize = s2 return _centered(ret,osize) elif mode == "valid": return _centered(ret,abs(s2-s1)+1)
936da8591e6b92539aeda1c0c884ca93d37a2754 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/936da8591e6b92539aeda1c0c884ca93d37a2754/signaltools.py
if (Numeric.product(kernel.shape) > Numeric.product(volume.shape)):
if (product(kernel.shape) > product(volume.shape)):
def convolve(in1, in2, mode='full'): """Convolve two N-dimensional arrays. Description: Convolve in1 and in2 with output size determined by mode. Inputs: in1 -- an N-dimensional array. in2 -- an array with the same number of dimensions as in1. mode -- a flag indicating the size of the output 'valid' (0): The output consists only of those elements that are computed by scaling the larger array with all the values of the smaller array. 'same' (1): The output is the same size as the largest input centered with respect to the 'full' output. 'full' (2): The output is the full discrete linear convolution of the inputs. (Default) Outputs: (out,) out -- an N-dimensional array containing a subset of the discrete linear convolution of in1 with in2. """ volume = asarray(in1) kernel = asarray(in2) if rank(volume) == rank(kernel) == 0: return volume*kernel if (Numeric.product(kernel.shape) > Numeric.product(volume.shape)): temp = kernel kernel = volume volume = temp del temp slice_obj = [slice(None,None,-1)]*len(kernel.shape) val = _valfrommode(mode) return sigtools._correlateND(volume,kernel[slice_obj],val)
936da8591e6b92539aeda1c0c884ca93d37a2754 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/936da8591e6b92539aeda1c0c884ca93d37a2754/signaltools.py
domain = Numeric.ones(kernel_size) numels = Numeric.product(kernel_size)
domain = ones(kernel_size) numels = product(kernel_size)
def medfilt(volume,kernel_size=None): """Perform a median filter on an N-dimensional array. Description: Apply a median filter to the input array using a local window-size given by kernel_size. Inputs: in -- An N-dimensional input array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of kernel_size should be odd. If kernel_size is a scalar, then this scalar is used as the size in each dimension. Outputs: (out,) out -- An array the same size as input containing the median filtered result. """ volume = asarray(volume) if kernel_size is None: kernel_size = [3] * len(volume.shape) kernel_size = asarray(kernel_size) if len(kernel_size.shape) == 0: kernel_size = [kernel_size.item()] * len(volume.shape) kernel_size = asarray(kernel_size) for k in range(len(volume.shape)): if (kernel_size[k] % 2) != 1: raise ValueError, "Each element of kernel_size should be odd." domain = Numeric.ones(kernel_size) numels = Numeric.product(kernel_size) order = int(numels/2) return sigtools._order_filterND(volume,domain,order)
936da8591e6b92539aeda1c0c884ca93d37a2754 /local1/tlutelli/issta_data/temp/all_python//python/2006_temp/2006/12971/936da8591e6b92539aeda1c0c884ca93d37a2754/signaltools.py