Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. public static Matrix MultiplyAsynchronous(Matrix matrix1, Matrix matrix2)
  2. {
  3.  
  4. if (matrix1.ColumnCount != matrix2.RowCount)
  5. throw new ArgumentException(Resources.ErrorMessages.ArgumentMatricesIncompatible);
  6. Matrix result = new Matrix(matrix1.RowCount, matrix2.ColumnCount);
  7.  
  8. double[] vector = matrix2.GetColumn(0).ToArray();
  9. double[] row = matrix1.GetRow(asynchronousStep).ToArray();
  10.  
  11. if (asynchronousStep == 0)
  12. {
  13. for (int index = 0; index < 3; index++)
  14. {
  15. result._matrix[0] += row[index] * vector[index];
  16. }
  17. result._matrix[1] = vector[1];
  18. result._matrix[2] = vector[2];
  19. }
  20. else if (asynchronousStep == 1)
  21. {
  22. for (int index = 0; index < 3; index++)
  23. {
  24. result._matrix[1] += row[index] * vector[index];
  25. }
  26. result._matrix[0] = vector[0];
  27. result._matrix[2] = vector[2];
  28.  
  29. }
  30. else if (asynchronousStep == 2)
  31. {
  32. for (int index = 0; index < 3; index++)
  33. {
  34. result._matrix[2] += row[index] * vector[index];
  35. }
  36. result._matrix[0] = vector[0];
  37. result._matrix[1] = vector[1];
  38.  
  39. }
  40.  
  41. asynchronousStep++;
  42. if(asynchronousStep > 2)
  43. {
  44. asynchronousStep = 0;
  45. }
  46.  
  47. return result;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement