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
Uniontype, and passes the data forward only when theUnioncarries the data type designated by thefixselcompile time parameter. Output data type is theUniontype designated by thefixselparameter.In the example, the driver
drvsends 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 theUnionare enumerated in the order they are listed, soUint[8]has an ID of0andInt[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
Queueand filters-out elements of theQueuebased on the decision made by the functionf()which is received as a parameter. Functionf()should receive elements of the inputQueueand output values of typeBool, either0if the element should be discarded or1if 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 aQueueof numbers0to9sent 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 properQueueformatting. 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
Queueare 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
selparameter to be specified at run time.