本文整理汇总了C#中SparseMatrix.AddElement方法的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix.AddElement方法的具体用法?C# SparseMatrix.AddElement怎么用?C# SparseMatrix.AddElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix.AddElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMatrixATA
public static SparseMatrix CreateMatrixATA(ref SparseMatrix A,ref NonManifoldMesh mesh)
{
// assume A is sorted
// assume values in parameter adj is in order
if (A == null)
throw new Exception("A matrix is null");
int[][] adj = MeshOperators.BuildTwoRingVV(ref mesh).GetRowIndex();
int n = A.ColumnSize;
SparseMatrix ATA = new SparseMatrix(n, n);
for (int i = 0; i < n; i++)
{
List<SparseMatrix.Element> col1 = A.GetColumn(i);
foreach (int j in adj[i])
{
List<SparseMatrix.Element> col2 = A.GetColumn(j);
int c1 = 0, c2 = 0;
double sum = 0.0;
bool used = false;
while (c1 < col1.Count && c2 < col2.Count)
{
if (col1[c1].i < col2[c2].i) { c1++; continue; }
if (col1[c1].i > col2[c2].i) { c2++; continue; }
sum += col1[c1].value * col2[c2].value;
used = true;
c1++;
c2++;
}
if (used)
ATA.AddElement(i, j, sum);
}
}
if (ATA.IsSymmetric() == false) throw new Exception("ATA is not symmetric!!");
return ATA;
}
示例2: ConvertToSparse
public SparseMatrix ConvertToSparse(double[,] i, double[,] j,double[,] value,int row,int col)
{
SparseMatrix sparse = new SparseMatrix(row, col);
for(int k=0;k<i.Length;k++)
{
int r = (int)i[k, 0] - 1;
int c = (int)j[k, 0] - 1;
sparse.AddElement(r,c, value[k,0]);
// Console.WriteLine("{0}--{1}--{2}", r,c, value[k, 0]);
}
return sparse;
}
示例3: Convert
public SparseMatrix Convert()
{
SparseMatrix result = new SparseMatrix(this.RowCount, this.ColumnCount);
foreach (KeyValuePair<Pair, double> item in this.mapData)
{
Pair pair = item.Key;
double value = item.Value;
result.AddElement(pair.Key,pair.Value, value);
}
return result;
}