How does chisel connect to such a port? - scala

I am learning the design of Boomv3.
The A part has a write port. The format is
val write_ports = Flipped(Vec(10, Valid(new RegisterFileWritePort(maxPregSz, registerWidth))))
B has a write port. The format is
val write_ports = Vec(5, Valid(new RegisterFileWritePort(maxPregSz, 4)))
C has a write port. The format is
val write_ports = Vec(5, Valid(new RegisterFileWritePort(maxPregSz, 4)))
I want to connect B and C to A.
When i use
A.write_ports <> B.write_ports
A.write_ports <> C.write_ports
, here will be a failed #: Left and Right are different length Vecs error.
But my original intention is that the length of A is 10. The length of B and C are both 5. This makes them connect.
But what should I do?

With these two bulk connexions, Chisel can't find where to assign B and C 5-sized Vec to B 10-sized Vec.
You should concatenate B and C vec and write one bulk connexion :
A.write_ports <> B.write_ports ++ C.write_ports
I tested it with scatie here.

Related

Accessing external (DSPF) fields using arrays in RPGLE free

In the old RPG III and the non-free RPGLE/RPG IV you could "rename" fields you get from either a record of a PF/LF or a record from a DSPF.
This lead to possibilities like grouping several lines of input (additional order text) into a array. So I didn't have to MOVEL or EVAL ottxt1 to the external described field x1txt1, ottxt2 to x1txt2 and so on.
I'd only had to rename the LF record and the DSPF record fields to the array-fields, read the record and shift them from the one array to the other and display my DSPF record
H DECEDIT('0,') DATEDIT(*DMY.) dftactgrp(*no)
Fsls001 cf e workstn
Fordtxtl0 if e k disk
D ot s 20a dim(6)
D x1 s 20a dim(6)
Iordtxtr
I ottxt1 ot(1)
I ottxt2 ot(2)
I ottxt3 ot(3)
I ottxt4 ot(4)
I ottxt5 ot(5)
I ottxt6 ot(6)
Isls00101
I x1txt1 x1(1)
I x1txt2 x1(2)
I x1txt3 x1(3)
I x1txt4 x1(4)
I x1txt5 x1(5)
I x1txt6 x1(6)
C k$or00 klist
C kfld otonbr
C kfld otopos
C eval otonbr = 2
C eval otopos = 2
C k$or00 chain ordtxtr
C if %found(ordtxtl0)
C eval x1 = ot
C endif
C
C exfmt sls00101
C
C move *on *inlr
But is this also possible in *FREE RPGLE? And if so, how?
You can define data structures containing the fields from the files, and overlay them with an array.
Replace your I specs and array definitions with these data structures. You don't have to specify anything besides the field names for the fields from the externally-described file.
dcl-ds otDs;
ottxt1;
ottxt2;
ottxt3;
ottxt4;
ottxt5;
ottxt6;
ot like(ottxt1) dim(6) pos(1);
end-ds;
dcl-ds x1Ds;
x1txt1;
x1txt2;
x1txt3;
x1txt4;
x1txt5;
x1txt6;
x1 like(x1txt1) dim(6) pos(1);
end-ds;

Adding Columns in kdb based on other columns value

