Skip to content

Commit

Permalink
Clean whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jluttine committed Feb 11, 2018
1 parent c854207 commit 7d74a0c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions bayespy/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def composite(X):
return X
return composite


def ceildiv(a, b):
"""
Compute a divided by b and rounded up.
Expand Down Expand Up @@ -314,8 +314,8 @@ class TestCase(unittest.TestCase):
Adds NumPy's features to Python's unittest.
"""

def assertAllClose(self, A, B,
msg="Arrays not almost equal",
def assertAllClose(self, A, B,
msg="Arrays not almost equal",
rtol=1e-4,
atol=0):

Expand All @@ -329,7 +329,7 @@ def assertArrayEqual(self, A, B, msg="Arrays not equal"):
pass

def assertMessage(self, M1, M2):

if len(M1) != len(M2):
self.fail("Message lists have different lengths")

Expand Down Expand Up @@ -448,7 +448,7 @@ def unique(l):
"""
seen = set()
seen_add = seen.add
return [ x for x in l if x not in seen and not seen_add(x)]
return [ x for x in l if x not in seen and not seen_add(x)]

def tempfile(prefix='', suffix=''):
return tmp.NamedTemporaryFile(prefix=prefix, suffix=suffix).name
Expand All @@ -459,11 +459,11 @@ def write_to_hdf5(group, data, name):
"""
try:
# Try using compression. It doesn't work for scalars.
group.create_dataset(name,
data=data,
group.create_dataset(name,
data=data,
compression='gzip')
except TypeError:
group.create_dataset(name,
group.create_dataset(name,
data=data)
except ValueError:
raise ValueError('Could not write %s' % data)
Expand Down Expand Up @@ -679,12 +679,12 @@ def zipper_merge(*lists):
This is known as alternating merge or zipper merge.
"""

return list(sum(zip(*lists), ()))

def remove_whitespace(s):
return ''.join(s.split())

def is_numeric(a):
return (np.isscalar(a) or
isinstance(a, list) or
Expand Down Expand Up @@ -726,7 +726,7 @@ def make_equal_length(*shapes):
Add leading 1s to shorter tuples.
"""

# Get maximum length
max_len = max((len(shape) for shape in shapes))

Expand Down Expand Up @@ -874,7 +874,7 @@ def sum_multiply(*args, axis=None, sumaxis=True, keepdims=False):
else:
if axis is None:
# Keep all axes
axes = range(max_dim)
axes = list(range(max_dim))
else:
# Find axes that are kept
if np.isscalar(axis):
Expand Down Expand Up @@ -934,19 +934,19 @@ def sum_multiply(*args, axis=None, sumaxis=True, keepdims=False):

def sum_product(*args, axes_to_keep=None, axes_to_sum=None, keepdims=False):
if axes_to_keep is not None:
return sum_multiply(*args,
axis=axes_to_keep,
return sum_multiply(*args,
axis=axes_to_keep,
sumaxis=False,
keepdims=keepdims)
else:
return sum_multiply(*args,
axis=axes_to_sum,
return sum_multiply(*args,
axis=axes_to_sum,
sumaxis=True,
keepdims=keepdims)

def moveaxis(A, axis_from, axis_to):
"""
Move the axis `axis_from` to position `axis_to`.
Move the axis `axis_from` to position `axis_to`.
"""
if ((axis_from < 0 and abs(axis_from) > np.ndim(A)) or
(axis_from >= 0 and axis_from >= np.ndim(A)) or
Expand Down Expand Up @@ -1275,7 +1275,7 @@ def m_dot(A,b):
# the last axes of b. Other axes are broadcasted. If A has shape
# (..., M, N) and b has shape (..., N), then the result has shape
# (..., M)

#b = reshape(b, shape(b)[:-1] + (1,) + shape(b)[-1:])
#return np.dot(A, b)
return np.einsum('...ik,...k->...i', A, b)
Expand Down Expand Up @@ -1360,7 +1360,7 @@ def dist_haversine(c1, c2, radius=6372795):

A = np.sin(dlat/2)**2 + np.cos(lat1)*np.cos(lat2)*(np.sin(dlon/2)**2)
C = 2 * np.arctan2(np.sqrt(A), np.sqrt(1-A))

return radius * C

def logsumexp(X, axis=None, keepdims=False):
Expand All @@ -1369,7 +1369,7 @@ def logsumexp(X, axis=None, keepdims=False):
"""

X = np.asanyarray(X)

maxX = np.amax(X, axis=axis, keepdims=True)

if np.ndim(maxX) > 0:
Expand Down Expand Up @@ -1464,7 +1464,7 @@ def mean(X, axis=None, keepdims=False):
nans = np.isnan(X)
X = X.copy()
X[nans] = 0
m = (np.sum(X, axis=axis, keepdims=keepdims) /
m = (np.sum(X, axis=axis, keepdims=keepdims) /
np.sum(~nans, axis=axis, keepdims=keepdims))
return m

Expand Down

0 comments on commit 7d74a0c

Please sign in to comment.