superneuromat.SynapseListView#

class superneuromat.SynapseListView(model: SNN, indices: list[int] | slice | None = None, max_len: int | None = None)[source]#

Redirects indexing to the SNN’s synapses.

Returns a Synapse or a list of Synapses.

This is used to allow for the following syntax:

snn.synapses[0]
snn.synapses[1:10]

You can take a view of a view:

snn.synapses[0:10][-5:]

You can add two views together. This will return a view of the concatenation of the two views.

However, if you add a view and something containing synapses from another model, or some other type of object,the result will be a list.

Equivalence checking can be done between views and views, or views and an iterable. In the latter case, element-wise equality is used.

Attributes:
delays
m

The SNN that this object is associated with.

num_onmodel
stdp_enabled
weights

Methods

add(other[, right])

Concatenate this ListView with another iterable.

append(x)

Append a compatible object to this ListView.

clear()

Make this ListView empty by clearing the indices of this ListView.

copy([model])

Create a copy of this ListView with the same indices, referring to the same SNN.

count(value)

Return the number of occurrences of value in this ListView.

extend(li)

Extend this ListView with the given iterable of compatible objects.

index(value[, start, stop])

Return the index of value in this ListView.

info([max_entries])

Generate a summary of the objects in this ListView.

insert(i, x)

Insert a compatible object at the given index in this ListView.

pop([index])

Remove and return the last item, or the item at the given index.

remove(value)

Remove the first occurrence of value from this ListView.

reverse()

Reverse the order of the items in this ListView.

sort([key, reverse])

Sort the items in this ListView.

tolist()

Returns a list of the objects in this ListView.

using_model(model)

Returns a copy of the listview using the given model.

add(other, right=False)[source]#

Concatenate this ListView with another iterable.

Parameters:
Returns:

If both operands self + other are ModelListViews of the same type and model, returns a ModelListView of the same type and model with the concatenated indices. Otherwise, returns a list of the concatenated objects.

Return type:

NeuronListView | SynapseListView | list[ModelAccessor | Any]

append(x)[source]#

Append a compatible object to this ListView.

Parameters:

x (Neuron | Synapse) – The object to append to this ListView.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if x is not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if x is not from the same model.

clear()[source]#

Make this ListView empty by clearing the indices of this ListView.

copy(model=None)[source]#

Create a copy of this ListView with the same indices, referring to the same SNN.

count(value)[source]#

Return the number of occurrences of value in this ListView.

Parameters:

value (int | Neuron | Synapse)

Returns:

The number of occurrences of value in this ListView.

If value can be cast to int (excluding ModelAccessors), then the number of occurrences of that index in the ListView.

Return type:

int

extend(li)[source]#

Extend this ListView with the given iterable of compatible objects.

Parameters:

li (Sequence[Neuron] | Sequence[Synapse]) – The iterable of objects to extend this ListView with.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if any of the objects are not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if any of the objects in are not from the same model.

index(value, start=0, stop=9223372036854775807)[source]#

Return the index of value in this ListView.

Parameters:
  • value (Neuron | Synapse)

  • start (int, optional) – The starting index of the search, by default 0

  • stop (_type_, optional) – The ending index of the search (non-inclusive), by default sys.maxsize

Returns:

first index of value in this ListView.

Return type:

int

Raises:

ValueError – if the value is not present.

info(max_entries: int | None = 30)[source]#

Generate a summary of the objects in this ListView.

Similar to SNN.neuron_info() or SNN.synapse_info(), but only including information about objects in this ListView.

Parameters:

max_entries (int | None, default=30) – Limits the number of entries which will be included. If None, all entries will be included.

Return type:

str

insert(i, x)[source]#

Insert a compatible object at the given index in this ListView.

Parameters:
  • i (int) – The index at which to insert x.

  • x (Neuron | Synapse) – The object to insert into this ListView.

Raises:
  • RuntimeError – If this ListView is not associated with an SNN.

  • ValueError – if x is not the same accessor type as this ListView (i.e. you can’t add a Neuron to a SynapseListView), or if x is not from the same model.

property m[source]#

The SNN that this object is associated with.

When setting this property, the object is moved from its current model to the new model, if possible.

pop(index=-1)[source]#

Remove and return the last item, or the item at the given index.

Parameters:

index (int, optional) – The index (in this list) of the item to return If not specified, the last item is returned.

Returns:

NeuronListViews will return Neurons, SynapseListViews will return Synapses.

Return type:

Neuron | Synapse

remove(value)[source]#

Remove the first occurrence of value from this ListView.

Parameters:

value (Neuron | Synapse) – The item to remove from this ListView.

Raises:
reverse()[source]#

Reverse the order of the items in this ListView.

sort(key=None, reverse=False)[source]#

Sort the items in this ListView.

Parameters:
  • key (callable | None, default=None) – A function to be called on each item in the ListView. The function should take a single argument, which will be the item from the ListView, and return a value that will be used for sorting. If None, the items will be sorted by its index in the SNN.

  • reverse (bool, default=False) – If True, the items will be sorted in descending order.

tolist()[source]#

Returns a list of the objects in this ListView.

using_model(model)[source]#

Returns a copy of the listview using the given model.