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

Non-contiguous subgroups #1229

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
604e633
WIP: First steps to generalize subgroups to be non-contiguous
mstimberg Feb 21, 2020
d67ca90
Update SpikeMonitor for non-contiguous subgroups
mstimberg Feb 24, 2020
eeff84b
Sort indices before their use in Subgroup
mstimberg Feb 25, 2020
97659da
Fix logic error in Cython/C++ SpikeMonitor code
mstimberg Feb 25, 2020
4672adf
Make PopulationRateMonitor work with non-contiguous subgroups
mstimberg Feb 25, 2020
4c677f0
Add subgroups test for StateMonitor
mstimberg Feb 26, 2020
db2dcd5
Fix subgroups of SpatialNeuron
mstimberg Feb 26, 2020
aa9237d
Forbid using non-contiguous subgroups in Synapses
mstimberg Feb 26, 2020
db3ddf4
Enable string expressions for subgroups
mstimberg Feb 26, 2020
f0a34d1
Make string expressions for subgroups/indexing work in standalone
mstimberg Feb 27, 2020
5acd917
Fix string indexing with references to external constants
mstimberg Feb 28, 2020
33f537e
Make doctest compatible with Windows output for 32bit ints
mstimberg Sep 14, 2020
b477583
Do not allow unsorted indices in subgroups
mstimberg Sep 14, 2020
0cfe648
Merge branch 'master' into non_contiguous_subgroup
mstimberg Jan 4, 2021
e48f89b
Merge branch 'master' into non_contiguous_subgroup
mstimberg Feb 22, 2021
92aff0b
Merge branch 'master' into non_contiguous_subgroup
mstimberg Apr 21, 2021
cdb5427
Fix a remaining case of a deprecated numpy scalar
mstimberg Apr 21, 2021
35bf32f
Merge remote-tracking branch 'origin/master' into non_contiguous_subg…
mstimberg Feb 8, 2022
3032909
Merge branch 'master' into non_contiguous_subgroup
mstimberg Feb 9, 2022
3177307
Merge remote-tracking branch 'origin/master' into non_contiguous_subg…
mstimberg Apr 29, 2022
89430b9
minor optimization for non-contiguous subgroups
mstimberg May 2, 2022
269d9e0
make PoissonGroup work with non-contiguous subgroups
mstimberg May 2, 2022
73cd6d9
make SpikeMonitor generated code deterministic
mstimberg May 2, 2022
d0abc65
Check for illegal subgroup indices in consistent way
mstimberg May 2, 2022
afd5324
Merge branch 'non_contiguous_subgroup' of github.com:brian-team/brian…
mstimberg May 2, 2022
20e0efb
revert run_tests script to original version
mstimberg May 2, 2022
3ae9e1a
Add/update tests for subgroups
mstimberg May 2, 2022
fd2933d
Merge branch 'master' into non_contiguous_subgroup
mstimberg Jun 8, 2022
c57e129
Merge branch 'master' into non_contiguous_subgroup
mstimberg Oct 19, 2022
d8707aa
Update documentation for non-contiguous subgroups
mstimberg Nov 10, 2022
7e495bb
Some more basic tests for incorrect subgroup creation
mstimberg Nov 10, 2022
ec0fe52
Merge branch 'master' into non_contiguous_subgroup
mstimberg Nov 10, 2022
aaacc26
Fix exception type in subgroup tests
mstimberg Nov 14, 2022
22629b8
Test+doc for non-contiguous indices in SpatialNeuron
mstimberg Nov 14, 2022
209d239
Merge branch 'master' into non_contiguous_subgroup
mstimberg Nov 22, 2022
65ec4c3
Remove deprecated usage of np.bool
mstimberg Nov 22, 2022
82e3ffc
Fragile but basic working version of SynapticSubgroup
mstimberg Mar 23, 2023
6f84542
Merge branch 'master' into non_contiguous_subgroup
mstimberg Mar 24, 2023
5509437
Remove unnecessary imports
mstimberg Mar 24, 2023
fe861b7
Add tests for synaptic subgroups
mstimberg Mar 24, 2023
73d214f
Support array indexing for multi-synaptic indices
mstimberg Mar 24, 2023
e51b0ae
Refactor `Group.Indexing` for better readability
mstimberg Mar 29, 2023
6ceba16
Add new tests for synaptic subgroups
mstimberg Mar 29, 2023
dbbb741
Small refactoring for synaptic indexing
mstimberg Mar 30, 2023
2ff3cb1
Fix a test
mstimberg Mar 31, 2023
fe0add7
Write sizes of dynamic arrays to disk after run in standalone mode
mstimberg Mar 31, 2023
eaf1efa
Simplify RateMonitor template for non-contiguous subgroup
mstimberg Apr 7, 2023
3759bf7
Minor reformatting in test
mstimberg Apr 7, 2023
2c4787b
Fail for out-of-range 1d array indices in Synapses
mstimberg Apr 19, 2023
53ae0d8
Handle scalar synaptic indices correctly
mstimberg Apr 20, 2023
6d27f53
Raise errors for boolean indices of incorrect shape
mstimberg Apr 20, 2023
adc17ec
Handle IndexErrors correctly for synapses as well
mstimberg Apr 20, 2023
fed868e
Install coveralls with pip everywhere
mstimberg Apr 20, 2023
d163840
Merge branch 'master' into non_contiguous_subgroup
mstimberg Jun 15, 2023
a7f6cbe
Fix incorrect merge
mstimberg Jun 15, 2023
1c050b2
Merge remote-tracking branch 'origin/master' into non_contiguous_subg…
mstimberg Oct 6, 2023
a7cd7f3
Do not force float64 in TimedArray
mstimberg Oct 26, 2023
437e3fe
Invalidate caches on each run
mstimberg Oct 26, 2023
de0ee35
Merge remote-tracking branch 'origin/master' into non_contiguous_subg…
mstimberg Oct 26, 2023
b476451
Fix cache invalidation
mstimberg Oct 30, 2023
285dffb
Correctly the return type of TimedArray functions in generated code
mstimberg Oct 30, 2023
4cb865b
WIP: Allow non-contiguous subgroups for synapses
mstimberg Nov 2, 2023
bb7ddb9
Allow non-contiguous subgroups for synapses
mstimberg Nov 14, 2023
ce5bb3b
Non-contiguous subgroups for synapses: summed variables
mstimberg Nov 14, 2023
16e2ffc
Test summed variable error for overlapping subgroups
mstimberg Nov 16, 2023
3097569
Merge branch 'master' into non_contiguous_subgroup
mstimberg Sep 13, 2024
f1ea1b5
minor fixes
mstimberg Sep 13, 2024
c21ec60
Re-add write sizes of dynamic arrays to disk
mstimberg Sep 13, 2024
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
Prev Previous commit
Next Next commit
Support array indexing for multi-synaptic indices
  • Loading branch information
