MatrixDotNet 0.0.3
See the version list below for details.
dotnet add package MatrixDotNet --version 0.0.3
NuGet\Install-Package MatrixDotNet -Version 0.0.3
<PackageReference Include="MatrixDotNet" Version="0.0.3" />
paket add MatrixDotNet --version 0.0.3
#r "nuget: MatrixDotNet, 0.0.3"
// Install MatrixDotNet as a Cake Addin #addin nuget:?package=MatrixDotNet&version=0.0.3 // Install MatrixDotNet as a Cake Tool #tool nuget:?package=MatrixDotNet&version=0.0.3
MatrixDotNet is a lightweight .NET library for calculate matrix. You can install MatrixDotNet via NuGet package.
Features
- MatrixDotNet is made in priority on speed and accuracy of calculations
Example
[!code-csharpStrassenSample.cs]
public class StrassenSample
{
int[,] matrix = new int[512,512];
int[,] matrix2 = new int[512,512];
private Matrix<int> matrix3;
private Matrix<int> matrix4;
[GlobalSetup]
public void Setup()
{
Random random = new Random();
Random random2 = new Random();
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
matrix[i, j] = random.Next(1, 10);
}
}
matrix3 = new Matrix<int>(matrix);
for (int i = 0; i < matrix2.GetLength(0); i++)
{
for (int j = 0; j < matrix2.GetLength(1); j++)
{
matrix2[i, j] = random2.Next(1, 10);
}
}
matrix4 = new Matrix<int>(matrix2);
}
[Benchmark]
public Matrix<int> Default()
{
return matrix3 * matrix4;
}
[Benchmark]
public Matrix<int> Strassen()
{
return MatrixExtension.MultiplyStrassen(matrix3, matrix4);
}
}
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.14393.3808 (1607/AnniversaryUpdate/Redstone1)
Intel Core i5-8250U CPU 1.60GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
Frequency=1757816 Hz, Resolution=568.8878 ns, Timer=TSC
[Host] : .NET Framework 4.8 (4.8.4180.0), X86 LegacyJIT
Job-YFITZW : .NET Framework 4.8 (4.8.4180.0), X86 LegacyJIT
IterationCount=5 LaunchCount=1 WarmupCount=5
Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|
Default | 69.88 s | 1.241 s | 0.322 s | - | - | - | 1.01 MB |
Strassen | 43.23 s | 0.991 s | 0.153 s | 30000.0000 | 5000.0000 | 2000.0000 | 174.32 MB |
As you can see algorithm Strassen
multiply works significant faster(x1.625) than default multiply matrix on big size MxN
.
MatrixDotNet bit hacks are present to improve performance
Example
public class MatrixBitMinVsDefaultMin
{
private int N = 256;
private int[,] matrix;
private Matrix<int> matrix3;
private Random random = new Random();
private int[] arr;
[GlobalSetup]
public void Setup()
{
matrix = new int[N,N];
arr = new int[N];
// init matrix random data
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
matrix[i, j] = random.Next(-255, 255);
}
}
matrix3 = new Matrix<int>(matrix);
}
[Benchmark]
public void DefaultMin()
{
for (int i = 0; i < N; i++)
{
arr[i] = matrix3.Min();
}
}
[Benchmark]
public void BitMin()
{
for (int i = 0; i < N; i++)
{
arr[i] = matrix3.BitMin();
}
}
}
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.14393.3808 (1607/AnniversaryUpdate/Redstone1)
Intel Core i5-8250U CPU 1.60GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
Frequency=1757816 Hz, Resolution=568.8878 ns, Timer=TSC
[Host] : .NET Framework 4.8 (4.8.4180.0), X86 LegacyJIT
DefaultJob : .NET Framework 4.8 (4.8.4180.0), X86 LegacyJIT
Method | Mean | Error | StdDev | Code Size |
---|---|---|---|---|
DefaultMin | 1,117.2 ms | 12.93 ms | 11.46 ms | 292 B |
BitMin | 646.5 ms | 4.16 ms | 3.25 ms | 165 B |
As you can see BitMin() method works faster(x1.725) than DefaultMin(). Because we eliminate branch prediction. See more information about Bitwise operations in article.
Sample
Lets see simple operations MatrixDotNet.
public sealed class Program
{
static void Main(string[] args)
{
// initialize matrix.
double[,] arr =
{
{5,56,7},
{3,6,3},
{5,9,15}
};
Matrix<float> matrix = new Matrix<float>(arr);
double[] right = { 1,23,5};
double[] res = matrix.KramerSolve(right);
for(var i = 0; i < res.Length; i++)
{
Console.Write($"x{i}: {res[i]}\n");
}
}
}
Result
x0: 12,393939393939394
x1: -0,6637806637806638
x2: -3,3997113997114
See more information docs
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MatrixDotNet:
Package | Downloads |
---|---|
DS.SeriesAnalysis
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
0.0.7.3 | 4,272 | 10/15/2021 | |
0.0.7.2 | 984 | 1/23/2021 | |
0.0.7.1 | 1,015 | 12/27/2020 | |
0.0.7 | 4,155 | 11/16/2020 | |
0.0.6.2 | 1,023 | 11/2/2020 | |
0.0.6.1 | 980 | 10/14/2020 | |
0.0.6 | 960 | 10/14/2020 | |
0.0.5 | 1,163 | 9/29/2020 | |
0.0.4 | 1,090 | 8/27/2020 | |
0.0.3.2 | 1,017 | 8/21/2020 | |
0.0.3.1 | 1,237 | 8/14/2020 | |
0.0.3 | 1,158 | 8/8/2020 |
Update pretty method, change function partition on namespace by logic.
Add matrix conversion such as add column or row and reduce column or row.
Add decomposition matrix LUP.
Add LU determinant, Shurs complement, algebraic complement, Inverse matrix, Shurs determinant
Add matrix builder which you can create matrix through expression or build identity matrix.
If you have any questions you can ask it on gitter MatrixDotNet https://gitter.im/MatrixDotNet/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge.