Skip to content

Commit

Permalink
change np.int/float/bool to int/float/bool
Browse files Browse the repository at this point in the history
change np.int/float/bool to int/float/bool
  • Loading branch information
bojunliu0818 committed Jun 14, 2023
1 parent 9fabde5 commit 8b9d2c0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 25 deletions.
7 changes: 6 additions & 1 deletion examples/Clustering-Comparison.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Clustering comparison"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -97,6 +99,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -123,6 +126,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -148,7 +152,7 @@
" t1 = time.time()\n",
" \n",
" if hasattr(algorithm, 'labels_'):\n",
" y_pred = algorithm.labels_[0].astype(np.int)\n",
" y_pred = algorithm.labels_[0].astype(int)\n",
" else:\n",
" y_pred = algorithm.transform([X])[0]\n",
" \n",
Expand All @@ -161,6 +165,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down
2 changes: 1 addition & 1 deletion msmbuilder/commands/featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _atom_indices_type(self, fn):
return np.loadtxt(fn, dtype=int, ndmin=1)

def _sigma_type(self, val):
return np.float(val)
return float(val)

class SuperposeFeaturizerCommand(FeaturizerCommand):
klass = SuperposeFeaturizer
Expand Down
2 changes: 1 addition & 1 deletion msmbuilder/featurizer/multichain.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_contact_pairs(self, contacts):

else:
self.residue_pairs = ensure_type(np.asarray(contacts),
dtype=np.int, ndim=2, name='contacts',
dtype=int, ndim=2, name='contacts',
shape=(None, 2), warn_on_cast=False)
if not np.all((self.residue_pairs >= 0) *
(self.residue_pairs < self.reference_frame.n_residues)):
Expand Down
2 changes: 1 addition & 1 deletion msmbuilder/msm/_metzner_mcmc_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def metzner_mcmc_slow(Z, n_samples, n_thin=1, random_state=None):
# them like this. This ensures that this function and
# `metzner_mcmc_fast` give _exactly_ the same sequence of transition
# matricies, given the same random seed.
i, j = (random.rand(2) * n_states).astype(np.int)
i, j = (random.rand(2) * n_states).astype(int)

sc = np.sum(K)
if i == j:
Expand Down
6 changes: 3 additions & 3 deletions msmbuilder/msm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def partial_transform(self, sequence, mode='clip'):
raise ValueError("Each sequence must be 1D")

f = np.vectorize(lambda k: self.mapping_.get(k, np.nan),
otypes=[np.float])
otypes=[float])

a = f(sequence)
if mode == 'fill':
Expand Down Expand Up @@ -557,9 +557,9 @@ def _transition_counts(sequences, lag_time=1, sliding_window=True):
and not contains_none
and classes.dtype.kind == 'i'
and np.all(classes == np.arange(n_states)))
mapping_fn = np.vectorize(mapping.get, otypes=[np.int])
mapping_fn = np.vectorize(mapping.get, otypes=[int])
none_to_nan = np.vectorize(lambda x: np.nan if x is None else x,
otypes=[np.float])
otypes=[float])

