Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Oct 11, 2024
1 parent 85a79ac commit e9ab2c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions spynnaker/pyNN/models/neuron/population_machine_neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from __future__ import annotations
from collections.abc import Container
import ctypes
from typing import List, NamedTuple, Sequence, Set, Union, cast, TYPE_CHECKING
from typing import (
List, NamedTuple, Sequence, Set, Union, Optional, cast, TYPE_CHECKING)

import numpy

Expand Down Expand Up @@ -231,21 +232,22 @@ def _write_neuron_data_spec(
self._neuron_data.write_data(
spec, self._vertex_slice, self._neuron_regions)

def __find_default_key(self) -> int:
def __find_default_key(self) -> Optional[int]:
routing_info = SpynnakerDataView.get_routing_infos()
if not self._pop_vertex.extra_partitions:
return routing_info.get_single_first_key_from_pre_vertex(
cast(AbstractVertex, self))
partition_ids = set(
routing_info.get_partitions_outgoing_from_vertex(self))
routing_info.get_partitions_outgoing_from_vertex(
cast(AbstractVertex, self)))
partition_ids = partition_ids - set(self._pop_vertex.extra_partitions)
if len(partition_ids) > 1:
raise ValueError(
"Multiple outgoing partitions found, cannot determine key")
if len(partition_ids) == 0:
return None
return routing_info.get_safe_first_key_from_pre_vertex(
self, next(iter(partition_ids)))
cast(AbstractVertex, self), next(iter(partition_ids)))

def _rewrite_neuron_data_spec(self, spec: DataSpecificationReloader):
"""
Expand Down
6 changes: 4 additions & 2 deletions spynnaker/pyNN/models/neuron/synaptic_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import (
Dict, List, NamedTuple, Optional, Sequence, Tuple, TYPE_CHECKING)
Dict, List, NamedTuple, Optional, Sequence, Tuple, TYPE_CHECKING, cast)

import numpy
from numpy import floating, uint32
Expand All @@ -40,6 +40,7 @@
get_sdram_for_bit_field_region, get_bitfield_key_map_data,
write_bitfield_init_data)
from spynnaker.pyNN.models.common import PopulationApplicationVertex
from spynnaker.pyNN.models.spike_source import SpikeSourcePoissonVertex

from .synaptic_matrix_app import SynapticMatrixApp

Expand Down Expand Up @@ -549,7 +550,8 @@ def get_connections_from_machine(
:rtype: list(~numpy.ndarray)
"""
if self.__is_sdram_poisson_source(app_edge):
return app_edge.pre_vertex.read_connections(synapse_info)
return cast(SpikeSourcePoissonVertex, app_edge.pre_vertex)\
.read_connections(synapse_info)
matrix = self.__matrices[app_edge, synapse_info]
return matrix.get_connections(placement)

Expand Down

0 comments on commit e9ab2c0

Please sign in to comment.