diff --git a/nestkernel/node_collection.cpp b/nestkernel/node_collection.cpp index f3be96c75c..b4323921f4 100644 --- a/nestkernel/node_collection.cpp +++ b/nestkernel/node_collection.cpp @@ -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; diff --git a/testsuite/pytests/sli2py_mpi/README.md b/testsuite/pytests/sli2py_mpi/README.md index cb48da01fc..6f9abee576 100644 --- a/testsuite/pytests/sli2py_mpi/README.md +++ b/testsuite/pytests/sli2py_mpi/README.md @@ -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. diff --git a/testsuite/pytests/test_regression_issue-3213.py b/testsuite/pytests/test_regression_issue-3213.py new file mode 100644 index 0000000000..2e13f9aac7 --- /dev/null +++ b/testsuite/pytests/test_regression_issue-3213.py @@ -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 . + +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)