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.
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:
other (ModelListView | Sequence[Neuron] | Sequence[Synapse])
right (bool, default=False) – Used for right-handed concatenation.
- Returns:
If both operands
self + other
areModelListView
s of the same type and model, returns aModelListView
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 ifx
is not from the same model.
- copy(model=None)[source]#
Create a copy of this ListView with the same indices, referring to the same
SNN
.
- 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:
- Returns:
first index of
value
in this ListView.- Return type:
- 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()
orSNN.synapse_info()
, but only including information about objects in this ListView.
- insert(i, x)[source]#
Insert a compatible object at the given index in this ListView.
- Parameters:
- 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 ifx
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.
- remove(value)[source]#
Remove the first occurrence of
value
from this ListView.- Parameters:
value (Neuron | Synapse) – The item to remove from this ListView.
- Raises:
RuntimeError – If this ListView is not associated with an
SNN
.ValueError – If
value
is not present 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 theSNN
.reverse (bool, default=False) – If
True
, the items will be sorted in descending order.