Skip to content

Commit

Permalink
Merge pull request #480 from SpiNNakerManchester/reduce_overhead_data…
Browse files Browse the repository at this point in the history
…_spec_colours

Reduce overhead data spec colours
  • Loading branch information
rowleya committed Nov 17, 2022
2 parents a27bc29 + 04be275 commit 9ca9c32
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pacman/utilities/utility_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ def get_n_bits(n_values):
return int(math.ceil(math.log2(n_values)))


def get_field_based_keys(key, vertex_slice):
def get_field_based_keys(key, vertex_slice, shift=0):
""" Translate a vertex slice with potentially multiple dimensions into
a list of keys, one for each atom of the vertex, by putting the values
into fields of the keys based on the shape of the slice.
:param int key: The base key
:param Slice vertex_slice: The slice to translate
:param int shift:
The left shift to apply to the atom key before adding to the key. Can
be used to make space for additional information at the bottom of the
key.
:rtype: list(int)
"""

Expand All @@ -173,19 +177,27 @@ def get_field_based_keys(key, vertex_slice):
# get the key
keys = numpy.sum(numpy.left_shift(coords, shifts), axis=1)

# Do any final shifting as required (zero shift is valid but does nothing)
if shift:
keys = numpy.left_shift(keys, shift)

# The final result is the above with the base key added
return keys + key


def get_field_based_index(base_key, vertex_slice):
def get_field_based_index(base_key, vertex_slice, shift=0):
""" Map field based keys back to indices
:param int base_key: The base key
:param Slice vertex_slice: The slice to translate
:param int shift:
The left shift to apply to the atom key before adding to the key. Can
be used to make space for additional information at the bottom of the
key.
:rtype: dict(int,int)
"""
# Get the field based keys
field_based_keys = get_field_based_keys(base_key, vertex_slice)
field_based_keys = get_field_based_keys(base_key, vertex_slice, shift)

# Inverse the index
return {
Expand Down

0 comments on commit 9ca9c32

Please sign in to comment.