def neuron_indexes(x,P): ''' Returns the array of neuron indexes corresponding to x, which can be a integer, an array, a slice or a subgroup. P is the neuron group. ''' if isinstance(x,NeuronGroup): # it should be checked that x is actually a subgroup of P i0=x._origin - P._origin # offset of the subgroup x in P return np.arange(i0,i0+len(x)) else: return slice_to_array(x,N=len(P))
def test_slice_to_array(): ''' Test the slice_to_array function (converts a slice to the corresponding array of integers). ''' # test special cases: array, sequence, int assert (slice_to_array(42) == np.array([42])).all() assert (slice_to_array([23, 42]) == np.array([23, 42])).all() assert (slice_to_array(np.array([23, 42])) == np.array([23, 42])).all() assert (slice_to_array(slice(0, 5)) == np.arange(0, 5)).all() assert (slice_to_array(slice(2, 5)) == np.arange(2, 5)).all() assert (slice_to_array(slice(2, None), N=5) == np.arange(2, 5)).all() assert (slice_to_array(slice(2, 5, 2)) == np.arange(2, 5, 2)).all() assert (slice_to_array(slice(2, -1, 2), N=10) == np.arange(2, 9, 2)).all()