I have a column like this in dataframe named test:
Name Client
A P
B Q
C R
D S
E T
I need to to create a new column clienttype in the same dataframe with condition that, if Client = P or Q clienttype = first. If client type = R or S clienttype = second and so on. Can anyone tell how to do this in kdb? Thanks
Could this be solved with a dictionary?
q)update ClientType:(`P`Q`R`S!`first`first`second`second)Client from tab
Name Client ClientType
----------------------
A P first
B Q first
C R second
D S second
E T
Extension to this: You can also use vector conditionals ?[;;] for these types of problems. Unfortunately in this case in would result in many nested vector conditionals:
update Clienttype:?[Client in`P`Q;`first;?[Client in`R`S;`second;`third]]from tab
Name Client Clienttype
----------------------
A P first
B Q first
C R second
D S second
E T third
If you only had two possible options (e.g. first and second) this approach could prove useful.
You did not tell us the types of the columns in your table, but if all your entries are single letter, they are best represented by q char type:
q)show t:([]Name:"ABCDE";Client:"PQRST")
Name Client
-----------
A P
B Q
C R
D S
E T
Now, the Clienttype is best stored as a number which can be computed as
q)update Clienttype:1+(("i"$Client)-"i"$"P")div 2 from t
Name Client Clienttype
----------------------
A P 1
B Q 1
C R 2
D S 2
E T 3
or if you must use symbols,
q)types:`first`second`third`fourth
q)update Clienttype:types(("i"$Client)-"i"$"P")div 2 from t
Name Client Clienttype
----------------------
A P first
B Q first
C R second
D S second
E T third

predicate encode in prolog

I'm new in prolog and I'm trying to write the predicate encode(L,L1) which counts the duplicates of elements in L ,for example:
encode([4,4,4,3,3],L).
L=[3,4,2,3].
This is what I have written:
encode(L,L1) :- encode(L,1,L1).
encode([],_,[]).
encode([H],N,[N,H]).
encode([H,H|T],N1,[N,H|T1]) :- M is N1+1, encode([H|T],M,[N,H|T1]).
encode([H,Y|T],N,[N,H|T1]) :- H\=Y, encode([Y|T],T1).
The above predicate is not reversible. It only works if the first parameter is provided.
How can I write encode reversible?
For example:
encode(L,[3,4,2,3]).
L = [4,4,4,3,3].
I think your algorithm has a redundant counter in it. A little simplified would be:
encoded([], []).
encoded([X], [1,X]).
encoded([X,Y|T], [1,X|R]) :-
dif(X, Y),
encoded([Y|T], R).
encoded([X,X|T], [N,X|R]) :-
N #> 1,
N #= N1 + 1,
encoded([X|T], [N1,X|R]).
Note in the last clause we need to ensure that N is greater than 1 as well.

Matlab: regexp usage

I am going to start illustration using a code:
A = 'G1(General G1Airlines american G1Fungus )';
Using regexp (or any other function) in Matlab I want to distinctively locate: G1, G1A and G1F.
Currently if I try to do something as:
B = regexp( A, 'G1')
It is not able to distinguish G1 with the G1A and G1F i.e. I need to force the comparison to find me only case with G1 and ignore G1A and G1F.
However, when I am searching for G1A then it should still find me the location of G1A.
Can someone please help ?
Edit: Another case for A is:
A = 'R1George Service SmalR1Al C&I)';
And the expression this time I need to find is R1 and R1A instead.
Edit:
I have a giant array containing A's and another big vector containing G1, R1, etc I need to search for.
If you want to find 'G1' but not 'G1A' or 'G1F' you can use
>> B = regexp(A, 'G1[^AF]')
B =
1
This will find 'G1' and the ^ is used to specify that it should not match any characters contained with []. Then you could use
>> B = regexp(A, 'G1[AF]')
B =
12 32
to find both 'G1A' and 'G1F'.

How can I know the line equivalence of two similar files?

When I add a line to the middle of a file, all following lines have their number incremented.
Is there a utility that generates the list of equivalent line numbers between two files?
The output would be something like:
1 1
2 2
3 4 (line added)
4 5
One can probably create such utility by using dynamic programming in a way similar to the diff algorithm. Seems useful, hasn't already been done?
I found out it is pretty easy to do with python's difflib:
import difflib
def seq_equivs(s1, s2):
equiv = []
s = difflib.SequenceMatcher(a=s1, b=s2)
for m in s.get_matching_blocks():
if m[2] == 0:
break
for n in range(1, 1+m[2]):
equiv.append((m[0]+n, m[1]+n))
return equiv
Example usage:
f1 = open('file1.txt').read().split('\n')
f2 = open('file2.txt').read().split('\n')
for equivs in seq_equivs(f1, f2):
print('%d %d' % equivs)