Skip to content

Commit

Permalink
Merge pull request #201 from Lnaden/master
Browse files Browse the repository at this point in the history
Future-proof NumPy ndarray == None and ndarray != None comparisons
  • Loading branch information
jchodera committed Jul 8, 2015
2 parents 681406b + 88ee579 commit c711dc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pymbar/mbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(self, u_kn, N_k, maximum_iterations=10000, relative_tolerance=1.0e-

# If an initial guess of the relative dimensionless free energies is
# specified, start with that.
if initial_f_k != None:
if initial_f_k is not None:
if self.verbose:
print("Initializing f_k with provided initial guess.")
# Cast to np array.
Expand Down Expand Up @@ -855,21 +855,21 @@ def computeExpectations(self, A_n, u_kn=None, output='averages', state_dependent
if not state_dependent:
if dims==2:
A_n = kn_to_n(A_n, N_k=self.N_k)
if u_kn != None:
if u_kn is not None:
if len(np.shape(u_kn)) == 3:
u_kn = kln_to_kn(u_kn, N_k=self.N_k)
elif len(np.shape(u_kn)) == 2:
u_kn = kn_to_n(u_kn, N_k=self.N_k)
else:
if dims==3:
A_n = kln_to_kn(A_n, N_k=self.N_k)
if u_kn != None:
if u_kn is not None:
if len(np.shape(u_kn)) == 3:
u_kn = kln_to_kn(u_kn, N_k=self.N_k)
elif len(np.shape(u_kn)) == 2:
u_kn = kn_to_n(u_kn, N_k=self.N_k)

if u_kn == None:
if u_kn is None:
u_kn = self.u_kn

# Retrieve N and K for convenience.
Expand Down Expand Up @@ -1136,7 +1136,7 @@ def computeEntropyAndEnthalpy(self, u_kn=None, uncertainty_method=None, verbose=
if dims==3:
u_kn = kln_to_kn(u_kn, N_k=self.N_k)

if u_kn == None:
if u_kn is None:
u_kn = self.u_kn

# Retrieve N and K for convenience.
Expand Down
4 changes: 2 additions & 2 deletions pymbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def kln_to_kn(kln, N_k = None, cleanup = False):
# rewrite into kn shape
[K, L, N_max] = np.shape(kln)

if N_k == None:
if N_k is None:
# We assume that all N_k are N_max.
# Not really an easier way to do this without being given the answer.
N_k = N_max * np.ones([L], dtype=np.int64)
Expand Down Expand Up @@ -107,7 +107,7 @@ def kn_to_n(kn, N_k = None, cleanup = False):
# rewrite into kn shape
[K, N_max] = np.shape(kn)

if N_k == None:
if N_k is None:
# We assume that all N_k are N_max.
# Not really an easier way to do this without being given the answer.
N_k = N_max*np.ones([K], dtype=np.int64)
Expand Down

0 comments on commit c711dc1

Please sign in to comment.