|
|
|
@ -182,6 +182,42 @@ namespace MathNet.Numerics.LinearAlgebra.Single |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SparseMatrix"/> class, copying
|
|
|
|
/// the values from the given matrix.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="matrix">The matrix to copy.</param>
|
|
|
|
public SparseMatrix(Matrix<float> matrix) |
|
|
|
: base(matrix.RowCount, matrix.ColumnCount) |
|
|
|
{ |
|
|
|
var sparseMatrix = matrix as SparseMatrix; |
|
|
|
|
|
|
|
var rows = matrix.RowCount; |
|
|
|
var columns = matrix.ColumnCount; |
|
|
|
|
|
|
|
if (sparseMatrix == null) |
|
|
|
{ |
|
|
|
for (var i = 0; i < rows; i++) |
|
|
|
{ |
|
|
|
for (var j = 0; j < columns; j++) |
|
|
|
{ |
|
|
|
SetValueAt(i, j, matrix.At(i, j)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
NonZerosCount = sparseMatrix.NonZerosCount; |
|
|
|
_rowIndex = new int[rows]; |
|
|
|
_columnIndices = new int[NonZerosCount]; |
|
|
|
_nonZeroValues = new float[NonZerosCount]; |
|
|
|
|
|
|
|
Buffer.BlockCopy(sparseMatrix._nonZeroValues, 0, _nonZeroValues, 0, NonZerosCount * Constants.SizeOfFloat); |
|
|
|
Buffer.BlockCopy(sparseMatrix._columnIndices, 0, _columnIndices, 0, NonZerosCount * Constants.SizeOfInt); |
|
|
|
Buffer.BlockCopy(sparseMatrix._rowIndex, 0, _rowIndex, 0, rows * Constants.SizeOfInt); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a <c>SparseMatrix</c> for the given number of rows and columns.
|
|
|
|
/// </summary>
|
|
|
|
|