From 708a4d3820217280cdb374f76103e078b1e0caf5 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 21 Nov 2012 16:49:30 +0200 Subject: [PATCH] Add new class: DenseColumnMajorSymmetricMatrixStorage Signed-off-by: Alexander Karatarakis --- .../DenseColumnMajorSymmetricMatrixStorage.cs | 77 +++++++++++++++++++ .../Indexers/Static/PackedStorageIndexer.cs | 2 +- .../Static/PackedStorageIndexerUpper.cs | 2 +- src/Numerics/Numerics.csproj | 1 + 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/Numerics/LinearAlgebra/Storage/DenseColumnMajorSymmetricMatrixStorage.cs diff --git a/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorSymmetricMatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorSymmetricMatrixStorage.cs new file mode 100644 index 00000000..c58279b6 --- /dev/null +++ b/src/Numerics/LinearAlgebra/Storage/DenseColumnMajorSymmetricMatrixStorage.cs @@ -0,0 +1,77 @@ +using System; + +namespace MathNet.Numerics.LinearAlgebra.Storage +{ + using MathNet.Numerics.LinearAlgebra.Storage.Indexers.Static; + using MathNet.Numerics.Properties; + + public class DenseColumnMajorSymmetricMatrixStorage : MatrixStorage + where T : struct, IEquatable, IFormattable + { + // [ruegg] public fields are OK here + + public readonly T[] Data; + + public readonly PackedStorageIndexerUpper Indexer; + + internal DenseColumnMajorSymmetricMatrixStorage(int order) + : base(order, order) + { + Indexer = new PackedStorageIndexerUpper(order); + Data = new T[Indexer.DataLength]; + } + + internal DenseColumnMajorSymmetricMatrixStorage(int order, T[] data) + : base(order, order) + { + if (data == null) + { + throw new ArgumentNullException("data"); + } + + Indexer = new PackedStorageIndexerUpper(order); + + if (data.Length != Indexer.DataLength) + { + throw new ArgumentOutOfRangeException("data", string.Format(Resources.ArgumentArrayWrongLength, Indexer.DataLength)); + } + + Data = data; + } + + /// + /// Retrieves the requested element without range checking. + /// + /// + /// The row of the element. + /// + /// + /// The column of the element. + /// + /// + /// The requested element. + /// + /// Not range-checked. + public override T At(int row, int column) + { + return Data[Indexer.IndexOf(row, column)]; + } + + /// + /// Sets the element without range checking. + /// + /// The row of the element. + /// The column of the element. + /// The value to set the element to. + /// WARNING: This method is not thread safe. Use "lock" with it and be sure to avoid deadlocks. + public override void At(int row, int column, T value) + { + Data[Indexer.IndexOf(row, column)] = value; + } + + public override void Clear() + { + Array.Clear(Data, 0, Data.Length); + } + } +} diff --git a/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexer.cs b/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexer.cs index 6d4eba54..56a22c4a 100644 --- a/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexer.cs +++ b/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexer.cs @@ -4,7 +4,7 @@ using Properties; /// - /// A class for managing indexing when using Packed Storage indexer, which is a column-major packing scheme for dense Symmetric, Hermitian or Triangular square matrices. + /// A class for managing indexing when using Packed Storage, which is a column-major packing scheme for dense Symmetric, Hermitian or Triangular square matrices. /// public abstract class PackedStorageIndexer : StaticStorageIndexer { diff --git a/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexerUpper.cs b/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexerUpper.cs index 4fc29f00..d9e91bc2 100644 --- a/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexerUpper.cs +++ b/src/Numerics/LinearAlgebra/Storage/Indexers/Static/PackedStorageIndexerUpper.cs @@ -3,7 +3,7 @@ using System; /// - /// A class for managing indexing when using Packed Storage scheme, which is a column-Wise packing scheme for Symmetric, Hermitian or Triangular square matrices. + /// A class for managing indexes when using Packed Storage, which is a column-major packing scheme for Symmetric, Hermitian or Triangular square matrices. /// This variation provides indexes for storing the upper triangle of a matrix (row less than or equal to column). /// public class PackedStorageIndexerUpper : PackedStorageIndexer diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index ce386ecb..a744dbca 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -140,6 +140,7 @@ +