Skip to content

Commit

Permalink
Merge pull request #3214 from heplesser/fix-3213
Browse files Browse the repository at this point in the history
Fix corner case for node collections
  • Loading branch information
heplesser authored Jun 4, 2024
2 parents 4ea6520 + 6e35ed1 commit d49d1b5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 4 additions & 2 deletions nestkernel/node_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,9 +1337,11 @@ NodeCollectionComposite::get_nc_index( const size_t node_id ) const
}
}

assert( lower == upper );
// If node_id is not in the NodeCollection, lower may pass upper in the loop above
// See test_regression_issue-3213.py for an example case.
assert( lower >= upper );

if ( node_id < parts_[ lower ][ 0 ] or parts_[ lower ][ parts_[ lower ].size() - 1 ] < node_id )
if ( lower > upper or node_id < parts_[ lower ][ 0 ] or parts_[ lower ][ parts_[ lower ].size() - 1 ] < node_id )
{
// node_id is in a gap of nc
return -1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/pytests/sli2py_mpi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Test in this directory run NEST with different numbers of MPI ranks and compare results.

See documentation in mpi_test_wrappe.py for details.
See documentation in mpi_test_wrapper.py for details.
38 changes: 38 additions & 0 deletions testsuite/pytests/test_regression_issue-3213.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
#
# test_regression_issue-3213.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import nest
import pytest

"""
Test that GetConnections works if NodeCollection with gaps is provided as source arg.
"""


def test_get_conns_works():
"""Main concern is that GetConnections() passes, expected number of connections based on all-to-all."""

num_n = 12
n = nest.Create("parrot_neuron", num_n)
nest.Connect(n, n)
pick = [3, 7, 9, 11]
conns = nest.GetConnections(source=n[pick])
assert len(conns) == num_n * len(pick)

0 comments on commit d49d1b5

Please sign in to comment.