本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Complex32.SparseMatrix类的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix类的具体用法?C# SparseMatrix怎么用?C# SparseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SparseMatrix类属于MathNet.Numerics.LinearAlgebra.Complex32命名空间,在下文中一共展示了SparseMatrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SolveWideMatrixThrowsArgumentException
public void SolveWideMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(2, 3);
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
}
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源:GpBiCgTest.cs
示例2: SolveWideMatrixThrowsArgumentException
public void SolveWideMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(2, 3);
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:TFQMRTest.cs
示例3: SolveLongMatrixThrowsArgumentException
public void SolveLongMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(3, 2);
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:TFQMRTest.cs
示例4: SolveLongMatrixThrowsArgumentException
public void SolveLongMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(3, 2);
var input = new DenseVector(3);
var solver = new BiCgStab();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:BiCgStabTest.cs
示例5: CreateUnitMatrix
/// <summary>
/// Create unit matrix.
/// </summary>
/// <param name="size">Matrix size.</param>
/// <returns>New unit matrix.</returns>
internal SparseMatrix CreateUnitMatrix(int size)
{
var matrix = new SparseMatrix(size);
for (var i = 0; i < size; i++)
{
matrix[i, i] = 2;
}
return matrix;
}
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:14,代码来源:PreConditionerTest.cs
示例6: CheckResult
/// <summary>
/// Check the result.
/// </summary>
/// <param name="preconditioner">Specific preconditioner.</param>
/// <param name="matrix">Source matrix.</param>
/// <param name="vector">Initial vector.</param>
/// <param name="result">Result vector.</param>
protected override void CheckResult(IPreconditioner<Complex32> preconditioner, SparseMatrix matrix, Vector<Complex32> vector, Vector<Complex32> result)
{
Assert.AreEqual(typeof(UnitPreconditioner<Complex32>), preconditioner.GetType(), "#01");
// Unit preconditioner is doing nothing. Vector and result should be equal
for (var i = 0; i < vector.Count; i++)
{
Assert.IsTrue(vector[i] == result[i], "#02-" + i);
}
}
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:17,代码来源:UnitPreconditionerTest.cs
示例7: CheckResult
/// <summary>
/// Check the result.
/// </summary>
/// <param name="preconditioner">Specific preconditioner.</param>
/// <param name="matrix">Source matrix.</param>
/// <param name="vector">Initial vector.</param>
/// <param name="result">Result vector.</param>
protected override void CheckResult(IPreconditioner<Complex32> preconditioner, SparseMatrix matrix, Vector<Complex32> vector, Vector<Complex32> result)
{
Assert.AreEqual(typeof (DiagonalPreconditioner), preconditioner.GetType(), "#01");
// Compute M * result = product
// compare vector and product. Should be equal
var product = new DenseVector(result.Count);
matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++)
{
Assert.IsTrue(vector[i].Real.AlmostEqualNumbersBetween(product[i].Real, -Epsilon.Magnitude()), "#02-" + i);
Assert.IsTrue(vector[i].Imaginary.AlmostEqualNumbersBetween(product[i].Imaginary, -Epsilon.Magnitude()), "#03-" + i);
}
}
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:21,代码来源:DiagonalTest.cs
示例8: CanAddSparseMatricesBothWays
public void CanAddSparseMatricesBothWays()
{
var m1 = new SparseMatrix(1, 3);
var m2 = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
var sum1 = m1 + m2;
var sum2 = m2 + m1;
Assert.IsTrue(sum1.Equals(m2));
Assert.IsTrue(sum1.Equals(sum2));
var sparseResult = new SparseMatrix(1, 3);
sparseResult.Add(m2, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
sparseResult.Add(m1, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
m1.Add(sparseResult, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
sparseResult.Add(sparseResult, sparseResult);
Assert.IsTrue(sparseResult.Equals(2*sum1));
var denseResult = new DenseMatrix(1, 3);
denseResult.Add(m2, denseResult);
Assert.IsTrue(denseResult.Equals(sum1));
denseResult = DenseMatrix.OfArray(new Complex32[,] {{0, 1, 1}});
denseResult.Add(m1, denseResult);
Assert.IsTrue(denseResult.Equals(sum1));
var m3 = DenseMatrix.OfArray(new Complex32[,] {{0, 1, 1}});
var sum3 = m1 + m3;
var sum4 = m3 + m1;
Assert.IsTrue(sum3.Equals(m3));
Assert.IsTrue(sum3.Equals(sum4));
}
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseMatrixTests.cs
示例9: InsertRow
/// <summary>
/// Creates a new <see cref="SparseMatrix"/> and inserts the given row at the given index.
/// </summary>
/// <param name="rowIndex">The index of where to insert the row.</param>
/// <param name="row">The row to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="row"/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="rowIndex"/> is < zero or > the number of rows.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="row"/> != the number of columns.</exception>
public override Matrix<Complex32> InsertRow(int rowIndex, Vector<Complex32> row)
{
if (row == null)
{
throw new ArgumentNullException("row");
}
if (rowIndex < 0 || rowIndex > RowCount)
{
throw new ArgumentOutOfRangeException("rowIndex");
}
if (row.Count != ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "row");
}
var result = new SparseMatrix(RowCount + 1, ColumnCount);
for (var i = 0; i < rowIndex; i++)
{
result.SetRow(i, Row(i));
}
result.SetRow(rowIndex, row);
for (var i = rowIndex + 1; i < RowCount; i++)
{
result.SetRow(i, Row(i - 1));
}
return result;
}
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:42,代码来源:DiagonalMatrix.cs
示例10: DiagonalStack
/// <summary>
/// Diagonally stacks his matrix on top of the given matrix. The new matrix is a M-by-N matrix,
/// where M = this.Rows + lower.Rows and N = this.Columns + lower.Columns.
/// The values of off the off diagonal matrices/blocks are set to zero.
/// </summary>
/// <param name="lower">The lower, right matrix.</param>
/// <exception cref="ArgumentNullException">If lower is <see langword="null" />.</exception>
/// <returns>the combined matrix</returns>
public override Matrix<Complex32> DiagonalStack(Matrix<Complex32> lower)
{
if (lower == null)
{
throw new ArgumentNullException("lower");
}
var result = new SparseMatrix(RowCount + lower.RowCount, ColumnCount + lower.ColumnCount);
DiagonalStack(lower, result);
return result;
}
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:19,代码来源:DiagonalMatrix.cs
示例11: InsertColumn
/// <summary>
/// Creates a new <see cref="SparseMatrix"/> and inserts the given column at the given index.
/// </summary>
/// <param name="columnIndex">The index of where to insert the column.</param>
/// <param name="column">The column to insert.</param>
/// <returns>A new <see cref="SparseMatrix"/> with the inserted column.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="column "/> is <see langword="null" />. </exception>
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="columnIndex"/> is < zero or > the number of columns.</exception>
/// <exception cref="ArgumentException">If the size of <paramref name="column"/> != the number of rows.</exception>
public override Matrix<Complex32> InsertColumn(int columnIndex, Vector<Complex32> column)
{
if (column == null)
{
throw new ArgumentNullException("column");
}
if (columnIndex < 0 || columnIndex > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
}
if (column.Count != RowCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension, "column");
}
var result = new SparseMatrix(RowCount, ColumnCount + 1);
for (var i = 0; i < columnIndex; i++)
{
result.SetColumn(i, Column(i));
}
result.SetColumn(columnIndex, column);
for (var i = columnIndex + 1; i < ColumnCount + 1; i++)
{
result.SetColumn(i, Column(i - 1));
}
return result;
}
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:42,代码来源:DiagonalMatrix.cs
示例12: SubMatrix
/// <summary>
/// Creates a matrix that contains the values from the requested sub-matrix.
/// </summary>
/// <param name="rowIndex">The row to start copying from.</param>
/// <param name="rowLength">The number of rows to copy. Must be positive.</param>
/// <param name="columnIndex">The column to start copying from.</param>
/// <param name="columnLength">The number of columns to copy. Must be positive.</param>
/// <returns>The requested sub-matrix.</returns>
/// <exception cref="ArgumentOutOfRangeException">If: <list><item><paramref name="rowIndex"/> is
/// negative, or greater than or equal to the number of rows.</item>
/// <item><paramref name="columnIndex"/> is negative, or greater than or equal to the number
/// of columns.</item>
/// <item><c>(columnIndex + columnLength) >= Columns</c></item>
/// <item><c>(rowIndex + rowLength) >= Rows</c></item></list></exception>
/// <exception cref="ArgumentException">If <paramref name="rowLength"/> or <paramref name="columnLength"/>
/// is not positive.</exception>
public override Matrix<Complex32> SubMatrix(int rowIndex, int rowLength, int columnIndex, int columnLength)
{
if (rowIndex >= RowCount || rowIndex < 0)
{
throw new ArgumentOutOfRangeException("rowIndex");
}
if (columnIndex >= ColumnCount || columnIndex < 0)
{
throw new ArgumentOutOfRangeException("columnIndex");
}
if (rowLength < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "rowLength");
}
if (columnLength < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "columnLength");
}
var colMax = columnIndex + columnLength;
var rowMax = rowIndex + rowLength;
if (rowMax > RowCount)
{
throw new ArgumentOutOfRangeException("rowLength");
}
if (colMax > ColumnCount)
{
throw new ArgumentOutOfRangeException("columnLength");
}
var result = new SparseMatrix(rowLength, columnLength);
if (rowIndex > columnIndex && columnIndex + columnLength > rowIndex)
{
for (var i = 0; rowIndex - columnIndex + i < Math.Min(columnLength, rowLength); i++)
{
result[i, rowIndex - columnIndex + i] = Data[rowIndex + i];
}
}
else if (rowIndex < columnIndex && rowIndex + rowLength > columnIndex)
{
for (var i = 0; rowIndex - columnIndex + i < Math.Min(columnLength, rowLength); i++)
{
result[columnIndex - rowIndex + i, i] = Data[columnIndex + i];
}
}
else
{
for (var i = 0; i < Math.Min(columnLength, rowLength); i++)
{
result[i, i] = Data[rowIndex + i];
}
}
return result;
}
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:77,代码来源:DiagonalMatrix.cs
示例13: Append
/// <summary>
/// Concatenates this matrix with the given matrix.
/// </summary>
/// <param name="right">The matrix to concatenate.</param>
/// <returns>The combined <see cref="SparseMatrix"/>.</returns>
public override Matrix<Complex32> Append(Matrix<Complex32> right)
{
if (right == null)
{
throw new ArgumentNullException("right");
}
if (right.RowCount != RowCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension);
}
var result = new SparseMatrix(RowCount, ColumnCount + right.ColumnCount);
Append(right, result);
return result;
}
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:21,代码来源:DiagonalMatrix.cs
示例14: OfDiagonalArray
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given array.
/// This new matrix will be independent from the array.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalArray(Complex32[] diagonal)
{
var m = new SparseMatrix(diagonal.Length, diagonal.Length);
m.SetDiagonal(diagonal);
return m;
}
开发者ID:smoothdeveloper,项目名称:mathnet-numerics,代码行数:11,代码来源:SparseMatrix.cs
示例15: ToRowMatrix
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<Complex32> ToRowMatrix()
{
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(0, _storage.Indices[i], _storage.Values[i]);
}
return matrix;
}
开发者ID:cdrnet,项目名称:mathnet-numerics-native,代码行数:14,代码来源:SparseVector.cs
示例16: ToColumnMatrix
/// <summary>
/// Create a matrix based on this vector in column form (one single column).
/// </summary>
/// <returns>This vector as a column matrix.</returns>
public override Matrix<Complex32> ToColumnMatrix()
{
var matrix = new SparseMatrix(Count, 1);
for (var i = 0; i < _storage.ValueCount; i++)
{
matrix.At(_storage.Indices[i], 0, _storage.Values[i]);
}
return matrix;
}
开发者ID:cdrnet,项目名称:mathnet-numerics-native,代码行数:14,代码来源:SparseVector.cs
示例17: ToRowMatrix
/// <summary>
/// Create a matrix based on this vector in row form (one single row).
/// </summary>
/// <returns>This vector as a row matrix.</returns>
public override Matrix<Complex32> ToRowMatrix()
{
var matrix = new SparseMatrix(1, Count);
for (var i = 0; i < NonZerosCount; i++)
{
matrix.At(0, _nonZeroIndices[i], _nonZeroValues[i]);
}
return matrix;
}
开发者ID:kevkon3,项目名称:mathnet-numerics,代码行数:14,代码来源:SparseVector.cs
示例18: DoMultiplySparse
void DoMultiplySparse(SparseMatrix other, SparseMatrix result)
{
result.Clear();
var ax = _storage.Values;
var ap = _storage.RowPointers;
var ai = _storage.ColumnIndices;
var bx = other._storage.Values;
var bp = other._storage.RowPointers;
var bi = other._storage.ColumnIndices;
int rows = RowCount;
int cols = other.ColumnCount;
int[] cp = result._storage.RowPointers;
var marker = new int[cols];
for (int ib = 0; ib < cols; ib++)
{
marker[ib] = -1;
}
int count = 0;
for (int i = 0; i < rows; i++)
{
// For each row of A
for (int j = ap[i]; j < ap[i + 1]; j++)
{
// Row number to be added
int a = ai[j];
for (int k = bp[a]; k < bp[a + 1]; k++)
{
int b = bi[k];
if (marker[b] != i)
{
marker[b] = i;
count++;
}
}
}
// Record non-zero count.
cp[i + 1] = count;
}
var ci = new int[count];
var cx = new Complex32[count];
for (int ib = 0; ib < cols; ib++)
{
marker[ib] = -1;
}
count = 0;
for (int i = 0; i < rows; i++)
{
int rowStart = cp[i];
for (int j = ap[i]; j < ap[i + 1]; j++)
{
int a = ai[j];
Complex32 aEntry = ax[j];
for (int k = bp[a]; k < bp[a + 1]; k++)
{
int b = bi[k];
Complex32 bEntry = bx[k];
if (marker[b] < rowStart)
{
marker[b] = count;
ci[marker[b]] = b;
cx[marker[b]] = aEntry * bEntry;
count++;
}
else
{
cx[marker[b]] += aEntry * bEntry;
}
}
}
}
result._storage.Values = cx;
result._storage.ColumnIndices = ci;
result._storage.Normalize();
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:85,代码来源:SparseMatrix.cs
示例19: OfDiagonalVector
/// <summary>
/// Create a new sparse matrix with the diagonal as a copy of the given vector.
/// This new matrix will be independent from the vector.
/// A new memory block will be allocated for storing the matrix.
/// </summary>
public static SparseMatrix OfDiagonalVector(Vector<Complex32> diagonal)
{
var m = new SparseMatrix(diagonal.Count, diagonal.Count);
m.SetDiagonal(diagonal);
return m;
}
开发者ID:smoothdeveloper,项目名称:mathnet-numerics,代码行数:11,代码来源:SparseMatrix.cs
示例20: Transpose
/// <summary>
/// Returns the transpose of this matrix.
/// </summary>
/// <returns>The transpose of this matrix.</returns>
public override Matrix<Complex32> Transpose()
{
var ret = new SparseMatrix(ColumnCount, RowCount)
{
_columnIndices = new int[NonZerosCount],
_nonZeroValues = new Complex32[NonZerosCount]
};
// Do an 'inverse' CopyTo iterate over the rows
for (var i = 0; i < _rowIndex.Length; i++)
{
// Get the begin / end index for the current row
var startIndex = _rowIndex[i];
var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
// Get the values for the current row
if (startIndex == endIndex)
{
// Begin and end are equal. There are no values in the row, Move to the next row
continue;
}
for (var j = startIndex; j < endIndex; j++)
{
ret.SetValueAt(_columnIndices[j], i, _nonZeroValues[j]);
}
}
return ret;
}
开发者ID:KeithVanderzanden,项目名称:mmbot,代码行数:34,代码来源:SparseMatrix.cs
注:本文中的MathNet.Numerics.LinearAlgebra.Complex32.SparseMatrix类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论