rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
rows = zip(*(map(converter._loose_call, map(itemgetter(i), rows)) for (i, converter) in enumerate(converters))) else: rows = zip(*(map(converter._strict_call, map(itemgetter(i), rows)) for (i, converter) in enumerate(converters))) | rows = zip(*[map(converter._loose_call, map(itemgetter(i), rows)) for (i, converter) in enumerate(converters)]) else: rows = zip(*[map(converter._strict_call, map(itemgetter(i), rows)) for (i, converter) in enumerate(converters)]) | def genfromtxt(fname, dtype=float, comments=asbytes('#'), delimiter=None, skiprows=0, skip_header=0, skip_footer=0, converters=None, missing=asbytes(''), missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, autostrip=False, case_sensitive=True, defaultfmt="f%i", unpack... |
case PyArray_BOOL: *(npy_bool *)(arr->data)=((*v).r!=0 && (*v).i!=0)); break;\\ case PyArray_UBYTE: *(unsigned char *)(arr->data)=(*v).r; break;\\ case PyArray_BYTE: *(signed char *)(arr->data)=(*v).r; break;\\ case PyArray_SHORT: *(short *)(arr->data)=(*v).r; break;\\ | case PyArray_BOOL: *(npy_bool *)(arr->data)=((*v).r!=0 && (*v).i!=0); break;\\ | #ifdef HAVE_LONG_LONG |
assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int32)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(... | self._check_ldexp(np.int8) self._check_ldexp(np.int16) self._check_ldexp(np.int32) self._check_ldexp('i') self._check_ldexp('l') def test_ldexp_overflow(self): imax = np.iinfo(np.dtype('l')).max imin = np.iinfo(np.dtype('l')).min assert_equal(ncu.ldexp(2., imax), np.inf) assert_equal(ncu.ldexp(2., imin), 0) | def test_ldexp(self): assert_almost_equal(ncu.ldexp(2., 3), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int32)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(3, np.int16)), 16.)... |
results = lapack_routine('L', n, a, m, 0) | results = lapack_routine(_L, n, a, m, 0) | def cholesky(a): """ Cholesky decomposition. Return the Cholesky decomposition, `L * L.H`, of the square matrix `a`, where `L` is lower-triangular and .H is the conjugate transpose operator (which is the ordinary transpose if `a` is real-valued). `a` must be Hermitian (symmetric if real-valued) and positive-definite.... |
results = lapack_routine('N', 'N', n, a, n, w, | results = lapack_routine(_N, _N, n, a, n, w, | def eigvals(a): """ Compute the eigenvalues of a general matrix. Main difference between `eigvals` and `eig`: the eigenvectors aren't returned. Parameters ---------- a : array_like, shape (M, M) A complex- or real-valued matrix whose eigenvalues will be computed. Returns ------- w : ndarray, shape (M,) The eigenvalu... |
results = lapack_routine('N', 'N', n, a, n, wr, wi, | results = lapack_routine(_N, _N, n, a, n, wr, wi, | def eigvals(a): """ Compute the eigenvalues of a general matrix. Main difference between `eigvals` and `eig`: the eigenvectors aren't returned. Parameters ---------- a : array_like, shape (M, M) A complex- or real-valued matrix whose eigenvalues will be computed. Returns ------- w : ndarray, shape (M,) The eigenvalu... |
results = lapack_routine('N', UPLO, n, a, n, w, work, -1, | results = lapack_routine(_N, UPLO, n, a, n, w, work, -1, | def eigvalsh(a, UPLO='L'): """ Compute the eigenvalues of a Hermitian or real symmetric matrix. Main difference from eigh: the eigenvectors are not computed. Parameters ---------- a : array_like, shape (M, M) A complex- or real-valued matrix whose eigenvalues are to be computed. UPLO : {'L', 'U'}, optional Specifies ... |
results = lapack_routine('N', UPLO, n, a, n, w, work, lwork, | results = lapack_routine(_N, UPLO, n, a, n, w, work, lwork, | def eigvalsh(a, UPLO='L'): """ Compute the eigenvalues of a Hermitian or real symmetric matrix. Main difference from eigh: the eigenvectors are not computed. Parameters ---------- a : array_like, shape (M, M) A complex- or real-valued matrix whose eigenvalues are to be computed. UPLO : {'L', 'U'}, optional Specifies ... |
results = lapack_routine('N', 'V', n, a, n, w, | results = lapack_routine(_N, _V, n, a, n, w, | def eig(a): """ Compute the eigenvalues and right eigenvectors of a square array. Parameters ---------- a : array_like, shape (M, M) A square array of real or complex elements. Returns ------- w : ndarray, shape (M,) The eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ord... |
results = lapack_routine('N', 'V', n, a, n, wr, wi, | results = lapack_routine(_N, _V, n, a, n, wr, wi, | def eig(a): """ Compute the eigenvalues and right eigenvectors of a square array. Parameters ---------- a : array_like, shape (M, M) A square array of real or complex elements. Returns ------- w : ndarray, shape (M,) The eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ord... |
results = lapack_routine('V', UPLO, n, a, n, w, work, -1, | results = lapack_routine(_V, UPLO, n, a, n, w, work, -1, | def eigh(a, UPLO='L'): """ Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix. Returns two objects, a 1-D array containing the eigenvalues of `a`, and a 2-D square array or matrix (depending on the input type) of the corresponding eigenvectors (in columns). Parameters ---------- a : array_like... |
results = lapack_routine('V', UPLO, n, a, n, w, work, lwork, | results = lapack_routine(_V, UPLO, n, a, n, w, work, lwork, | def eigh(a, UPLO='L'): """ Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix. Returns two objects, a 1-D array containing the eigenvalues of `a`, and a 2-D square array or matrix (depending on the input type) of the corresponding eigenvectors (in columns). Parameters ---------- a : array_like... |
option = 'A' | option = _A | def svd(a, full_matrices=1, compute_uv=1): """ Singular Value Decomposition. Factors the matrix ``a`` into ``u * np.diag(s) * v``, where ``u`` and ``v`` are unitary (i.e., ``u.H = inv(u)`` and similarly for ``v``) and ``s`` is a 1-D array of ``a``'s singular values. Note that, in the literature, it is common to see t... |
option = 'S' | option = _S | def svd(a, full_matrices=1, compute_uv=1): """ Singular Value Decomposition. Factors the matrix ``a`` into ``u * np.diag(s) * v``, where ``u`` and ``v`` are unitary (i.e., ``u.H = inv(u)`` and similarly for ``v``) and ``s`` is a 1-D array of ``a``'s singular values. Note that, in the literature, it is common to see t... |
option = 'N' | option = _N | def svd(a, full_matrices=1, compute_uv=1): """ Singular Value Decomposition. Factors the matrix ``a`` into ``u * np.diag(s) * v``, where ``u`` and ``v`` are unitary (i.e., ``u.H = inv(u)`` and similarly for ``v``) and ``s`` is a 1-D array of ``a``'s singular values. Note that, in the literature, it is common to see t... |
return self._c_arch_flags() | return [] | def get_flags_arch(self): return self._c_arch_flags() |
dtype=[('name', 'S5'),('col2',strtype)]) | dtype= mydtype) | def test_sort_order(self): # Test sorting an array with fields x1=np.array([21,32,14]) x2=np.array(['my','first','name']) x3=np.array([3.1,4.5,6.2]) r=np.rec.fromarrays([x1,x2,x3],names='id,word,number') |
assert_equal(r, [('a', 1), ('c', 3), ('b', 255), ('d', 258)]) | assert_equal(r, np.array([('a', 1), ('c', 3), ('b', 255), ('d', 258)], dtype=mydtype)) | def test_sort_order(self): # Test sorting an array with fields x1=np.array([21,32,14]) x2=np.array(['my','first','name']) x3=np.array([3.1,4.5,6.2]) r=np.rec.fromarrays([x1,x2,x3],names='id,word,number') |
For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors (with complex conjugation of `a`). For N dimensions it is a sum product over the last axis of `a` and the second-to-last of `b`:: dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m]) | Note that `vdot` handles multidimensional arrays differently than `dot`: it does *not* perform a matrix product, but flattens input arguments to 1-D vectors first. Consequently, it should only be used for vectors. | >>> def add_mod5(x, y): |
Returns dot product of `a` and `b`. Can be an int, float, or | Dot product of `a` and `b`. Can be an int, float, or | >>> def add_mod5(x, y): |
Notes ----- The dot product is the summation of element wise multiplication. .. math:: a \\cdot b = \\sum_{i=1}^n a_i^*b_i = a_1^*b_1+a_2^*b_2+\\cdots+a_n^*b_n | >>> def add_mod5(x, y): | |
write_version_py() | def setup_package(): # Rewrite the version file everytime write_version_py() # Perform 2to3 if needed local_path = os.path.dirname(os.path.abspath(sys.argv[0])) src_path = local_path if sys.version_info[0] == 3: src_path = os.path.join(local_path, 'build', 'py3k') sys.path.insert(0, os.path.join(local_path, 'tools')... | |
priv.append(fname2def("decl_%s" % f)) pub.append('NPY_%s' % fname2def("decl_%s" % f)) | _add_decl(f) | def check_ieee_macros(config): priv = [] pub = [] macros = [] # XXX: hack to circumvent cpp pollution from python: python put its # config.h in the public namespace, so we have a clash for the common # functions we test. We remove every function tested by python's # autoconf, hoping their own test are correct _macros... |
def seek(self, offset, whence=0): if whence == 1: offset = self.offset + offset if whence not in [0, 1]: raise IOError, "Illegal argument" if offset < self.offset: self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) def tell(self): return self.offset | class GzipFile(gzip.GzipFile): def seek(self, offset, whence=0): if whence == 1: offset = self.offset + offset if whence not in [0, 1]: raise IOError, "Illegal argument" if offset < self.offset: self.rewind() count = offset - self.offset for i in range(count // 1024): self.read(1024) self.read(count % 1024) def t... | def seek(self, offset, whence=0): # figure out new position (we can only seek forwards) if whence == 1: offset = self.offset + offset |
f = gzip.GzipFile(f) if sys.version_info[0] >= 3: import types f.seek = types.MethodType(seek, f) f.tell = types.MethodType(tell, f) else: import new f.seek = new.instancemethod(seek, f) f.tell = new.instancemethod(tell, f) | f = GzipFile(f) elif isinstance(f, gzip.GzipFile): mode = f.mode f = GzipFile(filename=f.filename, fileobj=f.fileobj) f.mode = mode | def tell(self): return self.offset |
import gzip | def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False): """ Load data from a text file. Each row in the text file must have the same number of values. Parameters ---------- fname : file or str File or filename to read. If the filename extension is ``.gz... | |
self.failUnlessRaises(ValueError, make_array, 8, 3, 1) | self.failUnlessRaises(RuntimeError, make_array, 8, 3, 1) | def make_array(size, offset, strides): try: r = ndarray([size], dtype=int, buffer=x, offset=offset*x.itemsize) except: raise RuntimeError(getexception()) r.strides = strides=strides*x.itemsize return r |
if verbose>1: | if verbose>1 or (verbose==1 and currentfilename.lower().endswith('.pyf')): | def crackline(line,reset=0): """ reset=-1 --- initialize reset=0 --- crack the line reset=1 --- final check if mismatch of blocks occured Cracked data is saved in grouplist[0]. """ global beginpattern,groupcounter,groupname,groupcache,grouplist,gotnextfile,\ filepositiontext,currentfilename,neededmodule,expectbeg... |
stdout=subprocess.PIPE, stderr=STDOUT, | stdout=subprocess.PIPE, stderr=None, | def _get_svn_revision(self,path): """Return path's SVN revision number. """ revision = None m = None try: p = subprocess.Popen(['svnversion'], shell=True, stdout=subprocess.PIPE, stderr=STDOUT, close_fds=True) sout = p.stdout m = re.match(r'(?P<revision>\d+)', sout.read()) except: pass if m: revision = int(m.group('rev... |
'__svn_version__.py'] | '__svn_version__.py', '__hg_version__.py'] | def get_version(self, version_file=None, version_variable=None): """Try to get version string of a package. |
outmess('analyzeline: appending intent(callback) %s'\ ' to %s arguments\n' % (k,groupcache[groupcounter]['name'])) | def analyzeline(m,case,line): global groupcounter,groupname,groupcache,grouplist,filepositiontext,\ currentfilename,f77modulename,neededinterface,neededmodule,expectbegin,\ gotnextfile,previous_context block=m.group('this') if case != 'multiline': previous_context = None if expectbegin and case not in ['begin','call','... | |
groupcache[groupcounter]['args'].append(k) | if k!=groupcache[groupcounter]['name']: outmess('analyzeline: appending intent(callback) %s'\ ' to %s arguments\n' % (k,groupcache[groupcounter]['name'])) groupcache[groupcounter]['args'].append(k) | def analyzeline(m,case,line): global groupcounter,groupname,groupcache,grouplist,filepositiontext,\ currentfilename,f77modulename,neededinterface,neededmodule,expectbegin,\ gotnextfile,previous_context block=m.group('this') if case != 'multiline': previous_context = None if expectbegin and case not in ['begin','call','... |
sys.stderr.write("Unknown mode: " + repr(mode)) | sys.stderr.write("Unknown mode: " + repr(mode) + "\n") | def generate_f2py_py(build_dir): f2py_exe = 'f2py'+os.path.basename(sys.executable)[6:] if f2py_exe[-4:]=='.exe': f2py_exe = f2py_exe[:-4] + '.py' if 'bdist_wininst' in sys.argv and f2py_exe[-3:] != '.py': f2py_exe = f2py_exe + '.py' target = os.path.join(build_dir,f2py_exe) if newer(__file__,target): log.info('Creatin... |
from StringIO import StringIO | if sys.version_info[0] >= 3: from io import BytesIO else: from cStringIO import StringIO as BytesIO | def _lookfor_generate_cache(module, import_modules, regenerate): """ Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate: bool Re-generate the docstring cache... |
sys.stdout = StringIO() sys.stderr = StringIO() | sys.stdout = BytesIO() sys.stderr = BytesIO() | def _lookfor_generate_cache(module, import_modules, regenerate): """ Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate: bool Re-generate the docstring cache... |
if isnan(x): return self.special_fmt % (_nan_str,) elif isinf(x): if x > 0: return self.special_fmt % (_inf_str,) else: return self.special_fmt % ('-' + _inf_str,) | import numeric as _nc err = _nc.seterr(invalid='ignore') try: if isnan(x): return self.special_fmt % (_nan_str,) elif isinf(x): if x > 0: return self.special_fmt % (_inf_str,) else: return self.special_fmt % ('-' + _inf_str,) finally: _nc.seterr(**err) | def __call__(self, x, strip_zeros=True): if isnan(x): return self.special_fmt % (_nan_str,) elif isinf(x): if x > 0: return self.special_fmt % (_inf_str,) else: return self.special_fmt % ('-' + _inf_str,) s = self.format % x if self.large_exponent: # 3-digit exponent expsign = s[-3] if expsign == '+' or expsign == '-':... |
('i', np.float), | ('i', np.single), | def test_roundtrip(self): x = np.array([1,2,3,4,5], dtype='i4') self._check_roundtrip(x) |
x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | def test_roundtrip(self): x = np.array([1,2,3,4,5], dtype='i4') self._check_roundtrip(x) |
x = np.array([1,2,3], dtype='>i8') | x = np.array([1,2,3], dtype='>q') | def test_roundtrip(self): x = np.array([1,2,3,4,5], dtype='i4') self._check_roundtrip(x) |
x = np.array([1,2,3], dtype='<i8') | x = np.array([1,2,3], dtype='<q') | def test_roundtrip(self): x = np.array([1,2,3,4,5], dtype='i4') self._check_roundtrip(x) |
('i', np.float), | ('i', np.single), | def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.float), ('j', np.double), ('k', np.longdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?')] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... |
x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.float), ('j', np.double), ('k', np.longdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?')] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... |
assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=d:i:d:j:^g:k:4s:l:=4w:m:3x:n:?:o:}') | def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.float), ('j', np.double), ('k', np.longdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?')] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | |
assert_equal(y.strides, (90,)) assert_equal(y.itemsize, 90) | assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:}') | def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.float), ('j', np.double), ('k', np.longdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?')] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... |
assert_equal(y.strides, (102,)) assert_equal(y.itemsize, 102) | assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:}') assert_equal(y.strides, (sz,)) assert_equal(y.itemsize, sz) | def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.float), ('j', np.double), ('k', np.longdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?')] x = np.array([(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... |
x = np.array([1,2,3], dtype='>l') | x = np.array([1,2,3], dtype='>i') | def test_export_endian(self): x = np.array([1,2,3], dtype='>l') y = memoryview(x) if sys.byteorder == 'little': assert_equal(y.format, '>l') else: assert_equal(y.format, 'l') |
assert_equal(y.format, '>l') | assert_equal(y.format, '>i') | def test_export_endian(self): x = np.array([1,2,3], dtype='>l') y = memoryview(x) if sys.byteorder == 'little': assert_equal(y.format, '>l') else: assert_equal(y.format, 'l') |
assert_equal(y.format, 'l') x = np.array([1,2,3], dtype='<l') | assert_equal(y.format, 'i') x = np.array([1,2,3], dtype='<i') | def test_export_endian(self): x = np.array([1,2,3], dtype='>l') y = memoryview(x) if sys.byteorder == 'little': assert_equal(y.format, '>l') else: assert_equal(y.format, 'l') |
assert_equal(y.format, 'l') | assert_equal(y.format, 'i') | def test_export_endian(self): x = np.array([1,2,3], dtype='>l') y = memoryview(x) if sys.byteorder == 'little': assert_equal(y.format, '>l') else: assert_equal(y.format, 'l') |
assert_equal(y.format, '<l') | assert_equal(y.format, '<i') | def test_export_endian(self): x = np.array([1,2,3], dtype='>l') y = memoryview(x) if sys.byteorder == 'little': assert_equal(y.format, '>l') else: assert_equal(y.format, 'l') |
_function_signature_re = re.compile(r"[a-z_]+\(.*[,=].*\)", re.I) | _function_signature_re = re.compile(r"[a-z0-9_]+\(.*[,=].*\)", re.I) | def interp(x, xp, fp, left=None, right=None): \"\"\".... (full docstring printed)\"\"\" if isinstance(x, (float, int, number)): return compiled_interp([x], xp, fp, left, right).item() else: return compiled_interp(x, xp, fp, left, right) |
for name in found: | for name in found[::-1]: | def relevance_value(a): return relevance(a, *cache[a]) |
continue | if isinstance(v, ufunc): pass else: continue | def _lookfor_generate_cache(module, import_modules, regenerate): """ Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate: bool Re-generate the docstring cache... |
pass raise e | exc = e raise exc | def load_library(libname, loader_path): if ctypes.__version__ < '1.0.1': import warnings warnings.warn("All features of ctypes interface may not work " \ "with ctypes < 1.0.1") |
names = dtype.names | names = list(dtype.names) | def genfromtxt(fname, dtype=float, comments='#', delimiter=None, skiprows=0, skip_header=0, skip_footer=0, converters=None, missing='', missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, replace_space='_', autostrip=False, case_sensitive=True, defaultfmt="f%i", unpac... |
( | def format_template(template, **kw): return jinja.from_string(template, **kw) | |
`Source code <{{source_link}}>`__ | (`Source code <{{source_link}}>`__ {%- if html_show_formats -%} | def format_template(template, **kw): return jinja.from_string(template, **kw) |
) | def format_template(template, **kw): return jinja.from_string(template, **kw) | |
source_code=source_code) | source_code=source_code, html_show_formats=config.plot_html_show_formats) | def run(arguments, content, options, state_machine, state, lineno): if arguments and content: raise RuntimeError("plot:: directive can't have both args and content") document = state_machine.document config = document.settings.env.config options.setdefault('include-source', config.plot_include_source) # determine in... |
state_machine.insert_input( lines, state_machine.input_lines.source(0)) | state_machine.insert_input(lines, source=source_file_name) | def run(arguments, content, options, state_machine, state, lineno): if arguments and content: raise RuntimeError("plot:: directive can't have both args and content") document = state_machine.document config = document.settings.env.config options.setdefault('include-source', config.plot_include_source) # determine in... |
def __init__(self, fid): | def __init__(self, fid, own_fid=False): | def __init__(self, fid): # Import is postponed to here since zipfile depends on gzip, an optional # component of the so-called standard library. import zipfile _zip = zipfile.ZipFile(fid) self._files = _zip.namelist() self.files = [] for x in self._files: if x.endswith('.npy'): self.files.append(x[:-4]) else: self.file... |
_ZIP_PREFIX = asbytes('PK\x03\x04') N = len(format.MAGIC_PREFIX) magic = fid.read(N) fid.seek(-N, 1) if magic.startswith(_ZIP_PREFIX): return NpzFile(fid) elif magic == format.MAGIC_PREFIX: if mmap_mode: return format.open_memmap(file, mode=mmap_mode) else: return format.read_array(fid) else: try: return _cload(fid) ex... | try: _ZIP_PREFIX = asbytes('PK\x03\x04') N = len(format.MAGIC_PREFIX) magic = fid.read(N) fid.seek(-N, 1) if magic.startswith(_ZIP_PREFIX): own_fid = False return NpzFile(fid, own_fid=True) elif magic == format.MAGIC_PREFIX: if mmap_mode: return format.open_memmap(file, mode=mmap_mode) else: return format.read_array(f... | def load(file, mmap_mode=None): """ Load a pickled, ``.npy``, or ``.npz`` binary file. Parameters ---------- file : file-like object or string The file to read. It must support ``seek()`` and ``read()`` methods. If the filename extension is ``.gz``, the file is first decompressed. mmap_mode: {None, 'r+', 'r', 'w+', '... |
arr = np.asanyarray(arr) format.write_array(fid, arr) | try: arr = np.asanyarray(arr) format.write_array(fid, arr) finally: if own_fid: fid.close() | def save(file, arr): """ Save an array to a binary file in NumPy ``.npy`` format. Parameters ---------- file : file or str File or filename to which the data is saved. If file is a file-object, then the filename is unchanged. If file is a string, a ``.npy`` extension will be appended to the file name if it does not ... |
\\*args : Arguments, optional | *args : Arguments, optional | def savez(file, *args, **kwds): """ Save several arrays into a single, archive file in ``.npz`` format. If arguments are passed in with no keywords, the corresponding variable names, in the .npz file, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the ``.npz`` file will... |
\\*\\*kwds : Keyword arguments, optional | **kwds : Keyword arguments, optional | def savez(file, *args, **kwds): """ Save several arrays into a single, archive file in ``.npz`` format. If arguments are passed in with no keywords, the corresponding variable names, in the .npz file, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the ``.npz`` file will... |
Using `savez` with \\*args, the arrays are saved with default names. | Using `savez` with *args, the arrays are saved with default names. | def savez(file, *args, **kwds): """ Save several arrays into a single, archive file in ``.npz`` format. If arguments are passed in with no keywords, the corresponding variable names, in the .npz file, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the ``.npz`` file will... |
Using `savez` with \\*\\*kwds, the arrays are saved with the keyword names. | Using `savez` with **kwds, the arrays are saved with the keyword names. | def savez(file, *args, **kwds): """ Save several arrays into a single, archive file in ``.npz`` format. If arguments are passed in with no keywords, the corresponding variable names, in the .npz file, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the ``.npz`` file will... |
isstring = False | own_fh = False | def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False): """ Load data from a text file. Each row in the text file must have the same number of values. Parameters ---------- fname : file or str File or filename to read. If the filename extension is ``.gz... |
isstring = True | own_fh = True | def loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False): """ Load data from a text file. Each row in the text file must have the same number of values. Parameters ---------- fname : file or str File or filename to read. If the filename extension is ``.gz... |
if isstring: | if own_fh: | def split_line(line): """Chop off comments, strip, and split at delimiter.""" line = asbytes(line).split(comments)[0].strip() if line: return line.split(delimiter) else: return [] |
X = np.asarray(X) if X.ndim == 1: if X.dtype.names is None: X = np.atleast_2d(X).T ncol = 1 | try: X = np.asarray(X) if X.ndim == 1: if X.dtype.names is None: X = np.atleast_2d(X).T ncol = 1 else: ncol = len(X.dtype.descr) | def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n'): """ Save an array to a text file. Parameters ---------- fname : filename or file handle If the filename ends in ``.gz``, the file is automatically saved in compressed gzip format. `loadtxt` understands gzipped files transparently. X : array_like Data to... |
ncol = len(X.dtype.descr) else: ncol = X.shape[1] if type(fmt) in (list, tuple): if len(fmt) != ncol: raise AttributeError('fmt has wrong shape. %s' % str(fmt)) format = asstr(delimiter).join(map(asstr, fmt)) elif type(fmt) is str: if fmt.count('%') == 1: fmt = [fmt, ]*ncol format = delimiter.join(fmt) elif fmt.cou... | ncol = X.shape[1] if type(fmt) in (list, tuple): if len(fmt) != ncol: raise AttributeError('fmt has wrong shape. %s' % str(fmt)) format = asstr(delimiter).join(map(asstr, fmt)) elif type(fmt) is str: if fmt.count('%') == 1: fmt = [fmt, ]*ncol format = delimiter.join(fmt) elif fmt.count('%') != ncol: raise Attribute... | def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n'): """ Save an array to a text file. Parameters ---------- fname : filename or file handle If the filename ends in ``.gz``, the file is automatically saved in compressed gzip format. `loadtxt` understands gzipped files transparently. X : array_like Data to... |
if not hasattr(regexp, 'match'): regexp = re.compile(asbytes(regexp)) if not isinstance(dtype, np.dtype): dtype = np.dtype(dtype) seq = regexp.findall(file.read()) if seq and not isinstance(seq[0], tuple): newdtype = np.dtype(dtype[dtype.names[0]]) output = np.array(seq, dtype=newdtype) output.dtype = dtype else: o... | own_fh = True try: if not hasattr(regexp, 'match'): regexp = re.compile(asbytes(regexp)) if not isinstance(dtype, np.dtype): dtype = np.dtype(dtype) seq = regexp.findall(file.read()) if seq and not isinstance(seq[0], tuple): newdtype = np.dtype(dtype[dtype.names[0]]) output = np.array(seq, dtype=newdtype) output.d... | def fromregex(file, regexp, dtype): """ Construct an array from a text file, using regular expression parsing. The returned array is always a structured array, and is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields of the structured array. P... |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_posinf(self): olderr = seterr(divide='ignore') try: assert_all(isfinite(array((1.,))/0.) == 0) finally: seterr(**olderr) |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_neginf(self): olderr = seterr(divide='ignore') try: assert_all(isfinite(array((-1.,))/0.) == 0) finally: seterr(**olderr) |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_posinf(self): olderr = seterr(divide='ignore') try: assert_all(isinf(array((1.,))/0.) == 1) finally: seterr(**olderr) |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_posinf_scalar(self): olderr = seterr(divide='ignore') try: assert_all(isinf(array(1.,)/0.) == 1) finally: seterr(**olderr) |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_neginf(self): olderr = seterr(divide='ignore') try: assert_all(isinf(array((-1.,))/0.) == 1) finally: seterr(**olderr) |
olderr = seterr(divide='ignore') | olderr = seterr(divide='ignore', invalid='ignore') | def test_neginf_scalar(self): olderr = seterr(divide='ignore') try: assert_all(isinf(array(-1.)/0.) == 1) finally: seterr(**olderr) |
ret['coutput'] = m['coutput'] ret['f2py_wrapper_output'] = m['f2py_wrapper_output'] | if 'coutput' in m: ret['coutput'] = m['coutput'] if 'f2py_wrapper_output' in m: ret['f2py_wrapper_output'] = m['f2py_wrapper_output'] | def modsign2map(m): """ modulename """ if ismodule(m): ret={'f90modulename':m['name'], 'F90MODULENAME':m['name'].upper(), 'texf90modulename':m['name'].replace('_','\\_')} else: ret={'modulename':m['name'], 'MODULENAME':m['name'].upper(), 'texmodulename':m['name'].replace('_','\\_')} ret['restdoc'] = getrestdoc(m) or []... |
Return a sorted copy of an array. | Sort the array, in-place | def sort(self, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=None): """ |
axis : int or None, optional | axis : int, optional | def sort(self, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=None): """ |
fill_value : {var} Value used to fill in the masked values. If None, use the the output of minimum_fill_value(). | fill_value : {var}, optional Value used internally for the masked values. If ``fill_value`` is not None, it supersedes ``endwith``. | def sort(self, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=None): """ |
The various sorting algorithms are characterized by their average speed, worst case performance, work space size, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The three available algorithms have the following properties: =========== ======= ============= ========... | See ``sort`` for notes on the different sorting algorithms. | def sort(self, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=None): """ |
>>> a = np.array([[1,4],[3,1]]) >>> np.sort(a) array([[1, 4], [1, 3]]) >>> np.sort(a, axis=None) array([1, 1, 3, 4]) >>> np.sort(a, axis=0) array([[1, 1], [3, 4]]) Use the `order` keyword to specify a field to use when sorting a structured array: >>> dtype = [('name', 'S10'), ('height', float), ('age', int)] >>> valu... | >>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> >>> a.sort() >>> print a [1 3 5 -- --] >>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> >>> a.sort(endwith=False) >>> print a [-- -- 1 3 5] >>> a = ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0]) >>> >>> a.sort(endwith=False, fill_value=3) >>> print ... | def sort(self, axis= -1, kind='quicksort', order=None, endwith=True, fill_value=None): """ |
p2 = (n+1)/2 | p2 = (n+1)//2 | def fftshift(x,axes=None): """ Shift the zero-frequency component to the center of the spectrum. This function swaps half-spaces for all axes listed (defaults to all). Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even. Parameters ---------- x : array_like Input array. axes : int or shape tuple, o... |
p2 = n-(n+1)/2 | p2 = n-(n+1)//2 | def ifftshift(x,axes=None): """ The inverse of fftshift. Parameters ---------- x : array_like Input array. axes : int or shape tuple, optional Axes over which to calculate. Defaults to None, which shifts all axes. Returns ------- y : ndarray The shifted array. See Also -------- fftshift : Shift zero-frequency compo... |
if sys.version_info[0] >= 3: from io import BytesIO else: from cStringIO import StringIO as BytesIO | from cStringIO import StringIO | def _lookfor_generate_cache(module, import_modules, regenerate): """ Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate: bool Re-generate the docstring cache... |
sys.stdout = BytesIO() sys.stderr = BytesIO() | sys.stdout = StringIO() sys.stderr = StringIO() | def _lookfor_generate_cache(module, import_modules, regenerate): """ Generate docstring cache for given module. Parameters ---------- module : str, None, module Module for which to generate docstring cache import_modules : bool Whether to import sub-modules in packages. regenerate: bool Re-generate the docstring cache... |
_compiler_status = (bool(m.group(1)), bool(m.group(2)), bool(m.group(3))) | _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))), bool(int(m.group(3)))) | def configuration(parent_name='',top_path=None): global config from numpy.distutils.misc_util import Configuration config = Configuration('', parent_name, top_path) return config |
>>> np.spacing(1, 2) == np.finfo(np.float64).eps | >>> np.spacing(1) == np.finfo(np.float64).eps | def add_newdoc(place, name, doc): docdict['.'.join((place, name))] = doc |
\telse if (PyString_Check(obj)) | \telse if (PyString_Check(obj) || PyUnicode_Check(obj)) | #ifdef DEBUGCFUNCS |
\telse if (PyString_Check(obj)) | \telse if (PyString_Check(obj) || PyUnicode_Check(obj)) | #ifdef __sgi |
\tif (PySequence_Check(obj) && (!PyString_Check(obj))) { | \tif (PySequence_Check(obj) && !(PyString_Check(obj) || PyUnicode_Check(obj))) { | #ifdef __sgi |
assert_almost_equal(ncu.ldexp(np.array(2., np.float96), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float96), np.array(3, np.int32)), 16.) | assert_almost_equal(ncu.ldexp(np.array(2., np.longdouble), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.longdouble), np.array(3, np.int32)), 16.) | def test_ldexp(self): assert_almost_equal(ncu.ldexp(2., 3), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int16)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float32), np.array(3, np.int32)), 16.) assert_almost_equal(ncu.ldexp(np.array(2., np.float64), np.array(3, np.int16)), 16.)... |
assert_complex_equal(z**1, z) assert_complex_equal(z**2, z*z) assert_complex_equal(z**3, z*z*z) | try: assert_complex_equal(z**1, z) assert_complex_equal(z**2, z*z) assert_complex_equal(z**3, z*z*z) finally: np.seterr(**err) | def assert_complex_equal(x, y): assert_array_equal(x.real, y.real) assert_array_equal(x.imag, y.imag) |
for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp2(logxf, logyf), logzf) | try: for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp2(logxf, logyf), logzf) finally: np.seterr(**err) | def test_inf(self) : inf = np.inf x = [inf, -inf, inf, -inf, inf, 1, -inf, 1] y = [inf, inf, -inf, -inf, 1, inf, 1, -inf] z = [inf, inf, inf, -inf, inf, inf, 1, 1] for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp2(... |
for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp(logxf, logyf), logzf) | try: for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp(logxf, logyf), logzf) finally: np.seterr(**err) | def test_inf(self) : inf = np.inf x = [inf, -inf, inf, -inf, inf, 1, -inf, 1] y = [inf, inf, -inf, -inf, 1, inf, 1, -inf] z = [inf, inf, inf, -inf, inf, inf, 1, 1] for dt in ['f','d','g'] : logxf = np.array(x, dtype=dt) logyf = np.array(y, dtype=dt) logzf = np.array(z, dtype=dt) assert_equal(np.logaddexp(l... |
assert np.isnan(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not nan" % (x, y, ncu.hypot(x, y)) | err = np.seterr(invalid='ignore') try: assert np.isnan(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not nan" % (x, y, ncu.hypot(x, y)) finally: np.seterr(**err) | def assert_hypot_isnan(x, y): assert np.isnan(ncu.hypot(x, y)), "hypot(%s, %s) is %s, not nan" % (x, y, ncu.hypot(x, y)) |
assert np.spacing(one) == eps assert np.isnan(np.spacing(nan)) assert np.isnan(np.spacing(inf)) assert np.isnan(np.spacing(-inf)) assert np.spacing(t(1e30)) != 0 | try: assert np.spacing(one) == eps assert np.isnan(np.spacing(nan)) assert np.isnan(np.spacing(inf)) assert np.isnan(np.spacing(-inf)) assert np.spacing(t(1e30)) != 0 finally: np.seterr(**err) | def _test_spacing(t): one = t(1) eps = np.finfo(t).eps nan = t(np.nan) inf = t(np.inf) assert np.spacing(one) == eps assert np.isnan(np.spacing(nan)) assert np.isnan(np.spacing(inf)) assert np.isnan(np.spacing(-inf)) assert np.spacing(t(1e30)) != 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.