mstimberg committed Mar 24, 2023
commit 73d214f0930f8eb967466dd8afb996ba99270e03
20 changes: 9 additions & 11 deletions brian2/synapses/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def slice_to_test(x):
pass

if isinstance(x, slice):
if isinstance(x, slice) and x == slice(None):
if x == slice(None):
# No need for testing
return lambda y: np.repeat(True, len(y))
start, stop, step = x.start, x.stop, x.step
Expand Down Expand Up @@ -668,20 +668,18 @@ def __call__(self, index=None, index_var="_idx"):
"'multisynaptic_index' when you create "
"the Synapses object."
)

# We want to access the raw arrays here, not go through the Variable
synapse_numbers = self.synapse_number.get_value()[matching_synapses]

if isinstance(k_indices, (numbers.Integral, slice)):
test_k = slice_to_test(k_indices)
final_indices = matching_synapses[test_k(synapse_numbers)]
else:
raise NotImplementedError(
"Indexing synapses with arrays notimplemented yet"
)
final_indices = matching_synapses[
np.in1d(synapse_numbers, k_indices)
]

# We want to access the raw arrays here, not go through the Variable
synapse_numbers = self.synapse_number.get_value()[matching_synapses]
final_indices = np.intersect1d(
matching_synapses,
np.flatnonzero(test_k(synapse_numbers)),
assume_unique=True,
)
else:
raise IndexError(f"Unsupported index type {type(index)}")

Expand Down
6 changes: 5 additions & 1 deletion brian2/tests/test_synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,11 @@ def test_state_variable_indexing():
assert len(S.w[:]) == len(S.w[np.arange(len(G1) * len(G2) * 2)])
assert S.w[3] == S.w[np.int32(3)] == S.w[np.int64(3)] # See issue #888

# Array-indexing (not yet supported for synapse index)
# Array-indexing
assert_equal(S.w[:, 0:3], S.w[:, [0, 1, 2]])
assert_equal(S.w[:, 0:3], S.w[np.arange(len(G1)), [0, 1, 2]])
assert_equal(S.w[:, 0:3], S.w[:, [0, 1, 2], [0, 1]])
assert_equal(S.w[:, 0:3, 0], S.w[:, [0, 1, 2], [0]])

# string-based indexing
assert_equal(S.w[0:3, :], S.w["i<3"])
Expand Down Expand Up @@ -780,6 +782,8 @@ def test_state_variable_indexing_with_subgroups():
# Array-indexing (not yet supported for synapse index)
assert_equal(S[:, 0:3].w[:], S[:, [0, 1, 2]].w[:])
assert_equal(S[:, 0:3].w[:], S[np.arange(len(G1)), [0, 1, 2]].w[:])
assert_equal(S[:, 0:3].w[:], S[:, [0, 1, 2], [0, 1]].w[:])
assert_equal(S[:, 0:3, 0].w[:], S[:, [0, 1, 2], [0]].w[:])

# string-based indexing
assert_equal(S[0:3, :].w[:], S["i<3"].w[:])
Expand Down