-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix matrix multiplication #141
Conversation
private static unsafe double[,] MulMatrixTest(double[,] left, double[,] right) | ||
{ | ||
var m = left.GetLength(0); | ||
var n = right.GetLength(1); | ||
var K = left.GetLength(1); | ||
var len1 = left.Length; | ||
var matrix = new double[m, n]; | ||
|
||
fixed (double* pointer1 = left) | ||
fixed (double* pointer2 = right) | ||
fixed (double* pointer3 = matrix) | ||
{ | ||
var span1 = new Span<double>(pointer1, len1); | ||
|
||
for (var i = 0; i < m; i++) | ||
{ | ||
var c = pointer3 + i * n; | ||
|
||
for (var k = 0; k < K; k++) | ||
{ | ||
var b = pointer2 + k * n; | ||
var a = span1[i * K + k]; | ||
for (var j = 0; j < n; j++) c[j] += a * b[j]; | ||
} | ||
} | ||
|
||
return matrix; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a f is here we have?)
Are you sure that we should use "unsafe code" is Unit Tests?
Obviously, I don't think so! As for me code in unit tests must be as simple&stupid as it only can be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is ctrl C + Ctrl V for testing:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in the end it doesn't even matter, copying code for unit tests from tested code...
var matrixB = new double[size, size]; | ||
for (int i = 0; i < matrixB.GetLength(0); i++) | ||
{ | ||
for (int j = 0; j < matrixB.GetLength(1); j++) | ||
{ | ||
matrixB[i, j] = 1; | ||
} | ||
} | ||
|
||
var expected = MulMatrixTest(matrixB, matrixB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiplication result for square matrixes that consist only of 1
will be just matrix size
xsize
that consist of size
No description provided.