filt¶
Filters various data types received at its input, by passing forward only certain parts of the data based on some criteria.
-
filt
(din: Union, *, fixsel) → din.types[fixsel]:¶ Receive data of the
Union
type, and passes the data forward only when theUnion
carries the data type designated by thefixsel
compile time parameter. Output data type is theUnion
type designated by thefixsel
parameter.In the example, the driver
drv
sends data of the typeUnion[Uint[8], Int[8]]
, which means that the data can either be an 8-bit unsigned integer or an 8-bit signed integer. Types in theUnion
are enumerated in the order they are listed, soUint[8]
has an ID of0
andInt[8]
has an ID of1
. The driver alternates between sending the unsigned and signed values, but only the unsigned values are passed forward sincefilt()
is configured to pass the values of the type with the ID of0
(fixsel = 0
).drv(t=Union[Uint[8], Int[8]], seq=[(1, 0), (2, 1), (3, 0), (4, 1), (5, 0)]) \ | filt(fixsel=0) \ | check(ref=[1, 3, 5])
-
filt
(din: Queue, *, f) → din Receives a
Queue
and filters-out elements of theQueue
based on the decision made by the functionf()
which is received as a parameter. Functionf()
should receive elements of the inputQueue
and output values of typeBool
, either0
if the element should be discarded or1
if it should be passed forward. It should have a following signature:-
f
(x: din.data) → Bool¶
The example shows how
filt()
can be used to select even numbers from aQueue
of numbers0
to9
sent by the driver. In order to retain the consistency of the outputQueue
.@datagear def even(x: Uint) -> Bool: return not x[0] drv(t=Queue[Uint[8]], seq=[list(range(10))]) \ | filt(f=even) \ | check(ref=[list(range(0, 10, 2))])
The
filt()
gear needs to delay output of the received data in order to maintain the properQueue
formatting. In the following example, the first element that is received needs to be kept in the buffer and finally output together with theeot
(end of transaction) flag.drv(t=Queue[Uint[8]], seq=[[0, 1, 3, 5, 7, 9]]) \
If all elements of the
Queue
are filtered out, nothing is sent forward:drv(t=Queue[Uint[8]], seq=[[1, 3, 5, 9]]) \
-
-
filt
(din: Tuple[{'data': Union, 'sel': Uint}]) → din['data'] Same functionality as the first filt() variant, but allows for the
sel
parameter to be specified at run time.