本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Complex32.SparseMatrix.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix.Clear方法的具体用法?C# SparseMatrix.Clear怎么用?C# SparseMatrix.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Complex32.SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix.Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}