Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy new version errors #238

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions neurolib/models/multimodel/builder/base/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,11 @@ def _init_xarray(self, times, results):
var_idx = 0
for node_idx, node_results in enumerate(self.state_variable_names):
for result_idx, result in enumerate(node_results):
xr_results[result][:, node_idx] = results[:, var_idx + result_idx].astype(np.floating)
xr_results[result][:, node_idx] = results[:, var_idx + result_idx].astype(float)
var_idx += len(node_results)

for state_var, array in xr_results.items():
xr_results[state_var] = array.astype(np.floating)
xr_results[state_var] = array.astype(float)

dataset = xr.Dataset(xr_results)

Expand Down
6 changes: 3 additions & 3 deletions neurolib/models/multimodel/builder/base/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _sanitize_matrix(matrix, target_shape):
"""
assert matrix.shape == target_shape
if isinstance(matrix, np.ndarray) and matrix.dtype.kind == "i":
return matrix.astype(np.float)
return matrix.astype(float)
else:
return matrix

Expand Down Expand Up @@ -436,7 +436,7 @@ def init_node(self, **kwargs):
assert self.idx_state_var is not None
# gather inputs form this node - assumes constant delays
var_idx = 0
self.inputs = np.zeros_like(self.connectivity, dtype=np.object)
self.inputs = np.zeros_like(self.connectivity, dtype=object)
# iterate over masses as `from`, hence columns
for from_mass, mass in enumerate(self.masses):
# iterate over indices as `to`, hence rows
Expand Down Expand Up @@ -800,7 +800,7 @@ def _construct_input_matrix(self, within_node_idx):
if isinstance(within_node_idx, int):
within_node_idx = [within_node_idx] * self.num_nodes
assert self.num_nodes == len(within_node_idx)
inputs = np.zeros_like(self.connectivity, dtype=np.object)
inputs = np.zeros_like(self.connectivity, dtype=object)

# iterate over nodes as `from`, hence columns
for from_node, (node, node_var_idx) in enumerate(zip(self.nodes, within_node_idx)):
Expand Down
4 changes: 2 additions & 2 deletions neurolib/models/multimodel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def _set_model_params(self):
# all matrices to floats
for k, v in params.items():
if isinstance(v, np.ndarray):
params[k] = v.astype(np.float)
params[k] = v.astype(float)
params.update(DEFAULT_RUN_PARAMS)
params["name"] = self.model_instance.label
params["description"] = self.model_instance.name
if isinstance(self.model_instance, Node):
params.update({"N": 1, "Cmat": np.zeros((1, 1))})
else:
params.update(
{"N": len(self.model_instance.nodes), "Cmat": self.model_instance.connectivity.astype(np.floating)}
{"N": len(self.model_instance.nodes), "Cmat": self.model_instance.connectivity.astype(float)}
)
return params

Expand Down
2 changes: 1 addition & 1 deletion neurolib/utils/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def resample_func(x):

resampled = resample_func(self.data.values)
# construct new times
new_times = (np.arange(resampled.shape[-1], dtype=np.float) / to_frequency) + self.data.time.values[0]
new_times = (np.arange(resampled.shape[-1], dtype=float) / to_frequency) + self.data.time.values[0]
# to dataframe
resampled = xr.DataArray(resampled, dims=self.data.dims, coords={**self.coords_not_time, "time": new_times})
add_steps = [f"resample to {to_frequency}Hz"]
Expand Down
6 changes: 3 additions & 3 deletions tests/multimodel/base/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

class TestSanitizeMatrix(unittest.TestCase):
def test_sanitize_matrix_int(self):
mat = (np.random.rand(2, 2) * 100.0).astype(np.int)
mat = (np.random.rand(2, 2) * 100.0).astype(int)
result = _sanitize_matrix(mat, (2, 2))
self.assertTrue(result.dtype.kind == "f")
np.testing.assert_equal(mat.astype(np.float), result)
np.testing.assert_equal(mat.astype(float), result)

def test_sanitize_matrix_float(self):
mat = np.random.rand(2, 2)
Expand All @@ -37,7 +37,7 @@ def test_sanitize_matrix_float(self):
np.testing.assert_equal(mat, result)

def test_sanitize_matrix_wrong(self):
mat = (np.random.rand(2, 2) * 100.0).astype(np.int)
mat = (np.random.rand(2, 2) * 100.0).astype(int)
with pytest.raises(AssertionError):
result = _sanitize_matrix(mat, (3, 3))

Expand Down
Loading