Skip to content

Commit

Permalink
general variables instead of numpy ones
Browse files Browse the repository at this point in the history
  • Loading branch information
jajcayn committed Jul 13, 2023
1 parent e1e0509 commit 72e3425
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
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(floating)
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(floating)

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(floating)}
)
return params

Expand Down
2 changes: 1 addition & 1 deletion neurolib/utils/parameterSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def getRandom(self, safe=False):
random_value = np.random.choice(value)
if isinstance(random_value, np.float64):
random_value = float(random_value)
elif isinstance(random_value, np.int64):
elif isinstance(random_value, int64):
random_value = int(random_value)
randomPar[key] = random_value
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/multimodel/base/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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)
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

0 comments on commit 72e3425

Please sign in to comment.