counts = np.zeros((n_states, n_states), dtype=float)
_transitions = []
Expand Down
2 changes: 1 addition & 1 deletion msmbuilder/msm/msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def eigtransform(self, sequences, right=True, mode='clip'):
is_finite = np.isfinite(y)
if not np.all(is_finite):
value = np.empty((y.shape[0], op.shape[1]))
value[is_finite, :] = np.take(op, y[is_finite].astype(np.int), axis=0)
value[is_finite, :] = np.take(op, y[is_finite].astype(int), axis=0)
value[~is_finite, :] = np.nan
else:
value = np.take(op, y, axis=0)
Expand Down
2 changes: 1 addition & 1 deletion msmbuilder/tests/test_bayes_ratematrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_4():
except ImportError:
n_params = scipy.misc.comb(n + 1, 2, exact=True)
alpha = np.ones(n)
beta = (np.arange(n_params - n) + 1).astype(np.float)
beta = (np.arange(n_params - n) + 1).astype(float)
counts = np.array([
[10, 2, 0, 0],
[1, 8, 2, 0],
Expand Down
20 changes: 10 additions & 10 deletions msmbuilder/tests/test_msm.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,26 @@ def test_transform():
v = model.transform([['a', 'b', 'c']])
assert isinstance(v, list)
assert len(v) == 1
assert v[0].dtype == np.int
assert v[0].dtype == int
np.testing.assert_array_equal(v[0], [0, 1, 2])

v = model.transform([['a', 'b', 'c', 'd']], 'clip')
assert isinstance(v, list)
assert len(v) == 1
assert v[0].dtype == np.int
assert v[0].dtype == int
np.testing.assert_array_equal(v[0], [0, 1, 2])

v = model.transform([['a', 'b', 'c', 'd']], 'fill')
assert isinstance(v, list)
assert len(v) == 1
assert v[0].dtype == np.float
assert v[0].dtype == float
np.testing.assert_array_equal(v[0], [0, 1, 2, np.nan])

v = model.transform([['a', 'a', 'SPLIT', 'b', 'b', 'b']], 'clip')
assert isinstance(v, list)
assert len(v) == 2
assert v[0].dtype == np.int
assert v[1].dtype == np.int
assert v[0].dtype == int
assert v[1].dtype == int
np.testing.assert_array_equal(v[0], [0, 0])
np.testing.assert_array_equal(v[1], [1, 1, 1])

Expand All @@ -193,26 +193,26 @@ def test_partial_transform():
v = model.partial_transform(['a', 'b', 'c'])
assert isinstance(v, list)
assert len(v) == 1
assert v[0].dtype == np.int
assert v[0].dtype == int
np.testing.assert_array_equal(v[0], [0, 1, 2])

v = model.partial_transform(['a', 'b', 'c', 'd'], 'clip')
assert isinstance(v, list)
assert len(v) == 1
assert v[0].dtype == np.int
assert v[0].dtype == int
np.testing.assert_array_equal(v[0], [0, 1, 2])

v = model.partial_transform(['a', 'b', 'c', 'd'], 'fill')
assert isinstance(v, np.ndarray)
assert len(v) == 4
assert v.dtype == np.float
assert v.dtype == float
np.testing.assert_array_equal(v, [0, 1, 2, np.nan])

v = model.partial_transform(['a', 'a', 'SPLIT', 'b', 'b', 'b'], 'clip')
assert isinstance(v, list)
assert len(v) == 2
assert v[0].dtype == np.int
assert v[1].dtype == np.int
assert v[0].dtype == int
assert v[1].dtype == int
np.testing.assert_array_equal(v[0], [0, 0])
np.testing.assert_array_equal(v[1], [1, 1, 1])

Expand Down
4 changes: 2 additions & 2 deletions msmbuilder/tpt/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _fraction_visited(source, sink, waypoint, tprob, for_committors,
.. [1] Dickson & Brooks (2012), J. Chem. Theory Comput., 8, 3044-3052.
"""

fraction_visited = (np.float(tprob[source, :].dot(cond_committors)) /
np.float(tprob[source, :].dot(for_committors)))
fraction_visited = (float(tprob[source, :].dot(cond_committors)) /
float(tprob[source, :].dot(for_committors)))

return fraction_visited
8 changes: 4 additions & 4 deletions msmbuilder/tpt/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ def top_path(sources, sinks, net_flux):
pathways from short off-equilibrium simulations." PNAS 106.45 (2009):
19011-19016.
"""
sources = np.array(sources, dtype=np.int).reshape((-1,))
sinks = np.array(sinks, dtype=np.int).reshape((-1,))
sources = np.array(sources, dtype=int).reshape((-1,))
sinks = np.array(sinks, dtype=int).reshape((-1,))

n_states = net_flux.shape[0]

queue = list(sources)
# nodes to check (the "queue")
# going to use list.pop method so I can't keep it as an array

visited = np.zeros(n_states).astype(np.bool)
visited = np.zeros(n_states).astype(bool)
# have we already checked this node?

previous_node = np.ones(n_states).astype(np.int) * -1
previous_node = np.ones(n_states).astype(int) * -1
# what node was found before finding this one

min_fluxes = np.ones(n_states) * -1 * np.inf
Expand Down

0 comments on commit 8b9d2c0

Please sign in to comment.