Skip to content
Snippets Groups Projects
Commit e9d6f98c authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add interleaver generators

parent 392f1049
No related branches found
No related tags found
1 merge request!190Add interleaver generators
Pipeline #89694 passed
"""
Functions to generate memory-variable test data that are used for research.
"""
import random
from typing import Optional, Set
from b_asic.process import PlainMemoryVariable
def _insert_delays(inputorder, outputorder, min_lifetime, cyclic):
size = len(inputorder)
maxdiff = min(outputorder[i] - inputorder[i] for i in range(size))
outputorder = [o - maxdiff + min_lifetime for o in outputorder]
maxdelay = max(outputorder[i] - inputorder[i] for i in range(size))
if cyclic:
if maxdelay < size:
outputorder = [o % size for o in outputorder]
else:
inputorder = inputorder + [i + size for i in inputorder]
outputorder = outputorder + [o + size for o in outputorder]
return inputorder, outputorder
def generate_random_interleaver(
size: int, min_lifetime: int = 0, cyclic: bool = True
) -> Set[PlainMemoryVariable]:
"""
Generate a ProcessCollection with memory variable corresponding to a random
interleaver with length *size*.
Parameters
----------
size : int
The size of the random interleaver sequence.
min_lifetime : int, default: 0
The minimum lifetime for a memory variable. Default is 0 meaning that at least
one variable is passed from the input to the output directly,
cyclic : bool, default: True
If the interleaver should operate continuously in a cyclic manner. That is,
start a new interleaving operation directly after the previous.
Returns
-------
ProcessCollection
"""
inputorder = list(range(size))
outputorder = inputorder[:]
random.shuffle(outputorder)
print(inputorder, outputorder)
inputorder, outputorder = _insert_delays(
inputorder, outputorder, min_lifetime, cyclic
)
print(inputorder, outputorder)
return {
PlainMemoryVariable(inputorder[i], 0, {0: outputorder[i]})
for i in range(size)
}
def generate_matrix_transposer(
height: int,
width: Optional[int] = None,
min_lifetime: int = 0,
cyclic: bool = True,
) -> Set[PlainMemoryVariable]:
r"""
Generate a ProcessCollection with memory variable corresponding to transposing a
matrix of size *height* :math:`\times` *width*. If *width* is not provided, a
square matrix of size *height* :math:`\times` *height* is used.
Parameters
----------
height : int
Matrix height.
width : int, optional
Matrix width. If not provided assumed to be equal to height, i.e., a square
matrix.
min_lifetime : int, default: 0
The minimum lifetime for a memory variable. Default is 0 meaning that at
least one variable is passed from the input to the output directly,
cyclic : bool, default: True
If the interleaver should operate continuously in a cyclic manner. That is,
start a new interleaving operation directly after the previous.
Returns
-------
ProcessCollection
"""
if width is None:
width = height
inputorder = []
for row in range(height):
for col in range(width):
inputorder.append(col + width * row)
outputorder = []
for row in range(width):
for col in range(height):
outputorder.append(col * width + row)
print(inputorder, outputorder)
inputorder, outputorder = _insert_delays(
inputorder, outputorder, min_lifetime, cyclic
)
print(inputorder, outputorder)
return {
PlainMemoryVariable(inputorder[i], 0, {0: outputorder[i]})
for i in range(width * height)
}
......@@ -20,7 +20,7 @@ clean:
rm -rf "$(SOURCEDIR)/examples"
show:
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/build/html/index.html')"
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(shell pwd)/_build/html/index.html')"
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
......
gui\_utils package
==================
gui\_utils.about\_window module
-------------------------------
.. automodule:: b_asic.gui_utils.about_window
:members:
:undoc-members:
......@@ -28,4 +28,6 @@ Table of Contents
api/index
GUI
scheduler_gui
gui_utils
examples/index
research
Research functions
==================
research.interleaver module
---------------------------
.. automodule:: b_asic.research.interleaver
:members:
:undoc-members:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment