Skip to content

Commit 5547c20

Browse files
authored
Merge pull request #44 from wo80/dev
Release version 4.0.0
2 parents 2fa5b20 + 8c2c61d commit 5547c20

19 files changed

+172
-160
lines changed

CSparse.Tests/CSparse.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
</ItemGroup>
4242

4343
<ItemGroup>
44-
<PackageReference Include="NUnit" Version="4.0.1" />
44+
<PackageReference Include="NUnit" Version="4.1.0" />
4545
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
46-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
46+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
4747
</ItemGroup>
4848

4949
<ItemGroup>

CSparse.Tests/HelperTest.cs

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
namespace CSparse.Tests
33
{
4+
using CSparse.Double;
45
using NUnit.Framework;
56

67
using C = System.Numerics.Complex;
@@ -33,5 +34,36 @@ public void TestTrimStorage()
3334
Assert.That(A.RowIndices.Length, Is.EqualTo(0));
3435
Assert.That(A.Values.Length, Is.EqualTo(0));
3536
}
37+
38+
[Test]
39+
public void TestValidateStorage()
40+
{
41+
var ap = new int[] { 0, 3, 6 };
42+
var ai = new int[] { 0, 1, 2, 0, 1, 2 };
43+
var ax = new double[] { 0, 0, 0, 0, 0, 0 };
44+
45+
var A = new SparseMatrix(3, 2, ax, ai, ap);
46+
47+
Assert.That(Helper.ValidateStorage(A), Is.True);
48+
49+
// Change order of column pointers.
50+
ap[1] = 6; ap[2] = 3;
51+
52+
Assert.That(Helper.ValidateStorage(A), Is.False);
53+
54+
// Revert change to column pointers.
55+
ap[1] = 3; ap[2] = 6;
56+
57+
// Row index larger than number of rows.
58+
ai[2] = 3;
59+
60+
Assert.That(Helper.ValidateStorage(A), Is.False);
61+
62+
// Change order of row indices.
63+
ai[1] = 2; ai[2] = 1;
64+
65+
Assert.That(Helper.ValidateStorage(A), Is.True);
66+
Assert.That(Helper.ValidateStorage(A, true), Is.False);
67+
}
3668
}
3769
}

CSparse/CSparse.csproj

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@
99
<Description>CSparse.NET provides numerical methods for sparse LU, Cholesky and QR decomposition of real and complex linear systems.</Description>
1010
<Product>CSparse.NET</Product>
1111
<Company />
12-
<Copyright>Copyright Christian Woltering © 2012-2023</Copyright>
12+
<Copyright>Copyright Christian Woltering © 2012-2024</Copyright>
1313
<Authors>Christian Woltering</Authors>
14-
<AssemblyVersion>3.8.1.0</AssemblyVersion>
15-
<FileVersion>3.8.1.0</FileVersion>
14+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
15+
<FileVersion>4.0.0.0</FileVersion>
1616
<PackageTags>math sparse matrix lu cholesky qr decomposition factorization </PackageTags>
17-
<Version>3.8.1</Version>
17+
<Version>4.0.0</Version>
1818
<AssemblyName>CSparse</AssemblyName>
1919
<RootNamespace>CSparse</RootNamespace>
2020
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
2121
<PackageProjectUrl>https://github.com/wo80/CSparse.NET</PackageProjectUrl>
22-
<RepositoryUrl>https://github.com/wo80/CSparse.NET</RepositoryUrl>
22+
<RepositoryUrl>https://github.com/wo80/CSparse.NET.git</RepositoryUrl>
2323
<RepositoryType>git</RepositoryType>
2424
<PackageReleaseNotes>
25-
Changes in version 3.8.1:
25+
The major version change is due to the removal of obsolete methods in the Converter class. Visibility of that class was changed from public to internal. In case those obsolete methods were still used, please switch to the static conversion methods provided by the SparseMatrix class.
2626

27-
* Add overloads for permutation Invert() and IsValid() methods taking the permutation length as argument.
27+
Other changes in version 4.0.0:
2828

29-
Changes in version 3.8.0:
30-
31-
* Add overloads for the factorization Solve() methods taking Span&lt;T&gt; as argument. Note that this introduces a dependency on System.Memory for the netstandard2.0 assembly.
32-
</PackageReleaseNotes>
29+
* Addition of helper method Helper.ValidateStorage(...) to validate the structure of a sparse matrix.
30+
* Update to GetHashCode() method of CompressedColumnStorage class.
31+
* Improvements to documentation.
32+
</PackageReleaseNotes>
3333
</PropertyGroup>
3434

