Added some basic methods for matrices.

This commit is contained in:
Filip Strajnar 2024-05-23 20:37:44 +02:00
parent 917c2b3059
commit 5774675fbd

View file

@ -1,6 +1,39 @@
namespace AioNet.DataStructures;
using System;
public static class Matrix
namespace AioNet.DataStructures
{
public static class Matrix
{
public static int NumberOfRows<T>(this T[,] source)
{
return source.GetLength(0);
}
public static int NumberOfColumns<T>(this T[,] source)
{
return source.GetLength(1);
}
public static T[][] ToJaggedArray<T>(this T[,] source)
{
int rows = source.NumberOfRows();
int columns = source.NumberOfColumns();
T[][] jaggedArray = new T[rows][];
for (int row = 0; row < rows; row++)
{
T[] currentRow = new T[columns];
for (int column = 0; column < columns; column++)
{
currentRow[column] = source[row, column];
}
jaggedArray[row] = currentRow;
}
return jaggedArray;
}
}
}