Skip to content
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

Matrix Multiplication #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Matrix Multiplication #1

wants to merge 11 commits into from

Conversation

artemiipatov
Copy link
Owner

No description provided.

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI под линуксом помер, посмотрите, пожалуйста.

using System.IO;
using NUnit.Framework;

namespace MatrixMultiplication.Tests;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше namespace писать первой строкой файла (сразу после шапки с лицензией, которую мы по традиции не пишем почему-то). Это более консистентно с синтаксисом других языков типа Java, и в целом более аккуратно.

var matrix2 = new DenseMatrix("matrix2.txt");
Assert.AreEqual(matrix1.Matrix, new[,] { { 10, 4, 5 }, { 8, 9, 1 } });
Assert.AreEqual(matrix2.Matrix, new[,] { { 2, 9 }, { 1, 7 }, {4, 19} });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неплохо бы, чтобы тест удалял создаваемые им файлы. Во избежание случайных зависимостей тестов по данным.

{
var correctResult = new[,] { { 44, 213 }, { 29, 154 } };
var matrix1 = new DenseMatrix(new[,] { { 10, 4, 5 }, { 8, 9, 1 } }, "matrix1.txt");
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, {4, 19} }, "matrix2.txt");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, {4, 19} }, "matrix2.txt");
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, {4, 19 } }, "matrix2.txt");

var matrix2 = new DenseMatrix(new[,] { { 100 } }, "matrix2.txt");
var result1 = DenseMatrix.MultiplyConcurrently(matrix1, matrix2);
var result2 = DenseMatrix.MultiplySerially(matrix1, matrix2);
Assert.AreEqual(result1.Matrix, new[,] { {900} });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assert.AreEqual(result1.Matrix, new[,] { {900} });
Assert.AreEqual(result1.Matrix, new[,] { { 900 } });

Comment on lines 11 to 13
/// <param name="N"></param>
/// <param name="calculationTime"></param>
/// <returns></returns>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пустые тэги не нужны

for (var r = 0; r < numberOfRows; r++)
{
var line = Array.ConvertAll(fileEnumerator.Current.Split(), int.Parse);
for (var c = 0; c < numberOfColumns; c++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так лучше их и называть, row и column

}
}

file.Close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще, using его сам закроет, но так тоже ок.

{
using var file = new StreamWriter(File.Create(path));

Random rnd = new Random();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Random rnd = new Random();
var rnd = new Random();

/// <returns>Result of matrix multiplication.</returns>
public static DenseMatrix MultiplyConcurrently(DenseMatrix matrix1, DenseMatrix matrix2)
{
var numberOfThreads = Environment.ProcessorCount / 3;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А если матрицы размером меньше, чем numberOfThreads?

@@ -0,0 +1,12 @@
| size | Concurrent Multiplication | Serial Multiplication |
|---------|------------------|------------------------|------------------|------------------------|
| | Expected Value | Standard Deviation | Expected Value | Standard Deviation |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Значения без единиц измерения бессмысленны

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почти всё ок

{
var correctResult = new[,] { { 44, 213 }, { 29, 154 } };
var matrix1 = new DenseMatrix(new[,] { { 10, 4, 5 }, { 8, 9, 1 } });
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, {4, 19} });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, {4, 19} });
var matrix2 = new DenseMatrix(new[,] { { 2, 9 }, { 1, 7 }, { 4, 19 } });

/// </summary>
/// <param name="calculationTime">Array, which elements are time of matrix multiplications.</param>
/// <returns>Returns long value -- expected value of the given data.</returns>
public static long CalculateExpectedValue(long[] calculationTime) => calculationTime.Sum() / calculationTime.Length;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В LINQ есть IEnumerable.Average, он бы сам это сделал


using System.Linq;

public class DenseMatrix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо комментарий :)

{
using var file = new StreamWriter(File.Create(path));

var rnd = new Random();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше random сделать статическим полем и инициализировать один раз.

@@ -0,0 +1,40 @@
namespace MatrixMultiplication;

public static class Table

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо комментарий :)

|---------|------------------|------------------------|------------------|------------------------|
| |Expected Value, ms| Standard Deviation, ms |Expected Value, ms| Standard Deviation, ms |
|---------|------------------|------------------------|------------------|------------------------|
| 100x100 |3 |1,0488088481701514 |12 |0,4472135954999579 |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что-то цифр после запятой многовато у среднеквадратичного отклонения. Речь про случайную величину всё-таки, и её можно измерить только с некоторой погрешностью, так что выводить просто результат арифметических подсчётов бессмысленно — цифры есть, но буквально ничего не значат. Тут, наверное, вообще только целая часть имеет значение, ну, может, ещё одна цифра после запятой, для маленьких матриц

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants