|
|
|
@ -30,6 +30,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
using System.Linq; |
|
|
|
using Generic; |
|
|
|
using Properties; |
|
|
|
using Storage; |
|
|
|
using Threading; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -44,6 +45,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
[Serializable] |
|
|
|
public class DiagonalMatrix : Matrix |
|
|
|
{ |
|
|
|
readonly SparseDiagonalMatrixStorage<double> _storage; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the matrix's data.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The matrix's data.</value>
|
|
|
|
readonly double[] _data; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class. This matrix is square with a given size.
|
|
|
|
/// </summary>
|
|
|
|
@ -53,7 +62,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// </exception>
|
|
|
|
public DiagonalMatrix(int order) : base(order) |
|
|
|
{ |
|
|
|
Data = new double[order]; |
|
|
|
_storage = new SparseDiagonalMatrixStorage<double>(order, order); |
|
|
|
_data = _storage.Data; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -67,11 +77,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// </param>
|
|
|
|
public DiagonalMatrix(int rows, int columns) : base(rows, columns) |
|
|
|
{ |
|
|
|
Data = new double[Math.Min(rows, columns)]; |
|
|
|
_storage = new SparseDiagonalMatrixStorage<double>(rows, columns); |
|
|
|
_data = _storage.Data; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all entries set to a particular value.
|
|
|
|
/// Initializes a new instance of the <see cref="DiagonalMatrix"/> class with all diagonal entries set to a particular value.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rows">
|
|
|
|
/// The number of rows.
|
|
|
|
@ -79,13 +90,15 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// <param name="columns">
|
|
|
|
/// The number of columns.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="value">The value which we assign to each element of the matrix.</param>
|
|
|
|
/// <param name="value">The value which we assign to each diagonal element of the matrix.</param>
|
|
|
|
public DiagonalMatrix(int rows, int columns, double value) : base(rows, columns) |
|
|
|
{ |
|
|
|
Data = new double[Math.Min(rows, columns)]; |
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
_storage = new SparseDiagonalMatrixStorage<double>(rows, columns); |
|
|
|
_data = _storage.Data; |
|
|
|
|
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
Data[i] = value; |
|
|
|
_data[i] = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -98,7 +111,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// <param name="diagonalArray">The one dimensional array which contain diagonal elements.</param>
|
|
|
|
public DiagonalMatrix(int rows, int columns, double[] diagonalArray) : base(rows, columns) |
|
|
|
{ |
|
|
|
Data = diagonalArray; |
|
|
|
_storage = new SparseDiagonalMatrixStorage<double>(rows, columns, diagonalArray); |
|
|
|
_data = _storage.Data; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -110,16 +124,16 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
|
|
|
|
public DiagonalMatrix(double[,] array) : this(array.GetLength(0), array.GetLength(1)) |
|
|
|
{ |
|
|
|
var rows = array.GetLength(0); |
|
|
|
var columns = array.GetLength(1); |
|
|
|
_storage = new SparseDiagonalMatrixStorage<double>(array.GetLength(0), array.GetLength(1)); |
|
|
|
_data = _storage.Data; |
|
|
|
|
|
|
|
for (var i = 0; i < rows; i++) |
|
|
|
for (var i = 0; i < RowCount; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < columns; j++) |
|
|
|
for (var j = 0; j < ColumnCount; j++) |
|
|
|
{ |
|
|
|
if (i == j) |
|
|
|
{ |
|
|
|
Data[i] = array[i, j]; |
|
|
|
_data[i] = array[i, j]; |
|
|
|
} |
|
|
|
else if (array[i, j] != 0.0 && !Double.IsNaN(array[i, j])) |
|
|
|
{ |
|
|
|
@ -129,14 +143,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the matrix's data.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The matrix's data.</value>
|
|
|
|
internal double[] Data |
|
|
|
internal SparseDiagonalMatrixStorage<double> Storage |
|
|
|
{ |
|
|
|
get; |
|
|
|
private set; |
|
|
|
get { return _storage; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -155,7 +164,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// may be thrown if one of the indices is outside the dimensions of the matrix.</exception>
|
|
|
|
public override double At(int row, int column) |
|
|
|
{ |
|
|
|
return row == column ? Data[row] : 0.0; |
|
|
|
return row == column ? _data[row] : 0.0; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -177,7 +186,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
{ |
|
|
|
if (row == column) |
|
|
|
{ |
|
|
|
Data[row] = value; |
|
|
|
_data[row] = value; |
|
|
|
} |
|
|
|
else if (value != 0.0 && !Double.IsNaN(value)) |
|
|
|
{ |
|
|
|
@ -219,7 +228,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// </summary>
|
|
|
|
public override void Clear() |
|
|
|
{ |
|
|
|
Array.Clear(Data, 0, Data.Length); |
|
|
|
_storage.Clear(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -246,13 +255,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (diagonalMatrix.Data.Length != Data.Length) |
|
|
|
if (diagonalMatrix._data.Length != _data.Length) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// If all else fails, perform element wise comparison.
|
|
|
|
return !Data.Where((t, i) => t != diagonalMatrix.Data[i]).Any(); |
|
|
|
return !_data.Where((t, i) => t != diagonalMatrix._data[i]).Any(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -263,14 +272,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// </returns>
|
|
|
|
public override int GetHashCode() |
|
|
|
{ |
|
|
|
var hashNum = Math.Min(Data.Length, 25); |
|
|
|
var hashNum = Math.Min(_data.Length, 25); |
|
|
|
long hash = 0; |
|
|
|
for (var i = 0; i < hashNum; i++) |
|
|
|
{ |
|
|
|
#if PORTABLE
|
|
|
|
hash ^= Precision.DoubleToInt64Bits(Data[i]); |
|
|
|
hash ^= Precision.DoubleToInt64Bits(_data[i]); |
|
|
|
#else
|
|
|
|
hash ^= BitConverter.DoubleToInt64Bits(Data[i]); |
|
|
|
hash ^= BitConverter.DoubleToInt64Bits(_data[i]); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
@ -350,7 +359,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Control.LinearAlgebraProvider.AddArrays(Data, diagOther.Data, diagResult.Data); |
|
|
|
Control.LinearAlgebraProvider.AddArrays(_data, diagOther._data, diagResult._data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -425,7 +434,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Control.LinearAlgebraProvider.SubtractArrays(Data, diagOther.Data, diagResult.Data); |
|
|
|
Control.LinearAlgebraProvider.SubtractArrays(_data, diagOther._data, diagResult._data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -446,12 +455,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
throw new ArgumentNullException("source"); |
|
|
|
} |
|
|
|
|
|
|
|
if (source.Length != Data.Length) |
|
|
|
if (source.Length != _data.Length) |
|
|
|
{ |
|
|
|
throw new ArgumentException(Resources.ArgumentArraysSameLength, "source"); |
|
|
|
} |
|
|
|
|
|
|
|
Buffer.BlockCopy(source, 0, Data, 0, source.Length * Constants.SizeOfDouble); |
|
|
|
|
|
|
|
Buffer.BlockCopy(source, 0, _data, 0, source.Length * Constants.SizeOfDouble); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -473,12 +482,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (Data.Length != denseSource.Data.Length) |
|
|
|
if (_data.Length != denseSource.Data.Length) |
|
|
|
{ |
|
|
|
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "source"); |
|
|
|
} |
|
|
|
|
|
|
|
Buffer.BlockCopy(denseSource.Data, 0, Data, 0, denseSource.Data.Length * Constants.SizeOfDouble); |
|
|
|
Buffer.BlockCopy(denseSource.Data, 0, _data, 0, denseSource.Data.Length * Constants.SizeOfDouble); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -514,7 +523,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
CopyTo(diagResult); |
|
|
|
} |
|
|
|
|
|
|
|
Control.LinearAlgebraProvider.ScaleArray(scalar, Data, diagResult.Data); |
|
|
|
Control.LinearAlgebraProvider.ScaleArray(scalar, _data, diagResult._data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -553,12 +562,12 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var thisDataCopy = new double[r.Data.Length]; |
|
|
|
var otherDataCopy = new double[r.Data.Length]; |
|
|
|
Buffer.BlockCopy(Data, 0, thisDataCopy, 0, (r.Data.Length > Data.Length) ? Data.Length * Constants.SizeOfDouble : r.Data.Length * Constants.SizeOfDouble); |
|
|
|
Buffer.BlockCopy(m.Data, 0, otherDataCopy, 0, (r.Data.Length > m.Data.Length) ? m.Data.Length * Constants.SizeOfDouble : r.Data.Length * Constants.SizeOfDouble); |
|
|
|
var thisDataCopy = new double[r._data.Length]; |
|
|
|
var otherDataCopy = new double[r._data.Length]; |
|
|
|
Buffer.BlockCopy(_data, 0, thisDataCopy, 0, (r._data.Length > _data.Length) ? _data.Length * Constants.SizeOfDouble : r._data.Length * Constants.SizeOfDouble); |
|
|
|
Buffer.BlockCopy(m._data, 0, otherDataCopy, 0, (r._data.Length > m._data.Length) ? m._data.Length * Constants.SizeOfDouble : r._data.Length * Constants.SizeOfDouble); |
|
|
|
|
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, r.Data); |
|
|
|
Control.LinearAlgebraProvider.PointWiseMultiplyArrays(thisDataCopy, otherDataCopy, r._data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -635,9 +644,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
result.Clear(); |
|
|
|
|
|
|
|
// Multiply the elements in the vector with the corresponding diagonal element in this.
|
|
|
|
for (var r = 0; r < Data.Length; r++) |
|
|
|
for (var r = 0; r < _data.Length; r++) |
|
|
|
{ |
|
|
|
result[r] = Data[r] * rightSide[r]; |
|
|
|
result[r] = _data[r] * rightSide[r]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -685,9 +694,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
result.Clear(); |
|
|
|
|
|
|
|
// Multiply the elements in the vector with the corresponding diagonal element in this.
|
|
|
|
for (var r = 0; r < Data.Length; r++) |
|
|
|
for (var r = 0; r < _data.Length; r++) |
|
|
|
{ |
|
|
|
result[r] = Data[r] * leftSide[r]; |
|
|
|
result[r] = _data[r] * leftSide[r]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -703,7 +712,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
throw new ArgumentException(Resources.ArgumentMatrixSquare); |
|
|
|
} |
|
|
|
|
|
|
|
return Data.Aggregate(1.0, (current, t) => current * t); |
|
|
|
return _data.Aggregate(1.0, (current, t) => current * t); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -716,7 +725,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
{ |
|
|
|
// TODO: Should we return reference to array? In current implementation we return copy of array, so changes in DenseVector will
|
|
|
|
// not influence onto diagonal elements
|
|
|
|
return new DenseVector((double[])Data.Clone()); |
|
|
|
return new DenseVector((double[])_data.Clone()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -784,24 +793,20 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
public override void CopyTo(Matrix<double> target) |
|
|
|
{ |
|
|
|
var diagonalTarget = target as DiagonalMatrix; |
|
|
|
|
|
|
|
if (diagonalTarget == null) |
|
|
|
if (diagonalTarget != null) |
|
|
|
{ |
|
|
|
base.CopyTo(target); |
|
|
|
_storage.CopyTo(diagonalTarget.Storage); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (ReferenceEquals(this, target)) |
|
|
|
var denseTarget = target as DenseMatrix; |
|
|
|
if (denseTarget != null) |
|
|
|
{ |
|
|
|
_storage.CopyTo(denseTarget.Storage); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (RowCount != target.RowCount || ColumnCount != target.ColumnCount) |
|
|
|
{ |
|
|
|
throw DimensionsDontMatch<ArgumentException>(this, target, "target"); |
|
|
|
} |
|
|
|
|
|
|
|
Buffer.BlockCopy(Data, 0, diagonalTarget.Data, 0, Data.Length * Constants.SizeOfDouble); |
|
|
|
base.CopyTo(target); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -811,7 +816,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
public override Matrix<double> Transpose() |
|
|
|
{ |
|
|
|
var ret = new DiagonalMatrix(ColumnCount, RowCount); |
|
|
|
Buffer.BlockCopy(Data, 0, ret.Data, 0, Data.Length * Constants.SizeOfDouble); |
|
|
|
Buffer.BlockCopy(_data, 0, ret._data, 0, _data.Length * Constants.SizeOfDouble); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
@ -865,9 +870,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
|
|
|
|
// Clear the result and copy the diagonal entry.
|
|
|
|
result.Clear(); |
|
|
|
if (columnIndex >= rowIndex && columnIndex < rowIndex + length && columnIndex < Data.Length) |
|
|
|
if (columnIndex >= rowIndex && columnIndex < rowIndex + length && columnIndex < _data.Length) |
|
|
|
{ |
|
|
|
result[columnIndex - rowIndex] = Data[columnIndex]; |
|
|
|
result[columnIndex - rowIndex] = _data[columnIndex]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -921,9 +926,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
|
|
|
|
// Clear the result and copy the diagonal entry.
|
|
|
|
result.Clear(); |
|
|
|
if (rowIndex >= columnIndex && rowIndex < columnIndex + length && rowIndex < Data.Length) |
|
|
|
if (rowIndex >= columnIndex && rowIndex < columnIndex + length && rowIndex < _data.Length) |
|
|
|
{ |
|
|
|
result[rowIndex - columnIndex] = Data[rowIndex]; |
|
|
|
result[rowIndex - columnIndex] = _data[rowIndex]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -931,21 +936,21 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
/// <returns>The L1 norm of the matrix.</returns>
|
|
|
|
public override double L1Norm() |
|
|
|
{ |
|
|
|
return Data.Aggregate(double.NegativeInfinity, (current, t) => Math.Max(current, Math.Abs(t))); |
|
|
|
return _data.Aggregate(double.NegativeInfinity, (current, t) => Math.Max(current, Math.Abs(t))); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>Calculates the L2 norm.</summary>
|
|
|
|
/// <returns>The L2 norm of the matrix.</returns>
|
|
|
|
public override double L2Norm() |
|
|
|
{ |
|
|
|
return Data.Aggregate(double.NegativeInfinity, (current, t) => Math.Max(current, Math.Abs(t))); |
|
|
|
return _data.Aggregate(double.NegativeInfinity, (current, t) => Math.Max(current, Math.Abs(t))); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>Calculates the Frobenius norm of this matrix.</summary>
|
|
|
|
/// <returns>The Frobenius norm of this matrix.</returns>
|
|
|
|
public override double FrobeniusNorm() |
|
|
|
{ |
|
|
|
var norm = Data.Sum(t => t * t); |
|
|
|
var norm = _data.Sum(t => t * t); |
|
|
|
return Math.Sqrt(norm); |
|
|
|
} |
|
|
|
|
|
|
|
@ -962,7 +967,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
{ |
|
|
|
var maxSv = double.NegativeInfinity; |
|
|
|
var minSv = double.PositiveInfinity; |
|
|
|
foreach (var t in Data) |
|
|
|
foreach (var t in _data) |
|
|
|
{ |
|
|
|
maxSv = Math.Max(maxSv, Math.Abs(t)); |
|
|
|
minSv = Math.Min(minSv, Math.Abs(t)); |
|
|
|
@ -983,11 +988,11 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
|
|
|
|
var inverse = (DiagonalMatrix)Clone(); |
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
if (Data[i] != 0.0) |
|
|
|
if (_data[i] != 0.0) |
|
|
|
{ |
|
|
|
inverse.Data[i] = 1.0 / Data[i]; |
|
|
|
inverse._data[i] = 1.0 / _data[i]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -1031,9 +1036,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
|
|
|
|
result.Clear(); |
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1096,9 +1101,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
} |
|
|
|
|
|
|
|
result.Clear(); |
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1192,7 +1197,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
int end = Math.Min(columnCount, rowCount + columnInit); |
|
|
|
for (var i = 0; columnInit + i < end; i++) |
|
|
|
{ |
|
|
|
result[i, columnInit + i] = Data[rowIndex + i]; |
|
|
|
result[i, columnInit + i] = _data[rowIndex + i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (rowIndex < columnIndex && rowIndex + rowCount > columnIndex) |
|
|
|
@ -1201,14 +1206,14 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
int end = Math.Min(columnCount + rowInit, rowCount); |
|
|
|
for (var i = 0; rowInit + i < end; i++) |
|
|
|
{ |
|
|
|
result[rowInit + i, i] = Data[columnIndex + i]; |
|
|
|
result[rowInit + i, i] = _data[columnIndex + i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
for (var i = 0; i < Math.Min(columnCount, rowCount); i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[rowIndex + i]; |
|
|
|
result[i, i] = _data[rowIndex + i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1222,9 +1227,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
public override double[,] ToArray() |
|
|
|
{ |
|
|
|
var result = new double[RowCount, ColumnCount]; |
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
@ -1373,9 +1378,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
result.Clear(); |
|
|
|
|
|
|
|
// Copy the diagonal part into the result matrix.
|
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
|
|
|
|
// Copy the lower matrix into the result matrix.
|
|
|
|
@ -1441,9 +1446,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
result.Clear(); |
|
|
|
|
|
|
|
// Copy the diagonal part into the result matrix.
|
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
|
|
|
|
// Copy the lower matrix into the result matrix.
|
|
|
|
@ -1505,9 +1510,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
result.Clear(); |
|
|
|
|
|
|
|
// Copy the diagonal part into the result matrix.
|
|
|
|
for (var i = 0; i < Data.Length; i++) |
|
|
|
for (var i = 0; i < _data.Length; i++) |
|
|
|
{ |
|
|
|
result[i, i] = Data[i]; |
|
|
|
result[i, i] = _data[i]; |
|
|
|
} |
|
|
|
|
|
|
|
// Copy the lower matrix into the result matrix.
|
|
|
|
@ -1567,9 +1572,9 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
CopyTo(result); |
|
|
|
} |
|
|
|
|
|
|
|
for (var index = 0; index < Data.Length; index++) |
|
|
|
for (var index = 0; index < _data.Length; index++) |
|
|
|
{ |
|
|
|
denseResult.Data[index] %= divisor; |
|
|
|
denseResult._data[index] %= divisor; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1589,7 +1594,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double |
|
|
|
var m = new DiagonalMatrix(order); |
|
|
|
for (var i = 0; i < order; i++) |
|
|
|
{ |
|
|
|
m.Data[i] = 1.0; |
|
|
|
m._data[i] = 1.0; |
|
|
|
} |
|
|
|
|
|
|
|
return m; |
|
|
|
|