diff options
author | Jarrod Millman <millman@berkeley.edu> | 2008-02-08 10:54:01 +0000 |
---|---|---|
committer | Jarrod Millman <millman@berkeley.edu> | 2008-02-08 10:54:01 +0000 |
commit | c66da19ab8bd6ad7f035b77026bbd703eab199d4 (patch) | |
tree | 55136b4e38d5991dbd68d4e0984c645f11cefce7 /numpy/lib | |
parent | 0b7800b455b3aaf50cb83a224f283e72f1dea951 (diff) | |
download | numpy-c66da19ab8bd6ad7f035b77026bbd703eab199d4.tar.gz |
ran reindent
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/arraysetops.py | 2 | ||||
-rw-r--r-- | numpy/lib/format.py | 5 | ||||
-rw-r--r-- | numpy/lib/io.py | 50 | ||||
-rw-r--r-- | numpy/lib/scimath.py | 28 | ||||
-rw-r--r-- | numpy/lib/setupscons.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_format.py | 28 | ||||
-rw-r--r-- | numpy/lib/utils.py | 16 |
7 files changed, 60 insertions, 71 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 1d99f7a97..f8304cced 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -207,7 +207,7 @@ def setmember1d( ar1, ar2 ): b1 = nm.zeros( ar1.shape, dtype = nm.int8 ) b2 = nm.ones( ar2.shape, dtype = nm.int8 ) tt = nm.concatenate( (b1, b2) ) - + # We need this to be a stable sort, so always use 'mergesort' here. The # values from the first array should always come before the values from the # second array. diff --git a/numpy/lib/format.py b/numpy/lib/format.py index bb58c5c61..10d6d27b7 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -227,7 +227,7 @@ def read_array_header_1_0(fp): raise ValueError("Header does not contain the correct keys: %r" % (keys,)) # Sanity-check the values. - if (not isinstance(d['shape'], tuple) or + if (not isinstance(d['shape'], tuple) or not numpy.all([isinstance(x, int) for x in d['shape']])): raise ValueError("shape is not valid: %r" % (d['shape'],)) if not isinstance(d['fortran_order'], bool): @@ -407,6 +407,3 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, mode=mode, offset=offset) return marray - - - diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 077bc797b..aa832487f 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -19,8 +19,8 @@ from _compiled_base import packbits, unpackbits _file = file class BagObj(object): - """A simple class that converts attribute lookups to - getitems on the class passed in. + """A simple class that converts attribute lookups to + getitems on the class passed in. """ def __init__(self, obj): self._obj = obj @@ -31,8 +31,8 @@ class BagObj(object): raise AttributeError, key class NpzFile(object): - """A dictionary-like object with lazy-loading of files in the zipped - archive provided on construction. + """A dictionary-like object with lazy-loading of files in the zipped + archive provided on construction. The arrays and file strings are lazily loaded on either getitem access using obj['key'] or attribute lookup using obj.f.key @@ -54,13 +54,13 @@ class NpzFile(object): def __getitem__(self, key): # FIXME: This seems like it will copy strings around - # more than is strictly necessary. The zipfile + # more than is strictly necessary. The zipfile # will read the string and then # the format.read_array will copy the string - # to another place in memory. - # It would be better if the zipfile could read + # to another place in memory. + # It would be better if the zipfile could read # (or at least uncompress) the data - # directly into the array memory. + # directly into the array memory. member = 0 if key in self._files: member = 1 @@ -90,21 +90,21 @@ def load(file, memmap=False): memmap : bool If true, then memory-map the .npy file or unzip the .npz file into a temporary directory and memory-map each component - This has no effect for a pickle. + This has no effect for a pickle. Returns ------- result : array, tuple, dict, etc. - data stored in the file. + data stored in the file. If file contains pickle data, then whatever is stored in the pickle is returned. - If the file is .npy file, then an array is returned. - If the file is .npz file, then a dictionary-like object is returned + If the file is .npy file, then an array is returned. + If the file is .npz file, then a dictionary-like object is returned which has a filename:array key:value pair for every file in the zip. Raises ------ - IOError + IOError """ if isinstance(file, type("")): fid = _file(file,"rb") @@ -124,7 +124,7 @@ def load(file, memmap=False): elif magic == format.MAGIC_PREFIX: # .npy file return format.read_array(fid) else: # Try a pickle - try: + try: return _cload(fid) except: raise IOError, \ @@ -133,8 +133,8 @@ def load(file, memmap=False): def save(file, arr): """Save an array to a binary file (a string or file-like object). - If the file is a string, then if it does not have the .npy extension, - it is appended and a file open. + If the file is a string, then if it does not have the .npy extension, + it is appended and a file open. Data is saved to the open file in NumPy-array format @@ -144,7 +144,7 @@ def save(file, arr): ... np.save('myfile', a) a = np.load('myfile.npy') - """ + """ if isinstance(file, str): if not file.endswith('.npy'): file = file + '.npy' @@ -158,15 +158,15 @@ def save(file, arr): def savez(file, *args, **kwds): """Save several arrays into an .npz file format which is a zipped-archive of arrays - - If keyword arguments are given, then filenames are taken from the keywords. - If arguments are passed in with no keywords, then stored file names are - arr_0, arr_1, etc. + + If keyword arguments are given, then filenames are taken from the keywords. + If arguments are passed in with no keywords, then stored file names are + arr_0, arr_1, etc. """ if isinstance(file, str): if not file.endswith('.npz'): - file = file + '.npz' + file = file + '.npz' namedict = kwds for i, val in enumerate(args): @@ -190,7 +190,7 @@ def savez(file, *args, **kwds): format.write_array(fid, np.asanyarray(val)) fid.close() zip.write(filename, arcname=fname) - + zip.close() for name in todel: os.remove(name) @@ -359,7 +359,3 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): if origShape is not None: X.shape = origShape - - - - diff --git a/numpy/lib/scimath.py b/numpy/lib/scimath.py index 429eac9c8..f35c87578 100644 --- a/numpy/lib/scimath.py +++ b/numpy/lib/scimath.py @@ -93,7 +93,7 @@ def _fix_real_lt_zero(x): """Convert `x` to complex if it has real, negative components. Otherwise, output is just the array version of the input (via asarray). - + Parameters ---------- x : array_like @@ -119,7 +119,7 @@ def _fix_int_lt_zero(x): """Convert `x` to double if it has real, negative components. Otherwise, output is just the array version of the input (via asarray). - + Parameters ---------- x : array_like @@ -145,7 +145,7 @@ def _fix_real_abs_gt_1(x): """Convert `x` to complex if it has real components x_i with abs(x_i)>1. Otherwise, output is just the array version of the input (via asarray). - + Parameters ---------- x : array_like @@ -203,7 +203,7 @@ def log(x): If x contains negative inputs, the answer is computed and returned in the complex domain. - + Parameters ---------- x : array_like @@ -221,7 +221,7 @@ def log(x): Negative arguments are correctly handled (recall that for negative arguments, the identity exp(log(z))==z does not hold anymore): - + >>> log(-math.exp(1)) == (1+1j*math.pi) True """ @@ -233,7 +233,7 @@ def log10(x): If x contains negative inputs, the answer is computed and returned in the complex domain. - + Parameters ---------- x : array_like @@ -263,7 +263,7 @@ def logn(n, x): If x contains negative inputs, the answer is computed and returned in the complex domain. - + Parameters ---------- x : array_like @@ -293,7 +293,7 @@ def log2(x): If x contains negative inputs, the answer is computed and returned in the complex domain. - + Parameters ---------- x : array_like @@ -307,7 +307,7 @@ def log2(x): (We set the printing precision so the example can be auto-tested) >>> import numpy as np; np.set_printoptions(precision=4) - + >>> log2([4,8]) array([ 2., 3.]) @@ -323,7 +323,7 @@ def power(x, p): If x contains negative values, it is converted to the complex domain. If p contains negative values, it is converted to floating point. - + Parameters ---------- x : array_like @@ -332,7 +332,7 @@ def power(x, p): Returns ------- array_like - + Examples -------- (We set the printing precision so the example can be auto-tested) @@ -357,7 +357,7 @@ def arccos(x): For real x with abs(x)<=1, this returns the principal value. If abs(x)>1, the complex arccos() is computed. - + Parameters ---------- x : array_like @@ -385,7 +385,7 @@ def arcsin(x): For real x with abs(x)<=1, this returns the principal value. If abs(x)>1, the complex arcsin() is computed. - + Parameters ---------- x : array_like @@ -414,7 +414,7 @@ def arctanh(x): For real x with abs(x)<=1, this returns the principal value. If abs(x)>1, the complex arctanh() is computed. - + Parameters ---------- x : array_like diff --git a/numpy/lib/setupscons.py b/numpy/lib/setupscons.py index ab0c304d3..4f31f6e8a 100644 --- a/numpy/lib/setupscons.py +++ b/numpy/lib/setupscons.py @@ -5,7 +5,7 @@ def configuration(parent_package='',top_path=None): config = Configuration('lib',parent_package,top_path) - config.add_sconscript('SConstruct', + config.add_sconscript('SConstruct', source_files = [join('src', '_compiled_base.c')]) config.add_data_dir('tests') diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index 28e938f0f..e7b27ce94 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -21,9 +21,9 @@ Set up: ... np.complex128, ... object, ... ] - >>> + >>> >>> basic_arrays = [] - >>> + >>> >>> for scalar in scalars: ... for endian in '<>': ... dtype = np.dtype(scalar).newbyteorder(endian) @@ -36,20 +36,20 @@ Set up: ... basic.reshape((3,5)).T, ... basic.reshape((3,5))[::-1,::2], ... ]) - ... - >>> + ... + >>> >>> Pdescr = [ ... ('x', 'i4', (2,)), ... ('y', 'f8', (2, 2)), ... ('z', 'u1')] - >>> - >>> + >>> + >>> >>> PbufferT = [ ... ([3,2], [[6.,4.],[6.,4.]], 8), ... ([4,3], [[7.,5.],[7.,5.]], 9), ... ] - >>> - >>> + >>> + >>> >>> Ndescr = [ ... ('x', 'i4', (2,)), ... ('Info', [ @@ -68,14 +68,14 @@ Set up: ... ('Value', 'c16')]), ... ('y', 'f8', (2, 2)), ... ('z', 'u1')] - >>> - >>> + >>> + >>> >>> NbufferT = [ ... ([3,2], (6j, 6., ('nn', [6j,4j], [6.,4.], [1,2]), 'NN', True), 'cc', ('NN', 6j), [[6.,4.],[6.,4.]], 8), ... ([4,3], (7j, 7., ('oo', [7j,5j], [7.,5.], [2,1]), 'OO', False), 'dd', ('OO', 7j), [[7.,5.],[7.,5.]], 9), ... ] - >>> - >>> + >>> + >>> >>> record_arrays = [ ... np.array(PbufferT, dtype=np.dtype(Pdescr).newbyteorder('<')), ... np.array(NbufferT, dtype=np.dtype(Ndescr).newbyteorder('<')), @@ -111,7 +111,7 @@ Test the header writing. ... f = StringIO() ... format.write_array_header_1_0(f, arr) ... print repr(f.getvalue()) - ... + ... "F\x00{'descr': '|u1', 'fortran_order': False, 'shape': (0,)} \n" "F\x00{'descr': '|u1', 'fortran_order': False, 'shape': ()} \n" "F\x00{'descr': '|u1', 'fortran_order': False, 'shape': (15,)} \n" @@ -506,5 +506,3 @@ def test_read_version_1_0_bad_magic(): for magic in bad_version_magic + malformed_magic: f = StringIO(magic) yield raises(ValueError)(format.read_array), f - - diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index a3bdc743b..9c97a1fdf 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -106,7 +106,7 @@ def deprecate(func, oldname=None, newname=None): else: str1 = "%s is deprecated, use %s" % (oldname, newname), depdoc = '%s is DEPRECATED!! -- use %s instead' % (oldname, newname,) - + def newfunc(*args,**kwds): warnings.warn(str1, DeprecationWarning) return func(*args, **kwds) @@ -487,28 +487,28 @@ def source(object, output=sys.stdout): # * raise SyntaxError instead of a custom exception. class SafeEval(object): - + def visit(self, node, **kw): cls = node.__class__ meth = getattr(self,'visit'+cls.__name__,self.default) return meth(node, **kw) - + def default(self, node, **kw): raise SyntaxError("Unsupported source construct: %s" % node.__class__) - + def visitExpression(self, node, **kw): for child in node.getChildNodes(): return self.visit(child, **kw) - + def visitConst(self, node, **kw): return node.value def visitDict(self, node,**kw): return dict([(self.visit(k),self.visit(v)) for k,v in node.items]) - + def visitTuple(self, node, **kw): return tuple([self.visit(i) for i in node.nodes]) - + def visitList(self, node, **kw): return [self.visit(i) for i in node.nodes] @@ -578,5 +578,3 @@ def safe_eval(source): raise #----------------------------------------------------------------------------- - - |