3535
<ItemGroup>

CSparse/Complex/Factorization/SparseLDL.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void Factorize(CompressedColumnStorage<Complex> A, IProgress<double> progress)
315315
y[k] = 0.0;
316316
for (; top < n; top++)
317317
{
318-
i = pattern[top]; // Pattern [top:n-1] is pattern of L(:,k)
318+
i = pattern[top]; // Pattern [top:n-1] is pattern of L(k,:)
319319
yi = y[i]; // get and clear Y(i)
320320
y[i] = 0.0;
321321
p2 = lp[i] + lnz[i];

CSparse/Constants.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class Constants
1818
public const int SizeOfDouble = sizeof(double);
1919

2020
/// <summary>
21-
/// The default threshold used for matrix values comparision.
21+
/// The default threshold used for matrix values comparison.
2222
/// </summary>
2323
public const double EqualsThreshold = 1e-12;
2424

CSparse/Converter.cs

+3-77
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,16 @@ namespace CSparse
77
/// <summary>
88
/// Converter for different types of storages.
99
/// </summary>
10-
public static class Converter
10+
internal static class Converter
1111
{
12-
/// <summary>
13-
/// Convert a coordinate storage to compressed sparse column (CSC) format.
14-
/// </summary>
15-
/// <param name="storage">Coordinate storage.</param>
16-
/// <param name="cleanup">Remove and sum duplicate entries.</param>
17-
/// <returns>Compressed sparse column storage.</returns>
18-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfIndexed(...) instead.")]
19-
public static CompressedColumnStorage<T> ToCompressedColumnStorage<T>(CoordinateStorage<T> storage,
20-
bool cleanup = true) where T : struct, IEquatable<T>, IFormattable
21-
{
22-
return ToCompressedColumnStorage_(storage, cleanup);
23-
}
24-
2512
/// <summary>
2613
/// Convert a coordinate storage to compressed sparse column (CSC) format.
2714
/// </summary>
2815
/// <param name="storage">Coordinate storage.</param>
2916
/// <param name="cleanup">Remove and sum duplicate entries.</param>
3017
/// <param name="inplace">Do the conversion in place (re-using the coordinate storage arrays).</param>
3118
/// <returns>Compressed sparse column storage.</returns>
32-
internal static CompressedColumnStorage<T> ToCompressedColumnStorage_<T>(CoordinateStorage<T> storage,
19+
public static CompressedColumnStorage<T> ToCompressedColumnStorage<T>(CoordinateStorage<T> storage,
3320
bool cleanup = true, bool inplace = false) where T : struct, IEquatable<T>, IFormattable
3421
{
3522
int nrows = storage.RowCount;
@@ -110,7 +97,7 @@ internal static CompressedColumnStorage<T> ToCompressedColumnStorage_<T>(Coordin
11097
/// <remarks>
11198
/// On return, the coordinate storage input arrays contain the compressed sparse
11299
/// column data structure for the resulting matrix. The <paramref name="work"/>
113-
/// array contains a copy of the column pointer.
100+
/// array contains a copy of the column pointers.
114101
///
115102
/// The entries of the output matrix are not sorted (the row indices in each
116103
/// column are not in increasing order).
@@ -193,15 +180,8 @@ private static void ConvertInPlace<T>(int columns, int nz, T[] values, int[] row
193180
/// </summary>
194181
/// <param name="array">2D array storage.</param>
195182
/// <returns>Coordinate storage.</returns>
196-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfArray(...) instead.")]
197183
public static CoordinateStorage<T> FromDenseArray<T>(T[,] array)
198184
where T : struct, IEquatable<T>, IFormattable
199-
{
200-
return FromDenseArray_(array);
201-
}
202-
203-
internal static CoordinateStorage<T> FromDenseArray_<T>(T[,] array)
204-
where T : struct, IEquatable<T>, IFormattable
205185
{
206186
int rowCount = array.GetLength(0);
207187
int columnCount = array.GetLength(1);
@@ -219,48 +199,15 @@ internal static CoordinateStorage<T> FromDenseArray_<T>(T[,] array)
219199
return storage;
220200
}
221201

222-
/// <summary>
223-
/// Convert a jagged array to compressed sparse column (CSC) format.
224-
/// </summary>
225-
/// <param name="array">Jagged array storage.</param>
226-
/// <returns>Compressed sparse column storage.</returns>
227-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfJaggedArray(...) instead.")]
228-
public static CompressedColumnStorage<T> ToCompressedColumnStorage<T>(T[][] array)
229-
where T : struct, IEquatable<T>, IFormattable
230-
{
231-
int nrows = array.Length;
232-
int ncols = array[0].Length;
233-
234-
var storage = new CoordinateStorage<T>(nrows, ncols, nrows);
235-
236-
for (int i = 0; i < nrows; i++)
237-
{
238-
for (int j = 0; j < ncols; j++)
239-
{
240-
storage.At(i, j, array[i][j]);
241-
}
242-
}
243-
244-
return ToCompressedColumnStorage_<T>(storage, false);
245-
}
246-
247-
248202
/// <summary>
249203
/// Convert a column major array to coordinate storage.
250204
/// </summary>
251205
/// <param name="array">Column major array storage.</param>
252206
/// <param name="rowCount">Number of rows.</param>
253207
/// <param name="columnCount">Number of columns.</param>
254208
/// <returns>Coordinate storage.</returns>
255-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfColumnMajor(...) instead.")]
256209
public static CoordinateStorage<T> FromColumnMajorArray<T>(T[] array, int rowCount, int columnCount)
257210
where T : struct, IEquatable<T>, IFormattable
258-
{
259-
return FromColumnMajorArray_(array, rowCount, columnCount);
260-
}
261-
262-
internal static CoordinateStorage<T> FromColumnMajorArray_<T>(T[] array, int rowCount, int columnCount)
263-
where T : struct, IEquatable<T>, IFormattable
264211
{
265212
var storage = new CoordinateStorage<T>(rowCount, columnCount, Math.Max(rowCount, columnCount));
266213

@@ -281,15 +228,8 @@ internal static CoordinateStorage<T> FromColumnMajorArray_<T>(T[] array, int row
281228
/// <param name="array">jagged array storage.</param>
282229
/// <returns>Coordinate storage.</returns>
283230
/// <remarks>All rows of the array are assumed to be equal in length</remarks>
284-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfColumnMajor(...) instead.")]
285231
public static CoordinateStorage<T> FromJaggedArray<T>(T[][] array)
286232
where T : struct, IEquatable<T>, IFormattable
287-
{
288-
return FromJaggedArray_(array);
289-
}
290-
291-
internal static CoordinateStorage<T> FromJaggedArray_<T>(T[][] array)
292-
where T : struct, IEquatable<T>, IFormattable
293233
{
294234
int rowCount = array.Length;
295235
int columnCount = array[0].Length;
@@ -314,15 +254,8 @@ internal static CoordinateStorage<T> FromJaggedArray_<T>(T[][] array)
314254
/// <param name="rowCount">Number of rows.</param>
315255
/// <param name="columnCount">Number of columns.</param>
316256
/// <returns>Coordinate storage.</returns>
317-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfRowMajor(...) instead.")]
318257
public static CoordinateStorage<T> FromRowMajorArray<T>(T[] array, int rowCount, int columnCount)
319258
where T : struct, IEquatable<T>, IFormattable
320-
{
321-
return FromRowMajorArray_(array, rowCount, columnCount);
322-
}
323-
324-
internal static CoordinateStorage<T> FromRowMajorArray_<T>(T[] array, int rowCount, int columnCount)
325-
where T : struct, IEquatable<T>, IFormattable
326259
{
327260
var storage = new CoordinateStorage<T>(rowCount, columnCount, Math.Max(rowCount, columnCount));
328261

@@ -344,15 +277,8 @@ internal static CoordinateStorage<T> FromRowMajorArray_<T>(T[] array, int rowCou
344277
/// <param name="rowCount">Number of rows.</param>
345278
/// <param name="columnCount">Number of columns.</param>
346279
/// <returns>Coordinate storage.</returns>
347-
[Obsolete("Will be removed in future versions. Use SparseMatrix.OfIndexed(...) instead.")]
348280
public static CoordinateStorage<T> FromEnumerable<T>(IEnumerable<Tuple<int, int, T>> enumerable, int rowCount, int columnCount)
349281
where T : struct, IEquatable<T>, IFormattable
350-
{
351-
return FromEnumerable_(enumerable, rowCount, columnCount);
352-
}
353-
354-
internal static CoordinateStorage<T> FromEnumerable_<T>(IEnumerable<Tuple<int, int, T>> enumerable, int rowCount, int columnCount)
355-
where T : struct, IEquatable<T>, IFormattable
356282
{
357283
var storage = new CoordinateStorage<T>(rowCount, columnCount, Math.Max(rowCount, columnCount));
358284

CSparse/Double/Factorization/SparseLDL.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void Factorize(CompressedColumnStorage<double> A, IProgress<double> progress)
314314
y[k] = 0.0;
315315
for (; top < n; top++)
316316
{
317-
i = pattern[top]; // Pattern [top:n-1] is pattern of L(:,k)
317+
i = pattern[top]; // Pattern [top:n-1] is pattern of L(k,:)
318318
yi = y[i]; // get and clear Y(i)
319319
y[i] = 0.0;
320320
p2 = lp[i] + lnz[i];

CSparse/Factorization/ISolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CSparse.Factorization
55
/// <summary>
66
/// Classes that solve a system of linear equations, <c>Ax = b</c>.
77
/// </summary>
8-
/// <typeparam name="T">Supported data types are double and <see cref="Complex"/>.</typeparam>
8+
/// <typeparam name="T">Supported data types are <c>double</c> and <see cref="System.Numerics.Complex"/>.</typeparam>
99
public interface ISolver<T> where T : struct, IEquatable<T>, IFormattable
1010
{
1111
/// <summary>

CSparse/Factorization/ISparseFactorization.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CSparse.Factorization
55
/// <summary>
66
/// Interface for factorization methods.
77
/// </summary>
8-
/// <typeparam name="T">Supported data types are <c>double</c> and <see cref="Complex"/>.</typeparam>
8+
/// <typeparam name="T">Supported data types are <c>double</c> and <see cref="System.Numerics.Complex"/>.</typeparam>
99
public interface ISparseFactorization<T> : ISolver<T>
1010
where T : struct, IEquatable<T>, IFormattable
1111
{

CSparse/Factorization/SparseQR.cs

+18-5
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,39 @@ namespace CSparse.Factorization
66
/// <summary>
77
/// Sparse QR decomposition abstract base class.
88
/// </summary>
9+
/// <typeparam name="T">Supported data types are <c>double</c> and <see cref="System.Numerics.Complex"/>.</typeparam>
910
public abstract class SparseQR<T> : ISparseFactorization<T>
1011
where T : struct, IEquatable<T>, IFormattable
1112
{
12-
protected readonly int m, n;
13+
/// <summary>number of rows</summary>
14+
protected readonly int m;
1315

16+
/// <summary>number of columns</summary>
17+
protected readonly int n;
18+
19+
/// <summary>symbolic factorization</summary>
1420
protected SymbolicFactorization S;
15-
protected CompressedColumnStorage<T> Q, R;
21+
22+
/// <summary>Q factor</summary>
23+
protected CompressedColumnStorage<T> Q;
24+
25+
/// <summary>R factor</summary>
26+
protected CompressedColumnStorage<T> R;
27+
28+
/// <summary>factors for Householder reflection</summary>
1629
protected double[] beta;
1730

1831
/// <summary>
1932
/// Initializes a new instance of the SparseQR class.
2033
/// </summary>
2134
protected SparseQR(int rows, int columns)
2235
{
23-
this.m = rows;
24-
this.n = columns;
36+
m = rows;
37+
n = columns;
2538
}
2639

2740
/// <summary>
28-
/// Gets the number of nonzeros in both Q and R factors together.
41+
/// Gets the number of non-zeros in both Q and R factors together.
2942
/// </summary>
3043
public int NonZerosCount
3144
{

CSparse/Factorization/SymbolicFactorization.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ public class SymbolicFactorization
3131
public int[] leftmost;
3232

3333
/// <summary>
34-
/// # of rows for QR, after adding fictitious rows
34+
/// number of rows for QR, after adding fictitious rows
3535
/// </summary>
3636
public int m2;
3737

3838
/// <summary>
39-
/// # entries in L for LU or Cholesky; in V for QR
39+
/// number of entries in L for LU or Cholesky; in V for QR
4040
/// </summary>
4141
public int lnz;
4242

4343
/// <summary>
44-
/// # entries in U for LU; in R for QR
44+
/// number of entries in U for LU; in R for QR
4545
/// </summary>
4646
public int unz;
4747
}

0 commit comments

Comments
 (0)