From 64c5f31a232f21e35a4069a62707041e75b92948 Mon Sep 17 00:00:00 2001 From: Thomas Nowotny Date: Tue, 5 Sep 2023 14:30:27 +0000 Subject: [PATCH 1/2] Casting the incoming list-like "post_indices" to a numpy array so that indexing into it with a numpy array is possible. Previously, there was an error if "post_indices" was a list because self.synapse_order is a numpy array and therefore cannot be used to index into this list. --- pygenn/genn_groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygenn/genn_groups.py b/pygenn/genn_groups.py index d1e3d8e4a..b38358e65 100644 --- a/pygenn/genn_groups.py +++ b/pygenn/genn_groups.py @@ -1010,7 +1010,7 @@ def set_sparse_connections(self, pre_indices, post_indices): self.pop.set_max_connections(max_row_length) # Set ind to sorted postsynaptic indices - self.ind = post_indices[self.synapse_order] + self.ind = np.asarray(post_indices)[self.synapse_order] # Cache the row lengths self.row_lengths = row_lengths From 60c0511a6cd08551e1ada5771cc5c56787c001e8 Mon Sep 17 00:00:00 2001 From: Thomas Nowotny Date: Tue, 5 Sep 2023 16:24:15 +0000 Subject: [PATCH 2/2] Changed the moment where index arrays are cast to numpy arrays as requested by @neworderofjamie --- pygenn/genn_groups.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pygenn/genn_groups.py b/pygenn/genn_groups.py index b38358e65..9936aceb3 100644 --- a/pygenn/genn_groups.py +++ b/pygenn/genn_groups.py @@ -995,6 +995,10 @@ def set_sparse_connections(self, pre_indices, post_indices): raise Exception("when weight sharing is used, set_sparse_connections" "can only be used on the 'master' population") elif self.is_ragged: + # Cast index arrays to numpy arrays if necessary + pre_indices = np.asarray(pre_indices) + post_indices = np.asarray(post_indices) + # Lexically sort indices self.synapse_order = np.lexsort((post_indices, pre_indices)) @@ -1010,7 +1014,7 @@ def set_sparse_connections(self, pre_indices, post_indices): self.pop.set_max_connections(max_row_length) # Set ind to sorted postsynaptic indices - self.ind = np.asarray(post_indices)[self.synapse_order] + self.ind = post_indices[self.synapse_order] # Cache the row lengths self.row_lengths = row_lengths