-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.fc
44 lines (38 loc) · 1.01 KB
/
2.fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-
TASK 2 - Matrix multiplier
Write the method that multiplies one matrix by another.
The 1st and 2nd parameter of the function will contain
a matrix implemented using tuples (eg: [[1,2], [3,4]]).
Matrices can be of different sizes, ranging from 4x4
up to 32x32.
Matrix can be rectangular where matrixA must to be of size n*m & matrixB of size m*p.
After calculating the result matrix, the function should return final result (as tuple).
-}
(int) tlen (tuple t) asm "TLEN";
() recv_internal() {
}
;; testable
(tuple) matrix_multiplier(tuple matrixA, tuple matrixB) method_id {
int n = tlen(matrixA);
int m = tlen(matrixB);
int p = tlen(matrixB.at(0));
int i = 0;
tuple answer = empty_tuple();
repeat(n) {
int j = 0;
tuple row = empty_tuple();
repeat(p) {
int t = 0;
int k = 0;
repeat(m) {
t += matrixA.at(i).at(k) * matrixB.at(k).at(j);
k += 1;
}
row~tpush(t);
j += 1;
}
answer~tpush(row);
i += 1;
}
return answer;
}