Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 4.4.0 - 2026-06-10

* Add Refactorize methods to SparseCholesky, SparseLDL and SparseLU

### Version 4.3.0 - 2025-11-11

* Add net10.0 and remove net6.0 target framework.
Expand Down
6 changes: 3 additions & 3 deletions CSparse.Tests/CSparse.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CSparse.Tests/Complex/ComplexNumberComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CSparse.Tests.Complex

public class ComplexNumberComparer : IComparer, IComparer<Complex>
{
public static ComplexNumberComparer Default = new ComplexNumberComparer();
public static ComplexNumberComparer Default = new();

// Floating point tolerance
const double TOL = 1e-8;
Expand Down
76 changes: 33 additions & 43 deletions CSparse.Tests/Complex/MatrixHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ namespace CSparse.Tests.Complex
using CSparse.Storage;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

class MatrixHelper
{
private static Dictionary<string, DenseTestData<Complex>> dense = new Dictionary<string, DenseTestData<Complex>>();

private static Dictionary<string, SparseTestData<Complex>> sparse = new Dictionary<string, SparseTestData<Complex>>();
private static readonly Dictionary<string, DenseTestData<Complex>> dense = [];
private static readonly Dictionary<string, SparseTestData<Complex>> sparse = [];

public static SparseTestData<Complex> LoadSparse(int rows, int columns)
{
string resource = string.Format("test-data-dense-{0}x{1}.txt", rows, columns);

SparseTestData<Complex> data;

if (!sparse.TryGetValue(resource, out data))
if (!sparse.TryGetValue(resource, out SparseTestData<Complex> data))
{
var dense = LoadDense(rows, columns);

Expand All @@ -35,9 +31,7 @@ public static DenseTestData<Complex> LoadDense(int rows, int columns)
{
string resource = string.Format("test-data-dense-{0}x{1}.txt", rows, columns);

DenseTestData<Complex> data;

if (!dense.TryGetValue(resource, out data))
if (!dense.TryGetValue(resource, out DenseTestData<Complex> data))
{
var stream = ResourceLoader.GetStream(resource, "Double");

Expand All @@ -53,22 +47,21 @@ private static DenseTestData<Complex> ReadDenseTestData(Stream stream)
{
var data = Tests.Double.DenseTestDataReader.Read(stream);

var result = new DenseTestData<Complex>();

result.A = ToComplex(data.A);
result.B = ToComplex(data.B);
result.x = ToComplex(data.x);
result.y = ToComplex(data.y);
result.AT = ToComplex(data.AT);
result.BT = ToComplex(data.BT);
result.ApB = ToComplex(data.ApB);
result.AmBT = ToComplex(data.AmBT);
result.ATmB = ToComplex(data.ATmB);
result.Ax = ToComplex(data.Ax);
result.ATy = ToComplex(data.ATy);
result.xTBT = ToComplex(data.xTBT);

return result;
return new DenseTestData<Complex>
{
A = ToComplex(data.A),
B = ToComplex(data.B),
x = ToComplex(data.x),
y = ToComplex(data.y),
AT = ToComplex(data.AT),
BT = ToComplex(data.BT),
ApB = ToComplex(data.ApB),
AmBT = ToComplex(data.AmBT),
ATmB = ToComplex(data.ATmB),
Ax = ToComplex(data.Ax),
ATy = ToComplex(data.ATy),
xTBT = ToComplex(data.xTBT)
};
}

private static Complex[] ToComplex(double[] vec)
Expand Down Expand Up @@ -101,26 +94,23 @@ private static DenseColumnMajorStorage<Complex> ToComplex(DenseColumnMajorStorag

private static SparseTestData<Complex> DenseToSparse(DenseTestData<Complex> dense)
{
var data = new SparseTestData<Complex>()
return new SparseTestData<Complex>
{
RowCount = dense.RowCount,
ColumnCount = dense.ColumnCount
ColumnCount = dense.ColumnCount,
A = DenseToSparse(dense.A),
B = DenseToSparse(dense.B),
x = dense.x,
y = dense.y,
AT = DenseToSparse(dense.AT),
BT = DenseToSparse(dense.BT),
ApB = DenseToSparse(dense.ApB),
AmBT = DenseToSparse(dense.AmBT),
ATmB = DenseToSparse(dense.ATmB),
Ax = dense.Ax,
ATy = dense.ATy,
xTBT = dense.xTBT
};

data.A = DenseToSparse(dense.A);
data.B = DenseToSparse(dense.B);
data.x = dense.x;
data.y = dense.y;
data.AT = DenseToSparse(dense.AT);
data.BT = DenseToSparse(dense.BT);
data.ApB = DenseToSparse(dense.ApB);
data.AmBT = DenseToSparse(dense.AmBT);
data.ATmB = DenseToSparse(dense.ATmB);
data.Ax = dense.Ax;
data.ATy = dense.ATy;
data.xTBT = dense.xTBT;

return data;
}

private static CompressedColumnStorage<Complex> DenseToSparse(DenseColumnMajorStorage<Complex> dense)
Expand Down
125 changes: 61 additions & 64 deletions CSparse.Tests/Double/DenseTestDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,77 @@ class DenseTestDataReader
{
public static DenseTestData<double> Read(Stream stream)
{
using (var reader = new StreamReader(stream))
using var reader = new StreamReader(stream);

string line = reader.ReadLine();

GetItem(line, out string name, out string value);

if (name != "size")
{
string line, name, value;
throw new FormatException("Expected first line = size.");
}

line = reader.ReadLine();
var data = ReadSize(value);

int m = data.RowCount;
int n = data.ColumnCount;

while ((line = reader.ReadLine()) != null)
{
GetItem(line, out name, out value);

if (name != "size")
if (name == "A")
{
throw new FormatException("Expected first line = size.");
data.A = ReadMatrix(value, m, n);
}

var data = ReadSize(value);

int m = data.RowCount;
int n = data.ColumnCount;

while ((line = reader.ReadLine()) != null)
else if (name == "B")
{
GetItem(line, out name, out value);

if (name == "A")
{
data.A = ReadMatrix(value, m, n);
}
else if (name == "B")
{
data.B = ReadMatrix(value, m, n);
}
else if (name == "x")
{
data.x = ReadVector(value, n);
}
else if (name == "y")
{
data.y = ReadVector(value, m);
}
else if (name == "A'")
{
data.AT = ReadMatrix(value, n, m);
}
else if (name == "B'")
{
data.BT = ReadMatrix(value, n, m);
}
else if (name == "A+B")
{
data.ApB = ReadMatrix(value, m, n);
}
else if (name == "A*B'")
{
data.AmBT = ReadMatrix(value, m, m);
}
else if (name == "A'*B")
{
data.ATmB = ReadMatrix(value, n, n);
}
else if (name == "A*x")
{
data.Ax = ReadVector(value, m);
}
else if (name == "A'*y")
{
data.ATy = ReadVector(value, n);
}
else if (name == "x'*B'")
{
data.xTBT = ReadVector(value, m);
}
data.B = ReadMatrix(value, m, n);
}
else if (name == "x")
{
data.x = ReadVector(value, n);
}
else if (name == "y")
{
data.y = ReadVector(value, m);
}
else if (name == "A'")
{
data.AT = ReadMatrix(value, n, m);
}
else if (name == "B'")
{
data.BT = ReadMatrix(value, n, m);
}
else if (name == "A+B")
{
data.ApB = ReadMatrix(value, m, n);
}
else if (name == "A*B'")
{
data.AmBT = ReadMatrix(value, m, m);
}
else if (name == "A'*B")
{
data.ATmB = ReadMatrix(value, n, n);
}
else if (name == "A*x")
{
data.Ax = ReadVector(value, m);
}
else if (name == "A'*y")
{
data.ATy = ReadVector(value, n);
}
else if (name == "x'*B'")
{
data.xTBT = ReadVector(value, m);
}

return data;
}

return data;
}

private static void GetItem(string line, out string name, out string value)
Expand Down
44 changes: 18 additions & 26 deletions CSparse.Tests/Double/MatrixHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ namespace CSparse.Tests.Double

class MatrixHelper
{
private static Dictionary<string, DenseTestData<double>> dense = new Dictionary<string, DenseTestData<double>>();

private static Dictionary<string, SparseTestData<double>> sparse = new Dictionary<string, SparseTestData<double>>();
private static readonly Dictionary<string, DenseTestData<double>> dense = [];
private static readonly Dictionary<string, SparseTestData<double>> sparse = [];

public static SparseTestData<double> LoadSparse(int rows, int columns)
{
string resource = string.Format("test-data-dense-{0}x{1}.txt", rows, columns);

SparseTestData<double> data;

if (!sparse.TryGetValue(resource, out data))
if (!sparse.TryGetValue(resource, out SparseTestData<double> data))
{
var dense = LoadDense(rows, columns);

Expand All @@ -31,9 +28,7 @@ public static DenseTestData<double> LoadDense(int rows, int columns)
{
string resource = string.Format("test-data-dense-{0}x{1}.txt", rows, columns);

DenseTestData<double> data;

if (!dense.TryGetValue(resource, out data))
if (!dense.TryGetValue(resource, out DenseTestData<double> data))
{
var stream = ResourceLoader.GetStream(resource, "Double");

Expand All @@ -47,26 +42,23 @@ public static DenseTestData<double> LoadDense(int rows, int columns)

private static SparseTestData<double> DenseToSparse(DenseTestData<double> dense)
{
var data = new SparseTestData<double>()
return new SparseTestData<double>
{
RowCount = dense.RowCount,
ColumnCount = dense.ColumnCount
ColumnCount = dense.ColumnCount,
A = DenseToSparse(dense.A),
B = DenseToSparse(dense.B),
x = dense.x,
y = dense.y,
AT = DenseToSparse(dense.AT),
BT = DenseToSparse(dense.BT),
ApB = DenseToSparse(dense.ApB),
AmBT = DenseToSparse(dense.AmBT),
ATmB = DenseToSparse(dense.ATmB),
Ax = dense.Ax,
ATy = dense.ATy,
xTBT = dense.xTBT
};

data.A = DenseToSparse(dense.A);
data.B = DenseToSparse(dense.B);
data.x = dense.x;
data.y = dense.y;
data.AT = DenseToSparse(dense.AT);
data.BT = DenseToSparse(dense.BT);
data.ApB = DenseToSparse(dense.ApB);
data.AmBT = DenseToSparse(dense.AmBT);
data.ATmB = DenseToSparse(dense.ATmB);
data.Ax = dense.Ax;
data.ATy = dense.ATy;
data.xTBT = dense.xTBT;

return data;
}

private static CompressedColumnStorage<double> DenseToSparse(DenseColumnMajorStorage<double> dense)
Expand Down
Loading