Skip to content

Commit

Permalink
Merge pull request mathnet#1003 from DoctorKrolic/debugger-display
Browse files Browse the repository at this point in the history
Add debugger display proxy to vector and matrix
  • Loading branch information
cdrnet authored Apr 23, 2023
2 parents eb89b3d + 927100a commit 752c6f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/Numerics/LinearAlgebra/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>

using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime;
using System.Runtime.CompilerServices;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;

namespace MathNet.Numerics.LinearAlgebra
{
Expand All @@ -42,6 +43,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary>
/// <typeparam name="T">Supported data types are <c>double</c>, <c>single</c>, <see cref="Complex"/>, and <see cref="Complex32"/>.</typeparam>
[Serializable]
[DebuggerTypeProxy(typeof(MatrixDebuggingView<>))]
public abstract partial class Matrix<T> : IFormattable, IEquatable<Matrix<T>>, ICloneable
where T : struct, IEquatable<T>, IFormattable
{
Expand Down Expand Up @@ -1879,4 +1881,18 @@ public bool ForAll2<TOther>(Func<T, TOther, bool> predicate, Matrix<TOther> othe
return Storage.Find2(other.Storage, (x, y) => !predicate(x, y), zeros) == null;
}
}

internal class MatrixDebuggingView<T>
where T : struct, IEquatable<T>, IFormattable
{
private readonly Matrix<T> _matrix;

public MatrixDebuggingView(Matrix<T> matrix)
{
_matrix = matrix;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[,] Items => _matrix.ToArray();
}
}
18 changes: 17 additions & 1 deletion src/Numerics/LinearAlgebra/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>

using MathNet.Numerics.LinearAlgebra.Storage;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.CompilerServices;
using MathNet.Numerics.LinearAlgebra.Storage;

namespace MathNet.Numerics.LinearAlgebra
{
Expand All @@ -41,6 +42,7 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary>
/// <typeparam name="T">Supported data types are double, single, <see cref="Complex"/>, and <see cref="Complex32"/>.</typeparam>
[Serializable]
[DebuggerTypeProxy(typeof(VectorDebuggingView<>))]
public abstract partial class Vector<T> : IFormattable, IEquatable<Vector<T>>, IList, IList<T>, ICloneable
where T : struct, IEquatable<T>, IFormattable
{
Expand Down Expand Up @@ -529,4 +531,18 @@ public bool ForAll2<TOther>(Func<T, TOther, bool> predicate, Vector<TOther> othe
return Storage.Find2(other.Storage, (x, y) => !predicate(x, y), zeros) == null;
}
}

internal class VectorDebuggingView<T>
where T : struct, IEquatable<T>, IFormattable
{
private readonly Vector<T> _vector;

public VectorDebuggingView(Vector<T> vector)
{
_vector = vector;
}

[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items => _vector.ToArray();
}
}

0 comments on commit 752c6f2

Please sign in to comment.