bugged stringlengths 4 228k | fixed stringlengths 0 96.3M | __index_level_0__ int64 0 481k |
|---|---|---|
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... | 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... | 1,100 |
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... | 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... | 1,101 |
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.do... | 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 = new.data.dtype new.ftype = _transtabl[new.dtype.char] return new else: return self.dot(other) | 1,102 |
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()... | 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 = new.data.dtype new.ftype = _transtabl[new.dtype.char] return new else: other = asarray(other) return self.transpose().dot(other... | 1,103 |
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 e... | 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 = new.data.dtype new.ftype = _transtabl[new.dtype.char] return new elif isspma... | 1,104 |
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 | def transpose(self, copy=False): M, N = self.shape new = csc_matrix((N, M), nzmax=self.nzmax, dtype=self.dtype) 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 | 1,105 |
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 | def copy(self): new = csr_matrix(self.shape, nzmax=self.nzmax, dtype=self.dtype) new.data = self.data.copy() new.colind = self.colind.copy() new.indptr = self.indptr.copy() new._check() return new | 1,106 |
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 N... | 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 N... | 1,107 |
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(itertool... | 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(itertool... | 1,108 |
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 ... | 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 ... | 1,109 |
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-s... | 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-s... | 1,110 |
def tell(self): self.file.tell() | def tell(self): return self.file.tell() | 1,111 |
def _get_namespace(self): return self.__namespace or default_namespace | def _get_namespace(self): return self.__namespace or default_namespace | 1,112 |
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 == 'wi... | 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() res = bbox_re.search(result) if res is None and sys.pla... | 1,113 |
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 == 'wi... | 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 == 'wi... | 1,114 |
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 == 'wi... | 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 == 'wi... | 1,115 |
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], ...... | defprint diff kmeans_(obs,guess,thresh=1e-5):print diff """*print diff Seeprint diff kmeansprint diff Outputs:print diff code_bookprint diff --print diff theprint diff lowestprint diff distortionprint diff codebookprint diff found.print diff avg_distprint diff --print diff theprint diff averageprint diff distanceprint ... | 1,116 |
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]])) | def check_diag(self): assert_equal(tri(4,k=1),array([[1,1,0,0], [1,1,1,0], [1,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]])) | 1,117 |
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) | 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) | 1,118 |
def _check_bdtrik(self): assert_equal(cephes.bdtrik(1,3,0.5),3.0) | def _check_bdtrik(self): assert_equal(cephes.bdtrik(1,3,0.5),3.0) | 1,119 |
def _check_chndtrix(self): assert_equal(cephes.chndtrix(0,1,0),0.0) | def check_chndtrix(self): assert_equal(cephes.chndtrix(0,1,0),0.0) | 1,120 |
def _check_gdtrib(self): assert_equal(cephes.gdtrib(1,0,1),5.0) | def _check_gdtrib(self): assert_equal(cephes.gdtrib(1,0,1),5.0) | 1,121 |
def _check_hankel1(self): cephes.hankel1(1,1) | def check_hankel1(self): cephes.hankel1(1,1) | 1,122 |
def _check_hankel1e(self): cephes.hankel1e(1,1) | def check_hankel1e(self): cephes.hankel1e(1,1) | 1,123 |
def _check_hankel2(self): cephes.hankel2(1,1) | def check_hankel2(self): cephes.hankel2(1,1) | 1,124 |
def _check_hankel2e(self): cephes.hankel2e(1,1) | def check_hankel2e(self): cephes.hankel2e(1,1) | 1,125 |
def _check_it2i0k0(self): cephes.it2i0k0(1) | def check_it2i0k0(self): cephes.it2i0k0(1) | 1,126 |
def _check_it2j0y0(self): cephes.it2j0y0(1) | def check_it2j0y0(self): cephes.it2j0y0(1) | 1,127 |
def _check_itairy(self): cephes.itairy(1) | def check_itairy(self): cephes.itairy(1) | 1,128 |
def check_ive(self): assert_equal(cephes.ive(1,0),0.0) | def _check_ive(self): assert_equal(cephes.ive(1,0),0.0) | 1,129 |
def check_jve(self): assert_equal(cephes.jve(0,0),1.0) | def _check_jve(self): assert_equal(cephes.jve(0,0),1.0) | 1,130 |
def _check_kei(self): cephes.kei(2) | def check_kei(self): cephes.kei(2) | 1,131 |
def _check_ker(self): cephes.ker(2) | def check_ker(self): cephes.ker(2) | 1,132 |
def _check_kerp(self): cephes.kerp(2) | def check_kerp(self): cephes.kerp(2) | 1,133 |
def _check_mathieu_modcem2(self): cephes.mathieu_modcem2(1,1,1) | def check_mathieu_modcem2(self): cephes.mathieu_modcem2(1,1,1) | 1,134 |
def _check_mathieu_modsem2(self): cephes.mathieu_modsem2(1,1,1) | def check_mathieu_modsem2(self): cephes.mathieu_modsem2(1,1,1) | 1,135 |
def check_modstruve(self): assert_equal(cephes.modstruve(1,0),0.0) | def _check_modstruve(self): assert_equal(cephes.modstruve(1,0),0.0) | 1,136 |
def __check_nbdtrik(self): cephes.nbdtrik(1,1,1) | def __check_nbdtrik(self): cephes.nbdtrik(1,1,1) | 1,137 |
def _check_ncfdtr(self): assert_equal(cephes.ncfdtr(1,1,1,0),0.0) | def check_ncfdtr(self): assert_equal(cephes.ncfdtr(1,1,1,0),0.0) | 1,138 |
def _check_ncfdtri(self): assert_equal(cephes.ncfdtri(1,1,1,0),0.0) | def check_ncfdtri(self): assert_equal(cephes.ncfdtri(1,1,1,0),0.0) | 1,139 |
def _check_ncfdtridfd(self): cephes.ncfdtridfd(1,0.5,0,1) | def check_ncfdtridfd(self): cephes.ncfdtridfd(1,0.5,0,1) | 1,140 |
def _check_nctdtrit(self): cephes.nctdtrit(.1,0.2,.5) | def check_nctdtrit(self): cephes.nctdtrit(.1,0.2,.5) | 1,141 |
def _check_nrdtrimn(self): assert_equal(cephes.nrdtrimn(0.5,1,1),1.0) | def check_nrdtrimn(self): assert_equal(cephes.nrdtrimn(0.5,1,1),1.0) | 1,142 |
def _check_nrdtrisd(self): assert_equal(cephes.nrdtrisd(0.5,0.5,0.5),0.0) | def check_nrdtrisd(self): assert_equal(cephes.nrdtrisd(0.5,0.5,0.5),0.0) | 1,143 |
def _check_obl_ang1(self): cephes.obl_ang1(1,1,1,0) | def check_obl_ang1(self): cephes.obl_ang1(1,1,1,0) | 1,144 |
def _check_obl_ang1_cv(self): assert_equal(cephes.obl_ang1_cv(1,1,1,1,0),(1.0,0.0)) | def _check_obl_ang1_cv(self): assert_equal(cephes.obl_ang1_cv(1,1,1,1,0),(1.0,0.0)) | 1,145 |
def _check_obl_rad1(self): cephes.obl_rad1(1,1,1,0) | def check_obl_rad1(self): cephes.obl_rad1(1,1,1,0) | 1,146 |
def _check_obl_rad1_cv(self): cephes.obl_rad1_cv(1,1,1,1,0) | def check_obl_rad1_cv(self): cephes.obl_rad1_cv(1,1,1,1,0) | 1,147 |
def _check_pbdv(self): assert_equal(cephes.pbdv(1,0),(0.0,0.0)) | def check_pbdv(self): assert_equal(cephes.pbdv(1,0),(0.0,0.0)) | 1,148 |
def _check_pbvv(self): cephes.pbvv(1,0) | def check_pbvv(self): cephes.pbvv(1,0) | 1,149 |
def _check_pdtrik(self): cephes.pdtrik(0.5,1) | def check_pdtrik(self): cephes.pdtrik(0.5,1) | 1,150 |
def _check_pro_ang1(self): cephes.pro_ang1(1,1,1,0) | def check_pro_ang1(self): cephes.pro_ang1(1,1,1,0) | 1,151 |
def _check_pro_ang1_cv(self): assert_equal(cephes.pro_ang1_cv(1,1,1,1,0),(1.0,0.0)) | def check_pro_ang1_cv(self): assert_equal(cephes.pro_ang1_cv(1,1,1,1,0),(1.0,0.0)) | 1,152 |
def check_pro_cv(self): assert_equal(cephes.pro_cv(1,1,0),2.0) | def _check_pro_cv(self): assert_equal(cephes.pro_cv(1,1,0),2.0) | 1,153 |
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) | 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) | 1,154 |
def check_smirnov(self): assert_equal(cephes.smirnov(1,1),0.0) | def check_smirnov(self): assert_equal(cephes.smirnov(1,1),0.0) | 1,155 |
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) | 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) | 1,156 |
def _check_stdtridf(self): cephes.stdtridf(0.7,1) | def check_stdtridf(self): cephes.stdtridf(0.7,1) | 1,157 |
def _check_stdtrit(self): cephes.stdtrit(1,0.7) | def check_stdtrit(self): cephes.stdtrit(1,0.7) | 1,158 |
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(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... | 1,159 |
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... | def _sph_harmonic(m,n,theta,phi): """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 | 1,160 |
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... | 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[-1, -1] val *= sqrt((2*n+1)/4.0/pi) val *= exp(0.5*(gammaln(n-m+1)-gammaln(n+m+1))) val *= ... | 1,161 |
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 t... | 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 t... | 1,162 |
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 = ... | 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 = ... | 1,163 |
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 = ... | 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 = ... | 1,164 |
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 = (ocs... | defelse: raise ValueError, "dense array must have rank 1 or 2" __init__(self,else: raise ValueError, "dense array must have rank 1 or 2" arg1,else: raise ValueError, "dense array must have rank 1 or 2" dims=None,else: raise ValueError, "dense array must have rank 1 or 2" nzmax=100,else: raise ValueError, "dense array m... | 1,165 |
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" | 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... | 1,166 |
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" | 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" | 1,167 |
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(... | 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(... | 1,168 |
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()) | 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()) | 1,169 |
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()) | 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()) | 1,170 |
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()) | 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()) | 1,171 |
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, float6... | 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, float6... | 1,172 |
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, float6... | 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, float6... | 1,173 |
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 asser... | 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 asser... | 1,174 |
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 proje... | 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 proje... | 1,175 |
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 proje... | 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 proje... | 1,176 |
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 proje... | 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 proje... | 1,177 |
def check_airy(self): | def check_airy(self): | 1,178 |
def check_airye(self): | def check_airye(self): | 1,179 |
def check_airye(self): | def check_airye(self): | 1,180 |
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,ar... | def check_arange(self): numstring = arange(0,2.21,.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,a... | 1,181 |
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,ar... | 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,2.2])) 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(numstring... | 1,182 |
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,ar... | 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,ar... | 1,183 |
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) | 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) | 1,184 |
def test_suite(level=1): suites = [] if level > 0: | def test_suite(level=1): suites = [] if level > 0: | 1,185 |
def test_suite(level=1): suites = [] if level > 0: | defsuites.append( unittest.makeSuite(test_array,'check_') ) test_suite(level=1):suites.append( unittest.makeSuite(test_array,'check_') ) suitessuites.append( unittest.makeSuite(test_array,'check_') ) =suites.append( unittest.makeSuite(test_array,'check_') ) []suites.append( unittest.makeSuite(test_array,'check_') ) ifs... | 1,186 |
def test_suite(level=1): suites = [] if level > 0: | def test_suite(level=1): suites = [] if level > 0: | 1,187 |
def resize1d(arr, newlen): old = len(arr) new = zeros((newlen,),arr.typecode()) new[:old] = arr return new | defresize1d(arr,newlen):old=len(arr)new=zeros((newlen,),arr.typecode())new[:old]=arrreturnnew | 1,188 |
def resize1d(arr, newlen): old = len(arr) new = zeros((newlen,),arr.typecode()) new[:old] = arr return new | def resize1d(arr, newlen): old = len(arr) new = zeros((newlen,),arr.typecode()) new[:old] = arr return new | 1,189 |
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 | def_convert_data(data1,data2,newtype):ifdata1.typecode()!=newtype:data1=data1.astype(newtype)ifdata2.typecode()!=newtype:data2=data2.astype(newtype)returndata1,data2 | 1,190 |
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: ... | 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: ... | 1,191 |
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... | 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... | 1,192 |
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) | def axes(type='b|'): vals = gist.limits() x0 = [vals[0],vals[1]] y0 = [0,0] x1 = [0,0] y1 = [vals[2], vals[3]] plot(x0,y0,type,x1,y1,type,hold=1) | 1,193 |
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... | 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,194 |
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 ... | def fmin_l_bfgs_b(func, x0, fprime=None, args=(), approx_grad=0, 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 fprim... | 1,195 |
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 | 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 | 1,196 |
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 ... | 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... | 1,197 |
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 outpu... | 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 outpu... | 1,198 |
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 filt... | 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 filt... | 1,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.