C
C#2y ago
alex_s7

❔ Convolution logic

have to implement the convolution logic in C#. I have attached my code. I created a unit test but it does not pass. public class SMatrix{ private int[,] matrix; private int rows; private int columns; public SMatrix(int[,] m) { matrix = m; rows = m.GetLength(0); columns = m.GetLength(1); } public SMatrix(int[] arr, int r, int c) { matrix = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { matrix[i, j] = arr[i * c + j]; } } rows = r; columns = c; } public int Rows { get { return rows; } } public int Columns { get { return columns; } } public int this[int i, int j] { get { return matrix[i, j]; } set { matrix[i, j] = value; } } public int[,] GetMatrix() { return matrix; } public static SMatrix operator (SMatrix a, SMatrix b) { int[,] result = new int[a.Rows - b.Rows + 1, a.Columns - b.Columns + 1]; for (int i = 0; i < result.GetLength(0); i++) { for (int j = 0; j < result.GetLength(1); j++) { for (int k = i; k < i + b.Rows; k++) { for (int l = j; l < j + b.Columns; l++) { result[i, j] += a[k, l] b[k - i, l - j]; } } } } return new SMatrix(result); } }
7 Replies
Denis
Denis2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Denis
Denis2y ago
and please also include your unit test
alex_s7
alex_s7OP2y ago
Sure give me a minute
alex_s7
alex_s7OP2y ago
Oh, I am sorry, my comment is still inside the file Can't anyone help me please?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server